| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include <qstyle.h>
|
|---|
| 43 | #include <private/qproxystyle_p.h>
|
|---|
| 44 | #include <private/qapplication_p.h>
|
|---|
| 45 | #include "qproxystyle.h"
|
|---|
| 46 | #include "qstylefactory.h"
|
|---|
| 47 | #include <private/qstyle_p.h>
|
|---|
| 48 |
|
|---|
| 49 | #if !defined(QT_NO_STYLE_PROXY) || defined(QT_PLUGIN)
|
|---|
| 50 |
|
|---|
| 51 | QT_BEGIN_NAMESPACE
|
|---|
| 52 |
|
|---|
| 53 | /*!
|
|---|
| 54 | \class QProxyStyle
|
|---|
| 55 |
|
|---|
| 56 | \brief The QProxyStyle class is a convenience class that simplifies
|
|---|
| 57 | dynamically overriding QStyle elements.
|
|---|
| 58 |
|
|---|
| 59 | \since 4.6
|
|---|
| 60 |
|
|---|
| 61 | A QProxyStyle wraps a QStyle (usually the default system style) for the
|
|---|
| 62 | purpose of dynamically overriding painting or other specific style behavior.
|
|---|
| 63 |
|
|---|
| 64 | The following example shows how to override the shortcut underline
|
|---|
| 65 | behavior on any platform:
|
|---|
| 66 |
|
|---|
| 67 | \snippet doc/src/snippets/code/src_gui_qproxystyle.cpp 1
|
|---|
| 68 |
|
|---|
| 69 | Warning: The \l {QCommonStyle} {common styles} provided by Qt will
|
|---|
| 70 | respect this hint, because they call QStyle::proxy(), but there is
|
|---|
| 71 | no guarantee that QStyle::proxy() will be called for user defined
|
|---|
| 72 | or system controlled styles. It would not work on a Mac, for
|
|---|
| 73 | example, where menus are handled by the operating system.
|
|---|
| 74 |
|
|---|
| 75 | \sa QStyle
|
|---|
| 76 | */
|
|---|
| 77 |
|
|---|
| 78 | void QProxyStylePrivate::ensureBaseStyle() const
|
|---|
| 79 | {
|
|---|
| 80 | Q_Q(const QProxyStyle);
|
|---|
| 81 |
|
|---|
| 82 | if (baseStyle)
|
|---|
| 83 | return;
|
|---|
| 84 |
|
|---|
| 85 | if (!baseStyle && !QApplicationPrivate::styleOverride.isEmpty()) {
|
|---|
| 86 | baseStyle = QStyleFactory::create(QApplicationPrivate::styleOverride);
|
|---|
| 87 | if (baseStyle) {
|
|---|
| 88 | // If baseStyle is an instance of the same proxyStyle
|
|---|
| 89 | // we destroy it and fall back to the desktop style
|
|---|
| 90 | if (qstrcmp(baseStyle->metaObject()->className(),
|
|---|
| 91 | q->metaObject()->className()) == 0) {
|
|---|
| 92 | delete baseStyle;
|
|---|
| 93 | baseStyle = 0;
|
|---|
| 94 | }
|
|---|
| 95 | }
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | if (!baseStyle) // Use application desktop style
|
|---|
| 99 | baseStyle = QStyleFactory::create(QApplicationPrivate::desktopStyleKey());
|
|---|
| 100 |
|
|---|
| 101 | if (!baseStyle) // Fallback to windows style
|
|---|
| 102 | baseStyle = QStyleFactory::create(QLatin1String("windows"));
|
|---|
| 103 |
|
|---|
| 104 | baseStyle->setProxy(const_cast<QProxyStyle*>(q));
|
|---|
| 105 | baseStyle->setParent(const_cast<QProxyStyle*>(q)); // Take ownership
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | /*!
|
|---|
| 109 | Constructs a QProxyStyle object for overriding behavior in \a style
|
|---|
| 110 | or in the current application \l{QStyle}{style} if \a style is 0
|
|---|
| 111 | (default). Normally \a style is 0, because you want to override
|
|---|
| 112 | behavior in the system style.
|
|---|
| 113 |
|
|---|
|
|---|