libyui-qt  2.46.13
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 
36 class QY2Styler : public QObject
37 {
38  Q_OBJECT
39 
40 protected:
41 
42  /**
43  * Constructor. Use the static styler() function instead to return the
44  * singleton for this class.
45  **/
46  QY2Styler( QObject * parent );
47 
48 public:
49 
50  static QY2Styler * styler();
51 
52  void loadStyleSheet( const QString &file ); // reads style sheet form a file
53  void setStyleSheet( const QString & text );
54  QString themeDir() const;
55  void registerWidget( QWidget *widget );
56  void unregisterWidget( QWidget *widget );
57  void registerChildWidget( QWidget *parent, QWidget *widget );
58  QString textStyle() const { return _textStyle; }
59 
60  bool updateRendering( QWidget *wid );
61 
62 protected:
63  void renderParent( QWidget *wid );
64  QImage getScaled( const QString name, const QSize & size );
65 
66  /**
67  * Search and replace some self-defined macros in the style sheet.
68  * Among other things, expands the file name inside url( filename.png ) in
69  * the style sheet with the full path.
70  **/
71  void processUrls( QString & text );
72 
73  /*
74  * Reimplemented from QObject.
75  **/
76  bool eventFilter( QObject * obj, QEvent * ev );
77 
78 
79 private:
80 
81  struct BackgrInfo
82  {
83  QString filename;
84  QImage pix;
85  QImage scaled;
86  QSize lastscale;
87  bool full;
88  };
89 
90  QHash<QString,BackgrInfo> _backgrounds;
91  QMap<QWidget*, QList< QWidget* > > _children;
92  QString _style;
93  QString _textStyle;
94 };
95 
96 
97 #endif // QY2Styler_h
void processUrls(QString &text)
Search and replace some self-defined macros in the style sheet.
Definition: QY2Styler.cc:116
QY2Styler(QObject *parent)
Constructor.
Definition: QY2Styler.cc:53