From 00e6d177141317fc3e4b14aebd606934bdc267ec Mon Sep 17 00:00:00 2001 From: Peter Repukat Date: Thu, 28 Oct 2021 19:33:56 +0200 Subject: [PATCH] Display executable/UWP icons throughout configurator --- GlosSIConfig/ExeImageProvider.cpp | 1 + GlosSIConfig/ExeImageProvider.h | 30 ++++++++ GlosSIConfig/GlosSIConfig.vcxproj | 2 + GlosSIConfig/GlosSIConfig.vcxproj.filters | 6 ++ GlosSIConfig/Resource.rc | 84 +++++++++++++++++++++-- GlosSIConfig/main.cpp | 4 ++ GlosSIConfig/qml/ShortcutCards.qml | 32 +++++---- GlosSIConfig/qml/ShortcutProps.qml | 18 +++++ 8 files changed, 159 insertions(+), 18 deletions(-) create mode 100644 GlosSIConfig/ExeImageProvider.cpp create mode 100644 GlosSIConfig/ExeImageProvider.h diff --git a/GlosSIConfig/ExeImageProvider.cpp b/GlosSIConfig/ExeImageProvider.cpp new file mode 100644 index 0000000..9162c94 --- /dev/null +++ b/GlosSIConfig/ExeImageProvider.cpp @@ -0,0 +1 @@ +#include "ExeImageProvider.h" diff --git a/GlosSIConfig/ExeImageProvider.h b/GlosSIConfig/ExeImageProvider.h new file mode 100644 index 0000000..d83dbe1 --- /dev/null +++ b/GlosSIConfig/ExeImageProvider.h @@ -0,0 +1,30 @@ +#pragma once +#include +#include +class ExeImageProvider : public QQuickImageProvider { + public: + ExeImageProvider() + : QQuickImageProvider(QQuickImageProvider::Image) + { + } + + QImage requestImage(const QString& id, QSize* size, const QSize& requestedSize) override + { + HICON icon = 0; + std::wstring path = id.toStdWString(); + icon = (HICON)LoadImage( + 0, + path.data(), + IMAGE_ICON, + GetSystemMetrics(SM_CXSMICON), + GetSystemMetrics(SM_CYSMICON), + LR_LOADFROMFILE | LR_LOADMAP3DCOLORS); + if (!icon) { + ExtractIconEx(path.data(), 0, &icon, nullptr, 1); + if (!icon) { + return {}; + } + } + return QImage::fromHICON(icon); + } +}; diff --git a/GlosSIConfig/GlosSIConfig.vcxproj b/GlosSIConfig/GlosSIConfig.vcxproj index 7a87e58..5d3a907 100644 --- a/GlosSIConfig/GlosSIConfig.vcxproj +++ b/GlosSIConfig/GlosSIConfig.vcxproj @@ -132,6 +132,7 @@ + @@ -149,6 +150,7 @@ + diff --git a/GlosSIConfig/GlosSIConfig.vcxproj.filters b/GlosSIConfig/GlosSIConfig.vcxproj.filters index c2771d7..4ee0cc0 100644 --- a/GlosSIConfig/GlosSIConfig.vcxproj.filters +++ b/GlosSIConfig/GlosSIConfig.vcxproj.filters @@ -34,6 +34,9 @@ Source Files + + Source Files + @@ -83,6 +86,9 @@ Header Files + + Header Files + diff --git a/GlosSIConfig/Resource.rc b/GlosSIConfig/Resource.rc index f955b2a..1fd04a0 100644 --- a/GlosSIConfig/Resource.rc +++ b/GlosSIConfig/Resource.rc @@ -51,8 +51,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,0,0,6800050 - PRODUCTVERSION 0,0,0,6800050 + FILEVERSION 0,0,0,7002809 + PRODUCTVERSION 0,0,0,7002809 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -69,12 +69,12 @@ BEGIN BEGIN VALUE "CompanyName", "Peter Repukat - FlatspotSoftware" VALUE "FileDescription", "GlosSI - Config" - VALUE "FileVersion", "0.0.0.68fbe50" + VALUE "FileVersion", "0.0.0.7ae28a9" VALUE "InternalName", "GlosSIConfig" VALUE "LegalCopyright", "Copyright (C) 2021 Peter Repukat - FlatspotSoftware" VALUE "OriginalFilename", "GlosSIConfig.exe" VALUE "ProductName", "GlosSi" - VALUE "ProductVersion", "0.0.0.68fbe50" + VALUE "ProductVersion", "0.0.0.7ae28a9" END END BLOCK "VarFileInfo" @@ -106,3 +106,79 @@ END + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GlosSIConfig/main.cpp b/GlosSIConfig/main.cpp index 63ba47b..ccb8f5b 100644 --- a/GlosSIConfig/main.cpp +++ b/GlosSIConfig/main.cpp @@ -23,6 +23,7 @@ limitations under the License. #include #include #pragma comment(lib, "Dwmapi.lib") +#include "ExeImageProvider.h" #endif #include "UIModel.h" @@ -72,6 +73,9 @@ int main(int argc, char* argv[]) QQmlApplicationEngine engine; UIModel uimodel; +#ifdef _WIN32 + engine.addImageProvider(QLatin1String("exe"), new ExeImageProvider()); +#endif engine.rootContext()->setContextProperty("uiModel", QVariant::fromValue(&uimodel)); engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); if (engine.rootObjects().isEmpty()) diff --git a/GlosSIConfig/qml/ShortcutCards.qml b/GlosSIConfig/qml/ShortcutCards.qml index cefac18..a619057 100644 --- a/GlosSIConfig/qml/ShortcutCards.qml +++ b/GlosSIConfig/qml/ShortcutCards.qml @@ -81,10 +81,26 @@ GridView { Material.elevation: 4 clip: true property bool isInSteam: uiModel.isInSteam(modelData); + + Image { + anchors.top: parent.top + anchors.left: parent.left + id: maybeIcon + source: modelData.icon + ? modelData.icon.endsWith(".exe") + ? "image://exe/" + modelData.icon + : "file:///" + modelData.icon + : null + width: 48 + height: 48 + visible: modelData.icon + } + Label { id: label anchors.top: parent.top - anchors.left: parent.left + anchors.leftMargin: 8 + anchors.left: maybeIcon.right anchors.right: parent.right text: modelData.name font.bold: true @@ -93,7 +109,7 @@ GridView { } Column { - anchors.top: label.bottom + anchors.top: maybeIcon.bottom anchors.left: parent.left anchors.bottom: buttonrow.top anchors.margins: 12 @@ -152,18 +168,6 @@ GridView { } } - Image { - anchors.right: parent.right - anchors.bottom: buttonrow.top - id: maybeIcon - anchors.bottomMargin: 8 - source: modelData.icon ? "file:///" + modelData.icon : null - // TODO: extract exe icons. - width: 48 - height: 48 - visible: modelData.icon - } - Button { id: steambutton anchors.left: parent.left diff --git a/GlosSIConfig/qml/ShortcutProps.qml b/GlosSIConfig/qml/ShortcutProps.qml index 7db0a60..207e77f 100644 --- a/GlosSIConfig/qml/ShortcutProps.qml +++ b/GlosSIConfig/qml/ShortcutProps.qml @@ -133,6 +133,23 @@ Item { id: launchlayout spacing: 4 width: parent.width + Image { + id: maybeIcon + source: shortcutInfo.icon + ? shortcutInfo.icon.endsWith(".exe") + ? "image://exe/" + shortcutInfo.icon + : "file:///" + shortcutInfo.icon + : null + Layout.preferredWidth: 48 + Layout.preferredHeight: 48 + visible: shortcutInfo.icon + Layout.alignment: Qt.AlignVCenter + } + Item { + Layout.preferredWidth: 8 + Layout.preferredHeight: 8 + visible: shortcutInfo.icon + } Item { Layout.preferredWidth: parent.width / 2 Layout.fillWidth: true @@ -273,6 +290,7 @@ Item { pathInput.text = fileDialog.selectedFile.toString().replace("file:///", "") if (nameInput.text == "") { nameInput.text = pathInput.text.replace(/.*(\\|\/)/,"").replace(/\.[0-z]*$/, "") + shortcutInfo.icon = nameInput.text } launchApp.checked = true }