~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/styles/qstylefactory.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the style module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qstylefactory.h"
 
30
#include "qstyleplugin.h"
 
31
#include "private/qfactoryloader_p.h"
 
32
#include "qmutex.h"
 
33
 
 
34
#include "qapplication.h"
 
35
#include "qwindowsstyle.h"
 
36
#include "qmotifstyle.h"
 
37
#include "qcdestyle.h"
 
38
#ifndef QT_NO_STYLE_PLASTIQUE
 
39
#include "qplastiquestyle.h"
 
40
#endif
 
41
#ifndef QT_NO_STYLE_WINDOWSXP
 
42
#include "qwindowsxpstyle.h"
 
43
#endif
 
44
 
 
45
#if !defined(QT_NO_STYLE_MAC) && defined(Q_WS_MAC)
 
46
#  include <private/qt_mac_p.h>
 
47
#  include "qmacstyle_mac.h"
 
48
QString qt_mac_from_pascal_string(const Str255); //qglobal.cpp
 
49
#endif
 
50
 
 
51
#ifndef QT_NO_COMPONENT
 
52
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
 
53
    (QStyleFactoryInterface_iid, QCoreApplication::libraryPaths(), "/styles", Qt::CaseInsensitive))
 
54
#endif
 
55
 
 
56
/*!
 
57
    \class QStyleFactory qstylefactory.h
 
58
    \brief The QStyleFactory class creates QStyle objects.
 
59
 
 
60
    \ingroup appearance
 
61
 
 
62
    The style factory creates a QStyle object for a given key with
 
63
    QStyleFactory::create(key).
 
64
 
 
65
    The styles are either built-in or dynamically loaded from a style
 
66
    plugin (see \l QStylePlugin).
 
67
 
 
68
    QStyleFactory::keys() returns a list of valid keys, typically
 
69
    including "windows", "motif", "cde", and "plastique".
 
70
    Depending on the platform, "windowsxp" and "macintosh" may be
 
71
    available.
 
72
 
 
73
    \sa QStyle
 
74
*/
 
75
 
 
76
/*!
 
77
    Creates a QStyle object that matches \a key. This is either a
 
78
    built-in style, or a style from a style plugin.
 
79
 
 
80
    \sa keys()
 
81
*/
 
82
QStyle *QStyleFactory::create(const QString& key)
 
83
{
 
84
    QStyle *ret = 0;
 
85
    QString style = key.toLower();
 
86
#ifndef QT_NO_STYLE_WINDOWS
 
87
    if (style == "windows")
 
88
        ret = new QWindowsStyle;
 
89
    else
 
90
#endif
 
91
#ifndef QT_NO_STYLE_WINDOWSXP
 
92
    if (style == "windowsxp")
 
93
        ret = new QWindowsXPStyle;
 
94
    else
 
95
#endif
 
96
#ifndef QT_NO_STYLE_MOTIF
 
97
    if (style == "motif")
 
98
        ret = new QMotifStyle;
 
99
    else
 
100
#endif
 
101
#ifndef QT_NO_STYLE_CDE
 
102
    if (style == "cde")
 
103
        ret = new QCDEStyle;
 
104
    else
 
105
#endif
 
106
#ifndef QT_NO_STYLE_PLASTIQUE
 
107
    if (style == "plastique")
 
108
        ret = new QPlastiqueStyle;
 
109
    else
 
110
#endif
 
111
#if !defined(QT_NO_STYLE_MAC) && defined(Q_WS_MAC)
 
112
    if(style.left(9) == "macintosh")
 
113
        ret = new QMacStyle;
 
114
    else
 
115
#endif
 
116
    { } // Keep these here - they make the #ifdefery above work
 
117
#ifndef QT_NO_COMPONENT
 
118
    if(!ret) {
 
119
        if (QStyleFactoryInterface *factory = qobject_cast<QStyleFactoryInterface*>(loader()->instance(style)))
 
120
            ret = factory->create(style);
 
121
    }
 
122
#endif
 
123
    if(ret)
 
124
        ret->setObjectName(style);
 
125
    return ret;
 
126
}
 
127
 
 
128
/*!
 
129
    Returns the list of keys this factory can create styles for.
 
130
 
 
131
    \sa create()
 
132
*/
 
133
QStringList QStyleFactory::keys()
 
134
{
 
135
#ifndef QT_NO_COMPONENT
 
136
    QStringList list = loader()->keys();
 
137
#else
 
138
    QStringList list;
 
139
#endif
 
140
#ifndef QT_NO_STYLE_WINDOWS
 
141
    if (!list.contains("Windows"))
 
142
        list << "Windows";
 
143
#endif
 
144
#ifndef QT_NO_STYLE_WINDOWSXP
 
145
    if (!list.contains("WindowsXP"))
 
146
        list << "WindowsXP";
 
147
#endif
 
148
#ifndef QT_NO_STYLE_MOTIF
 
149
    if (!list.contains("Motif"))
 
150
        list << "Motif";
 
151
#endif
 
152
#ifndef QT_NO_STYLE_CDE
 
153
    if (!list.contains("CDE"))
 
154
        list << "CDE";
 
155
#endif
 
156
#ifndef QT_NO_STYLE_PLASTIQUE
 
157
    if (!list.contains("Plastique"))
 
158
        list << "Plastique";
 
159
#endif
 
160
#if !defined(QT_NO_STYLE_MAC) && defined(Q_WS_MAC)
 
161
    QString mstyle = "Macintosh";
 
162
    Collection c = NewCollection();
 
163
    if (c) {
 
164
        GetTheme(c);
 
165
        Str255 str;
 
166
        long int s = 256;
 
167
        if(!GetCollectionItem(c, kThemeNameTag, 0, &s, &str))
 
168
            mstyle += " (" + qt_mac_from_pascal_string(str) + ")";
 
169
    }
 
170
    if (!list.contains(mstyle))
 
171
        list << mstyle;
 
172
    DisposeCollection(c);
 
173
#endif
 
174
 
 
175
    return list;
 
176
}