• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

PlasmaCore

  • sources
  • kde-4.14
  • kde-runtime
  • plasma
  • declarativeimports
  • core
theme.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Marco Martin <mart@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Library General Public License as
6  * published by the Free Software Foundation; either version 2, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include "theme.h"
21 
22 #include <QDeclarativePropertyMap>
23 
24 #include <KIconLoader>
25 
26 class FontProxySingleton
27 {
28 public:
29  FontProxySingleton()
30  : defaultFont(Plasma::Theme::DefaultFont),
31  desktopFont(Plasma::Theme::DesktopFont),
32  smallestFont(Plasma::Theme::SmallestFont)
33  {
34  }
35 
36  FontProxy defaultFont;
37  FontProxy desktopFont;
38  FontProxy smallestFont;
39 };
40 
41 K_GLOBAL_STATIC(FontProxySingleton, privateFontProxySingleton)
42 
43 FontProxy::FontProxy(Plasma::Theme::FontRole role, QObject *parent)
44  : QObject(parent),
45  m_fontRole(role)
46 {
47  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
48  this, SIGNAL(boldChanged()));
49  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
50  this, SIGNAL(capitalizationChanged()));
51  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
52  this, SIGNAL(familyChanged()));
53  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
54  this, SIGNAL(italicChanged()));
55  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
56  this, SIGNAL(letterSpacingChanged()));
57  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
58  this, SIGNAL(pixelSizeChanged()));
59  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
60  this, SIGNAL(pointSizeChanged()));
61  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
62  this, SIGNAL(strikeoutChanged()));
63  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
64  this, SIGNAL(underlineChanged()));
65  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
66  this, SIGNAL(weightChanged()));
67  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
68  this, SIGNAL(wordSpacingChanged()));
69  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
70  this, SIGNAL(mSizeChanged()));
71 }
72 
73 FontProxy::~FontProxy()
74 {
75 }
76 
77 FontProxy *FontProxy::defaultFont()
78 {
79  return &privateFontProxySingleton->defaultFont;
80 }
81 
82 FontProxy *FontProxy::desktopFont()
83 {
84  return &privateFontProxySingleton->desktopFont;
85 }
86 
87 FontProxy *FontProxy::smallestFont()
88 {
89  return &privateFontProxySingleton->smallestFont;
90 }
91 
92 bool FontProxy::bold() const
93 {
94  return Plasma::Theme::defaultTheme()->font(m_fontRole).bold();
95 }
96 
97 FontProxy::Capitalization FontProxy::capitalization() const
98 {
99  return (FontProxy::Capitalization)Plasma::Theme::defaultTheme()->font(m_fontRole).capitalization();
100 }
101 
102 QString FontProxy::family() const
103 {
104  return Plasma::Theme::defaultTheme()->font(m_fontRole).family();
105 }
106 
107 bool FontProxy::italic() const
108 {
109  return Plasma::Theme::defaultTheme()->font(m_fontRole).italic();
110 }
111 
112 qreal FontProxy::letterSpacing() const
113 {
114  return Plasma::Theme::defaultTheme()->font(m_fontRole).letterSpacing();
115 }
116 
117 int FontProxy::pixelSize() const
118 {
119  return Plasma::Theme::defaultTheme()->font(m_fontRole).pixelSize();
120 }
121 
122 qreal FontProxy::pointSize() const
123 {
124  return Plasma::Theme::defaultTheme()->font(m_fontRole).pointSizeF();
125 }
126 
127 bool FontProxy::strikeout() const
128 {
129  return Plasma::Theme::defaultTheme()->font(m_fontRole).strikeOut();
130 }
131 
132 bool FontProxy::underline() const
133 {
134  return Plasma::Theme::defaultTheme()->font(m_fontRole).underline();
135 }
136 
137 FontProxy::Weight FontProxy::weight() const
138 {
139  return (FontProxy::Weight)Plasma::Theme::defaultTheme()->font(m_fontRole).weight();
140 }
141 
142 qreal FontProxy::wordSpacing() const
143 {
144  return Plasma::Theme::defaultTheme()->font(m_fontRole).wordSpacing();
145 }
146 
147 QSize FontProxy::mSize() const
148 {
149  return QFontMetrics(Plasma::Theme::defaultTheme()->font(m_fontRole)).boundingRect("M").size();
150 }
151 
152 
153 //********** Theme *************
154 
155 ThemeProxy::ThemeProxy(QObject *parent)
156  : QObject(parent)
157 {
158  m_defaultIconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
159 
160  m_iconSizes = new QDeclarativePropertyMap(this);
161  m_iconSizes->insert("desktop", QVariant(KIconLoader::global()->currentSize(KIconLoader::Desktop)));
162  m_iconSizes->insert("panel", QVariant(KIconLoader::global()->currentSize(KIconLoader::Panel)));
163  m_iconSizes->insert("toolbar", KIconLoader::global()->currentSize(KIconLoader::Toolbar));
164  m_iconSizes->insert("small", KIconLoader::global()->currentSize(KIconLoader::Small));
165  m_iconSizes->insert("dialog", KIconLoader::global()->currentSize(KIconLoader::Dialog));
166 
167  connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SIGNAL(themeChanged()));
168  connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()), this, SLOT(iconLoaderSettingsChanged()));
169 }
170 
171 ThemeProxy::~ThemeProxy()
172 {
173 }
174 
175 QString ThemeProxy::themeName() const
176 {
177  return Plasma::Theme::defaultTheme()->themeName();
178 }
179 
180 QObject *ThemeProxy::defaultFont() const
181 {
182  return FontProxy::defaultFont();
183 }
184 
185 QObject *ThemeProxy::desktopFont() const
186 {
187  return FontProxy::desktopFont();
188 }
189 
190 QObject *ThemeProxy::smallestFont() const
191 {
192  return FontProxy::smallestFont();
193 }
194 
195 bool ThemeProxy::windowTranslucencyEnabled() const
196 {
197  return Plasma::Theme::defaultTheme()->windowTranslucencyEnabled();
198 }
199 
200 KUrl ThemeProxy::homepage() const
201 {
202  return Plasma::Theme::defaultTheme()->homepage();
203 }
204 
205 bool ThemeProxy::useGlobalSettings() const
206 {
207  return Plasma::Theme::defaultTheme()->useGlobalSettings();
208 }
209 
210 QString ThemeProxy::wallpaperPath() const
211 {
212  return Plasma::Theme::defaultTheme()->wallpaperPath();
213 }
214 
215 QString ThemeProxy::wallpaperPathForSize(int width, int height) const
216 {
217  return Plasma::Theme::defaultTheme()->wallpaperPath(QSize(width, height));
218 }
219 
220 QColor ThemeProxy::textColor() const
221 {
222  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
223 }
224 
225 QColor ThemeProxy::highlightColor() const
226 {
227  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::HighlightColor);
228 }
229 
230 QColor ThemeProxy::backgroundColor() const
231 {
232  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor);
233 }
234 
235 QColor ThemeProxy::buttonTextColor() const
236 {
237  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonTextColor);
238 }
239 
240 QColor ThemeProxy::buttonBackgroundColor() const
241 {
242  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonBackgroundColor);
243 }
244 
245 QColor ThemeProxy::linkColor() const
246 {
247  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::LinkColor);
248 }
249 
250 QColor ThemeProxy::visitedLinkColor() const
251 {
252  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::VisitedLinkColor);
253 }
254 
255 QColor ThemeProxy::buttonHoverColor() const
256 {
257  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonHoverColor);
258 }
259 
260 QColor ThemeProxy::buttonFocusColor() const
261 {
262  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonFocusColor);
263 }
264 
265 QColor ThemeProxy::viewTextColor() const
266 {
267  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::ViewTextColor);
268 }
269 
270 QColor ThemeProxy::viewBackgroundColor() const
271 {
272  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::ViewBackgroundColor);
273 }
274 
275 QColor ThemeProxy::viewHoverColor() const
276 {
277  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::ViewHoverColor);
278 }
279 
280 QColor ThemeProxy::viewFocusColor() const
281 {
282  return Plasma::Theme::defaultTheme()->color(Plasma::Theme::ViewFocusColor);
283 }
284 
285 QString ThemeProxy::styleSheet() const
286 {
287  return Plasma::Theme::defaultTheme()->styleSheet(QString());
288 }
289 
290 int ThemeProxy::smallIconSize() const
291 {
292  return KIconLoader::SizeSmall;
293 }
294 
295 int ThemeProxy::smallMediumIconSize() const
296 {
297  return KIconLoader::SizeSmallMedium;
298 }
299 
300 int ThemeProxy::mediumIconSize() const
301 {
302  return KIconLoader::SizeMedium;
303 }
304 
305 int ThemeProxy::largeIconSize() const
306 {
307  return KIconLoader::SizeLarge;
308 }
309 
310 int ThemeProxy::hugeIconSize() const
311 {
312  return KIconLoader::SizeHuge;
313 }
314 
315 int ThemeProxy::enormousIconSize() const
316 {
317  return KIconLoader::SizeEnormous;
318 }
319 
320 void ThemeProxy::iconLoaderSettingsChanged()
321 {
322  m_defaultIconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
323 
324  m_iconSizes->insert("desktop", QVariant(KIconLoader::global()->currentSize(KIconLoader::Desktop)));
325  m_iconSizes->insert("toolbar", KIconLoader::global()->currentSize(KIconLoader::Toolbar));
326  m_iconSizes->insert("small", KIconLoader::global()->currentSize(KIconLoader::Small));
327  m_iconSizes->insert("dialog", KIconLoader::global()->currentSize(KIconLoader::Dialog));
328 
329 
330  emit defaultIconSizeChanged();
331  emit iconSizesChanged();
332 }
333 
334 int ThemeProxy::defaultIconSize() const
335 {
336  return m_defaultIconSize;
337 }
338 
339 QDeclarativePropertyMap *ThemeProxy::iconSizes() const
340 {
341  return m_iconSizes;
342 }
343 
344 #include "theme.moc"
345 
ThemeProxy::~ThemeProxy
~ThemeProxy()
Definition: theme.cpp:171
QDeclarativePropertyMap
ThemeProxy::linkColor
QColor linkColor() const
QRect::size
QSize size() const
ThemeProxy::wallpaperPath
QString wallpaperPath() const
ThemeProxy::smallestFont
QObject * smallestFont() const
QDeclarativePropertyMap::insert
void insert(const QString &key, const QVariant &value)
FontProxy::italic
bool italic() const
theme.h
ThemeProxy::desktopFont
QObject * desktopFont() const
QFontMetrics
ThemeProxy::iconSizes
QDeclarativePropertyMap * iconSizes() const
FontProxy::wordSpacing
qreal wordSpacing() const
ThemeProxy::defaultIconSizeChanged
void defaultIconSizeChanged()
ThemeProxy::ThemeProxy
ThemeProxy(QObject *parent=0)
Definition: theme.cpp:155
FontProxy::pixelSize
int pixelSize() const
QFontMetrics::boundingRect
QRect boundingRect(QChar ch) const
ThemeProxy::mediumIconSize
int mediumIconSize() const
QObject
FontProxy::smallestFont
static FontProxy * smallestFont()
Definition: theme.cpp:87
ThemeProxy::highlightColor
QColor highlightColor() const
FontProxy::~FontProxy
~FontProxy()
Definition: theme.cpp:73
FontProxy::defaultFont
static FontProxy * defaultFont()
Definition: theme.cpp:77
QString
QColor
ThemeProxy::windowTranslucencyEnabled
bool windowTranslucencyEnabled() const
Definition: theme.cpp:195
FontProxy::Weight
Weight
Definition: theme.h:120
FontProxy::weight
Weight weight() const
FontProxy::Capitalization
Capitalization
Definition: theme.h:112
QSize
ThemeProxy::enormousIconSize
int enormousIconSize() const
ThemeProxy::hugeIconSize
int hugeIconSize() const
ThemeProxy::largeIconSize
int largeIconSize() const
FontProxy::bold
bool bold() const
ThemeProxy::useGlobalSettings
bool useGlobalSettings() const
FontProxy::desktopFont
static FontProxy * desktopFont()
Definition: theme.cpp:82
FontProxy::letterSpacing
qreal letterSpacing() const
ThemeProxy::wallpaperPathForSize
Q_INVOKABLE QString wallpaperPathForSize(int width=-1, int height=-1) const
Definition: theme.cpp:215
FontProxy::pointSize
qreal pointSize() const
FontProxy::underline
bool underline() const
FontProxy::mSize
QSize mSize() const
ThemeProxy::styleSheet
QString styleSheet() const
ThemeProxy::iconSizesChanged
void iconSizesChanged()
ThemeProxy::buttonTextColor
QColor buttonTextColor() const
ThemeProxy::backgroundColor
QColor backgroundColor() const
ThemeProxy::defaultFont
QObject * defaultFont() const
ThemeProxy::themeChanged
void themeChanged()
ThemeProxy::themeName
QString themeName() const
ThemeProxy::visitedLinkColor
QColor visitedLinkColor() const
FontProxy::capitalization
Capitalization capitalization() const
ThemeProxy::buttonFocusColor
QColor buttonFocusColor() const
ThemeProxy::viewHoverColor
QColor viewHoverColor() const
ThemeProxy::viewBackgroundColor
QColor viewBackgroundColor() const
FontProxy::strikeout
bool strikeout() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
ThemeProxy::buttonHoverColor
QColor buttonHoverColor() const
ThemeProxy::textColor
QColor textColor() const
ThemeProxy::smallMediumIconSize
int smallMediumIconSize() const
ThemeProxy::viewTextColor
QColor viewTextColor() const
FontProxy::family
QString family() const
ThemeProxy::smallIconSize
int smallIconSize() const
FontProxy
Definition: theme.h:33
ThemeProxy::homepage
KUrl homepage() const
ThemeProxy::viewFocusColor
QColor viewFocusColor() const
QVariant
ThemeProxy::defaultIconSize
int defaultIconSize() const
ThemeProxy::buttonBackgroundColor
QColor buttonBackgroundColor() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:28 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PlasmaCore

Skip menu "PlasmaCore"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal