libyui-qt
QY2Styler.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: QY2Styler.h
20 
21  Author: Stefan Kulow <coolo@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef QY2Styler_h
27 #define QY2Styler_h
28 
29 #include <QObject>
30 #include <QHash>
31 #include <QString>
32 #include <QImage>
33 #include <QMap>
34 
35 #define HIGH_CONTRAST_STYLE_SHEET "highcontrast.qss"
36 #define DEFAULT_STYLE_SHEET "style.qss"
37 
38 class QY2Styler : public QObject
39 {
40  Q_OBJECT
41 
42 protected:
43 
48  QY2Styler( QObject * parent,
49  const QString & defaultStyleSheet = "",
50  const QString & alternateStyleSheet = "" );
51 
52 public:
53 
54  static QY2Styler * styler();
55 
62  bool styleSheetExists( const QString & file );
63 
70  bool loadStyleSheet( const QString &file );
71 
77  void setStyleSheet( const QString & text );
78 
87  bool loadDefaultStyleSheet();
88 
98 
102  QString themeDir() const;
103 
109  void registerWidget( QWidget *widget );
110 
116  void unregisterWidget( QWidget *widget );
117 
118 
125  void registerChildWidget( QWidget *parent, QWidget *widget );
126 
127  QString textStyle() const { return _textStyle; }
128 
136  void setDefaultStyleSheet(const QString & styleSheet);
137 
145  void setAlternateStyleSheet(const QString & styleSheet);
146 
151 
155  bool usingAlternateStyleSheet() { return _usingAlternateStyleSheet; }
156 
157  bool updateRendering( QWidget *wid );
158 
159 protected:
160  void renderParent( QWidget *wid );
161  QImage getScaled( const QString name, const QSize & size );
162 
168  void processUrls( QString & text );
169 
173  const QString buildStyleSheet(QString content);
174 
180  const QString buildStyleSheet(QString content, QStringList & alreadyImportedFilenames);
181 
187  const QString buildStyleSheetFromFile(const QString & filename, QStringList & alreadyImportedFilenames);
188 
189  /*
190  * Reimplemented from QObject.
191  **/
192  bool eventFilter( QObject * obj, QEvent * ev );
193 
194  QString _currentStyleSheet;
195  QString _defaultStyleSheet = DEFAULT_STYLE_SHEET;
196  QString _alternateStyleSheet = HIGH_CONTRAST_STYLE_SHEET;
197  bool _usingAlternateStyleSheet = false;
198 
199 private:
200 
201  struct BackgrInfo
202  {
203  QString filename;
204  QImage pix;
205  QImage scaled;
206  QSize lastscale;
207  bool full;
208  };
209 
210  QHash<QString,BackgrInfo> _backgrounds;
211  QMap<QWidget*, QList< QWidget* > > _children;
212  // remember all registered widgets to allow styling not only for
213  // the explicitly requested children widgets (stored in _children)
214  QList< QWidget* > _registered_widgets;
215  QString _style;
216  QString _textStyle;
217 };
218 
219 
220 #endif // QY2Styler_h
bool styleSheetExists(const QString &file)
Definition: QY2Styler.cc:91
QY2Styler(QObject *parent, const QString &defaultStyleSheet="", const QString &alternateStyleSheet="")
Definition: QY2Styler.cc:53
const QString buildStyleSheet(QString content)
Definition: QY2Styler.cc:152
void toggleAlternateStyleSheet()
Definition: QY2Styler.cc:206
const QString buildStyleSheetFromFile(const QString &filename, QStringList &alreadyImportedFilenames)
Definition: QY2Styler.cc:175
void setStyleSheet(const QString &text)
Definition: QY2Styler.cc:189
void registerWidget(QWidget *widget)
Definition: QY2Styler.cc:282
bool loadStyleSheet(const QString &file)
Definition: QY2Styler.cc:132
Definition: QY2Styler.h:38
bool usingAlternateStyleSheet()
Definition: QY2Styler.h:155
void processUrls(QString &text)
Definition: QY2Styler.cc:215
bool loadDefaultStyleSheet()
Definition: QY2Styler.cc:116
void setDefaultStyleSheet(const QString &styleSheet)
Definition: QY2Styler.cc:98
void setAlternateStyleSheet(const QString &styleSheet)
Definition: QY2Styler.cc:107
bool loadAlternateStyleSheet()
Definition: QY2Styler.cc:124
void registerChildWidget(QWidget *parent, QWidget *widget)
Definition: QY2Styler.cc:298
QString themeDir() const
Definition: QY2Styler.cc:276
void unregisterWidget(QWidget *widget)
Definition: QY2Styler.cc:291