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