1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 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 "qaxwidgetpropertysheet.h"
|
---|
43 | #include "qdesigneraxwidget.h"
|
---|
44 |
|
---|
45 | #include <QtDesigner/QDesignerMemberSheetExtension>
|
---|
46 | #include <QtDesigner/QDesignerFormWindowInterface>
|
---|
47 | #include <QtDesigner/QDesignerFormEditorInterface>
|
---|
48 | #include <QtDesigner/QDesignerPropertyEditorInterface>
|
---|
49 |
|
---|
50 | #include <QtDesigner/QExtensionManager>
|
---|
51 | #include <QtCore/QDebug>
|
---|
52 | #include <QtCore/QTimer>
|
---|
53 |
|
---|
54 | static const char *geometryPropertyC = "geometry";
|
---|
55 |
|
---|
56 | QT_BEGIN_NAMESPACE
|
---|
57 |
|
---|
58 | const char *QAxWidgetPropertySheet::controlPropertyName = "control";
|
---|
59 |
|
---|
60 | QAxWidgetPropertySheet::QAxWidgetPropertySheet(QDesignerAxWidget *object, QObject *parent) :
|
---|
61 | QDesignerPropertySheet(object, parent),
|
---|
62 | m_controlProperty(controlPropertyName),
|
---|
63 | m_propertyGroup(QLatin1String("QAxWidget"))
|
---|
64 | {
|
---|
65 | if (!axWidget()->loaded()) { // For some obscure reason....
|
---|
66 | const int controlIndex = QDesignerPropertySheet::indexOf(m_controlProperty);
|
---|
67 | setPropertyGroup(controlIndex, m_propertyGroup);
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | bool QAxWidgetPropertySheet::isEnabled(int index) const
|
---|
72 | {
|
---|
73 | if (propertyName(index) == m_controlProperty)
|
---|
74 | return false;
|
---|
75 | return QDesignerPropertySheet::isEnabled(index);
|
---|
76 | }
|
---|
77 |
|
---|
78 | bool QAxWidgetPropertySheet::dynamicPropertiesAllowed() const
|
---|
79 | {
|
---|
80 | return false;
|
---|
81 | }
|
---|
82 |
|
---|
83 | QDesignerAxWidget *QAxWidgetPropertySheet::axWidget() const
|
---|
84 | {
|
---|
85 | return static_cast<QDesignerAxWidget*>(object());
|
---|
86 | }
|
---|
87 |
|
---|
88 | // Reload as the meta object changes.
|
---|
89 | bool QAxWidgetPropertySheet::reset(int index)
|
---|
90 | {
|
---|
91 | const QString name = propertyName(index);
|
---|
92 | QMap<QString, QVariant>::iterator it = m_currentProperties.changedProperties.find(name);
|
---|
93 | if (it != m_currentProperties.changedProperties.end())
|
---|
94 | m_currentProperties.changedProperties.erase(it);
|
---|
95 | if (name != m_controlProperty)
|
---|
96 | return QDesignerPropertySheet::reset(index);
|
---|
97 | axWidget()->resetControl();
|
---|
98 | QTimer::singleShot(0, this, SLOT(updatePropertySheet()));
|
---|
99 | return true;
|
---|
100 | }
|
---|
101 |
|
---|
102 | void QAxWidgetPropertySheet::setProperty(int index, const QVariant &value)
|
---|
103 | {
|
---|
104 |
|
---|
105 | // take care of all changed properties
|
---|
106 | const QString name = propertyName(index);
|
---|
107 | m_currentProperties.changedProperties[name] = value;
|
---|
108 | if (name != m_controlProperty) {
|
---|
109 | QDesignerPropertySheet::setProperty(index, value);
|
---|
110 | return;
|
---|
111 | }
|
---|
112 | // Loading forms: Reload
|
---|
113 | if (name == m_controlProperty) {
|
---|
114 | const QString clsid = value.toString();
|
---|
115 | if (clsid.isEmpty() || !axWidget()->loadControl(clsid))
|
---|
116 | reset(index);
|
---|
117 | else
|
---|
118 | QTimer::singleShot(100, this, SLOT(updatePropertySheet()));
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | int QAxWidgetPropertySheet::indexOf(const QString &name) const
|
---|
123 | {
|
---|
124 | const int index = QDesignerPropertySheet::indexOf(name);
|
---|
125 | if (index != -1)
|
---|
126 | return index;
|
---|
127 | // Loading before recreation of sheet in timer slot: Add a fake property to store the value
|
---|
128 | const QVariant dummValue(0);
|
---|
129 | QAxWidgetPropertySheet *that = const_cast<QAxWidgetPropertySheet *>(this);
|
---|
130 | const int newIndex = that->createFakeProperty(name, dummValue);
|
---|
131 | that->setPropertyGroup(newIndex, m_propertyGroup);
|
---|
132 | return newIndex;
|
---|
133 | }
|
---|
134 |
|
---|
135 | void QAxWidgetPropertySheet::updatePropertySheet()
|
---|
136 | {
|
---|
137 | // refresh the property sheet (we are deleting m_currentProperties)
|
---|
138 | struct SavedProperties tmp = m_currentProperties;
|
---|
139 | QDesignerAxWidget *axw = axWidget();
|
---|
140 | QDesignerFormWindowInterface *formWin = QDesignerFormWindowInterface::findFormWindow(axw);
|
---|
141 | Q_ASSERT(formWin != 0);
|
---|
142 | tmp.widget = axw;
|
---|
143 | tmp.clsid = axw->control();
|
---|
144 | // Delete the sheets as they cache the meta object and other information
|
---|
145 | delete this;
|
---|
146 | delete qt_extension<QDesignerMemberSheetExtension *>(formWin->core()->extensionManager(), axw);
|
---|
147 | reloadPropertySheet(tmp, formWin);
|
---|
148 | }
|
---|
149 |
|
---|
150 | void QAxWidgetPropertySheet::reloadPropertySheet(const struct SavedProperties &properties, QDesignerFormWindowInterface *formWin)
|
---|
151 | {
|
---|
152 | QDesignerFormEditorInterface *core = formWin->core();
|
---|
153 | //Recreation of the property sheet
|
---|
154 | QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension *>(core->extensionManager(), properties.widget);
|
---|
155 |
|
---|
156 | bool foundGeometry = false;
|
---|
157 | const QString geometryProperty = QLatin1String(geometryPropertyC);
|
---|
158 | const SavedProperties::NamePropertyMap::const_iterator cend = properties.changedProperties.constEnd();
|
---|
159 | for (SavedProperties::NamePropertyMap::const_iterator i = properties.changedProperties.constBegin(); i != cend; ++i) {
|
---|
160 | const QString name = i.key();
|
---|
161 | const int index = sheet->indexOf(name);
|
---|
162 | if (index == -1)
|
---|
163 | continue;
|
---|
164 | // filter out geometry as this will resize the control
|
---|
165 | // to is default size even if it is attached to an layout
|
---|
166 | // but set the changed flag to work around preview bug...
|
---|
167 | if (name == geometryProperty) {
|
---|
168 | sheet->setChanged(index, true);
|
---|
169 | foundGeometry = true;
|
---|
170 | continue;
|
---|
171 | }
|
---|
172 | if (name == QLatin1String(controlPropertyName)) {
|
---|
173 | sheet->setChanged(index, !i.value().toString().isEmpty());
|
---|
174 | continue;
|
---|
175 | }
|
---|
176 | sheet->setChanged(index, true);
|
---|
177 | sheet->setProperty(index, i.value());
|
---|
178 | }
|
---|
179 |
|
---|
180 | if (!foundGeometry) // Make sure geometry is always changed in Designer
|
---|
181 | sheet->setChanged(sheet->indexOf(geometryProperty), true);
|
---|
182 |
|
---|
183 | if (core->propertyEditor()->object() == properties.widget) {
|
---|
184 | formWin->clearSelection(true);
|
---|
185 | formWin->selectWidget(properties.widget);
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | QT_END_NAMESPACE
|
---|