Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdesigneraxwidget.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtCore/qmetaobject.h>
7#include <QtCore/qdebug.h>
8#include <QtGui/qicon.h>
9#include <QtGui/qpainter.h>
10#include <QtGui/qevent.h>
11
12#include <QtAxContainer/QAxWidget>
13
14#include <qt_windows.h>
15#include <olectl.h>
16
17enum { debugAxWidget = 0 };
18
20
21/* XPM */
22const char *widgetIconXPM[]={
23"22 22 6 1",
24"a c #000000",
25"# c #808080",
26"+ c #aaa5a0",
27"b c #dddddd",
28"* c #d4d0c8",
29". c none",
30".........#aa#...#aa#..",
31".........abba...abba..",
32".........abba...abba..",
33".........#aa#...#aa#..",
34"..........aa.....aa...",
35"..........aa.....aa...",
36"..........aa.....aa...",
37".......aaaaaaaaaaaaaaa",
38".......a*************a",
39".......a************#a",
40".......a***********+#a",
41".......a***********+#a",
42".......a***********+#a",
43"#aa#...a***********+#a",
44"abbaaaaa***********+#a",
45"abbaaaaa***********+#a",
46"#aa#...a***********+#a",
47".......a***********+#a",
48".......a***********+#a",
49".......a**++++++++++#a",
50".......a*############a",
51".......aaaaaaaaaaaaaaa"};
52
53QDesignerAxWidget::QDesignerAxWidget(QWidget *parent) :
54 QWidget(parent),
55 m_axImage(widgetIcon())
56{
57}
58
60{
61 delete m_axobject;
62}
63
64QPixmap QDesignerAxWidget::widgetIcon()
65{
66 return QPixmap(widgetIconXPM);
67}
68
70{
71 if (m_axobject)
72 return m_axobject->control();
73 return QString();
74}
75
76void QDesignerAxWidget::setControl(const QString &clsid)
77{
78 if (clsid == control())
79 return;
80 if (clsid.isEmpty()) {
82 } else {
83 loadControl(clsid);
84 }
85}
87{
88 if (!m_axobject)
89 return;
90 delete m_axobject;
91 m_axobject = nullptr;
92 update();
93}
94
95bool QDesignerAxWidget::loadControl(const QString &clsid)
96{
97 if (clsid.isEmpty())
98 return false;
99 if (m_axobject)
101 m_axobject = new QAxWidget();
102
103 if (!m_axobject->setControl(clsid)) {
104 delete m_axobject;
105 m_axobject = nullptr;
106 return false;
107 }
108 update();
109 return true;
110}
111
113{
114 if (m_axobject)
115 return m_axobject->sizeHint();
116 return m_defaultSize;
117}
118
120{
121 if (m_axobject)
122 return m_axobject->minimumSizeHint();
123 return QWidget::minimumSizeHint();
124}
125
126void QDesignerAxWidget::paintEvent(QPaintEvent * /*event */)
127{
128 QPainter p(this);
129 const QRect r = contentsRect();
130 const int contentsWidth = r.width();
131 const int contentsHeight= r.height();
132 if (m_axobject) { // QAxWidget has no concept of sizeHint()
133 if (m_drawFlags & DrawControl) {
134 m_axobject->resize(size());
135 m_axobject->render(&p, pos());
136 }
137 if (m_drawFlags & DrawIndicator) {
138 static const QString loaded = tr("Control loaded");
139 QColor patternColor(Qt::green);
140 if (m_drawFlags & DrawControl)
141 patternColor.setAlpha(80);
142 p.setBrush(QBrush(patternColor, Qt::BDiagPattern));
143 p.setPen(Qt::black);
144 if (r.height() > 5)
145 p.drawText(5,contentsHeight - 5, loaded);
146 }
147 }
148 if (m_drawFlags & DrawFrame) {
149 p.drawRect(r.adjusted(0, 0, -1, -1));
150 }
151 if (m_drawFlags & DrawIndicator) {
152 if (contentsWidth > m_axImage.width() && contentsHeight > m_axImage.height())
153 p.drawPixmap((contentsWidth - m_axImage.width()) / 2,
154 (contentsHeight-m_axImage.height()) / 2, m_axImage);
155 }
156}
157
158// --------- QDesignerAxPluginWidget
160 QDesignerAxWidget(parent)
161{
162}
163
165
167{
168 if (const QAxWidget *aw = axobject())
169 return aw->metaObject();
170
171 return QDesignerAxWidget::metaObject();
172}
173
174#ifndef QT_NO_EXCEPTIONS
175
176static QString msgComException(const QObject *o, const QMetaObject::Call call, int index)
177{
178 return QDesignerAxWidget::tr("A COM exception occurred when executing a meta call of type %1, index %2 of \"%3\".").
179 arg(call).arg(index).arg(o->objectName());
180}
181
182#endif // QT_NO_EXCEPTIONS
183
184static bool isInheritedCall(const QMetaObject *mo, QMetaObject::Call call, int id)
185{
186 return call == QMetaObject::InvokeMetaMethod
187 ? (id < mo->methodOffset()) : (id < mo->propertyOffset());
188}
189
190int QDesignerAxPluginWidget::qt_metacall(QMetaObject::Call call, int signal, void **argv)
191{
192 QAxWidget *aw = axobject();
193 if (!aw)
194 return QDesignerAxWidget::qt_metacall(call,signal,argv);
195
196
197 const QMetaObject *mo = metaObject();
198 // Have base class handle inherited stuff (geometry, enabled...)
199 if (isInheritedCall(mo, call, signal)) {
200 // Skip over QAxBaseWidget
201 return isInheritedCall(mo->superClass(), call, signal)
202 ? QDesignerAxWidget::qt_metacall(call, signal, argv) : -1;
203 }
204
205 int rc = -1;
206#ifndef QT_NO_EXCEPTIONS
207 try {
208#endif
209 if (debugAxWidget)
210 if (call != QMetaObject::InvokeMetaMethod)
211 qDebug() << objectName() << call << signal << mo->property(signal).name();
212 switch (call) {
213 case QMetaObject::ResetProperty:
214 rc = aw->qt_metacall(call, signal, argv);
215 update();
216 m_propValues.remove(signal);
217 break;
218 case QMetaObject::WriteProperty:
219 rc = aw->qt_metacall(call, signal, argv);
220 update();
221 m_propValues.insert(signal, true);
222 break;
223 default:
224 rc = aw->qt_metacall(call, signal, argv);
225 break;
226 }
227#ifndef QT_NO_EXCEPTIONS
228 } catch(...) {
229 qWarning(msgComException(this, call, signal).toUtf8());
230 }
231#endif
232 return rc;
233}
234
235QT_END_NAMESPACE
QDesignerAxPluginWidget(QWidget *parent)
const QMetaObject * metaObject() const override
int qt_metacall(QMetaObject::Call, int, void **) override
virtual ~QDesignerAxPluginWidget()
QAxWidget * axobject() const
void paintEvent(QPaintEvent *event) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
QString control() const
QSize minimumSizeHint() const override
bool loadControl(const QString &clsid)
QSize sizeHint() const override
void setControl(const QString &clsid)
QT_BEGIN_NAMESPACE const char * widgetIconXPM[]
static bool isInheritedCall(const QMetaObject *mo, QMetaObject::Call call, int id)
static QString msgComException(const QObject *o, const QMetaObject::Call call, int index)