1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2020 The Qt Company Ltd. |
4 | ** Contact: https://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 https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://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 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | // Gui types |
41 | #include "qbitmap.h" |
42 | #include "qbrush.h" |
43 | #include "qcolor.h" |
44 | #include "qcolorspace.h" |
45 | #include "qcursor.h" |
46 | #include "qfont.h" |
47 | #include "qimage.h" |
48 | #if QT_CONFIG(shortcut) |
49 | # include "qkeysequence.h" |
50 | #endif |
51 | #include "qtransform.h" |
52 | #include "qpalette.h" |
53 | #include "qpen.h" |
54 | #include "qpixmap.h" |
55 | #include "qpolygon.h" |
56 | #include "qregion.h" |
57 | #include "qtextformat.h" |
58 | #include "qmatrix4x4.h" |
59 | #include "qvector2d.h" |
60 | #include "qvector3d.h" |
61 | #include "qvector4d.h" |
62 | #include "qquaternion.h" |
63 | #include "qicon.h" |
64 | |
65 | // Core types |
66 | #include "qvariant.h" |
67 | #include "qbitarray.h" |
68 | #include "qbytearray.h" |
69 | #include "qdatastream.h" |
70 | #include "qdebug.h" |
71 | #include "qmap.h" |
72 | #include "qdatetime.h" |
73 | #include "qlist.h" |
74 | #include "qstring.h" |
75 | #include "qstringlist.h" |
76 | #include "qurl.h" |
77 | #include "qlocale.h" |
78 | #include "quuid.h" |
79 | |
80 | #ifndef QT_NO_GEOM_VARIANT |
81 | #include "qsize.h" |
82 | #include "qpoint.h" |
83 | #include "qrect.h" |
84 | #include "qline.h" |
85 | #endif |
86 | |
87 | #include <float.h> |
88 | |
89 | #include "private/qvariant_p.h" |
90 | #include <private/qmetatype_p.h> |
91 | |
92 | QT_BEGIN_NAMESPACE |
93 | |
94 | namespace { |
95 | struct GuiTypesFilter { |
96 | template<typename T> |
97 | struct Acceptor { |
98 | static const bool IsAccepted = QModulesPrivate::QTypeModuleInfo<T>::IsGui && QtMetaTypePrivate::TypeDefinition<T>::IsAvailable; |
99 | }; |
100 | }; |
101 | |
102 | static const struct : QMetaTypeModuleHelper |
103 | { |
104 | #define QT_IMPL_METATYPEINTERFACE_GUI_TYPES(MetaTypeName, MetaTypeId, RealName) \ |
105 | QT_METATYPE_INTERFACE_INIT(RealName), |
106 | |
107 | const QtPrivate::QMetaTypeInterface *interfaceForType(int type) const override { |
108 | switch (type) { |
109 | QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_CONVERT_ID_TO_TYPE) |
110 | default: return nullptr; |
111 | } |
112 | } |
113 | #undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES |
114 | |
115 | bool convert(const void *from, int fromTypeId, void *to, int toTypeId) const override |
116 | { |
117 | Q_ASSERT(fromTypeId != toTypeId); |
118 | |
119 | bool onlyCheck = (from == nullptr && to == nullptr); |
120 | |
121 | using Int = int; |
122 | switch (makePair(toTypeId, fromTypeId)) { |
123 | QMETATYPE_CONVERTER(QByteArray, QColor, |
124 | result = source.name(source.alpha() != 255 ? |
125 | QColor::HexArgb : QColor::HexRgb).toLatin1(); |
126 | return true; |
127 | ); |
128 | QMETATYPE_CONVERTER(QColor, QByteArray, |
129 | result.setNamedColor(QLatin1String(source)); |
130 | return result.isValid(); |
131 | ); |
132 | QMETATYPE_CONVERTER(QString, QColor, |
133 | result = source.name(source.alpha() != 255 ? |
134 | QColor::HexArgb : QColor::HexRgb); |
135 | return true; |
136 | ); |
137 | QMETATYPE_CONVERTER(QColor, QString, |
138 | result.setNamedColor(source); |
139 | return result.isValid(); |
140 | ); |
141 | #if QT_CONFIG(shortcut) |
142 | QMETATYPE_CONVERTER(QString, QKeySequence, |
143 | result = source.toString(QKeySequence::NativeText); |
144 | return true; |
145 | ); |
146 | QMETATYPE_CONVERTER(QKeySequence, QString, result = source; return true;); |
147 | QMETATYPE_CONVERTER(Int, QKeySequence, |
148 | result = source.isEmpty() ? 0 : source[0].toCombined(); |
149 | return true; |
150 | ); |
151 | QMETATYPE_CONVERTER(QKeySequence, Int, result = source; return true;); |
152 | #endif |
153 | QMETATYPE_CONVERTER(QString, QFont, result = source.toString(); return true;); |
154 | QMETATYPE_CONVERTER(QFont, QString, return result.fromString(source);); |
155 | QMETATYPE_CONVERTER(QPixmap, QImage, result = QPixmap::fromImage(source); return true;); |
156 | QMETATYPE_CONVERTER(QImage, QPixmap, result = source.toImage(); return true;); |
157 | QMETATYPE_CONVERTER(QPixmap, QBitmap, result = source; return true;); |
158 | QMETATYPE_CONVERTER(QBitmap, QPixmap, result = QBitmap::fromPixmap(source); return true;); |
159 | QMETATYPE_CONVERTER(QImage, QBitmap, result = source.toImage(); return true;); |
160 | QMETATYPE_CONVERTER(QBitmap, QImage, result = QBitmap::fromImage(source); return true;); |
161 | QMETATYPE_CONVERTER(QPixmap, QBrush, result = source.texture(); return true;); |
162 | QMETATYPE_CONVERTER(QBrush, QPixmap, result = source; return true;); |
163 | QMETATYPE_CONVERTER(QColor, QBrush, |
164 | if (source.style() == Qt::SolidPattern) { |
165 | result = source.color(); |
166 | return true; |
167 | } |
168 | return false; |
169 | ); |
170 | QMETATYPE_CONVERTER(QBrush, QColor, result = source; return true;); |
171 | default: |
172 | break; |
173 | } |
174 | return false; |
175 | } |
176 | } qVariantGuiHelper; |
177 | |
178 | } // namespace used to hide QVariant handler |
179 | |
180 | void qRegisterGuiVariant() |
181 | { |
182 | qMetaTypeGuiHelper = &qVariantGuiHelper; |
183 | } |
184 | Q_CONSTRUCTOR_FUNCTION(qRegisterGuiVariant) |
185 | |
186 | QT_END_NAMESPACE |
187 | |