source: trunk/tools/designer/src/lib/uilib/properties_p.h@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 7.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 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 Qt Designer 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//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the Qt API. It exists for the convenience
47// of Qt Designer. This header
48// file may change from version to version without notice, or even be removed.
49//
50// We mean it.
51//
52
53#ifndef UILIBPROPERTIES_H
54#define UILIBPROPERTIES_H
55
56#include <QtDesigner/uilib_global.h>
57
58#include <QtCore/QObject>
59#include <QtCore/QMetaProperty>
60#include <QtCore/QLocale>
61#include <QtCore/QCoreApplication>
62
63#include <QtGui/QWidget>
64
65#include "formbuilderextra_p.h"
66
67QT_BEGIN_NAMESPACE
68
69#ifdef QFORMINTERNAL_NAMESPACE
70namespace QFormInternal
71{
72#endif
73
74class QAbstractFormBuilder;
75class DomProperty;
76
77QDESIGNER_UILIB_EXPORT DomProperty *variantToDomProperty(QAbstractFormBuilder *abstractFormBuilder, const QMetaObject *meta, const QString &propertyName, const QVariant &value);
78
79
80QDESIGNER_UILIB_EXPORT QVariant domPropertyToVariant(const DomProperty *property);
81QDESIGNER_UILIB_EXPORT QVariant domPropertyToVariant(QAbstractFormBuilder *abstractFormBuilder, const QMetaObject *meta, const DomProperty *property);
82
83// This class exists to provide meta information
84// for enumerations only.
85class QAbstractFormBuilderGadget: public QWidget
86{
87 Q_OBJECT
88 Q_PROPERTY(Qt::ItemFlags itemFlags READ fakeItemFlags)
89 Q_PROPERTY(Qt::CheckState checkState READ fakeCheckState)
90 Q_PROPERTY(Qt::Alignment textAlignment READ fakeAlignment)
91 Q_PROPERTY(Qt::Orientation orientation READ fakeOrientation)
92 Q_PROPERTY(QSizePolicy::Policy sizeType READ fakeSizeType)
93 Q_PROPERTY(QPalette::ColorRole colorRole READ fakeColorRole)
94 Q_PROPERTY(QPalette::ColorGroup colorGroup READ fakeColorGroup)
95 Q_PROPERTY(QFont::StyleStrategy styleStrategy READ fakeStyleStrategy)
96 Q_PROPERTY(Qt::CursorShape cursorShape READ fakeCursorShape)
97 Q_PROPERTY(Qt::BrushStyle brushStyle READ fakeBrushStyle)
98 Q_PROPERTY(Qt::ToolBarArea toolBarArea READ fakeToolBarArea)
99 Q_PROPERTY(QGradient::Type gradientType READ fakeGradientType)
100 Q_PROPERTY(QGradient::Spread gradientSpread READ fakeGradientSpread)
101 Q_PROPERTY(QGradient::CoordinateMode gradientCoordinate READ fakeGradientCoordinate)
102 Q_PROPERTY(QLocale::Language language READ fakeLanguage)
103 Q_PROPERTY(QLocale::Country country READ fakeCountry)
104public:
105 QAbstractFormBuilderGadget() { Q_ASSERT(0); }
106
107 Qt::Orientation fakeOrientation() const { Q_ASSERT(0); return Qt::Horizontal; }
108 QSizePolicy::Policy fakeSizeType() const { Q_ASSERT(0); return QSizePolicy::Expanding; }
109 QPalette::ColorGroup fakeColorGroup() const { Q_ASSERT(0); return static_cast<QPalette::ColorGroup>(0); }
110 QPalette::ColorRole fakeColorRole() const { Q_ASSERT(0); return static_cast<QPalette::ColorRole>(0); }
111 QFont::StyleStrategy fakeStyleStrategy() const { Q_ASSERT(0); return QFont::PreferDefault; }
112 Qt::CursorShape fakeCursorShape() const { Q_ASSERT(0); return Qt::ArrowCursor; }
113 Qt::BrushStyle fakeBrushStyle() const { Q_ASSERT(0); return Qt::NoBrush; }
114 Qt::ToolBarArea fakeToolBarArea() const { Q_ASSERT(0); return Qt::NoToolBarArea; }
115 QGradient::Type fakeGradientType() const { Q_ASSERT(0); return QGradient::NoGradient; }
116 QGradient::Spread fakeGradientSpread() const { Q_ASSERT(0); return QGradient::PadSpread; }
117 QGradient::CoordinateMode fakeGradientCoordinate() const { Q_ASSERT(0); return QGradient::LogicalMode; }
118 QLocale::Language fakeLanguage() const { Q_ASSERT(0); return QLocale::C; }
119 QLocale::Country fakeCountry() const { Q_ASSERT(0); return QLocale::AnyCountry; }
120 Qt::ItemFlags fakeItemFlags() const { Q_ASSERT(0); return Qt::NoItemFlags; }
121 Qt::CheckState fakeCheckState() const { Q_ASSERT(0); return Qt::Unchecked; }
122 Qt::Alignment fakeAlignment() const { Q_ASSERT(0); return Qt::AlignLeft; }
123};
124
125// Convert key to value for a given QMetaEnum
126template <class EnumType>
127inline EnumType enumKeyToValue(const QMetaEnum &metaEnum,const char *key, const EnumType* = 0)
128{
129 int val = metaEnum.keyToValue(key);
130 if (val == -1) {
131
132 uiLibWarning(QCoreApplication::translate("QFormBuilder", "The enumeration-value '%1' is invalid. The default value '%2' will be used instead.")
133 .arg(QString::fromUtf8(key)).arg(QString::fromUtf8(metaEnum.key(0))));
134 val = metaEnum.value(0);
135 }
136 return static_cast<EnumType>(val);
137}
138
139// Convert keys to value for a given QMetaEnum
140template <class EnumType>
141inline EnumType enumKeysToValue(const QMetaEnum &metaEnum,const char *keys, const EnumType* = 0)
142{
143 int val = metaEnum.keysToValue(keys);
144 if (val == -1) {
145
146 uiLibWarning(QCoreApplication::translate("QFormBuilder", "The flag-value '%1' is invalid. Zero will be used instead.")
147 .arg(QString::fromUtf8(keys)));
148 val = 0;
149 }
150 return static_cast<EnumType>(QFlag(val));
151}
152
153// Access meta enumeration object of a qobject
154template <class QObjectType>
155inline QMetaEnum metaEnum(const char *name, const QObjectType* = 0)
156{
157 const int e_index = QObjectType::staticMetaObject.indexOfProperty(name);
158 Q_ASSERT(e_index != -1);
159 return QObjectType::staticMetaObject.property(e_index).enumerator();
160}
161
162// Convert key to value for enumeration by name
163template <class QObjectType, class EnumType>
164inline EnumType enumKeyOfObjectToValue(const char *enumName, const char *key, const QObjectType* = 0, const EnumType* = 0)
165{
166 const QMetaEnum me = metaEnum<QObjectType>(enumName);
167 return enumKeyToValue<EnumType>(me, key);
168}
169
170#ifdef QFORMINTERNAL_NAMESPACE
171}
172#endif
173
174QT_END_NAMESPACE
175
176#endif // UILIBPROPERTIES_H
Note: See TracBrowser for help on using the repository browser.