From 7b6121cb0572461c7e6379d786d3a3c0f37b4d7e Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 15 Oct 2021 00:23:22 +0200 Subject: [PATCH] Use ForkAwesome icons more consistently in tray widget Mixing ForkAwesome icons too much with the regular icon theme doesn't look good (depending on the theme) so let's prefer ForkAwesome icons within the tray widget which already uses ForkAwesome in some places like certain buttons and models. This makes it also look more in-line with Syncthing's web UI. For context menus and dialogs let's prefer system icons because there are hardly any ForkAwesome icons used/required so far and it is maybe nicer to be in-line with the system here. --- tray/gui/devbuttonsitemdelegate.cpp | 13 ++++------- tray/gui/devbuttonsitemdelegate.h | 5 ---- tray/gui/dirbuttonsitemdelegate.cpp | 24 ++++++++----------- tray/gui/dirbuttonsitemdelegate.h | 7 ------ tray/gui/downloaditemdelegate.cpp | 8 ++++--- tray/gui/downloaditemdelegate.h | 3 --- tray/gui/trayicon.cpp | 5 ++-- tray/gui/traywidget.cpp | 36 ++++++++++------------------- tray/gui/traywidget.ui | 28 ++++++++-------------- 9 files changed, 43 insertions(+), 86 deletions(-) diff --git a/tray/gui/devbuttonsitemdelegate.cpp b/tray/gui/devbuttonsitemdelegate.cpp index c67f3e6..d1539d4 100644 --- a/tray/gui/devbuttonsitemdelegate.cpp +++ b/tray/gui/devbuttonsitemdelegate.cpp @@ -2,6 +2,10 @@ #include #include +#include + +#include +#include #include #include @@ -23,12 +27,6 @@ inline int centerObj(int avail, int size) DevButtonsItemDelegate::DevButtonsItemDelegate(QObject *parent) : QStyledItemDelegate(parent) - , m_pauseIcon( - QIcon::fromTheme(QStringLiteral("media-playback-pause"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/media-playback-pause.svg"))) - .pixmap(QSize(16, 16))) - , m_resumeIcon( - QIcon::fromTheme(QStringLiteral("media-playback-start"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/media-playback-start.svg"))) - .pixmap(QSize(16, 16))) { } @@ -59,8 +57,7 @@ void DevButtonsItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem return; } const int buttonY = option.rect.y() + centerObj(option.rect.height(), 16); - painter->drawPixmap( - option.rect.right() - 16, buttonY, 16, 16, index.data(SyncthingDeviceModel::DevicePaused).toBool() ? m_resumeIcon : m_pauseIcon); + IconManager::instance().forkAwesomeRenderer().render(index.data(SyncthingDeviceModel::DevicePaused).toBool() ? QtForkAwesome::Icon::Play : QtForkAwesome::Icon::Pause, painter, QRect(option.rect.right() - 16, buttonY, 16, 16), QGuiApplication::palette().color(QPalette::Text)); } } } // namespace QtGui diff --git a/tray/gui/devbuttonsitemdelegate.h b/tray/gui/devbuttonsitemdelegate.h index 89b50be..6a24ba4 100644 --- a/tray/gui/devbuttonsitemdelegate.h +++ b/tray/gui/devbuttonsitemdelegate.h @@ -1,7 +1,6 @@ #ifndef DEVBUTTONSITEMDELEGATE_H #define DEVBUTTONSITEMDELEGATE_H -#include #include #include @@ -13,10 +12,6 @@ public: DevButtonsItemDelegate(QObject *parent); void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override; - -private: - const QPixmap m_pauseIcon; - const QPixmap m_resumeIcon; }; } // namespace QtGui diff --git a/tray/gui/dirbuttonsitemdelegate.cpp b/tray/gui/dirbuttonsitemdelegate.cpp index 3e264fd..67563d6 100644 --- a/tray/gui/dirbuttonsitemdelegate.cpp +++ b/tray/gui/dirbuttonsitemdelegate.cpp @@ -1,6 +1,10 @@ #include "./dirbuttonsitemdelegate.h" #include +#include + +#include +#include #include #include @@ -22,16 +26,6 @@ inline int centerObj(int avail, int size) DirButtonsItemDelegate::DirButtonsItemDelegate(QObject *parent) : QStyledItemDelegate(parent) - , m_refreshIcon(QIcon::fromTheme(QStringLiteral("view-refresh"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/view-refresh.svg"))) - .pixmap(QSize(16, 16))) - , m_folderIcon(QIcon::fromTheme(QStringLiteral("folder-open"), QIcon(QStringLiteral(":/icons/hicolor/scalable/places/folder-open.svg"))) - .pixmap(QSize(16, 16))) - , m_pauseIcon( - QIcon::fromTheme(QStringLiteral("media-playback-pause"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/media-playback-pause.svg"))) - .pixmap(QSize(16, 16))) - , m_resumeIcon( - QIcon::fromTheme(QStringLiteral("media-playback-start"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/media-playback-start.svg"))) - .pixmap(QSize(16, 16))) { } @@ -49,7 +43,7 @@ void DirButtonsItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter); // draw text - QRectF textRect = option.rect; + auto textRect = QRectF(option.rect); textRect.setWidth(textRect.width() - 58); QTextOption textOption; textOption.setAlignment(opt.displayAlignment); @@ -60,11 +54,13 @@ void DirButtonsItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem // draw buttons const int buttonY = option.rect.y() + centerObj(option.rect.height(), 16); const bool dirPaused = index.data(SyncthingDirectoryModel::DirectoryPaused).toBool(); + const auto iconColor = QGuiApplication::palette().color(QPalette::Text); + auto &forkAwesomeRenderer = IconManager::instance().forkAwesomeRenderer(); if (!dirPaused) { - painter->drawPixmap(option.rect.right() - 52, buttonY, 16, 16, m_refreshIcon); + forkAwesomeRenderer.render(QtForkAwesome::Icon::Refresh, painter, QRect(option.rect.right() - 52, buttonY, 16, 16), iconColor); } - painter->drawPixmap(option.rect.right() - 34, buttonY, 16, 16, dirPaused ? m_resumeIcon : m_pauseIcon); - painter->drawPixmap(option.rect.right() - 16, buttonY, 16, 16, m_folderIcon); + forkAwesomeRenderer.render(dirPaused ? QtForkAwesome::Icon::Play : QtForkAwesome::Icon::Pause, painter, QRect(option.rect.right() - 34, buttonY, 16, 16), iconColor); + forkAwesomeRenderer.render(QtForkAwesome::Icon::Folder, painter, QRect(option.rect.right() - 16, buttonY, 16, 16), iconColor); } } } // namespace QtGui diff --git a/tray/gui/dirbuttonsitemdelegate.h b/tray/gui/dirbuttonsitemdelegate.h index 795f35f..dc710a4 100644 --- a/tray/gui/dirbuttonsitemdelegate.h +++ b/tray/gui/dirbuttonsitemdelegate.h @@ -1,7 +1,6 @@ #ifndef DIRBUTTONSITEMDELEGATE_H #define DIRBUTTONSITEMDELEGATE_H -#include #include namespace QtGui { @@ -12,12 +11,6 @@ public: DirButtonsItemDelegate(QObject *parent); void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override; - -private: - const QPixmap m_refreshIcon; - const QPixmap m_folderIcon; - const QPixmap m_pauseIcon; - const QPixmap m_resumeIcon; }; } // namespace QtGui diff --git a/tray/gui/downloaditemdelegate.cpp b/tray/gui/downloaditemdelegate.cpp index 5471b1e..efb23c8 100644 --- a/tray/gui/downloaditemdelegate.cpp +++ b/tray/gui/downloaditemdelegate.cpp @@ -1,6 +1,10 @@ #include "./downloaditemdelegate.h" #include +#include + +#include +#include #include #include @@ -26,8 +30,6 @@ inline int centerObj(int avail, int size) DownloadItemDelegate::DownloadItemDelegate(QObject *parent) : QStyledItemDelegate(parent) - , m_folderIcon(QIcon::fromTheme(QStringLiteral("folder-open"), QIcon(QStringLiteral(":/icons/hicolor/scalable/places/folder-open.svg"))) - .pixmap(QSize(16, 16))) { } @@ -81,7 +83,7 @@ void DownloadItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & if (!index.parent().isValid()) { buttonY += centerObj(progressBarOption.rect.height(), 16); } - painter->drawPixmap(option.rect.right() - 16, buttonY, 16, 16, m_folderIcon); + IconManager::instance().forkAwesomeRenderer().render(QtForkAwesome::Icon::Folder, painter, QRect(option.rect.right() - 16, buttonY, 16, 16), QGuiApplication::palette().color(QPalette::Text)); // draw file icon if (index.parent().isValid()) { diff --git a/tray/gui/downloaditemdelegate.h b/tray/gui/downloaditemdelegate.h index 53fd3d9..c25f7cc 100644 --- a/tray/gui/downloaditemdelegate.h +++ b/tray/gui/downloaditemdelegate.h @@ -13,9 +13,6 @@ public: void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; - -private: - const QPixmap m_folderIcon; }; } // namespace QtGui diff --git a/tray/gui/trayicon.cpp b/tray/gui/trayicon.cpp index d3c113e..af4161a 100644 --- a/tray/gui/trayicon.cpp +++ b/tray/gui/trayicon.cpp @@ -49,7 +49,7 @@ TrayIcon::TrayIcon(const QString &connectionConfig, QObject *parent) // set context menu #ifndef SYNCTHINGTRAY_UNIFY_TRAY_MENUS - connect(m_contextMenu.addAction(QIcon(QStringLiteral(":/icons/hicolor/scalable/status/syncthing-default.svg")), tr("Open Syncthing")), + connect(m_contextMenu.addAction(QIcon(QStringLiteral("syncthing.fa")), tr("Open Syncthing")), &QAction::triggered, &widget, &TrayWidget::showWebUi); connect(m_contextMenu.addAction( QIcon::fromTheme(QStringLiteral("preferences-other"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/preferences-other.svg"))), @@ -59,8 +59,7 @@ TrayIcon::TrayIcon(const QString &connectionConfig, QObject *parent) QIcon::fromTheme(QStringLiteral("folder-sync"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/folder-sync.svg"))), tr("Rescan all")), &QAction::triggered, &widget.connection(), &SyncthingConnection::rescanAllDirs); - connect(m_contextMenu.addAction( - QIcon::fromTheme(QStringLiteral("text-x-generic"), QIcon(QStringLiteral(":/icons/hicolor/scalable/mimetypes/text-x-generic.svg"))), + connect(m_contextMenu.addAction(QIcon(QStringLiteral("file-code-o.fa")), tr("Log")), &QAction::triggered, &widget, &TrayWidget::showLog); m_errorsAction = m_contextMenu.addAction( diff --git a/tray/gui/traywidget.cpp b/tray/gui/traywidget.cpp index 24ba380..ea03f4f 100644 --- a/tray/gui/traywidget.cpp +++ b/tray/gui/traywidget.cpp @@ -122,20 +122,17 @@ TrayWidget::TrayWidget(TrayMenu *parent) cornerFrameLayout->addWidget(viewIdButton); auto *restartButton = new QPushButton(m_cornerFrame); restartButton->setToolTip(tr("Restart Syncthing")); - restartButton->setIcon( - QIcon::fromTheme(QStringLiteral("system-reboot"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/view-refresh.svg")))); + restartButton->setIcon(QIcon(QStringLiteral("power-off.fa"))); restartButton->setFlat(true); cornerFrameLayout->addWidget(restartButton); auto *showLogButton = new QPushButton(m_cornerFrame); showLogButton->setToolTip(tr("Show Syncthing log")); - showLogButton->setIcon( - QIcon::fromTheme(QStringLiteral("text-x-generic"), QIcon(QStringLiteral(":/icons/hicolor/scalable/mimetypes/text-x-generic.svg")))); + showLogButton->setIcon(QIcon(QStringLiteral("file-code-o.fa"))); showLogButton->setFlat(true); cornerFrameLayout->addWidget(showLogButton); auto *scanAllButton = new QPushButton(m_cornerFrame); scanAllButton->setToolTip(tr("Rescan all directories")); - scanAllButton->setIcon( - QIcon::fromTheme(QStringLiteral("folder-sync"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/folder-sync.svg")))); + scanAllButton->setIcon(QIcon(QStringLiteral("search.fa"))); scanAllButton->setFlat(true); cornerFrameLayout->addWidget(scanAllButton); m_ui->tabWidget->setCornerWidget(m_cornerFrame, Qt::BottomRightCorner); @@ -154,10 +151,8 @@ TrayWidget::TrayWidget(TrayMenu *parent) // setup other widgets m_ui->notificationsPushButton->setHidden(true); - m_ui->globalTextLabel->setPixmap( - QIcon::fromTheme(QStringLiteral("globe"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/globe.svg"))).pixmap(16)); - m_ui->localTextLabel->setPixmap( - QIcon::fromTheme(QStringLiteral("user-home"), QIcon(QStringLiteral(":/icons/hicolor/scalable/places/user-home.svg"))).pixmap(16)); + m_ui->globalTextLabel->setPixmap(QIcon(QStringLiteral("globe.fa")).pixmap(16)); + m_ui->localTextLabel->setPixmap(QIcon(QStringLiteral("home.fa")).pixmap(16)); updateTraffic(); // add actions from right-click menu if it is not available @@ -395,8 +390,7 @@ void TrayWidget::handleStatusChanged(SyncthingStatus status) case SyncthingStatus::Disconnected: m_ui->statusPushButton->setText(tr("Connect")); m_ui->statusPushButton->setToolTip(tr("Not connected to Syncthing, click to connect")); - m_ui->statusPushButton->setIcon( - QIcon::fromTheme(QStringLiteral("view-refresh"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/view-refresh.svg")))); + m_ui->statusPushButton->setIcon(QIcon(QStringLiteral("refresh.fa"))); m_ui->statusPushButton->setHidden(false); updateTraffic(); // ensure previous traffic statistics are no longer shown break; @@ -409,15 +403,13 @@ void TrayWidget::handleStatusChanged(SyncthingStatus status) case SyncthingStatus::RemoteNotInSync: m_ui->statusPushButton->setText(tr("Pause")); m_ui->statusPushButton->setToolTip(tr("Syncthing is running, click to pause all devices")); - m_ui->statusPushButton->setIcon(QIcon::fromTheme( - QStringLiteral("media-playback-pause"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/media-playback-pause.svg")))); + m_ui->statusPushButton->setIcon(QIcon(QStringLiteral("pause.fa"))); m_ui->statusPushButton->setHidden(false); break; case SyncthingStatus::Paused: m_ui->statusPushButton->setText(tr("Continue")); m_ui->statusPushButton->setToolTip(tr("At least one device is paused, click to resume")); - m_ui->statusPushButton->setIcon(QIcon::fromTheme( - QStringLiteral("media-playback-start"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/media-playback-start.svg")))); + m_ui->statusPushButton->setIcon(QIcon(QStringLiteral("play.fa"))); m_ui->statusPushButton->setHidden(false); break; default:; @@ -736,13 +728,11 @@ Settings::Launcher::LauncherStatus TrayWidget::applyLauncherSettings(bool reconn if (launcherStatus.running) { m_ui->startStopPushButton->setText(tr("Stop")); m_ui->startStopPushButton->setToolTip(tr("Stop Syncthing instance launched via tray icon")); - m_ui->startStopPushButton->setIcon( - QIcon::fromTheme(QStringLiteral("process-stop"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/process-stop.svg")))); + m_ui->startStopPushButton->setIcon(QIcon(QStringLiteral("stop.fa"))); } else { m_ui->startStopPushButton->setText(tr("Start")); m_ui->startStopPushButton->setToolTip(tr("Start Syncthing with the built-in launcher configured in the settings")); - m_ui->startStopPushButton->setIcon( - QIcon::fromTheme(QStringLiteral("system-run"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/system-run.svg")))); + m_ui->startStopPushButton->setIcon(QIcon(QStringLiteral("play.fa"))); } return launcherStatus; } @@ -780,15 +770,13 @@ Settings::Systemd::ServiceStatus TrayWidget::applySystemdSettings(bool reconnect m_ui->startStopPushButton->setToolTip( (serviceStatus.userService ? QStringLiteral("systemctl --user stop ") : QStringLiteral("systemctl stop ")) + systemdSettings.syncthingUnit); - m_ui->startStopPushButton->setIcon( - QIcon::fromTheme(QStringLiteral("process-stop"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/process-stop.svg")))); + m_ui->startStopPushButton->setIcon(QIcon(QStringLiteral("stop.fa"))); } else { m_ui->startStopPushButton->setText(tr("Start")); m_ui->startStopPushButton->setToolTip( (serviceStatus.userService ? QStringLiteral("systemctl --user start ") : QStringLiteral("systemctl start ")) + systemdSettings.syncthingUnit); - m_ui->startStopPushButton->setIcon( - QIcon::fromTheme(QStringLiteral("system-run"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/system-run.svg")))); + m_ui->startStopPushButton->setIcon(QIcon(QStringLiteral("play.fa"))); } return serviceStatus; } diff --git a/tray/gui/traywidget.ui b/tray/gui/traywidget.ui index 482a0ff..45097b6 100644 --- a/tray/gui/traywidget.ui +++ b/tray/gui/traywidget.ui @@ -58,8 +58,7 @@ Connect - - :/icons/hicolor/scalable/actions/view-refresh.svg:/icons/hicolor/scalable/actions/view-refresh.svg + refresh.fa true @@ -72,8 +71,7 @@ Start - - :/icons/hicolor/scalable/apps/system-run.svg:/icons/hicolor/scalable/apps/system-run.svg + play.fa true @@ -99,8 +97,7 @@ About - - :/icons/hicolor/scalable/actions/help-about.svg:/icons/hicolor/scalable/actions/help-about.svg + info.fa true @@ -113,8 +110,7 @@ Settings - - :/icons/hicolor/scalable/actions/application-menu.svg:/icons/hicolor/scalable/actions/application-menu.svg + cogs.fa true @@ -145,8 +141,7 @@ - - :/icons/hicolor/scalable/actions/network-connect.svg:/icons/hicolor/scalable/actions/network-connect.svg + plug.fa true @@ -383,8 +378,7 @@ For <i>all</i> notifications, checkout the log - - :/icons/hicolor/scalable/places/folder.svg:/icons/hicolor/scalable/places/folder.svg + folder.fa Directories @@ -416,8 +410,7 @@ For <i>all</i> notifications, checkout the log - - :/icons/hicolor/scalable/places/network-workgroup.svg:/icons/hicolor/scalable/places/network-workgroup.svg + sitemap.fa Devices @@ -449,8 +442,7 @@ For <i>all</i> notifications, checkout the log - - :/icons/hicolor/scalable/places/folder-download.svg:/icons/hicolor/scalable/places/folder-download.svg + download.fa Downloads @@ -478,9 +470,7 @@ For <i>all</i> notifications, checkout the log - - . - :/icons/hicolor/scalable/actions/appointment-new.svg. + history.fa Recent changes