libyui-qt
Loading...
Searching...
No Matches
QY2Styler.h
1/*
2 Copyright (C) 2000-2012 Novell, Inc
3 Copyright (C) 2022 SUSE LLC
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) version 3.0 of the License. This library
8 is distributed in the hope that it will be useful, but WITHOUT ANY
9 WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11 License for more details. You should have received a copy of the GNU
12 Lesser General Public License along with this library; if not, write
13 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
14 Floor, Boston, MA 02110-1301 USA
15*/
16
17
18/*-/
19
20 File: QY2Styler.h
21
22 Author: Stefan Kulow <coolo@suse.de>
23
24/-*/
25
26
27#ifndef QY2Styler_h
28#define QY2Styler_h
29
30#include <QObject>
31#include <QHash>
32#include <QString>
33#include <QImage>
34#include <QMap>
35
36class YWidget;
37
38#define HIGH_CONTRAST_STYLE_SHEET "highcontrast.qss"
39#define DEFAULT_STYLE_SHEET "style.qss"
40
41class QY2Styler : public QObject
42{
43 Q_OBJECT
44
45protected:
46
51 QY2Styler( QObject * parent,
52 const QString & defaultStyleSheet = "",
53 const QString & alternateStyleSheet = "" );
54
55public:
56
61 static QY2Styler * styler();
62
69 bool styleSheetExists( const QString & file );
70
77 bool loadStyleSheet( const QString & file );
78
84 void setStyleSheet( const QString & text );
85
95
105
109 QString themeDir() const;
110
114 QStringList allStyleSheets();
115
121 void registerWidget( QWidget *widget );
122
128 void unregisterWidget( QWidget *widget );
129
130
137 void registerChildWidget( QWidget *parent, QWidget *widget );
138
139 QString textStyle() const { return _textStyle; }
140
144 QString currentStyleSheet() const { return _currentStyleSheet; }
145
152 void setDefaultStyleSheet( const QString & styleSheet );
153
157 QString defaultStyleSheet() const { return _defaultStyleSheet; }
158
159
166 void setAlternateStyleSheet( const QString & styleSheet );
167
171 QString alternateStyleSheet() const { return _alternateStyleSheet; }
172
177
181 bool usingAlternateStyleSheet() { return _usingAlternateStyleSheet; }
182
183 bool updateRendering( QWidget * widget );
184
185
186protected:
187
188 void renderParent( QWidget * widget );
189 QImage getScaled( const QString & name, const QSize & size );
190
196 void processUrls( QString & text );
197
201 QString buildStyleSheet( const QString & content );
202
209 QString buildStyleSheet( const QString & content,
210 QStringList & alreadyImportedFilenames_ret );
211
218 QString buildStyleSheetFromFile( const QString & filename,
219 QStringList & alreadyImportedFilenames_ret );
220
226 void setRichTextStyleSheet(YWidget *widget);
227
228 /*
229 * Reimplemented from QObject.
230 **/
231 bool eventFilter( QObject * obj, QEvent * ev );
232
234 {
235 QString filename;
236 QImage pix;
237 QImage scaled;
238 QSize lastscale;
239 bool full;
240 };
241
242 //
243 // Data members
244 //
245
246 QString _currentStyleSheet;
247 QString _defaultStyleSheet = DEFAULT_STYLE_SHEET;
248 QString _alternateStyleSheet = HIGH_CONTRAST_STYLE_SHEET;
249 bool _usingAlternateStyleSheet = false;
250
251 QHash<QString,BackgrInfo> _backgrounds;
252 QMap<QWidget*, QList< QWidget* > > _children;
253
254 // store all registered widgets to allow styling not only for
255 // the explicitly requested children widgets (stored in _children)
256 QList< QWidget* > _registered_widgets;
257
258 QString _style;
259 QString _textStyle;
260};
261
262
263#endif // QY2Styler_h
Definition QY2Styler.h:42
bool loadAlternateStyleSheet()
Definition QY2Styler.cc:141
QStringList allStyleSheets()
Definition QY2Styler.cc:538
void processUrls(QString &text)
Definition QY2Styler.cc:271
QString alternateStyleSheet() const
Definition QY2Styler.h:171
QY2Styler(QObject *parent, const QString &defaultStyleSheet="", const QString &alternateStyleSheet="")
Definition QY2Styler.cc:56
bool styleSheetExists(const QString &file)
Definition QY2Styler.cc:98
void setAlternateStyleSheet(const QString &styleSheet)
Definition QY2Styler.cc:118
QString defaultStyleSheet() const
Definition QY2Styler.h:157
void setRichTextStyleSheet(YWidget *widget)
Definition QY2Styler.cc:244
void registerWidget(QWidget *widget)
Definition QY2Styler.cc:339
void unregisterWidget(QWidget *widget)
Definition QY2Styler.cc:349
void setDefaultStyleSheet(const QString &styleSheet)
Definition QY2Styler.cc:106
void toggleAlternateStyleSheet()
Definition QY2Styler.cc:261
QString buildStyleSheetFromFile(const QString &filename, QStringList &alreadyImportedFilenames_ret)
Definition QY2Styler.cc:202
QString themeDir() const
Definition QY2Styler.cc:332
bool usingAlternateStyleSheet()
Definition QY2Styler.h:181
bool loadDefaultStyleSheet()
Definition QY2Styler.cc:130
void setStyleSheet(const QString &text)
Definition QY2Styler.cc:219
QString currentStyleSheet() const
Definition QY2Styler.h:144
QString buildStyleSheet(const QString &content)
Definition QY2Styler.cc:173
static QY2Styler * styler()
Definition QY2Styler.cc:72
bool loadStyleSheet(const QString &file)
Definition QY2Styler.cc:152
void registerChildWidget(QWidget *parent, QWidget *widget)
Definition QY2Styler.cc:357
Definition QY2Styler.h:234