Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
5
#
include
"qdesigneraxwidget.h"
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
18
enum
{ debugAxWidget = 0 };
19
20
QT_BEGIN_NAMESPACE
21
22
/* XPM */
23
const
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
54
QDesignerAxWidget
::QDesignerAxWidget(QWidget *parent) :
55
QWidget(parent),
56
m_axImage(widgetIcon())
57
{
58
}
59
60
QDesignerAxWidget
::~
QDesignerAxWidget
()
61
{
62
delete
m_axobject;
63
}
64
65
QPixmap
QDesignerAxWidget
::widgetIcon()
66
{
67
return
QPixmap(widgetIconXPM);
68
}
69
70
QString
QDesignerAxWidget
::
control
()
const
71
{
72
if
(m_axobject)
73
return
m_axobject->control();
74
return
QString();
75
}
76
77
void
QDesignerAxWidget
::
setControl
(
const
QString &clsid)
78
{
79
if
(clsid == control())
80
return
;
81
if
(clsid.isEmpty()) {
82
resetControl
(
)
;
83
}
else
{
84
loadControl(clsid);
85
}
86
}
87
void
QDesignerAxWidget
::
resetControl
()
88
{
89
if
(!m_axobject)
90
return
;
91
delete
m_axobject;
92
m_axobject =
nullptr
;
93
update();
94
}
95
96
bool
QDesignerAxWidget
::
loadControl
(
const
QString &clsid)
97
{
98
if
(clsid.isEmpty())
99
return
false
;
100
if
(m_axobject)
101
resetControl
(
)
;
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
113
QSize
QDesignerAxWidget
::
sizeHint
()
const
114
{
115
if
(m_axobject)
116
return
m_axobject->sizeHint();
117
return
m_defaultSize;
118
}
119
120
QSize
QDesignerAxWidget
::
minimumSizeHint
()
const
121
{
122
if
(m_axobject)
123
return
m_axobject->minimumSizeHint();
124
return
QWidget::minimumSizeHint();
125
}
126
127
void
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
160
QDesignerAxPluginWidget
::
QDesignerAxPluginWidget
(QWidget *parent) :
161
QDesignerAxWidget
(parent)
162
{
163
}
164
165
QDesignerAxPluginWidget
::~
QDesignerAxPluginWidget
() =
default
;
166
167
const
QMetaObject
*
QDesignerAxPluginWidget
::
metaObject
()
const
168
{
169
if
(
const
QAxWidget *aw =
axobject
())
170
return
aw->metaObject();
171
172
return
QDesignerAxWidget::metaObject();
173
}
174
175
#
ifndef
QT_NO_EXCEPTIONS
176
177
static
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
185
static
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
191
int
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
236
QT_END_NAMESPACE
QDesignerAxPluginWidget
Definition
qdesigneraxwidget.h:70
QDesignerAxPluginWidget::QDesignerAxPluginWidget
QDesignerAxPluginWidget(QWidget *parent)
Definition
qdesigneraxwidget.cpp:160
QDesignerAxPluginWidget::metaObject
const QMetaObject * metaObject() const override
Definition
qdesigneraxwidget.cpp:167
QDesignerAxPluginWidget::qt_metacall
int qt_metacall(QMetaObject::Call, int, void **) override
Definition
qdesigneraxwidget.cpp:191
QDesignerAxPluginWidget::~QDesignerAxPluginWidget
virtual ~QDesignerAxPluginWidget()
QDesignerAxWidget
Definition
qdesigneraxwidget.h:29
QDesignerAxWidget::axobject
QAxWidget * axobject() const
Definition
qdesigneraxwidget.h:60
QDesignerAxWidget::resetControl
void resetControl()
Definition
qdesigneraxwidget.cpp:87
QDesignerAxWidget::paintEvent
void paintEvent(QPaintEvent *event) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
Definition
qdesigneraxwidget.cpp:127
QDesignerAxWidget::control
QString control() const
Definition
qdesigneraxwidget.cpp:70
QDesignerAxWidget::minimumSizeHint
QSize minimumSizeHint() const override
Definition
qdesigneraxwidget.cpp:120
QDesignerAxWidget::~QDesignerAxWidget
virtual ~QDesignerAxWidget()
Definition
qdesigneraxwidget.cpp:60
QDesignerAxWidget::loadControl
bool loadControl(const QString &clsid)
Definition
qdesigneraxwidget.cpp:96
QDesignerAxWidget::sizeHint
QSize sizeHint() const override
Definition
qdesigneraxwidget.cpp:113
QDesignerAxWidget::DrawControl
@ DrawControl
Definition
qdesigneraxwidget.h:53
QDesignerAxWidget::DrawIndicator
@ DrawIndicator
Definition
qdesigneraxwidget.h:53
QDesignerAxWidget::DrawFrame
@ DrawFrame
Definition
qdesigneraxwidget.h:53
QDesignerAxWidget::setControl
void setControl(const QString &clsid)
Definition
qdesigneraxwidget.cpp:77
widgetIconXPM
QT_BEGIN_NAMESPACE const char * widgetIconXPM[]
Definition
qdesigneraxwidget.cpp:23
isInheritedCall
static bool isInheritedCall(const QMetaObject *mo, QMetaObject::Call call, int id)
Definition
qdesigneraxwidget.cpp:185
msgComException
static QString msgComException(const QObject *o, const QMetaObject::Call call, int index)
Definition
qdesigneraxwidget.cpp:177
qttools
src
designer
src
plugins
activeqt
qdesigneraxwidget.cpp
Generated on
for Qt by
1.18.0