diff options
author | Janek Bevendorff <janek@jbev.net> | 2020-10-14 21:45:24 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2020-10-15 06:55:01 +0300 |
commit | 389899e0c62c399036e2fd3d35f4145523cd30fe (patch) | |
tree | 4fcbd837c4b26ddd26b302099d99577db6e72a41 | |
parent | b0e038e7891efbcab073ff66c72932aeb09cf687 (diff) |
Fix theme issues on macOS
* Fix #5025 - Change edit entry widget title separator to the common bullet character • (U+2022)
* Fix #5307 and Fix #5347 - Remove transparent toolbar/window on macOS and properly color text in toolbar.
-rw-r--r-- | src/gui/MainWindow.cpp | 3 | ||||
-rw-r--r-- | src/gui/entry/EditEntryWidget.cpp | 6 | ||||
-rw-r--r-- | src/gui/osutils/macutils/AppKit.h | 1 | ||||
-rw-r--r-- | src/gui/styles/base/BaseStyle.cpp | 45 | ||||
-rw-r--r-- | src/gui/styles/base/BaseStyle.h | 9 | ||||
-rw-r--r-- | src/gui/styles/dark/DarkStyle.cpp | 19 | ||||
-rw-r--r-- | src/gui/styles/dark/DarkStyle.h | 1 | ||||
-rw-r--r-- | src/gui/styles/light/LightStyle.cpp | 19 | ||||
-rw-r--r-- | src/gui/styles/light/LightStyle.h | 1 | ||||
-rw-r--r-- | tests/gui/TestGui.cpp | 2 |
10 files changed, 84 insertions, 22 deletions
diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 49ab5abb2..f3a6e5831 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -499,9 +499,6 @@ MainWindow::MainWindow() #ifdef Q_OS_MACOS setUnifiedTitleAndToolBarOnMac(true); - if (macUtils()->isDarkMode()) { - setStyleSheet("QToolButton {color:white;}"); - } #endif #ifdef WITH_XC_UPDATECHECK diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 22105c4d2..680243280 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -800,12 +800,12 @@ void EditEntryWidget::loadEntry(Entry* entry, connect(m_entry, &Entry::entryModified, this, [this] { m_entryModifiedTimer.start(); }); if (history) { - setHeadline(QString("%1 \u2B29 %2").arg(parentName, tr("Entry history"))); + setHeadline(QString("%1 \u2022 %2").arg(parentName, tr("Entry history"))); } else { if (create) { - setHeadline(QString("%1 \u2B29 %2").arg(parentName, tr("Add entry"))); + setHeadline(QString("%1 \u2022 %2").arg(parentName, tr("Add entry"))); } else { - setHeadline(QString("%1 \u2B29 %2 \u2B29 %3").arg(parentName, entry->title(), tr("Edit entry"))); + setHeadline(QString("%1 \u2022 %2 \u2022 %3").arg(parentName, entry->title(), tr("Edit entry"))); } } diff --git a/src/gui/osutils/macutils/AppKit.h b/src/gui/osutils/macutils/AppKit.h index a6f7b3a12..02121683d 100644 --- a/src/gui/osutils/macutils/AppKit.h +++ b/src/gui/osutils/macutils/AppKit.h @@ -37,6 +37,7 @@ public: bool hideProcess(pid_t pid); bool isHidden(pid_t pid); bool isDarkMode(); + bool hasDarkMode(); bool enableAccessibility(); bool enableScreenRecording(); void toggleForegroundApp(bool foreground); diff --git a/src/gui/styles/base/BaseStyle.cpp b/src/gui/styles/base/BaseStyle.cpp index 2c72f9bcc..104e1d4d9 100644 --- a/src/gui/styles/base/BaseStyle.cpp +++ b/src/gui/styles/base/BaseStyle.cpp @@ -284,6 +284,17 @@ namespace Phantom ? highlightedOutlineOf(pal) : Grad(pal.color(QPalette::WindowText), pal.color(QPalette::Window)).sample(0.5); } + +#ifdef Q_OS_MACOS + QColor tabBarBase(const QPalette& pal) + { + return hack_isLightPalette(pal) ? QRgb(0xD1D1D1) : QRgb(0x252525); + } + QColor tabBarBaseInactive(const QPalette& pal) + { + return hack_isLightPalette(pal) ? QRgb(0xF4F4F4) : QRgb(0x282828); + } +#endif } // namespace DeriveColors namespace SwatchColors @@ -330,6 +341,9 @@ namespace Phantom S_itemView_headerOnLine, S_scrollbarGutter_disabled, + S_tabBarBase, + S_tabBarBase_inactive, + // Aliases S_progressBar = S_highlight, S_progressBar_specular = S_highlight_specular, @@ -342,7 +356,7 @@ namespace Phantom enum { - Num_SwatchColors = SwatchColors::S_scrollbarGutter_disabled + 1, + Num_SwatchColors = SwatchColors::S_tabBarBase_inactive + 1, Num_ShadowSteps = 3, }; @@ -445,6 +459,14 @@ namespace Phantom colors[S_itemView_headerOnLine] = Dc::itemViewHeaderOnLineColorOf(pal); colors[S_scrollbarGutter_disabled] = colors[S_window]; +#ifdef Q_OS_MACOS + colors[S_tabBarBase] = Dc::tabBarBase(pal); + colors[S_tabBarBase_inactive] = Dc::tabBarBaseInactive(pal); +#else + colors[S_tabBarBase] = pal.color(QPalette::Active, QPalette::Window); + colors[S_tabBarBase_inactive] = pal.color(QPalette::Inactive, QPalette::Window); +#endif + brushes[S_none] = Qt::NoBrush; for (int i = S_none + 1; i < Num_SwatchColors; ++i) { // todo try to reuse @@ -1553,6 +1575,12 @@ void BaseStyle::drawPrimitive(PrimitiveElement elem, auto tbb = qstyleoption_cast<const QStyleOptionTabBarBase*>(option); if (!tbb) break; + +#ifdef Q_OS_MACOS + painter->fillRect(widget->rect(), + swatch.color(option->state & QStyle::State_Active ? S_tabBarBase : S_tabBarBase_inactive)); +#endif + Qt::Edge edge = Qt::TopEdge; switch (tbb->shape) { case QTabBar::RoundedNorth: @@ -2255,6 +2283,21 @@ void BaseStyle::drawControl(ControlElement element, auto toolBar = qstyleoption_cast<const QStyleOptionToolBar*>(option); if (!toolBar) break; + +#ifdef Q_OS_MACOS + if (auto* mainWindow = qobject_cast<QMainWindow*>(widget->window())) { + // Fill toolbar background with transparent pixels to reveal the + // gradient background drawn by the Cocoa platform plugin. + // Inspired by qmacstyle_mac.mm. + if (m_drawNativeMacOsToolBar && toolBar && toolBar->toolBarArea == Qt::TopToolBarArea + && mainWindow->unifiedTitleAndToolBarOnMac()) { + painter->setCompositionMode(QPainter::CompositionMode_Source); + painter->fillRect(option->rect, Qt::transparent); + break; + } + } +#endif + painter->fillRect(option->rect, option->palette.window().color()); bool isFloating = false; if (auto tb = qobject_cast<const QToolBar*>(widget)) { diff --git a/src/gui/styles/base/BaseStyle.h b/src/gui/styles/base/BaseStyle.h index 86d81b44b..d3c20915c 100644 --- a/src/gui/styles/base/BaseStyle.h +++ b/src/gui/styles/base/BaseStyle.h @@ -97,6 +97,15 @@ protected: return {}; } +#ifdef Q_OS_MACOS + /** + * Whether to draw a native macOS toolbar or fill it with a solid color instead. + * Can be set to false to avoid mixed themes if the OS theme isn't the same as + * the KeePassXC application theme. + */ + bool m_drawNativeMacOsToolBar = true; +#endif + BaseStylePrivate* d; }; diff --git a/src/gui/styles/dark/DarkStyle.cpp b/src/gui/styles/dark/DarkStyle.cpp index b8e548228..25f75e5ab 100644 --- a/src/gui/styles/dark/DarkStyle.cpp +++ b/src/gui/styles/dark/DarkStyle.cpp @@ -23,6 +23,14 @@ #include <QMenuBar> #include <QToolBar> +DarkStyle::DarkStyle() + : BaseStyle() +{ +#ifdef Q_OS_MACOS + m_drawNativeMacOsToolBar = osUtils->isDarkMode(); +#endif +} + QPalette DarkStyle::standardPalette() const { auto palette = BaseStyle::standardPalette(); @@ -105,13 +113,10 @@ void DarkStyle::polish(QWidget* widget) || qobject_cast<QToolBar*>(widget)) { auto palette = widget->palette(); #if defined(Q_OS_MACOS) - if (osUtils->isDarkMode()) { - // Let the Cocoa platform plugin draw its own background - palette.setColor(QPalette::All, QPalette::Window, Qt::transparent); - } else { - palette.setColor(QPalette::Active, QPalette::Window, QRgb(0x2A2A2A)); - palette.setColor(QPalette::Inactive, QPalette::Window, QRgb(0x2D2D2D)); - palette.setColor(QPalette::Disabled, QPalette::Window, QRgb(0x2A2A2A)); + if (!osUtils->isDarkMode()) { + palette.setColor(QPalette::Active, QPalette::Window, QRgb(0x252525)); + palette.setColor(QPalette::Inactive, QPalette::Window, QRgb(0x282828)); + palette.setColor(QPalette::Disabled, QPalette::Window, QRgb(0x252525)); } #elif defined(Q_OS_WIN) // Register event filter for better dark mode support diff --git a/src/gui/styles/dark/DarkStyle.h b/src/gui/styles/dark/DarkStyle.h index 9b955d3a5..3de05c065 100644 --- a/src/gui/styles/dark/DarkStyle.h +++ b/src/gui/styles/dark/DarkStyle.h @@ -26,6 +26,7 @@ class DarkStyle : public BaseStyle Q_OBJECT public: + DarkStyle(); QPalette standardPalette() const override; using BaseStyle::polish; diff --git a/src/gui/styles/light/LightStyle.cpp b/src/gui/styles/light/LightStyle.cpp index 8dd9d6c53..f1f0cb997 100644 --- a/src/gui/styles/light/LightStyle.cpp +++ b/src/gui/styles/light/LightStyle.cpp @@ -24,6 +24,14 @@ #include <QMenuBar> #include <QToolBar> +LightStyle::LightStyle() + : BaseStyle() +{ +#ifdef Q_OS_MACOS + m_drawNativeMacOsToolBar = !osUtils->isDarkMode(); +#endif +} + QPalette LightStyle::standardPalette() const { auto palette = BaseStyle::standardPalette(); @@ -106,13 +114,10 @@ void LightStyle::polish(QWidget* widget) || qobject_cast<QToolBar*>(widget)) { auto palette = widget->palette(); #if defined(Q_OS_MACOS) - if (!osUtils->isDarkMode()) { - // Let the Cocoa platform plugin draw its own background - palette.setColor(QPalette::All, QPalette::Window, Qt::transparent); - } else { - palette.setColor(QPalette::Active, QPalette::Window, QRgb(0xD6D6D6)); - palette.setColor(QPalette::Inactive, QPalette::Window, QRgb(0xF6F6F6)); - palette.setColor(QPalette::Disabled, QPalette::Window, QRgb(0xD4D4D4)); + if (osUtils->isDarkMode()) { + palette.setColor(QPalette::Active, QPalette::Window, QRgb(0xD1D1D1)); + palette.setColor(QPalette::Inactive, QPalette::Window, QRgb(0xF4F4F4)); + palette.setColor(QPalette::Disabled, QPalette::Window, QRgb(0xD1D1D1)); } #elif defined(Q_OS_WIN) palette.setColor(QPalette::All, QPalette::Window, QRgb(0xFFFFFF)); diff --git a/src/gui/styles/light/LightStyle.h b/src/gui/styles/light/LightStyle.h index d2d4f48a3..87e202502 100644 --- a/src/gui/styles/light/LightStyle.h +++ b/src/gui/styles/light/LightStyle.h @@ -26,6 +26,7 @@ class LightStyle : public BaseStyle Q_OBJECT public: + LightStyle(); QPalette standardPalette() const override; using BaseStyle::polish; diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 060a29520..c79de84bb 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -575,7 +575,7 @@ void TestGui::testSearchEditEntry() // Check the path in header is "parent-group > entry" QCOMPARE(m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget")->findChild<QLabel*>("headerLabel")->text(), - QStringLiteral("Good \u2B29 Doggy \u2B29 Edit entry")); + QStringLiteral("Good \u2022 Doggy \u2022 Edit entry")); } void TestGui::testAddEntry() |