Simplify coloring of common ForkAwesome icons
The normal QPalette can be used to determine the icon color so it is unnecessary to use the flag for custom bright colors here (which is only intended for colors which are not on the standard QPalette).
This commit is contained in:
parent
de3205df00
commit
19bede39a2
|
@ -12,7 +12,8 @@ SyncthingDirActions::SyncthingDirActions(const SyncthingDir &dir, const Syncthin
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_dirId(dir.id)
|
, 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.setSeparator(true);
|
||||||
m_infoAction.setIcon(icons.folder);
|
m_infoAction.setIcon(icons.folder);
|
||||||
m_globalStatusAction.setIcon(icons.globe);
|
m_globalStatusAction.setIcon(icons.globe);
|
||||||
|
|
|
@ -169,7 +169,7 @@ QVariant SyncthingDeviceModel::data(const QModelIndex &index, int role) const
|
||||||
case DeviceDetailIcon:
|
case DeviceDetailIcon:
|
||||||
if (index.column() == 0) {
|
if (index.column() == 0) {
|
||||||
// attribute icons
|
// attribute icons
|
||||||
const auto &icons = m_brightColors ? forkAwesomeIconsForDarkTheme() : forkAwesomeIconsForLightTheme();
|
const auto &icons = commonForkAwesomeIcons();
|
||||||
switch (index.row()) {
|
switch (index.row()) {
|
||||||
case 0:
|
case 0:
|
||||||
return icons.hashtag;
|
return icons.hashtag;
|
||||||
|
@ -354,7 +354,12 @@ void SyncthingDeviceModel::devStatusChanged(const SyncthingDev &, int index)
|
||||||
|
|
||||||
void SyncthingDeviceModel::handleStatusIconsChanged()
|
void SyncthingDeviceModel::handleStatusIconsChanged()
|
||||||
{
|
{
|
||||||
emit dataChanged(index(0, 0), index(static_cast<int>(m_devs.size()) - 1, 0), QVector<int>({ Qt::DecorationRole }));
|
invalidateTopLevelIndicies(QVector<int>({ Qt::DecorationRole }));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SyncthingDeviceModel::handleForkAwesomeIconsChanged()
|
||||||
|
{
|
||||||
|
invalidateNestedIndicies(QVector<int>({ Qt::DecorationRole, DeviceDetailIcon }));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SyncthingDeviceModel::devStatusString(const SyncthingDev &dev)
|
QString SyncthingDeviceModel::devStatusString(const SyncthingDev &dev)
|
||||||
|
|
|
@ -43,6 +43,7 @@ public Q_SLOTS:
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void devStatusChanged(const SyncthingDev &, int index);
|
void devStatusChanged(const SyncthingDev &, int index);
|
||||||
void handleStatusIconsChanged() override;
|
void handleStatusIconsChanged() override;
|
||||||
|
void handleForkAwesomeIconsChanged() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QString devStatusString(const SyncthingDev &dev);
|
static QString devStatusString(const SyncthingDev &dev);
|
||||||
|
|
|
@ -191,7 +191,7 @@ QVariant SyncthingDirectoryModel::data(const QModelIndex &index, int role) const
|
||||||
case DirectoryDetailIcon:
|
case DirectoryDetailIcon:
|
||||||
if (index.column() == 0) {
|
if (index.column() == 0) {
|
||||||
// attribute icons
|
// attribute icons
|
||||||
const auto &icons = m_brightColors ? forkAwesomeIconsForDarkTheme() : forkAwesomeIconsForLightTheme();
|
const auto &icons = commonForkAwesomeIcons();
|
||||||
switch (row) {
|
switch (row) {
|
||||||
case 0:
|
case 0:
|
||||||
return icons.hashtag;
|
return icons.hashtag;
|
||||||
|
@ -445,7 +445,12 @@ void SyncthingDirectoryModel::handleNewConfigAvailable()
|
||||||
|
|
||||||
void SyncthingDirectoryModel::handleStatusIconsChanged()
|
void SyncthingDirectoryModel::handleStatusIconsChanged()
|
||||||
{
|
{
|
||||||
emit dataChanged(index(0, 0), index(static_cast<int>(m_dirs.size()) - 1, 0), QVector<int>({ Qt::DecorationRole }));
|
invalidateTopLevelIndicies(QVector<int>({ Qt::DecorationRole }));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SyncthingDirectoryModel::handleForkAwesomeIconsChanged()
|
||||||
|
{
|
||||||
|
invalidateNestedIndicies(QVector<int>({ Qt::DecorationRole, DirectoryDetailIcon }));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SyncthingDirectoryModel::dirStatusString(const SyncthingDir &dir)
|
QString SyncthingDirectoryModel::dirStatusString(const SyncthingDir &dir)
|
||||||
|
|
|
@ -46,6 +46,7 @@ private Q_SLOTS:
|
||||||
void handleConfigInvalidated() override;
|
void handleConfigInvalidated() override;
|
||||||
void handleNewConfigAvailable() override;
|
void handleNewConfigAvailable() override;
|
||||||
void handleStatusIconsChanged() override;
|
void handleStatusIconsChanged() override;
|
||||||
|
void handleForkAwesomeIconsChanged() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QString dirStatusString(const SyncthingDir &dir);
|
static QString dirStatusString(const SyncthingDir &dir);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QPalette>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
|
|
||||||
|
@ -301,9 +302,15 @@ ForkAwesomeIcons::ForkAwesomeIcons(QtForkAwesome::Renderer &renderer, const QCol
|
||||||
IconManager::IconManager()
|
IconManager::IconManager()
|
||||||
: m_statusIcons()
|
: m_statusIcons()
|
||||||
, m_trayIcons(m_statusIcons)
|
, m_trayIcons(m_statusIcons)
|
||||||
, m_forkAwesomeIconsForLightTheme(m_forkAwesomeRenderer, QColor(10, 10, 10), QSize(64, 64))
|
, m_commonForkAwesomeIcons(m_forkAwesomeRenderer, QGuiApplication::palette().color(QPalette::Normal, QPalette::Text), QSize(64, 64))
|
||||||
, m_fontAwesomeIconsForDarkTheme(m_forkAwesomeRenderer, Qt::white, 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()
|
IconManager &IconManager::instance()
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QColor)
|
QT_FORWARD_DECLARE_CLASS(QColor)
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QPalette)
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
|
||||||
|
@ -148,11 +149,14 @@ public:
|
||||||
const StatusIcons &statusIcons() const;
|
const StatusIcons &statusIcons() const;
|
||||||
const StatusIcons &trayIcons() const;
|
const StatusIcons &trayIcons() const;
|
||||||
QtForkAwesome::Renderer &forkAwesomeRenderer();
|
QtForkAwesome::Renderer &forkAwesomeRenderer();
|
||||||
const ForkAwesomeIcons &forkAwesomeIconsForLightTheme() const;
|
const ForkAwesomeIcons &commonForkAwesomeIcons() const;
|
||||||
const ForkAwesomeIcons &forkAwesomeIconsForDarkTheme() const;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void statusIconsChanged(const StatusIcons &newStatusIcons, const StatusIcons &newTrayIcons);
|
void statusIconsChanged(const StatusIcons &newStatusIcons, const StatusIcons &newTrayIcons);
|
||||||
|
void forkAwesomeIconsChanged(const ForkAwesomeIcons &newForkAwesomeIcons);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void handlePaletteChanged(const QPalette &pal);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IconManager();
|
IconManager();
|
||||||
|
@ -160,8 +164,7 @@ private:
|
||||||
StatusIcons m_statusIcons;
|
StatusIcons m_statusIcons;
|
||||||
StatusIcons m_trayIcons;
|
StatusIcons m_trayIcons;
|
||||||
QtForkAwesome::Renderer m_forkAwesomeRenderer;
|
QtForkAwesome::Renderer m_forkAwesomeRenderer;
|
||||||
ForkAwesomeIcons m_forkAwesomeIconsForLightTheme;
|
ForkAwesomeIcons m_commonForkAwesomeIcons;
|
||||||
ForkAwesomeIcons m_fontAwesomeIconsForDarkTheme;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void IconManager::applySettings(const StatusIconSettings *statusIconSettings, const StatusIconSettings *trayIconSettings)
|
inline void IconManager::applySettings(const StatusIconSettings *statusIconSettings, const StatusIconSettings *trayIconSettings)
|
||||||
|
@ -194,14 +197,9 @@ inline QtForkAwesome::Renderer &IconManager::forkAwesomeRenderer()
|
||||||
return m_forkAwesomeRenderer;
|
return m_forkAwesomeRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const ForkAwesomeIcons &IconManager::forkAwesomeIconsForLightTheme() const
|
inline const ForkAwesomeIcons &IconManager::commonForkAwesomeIcons() const
|
||||||
{
|
{
|
||||||
return m_forkAwesomeIconsForLightTheme;
|
return m_commonForkAwesomeIcons;
|
||||||
}
|
|
||||||
|
|
||||||
inline const ForkAwesomeIcons &IconManager::forkAwesomeIconsForDarkTheme() const
|
|
||||||
{
|
|
||||||
return m_fontAwesomeIconsForDarkTheme;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const StatusIcons &statusIcons()
|
inline const StatusIcons &statusIcons()
|
||||||
|
@ -214,14 +212,9 @@ inline const StatusIcons &trayIcons()
|
||||||
return IconManager::instance().trayIcons();
|
return IconManager::instance().trayIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const ForkAwesomeIcons &forkAwesomeIconsForLightTheme()
|
inline const ForkAwesomeIcons &commonForkAwesomeIcons()
|
||||||
{
|
{
|
||||||
return IconManager::instance().forkAwesomeIconsForLightTheme();
|
return IconManager::instance().commonForkAwesomeIcons();
|
||||||
}
|
|
||||||
|
|
||||||
inline const ForkAwesomeIcons &forkAwesomeIconsForDarkTheme()
|
|
||||||
{
|
|
||||||
return IconManager::instance().forkAwesomeIconsForDarkTheme();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
|
@ -12,7 +12,10 @@ SyncthingModel::SyncthingModel(SyncthingConnection &connection, QObject *parent)
|
||||||
{
|
{
|
||||||
connect(&m_connection, &SyncthingConnection::newConfig, this, &SyncthingModel::handleConfigInvalidated);
|
connect(&m_connection, &SyncthingConnection::newConfig, this, &SyncthingModel::handleConfigInvalidated);
|
||||||
connect(&m_connection, &SyncthingConnection::newConfigApplied, this, &SyncthingModel::handleNewConfigAvailable);
|
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<int> &SyncthingModel::colorRoles() const
|
const QVector<int> &SyncthingModel::colorRoles() const
|
||||||
|
@ -21,6 +24,22 @@ const QVector<int> &SyncthingModel::colorRoles() const
|
||||||
return colorRoles;
|
return colorRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SyncthingModel::invalidateTopLevelIndicies(const QVector<int> &affectedRoles)
|
||||||
|
{
|
||||||
|
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1), affectedRoles);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SyncthingModel::invalidateNestedIndicies(const QVector<int> &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)
|
void SyncthingModel::setBrightColors(bool brightColors)
|
||||||
{
|
{
|
||||||
if (m_brightColors == brightColors) {
|
if (m_brightColors == brightColors) {
|
||||||
|
@ -28,22 +47,8 @@ void SyncthingModel::setBrightColors(bool brightColors)
|
||||||
}
|
}
|
||||||
m_brightColors = brightColors;
|
m_brightColors = brightColors;
|
||||||
|
|
||||||
const QVector<int> &affectedRoles = colorRoles();
|
if (const QVector<int> &affectedRoles = colorRoles(); !affectedRoles.isEmpty()) {
|
||||||
if (affectedRoles.isEmpty()) {
|
invalidateTopLevelIndicies(affectedRoles);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,4 +66,8 @@ void SyncthingModel::handleStatusIconsChanged()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SyncthingModel::handleForkAwesomeIconsChanged()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
|
@ -27,11 +27,14 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual const QVector<int> &colorRoles() const;
|
virtual const QVector<int> &colorRoles() const;
|
||||||
|
void invalidateTopLevelIndicies(const QVector<int> &affectedRoles);
|
||||||
|
void invalidateNestedIndicies(const QVector<int> &affectedRoles);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
virtual void handleConfigInvalidated();
|
virtual void handleConfigInvalidated();
|
||||||
virtual void handleNewConfigAvailable();
|
virtual void handleNewConfigAvailable();
|
||||||
virtual void handleStatusIconsChanged();
|
virtual void handleStatusIconsChanged();
|
||||||
|
virtual void handleForkAwesomeIconsChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Data::SyncthingConnection &m_connection;
|
Data::SyncthingConnection &m_connection;
|
||||||
|
|
|
@ -110,11 +110,7 @@ QVariant SyncthingRecentChangesModel::data(const QModelIndex &index, int role) c
|
||||||
case ActionIcon:
|
case ActionIcon:
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
if (change.fileChange.local) {
|
return change.fileChange.local ? commonForkAwesomeIcons().home : commonForkAwesomeIcons().globe;
|
||||||
return m_brightColors ? forkAwesomeIconsForDarkTheme().home : forkAwesomeIconsForLightTheme().home;
|
|
||||||
} else {
|
|
||||||
return m_brightColors ? forkAwesomeIconsForDarkTheme().globe : forkAwesomeIconsForLightTheme().globe;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
|
@ -218,6 +214,11 @@ void SyncthingRecentChangesModel::handleStatusChanged(SyncthingStatus status)
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SyncthingRecentChangesModel::handleForkAwesomeIconsChanged()
|
||||||
|
{
|
||||||
|
invalidateTopLevelIndicies(QVector<int>({ Qt::DecorationRole, ActionIcon }));
|
||||||
|
}
|
||||||
|
|
||||||
void SyncthingRecentChangesModel::setMaxRows(int maxRows)
|
void SyncthingRecentChangesModel::setMaxRows(int maxRows)
|
||||||
{
|
{
|
||||||
m_maxRows = maxRows < 0 ? std::numeric_limits<int>::max() : maxRows;
|
m_maxRows = maxRows < 0 ? std::numeric_limits<int>::max() : maxRows;
|
||||||
|
|
|
@ -51,6 +51,7 @@ private Q_SLOTS:
|
||||||
void handleConfigInvalidated() override;
|
void handleConfigInvalidated() override;
|
||||||
void handleNewConfigAvailable() override;
|
void handleNewConfigAvailable() override;
|
||||||
void handleStatusChanged(SyncthingStatus status);
|
void handleStatusChanged(SyncthingStatus status);
|
||||||
|
void handleForkAwesomeIconsChanged() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ensureWithinLimit();
|
void ensureWithinLimit();
|
||||||
|
|
Loading…
Reference in New Issue