diff --git a/fileitemactionplugin/syncthingdiractions.cpp b/fileitemactionplugin/syncthingdiractions.cpp index bf5a55b..9701499 100644 --- a/fileitemactionplugin/syncthingdiractions.cpp +++ b/fileitemactionplugin/syncthingdiractions.cpp @@ -12,7 +12,8 @@ SyncthingDirActions::SyncthingDirActions(const SyncthingDir &dir, const Syncthin : QObject(parent) , m_dirId(dir.id) { - const auto &icons = !data || !data->isUsingBrightCustomColors() ? forkAwesomeIconsForLightTheme() : forkAwesomeIconsForDarkTheme(); + Q_UNUSED(data) + const auto &icons = commonForkAwesomeIcons(); m_infoAction.setSeparator(true); m_infoAction.setIcon(icons.folder); m_globalStatusAction.setIcon(icons.globe); diff --git a/model/syncthingdevicemodel.cpp b/model/syncthingdevicemodel.cpp index 3a7cd90..6827cf4 100644 --- a/model/syncthingdevicemodel.cpp +++ b/model/syncthingdevicemodel.cpp @@ -169,7 +169,7 @@ QVariant SyncthingDeviceModel::data(const QModelIndex &index, int role) const case DeviceDetailIcon: if (index.column() == 0) { // attribute icons - const auto &icons = m_brightColors ? forkAwesomeIconsForDarkTheme() : forkAwesomeIconsForLightTheme(); + const auto &icons = commonForkAwesomeIcons(); switch (index.row()) { case 0: return icons.hashtag; @@ -354,7 +354,12 @@ void SyncthingDeviceModel::devStatusChanged(const SyncthingDev &, int index) void SyncthingDeviceModel::handleStatusIconsChanged() { - emit dataChanged(index(0, 0), index(static_cast(m_devs.size()) - 1, 0), QVector({ Qt::DecorationRole })); + invalidateTopLevelIndicies(QVector({ Qt::DecorationRole })); +} + +void SyncthingDeviceModel::handleForkAwesomeIconsChanged() +{ + invalidateNestedIndicies(QVector({ Qt::DecorationRole, DeviceDetailIcon })); } QString SyncthingDeviceModel::devStatusString(const SyncthingDev &dev) diff --git a/model/syncthingdevicemodel.h b/model/syncthingdevicemodel.h index 550392f..2ebaa9a 100644 --- a/model/syncthingdevicemodel.h +++ b/model/syncthingdevicemodel.h @@ -43,6 +43,7 @@ public Q_SLOTS: private Q_SLOTS: void devStatusChanged(const SyncthingDev &, int index); void handleStatusIconsChanged() override; + void handleForkAwesomeIconsChanged() override; private: static QString devStatusString(const SyncthingDev &dev); diff --git a/model/syncthingdirectorymodel.cpp b/model/syncthingdirectorymodel.cpp index cb86bf6..98d610d 100644 --- a/model/syncthingdirectorymodel.cpp +++ b/model/syncthingdirectorymodel.cpp @@ -191,7 +191,7 @@ QVariant SyncthingDirectoryModel::data(const QModelIndex &index, int role) const case DirectoryDetailIcon: if (index.column() == 0) { // attribute icons - const auto &icons = m_brightColors ? forkAwesomeIconsForDarkTheme() : forkAwesomeIconsForLightTheme(); + const auto &icons = commonForkAwesomeIcons(); switch (row) { case 0: return icons.hashtag; @@ -445,7 +445,12 @@ void SyncthingDirectoryModel::handleNewConfigAvailable() void SyncthingDirectoryModel::handleStatusIconsChanged() { - emit dataChanged(index(0, 0), index(static_cast(m_dirs.size()) - 1, 0), QVector({ Qt::DecorationRole })); + invalidateTopLevelIndicies(QVector({ Qt::DecorationRole })); +} + +void SyncthingDirectoryModel::handleForkAwesomeIconsChanged() +{ + invalidateNestedIndicies(QVector({ Qt::DecorationRole, DirectoryDetailIcon })); } QString SyncthingDirectoryModel::dirStatusString(const SyncthingDir &dir) diff --git a/model/syncthingdirectorymodel.h b/model/syncthingdirectorymodel.h index ed60930..e66c8e5 100644 --- a/model/syncthingdirectorymodel.h +++ b/model/syncthingdirectorymodel.h @@ -46,6 +46,7 @@ private Q_SLOTS: void handleConfigInvalidated() override; void handleNewConfigAvailable() override; void handleStatusIconsChanged() override; + void handleForkAwesomeIconsChanged() override; private: static QString dirStatusString(const SyncthingDir &dir); diff --git a/model/syncthingicons.cpp b/model/syncthingicons.cpp index 9720ecb..5fec9b7 100644 --- a/model/syncthingicons.cpp +++ b/model/syncthingicons.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -301,9 +302,15 @@ ForkAwesomeIcons::ForkAwesomeIcons(QtForkAwesome::Renderer &renderer, const QCol IconManager::IconManager() : m_statusIcons() , m_trayIcons(m_statusIcons) - , m_forkAwesomeIconsForLightTheme(m_forkAwesomeRenderer, QColor(10, 10, 10), QSize(64, 64)) - , m_fontAwesomeIconsForDarkTheme(m_forkAwesomeRenderer, Qt::white, QSize(64, 64)) + , m_commonForkAwesomeIcons(m_forkAwesomeRenderer, QGuiApplication::palette().color(QPalette::Normal, QPalette::Text), QSize(64, 64)) { + QObject::connect(qGuiApp, &QGuiApplication::paletteChanged, this, &IconManager::handlePaletteChanged); +} + +void IconManager::handlePaletteChanged(const QPalette &pal) +{ + emit forkAwesomeIconsChanged( + m_commonForkAwesomeIcons = ForkAwesomeIcons(m_forkAwesomeRenderer, pal.color(QPalette::Normal, QPalette::Text), QSize(64, 64))); } IconManager &IconManager::instance() diff --git a/model/syncthingicons.h b/model/syncthingicons.h index b4561b1..ba91008 100644 --- a/model/syncthingicons.h +++ b/model/syncthingicons.h @@ -11,6 +11,7 @@ #include QT_FORWARD_DECLARE_CLASS(QColor) +QT_FORWARD_DECLARE_CLASS(QPalette) namespace Data { @@ -148,11 +149,14 @@ public: const StatusIcons &statusIcons() const; const StatusIcons &trayIcons() const; QtForkAwesome::Renderer &forkAwesomeRenderer(); - const ForkAwesomeIcons &forkAwesomeIconsForLightTheme() const; - const ForkAwesomeIcons &forkAwesomeIconsForDarkTheme() const; + const ForkAwesomeIcons &commonForkAwesomeIcons() const; Q_SIGNALS: void statusIconsChanged(const StatusIcons &newStatusIcons, const StatusIcons &newTrayIcons); + void forkAwesomeIconsChanged(const ForkAwesomeIcons &newForkAwesomeIcons); + +private Q_SLOTS: + void handlePaletteChanged(const QPalette &pal); private: IconManager(); @@ -160,8 +164,7 @@ private: StatusIcons m_statusIcons; StatusIcons m_trayIcons; QtForkAwesome::Renderer m_forkAwesomeRenderer; - ForkAwesomeIcons m_forkAwesomeIconsForLightTheme; - ForkAwesomeIcons m_fontAwesomeIconsForDarkTheme; + ForkAwesomeIcons m_commonForkAwesomeIcons; }; inline void IconManager::applySettings(const StatusIconSettings *statusIconSettings, const StatusIconSettings *trayIconSettings) @@ -194,14 +197,9 @@ inline QtForkAwesome::Renderer &IconManager::forkAwesomeRenderer() return m_forkAwesomeRenderer; } -inline const ForkAwesomeIcons &IconManager::forkAwesomeIconsForLightTheme() const +inline const ForkAwesomeIcons &IconManager::commonForkAwesomeIcons() const { - return m_forkAwesomeIconsForLightTheme; -} - -inline const ForkAwesomeIcons &IconManager::forkAwesomeIconsForDarkTheme() const -{ - return m_fontAwesomeIconsForDarkTheme; + return m_commonForkAwesomeIcons; } inline const StatusIcons &statusIcons() @@ -214,14 +212,9 @@ inline const StatusIcons &trayIcons() return IconManager::instance().trayIcons(); } -inline const ForkAwesomeIcons &forkAwesomeIconsForLightTheme() +inline const ForkAwesomeIcons &commonForkAwesomeIcons() { - return IconManager::instance().forkAwesomeIconsForLightTheme(); -} - -inline const ForkAwesomeIcons &forkAwesomeIconsForDarkTheme() -{ - return IconManager::instance().forkAwesomeIconsForDarkTheme(); + return IconManager::instance().commonForkAwesomeIcons(); } } // namespace Data diff --git a/model/syncthingmodel.cpp b/model/syncthingmodel.cpp index aa1f701..918b539 100644 --- a/model/syncthingmodel.cpp +++ b/model/syncthingmodel.cpp @@ -12,7 +12,10 @@ SyncthingModel::SyncthingModel(SyncthingConnection &connection, QObject *parent) { connect(&m_connection, &SyncthingConnection::newConfig, this, &SyncthingModel::handleConfigInvalidated); connect(&m_connection, &SyncthingConnection::newConfigApplied, this, &SyncthingModel::handleNewConfigAvailable); - connect(&IconManager::instance(), &IconManager::statusIconsChanged, this, &SyncthingModel::handleStatusIconsChanged); + + const auto &iconManager = IconManager::instance(); + connect(&iconManager, &IconManager::statusIconsChanged, this, &SyncthingModel::handleStatusIconsChanged); + connect(&iconManager, &IconManager::forkAwesomeIconsChanged, this, &SyncthingModel::handleForkAwesomeIconsChanged); } const QVector &SyncthingModel::colorRoles() const @@ -21,6 +24,22 @@ const QVector &SyncthingModel::colorRoles() const return colorRoles; } +void SyncthingModel::invalidateTopLevelIndicies(const QVector &affectedRoles) +{ + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1), affectedRoles); +} + +void SyncthingModel::invalidateNestedIndicies(const QVector &affectedRoles) +{ + for (auto i = 0, rows = rowCount(); i != rows; ++i) { + const auto parentIndex = index(i, 0); + const auto childRows = rowCount(parentIndex); + if (childRows > 0) { + emit dataChanged(index(0, 0, parentIndex), index(childRows - 1, columnCount(parentIndex) - 1), affectedRoles); + } + } +} + void SyncthingModel::setBrightColors(bool brightColors) { if (m_brightColors == brightColors) { @@ -28,22 +47,8 @@ void SyncthingModel::setBrightColors(bool brightColors) } m_brightColors = brightColors; - const QVector &affectedRoles = colorRoles(); - if (affectedRoles.isEmpty()) { - return; - } - - // update top-level indices - const auto rows = rowCount(); - emit dataChanged(index(0, 0), index(rows - 1, columnCount() - 1), affectedRoles); - - // update nested indices - for (auto i = 0; i != rows; ++i) { - const auto parentIndex = index(i, 0); - const auto childRows = rowCount(parentIndex); - if (childRows > 0) { - emit dataChanged(index(0, 0, parentIndex), index(childRows - 1, columnCount(parentIndex) - 1), affectedRoles); - } + if (const QVector &affectedRoles = colorRoles(); !affectedRoles.isEmpty()) { + invalidateTopLevelIndicies(affectedRoles); } } @@ -61,4 +66,8 @@ void SyncthingModel::handleStatusIconsChanged() { } +void SyncthingModel::handleForkAwesomeIconsChanged() +{ +} + } // namespace Data diff --git a/model/syncthingmodel.h b/model/syncthingmodel.h index 11f8fe3..da2ccbc 100644 --- a/model/syncthingmodel.h +++ b/model/syncthingmodel.h @@ -27,11 +27,14 @@ public: protected: virtual const QVector &colorRoles() const; + void invalidateTopLevelIndicies(const QVector &affectedRoles); + void invalidateNestedIndicies(const QVector &affectedRoles); private Q_SLOTS: virtual void handleConfigInvalidated(); virtual void handleNewConfigAvailable(); virtual void handleStatusIconsChanged(); + virtual void handleForkAwesomeIconsChanged(); protected: Data::SyncthingConnection &m_connection; diff --git a/model/syncthingrecentchangesmodel.cpp b/model/syncthingrecentchangesmodel.cpp index b75c58c..9d10504 100644 --- a/model/syncthingrecentchangesmodel.cpp +++ b/model/syncthingrecentchangesmodel.cpp @@ -110,11 +110,7 @@ QVariant SyncthingRecentChangesModel::data(const QModelIndex &index, int role) c case ActionIcon: switch (index.column()) { case 0: - if (change.fileChange.local) { - return m_brightColors ? forkAwesomeIconsForDarkTheme().home : forkAwesomeIconsForLightTheme().home; - } else { - return m_brightColors ? forkAwesomeIconsForDarkTheme().globe : forkAwesomeIconsForLightTheme().globe; - } + return change.fileChange.local ? commonForkAwesomeIcons().home : commonForkAwesomeIcons().globe; } break; case Qt::ToolTipRole: @@ -218,6 +214,11 @@ void SyncthingRecentChangesModel::handleStatusChanged(SyncthingStatus status) endResetModel(); } +void SyncthingRecentChangesModel::handleForkAwesomeIconsChanged() +{ + invalidateTopLevelIndicies(QVector({ Qt::DecorationRole, ActionIcon })); +} + void SyncthingRecentChangesModel::setMaxRows(int maxRows) { m_maxRows = maxRows < 0 ? std::numeric_limits::max() : maxRows; diff --git a/model/syncthingrecentchangesmodel.h b/model/syncthingrecentchangesmodel.h index 2eb0355..c9f9ca1 100644 --- a/model/syncthingrecentchangesmodel.h +++ b/model/syncthingrecentchangesmodel.h @@ -51,6 +51,7 @@ private Q_SLOTS: void handleConfigInvalidated() override; void handleNewConfigAvailable() override; void handleStatusChanged(SyncthingStatus status); + void handleForkAwesomeIconsChanged() override; private: void ensureWithinLimit();