1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <IconThemeSelector.hxx>
#include <QtCustomStyle.hxx>
#include <QtFrame.hxx>
#include <QtWidgets/qdrawutil.h>
#include <QtWidgets/QApplication>
#include <vcl/themecolors.hxx>
#include <vcl/qt/QtUtils.hxx>
void QtCustomStyle::drawPrimitive(PrimitiveElement element, const QStyleOption* option,
QPainter* painter, const QWidget* widget) const
{
if (!ThemeColors::IsThemeLoaded() || IsSystemThemeChanged())
{
QProxyStyle::drawPrimitive(element, option, painter, widget);
return;
}
const ThemeColors& aThemeColors = ThemeColors::GetThemeColors();
switch (element)
{
case PE_FrameTabWidget:
{
painter->save();
QBrush aFillBrush(toQColor(aThemeColors.GetWindowColor()));
QStyleOption aOpt = *option;
qDrawWinPanel(painter, option->rect, option->palette, false, &aFillBrush);
painter->restore();
break;
}
case PE_FrameFocusRect:
break;
default:
QProxyStyle::drawPrimitive(element, option, painter, widget);
}
}
QPalette QtCustomStyle::customPalette()
{
if (!ThemeColors::IsThemeLoaded())
return QApplication::palette();
const ThemeColors& aThemeColors = ThemeColors::GetThemeColors();
QPalette aPal;
aPal.setColor(QPalette::Base, toQColor(aThemeColors.GetBaseColor()));
aPal.setColor(QPalette::Window, toQColor(aThemeColors.GetWindowColor()));
aPal.setColor(QPalette::WindowText, toQColor(aThemeColors.GetWindowTextColor()));
aPal.setColor(QPalette::Disabled, QPalette::WindowText,
toQColor(aThemeColors.GetSeparatorColor()));
aPal.setColor(QPalette::Text, toQColor(aThemeColors.GetButtonTextColor()));
aPal.setColor(QPalette::ButtonText, toQColor(aThemeColors.GetButtonTextColor()));
aPal.setColor(QPalette::Disabled, QPalette::ButtonText,
toQColor(aThemeColors.GetDisabledTextColor()));
aPal.setColor(QPalette::PlaceholderText, toQColor(aThemeColors.GetWindowTextColor()));
aPal.setColor(QPalette::Button, toQColor(aThemeColors.GetButtonColor()));
aPal.setColor(QPalette::Highlight, toQColor(aThemeColors.GetAccentColor()));
aPal.setColor(QPalette::Dark, toQColor(aThemeColors.GetShadeColor()));
aPal.setColor(QPalette::Midlight, toQColor(aThemeColors.GetShadeColor()));
aPal.setColor(QPalette::Light, toQColor(aThemeColors.GetWindowColor()));
aPal.setColor(QPalette::Shadow, toQColor(aThemeColors.GetWindowColor()));
return aPal;
}
QPalette QtCustomStyle::GetMenuBarPalette()
{
if (!ThemeColors::IsThemeLoaded() || IsSystemThemeChanged())
return QApplication::palette();
QPalette aPal;
const ThemeColors& aThemeColors = ThemeColors::GetThemeColors();
aPal.setColor(QPalette::Text, toQColor(aThemeColors.GetMenuBarTextColor()));
aPal.setColor(QPalette::ButtonText, toQColor(aThemeColors.GetMenuBarTextColor()));
aPal.setColor(QPalette::Window, toQColor(aThemeColors.GetMenuBarColor()));
aPal.setColor(QPalette::Highlight, toQColor(aThemeColors.GetMenuBarHighlightColor()));
aPal.setColor(QPalette::HighlightedText, toQColor(aThemeColors.GetMenuBarHighlightTextColor()));
return aPal;
}
QPalette QtCustomStyle::GetMenuPalette()
{
if (!ThemeColors::IsThemeLoaded() || IsSystemThemeChanged())
return QApplication::palette();
QPalette aPal;
const ThemeColors& aThemeColors = ThemeColors::GetThemeColors();
aPal.setColor(QPalette::Base, toQColor(aThemeColors.GetMenuColor()));
aPal.setColor(QPalette::Highlight, toQColor(aThemeColors.GetMenuHighlightColor()));
aPal.setColor(QPalette::HighlightedText, toQColor(aThemeColors.GetMenuHighlightTextColor()));
aPal.setColor(QPalette::Disabled, QPalette::WindowText,
toQColor(aThemeColors.GetDisabledTextColor()));
aPal.setColor(QPalette::Window, toQColor(aThemeColors.GetMenuColor()));
aPal.setColor(QPalette::Text, toQColor(aThemeColors.GetMenuTextColor()));
aPal.setColor(QPalette::Disabled, QPalette::Text,
toQColor(aThemeColors.GetDisabledTextColor()));
aPal.setColor(QPalette::ButtonText, toQColor(aThemeColors.GetMenuTextColor()));
aPal.setColor(QPalette::WindowText, toQColor(aThemeColors.GetMenuTextColor()));
aPal.setColor(QPalette::Button, toQColor(aThemeColors.GetButtonColor()));
aPal.setColor(QPalette::Disabled, QPalette::ButtonText,
toQColor(aThemeColors.GetDisabledTextColor()));
aPal.setColor(QPalette::Dark, toQColor(aThemeColors.GetMenuColor()));
aPal.setColor(QPalette::Midlight, toQColor(aThemeColors.GetMenuColor()));
aPal.setColor(QPalette::Light, toQColor(aThemeColors.GetMenuColor()));
aPal.setColor(QPalette::Shadow, toQColor(aThemeColors.GetMenuColor()));
return aPal;
}
bool QtCustomStyle::IsSystemThemeChanged()
{
return QApplication::palette() != QtCustomStyle::customPalette();
}
void QtCustomStyle::LoadCustomStyle(bool bDarkMode)
{
if (!ThemeColors::IsThemeLoaded()
|| ThemeColors::IsAutomaticTheme(ThemeColors::GetThemeColors().GetThemeName()))
return;
// don't set custom palette in case the system theme has been changed.
if (!(m_bIsCustomStyleSet && IsSystemThemeChanged()))
QApplication::setPalette(QtCustomStyle::customPalette());
QIcon::setThemeName(toQString(vcl::IconThemeSelector::GetIconThemeForDesktopEnvironment(
Application::GetDesktopEnvironment(), bDarkMode)));
if (m_bIsCustomStyleSet)
return;
QApplication::setStyle(new QtCustomStyle);
m_bIsCustomStyleSet = true;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|