source: trunk/tools/designer/src/plugins/activeqt/qdesigneraxwidget.cpp@ 846

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

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 7.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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#include "qdesigneraxwidget.h"
43
44#include <QtCore/QMetaProperty>
45#include <QtCore/QDebug>
46#include <QtGui/QIcon>
47#include <QtGui/QPainter>
48#include <QtGui/QResizeEvent>
49
50#include <ActiveQt/QAxWidget>
51
52#include <olectl.h>
53#include <qaxtypes.h>
54
55enum { debugAxWidget = 0 };
56
57QT_BEGIN_NAMESPACE
58
59/* XPM */
60const char *widgetIconXPM[]={
61"22 22 6 1",
62"a c #000000",
63"# c #808080",
64"+ c #aaa5a0",
65"b c #dddddd",
66"* c #d4d0c8",
67". c none",
68".........#aa#...#aa#..",
69".........abba...abba..",
70".........abba...abba..",
71".........#aa#...#aa#..",
72"..........aa.....aa...",
73"..........aa.....aa...",
74"..........aa.....aa...",
75".......aaaaaaaaaaaaaaa",
76".......a*************a",
77".......a************#a",
78".......a***********+#a",
79".......a***********+#a",
80".......a***********+#a",
81"#aa#...a***********+#a",
82"abbaaaaa***********+#a",
83"abbaaaaa***********+#a",
84"#aa#...a***********+#a",
85".......a***********+#a",
86".......a***********+#a",
87".......a**++++++++++#a",
88".......a*############a",
89".......aaaaaaaaaaaaaaa"};
90
91QDesignerAxWidget::QDesignerAxWidget(QWidget *parent) :
92 QWidget(parent),
93 m_defaultSize(80, 70),
94 m_drawFlags(DrawIndicator|DrawFrame|DrawControl),
95 m_axobject(0),
96 m_axImage(widgetIcon())
97{
98}
99
100QDesignerAxWidget::~QDesignerAxWidget()
101{
102 delete m_axobject;
103}
104
105QPixmap QDesignerAxWidget::widgetIcon()
106{
107 return QPixmap(widgetIconXPM);
108}
109
110QString QDesignerAxWidget::control() const
111{
112 if (m_axobject)
113 return m_axobject->control();
114 return QString();
115}
116
117void QDesignerAxWidget::setControl(const QString &clsid)
118{
119 if (clsid == control())
120 return;
121 if (clsid.isEmpty()) {
122 resetControl();
123 } else {
124 loadControl(clsid);
125 }
126}
127void QDesignerAxWidget::resetControl()
128{
129 if (!m_axobject)
130 return;
131 delete m_axobject;
132 m_axobject = 0;
133 update();
134}
135
136bool QDesignerAxWidget::loadControl(const QString &clsid)
137{
138 if (clsid.isEmpty())
139 return false;
140 if (m_axobject)
141 resetControl();
142 m_axobject = new QAxWidget();
143
144 if (!m_axobject->setControl(clsid)) {
145 delete m_axobject;
146 m_axobject = 0;
147 return false;
148 }
149 update();
150 return true;
151}
152
153QSize QDesignerAxWidget::sizeHint() const
154{
155 if (m_axobject)
156 return m_axobject->sizeHint();
157 return m_defaultSize;
158}
159
160QSize QDesignerAxWidget::minimumSizeHint() const
161{
162 if (m_axobject)
163 return m_axobject->minimumSizeHint();
164 return QWidget::minimumSizeHint();
165}
166
167void QDesignerAxWidget::paintEvent(QPaintEvent * /*event */)
168{
169 QPainter p(this);
170 const QRect r = contentsRect();
171 const int contentsWidth = r.width();
172 const int contentsHeight= r.height();
173 if (m_axobject) { // QAxWidget has no concept of sizeHint()
174 if (m_drawFlags & DrawControl) {
175 m_axobject->resize(size());
176 m_axobject->render(&p);
177 }
178 if (m_drawFlags & DrawIndicator) {
179 static const QString loaded = tr("Control loaded");
180 QColor patternColor(Qt::green);
181 if (m_drawFlags & DrawControl)
182 patternColor.setAlpha(80);
183 p.setBrush(QBrush(patternColor, Qt::BDiagPattern));
184 p.setPen(Qt::black);
185 if (r.height() > 5)
186 p.drawText(5,contentsHeight - 5, loaded);
187 }
188 }
189 if (m_drawFlags & DrawFrame) {
190 p.drawRect(r.adjusted(0, 0, -1, -1));
191 }
192 if (m_drawFlags & DrawIndicator) {
193 if (contentsWidth > m_axImage.width() && contentsHeight > m_axImage.height())
194 p.drawPixmap((contentsWidth - m_axImage.width()) / 2,
195 (contentsHeight-m_axImage.height()) / 2, m_axImage);
196 }
197}
198
199// --------- QDesignerAxPluginWidget