QtCanpool 3.3.0
载入中...
搜索中...
未找到
qxthemepalette.cpp
浏览该文件的文档.
1
5#include "qxthemepalette.h"
6
7#include <QtGui/QColor>
8
10
11namespace
12{
13
15struct Scheme {
16 QColor window;
17 QColor base;
19 QColor button;
20 QColor text;
22 QColor highlight;
26};
27
34QPalette buildPalette(const Scheme &s)
35{
36 QPalette p;
37 p.setColor(QPalette::Window, s.window);
38 p.setColor(QPalette::WindowText, s.text);
39 p.setColor(QPalette::Base, s.base);
40 p.setColor(QPalette::AlternateBase, s.alternateBase);
41 p.setColor(QPalette::ToolTipBase, s.toolTipBase);
42 p.setColor(QPalette::ToolTipText, s.toolTipText);
43 p.setColor(QPalette::Text, s.text);
44 p.setColor(QPalette::Button, s.button);
45 p.setColor(QPalette::ButtonText, s.text);
46 p.setColor(QPalette::BrightText, s.highlightText);
47 p.setColor(QPalette::Light, s.window.lighter(130));
48 p.setColor(QPalette::Midlight, s.window.lighter(115));
49 p.setColor(QPalette::Mid, s.window.darker(115));
50 p.setColor(QPalette::Dark, s.window.darker(150));
51 p.setColor(QPalette::Shadow, s.window.darker(200));
52 p.setColor(QPalette::Highlight, s.highlight);
53 p.setColor(QPalette::HighlightedText, s.highlightText);
54 p.setColor(QPalette::Link, s.highlight);
55 p.setColor(QPalette::LinkVisited, s.highlight.darker(120));
56#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
57 p.setColor(QPalette::PlaceholderText, s.textDisabled);
58#endif
59
60 // Disabled group: the style sheets mostly do not cover it, so the palette
61 // has to provide readable-but-muted text.
62 p.setColor(QPalette::Disabled, QPalette::WindowText, s.textDisabled);
63 p.setColor(QPalette::Disabled, QPalette::Text, s.textDisabled);
64 p.setColor(QPalette::Disabled, QPalette::ButtonText, s.textDisabled);
65 p.setColor(QPalette::Disabled, QPalette::ToolTipText, s.textDisabled);
66 p.setColor(QPalette::Disabled, QPalette::HighlightedText, s.textDisabled);
67 return p;
68}
69
70const Scheme kLightScheme = {
71 QColor(0xf5, 0xf5, 0xf5), // window
72 QColor(0xff, 0xff, 0xff), // base
73 QColor(0xf5, 0xf5, 0xf5), // alternateBase
74 QColor(0xf5, 0xf5, 0xf5), // button
75 QColor(0x0f, 0x0f, 0x0f), // text
76 QColor(0xa0, 0xa0, 0xa0), // textDisabled
77 QColor(0x00, 0x78, 0xd4), // highlight
78 QColor(0xff, 0xff, 0xff), // highlightText
79 QColor(0xff, 0xff, 0xff), // toolTipBase
80 QColor(0x0f, 0x0f, 0x0f), // toolTipText
81};
82
83const Scheme kDarkScheme = {
84 QColor(0x29, 0x29, 0x29), // window
85 QColor(0x23, 0x28, 0x2c), // base
86 QColor(0x29, 0x29, 0x29), // alternateBase
87 QColor(0x29, 0x29, 0x29), // button
88 QColor(0xf0, 0xf0, 0xf0), // text
89 QColor(0xa0, 0xa0, 0xa0), // textDisabled
90 QColor(0x00, 0x78, 0xd4), // highlight
91 QColor(0xff, 0xff, 0xff), // highlightText
92 QColor(0x23, 0x28, 0x2c), // toolTipBase
93 QColor(0xf0, 0xf0, 0xf0), // toolTipText
94};
95
96} // namespace
97
98QPalette lightPalette()
99{
100 return buildPalette(kLightScheme);
101}
102
103QPalette darkPalette()
104{
105 return buildPalette(kDarkScheme);
106}
107
108QPalette palette(Theme theme)
109{
110 return isDarkTheme(theme) ? darkPalette() : lightPalette();
111}
112
bool isDarkTheme(Theme theme)
True for the themes that draw on a dark background.
Definition qxtheme.cpp:78
QPalette lightPalette()
The palette that backs the light themes.
QPalette darkPalette()
The palette that backs the dark themes.
Theme
The themes understood by QxThemeManager.
Definition qxtheme.h:22
QPalette palette(Theme theme)
Palette matching theme: the dark palette for DarkWps / DarkOfficePlus, the light one otherwise.
#define QX_THEME_BEGIN_NAMESPACE
#define QX_THEME_END_NAMESPACE
QColor textDisabled
QColor toolTipBase
QColor base
QColor highlightText
QColor text
QColor highlight
QColor window
QColor toolTipText
QColor button
QColor alternateBase