Ok, the long awaited config wizard is here (at least in a very basic state). There...
[quassel.git] / src / contrib / libqxt-2007-10-24 / src / gui / qxtproxystyle.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
4 **
5 ** This file is part of the QxtGui module of the Qt eXTension library
6 **
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
9 ** IBM.
10 **
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
15 **
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
20 **
21 ** <http://libqxt.sourceforge.net>  <foundation@libqxt.org>
22 **
23 ****************************************************************************/
24 #include <QStyleFactory>
25 #include "qxtproxystyle.h"
26
27 /*!
28     \class QxtProxyStyle QxtProxyStyle
29     \ingroup QxtGui
30     \brief A proxy style.
31
32     A technique called "proxy style" is a common way for creating
33     cross-platform custom styles. Developers often want to do slight
34     adjustments in some specific values returned by QStyle. A proxy
35     style is the solution to avoid subclassing any platform specific
36     style (eg. QPlastiqueStyle, QWindowsXPStyle, or QMacStyle) and
37     to retain the native look on all supported platforms.
38
39     The subject has been discussed in Qt Quarterly 9:
40     http://doc.trolltech.com/qq/qq09-q-and-a.html#style (just notice
41     that there are a few noteworthy spelling mistakes in the article).
42
43     Proxy styles are becoming obsolete thanks to style sheets
44     introduced in Qt 4.2. However, style sheets still is a new
45     concept and only a portion of features are supported yet. Both -
46     style sheets and proxy styles - have their pros and cons.
47
48     \section usage Usage
49
50     Implement the custom behaviour in a subclass of QxtProxyStyle:
51     \code
52     class MyCustomStyle : public QxtProxyStyle
53     {
54        public:
55           MyCustomStyle(const QString& baseStyle) : QxtProxyStyle(baseStyle)
56           {
57           }
58
59           int pixelMetric(PixelMetric metric, const QStyleOption* option = 0, const QWidget* widget = 0) const
60           {
61              if (metric == QStyle::PM_ButtonMargin)
62                 return 6;
63              return QxtProxyStyle::pixelMetric(metric, option, widget);
64           }
65     };
66     \endcode
67
68     Using the custom style for the whole application:
69     \code
70     QString defaultStyle = QApplication::style()->objectName();
71     QApplication::setStyle(new MyCustomStyle(defaultStyle));
72     \endcode
73
74     Using the custom style for a single widget:
75     \code
76     QString defaultStyle = widget->style()->objectName();
77     widget->setStyle(new MyCustomStyle(defaultStyle));
78     \endcode
79  */
80
81 /*!
82     Constructs a new QxtProxyStyle for \a style.
83     See QStyleFactory::keys() for supported styles.
84
85     \sa QStyleFactory::keys()
86  */
87 QxtProxyStyle::QxtProxyStyle(const QString& baseStyle)
88         : QStyle(), style(QStyleFactory::create(baseStyle))
89 {
90     setObjectName(QLatin1String("proxy"));
91 }
92
93 /*!
94     Destructs the proxy style.
95  */
96 QxtProxyStyle::~QxtProxyStyle()
97 {
98     delete style;
99 }
100
101 void QxtProxyStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget) const
102 {
103     style->drawComplexControl(control, option, painter, widget);
104 }
105
106 void QxtProxyStyle::drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget)  const
107 {
108     style->drawControl(element, option, painter, widget);
109 }
110
111 void QxtProxyStyle::drawItemPixmap(QPainter* painter, const QRect& rect, int alignment, const QPixmap& pixmap) const
112 {
113     style->drawItemPixmap(painter, rect, alignment, pixmap);
114 }
115
116 void QxtProxyStyle::drawItemText(QPainter* painter, const QRect& rect, int alignment, const QPalette& pal, bool enabled, const QString& text, QPalette::ColorRole textRole) const
117 {
118     style->drawItemText(painter, rect, alignment, pal, enabled, text, textRole);
119 }
120
121 void QxtProxyStyle::drawPrimitive(PrimitiveElement elem, const QStyleOption* option, QPainter* painter, const QWidget* widget) const
122 {
123     style->drawPrimitive(elem, option, painter, widget);
124 }
125
126 QPixmap QxtProxyStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap& pixmap, const QStyleOption* option) const
127 {
128     return style->generatedIconPixmap(iconMode, pixmap, option);
129 }
130
131 QStyle::SubControl QxtProxyStyle::hitTestComplexControl(ComplexControl control, const QStyleOptionComplex* option, const QPoint& pos, const QWidget* widget) const
132 {
133     return style->hitTestComplexControl(control, option, pos, widget);
134 }
135
136 QRect QxtProxyStyle::itemPixmapRect(const QRect& rect, int alignment, const QPixmap& pixmap) const
137 {
138     return style->itemPixmapRect(rect, alignment, pixmap);
139 }
140
141 QRect QxtProxyStyle::itemTextRect(const QFontMetrics& metrics, const QRect& rect, int alignment, bool enabled, const QString& text) const
142 {
143     return style->itemTextRect(metrics, rect, alignment, enabled, text);
144 }
145
146 int QxtProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const
147 {
148     return style->pixelMetric(metric, option, widget);
149 }
150
151 void QxtProxyStyle::polish(QWidget* widget)
152 {
153     style->polish(widget);
154 }
155
156 void QxtProxyStyle::polish(QApplication* app)
157 {
158     style->polish(app);
159 }
160
161 void QxtProxyStyle::polish(QPalette& pal)
162 {
163     style->polish(pal);
164 }
165
166 QSize QxtProxyStyle::sizeFromContents(ContentsType type, const QStyleOption* option, const QSize& contentsSize, const QWidget* widget) const
167 {
168     return style->sizeFromContents(type, option, contentsSize, widget);
169 }
170
171 QIcon QxtProxyStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption* option, const QWidget* widget) const
172 {
173     return style->standardIcon(standardIcon, option, widget);
174 }
175
176 QPalette QxtProxyStyle::standardPalette() const
177 {
178     return style->standardPalette();
179 }
180
181 QPixmap QxtProxyStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption* option, const QWidget* widget) const
182 {
183     return style->standardPixmap(standardPixmap, option, widget);
184 }
185
186 int QxtProxyStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
187 {
188     return style->styleHint(hint, option, widget, returnData);
189 }
190
191 QRect QxtProxyStyle::subControlRect(ComplexControl control, const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget) const
192 {
193     return style->subControlRect(control, option, subControl, widget);
194 }
195
196 QRect QxtProxyStyle::subElementRect(SubElement element, const QStyleOption* option, const QWidget* widget) const
197 {
198     return style->subElementRect(element, option, widget);
199 }
200
201 void QxtProxyStyle::unpolish(QWidget* widget)
202 {
203     style->unpolish(widget);
204 }
205
206 void QxtProxyStyle::unpolish(QApplication* app)
207 {
208     style->unpolish(app);
209 }