Make the Plasmoid's Fork Awesome icon coloring react to theme changes
* Make the Fork Awesome image provider URL a property and change its value if the Plasmoid's theme changes to cause Qt Quick to redraw images * Turn caching of Image objects off so Qt Quick actually fetches the images again from the image provider * Change the URL only back after returning to the event loop; otherwise Qt Quick apparently does not react to the property change * See https://github.com/Martchus/syncthingtray/issues/126
This commit is contained in:
parent
d260831b55
commit
8ec133e62d
|
@ -66,7 +66,7 @@ static inline QPalette paletteFromTheme(const Plasma::Theme &theme)
|
|||
|
||||
SyncthingApplet::SyncthingApplet(QObject *parent, const QVariantList &data)
|
||||
: Applet(parent, data)
|
||||
, m_palette(paletteFromTheme(m_theme))
|
||||
, m_faUrl(QStringLiteral("image://fa/"))
|
||||
, m_iconManager(IconManager::instance(&m_palette))
|
||||
, m_aboutDlg(nullptr)
|
||||
, m_connection()
|
||||
|
@ -555,10 +555,17 @@ void Plasmoid::SyncthingApplet::handleImageProviderDestroyed()
|
|||
|
||||
void SyncthingApplet::handleThemeChanged()
|
||||
{
|
||||
IconManager::instance().setPalette(paletteFromTheme(m_theme));
|
||||
if (m_imageProvider) {
|
||||
m_imageProvider->setDefaultColor(m_theme.color(Plasma::Theme::TextColor, Plasma::Theme::NormalColorGroup));
|
||||
}
|
||||
// unset the fa-URL to provoke Qt Quick to reload the images
|
||||
emit faUrlChanged(m_faUrl = QString());
|
||||
|
||||
// return to the event loop before setting the new theme color; otherwise Qt Quick does not update the images
|
||||
QTimer::singleShot(0, this, [this] {
|
||||
IconManager::instance().setPalette(paletteFromTheme(m_theme));
|
||||
if (m_imageProvider) {
|
||||
m_imageProvider->setDefaultColor(m_theme.color(Plasma::Theme::TextColor, Plasma::Theme::NormalColorGroup));
|
||||
}
|
||||
emit faUrlChanged(m_faUrl = QStringLiteral("image://fa/"));
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
|
|
|
@ -77,6 +77,7 @@ class SyncthingApplet : public Plasma::Applet {
|
|||
Q_PROPERTY(bool notificationsAvailable READ areNotificationsAvailable NOTIFY notificationsAvailableChanged)
|
||||
Q_PROPERTY(bool passive READ isPassive NOTIFY passiveChanged)
|
||||
Q_PROPERTY(QList<QtUtilities::ChecklistItem> passiveStates READ passiveStates WRITE setPassiveStates)
|
||||
Q_PROPERTY(QString faUrl READ faUrl NOTIFY faUrlChanged)
|
||||
|
||||
public:
|
||||
SyncthingApplet(QObject *parent, const QVariantList &data);
|
||||
|
@ -117,6 +118,7 @@ public:
|
|||
bool isPassive() const;
|
||||
const QList<QtUtilities::ChecklistItem> &passiveStates() const;
|
||||
void setPassiveStates(const QList<QtUtilities::ChecklistItem> &passiveStates);
|
||||
QString faUrl();
|
||||
|
||||
public Q_SLOTS:
|
||||
void init() override;
|
||||
|
@ -160,6 +162,7 @@ Q_SIGNALS:
|
|||
void sizeChanged(const QSize &size);
|
||||
void notificationsAvailableChanged(bool notificationsAvailable);
|
||||
void passiveChanged(bool passive);
|
||||
void faUrlChanged(const QString &faUrl);
|
||||
|
||||
private Q_SLOTS:
|
||||
void handleSettingsChanged();
|
||||
|
@ -184,6 +187,7 @@ private Q_SLOTS:
|
|||
|
||||
private:
|
||||
Plasma::Theme m_theme;
|
||||
QString m_faUrl;
|
||||
QPalette m_palette;
|
||||
Data::IconManager &m_iconManager;
|
||||
QtUtilities::AboutDialog *m_aboutDlg;
|
||||
|
@ -310,6 +314,11 @@ inline const QList<QtUtilities::ChecklistItem> &SyncthingApplet::passiveStates()
|
|||
return m_passiveSelectionModel.items();
|
||||
}
|
||||
|
||||
inline QString SyncthingApplet::faUrl()
|
||||
{
|
||||
return m_faUrl;
|
||||
}
|
||||
|
||||
inline void SyncthingApplet::setPassive(bool passive)
|
||||
{
|
||||
if (passive != isPassive()) {
|
||||
|
|
|
@ -59,7 +59,8 @@ Item {
|
|||
}
|
||||
TinyButton {
|
||||
id: resumePauseButton
|
||||
icon.source: paused ? "image://fa/play" : "image://fa/pause"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + (paused ? "play" : "pause")
|
||||
icon.cache: false
|
||||
tooltip: paused ? qsTr("Resume") : qsTr("Pause")
|
||||
enabled: !isOwnDevice
|
||||
onClicked: {
|
||||
|
|
|
@ -77,7 +77,7 @@ ColumnLayout {
|
|||
}
|
||||
TinyButton {
|
||||
id: errorsButton
|
||||
icon.source: "image://fa/exclamation-triangle"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "exclamation-triangle"
|
||||
tooltip: qsTr("Show errors")
|
||||
visible: pullErrorCount > 0
|
||||
onClicked: {
|
||||
|
@ -88,7 +88,7 @@ ColumnLayout {
|
|||
}
|
||||
TinyButton {
|
||||
id: rescanButton
|
||||
icon.source: "image://fa/refresh"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "refresh"
|
||||
tooltip: qsTr("Rescan")
|
||||
enabled: !paused
|
||||
onClicked: plasmoid.nativeInterface.connection.rescan(
|
||||
|
@ -96,7 +96,7 @@ ColumnLayout {
|
|||
}
|
||||
TinyButton {
|
||||
id: resumePauseButton
|
||||
icon.source: paused ? "image://fa/play" : "image://fa/pause"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + (paused ? "play" : "pause")
|
||||
tooltip: paused ? qsTr("Resume") : qsTr("Pause")
|
||||
onClicked: {
|
||||
paused ? plasmoid.nativeInterface.connection.resumeDirectories(
|
||||
|
@ -106,7 +106,7 @@ ColumnLayout {
|
|||
}
|
||||
TinyButton {
|
||||
id: openButton
|
||||
icon.source: "image://fa/folder"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "folder"
|
||||
tooltip: qsTr("Open in file browser")
|
||||
onClicked: {
|
||||
Qt.openUrlExternally(path)
|
||||
|
|
|
@ -62,7 +62,7 @@ Item {
|
|||
}
|
||||
TinyButton {
|
||||
id: openButton
|
||||
icon.source: "image://fa/folder"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "folder"
|
||||
tooltip: qsTr("Open in file browser")
|
||||
enabled: path !== undefined
|
||||
onClicked: {
|
||||
|
@ -118,7 +118,7 @@ Item {
|
|||
}
|
||||
}
|
||||
TinyButton {
|
||||
icon.source: "image://fa/folder"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "folder"
|
||||
tooltip: qsTr("Open in file browser")
|
||||
onClicked: {
|
||||
Qt.openUrlExternally(path + "/..")
|
||||
|
|
|
@ -27,25 +27,25 @@ PlasmaComponents3.Page {
|
|||
TabButton {
|
||||
id: dirsTabButton
|
||||
text: qsTr("Directories")
|
||||
icon.source: "image://fa/folder"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "folder"
|
||||
width: tabBar.buttonWidth
|
||||
}
|
||||
TabButton {
|
||||
id: devsTabButton
|
||||
text: qsTr("Devices")
|
||||
icon.source: "image://fa/sitemap"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "sitemap"
|
||||
width: tabBar.buttonWidth
|
||||
}
|
||||
TabButton {
|
||||
id: downloadsTabButton
|
||||
text: qsTr("Downloads")
|
||||
icon.source: "image://fa/download"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "download"
|
||||
width: tabBar.buttonWidth
|
||||
}
|
||||
TabButton {
|
||||
id: recentChangesTabButton
|
||||
text: qsTr("History")
|
||||
icon.source: "image://fa/history"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "history"
|
||||
width: tabBar.buttonWidth
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ PlasmaComponents3.Page {
|
|||
id: searchButton
|
||||
anchors.right: mainLayout.right
|
||||
anchors.verticalCenter: infoLayout.verticalCenter
|
||||
icon.source: "image://fa/search"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "search"
|
||||
width: PlasmaCore.Units.iconSizes.smallMedium
|
||||
height: width
|
||||
enabled: tabBar.currentIndex === 0
|
||||
|
@ -232,7 +232,8 @@ PlasmaComponents3.Page {
|
|||
Layout.preferredHeight: 16
|
||||
height: 16
|
||||
fillMode: Image.PreserveAspectFit
|
||||
source: "image://fa/globe"
|
||||
source: plasmoid.nativeInterface.faUrl + "globe"
|
||||
cache: false
|
||||
}
|
||||
StatisticsView {
|
||||
Layout.leftMargin: 4
|
||||
|
@ -241,7 +242,7 @@ PlasmaComponents3.Page {
|
|||
}
|
||||
IconLabel {
|
||||
Layout.leftMargin: 5
|
||||
iconSource: "image://fa/cloud-download"
|
||||
iconSource: plasmoid.nativeInterface.faUrl + "cloud-download"
|
||||
iconOpacity: plasmoid.nativeInterface.hasIncomingTraffic ? 1.0 : 0.5
|
||||
text: plasmoid.nativeInterface.incomingTraffic
|
||||
tooltip: qsTr("Global incoming traffic")
|
||||
|
@ -256,7 +257,8 @@ PlasmaComponents3.Page {
|
|||
Layout.preferredHeight: 16
|
||||
height: 16
|
||||
fillMode: Image.PreserveAspectFit
|
||||
source: "image://fa/home"
|
||||
source: plasmoid.nativeInterface.faUrl + "home"
|
||||
cache: false
|
||||
}
|
||||
StatisticsView {
|
||||
Layout.leftMargin: 4
|
||||
|
@ -265,7 +267,7 @@ PlasmaComponents3.Page {
|
|||
}
|
||||
IconLabel {
|
||||
Layout.leftMargin: 5
|
||||
iconSource: "image://fa/cloud-upload"
|
||||
iconSource: plasmoid.nativeInterface.faUrl + "cloud-upload"
|
||||
iconOpacity: plasmoid.nativeInterface.hasOutgoingTraffic ? 1.0 : 0.5
|
||||
text: plasmoid.nativeInterface.outgoingTraffic
|
||||
tooltip: qsTr("Global outgoing traffic")
|
||||
|
|
|
@ -21,6 +21,7 @@ Item {
|
|||
Layout.preferredWidth: 16
|
||||
Layout.preferredHeight: 16
|
||||
height: 16
|
||||
cache: false
|
||||
fillMode: Image.PreserveAspectFit
|
||||
}
|
||||
PlasmaComponents3.Label {
|
||||
|
|
|
@ -46,7 +46,7 @@ Item {
|
|||
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
||||
height: parent.height
|
||||
fillMode: Image.PreserveAspectFit
|
||||
source: "image://fa/calendar"
|
||||
source: plasmoid.nativeInterface.faUrl + "calendar"
|
||||
}
|
||||
PlasmaComponents3.Label {
|
||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
||||
|
@ -62,7 +62,7 @@ Item {
|
|||
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
||||
height: parent.height
|
||||
fillMode: Image.PreserveAspectFit
|
||||
source: "image://fa/qrcode"
|
||||
source: plasmoid.nativeInterface.faUrl + "qrcode"
|
||||
}
|
||||
PlasmaComponents3.Label {
|
||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
||||
|
@ -78,7 +78,7 @@ Item {
|
|||
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
||||
height: parent.height
|
||||
fillMode: Image.PreserveAspectFit
|
||||
source: itemType === "file" ? "image://fa/file-o" : "image://fa/folder-o"
|
||||
source: plasmoid.nativeInterface.faUrl + (itemType === "file" ? "file-o" : "folder-o")
|
||||
}
|
||||
PlasmaComponents3.Label {
|
||||
text: directoryId + ": "
|
||||
|
|
|
@ -7,17 +7,17 @@ RowLayout {
|
|||
property string context: "?"
|
||||
|
||||
IconLabel {
|
||||
iconSource: "image://fa/file-o"
|
||||
iconSource: plasmoid.nativeInterface.faUrl + "file-o"
|
||||
text: statistics.files !== undefined ? statistics.files : "?"
|
||||
tooltip: context + qsTr(" files")
|
||||
}
|
||||
IconLabel {
|
||||
iconSource: "image://fa/folder-o"
|
||||
iconSource: plasmoid.nativeInterface.faUrl + "folder-o"
|
||||
text: statistics.dirs !== undefined ? statistics.dirs : "?"
|
||||
tooltip: context + qsTr(" directories")
|
||||
}
|
||||
IconLabel {
|
||||
iconSource: "image://fa/hdd-o"
|
||||
iconSource: plasmoid.nativeInterface.faUrl + "hdd-o"
|
||||
text: statistics.bytes !== undefined ? plasmoid.nativeInterface.formatFileSize(
|
||||
statistics.bytes) : "?"
|
||||
tooltip: context + qsTr(" size")
|
||||
|
|
|
@ -17,6 +17,7 @@ PlasmaComponents3.TabButton {
|
|||
id: image
|
||||
Layout.preferredHeight: height
|
||||
source: root.icon.source
|
||||
cache: false
|
||||
height: units.iconSizes.small
|
||||
fillMode: Image.PreserveAspectFit
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ PlasmaComponents3.ToolButton {
|
|||
}
|
||||
contentItem: Image {
|
||||
source: root.icon.source
|
||||
cache: false
|
||||
height: parent.height
|
||||
fillMode: Image.PreserveAspectFit
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ RowLayout {
|
|||
PropertyChanges {
|
||||
target: connectButton
|
||||
text: qsTr("Connect")
|
||||
icon.source: "image://fa/refresh"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "refresh"
|
||||
visible: true
|
||||
}
|
||||
},
|
||||
|
@ -39,7 +39,7 @@ RowLayout {
|
|||
PropertyChanges {
|
||||
target: connectButton
|
||||
text: qsTr("Resume")
|
||||
icon.source: "image://fa/play"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "play"
|
||||
visible: true
|
||||
}
|
||||
},
|
||||
|
@ -48,7 +48,7 @@ RowLayout {
|
|||
PropertyChanges {
|
||||
target: connectButton
|
||||
text: qsTr("Pause")
|
||||
icon.source: "image://fa/pause"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "pause"
|
||||
visible: true
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ RowLayout {
|
|||
target: startStopButton
|
||||
visible: true
|
||||
text: qsTr("Stop")
|
||||
icon.source: "image://fa/stop"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "stop"
|
||||
}
|
||||
PropertyChanges {
|
||||
target: startStopToolTip
|
||||
|
@ -111,7 +111,7 @@ RowLayout {
|
|||
target: startStopButton
|
||||
visible: true
|
||||
text: qsTr("Start")
|
||||
icon.source: "image://fa/play"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "play"
|
||||
}
|
||||
PropertyChanges {
|
||||
target: startStopToolTip
|
||||
|
@ -178,7 +178,7 @@ RowLayout {
|
|||
}
|
||||
}
|
||||
ToolButton {
|
||||
icon.source: "image://fa/info"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "info"
|
||||
visible: showExtraButtons
|
||||
onClicked: {
|
||||
plasmoid.nativeInterface.showAboutDialog()
|
||||
|
@ -190,7 +190,7 @@ RowLayout {
|
|||
}
|
||||
ToolButton {
|
||||
id: showOwnIdButton
|
||||
icon.source: "image://fa/qrcode"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "qrcode"
|
||||
visible: showExtraButtons
|
||||
onClicked: {
|
||||
plasmoid.nativeInterface.showOwnDeviceId()
|
||||
|
@ -206,7 +206,7 @@ RowLayout {
|
|||
}
|
||||
ToolButton {
|
||||
id: showLogButton
|
||||
icon.source: "image://fa/file-text"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "file-text"
|
||||
visible: showExtraButtons
|
||||
onClicked: {
|
||||
plasmoid.nativeInterface.showLog()
|
||||
|
@ -222,7 +222,7 @@ RowLayout {
|
|||
}
|
||||
ToolButton {
|
||||
id: rescanAllDirsButton
|
||||
icon.source: "image://fa/refresh"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "refresh"
|
||||
onClicked: plasmoid.nativeInterface.connection.rescanAllDirs()
|
||||
PlasmaComponents3.ToolTip {
|
||||
text: qsTr("Rescan all directories")
|
||||
|
@ -234,7 +234,7 @@ RowLayout {
|
|||
}
|
||||
ToolButton {
|
||||
id: settingsButton
|
||||
icon.source: "image://fa/cog"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "cog"
|
||||
visible: showExtraButtons
|
||||
onClicked: {
|
||||
plasmoid.nativeInterface.showSettingsDlg()
|
||||
|
@ -250,7 +250,7 @@ RowLayout {
|
|||
}
|
||||
ToolButton {
|
||||
id: webUIButton
|
||||
icon.source: "image://fa/syncthing"
|
||||
icon.source: plasmoid.nativeInterface.faUrl + "syncthing"
|
||||
onClicked: {
|
||||
plasmoid.nativeInterface.showWebUI()
|
||||
plasmoid.expanded = false
|
||||
|
|
|
@ -13,6 +13,7 @@ PlasmaComponents3.ToolButton {
|
|||
PlasmaCore.ColorScope.inherit: true
|
||||
Image {
|
||||
source: root.icon.source
|
||||
cache: false
|
||||
height: parent.height
|
||||
fillMode: Image.PreserveAspectFit
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue