Improve theme colour contrast.

Fixes #4407
Fixes #4637

Additional changes:
- Fix reference entry colour being incompatible with dark themes
- Fix QWizard page being too bright in dark mode
- Prevent unfocused wheel scroll changes to theme setting
This commit is contained in:
Janek Bevendorff 2020-03-07 00:58:56 +01:00
parent 1a3dc2145d
commit 8d2f7832ed
9 changed files with 82 additions and 53 deletions

View File

@ -125,6 +125,7 @@ ApplicationSettingsWidget::ApplicationSettingsWidget(QWidget* parent)
m_generalUi->faviconTimeoutSpinBox->installEventFilter(mouseWheelFilter);
m_generalUi->toolButtonStyleComboBox->installEventFilter(mouseWheelFilter);
m_generalUi->languageComboBox->installEventFilter(mouseWheelFilter);
m_generalUi->appThemeSelection->installEventFilter(mouseWheelFilter);
#ifdef WITH_XC_UPDATECHECK
connect(m_generalUi->checkForUpdatesOnStartupCheckBox, SIGNAL(toggled(bool)), SLOT(checkUpdatesToggled(bool)));

View File

@ -395,7 +395,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0,0,1">
<item>
<widget class="QLabel" name="appThemeLabel">
<property name="text">
@ -411,6 +411,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="accessibleName">
<string>Application Theme Selection</string>
</property>

View File

@ -283,12 +283,11 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
foregroundColor.setNamedColor(entry->foregroundColor());
if (entry->hasReferences()) {
QPalette p;
#ifdef Q_OS_MACOS
if (macUtils()->isDarkMode()) {
return QVariant(p.color(QPalette::Inactive, QPalette::Dark));
}
#endif
return QVariant(p.color(QPalette::Active, QPalette::Mid));
foregroundColor = p.color(QPalette::Current, QPalette::Text);
int lightness =
qMin(255, qMax(0, foregroundColor.lightness() + (foregroundColor.lightness() < 110 ? 85 : -51)));
foregroundColor.setHsl(foregroundColor.hue(), foregroundColor.saturation(), lightness);
return QVariant(foregroundColor);
} else if (foregroundColor.isValid()) {
return QVariant(foregroundColor);
}

View File

@ -173,6 +173,12 @@ namespace Phantom
hsl.l = std::pow(Phantom::saturate(std::pow(hsl.l, 1.0 / gamma) + ld * 0.8), gamma);
return hsl.toQColor();
}
bool hack_isLightPalette(const QPalette& pal)
{
Hsl hsl0 = Hsl::ofQColor(pal.color(QPalette::WindowText));
Hsl hsl1 = Hsl::ofQColor(pal.color(QPalette::Window));
return hsl0.l < hsl1.l;
}
QColor buttonColor(const QPalette& pal)
{
// temp hack
@ -246,8 +252,11 @@ namespace Phantom
}
QColor indicatorColorOf(const QPalette& palette, QPalette::ColorGroup group = QPalette::Current)
{
return Grad(palette.color(group, QPalette::WindowText), palette.color(group, QPalette::Button))
.sample(0.45);
if (hack_isLightPalette(palette)) {
qreal adjust = (palette.currentColorGroup() == QPalette::Disabled) ? 0.09 : 0.32;
return adjustLightness(palette.color(group, QPalette::WindowText), adjust);
}
return adjustLightness(palette.color(group, QPalette::WindowText), -0.05);
}
QColor inactiveTabFillColorOf(const QColor& underlying)
{
@ -266,12 +275,6 @@ namespace Phantom
{
return adjustLightness(pal.color(QPalette::Highlight), -0.15);
}
bool hack_isLightPalette(const QPalette& pal)
{
Hsl hsl0 = Hsl::ofQColor(pal.color(QPalette::WindowText));
Hsl hsl1 = Hsl::ofQColor(pal.color(QPalette::Window));
return hsl0.l < hsl1.l;
}
QColor itemViewHeaderOnLineColorOf(const QPalette& pal)
{
return hack_isLightPalette(pal)
@ -293,6 +296,7 @@ namespace Phantom
S_highlight,
S_highlightedText,
S_scrollbarGutter,
S_scrollbarSlider,
S_window_outline,
S_window_specular,
S_window_divider,
@ -397,6 +401,7 @@ namespace Phantom
colors[S_highlight] = pal.color(QPalette::Highlight);
colors[S_highlightedText] = pal.color(QPalette::HighlightedText);
colors[S_scrollbarGutter] = isLight ? Dc::gutterColorOf(pal) : Dc::darkGutterColorOf(pal);
colors[S_scrollbarSlider] = isLight ? colors[S_button] : Dc::adjustLightness(colors[S_window], 0.2);
colors[S_window_outline] =
isLight ? Dc::adjustLightness(colors[S_window], -0.1) : Dc::adjustLightness(colors[S_window], 0.03);
@ -422,10 +427,10 @@ namespace Phantom
: Dc::lightSpecularOf(colors[S_sliderHandle_pressed]);
colors[S_base_shadow] = Dc::overhangShadowOf(colors[S_base]);
colors[S_base_divider] = Dc::dividerColor(colors[S_base]);
colors[S_base_divider] = colors[S_window_divider];
colors[S_windowText_disabled] = pal.color(QPalette::Disabled, QPalette::WindowText);
colors[S_highlight_outline] = isLight ? Dc::adjustLightness(colors[S_highlight], -0.02)
: Dc::adjustLightness(colors[S_highlight], 0.02);
: Dc::adjustLightness(colors[S_highlight], 0.05);
colors[S_highlight_specular] = Dc::specularOf(colors[S_highlight]);
colors[S_progressBar_outline] = Dc::progressBarOutlineColorOf(pal);
colors[S_inactiveTabYesFrame] = Dc::inactiveTabFillColorOf(colors[S_tabFrame]);
@ -1087,14 +1092,19 @@ namespace Phantom
// for parts of widgets which may want to be drawn as disabled even if the
// actual widget is not set as disabled, such as scrollbar step buttons when
// the scrollbar has no movable range.
Q_NEVER_INLINE void
drawArrow(QPainter* painter, QRect rect, Qt::ArrowType type, const PhSwatch& swatch, bool allowEnabled = true)
Q_NEVER_INLINE void drawArrow(QPainter* painter,
QRect rect,
Qt::ArrowType type,
const PhSwatch& swatch,
bool allowEnabled = true,
qreal lightnessAdjustment = 0.0)
{
if (rect.isEmpty())
return;
using namespace SwatchColors;
Phantom::drawArrow(
painter, rect, type, swatch.brush(allowEnabled ? S_indicator_current : S_indicator_disabled));
auto brush = swatch.brush(allowEnabled ? S_indicator_current : S_indicator_disabled);
brush.setColor(DeriveColors::adjustLightness(brush.color(), lightnessAdjustment));
Phantom::drawArrow(painter, rect, type, brush);
}
// This draws exactly within the rect provided. If you provide a square rect,
@ -1659,10 +1669,11 @@ void BaseStyle::drawPrimitive(PrimitiveElement elem,
return;
QRect r = header->rect;
QPoint offset = QPoint(Phantom::HeaderSortIndicator_HOffset, Phantom::HeaderSortIndicator_VOffset);
qreal lightness = Phantom::DeriveColors::hack_isLightPalette(widget->palette()) ? 0.03 : 0.0;
if (header->sortIndicator & QStyleOptionHeader::SortUp) {
Ph::drawArrow(painter, r.translated(offset), Qt::DownArrow, swatch);
Ph::drawArrow(painter, r.translated(offset), Qt::DownArrow, swatch, true, lightness);
} else if (header->sortIndicator & QStyleOptionHeader::SortDown) {
Ph::drawArrow(painter, r.translated(offset), Qt::UpArrow, swatch);
Ph::drawArrow(painter, r.translated(offset), Qt::UpArrow, swatch, true, lightness);
}
break;
}
@ -2091,7 +2102,7 @@ void BaseStyle::drawPrimitive(PrimitiveElement elem,
thumbFill = S_button_pressed;
thumbSpecular = S_button_pressed_specular;
} else {
thumbFill = S_button;
thumbFill = S_scrollbarSlider;
thumbSpecular = S_button_specular;
}
Qt::Edges edges;
@ -3485,7 +3496,7 @@ void BaseStyle::drawComplexControl(ComplexControl control,
qreal radius =
(scrollBar->orientation == Qt::Horizontal ? scrollBarSlider.height() : scrollBarSlider.width()) / 2.0;
painter->fillRect(scrollBarSlider, swatch.color(S_window));
Ph::paintSolidRoundRect(painter, scrollBarSlider, radius, swatch, S_button);
Ph::paintSolidRoundRect(painter, scrollBarSlider, radius, swatch, S_scrollbarSlider);
}
// The SubLine (up/left) buttons

View File

@ -37,7 +37,7 @@ QGroupBox {
}
QGroupBox::title {
margin-top: -3.4em;
margin-top: -3.35em;
margin-left: -.4em;
subcontrol-origin: padding;
}

View File

@ -51,15 +51,15 @@ void DarkStyle::polish(QPalette& palette)
palette.setColor(QPalette::Inactive, QPalette::Base, QStringLiteral("#2A2A2D"));
palette.setColor(QPalette::Disabled, QPalette::Base, QStringLiteral("#343437"));
palette.setColor(QPalette::Active, QPalette::AlternateBase, QStringLiteral("#303036"));
palette.setColor(QPalette::Inactive, QPalette::AlternateBase, QStringLiteral("#333338"));
palette.setColor(QPalette::Active, QPalette::AlternateBase, QStringLiteral("#2C2C30"));
palette.setColor(QPalette::Inactive, QPalette::AlternateBase, QStringLiteral("#2B2B2F"));
palette.setColor(QPalette::Disabled, QPalette::AlternateBase, QStringLiteral("#36363A"));
palette.setColor(QPalette::All, QPalette::ToolTipBase, QStringLiteral("#2D532D"));
palette.setColor(QPalette::All, QPalette::ToolTipText, QStringLiteral("#BFBFBF"));
palette.setColor(QPalette::Active, QPalette::Button, QStringLiteral("#28282B"));
palette.setColor(QPalette::Inactive, QPalette::Button, QStringLiteral("#2B2B2E"));
palette.setColor(QPalette::Inactive, QPalette::Button, QStringLiteral("#28282B"));
palette.setColor(QPalette::Disabled, QPalette::Button, QStringLiteral("#2B2A2A"));
palette.setColor(QPalette::Active, QPalette::ButtonText, QStringLiteral("#B9B9BE"));
@ -67,11 +67,11 @@ void DarkStyle::polish(QPalette& palette)
palette.setColor(QPalette::Disabled, QPalette::ButtonText, QStringLiteral("#73747E"));
palette.setColor(QPalette::Active, QPalette::Highlight, QStringLiteral("#2D532D"));
palette.setColor(QPalette::Inactive, QPalette::Highlight, QStringLiteral("#294C29"));
palette.setColor(QPalette::Inactive, QPalette::Highlight, QStringLiteral("#354637"));
palette.setColor(QPalette::Disabled, QPalette::Highlight, QStringLiteral("#293D29"));
palette.setColor(QPalette::Active, QPalette::HighlightedText, QStringLiteral("#CCCCCC"));
palette.setColor(QPalette::Inactive, QPalette::HighlightedText, QStringLiteral("#C7C7C7"));
palette.setColor(QPalette::Inactive, QPalette::HighlightedText, QStringLiteral("#CECECE"));
palette.setColor(QPalette::Disabled, QPalette::HighlightedText, QStringLiteral("#707070"));
palette.setColor(QPalette::All, QPalette::Light, QStringLiteral("#414145"));
@ -80,10 +80,10 @@ void DarkStyle::polish(QPalette& palette)
palette.setColor(QPalette::All, QPalette::Dark, QStringLiteral("#202022"));
palette.setColor(QPalette::All, QPalette::Shadow, QStringLiteral("#19191A"));
palette.setColor(QPalette::All, QPalette::Link, QStringLiteral("#6BAE6B"));
palette.setColor(QPalette::Disabled, QPalette::Link, QStringLiteral("#9DE9D"));
palette.setColor(QPalette::All, QPalette::LinkVisited, QStringLiteral("#70A970"));
palette.setColor(QPalette::Disabled, QPalette::LinkVisited, QStringLiteral("#98A998"));
palette.setColor(QPalette::All, QPalette::Link, QStringLiteral("#68B668"));
palette.setColor(QPalette::Disabled, QPalette::Link, QStringLiteral("#74A474"));
palette.setColor(QPalette::All, QPalette::LinkVisited, QStringLiteral("#75B875"));
palette.setColor(QPalette::Disabled, QPalette::LinkVisited, QStringLiteral("#77A677"));
}
QString DarkStyle::getAppStyleSheet() const

View File

@ -49,31 +49,31 @@ void LightStyle::polish(QPalette& palette)
palette.setColor(QPalette::Disabled, QPalette::BrightText, QStringLiteral("#E4E5E7"));
palette.setColor(QPalette::Active, QPalette::Base, QStringLiteral("#F9F9F9"));
palette.setColor(QPalette::Inactive, QPalette::Base, QStringLiteral("#F5F5F4"));
palette.setColor(QPalette::Inactive, QPalette::Base, QStringLiteral("#FCFCFC"));
palette.setColor(QPalette::Disabled, QPalette::Base, QStringLiteral("#EFEFF2"));
palette.setColor(QPalette::Active, QPalette::AlternateBase, QStringLiteral("#ECF3E8"));
palette.setColor(QPalette::Inactive, QPalette::AlternateBase, QStringLiteral("#EAF2E6"));
palette.setColor(QPalette::Inactive, QPalette::AlternateBase, QStringLiteral("#F1F6EE"));
palette.setColor(QPalette::Disabled, QPalette::AlternateBase, QStringLiteral("#E1E9DD"));
palette.setColor(QPalette::All, QPalette::ToolTipBase, QStringLiteral("#548C1D"));
palette.setColor(QPalette::All, QPalette::ToolTipText, QStringLiteral("#F7F7F7"));
palette.setColor(QPalette::All, QPalette::ToolTipBase, QStringLiteral("#4D7F1A"));
palette.setColor(QPalette::All, QPalette::ToolTipText, QStringLiteral("#F9F9F9"));
palette.setColor(QPalette::Active, QPalette::Button, QStringLiteral("#D4D5DD"));
palette.setColor(QPalette::Inactive, QPalette::Button, QStringLiteral("#DCDCE0"));
palette.setColor(QPalette::Disabled, QPalette::Button, QStringLiteral("#E5E5E6"));
palette.setColor(QPalette::Active, QPalette::ButtonText, QStringLiteral("#181A18"));
palette.setColor(QPalette::Inactive, QPalette::ButtonText, QStringLiteral("#5F6671"));
palette.setColor(QPalette::Inactive, QPalette::ButtonText, QStringLiteral("#454A54"));
palette.setColor(QPalette::Disabled, QPalette::ButtonText, QStringLiteral("#97979B"));
palette.setColor(QPalette::Active, QPalette::Highlight, QStringLiteral("#549712"));
palette.setColor(QPalette::Inactive, QPalette::Highlight, QStringLiteral("#528D16"));
palette.setColor(QPalette::Disabled, QPalette::Highlight, QStringLiteral("#6F9847"));
palette.setColor(QPalette::Active, QPalette::Highlight, QStringLiteral("#507F1F"));
palette.setColor(QPalette::Inactive, QPalette::Highlight, QStringLiteral("#A6BE8E"));
palette.setColor(QPalette::Disabled, QPalette::Highlight, QStringLiteral("#C3D5B4"));
palette.setColor(QPalette::Active, QPalette::HighlightedText, QStringLiteral("#FCFCFC"));
palette.setColor(QPalette::Inactive, QPalette::HighlightedText, QStringLiteral("#F2F2F2"));
palette.setColor(QPalette::Disabled, QPalette::HighlightedText, QStringLiteral("#D9D9D9"));
palette.setColor(QPalette::Active, QPalette::HighlightedText, QStringLiteral("#FFFFFF"));
palette.setColor(QPalette::Inactive, QPalette::HighlightedText, QStringLiteral("#252528"));
palette.setColor(QPalette::Disabled, QPalette::HighlightedText, QStringLiteral("#8C8C92"));
palette.setColor(QPalette::All, QPalette::Light, QStringLiteral("#F9F9F9"));
palette.setColor(QPalette::All, QPalette::Midlight, QStringLiteral("#E9E9EB"));
@ -81,10 +81,10 @@ void LightStyle::polish(QPalette& palette)
palette.setColor(QPalette::All, QPalette::Dark, QStringLiteral("#BBBBC2"));
palette.setColor(QPalette::All, QPalette::Shadow, QStringLiteral("#6C6D79"));
palette.setColor(QPalette::All, QPalette::Link, QStringLiteral("#429F14"));
palette.setColor(QPalette::Disabled, QPalette::Link, QStringLiteral("#949F8F"));
palette.setColor(QPalette::All, QPalette::LinkVisited, QStringLiteral("#3F8C17"));
palette.setColor(QPalette::Disabled, QPalette::LinkVisited, QStringLiteral("#838C7E"));
palette.setColor(QPalette::All, QPalette::Link, QStringLiteral("#4B7B19"));
palette.setColor(QPalette::Disabled, QPalette::Link, QStringLiteral("#4F6935"));
palette.setColor(QPalette::All, QPalette::LinkVisited, QStringLiteral("#507826"));
palette.setColor(QPalette::Disabled, QPalette::LinkVisited, QStringLiteral("#506935"));
}
QString LightStyle::getAppStyleSheet() const

View File

@ -9,10 +9,10 @@ EntryPreviewWidget QLineEdit:disabled, EntryPreviewWidget QTextEdit:disabled {
}
QGroupBox::title {
color: palette(highlight);
color: #4B7B19;
}
QToolTip {
color: #F7F7F7;
background-color: #548C1D;
color: #F9F9F9;
background-color: #4D7F1A;
}

View File

@ -26,6 +26,8 @@
#include "core/Resources.h"
#include "format/KeePass2.h"
#include <QFrame>
#include <QPalette>
#include <QVBoxLayout>
NewDatabaseWizard::NewDatabaseWizard(QWidget* parent)
@ -50,6 +52,19 @@ NewDatabaseWizard::NewDatabaseWizard(QWidget* parent)
Q_INIT_RESOURCE(wizard);
setPixmap(QWizard::BackgroundPixmap, QPixmap(":/wizard/background-pixmap.png"));
// Fix MacStyle QWizard page frame too bright in dark mode (QTBUG-70346, QTBUG-71696)
QPalette defaultPalette;
auto windowColor = defaultPalette.color(QPalette::Window);
windowColor.setAlpha(153);
auto baseColor = defaultPalette.color(QPalette::Base);
baseColor.setAlpha(153);
auto* pageFrame = findChildren<QFrame*>()[0];
auto framePalette = pageFrame->palette();
framePalette.setBrush(QPalette::Window, windowColor.lighter(120));
framePalette.setBrush(QPalette::Base, baseColor.lighter(120));
pageFrame->setPalette(framePalette);
}
NewDatabaseWizard::~NewDatabaseWizard()