qproxystyle.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/styles/qproxystyle.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include <qstyle.h>-
35#include <private/qproxystyle_p.h>-
36#include <private/qapplication_p.h>-
37#include "qproxystyle.h"-
38#include "qstylefactory.h"-
39#include <private/qstyle_p.h>-
40-
41#if !defined(QT_NO_STYLE_PROXY) || defined(QT_PLUGIN)-
42-
43QT_BEGIN_NAMESPACE-
44-
45/*!-
46 \class QProxyStyle-
47-
48 \brief The QProxyStyle class is a convenience class that simplifies-
49 dynamically overriding QStyle elements.-
50-
51 \since 4.6-
52-
53 \inmodule QtWidgets-
54-
55 A QProxyStyle wraps a QStyle (usually the default system style) for the-
56 purpose of dynamically overriding painting or other specific style behavior.-
57-
58 The following example shows how to override the shortcut underline-
59 behavior on any platform:-
60-
61 \snippet code/src_gui_qproxystyle.cpp 1-
62-
63 Warning: The \l {QCommonStyle} {common styles} provided by Qt will-
64 respect this hint, because they call QStyle::proxy(), but there is-
65 no guarantee that QStyle::proxy() will be called for user defined-
66 or system controlled styles. It would not work on a Mac, for-
67 example, where menus are handled by the operating system.-
68-
69 \sa QStyle-
70*/-
71-
72void QProxyStylePrivate::ensureBaseStyle() const-
73{-
74 Q_Q(const QProxyStyle);-
75-
76 if (baseStyle)
baseStyleDescription
TRUEnever evaluated
FALSEnever evaluated
0
77 return;
never executed: return;
0
78-
79 if (!baseStyle && !QApplicationPrivate::styleOverride.isEmpty()) {
!baseStyleDescription
TRUEnever evaluated
FALSEnever evaluated
!QApplicationP...ride.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
80 baseStyle = QStyleFactory::create(QApplicationPrivate::styleOverride);-
81 if (baseStyle) {
baseStyleDescription
TRUEnever evaluated
FALSEnever evaluated
0
82 // If baseStyle is an instance of the same proxyStyle-
83 // we destroy it and fall back to the desktop style-
84 if (qstrcmp(baseStyle->metaObject()->className(),
qstrcmp(baseSt...ssName()) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
85 q->metaObject()->className()) == 0) {
qstrcmp(baseSt...ssName()) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
86 delete baseStyle;-
87 baseStyle = 0;-
88 }
never executed: end of block
0
89 }
never executed: end of block
0
90 }
never executed: end of block
0
91-
92 if (!baseStyle) // Use application desktop style
!baseStyleDescription
TRUEnever evaluated
FALSEnever evaluated
0
93 baseStyle = QStyleFactory::create(QApplicationPrivate::desktopStyleKey());
never executed: baseStyle = QStyleFactory::create(QApplicationPrivate::desktopStyleKey());
0
94-
95 if (!baseStyle) // Fallback to windows style
!baseStyleDescription
TRUEnever evaluated
FALSEnever evaluated
0
96 baseStyle = QStyleFactory::create(QLatin1String("windows"));
never executed: baseStyle = QStyleFactory::create(QLatin1String("windows"));
0
97-
98 baseStyle->setProxy(const_cast<QProxyStyle*>(q));-
99 baseStyle->setParent(const_cast<QProxyStyle*>(q)); // Take ownership-
100}
never executed: end of block
0
101-
102/*!-
103 Constructs a QProxyStyle object for overriding behavior in the-
104 specified \a style, or in the default native \l{QApplication::style()}-
105 {style} if \a style is not specified.-
106-
107 Ownership of \a style is transferred to QProxyStyle.-
108*/-
109QProxyStyle::QProxyStyle(QStyle *style) :-
110 QCommonStyle(*new QProxyStylePrivate())-
111{-
112 Q_D(QProxyStyle);-
113 if (style) {
styleDescription
TRUEnever evaluated
FALSEnever evaluated
0
114 d->baseStyle = style;-
115 style->setProxy(this);-
116 style->setParent(this); // Take ownership-
117 }
never executed: end of block
0
118}
never executed: end of block
0
119-
120/*!-
121 Constructs a QProxyStyle object for overriding behavior in-
122 the base style specified by style \a key, or in the current-
123 \l{QApplication::style()}{application style} if the specified-
124 style \a key is unrecognized.-
125-
126 \sa QStyleFactory::create()-
127*/-
128QProxyStyle::QProxyStyle(const QString &key) :-
129 QCommonStyle(*new QProxyStylePrivate())-
130{-
131 Q_D(QProxyStyle);-
132 QStyle *style = QStyleFactory::create(key);-
133 if (style) {
styleDescription
TRUEnever evaluated
FALSEnever evaluated
0
134 d->baseStyle = style;-
135 style->setProxy(this);-
136 style->setParent(this); // Take ownership-
137 }
never executed: end of block
0
138}
never executed: end of block
0
139-
140/*!-
141 Destroys the QProxyStyle object.-
142*/-
143QProxyStyle::~QProxyStyle()-
144{-
145}-
146-
147/*!-
148 Returns the proxy base style object. If no base style-
149 is set on the proxy style, QProxyStyle will create-
150 an instance of the application style instead.-
151-
152 \sa setBaseStyle(), QStyle-
153*/-
154QStyle *QProxyStyle::baseStyle() const-
155{-
156 Q_D (const QProxyStyle);-
157 d->ensureBaseStyle();-
158 return d->baseStyle;
never executed: return d->baseStyle;
0
159}-
160-
161/*!-
162 Sets the base style that should be proxied.-
163-
164 Ownership of \a style is transferred to QProxyStyle.-
165-
166 If style is zero, a desktop-dependant style will be-
167 assigned automatically.-
168*/-
169void QProxyStyle::setBaseStyle(QStyle *style)-
170{-
171 Q_D (QProxyStyle);-
172-
173 if (d->baseStyle && d->baseStyle->parent() == this)
d->baseStyleDescription
TRUEnever evaluated
FALSEnever evaluated
d->baseStyle->parent() == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
174 d->baseStyle->deleteLater();
never executed: d->baseStyle->deleteLater();
0
175-
176 d->baseStyle = style;-
177-
178 if (d->baseStyle) {
d->baseStyleDescription
TRUEnever evaluated
FALSEnever evaluated
0
179 d->baseStyle->setProxy(this);-
180 d->baseStyle->setParent(this);-
181 }
never executed: end of block
0
182}
never executed: end of block
0
183-
184/*! \reimp-
185 */-
186void QProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const-
187{-
188 Q_D (const QProxyStyle);-
189 d->ensureBaseStyle();-
190 d->baseStyle->drawPrimitive(element, option, painter, widget);-
191}
never executed: end of block
0
192-
193/*!-
194 \reimp-
195 */-
196void QProxyStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const-
197{-
198 Q_D (const QProxyStyle);-
199 d->ensureBaseStyle();-
200 d->baseStyle->drawControl(element, option, painter, widget);-
201}
never executed: end of block
0
202-
203/*! \reimp-
204 */-
205void QProxyStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const-
206{-
207 Q_D (const QProxyStyle);-
208 d->ensureBaseStyle();-
209 d->baseStyle->drawComplexControl(control, option, painter, widget);-
210}
never executed: end of block
0
211-
212/*! \reimp-
213 */-
214void QProxyStyle::drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled,-
215 const QString &text, QPalette::ColorRole textRole) const-
216{-
217 Q_D (const QProxyStyle);-
218 d->ensureBaseStyle();-
219 d->baseStyle->drawItemText(painter, rect, flags, pal, enabled, text, textRole);-
220}
never executed: end of block
0
221-
222/*! \reimp-
223 */-
224void QProxyStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const-
225{-
226 Q_D (const QProxyStyle);-
227 d->ensureBaseStyle();-
228 d->baseStyle->drawItemPixmap(painter, rect, alignment, pixmap);-
229}
never executed: end of block
0
230-
231/*! \reimp-
232 */-
233QSize QProxyStyle::sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const-
234{-
235 Q_D (const QProxyStyle);-
236 d->ensureBaseStyle();-
237 return d->baseStyle->sizeFromContents(type, option, size, widget);
never executed: return d->baseStyle->sizeFromContents(type, option, size, widget);
0
238}-
239-
240/*! \reimp-
241 */-
242QRect QProxyStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const-
243{-
244 Q_D (const QProxyStyle);-
245 d->ensureBaseStyle();-
246 return d->baseStyle->subElementRect(element, option, widget);
never executed: return d->baseStyle->subElementRect(element, option, widget);
0
247}-
248-
249/*! \reimp-
250 */-
251QRect QProxyStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *option, SubControl sc, const QWidget *widget) const-
252{-
253 Q_D (const QProxyStyle);-
254 d->ensureBaseStyle();-
255 return d->baseStyle->subControlRect(cc, option, sc, widget);
never executed: return d->baseStyle->subControlRect(cc, option, sc, widget);
0
256}-
257-
258/*! \reimp-
259 */-
260QRect QProxyStyle::itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const-
261{-
262 Q_D (const QProxyStyle);-
263 d->ensureBaseStyle();-
264 return d->baseStyle->itemTextRect(fm, r, flags, enabled, text);
never executed: return d->baseStyle->itemTextRect(fm, r, flags, enabled, text);
0
265}-
266-
267/*! \reimp-
268 */-
269QRect QProxyStyle::itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const-
270{-
271 Q_D (const QProxyStyle);-
272 d->ensureBaseStyle();-
273 return d->baseStyle->itemPixmapRect(r, flags, pixmap);
never executed: return d->baseStyle->itemPixmapRect(r, flags, pixmap);
0
274}-
275-
276/*! \reimp-
277 */-
278QStyle::SubControl QProxyStyle::hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, const QPoint &pos, const QWidget *widget) const-
279{-
280 Q_D (const QProxyStyle);-
281 d->ensureBaseStyle();-
282 return d->baseStyle->hitTestComplexControl(control, option, pos, widget);
never executed: return d->baseStyle->hitTestComplexControl(control, option, pos, widget);
0
283}-
284-
285/*! \reimp-
286 */-
287int QProxyStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const-
288{-
289 Q_D (const QProxyStyle);-
290 d->ensureBaseStyle();-
291 return d->baseStyle->styleHint(hint, option, widget, returnData);
never executed: return d->baseStyle->styleHint(hint, option, widget, returnData);
0
292}-
293-
294/*! \reimp-
295 */-
296int QProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const-
297{-
298 Q_D (const QProxyStyle);-
299 d->ensureBaseStyle();-
300 return d->baseStyle->pixelMetric(metric, option, widget);
never executed: return d->baseStyle->pixelMetric(metric, option, widget);
0
301}-
302-
303/*! \reimp-
304 */-
305QPixmap QProxyStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const-
306{-
307 Q_D (const QProxyStyle);-
308 d->ensureBaseStyle();-
309 return d->baseStyle->standardPixmap(standardPixmap, opt, widget);
never executed: return d->baseStyle->standardPixmap(standardPixmap, opt, widget);
0
310}-
311-
312/*! \reimp-
313 */-
314QPixmap QProxyStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const-
315{-
316 Q_D (const QProxyStyle);-
317 d->ensureBaseStyle();-
318 return d->baseStyle->generatedIconPixmap(iconMode, pixmap, opt);
never executed: return d->baseStyle->generatedIconPixmap(iconMode, pixmap, opt);
0
319}-
320-
321/*! \reimp-
322 */-
323QPalette QProxyStyle::standardPalette() const-
324{-
325 Q_D (const QProxyStyle);-
326 d->ensureBaseStyle();-
327 return d->baseStyle->standardPalette();
never executed: return d->baseStyle->standardPalette();
0
328}-
329-
330/*! \reimp-
331 */-
332void QProxyStyle::polish(QWidget *widget)-
333{-
334 Q_D (QProxyStyle);-
335 d->ensureBaseStyle();-
336 d->baseStyle->polish(widget);-
337}
never executed: end of block
0
338-
339/*! \reimp-
340 */-
341void QProxyStyle::polish(QPalette &pal)-
342{-
343 Q_D (QProxyStyle);-
344 d->ensureBaseStyle();-
345 d->baseStyle->polish(pal);-
346}
never executed: end of block
0
347-
348/*! \reimp-
349 */-
350void QProxyStyle::polish(QApplication *app)-
351{-
352 Q_D (QProxyStyle);-
353 d->ensureBaseStyle();-
354 d->baseStyle->polish(app);-
355}
never executed: end of block
0
356-
357/*! \reimp-
358 */-
359void QProxyStyle::unpolish(QWidget *widget)-
360{-
361 Q_D (QProxyStyle);-
362 d->ensureBaseStyle();-
363 d->baseStyle->unpolish(widget);-
364}
never executed: end of block
0
365-
366/*! \reimp-
367 */-
368void QProxyStyle::unpolish(QApplication *app)-
369{-
370 Q_D (QProxyStyle);-
371 d->ensureBaseStyle();-
372 d->baseStyle->unpolish(app);-
373}
never executed: end of block
0
374-
375/*! \reimp-
376 */-
377bool QProxyStyle::event(QEvent *e)-
378{-
379 Q_D (QProxyStyle);-
380 d->ensureBaseStyle();-
381 return d->baseStyle->event(e);
never executed: return d->baseStyle->event(e);
0
382}-
383-
384/*!-
385 Returns an icon for the given \a standardIcon.-
386-
387 Reimplement this slot to provide your own icons in a QStyle-
388 subclass. The \a option argument can be used to pass extra-
389 information required to find the appropriate icon. The \a widget-
390 argument is optional and can also be used to help find the icon.-
391 */-
392QIcon QProxyStyle::standardIcon(StandardPixmap standardIcon,-
393 const QStyleOption *option,-
394 const QWidget *widget) const-
395{-
396 Q_D (const QProxyStyle);-
397 d->ensureBaseStyle();-
398 return d->baseStyle->standardIcon(standardIcon, option, widget);
never executed: return d->baseStyle->standardIcon(standardIcon, option, widget);
0
399}-
400-
401/*!-
402 This slot is called by layoutSpacing() to determine the spacing that-
403 should be used between \a control1 and \a control2 in a layout. \a-
404 orientation specifies whether the controls are laid out side by side-
405 or stacked vertically. The \a option parameter can be used to pass-
406 extra information about the parent widget. The \a widget parameter-
407 is optional and can also be used if \a option is 0.-
408-
409 The default implementation returns -1.-
410-
411 \sa combinedLayoutSpacing()-
412 */-
413int QProxyStyle::layoutSpacing(QSizePolicy::ControlType control1,-
414 QSizePolicy::ControlType control2,-
415 Qt::Orientation orientation,-
416 const QStyleOption *option,-
417 const QWidget *widget) const-
418{-
419 Q_D (const QProxyStyle);-
420 d->ensureBaseStyle();-
421 return d->baseStyle->layoutSpacing(control1, control2, orientation, option, widget);
never executed: return d->baseStyle->layoutSpacing(control1, control2, orientation, option, widget);
0
422}-
423-
424QT_END_NAMESPACE-
425-
426#include "moc_qproxystyle.cpp"-
427-
428#endif // QT_NO_STYLE_PROXY-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9