forked from keepassxreboot/keepassxc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add central colour palette for widget states.
Hard-coded widget state colours (error, warning, health etc.) are replace by a central palette class, which also takes care of determining if KeePassXC is in dark or light mode. Colours expected to be used as background for normal text were tested for WCAG level A compliance. Health colours were adjusted for better harmony with the application theme and tested for sufficient contrast with a colour blindness simulator.
- Loading branch information
Showing
6 changed files
with
142 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (C) 2020 KeePassXC Team <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 or (at your option) | ||
* version 3 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "StateColorPalette.h" | ||
|
||
#include "gui/Application.h" | ||
|
||
StateColorPalette::StateColorPalette() | ||
{ | ||
if (kpxcApp->isDarkTheme()) { | ||
initDefaultPaletteDark(); | ||
} else { | ||
initDefaultPaletteLight(); | ||
} | ||
} | ||
|
||
void StateColorPalette::initDefaultPaletteLight() | ||
{ | ||
setColor(ColorRole::Error, QStringLiteral("#FF7D7D")); | ||
setColor(ColorRole::Warning, QStringLiteral("#FFD30F")); | ||
setColor(ColorRole::Info, QStringLiteral("#84D0E1")); | ||
setColor(ColorRole::Incomplete, QStringLiteral("#FFD30F")); | ||
|
||
setColor(ColorRole::HealthCritical, QStringLiteral("#C43F31")); | ||
setColor(ColorRole::HealthBad, QStringLiteral("#E07F16")); | ||
setColor(ColorRole::HealthWeak, QStringLiteral("#FFD30F")); | ||
setColor(ColorRole::HealthOk, QStringLiteral("#5EA10E")); | ||
setColor(ColorRole::HealthExcellent, QStringLiteral("#118f17")); | ||
} | ||
|
||
void StateColorPalette::initDefaultPaletteDark() | ||
{ | ||
setColor(ColorRole::Error, QStringLiteral("#802D2D")); | ||
setColor(ColorRole::Warning, QStringLiteral("#73682E")); | ||
setColor(ColorRole::Info, QStringLiteral("#207183")); | ||
setColor(ColorRole::Incomplete, QStringLiteral("#665124")); | ||
|
||
setColor(ColorRole::HealthCritical, QStringLiteral("#C43F31")); | ||
setColor(ColorRole::HealthBad, QStringLiteral("#DB9837")); | ||
setColor(ColorRole::HealthWeak, QStringLiteral("#F0C400")); | ||
setColor(ColorRole::HealthOk, QStringLiteral("#608A22")); | ||
setColor(ColorRole::HealthExcellent, QStringLiteral("#1F8023")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2020 KeePassXC Team <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 or (at your option) | ||
* version 3 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef KEEPASSXC_STATECOLORPALETTE_H | ||
#define KEEPASSXC_STATECOLORPALETTE_H | ||
|
||
#include <QColor> | ||
#include <QHash> | ||
#include <QObject> | ||
|
||
/** | ||
* Extended color palette for indicating custom widget states. | ||
*/ | ||
class StateColorPalette | ||
{ | ||
Q_GADGET | ||
|
||
public: | ||
StateColorPalette(); | ||
|
||
enum ColorRole | ||
{ | ||
Error, | ||
Warning, | ||
Info, | ||
Incomplete, | ||
HealthCritical, | ||
HealthBad, | ||
HealthPoor, | ||
HealthWeak, | ||
HealthOk, | ||
HealthExcellent | ||
}; | ||
|
||
inline void setColor(ColorRole role, const QColor& color) | ||
{ | ||
m_colorMap[role] = color; | ||
} | ||
|
||
inline QColor color(ColorRole role) const | ||
{ | ||
return m_colorMap.value(role); | ||
} | ||
|
||
private: | ||
void initDefaultPaletteLight(); | ||
void initDefaultPaletteDark(); | ||
|
||
QHash<ColorRole, QColor> m_colorMap; | ||
}; | ||
|
||
#endif // KEEPASSXC_STATECOLORPALETTE_H |