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 QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qdecorationfactory_qws.h"
43 #include "qdecorationplugin_qws.h"
44 #include "private/qfactoryloader_p.h"
45 #include "qmutex.h"
46
47 #include "qapplication.h"
48 #include "qdecorationdefault_qws.h"
49 #include "qdecorationwindows_qws.h"
50 #include "qdecorationstyled_qws.h"
51
52 QT_BEGIN_NAMESPACE
53
54 #ifndef QT_NO_LIBRARY
55 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
56 (QDecorationFactoryInterface_iid,
57 QLatin1String("/decorations"), Qt::CaseInsensitive))
58 #endif
59
60
61
62 /*!
63 \class QDecorationFactory
64 \ingroup qws
65 \ingroup appearance
66
67 \brief The QDecorationFactory class creates window decorations in
68 Qt for Embedded Linux.
69
70 Note that this class is only available in \l{Qt for Embedded Linux}.
71
72 QDecorationFactory is used to detect and instantiate the available
73 decorations, allowing \l{Qt for Embedded Linux} to load the preferred
74 decoration into the application at runtime. The create() function
75 returns a QDecoration object representing the decoration
76 identified by a given key. The valid keys (i.e. the supported
77 decorations) can be retrieved using the keys() function.
78
79 \l{Qt for Embedded Linux} provides three built-in decorations: \c Default,
80 \c Styled and \c Windows. In addition, custom decorations can be
81 added using Qt's \l {How to Create Qt Plugins}{plugin mechanism},
82 i.e. by subclassing the QDecoration class and creating a mouse
83 driver plugin (QDecorationPlugin).
84
85 \sa QDecoration, QDecorationPlugin
86 */
87
88 /*!
89 Creates the decoration specified by the given \a key. Note that
90 the keys are case-insensitive.
91
92 \sa keys()
93 */
94
create(const QString & key)95 QDecoration *QDecorationFactory::create(const QString& key)
96 {
97 QDecoration *ret = 0;
98 QString decoration = key.toLower();
99 #ifndef QT_NO_QWS_DECORATION_DEFAULT
100 if (decoration == QLatin1String("default"))
101 ret = new QDecorationDefault;
102 else
103 #endif
104 #ifndef QT_NO_QWS_DECORATION_WINDOWS
105 if (decoration == QLatin1String("windows"))
106 ret = new QDecorationWindows;
107 else
108 #endif
109 #ifndef QT_NO_QWS_DECORATION_STYLED
110 if (decoration == QLatin1String("styled"))
111 ret = new QDecorationStyled;
112 else
113 #endif
114 { } // Keep these here - they make the #ifdefery above work
115 #ifndef QT_NO_LIBRARY
116 if (!ret) {
117 if (QDecorationFactoryInterface *factory = qobject_cast<QDecorationFactoryInterface*>(loader()->instance(decoration))) {
118 ret = factory->create(decoration);
119 }
120 }
121 #endif
122 return ret;
123 }
124
125 /*!
126 Returns the list of valid keys, i.e., the available decorations.
127
128 \sa create()
129 */
keys()130 QStringList QDecorationFactory::keys()
131 {
132 QStringList list;
133 #ifndef QT_NO_QWS_DECORATION_STYLED
134 list << QLatin1String("Styled");
135 #endif
136 #ifndef QT_NO_QWS_DECORATION_DEFAULT
137 list << QLatin1String("Default");
138 #endif
139 #ifndef QT_NO_QWS_DECORATION_WINDOWS
140 list << QLatin1String("Windows");
141 #endif
142
143 #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
144 #ifndef QT_NO_LIBRARY
145 QStringList plugins = loader()->keys();
146 for (int i = 0; i < plugins.size(); ++i) {
147 if (!list.contains(plugins.at(i)))
148 list += plugins.at(i);
149 }
150 #endif //QT_NO_LIBRARY
151 #endif //QT_MAKEDLL
152
153 return list;
154 }
155
156 QT_END_NAMESPACE
157