From 0651323da477d9f8a657fe0d27a98d73255d05ea Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 15 Oct 2021 22:18:30 +0200 Subject: [PATCH] Use ForkAwesome consistently in Plasmoid as well --- CMakeLists.txt | 1 + plasmoid/CMakeLists.txt | 1 + plasmoid/lib/CMakeLists.txt | 4 + plasmoid/lib/syncthingapplet.cpp | 12 ++- plasmoid/lib/syncthingapplet.h | 1 + plasmoid/package/contents/ui/DevicesPage.qml | 2 +- .../package/contents/ui/DirectoriesPage.qml | 8 +- .../package/contents/ui/DownloadsPage.qml | 4 +- .../contents/ui/FullRepresentation.qml | 76 ++++++++----------- plasmoid/package/contents/ui/IconLabel.qml | 5 +- .../package/contents/ui/StatisticsView.qml | 6 +- plasmoid/package/contents/ui/TinyButton.qml | 16 +++- plasmoid/package/contents/ui/ToolButton.qml | 32 ++++++++ plasmoid/package/contents/ui/main.qml | 1 + 14 files changed, 110 insertions(+), 59 deletions(-) create mode 100644 plasmoid/package/contents/ui/ToolButton.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index 8448acb..6f73129 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ else() if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${BUNDLED_QT_FORK_AWESOME_PATH}" OR IS_DIRECTORY "${BUNDLED_QT_FORK_AWESOME_PATH}") add_subdirectory("${BUNDLED_QT_FORK_AWESOME_PATH}" qtforkawesome) set(${NAMESPACE_PREFIX}qtforkawesome${CONFIGURATION_PACKAGE_SUFFIX_QTFORKAWESOME}_DIR "${CMAKE_CURRENT_BINARY_DIR}/qtforkawesome/qtforkawesome") + set(${NAMESPACE_PREFIX}qtquickforkawesome${CONFIGURATION_PACKAGE_SUFFIX_QTFORKAWESOME}_DIR "${CMAKE_CURRENT_BINARY_DIR}/qtforkawesome/qtquickforkawesome") set(${NAMESPACE_PREFIX}qtforkawesomeiconengine${CONFIGURATION_PACKAGE_SUFFIX_QTFORKAWESOME}_DIR "${CMAKE_CURRENT_BINARY_DIR}/qtforkawesome/iconengineplugin") else() message(FATAL_ERROR "Specified directory for qtforkawesome sources \"${BUNDLED_QT_FORK_AWESOME_PATH}\" does not exist.") diff --git a/plasmoid/CMakeLists.txt b/plasmoid/CMakeLists.txt index 12e0d26..fd2263b 100644 --- a/plasmoid/CMakeLists.txt +++ b/plasmoid/CMakeLists.txt @@ -22,6 +22,7 @@ set(PLASMOID_FILES package/contents/ui/DetailItem.qml package/contents/ui/ToolTipTrigger.qml package/contents/ui/ToolTipView.qml + package/contents/ui/ToolButton.qml package/contents/ui/TinyButton.qml package/contents/ui/IconLabel.qml package/contents/ui/StatisticsView.qml diff --git a/plasmoid/lib/CMakeLists.txt b/plasmoid/lib/CMakeLists.txt index efcbdc9..b3c521a 100644 --- a/plasmoid/lib/CMakeLists.txt +++ b/plasmoid/lib/CMakeLists.txt @@ -11,6 +11,10 @@ set(TS_FILES ../translations/${META_PROJECT_NAME}_de_DE.ts ../translations/${MET find_package(${PACKAGE_NAMESPACE_PREFIX}qtutilities${CONFIGURATION_PACKAGE_SUFFIX_QTUTILITIES} 6.2.0 REQUIRED) use_qt_utilities() +# find qtforkawesomequickimageprovider +find_package(${PACKAGE_NAMESPACE_PREFIX}qtquickforkawesome${CONFIGURATION_PACKAGE_SUFFIX_QTFORKAWESOME} 0.0.1 REQUIRED) +use_qt_quick_fork_awesome() + # check whether qtutilities supports DBus notifications get_target_property(QT_UTILITIES_COMPILE_DEFINITIONS ${QT_UTILITIES_LIB} INTERFACE_COMPILE_DEFINITIONS) list(FIND QT_UTILITIES_COMPILE_DEFINITIONS QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS) diff --git a/plasmoid/lib/syncthingapplet.cpp b/plasmoid/lib/syncthingapplet.cpp index 00e2954..e84b474 100644 --- a/plasmoid/lib/syncthingapplet.cpp +++ b/plasmoid/lib/syncthingapplet.cpp @@ -20,6 +20,7 @@ #include "resources/qtconfig.h" #include +#include #include #include @@ -39,8 +40,6 @@ #include #include -#include - using namespace std; using namespace Data; using namespace Plasma; @@ -135,6 +134,15 @@ void SyncthingApplet::init() m_initialized = true; } +void SyncthingApplet::initEngine(QObject *object) +{ + auto engine = qmlEngine(object); + if (!engine) { + return; + } + engine->addImageProvider(QStringLiteral("fa"), new QtForkAwesome::QuickImageProvider(IconManager::instance().forkAwesomeRenderer())); +} + QIcon SyncthingApplet::statusIcon() const { return m_statusInfo.statusIcon(); diff --git a/plasmoid/lib/syncthingapplet.h b/plasmoid/lib/syncthingapplet.h index 2707453..705adfe 100644 --- a/plasmoid/lib/syncthingapplet.h +++ b/plasmoid/lib/syncthingapplet.h @@ -111,6 +111,7 @@ public: public Q_SLOTS: void init() override; + void initEngine(QObject *object); void showSettingsDlg(); void showWebUI(); void showLog(); diff --git a/plasmoid/package/contents/ui/DevicesPage.qml b/plasmoid/package/contents/ui/DevicesPage.qml index 4b1ab05..d471529 100644 --- a/plasmoid/package/contents/ui/DevicesPage.qml +++ b/plasmoid/package/contents/ui/DevicesPage.qml @@ -60,7 +60,7 @@ Item { } TinyButton { id: resumePauseButton - icon.name: paused ? "media-playback-start" : "media-playback-pause" + icon.source: paused ? "image://fa/play" : "image://fa/pause" tooltip: paused ? qsTr("Resume") : qsTr("Pause") enabled: !isOwnDevice onClicked: { diff --git a/plasmoid/package/contents/ui/DirectoriesPage.qml b/plasmoid/package/contents/ui/DirectoriesPage.qml index 4d9307a..f437bca 100644 --- a/plasmoid/package/contents/ui/DirectoriesPage.qml +++ b/plasmoid/package/contents/ui/DirectoriesPage.qml @@ -67,7 +67,7 @@ ColumnLayout { } TinyButton { id: errorsButton - icon.name: "data-error" + icon.source: "image://fa/exclamation-triangle" tooltip: qsTr("Show errors") visible: pullErrorCount > 0 onClicked: { @@ -78,7 +78,7 @@ ColumnLayout { } TinyButton { id: rescanButton - icon.name: "view-refresh" + icon.source: "image://fa/refresh" tooltip: qsTr("Rescan") enabled: !paused onClicked: plasmoid.nativeInterface.connection.rescan( @@ -86,7 +86,7 @@ ColumnLayout { } TinyButton { id: resumePauseButton - icon.name: paused ? "media-playback-start" : "media-playback-pause" + icon.source: paused ? "image://fa/play" : "image://fa/pause" tooltip: paused ? qsTr("Resume") : qsTr("Pause") onClicked: { paused ? plasmoid.nativeInterface.connection.resumeDirectories( @@ -96,7 +96,7 @@ ColumnLayout { } TinyButton { id: openButton - icon.name: "folder" + icon.source: "image://fa/folder" tooltip: qsTr("Open in file browser") onClicked: { Qt.openUrlExternally(path) diff --git a/plasmoid/package/contents/ui/DownloadsPage.qml b/plasmoid/package/contents/ui/DownloadsPage.qml index 9075525..3013a8f 100644 --- a/plasmoid/package/contents/ui/DownloadsPage.qml +++ b/plasmoid/package/contents/ui/DownloadsPage.qml @@ -63,7 +63,7 @@ Item { } TinyButton { id: openButton - icon.name: "folder" + icon.source: "image://fa/folder" tooltip: qsTr("Open in file browser") enabled: path !== undefined onClicked: { @@ -119,7 +119,7 @@ Item { } } TinyButton { - icon.name: "folder" + icon.source: "image://fa/folder" tooltip: qsTr("Open in file browser") onClicked: { Qt.openUrlExternally(path + "/..") diff --git a/plasmoid/package/contents/ui/FullRepresentation.qml b/plasmoid/package/contents/ui/FullRepresentation.qml index 8f7b01c..51fa74e 100644 --- a/plasmoid/package/contents/ui/FullRepresentation.qml +++ b/plasmoid/package/contents/ui/FullRepresentation.qml @@ -182,7 +182,7 @@ ColumnLayout { id: toolBar Layout.fillWidth: true - PlasmaComponents3.ToolButton { + ToolButton { id: connectButton states: [ State { @@ -190,7 +190,7 @@ ColumnLayout { PropertyChanges { target: connectButton text: qsTr("Connect") - icon.name: "view-refresh" + icon.source: "image://fa/refresh" visible: true } }, @@ -206,7 +206,7 @@ ColumnLayout { PropertyChanges { target: connectButton text: qsTr("Resume") - icon.name: "media-playback-start" + icon.source: "image://fa/play" visible: true } }, @@ -215,7 +215,7 @@ ColumnLayout { PropertyChanges { target: connectButton text: qsTr("Pause") - icon.name: "media-playback-pause" + icon.source: "image://fa/pause" visible: true } } @@ -256,7 +256,7 @@ ColumnLayout { onActivated: connectButton.clicked() } } - PlasmaComponents3.ToolButton { + ToolButton { id: startStopButton states: [ State { @@ -265,7 +265,7 @@ ColumnLayout { target: startStopButton visible: true text: qsTr("Stop") - icon.name: "process-stop" + icon.source: "image://fa/stop" } PropertyChanges { target: startStopToolTip @@ -279,7 +279,7 @@ ColumnLayout { target: startStopButton visible: true text: qsTr("Start") - icon.name: "system-run" + icon.source: "image://fa/play" } PropertyChanges { target: startStopToolTip @@ -345,8 +345,8 @@ ColumnLayout { } } } - PlasmaComponents3.ToolButton { - icon.name: "help-about" + ToolButton { + icon.source: "image://fa/info" PlasmaComponents3.ToolTip { text: qsTr("About Syncthing Tray") } @@ -355,15 +355,9 @@ ColumnLayout { plasmoid.expanded = false } } - PlasmaComponents3.ToolButton { + ToolButton { id: showOwnIdButton - // use PlasmaCore.IconItem for the icon because I wouldn't know how to show the QIcon otherwise - contentItem: PlasmaCore.IconItem { - source: plasmoid.nativeInterface.loadForkAwesomeIcon("qrcode", 64) - } - // set preferred size so the tool button is displayed consistently with the previous one despite using PlasmaCore.IconItem - Layout.preferredWidth: settingsButton.width - Layout.preferredHeight: settingsButton.height + icon.source: "image://fa/qrcode" onClicked: { plasmoid.nativeInterface.showOwnDeviceId() plasmoid.expanded = false @@ -376,9 +370,9 @@ ColumnLayout { onActivated: showOwnIdButton.clicked() } } - PlasmaComponents3.ToolButton { + ToolButton { id: showLogButton - icon.name: "text-x-generic" + icon.source: "image://fa/file-code-o" onClicked: { plasmoid.nativeInterface.showLog() plasmoid.expanded = false @@ -391,9 +385,9 @@ ColumnLayout { onActivated: showLogButton.clicked() } } - PlasmaComponents3.ToolButton { + ToolButton { id: rescanAllDirsButton - icon.name: "folder-sync" + icon.source: "image://fa/search" onClicked: plasmoid.nativeInterface.connection.rescanAllDirs() PlasmaComponents3.ToolTip { text: qsTr("Rescan all directories") @@ -403,9 +397,9 @@ ColumnLayout { onActivated: rescanAllDirsButton.clicked() } } - PlasmaComponents3.ToolButton { + ToolButton { id: settingsButton - icon.name: "preferences-other" + icon.source: "image://fa/cogs" onClicked: { plasmoid.nativeInterface.showSettingsDlg() plasmoid.expanded = false @@ -418,15 +412,9 @@ ColumnLayout { onActivated: settingsButton.clicked() } } - PlasmaComponents3.ToolButton { + ToolButton { id: webUIButton - // use PlasmaCore.IconItem for the icon because I wouldn't know how to show the QIcon otherwise - contentItem: PlasmaCore.IconItem { - source: plasmoid.nativeInterface.loadForkAwesomeIcon("syncthing") - } - // set preferred size so the tool button is displayed consistently with the previous one despite using PlasmaCore.IconItem - Layout.preferredWidth: settingsButton.width - Layout.preferredHeight: settingsButton.height + icon.source: "image://fa/syncthing" onClicked: { plasmoid.nativeInterface.showWebUI() plasmoid.expanded = false @@ -472,10 +460,12 @@ ColumnLayout { rowSpacing: 1 columnSpacing: 4 - PlasmaCore.IconItem { + Image { Layout.preferredWidth: 16 Layout.preferredHeight: 16 - source: "globe" + height: 16 + fillMode: Image.PreserveAspectFit + source: "image://fa/globe" } StatisticsView { Layout.leftMargin: 4 @@ -485,17 +475,18 @@ ColumnLayout { IconLabel { Layout.leftMargin: 10 - iconSource: plasmoid.nativeInterface.loadForkAwesomeIcon( - "cloud-download") + iconSource: "image://fa/cloud-download" iconOpacity: plasmoid.nativeInterface.hasIncomingTraffic ? 1.0 : 0.5 text: plasmoid.nativeInterface.incomingTraffic tooltip: qsTr("Global incoming traffic") } - PlasmaCore.IconItem { + Image { Layout.preferredWidth: 16 Layout.preferredHeight: 16 - source: "user-home-symbolic" + height: 16 + fillMode: Image.PreserveAspectFit + source: "image://fa/home" } StatisticsView { Layout.leftMargin: 4 @@ -505,8 +496,7 @@ ColumnLayout { IconLabel { Layout.leftMargin: 10 - iconSource: plasmoid.nativeInterface.loadForkAwesomeIcon( - "cloud-upload") + iconSource: "image://fa/cloud-upload" iconOpacity: plasmoid.nativeInterface.hasOutgoingTraffic ? 1.0 : 0.5 text: plasmoid.nativeInterface.outgoingTraffic tooltip: qsTr("Global outgoing traffic") @@ -540,22 +530,22 @@ ColumnLayout { PlasmaComponents.TabButton { id: dirsTabButton - iconSource: "folder-symbolic" + iconSource: plasmoid.nativeInterface.loadForkAwesomeIcon("folder") tab: dirsPage } PlasmaComponents.TabButton { id: devsTabButton - iconSource: "network-server-symbolic" + iconSource: plasmoid.nativeInterface.loadForkAwesomeIcon("sitemap") tab: devicesPage } PlasmaComponents.TabButton { id: downloadsTabButton - iconSource: "folder-download-symbolic" + iconSource: plasmoid.nativeInterface.loadForkAwesomeIcon("download") tab: downloadsPage } PlasmaComponents.TabButton { id: recentChangesTabButton - iconSource: "document-open-recent-symbolic" + iconSource: plasmoid.nativeInterface.loadForkAwesomeIcon("history") tab: recentChangesPage } } diff --git a/plasmoid/package/contents/ui/IconLabel.qml b/plasmoid/package/contents/ui/IconLabel.qml index 969adef..81f8821 100644 --- a/plasmoid/package/contents/ui/IconLabel.qml +++ b/plasmoid/package/contents/ui/IconLabel.qml @@ -16,11 +16,12 @@ Item { RowLayout { id: layout - PlasmaCore.IconItem { + Image { id: iconItem Layout.preferredWidth: 16 Layout.preferredHeight: 16 - opacity: 0.7 + height: 16 + fillMode: Image.PreserveAspectFit } PlasmaComponents3.Label { id: label diff --git a/plasmoid/package/contents/ui/StatisticsView.qml b/plasmoid/package/contents/ui/StatisticsView.qml index 8d9e8dd..c4cf5ef 100644 --- a/plasmoid/package/contents/ui/StatisticsView.qml +++ b/plasmoid/package/contents/ui/StatisticsView.qml @@ -7,17 +7,17 @@ RowLayout { property string context: "?" IconLabel { - iconSource: plasmoid.nativeInterface.loadForkAwesomeIcon("file-o") + iconSource: "image://fa/file-o" text: statistics.files !== undefined ? statistics.files : "?" tooltip: context + qsTr(" files") } IconLabel { - iconSource: plasmoid.nativeInterface.loadForkAwesomeIcon("folder-o") + iconSource: "image://fa/folder-o" text: statistics.dirs !== undefined ? statistics.dirs : "?" tooltip: context + qsTr(" directories") } IconLabel { - iconSource: plasmoid.nativeInterface.loadForkAwesomeIcon("hdd-o") + iconSource: "image://fa/hdd-o" text: statistics.bytes !== undefined ? plasmoid.nativeInterface.formatFileSize( statistics.bytes) : "?" tooltip: context + qsTr(" size") diff --git a/plasmoid/package/contents/ui/TinyButton.qml b/plasmoid/package/contents/ui/TinyButton.qml index 6d14bff..292383b 100644 --- a/plasmoid/package/contents/ui/TinyButton.qml +++ b/plasmoid/package/contents/ui/TinyButton.qml @@ -1,10 +1,22 @@ +import QtQuick 2.8 +import QtQuick.Layouts 1.1 import org.kde.plasma.components 3.0 as PlasmaComponents3 PlasmaComponents3.ToolButton { + id: root + property alias tooltip: tooltip.text - icon.width: units.iconSizes.small - icon.height: units.iconSizes.small + + Layout.fillHeight: true + Layout.preferredWidth: units.iconSizes.smallMedium + Layout.preferredHeight: units.iconSizes.smallMedium + PlasmaComponents3.ToolTip { id: tooltip } + contentItem: Image { + source: root.icon.source + height: parent.height + fillMode: Image.PreserveAspectFit + } } diff --git a/plasmoid/package/contents/ui/ToolButton.qml b/plasmoid/package/contents/ui/ToolButton.qml new file mode 100644 index 0000000..f8a39cb --- /dev/null +++ b/plasmoid/package/contents/ui/ToolButton.qml @@ -0,0 +1,32 @@ +import QtQuick 2.8 +import QtQuick.Layouts 1.1 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 3.0 as PlasmaComponents3 + +PlasmaComponents3.ToolButton { + id: root + Layout.fillHeight: true + Layout.preferredHeight: units.iconSizes.smallMedium + contentItem: Grid { + columns: 2 + columnSpacing: label.visible ? units.smallSpacing : 0 + verticalItemAlignment: Grid.AlignVCenter + PlasmaCore.ColorScope.inherit: true + Image { + source: root.icon.source + height: parent.height + fillMode: Image.PreserveAspectFit + } + PlasmaComponents3.Label { + id: label + visible: text.length > 0 + text: root.text + font: root.parent.font + color: PlasmaCore.ColorScope.textColor + elide: Text.ElideRight + Layout.fillWidth: true + Layout.fillHeight: true + } + } +} + diff --git a/plasmoid/package/contents/ui/main.qml b/plasmoid/package/contents/ui/main.qml index e7f87e1..75868ec 100644 --- a/plasmoid/package/contents/ui/main.qml +++ b/plasmoid/package/contents/ui/main.qml @@ -62,6 +62,7 @@ Item { } Component.onCompleted: { + plasmoid.nativeInterface.initEngine(this) plasmoid.removeAction("configure") plasmoid.setAction( "showWebUI", qsTr("Open Syncthing"),