Skip to content

Commit

Permalink
Use colors from Plasma theme in Plasmoid
Browse files Browse the repository at this point in the history
One might configure a light color theme for applications and a dark theme
for Plasma (or vice versa) so this is an important difference, see
#126.
  • Loading branch information
Martchus committed Feb 2, 2022
1 parent c5c34bd commit 3e38a99
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(META_APP_CATEGORIES "Network;FileTransfer")
set(META_GUI_OPTIONAL false)
set(META_VERSION_MAJOR 1)
set(META_VERSION_MINOR 1)
set(META_VERSION_PATCH 15)
set(META_VERSION_PATCH 16)
set(META_VERSION_EXACT_SONAME ON)
set(META_ADD_DEFAULT_CPP_UNIT_TEST_APPLICATION ON)

Expand Down
16 changes: 9 additions & 7 deletions model/syncthingicons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,30 +300,32 @@ ForkAwesomeIcons::ForkAwesomeIcons(QtForkAwesome::Renderer &renderer, const QCol
{
}

IconManager::IconManager()
IconManager::IconManager(const QPalette *palette)
: m_statusIcons()
, m_trayIcons(m_statusIcons)
, m_commonForkAwesomeIcons(m_forkAwesomeRenderer, QGuiApplication::palette().color(QPalette::Normal, QPalette::Text), QSize(64, 64))
, m_commonForkAwesomeIcons(m_forkAwesomeRenderer, (palette ? *palette : QGuiApplication::palette()).color(QPalette::Normal, QPalette::Text), QSize(64, 64))
{
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
QObject::connect(qGuiApp, &QGuiApplication::paletteChanged, this, &IconManager::handlePaletteChanged);
if (!palette) {
QObject::connect(qGuiApp, &QGuiApplication::paletteChanged, this, &IconManager::setPalette);
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}

void IconManager::handlePaletteChanged(const QPalette &pal)
void IconManager::setPalette(const QPalette &palette)
{
emit forkAwesomeIconsChanged(
m_commonForkAwesomeIcons = ForkAwesomeIcons(m_forkAwesomeRenderer, pal.color(QPalette::Normal, QPalette::Text), QSize(64, 64)));
m_commonForkAwesomeIcons = ForkAwesomeIcons(m_forkAwesomeRenderer, palette.color(QPalette::Normal, QPalette::Text), QSize(64, 64)));
}

IconManager &IconManager::instance()
IconManager &IconManager::instance(const QPalette *palette)
{
static IconManager iconManager;
static auto iconManager = IconManager(palette);
return iconManager;
}

Expand Down
14 changes: 7 additions & 7 deletions model/syncthingicons.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,23 @@ struct LIB_SYNCTHING_MODEL_EXPORT ForkAwesomeIcons {
class LIB_SYNCTHING_MODEL_EXPORT IconManager : public QObject {
Q_OBJECT
public:
static IconManager &instance();
static IconManager &instance(const QPalette *palette = nullptr);

void applySettings(const StatusIconSettings *statusIconSettings = nullptr, const StatusIconSettings *trayIconSettings = nullptr);
const StatusIcons &statusIcons() const;
const StatusIcons &trayIcons() const;
QtForkAwesome::Renderer &forkAwesomeRenderer();
const ForkAwesomeIcons &commonForkAwesomeIcons() const;

Q_SIGNALS:
void statusIconsChanged(const StatusIcons &newStatusIcons, const StatusIcons &newTrayIcons);
void forkAwesomeIconsChanged(const ForkAwesomeIcons &newForkAwesomeIcons);
public Q_SLOTS:
void setPalette(const QPalette &palette);

private Q_SLOTS:
void handlePaletteChanged(const QPalette &pal);
Q_SIGNALS:
void statusIconsChanged(const Data::StatusIcons &newStatusIcons, const Data::StatusIcons &newTrayIcons);
void forkAwesomeIconsChanged(const Data::ForkAwesomeIcons &newForkAwesomeIcons);

private:
IconManager();
explicit IconManager(const QPalette *palette = nullptr);

StatusIcons m_statusIcons;
StatusIcons m_trayIcons;
Expand Down
2 changes: 1 addition & 1 deletion plasmoid/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ find_package(${PACKAGE_NAMESPACE_PREFIX}qtutilities${CONFIGURATION_PACKAGE_SUFFI
use_qt_utilities()

# find qtforkawesomequickimageprovider
find_package(${PACKAGE_NAMESPACE_PREFIX}qtquickforkawesome${CONFIGURATION_PACKAGE_SUFFIX_QTFORKAWESOME} 0.0.1 REQUIRED)
find_package(${PACKAGE_NAMESPACE_PREFIX}qtquickforkawesome${CONFIGURATION_PACKAGE_SUFFIX_QTFORKAWESOME} 0.0.3 REQUIRED)
use_qt_quick_fork_awesome()

# check whether qtutilities supports DBus notifications
Expand Down
28 changes: 25 additions & 3 deletions plasmoid/lib/syncthingapplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#include <KConfigGroup>

#include <Plasma/Theme>

#include <QClipboard>
#include <QDesktopServices>
#include <QGuiApplication>
Expand All @@ -51,6 +53,8 @@ namespace Plasmoid {

SyncthingApplet::SyncthingApplet(QObject *parent, const QVariantList &data)
: Applet(parent, data)
, m_palette(m_theme.palette())
, m_iconManager(IconManager::instance(&m_palette))
, m_aboutDlg(nullptr)
, m_connection()
, m_notifier(m_connection)
Expand All @@ -61,6 +65,7 @@ SyncthingApplet::SyncthingApplet(QObject *parent, const QVariantList &data)
, m_downloadModel(m_connection)
, m_recentChangesModel(m_connection)
, m_settingsDlg(nullptr)
, m_imageProvider(nullptr)
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
, m_webViewDlg(nullptr)
#endif
Expand Down Expand Up @@ -112,7 +117,8 @@ void SyncthingApplet::init()
connect(&m_dbusNotifier, &DBusStatusNotifier::showNotificationsRequested, this, &SyncthingApplet::showNotificationsDialog);
connect(&m_dbusNotifier, &DBusStatusNotifier::errorDetailsRequested, this, &SyncthingApplet::showInternalErrorsDialog);
connect(&m_dbusNotifier, &DBusStatusNotifier::webUiRequested, this, &SyncthingApplet::showWebUI);
connect(&IconManager::instance(), &IconManager::statusIconsChanged, this, &SyncthingApplet::connectionStatusChanged);
connect(&m_iconManager, &IconManager::statusIconsChanged, this, &SyncthingApplet::connectionStatusChanged);
connect(&m_theme, &Plasma::Theme::themeChanged, this, &SyncthingApplet::handleThemeChanged);

// restore settings
Settings::restore();
Expand All @@ -137,11 +143,14 @@ void SyncthingApplet::init()

void SyncthingApplet::initEngine(QObject *object)
{
auto engine = qmlEngine(object);
const auto engine = qmlEngine(object);
if (!engine) {
return;
}
engine->addImageProvider(QStringLiteral("fa"), new QtForkAwesome::QuickImageProvider(IconManager::instance().forkAwesomeRenderer()));
const auto color = m_theme.color(Plasma::Theme::TextColor, Plasma::Theme::NormalColorGroup);
m_imageProvider = new QtForkAwesome::QuickImageProvider(m_iconManager.forkAwesomeRenderer(), color);
connect(engine, &QObject::destroyed, this, &SyncthingApplet::handleImageProviderDestroyed); // engine has ownership over image provider
engine->addImageProvider(QStringLiteral("fa"), m_imageProvider);
}

QIcon SyncthingApplet::statusIcon() const
Expand Down Expand Up @@ -524,6 +533,19 @@ void SyncthingApplet::handleSystemdServiceError(const QString &context, const QS
QNetworkReply::NoError, QNetworkRequest(), QByteArray());
}

void Plasmoid::SyncthingApplet::handleImageProviderDestroyed()
{
m_imageProvider = nullptr;
}

void SyncthingApplet::handleThemeChanged()
{
IconManager::instance().setPalette(m_theme.palette());
if (m_imageProvider) {
m_imageProvider->setDefaultColor(m_theme.color(Plasma::Theme::TextColor, Plasma::Theme::NormalColorGroup));
}
}

#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
void SyncthingApplet::handleSystemdStatusChanged()
{
Expand Down
13 changes: 13 additions & 0 deletions plasmoid/lib/syncthingapplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,24 @@
#define PLASMA_NO_DEPRECATED_WARNINGS 1

#include <Plasma/Applet>
#include <Plasma/Theme>

#include <QPalette>
#include <QSize>

namespace Data {
struct SyncthingConnectionSettings;
class IconManager;
} // namespace Data

namespace QtGui {
class WebViewDialog;
}

namespace QtForkAwesome {
class QuickImageProvider;
}

namespace Plasmoid {

class SettingsDialog;
Expand Down Expand Up @@ -171,9 +178,14 @@ private Q_SLOTS:
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
void handleSystemdStatusChanged();
#endif
void handleImageProviderDestroyed();
void handleThemeChanged();
void setPassive(bool passive);

private:
Plasma::Theme m_theme;
QPalette m_palette;
Data::IconManager &m_iconManager;
QtUtilities::AboutDialog *m_aboutDlg;
Data::SyncthingConnection m_connection;
Data::SyncthingOverallDirStatistics m_overallStats;
Expand All @@ -192,6 +204,7 @@ private Q_SLOTS:
SettingsDialog *m_settingsDlg;
QtGui::DBusStatusNotifier m_dbusNotifier;
std::vector<Data::SyncthingLogEntry> m_notifications;
QtForkAwesome::QuickImageProvider *m_imageProvider;
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
QtGui::WebViewDialog *m_webViewDlg;
#endif
Expand Down

0 comments on commit 3e38a99

Please sign in to comment.