author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 09:15:16 +0300 | |
branch | RCL_3 |
changeset 11 | 68d3b337861b |
parent 5 | d3bac044e0f0 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the Qt Designer of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qdesigner_taskmenu_p.h" |
|
43 |
#include "qdesigner_command_p.h" |
|
44 |
#include "richtexteditor_p.h" |
|
45 |
#include "plaintexteditor_p.h" |
|
46 |
#include "stylesheeteditor_p.h" |
|
47 |
#include "qlayout_widget_p.h" |
|
48 |
#include "layout_p.h" |
|
49 |
#include "spacer_widget_p.h" |
|
50 |
#include "textpropertyeditor_p.h" |
|
51 |
#include "promotiontaskmenu_p.h" |
|
52 |
#include "metadatabase_p.h" |
|
53 |
#include "scriptdialog_p.h" |
|
54 |
#include "scriptcommand_p.h" |
|
55 |
#include "signalslotdialog_p.h" |
|
56 |
#include "qdesigner_membersheet_p.h" |
|
57 |
#include "qdesigner_propertycommand_p.h" |
|
58 |
#include "qdesigner_utils_p.h" |
|
59 |
#include "qdesigner_objectinspector_p.h" |
|
60 |
#include "morphmenu_p.h" |
|
61 |
#include "qdesigner_integration_p.h" |
|
62 |
#include "formlayoutmenu_p.h" |
|
63 |
#include "ui_selectsignaldialog.h" |
|
64 |
#include "widgetfactory_p.h" |
|
65 |
#include "abstractintrospection_p.h" |
|
66 |
#include "widgetdatabase_p.h" |
|
67 |
||
68 |
#include <shared_enums_p.h> |
|
69 |
||
70 |
#include <QtDesigner/QDesignerFormWindowInterface> |
|
71 |
#include <QtDesigner/QDesignerFormWindowCursorInterface> |
|
72 |
#include <QtDesigner/QDesignerPropertySheetExtension> |
|
73 |
#include <QtDesigner/QDesignerFormEditorInterface> |
|
74 |
#include <QtDesigner/QDesignerLanguageExtension> |
|
75 |
#include <QtDesigner/QExtensionManager> |
|
76 |
||
77 |
#include <QtGui/QAction> |
|
78 |
#include <QtGui/QActionGroup> |
|
79 |
#include <QtGui/QWidget> |
|
80 |
#include <QtGui/QMenuBar> |
|
81 |
#include <QtGui/QMainWindow> |
|
82 |
#include <QtGui/QStatusBar> |
|
83 |
#include <QtGui/QDialogButtonBox> |
|
84 |
#include <QtGui/QVBoxLayout> |
|
85 |
#include <QtGui/QPushButton> |
|
86 |
#include <QtGui/QUndoStack> |
|
87 |
#include <QtCore/QDebug> |
|
88 |
#include <QtCore/QSignalMapper> |
|
89 |
#include <QtCore/QCoreApplication> |
|
90 |
||
91 |
QT_BEGIN_NAMESPACE |
|
92 |
||
93 |
static QMenuBar *findMenuBar(const QWidget *widget) |
|
94 |
{ |
|
95 |
const QList<QObject*> children = widget->children(); |
|
96 |
foreach (QObject *obj, widget->children()) { |
|
97 |
if (QMenuBar *mb = qobject_cast<QMenuBar*>(obj)) { |
|
98 |
return mb; |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
return 0; |
|
103 |
} |
|
104 |
||
105 |
static QStatusBar *findStatusBar(const QWidget *widget) |
|
106 |
{ |
|
107 |
const QList<QObject*> children = widget->children(); |
|
108 |
foreach (QObject *obj, widget->children()) { |
|
109 |
if (QStatusBar *sb = qobject_cast<QStatusBar*>(obj)) { |
|
110 |
return sb; |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
return 0; |
|
115 |
} |
|
116 |
||
117 |
static inline QAction *createSeparatorHelper(QObject *parent) { |
|
118 |
QAction *rc = new QAction(parent); |
|
119 |
rc->setSeparator(true); |
|
120 |
return rc; |
|
121 |
} |
|
122 |
||
123 |
static inline qdesigner_internal::QDesignerIntegration *integration(const QDesignerFormEditorInterface *core) { |
|
124 |
return qobject_cast<qdesigner_internal::QDesignerIntegration *>(core->integration()); |
|
125 |
} |
|
126 |
||
127 |
static QString objName(const QDesignerFormEditorInterface *core, QObject *object) { |
|
128 |
QDesignerPropertySheetExtension *sheet |
|
129 |
= qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), object); |
|
130 |
Q_ASSERT(sheet != 0); |
|
131 |
||
132 |
const QString objectNameProperty = QLatin1String("objectName"); |
|
133 |
const int index = sheet->indexOf(objectNameProperty); |
|
134 |
const qdesigner_internal::PropertySheetStringValue objectNameValue |
|
135 |
= qVariantValue<qdesigner_internal::PropertySheetStringValue>(sheet->property(index)); |
|
136 |
return objectNameValue.value(); |
|
137 |
} |
|
138 |
||
139 |
enum { ApplyMinimumWidth = 0x1, ApplyMinimumHeight = 0x2, ApplyMaximumWidth = 0x4, ApplyMaximumHeight = 0x8 }; |
|
140 |
||
141 |
namespace { |
|
142 |
// --------------- ObjectNameDialog |
|
143 |
class ObjectNameDialog : public QDialog |
|
144 |
{ |
|
145 |
public: |
|
146 |
ObjectNameDialog(QWidget *parent, const QString &oldName); |
|
147 |
QString newObjectName() const; |
|
148 |
||
149 |
private: |
|
150 |
qdesigner_internal::TextPropertyEditor *m_editor; |
|
151 |
}; |
|
152 |
||
153 |
ObjectNameDialog::ObjectNameDialog(QWidget *parent, const QString &oldName) |
|
154 |
: QDialog(parent), |
|
155 |
m_editor( new qdesigner_internal::TextPropertyEditor(this, qdesigner_internal::TextPropertyEditor::EmbeddingNone, |
|
156 |
qdesigner_internal::ValidationObjectName)) |
|
157 |
{ |
|
158 |
setWindowTitle(QCoreApplication::translate("ObjectNameDialog", "Change Object Name")); |
|
159 |
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); |
|
160 |
||
161 |
QVBoxLayout *vboxLayout = new QVBoxLayout(this); |
|
162 |
vboxLayout->addWidget(new QLabel(QCoreApplication::translate("ObjectNameDialog", "Object Name"))); |
|
163 |
||
164 |
m_editor->setText(oldName); |
|
165 |
m_editor->selectAll(); |
|
166 |
m_editor->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
|
167 |
vboxLayout->addWidget(m_editor); |
|
168 |
||
169 |
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, |
|
170 |
Qt::Horizontal, this); |
|
171 |
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); |
|
172 |
okButton->setDefault(true); |
|
173 |
vboxLayout->addWidget(buttonBox); |
|
174 |
||
175 |
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); |
|
176 |
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); |
|
177 |
} |
|
178 |
||
179 |
QString ObjectNameDialog::newObjectName() const |
|
180 |
{ |
|
181 |
return m_editor->text(); |
|
182 |
} |
|
183 |
||
184 |
} |
|
185 |
||
186 |
namespace qdesigner_internal { |
|
187 |
// -------------- QDesignerTaskMenuPrivate |
|
188 |
class QDesignerTaskMenuPrivate { |
|
189 |
public: |
|
190 |
QDesignerTaskMenuPrivate(QWidget *widget, QObject *parent); |
|
191 |
||
192 |
QDesignerTaskMenu *m_q; |
|
193 |
QPointer<QWidget> m_widget; |
|
194 |
QAction *m_separator; |
|
195 |
QAction *m_separator2; |
|
196 |
QAction *m_separator3; |
|
197 |
QAction *m_separator4; |
|
198 |
QAction *m_separator5; |
|
199 |
QAction *m_separator6; |
|
200 |
QAction *m_separator7; |
|
201 |
QAction *m_changeObjectNameAction; |
|
202 |
QAction *m_changeToolTip; |
|
203 |
QAction *m_changeWhatsThis; |
|
204 |
QAction *m_changeStyleSheet; |
|
205 |
MorphMenu *m_morphMenu; |
|
206 |
FormLayoutMenu *m_formLayoutMenu; |
|
207 |
||
208 |
QAction *m_addMenuBar; |
|
209 |
QAction *m_addToolBar; |
|
210 |
QAction *m_addStatusBar; |
|
211 |
QAction *m_removeStatusBar; |
|
212 |
QAction *m_changeScript; |
|
213 |
QAction *m_containerFakeMethods; |
|
214 |
QAction *m_navigateToSlot; |
|
215 |
PromotionTaskMenu* m_promotionTaskMenu; |
|
216 |
QActionGroup *m_sizeActionGroup; |
|
217 |
QAction *m_sizeActionsSubMenu; |
|
218 |
}; |
|
219 |
||
220 |
QDesignerTaskMenuPrivate::QDesignerTaskMenuPrivate(QWidget *widget, QObject *parent) : |
|
221 |
m_q(0), |
|
222 |
m_widget(widget), |
|
223 |
m_separator(createSeparatorHelper(parent)), |
|
224 |
m_separator2(createSeparatorHelper(parent)), |
|
225 |
m_separator3(createSeparatorHelper(parent)), |
|
226 |
m_separator4(createSeparatorHelper(parent)), |
|
227 |
m_separator5(createSeparatorHelper(parent)), |
|
228 |
m_separator6(createSeparatorHelper(parent)), |
|
229 |
m_separator7(createSeparatorHelper(parent)), |
|
230 |
m_changeObjectNameAction(new QAction(QDesignerTaskMenu::tr("Change objectName..."), parent)), |
|
231 |
m_changeToolTip(new QAction(QDesignerTaskMenu::tr("Change toolTip..."), parent)), |
|
232 |
m_changeWhatsThis(new QAction(QDesignerTaskMenu::tr("Change whatsThis..."), parent)), |
|
233 |
m_changeStyleSheet(new QAction(QDesignerTaskMenu::tr("Change styleSheet..."), parent)), |
|
234 |
m_morphMenu(new MorphMenu(parent)), |
|
235 |
m_formLayoutMenu(new FormLayoutMenu(parent)), |
|
236 |
m_addMenuBar(new QAction(QDesignerTaskMenu::tr("Create Menu Bar"), parent)), |
|
237 |
m_addToolBar(new QAction(QDesignerTaskMenu::tr("Add Tool Bar"), parent)), |
|
238 |
m_addStatusBar(new QAction(QDesignerTaskMenu::tr("Create Status Bar"), parent)), |
|
239 |
m_removeStatusBar(new QAction(QDesignerTaskMenu::tr("Remove Status Bar"), parent)), |
|
240 |
m_changeScript(new QAction(QDesignerTaskMenu::tr("Change script..."), parent)), |
|
241 |
m_containerFakeMethods(new QAction(QDesignerTaskMenu::tr("Change signals/slots..."), parent)), |
|
242 |
m_navigateToSlot(new QAction(QDesignerTaskMenu::tr("Go to slot..."), parent)), |
|
243 |
m_promotionTaskMenu(new PromotionTaskMenu(widget, PromotionTaskMenu::ModeManagedMultiSelection, parent)), |
|
244 |
m_sizeActionGroup(new QActionGroup(parent)), |
|
245 |
m_sizeActionsSubMenu(new QAction(QDesignerTaskMenu::tr("Size Constraints"), parent)) |
|
246 |
{ |
|
247 |
QMenu *sizeMenu = new QMenu; |
|
248 |
m_sizeActionsSubMenu->setMenu(sizeMenu); |
|
249 |
QAction *sizeAction = m_sizeActionGroup->addAction(QDesignerTaskMenu::tr("Set Minimum Width")); |
|
250 |
sizeAction->setData(ApplyMinimumWidth); |
|
251 |
sizeMenu->addAction(sizeAction); |
|
252 |
||
253 |
sizeAction = m_sizeActionGroup->addAction(QDesignerTaskMenu::tr("Set Minimum Height")); |
|
254 |
sizeAction->setData(ApplyMinimumHeight); |
|
255 |
sizeMenu->addAction(sizeAction); |
|
256 |
||
257 |
sizeAction = m_sizeActionGroup->addAction(QDesignerTaskMenu::tr("Set Minimum Size")); |
|
258 |
sizeAction->setData(ApplyMinimumWidth|ApplyMinimumHeight); |
|
259 |
sizeMenu->addAction(sizeAction); |
|
260 |
||
261 |
sizeMenu->addSeparator(); |
|
262 |
||
263 |
sizeAction = m_sizeActionGroup->addAction(QDesignerTaskMenu::tr("Set Maximum Width")); |
|
264 |
sizeAction->setData(ApplyMaximumWidth); |
|
265 |
sizeMenu->addAction(sizeAction); |
|
266 |
||
267 |
sizeAction = m_sizeActionGroup->addAction(QDesignerTaskMenu::tr("Set Maximum Height")); |
|
268 |
sizeAction->setData(ApplyMaximumHeight); |
|
269 |
sizeMenu->addAction(sizeAction); |
|
270 |
||
271 |
sizeAction = m_sizeActionGroup->addAction(QDesignerTaskMenu::tr("Set Maximum Size")); |
|
272 |
sizeAction->setData(ApplyMaximumWidth|ApplyMaximumHeight); |
|
273 |
sizeMenu->addAction(sizeAction); |
|
274 |
} |
|
275 |
||
276 |
// --------- QDesignerTaskMenu |
|
277 |
QDesignerTaskMenu::QDesignerTaskMenu(QWidget *widget, QObject *parent) : |
|
278 |
QObject(parent), |
|
279 |
d(new QDesignerTaskMenuPrivate(widget, parent)) |
|
280 |
{ |
|
281 |
d->m_q = this; |
|
282 |
Q_ASSERT(qobject_cast<QDesignerFormWindowInterface*>(widget) == 0); |
|
283 |
||
284 |
connect(d->m_changeObjectNameAction, SIGNAL(triggered()), this, SLOT(changeObjectName())); |
|
285 |
connect(d->m_changeToolTip, SIGNAL(triggered()), this, SLOT(changeToolTip())); |
|
286 |
connect(d->m_changeWhatsThis, SIGNAL(triggered()), this, SLOT(changeWhatsThis())); |
|
287 |
connect(d->m_changeStyleSheet, SIGNAL(triggered()), this, SLOT(changeStyleSheet())); |
|
288 |
connect(d->m_addMenuBar, SIGNAL(triggered()), this, SLOT(createMenuBar())); |
|
289 |
connect(d->m_addToolBar, SIGNAL(triggered()), this, SLOT(addToolBar())); |
|
290 |
connect(d->m_addStatusBar, SIGNAL(triggered()), this, SLOT(createStatusBar())); |
|
291 |
connect(d->m_removeStatusBar, SIGNAL(triggered()), this, SLOT(removeStatusBar())); |
|
292 |
connect(d->m_changeScript, SIGNAL(triggered()), this, SLOT(changeScript())); |
|
293 |
connect(d->m_containerFakeMethods, SIGNAL(triggered()), this, SLOT(containerFakeMethods())); |
|
294 |
connect(d->m_navigateToSlot, SIGNAL(triggered()), this, SLOT(slotNavigateToSlot())); |
|
295 |
connect(d->m_sizeActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(applySize(QAction*))); |
|
296 |
} |
|
297 |
||
298 |
QDesignerTaskMenu::~QDesignerTaskMenu() |
|
299 |
{ |
|
300 |
delete d; |
|
301 |
} |
|
302 |
||
303 |
QAction *QDesignerTaskMenu::createSeparator() |
|
304 |
{ |
|
305 |
return createSeparatorHelper(this); |
|
306 |
} |
|
307 |
||
308 |
QWidget *QDesignerTaskMenu::widget() const |
|
309 |
{ |
|
310 |
return d->m_widget; |
|
311 |
} |
|
312 |
||
313 |
QDesignerFormWindowInterface *QDesignerTaskMenu::formWindow() const |
|
314 |
{ |
|
315 |
QDesignerFormWindowInterface *result = QDesignerFormWindowInterface::findFormWindow(widget()); |
|
316 |
Q_ASSERT(result != 0); |
|
317 |
return result; |
|
318 |
} |
|
319 |
||
320 |
void QDesignerTaskMenu::createMenuBar() |
|
321 |
{ |
|
322 |
if (QDesignerFormWindowInterface *fw = formWindow()) { |
|
323 |
QMainWindow *mw = qobject_cast<QMainWindow*>(fw->mainContainer()); |
|
324 |
if (!mw) { |
|
325 |
// ### warning message |
|
326 |
return; |
|
327 |
} |
|
328 |
||
329 |
CreateMenuBarCommand *cmd = new CreateMenuBarCommand(fw); |
|
330 |
cmd->init(mw); |
|
331 |
fw->commandHistory()->push(cmd); |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
void QDesignerTaskMenu::addToolBar() |
|
336 |
{ |
|
337 |
if (QDesignerFormWindowInterface *fw = formWindow()) { |
|
338 |
QMainWindow *mw = qobject_cast<QMainWindow*>(fw->mainContainer()); |
|
339 |
if (!mw) { |
|
340 |
// ### warning message |
|
341 |
return; |
|
342 |
} |
|
343 |
||
344 |
AddToolBarCommand *cmd = new AddToolBarCommand(fw); |
|
345 |
cmd->init(mw); |
|
346 |
fw->commandHistory()->push(cmd); |
|
347 |
} |
|
348 |
} |
|
349 |
||
350 |
void QDesignerTaskMenu::createStatusBar() |
|
351 |
{ |
|
352 |
if (QDesignerFormWindowInterface *fw = formWindow()) { |
|
353 |
QMainWindow *mw = qobject_cast<QMainWindow*>(fw->mainContainer()); |
|
354 |
if (!mw) { |
|
355 |
// ### warning message |
|
356 |
return; |
|
357 |
} |
|
358 |
||
359 |
CreateStatusBarCommand *cmd = new CreateStatusBarCommand(fw); |
|
360 |
cmd->init(mw); |
|
361 |
fw->commandHistory()->push(cmd); |
|
362 |
} |
|
363 |
} |
|
364 |
||
365 |
void QDesignerTaskMenu::removeStatusBar() |
|
366 |
{ |
|
367 |
if (QDesignerFormWindowInterface *fw = formWindow()) { |
|
368 |
QMainWindow *mw = qobject_cast<QMainWindow*>(fw->mainContainer()); |
|
369 |
if (!mw) { |
|
370 |
// ### warning message |
|
371 |
return; |
|
372 |
} |
|
373 |
||
374 |
DeleteStatusBarCommand *cmd = new DeleteStatusBarCommand(fw); |
|
375 |
cmd->init(findStatusBar(mw)); |
|
376 |
fw->commandHistory()->push(cmd); |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
QList<QAction*> QDesignerTaskMenu::taskActions() const |
|
381 |
{ |
|
382 |
QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(widget()); |
|
383 |
Q_ASSERT(formWindow); |
|
384 |
||
385 |
const bool isMainContainer = formWindow->mainContainer() == widget(); |
|
386 |
||
387 |
QList<QAction*> actions; |
|
388 |
||
389 |
if (const QMainWindow *mw = qobject_cast<const QMainWindow*>(formWindow->mainContainer())) { |
|
390 |
if (isMainContainer || mw->centralWidget() == widget()) { |
|
391 |
if (!findMenuBar(mw)) { |
|
392 |
actions.append(d->m_addMenuBar); |
|
393 |
} |
|
394 |
||
395 |
actions.append(d->m_addToolBar); |
|
396 |
// ### create the status bar |
|
397 |
if (!findStatusBar(mw)) |
|
398 |
actions.append(d->m_addStatusBar); |
|
399 |
else |
|
400 |
actions.append(d->m_removeStatusBar); |
|
401 |
actions.append(d->m_separator); |
|
402 |
} |
|
403 |
} |
|
404 |
actions.append(d->m_changeObjectNameAction); |
|
405 |
d->m_morphMenu->populate(d->m_widget, formWindow, actions); |
|
406 |
d->m_formLayoutMenu->populate(d->m_widget, formWindow, actions); |
|
407 |
actions.append(d->m_separator2); |
|
408 |
actions.append(d->m_changeToolTip); |
|
409 |
actions.append(d->m_changeWhatsThis); |
|
410 |
actions.append(d->m_changeStyleSheet); |
|
411 |
actions.append(d->m_separator6); |
|
412 |
actions.append(d->m_sizeActionsSubMenu); |
|
413 |
d->m_promotionTaskMenu->setMode(formWindow->isManaged(d->m_widget) ? |
|
414 |
PromotionTaskMenu::ModeManagedMultiSelection : PromotionTaskMenu::ModeUnmanagedMultiSelection); |
|
415 |
d->m_promotionTaskMenu->addActions(formWindow, PromotionTaskMenu::LeadingSeparator, actions); |
|
416 |
||
417 |
#ifdef WANT_SCRIPT_OPTION |
|
418 |
if (!isMainContainer) { |
|
419 |
actions.append(d->m_separator4); |
|
420 |
actions.append(d->m_changeScript); |
|
421 |
} |
|
422 |
#endif |
|
423 |
if (isMainContainer && !qt_extension<QDesignerLanguageExtension*>(formWindow->core()->extensionManager(), formWindow->core())) { |
|
424 |
actions.append(d->m_separator5); |
|
425 |
actions.append(d->m_containerFakeMethods); |
|
426 |
} |
|
427 |
||
428 |
if (isSlotNavigationEnabled(formWindow->core())) { |
|
429 |
actions.append(d->m_separator7); |
|
430 |
actions.append(d->m_navigateToSlot); |
|
431 |
} |
|
432 |
||
433 |
return actions; |
|
434 |
} |
|
435 |
||
436 |
void QDesignerTaskMenu::changeObjectName() |
|
437 |
{ |
|
438 |
QDesignerFormWindowInterface *fw = formWindow(); |
|
439 |
Q_ASSERT(fw != 0); |
|
440 |
||
441 |
const QString oldObjectName = objName(fw->core(), widget()); |
|
442 |
||
443 |
ObjectNameDialog dialog(fw, oldObjectName); |
|
444 |
if (dialog.exec() == QDialog::Accepted) { |
|
445 |
const QString newObjectName = dialog.newObjectName(); |
|
446 |
if (!newObjectName.isEmpty() && newObjectName != oldObjectName ) { |
|
447 |
const QString objectNameProperty = QLatin1String("objectName"); |
|
448 |
PropertySheetStringValue objectNameValue; |
|
449 |
objectNameValue.setValue(newObjectName); |
|
450 |
setProperty(fw, CurrentWidgetMode, objectNameProperty, qVariantFromValue(objectNameValue)); |
|
451 |
} |
|
452 |
} |
|
453 |
} |
|
454 |
||
455 |
void QDesignerTaskMenu::changeTextProperty(const QString &propertyName, const QString &windowTitle, PropertyMode pm, Qt::TextFormat desiredFormat) |
|
456 |
{ |
|
457 |
QDesignerFormWindowInterface *fw = formWindow(); |
|
458 |
if (!fw) |
|
459 |
return; |
|
460 |
Q_ASSERT(d->m_widget->parentWidget() != 0); |
|
461 |
||
462 |
const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(fw->core()->extensionManager(), d->m_widget); |
|
463 |
const int index = sheet->indexOf(propertyName); |
|
464 |
if (index == -1) { |
|
465 |
qDebug() << "** WARNING Invalid property" << propertyName << " passed to changeTextProperty!"; |
|
466 |
return; |
|
467 |
} |
|
468 |
PropertySheetStringValue textValue = qVariantValue<PropertySheetStringValue>(sheet->property(index)); |
|
469 |
const QString oldText = textValue.value(); |
|
470 |
// Pop up respective dialog |
|
471 |
bool accepted = false; |
|
472 |
QString newText; |
|
473 |
switch (desiredFormat) { |
|
474 |
case Qt::PlainText: { |
|
475 |
PlainTextEditorDialog dlg(fw->core(), fw); |
|
476 |
if (!windowTitle.isEmpty()) |
|
477 |
dlg.setWindowTitle(windowTitle); |
|
478 |
dlg.setDefaultFont(d->m_widget->font()); |
|
479 |
dlg.setText(oldText); |
|
480 |
accepted = dlg.showDialog() == QDialog::Accepted; |
|
481 |
newText = dlg.text(); |
|
482 |
} |
|
483 |
break; |
|
484 |
default: { |
|
485 |
RichTextEditorDialog dlg(fw->core(), fw); |
|
486 |
if (!windowTitle.isEmpty()) |
|
487 |
dlg.setWindowTitle(windowTitle); |
|
488 |
dlg.setDefaultFont(d->m_widget->font()); |
|
489 |
dlg.setText(oldText); |
|
490 |
accepted = dlg.showDialog() == QDialog::Accepted; |
|
491 |
newText = dlg.text(desiredFormat); |
|
492 |
} |
|
493 |
break; |
|
494 |
} |
|
495 |
// change property |
|
496 |
if (!accepted || oldText == newText) |
|
497 |
return; |
|
498 |
||
499 |
||
500 |
textValue.setValue(newText); |
|
501 |
setProperty(fw, pm, propertyName, qVariantFromValue(textValue)); |
|
502 |
} |
|
503 |
||
504 |
void QDesignerTaskMenu::changeToolTip() |
|
505 |
{ |
|
506 |
changeTextProperty(QLatin1String("toolTip"), tr("Edit ToolTip"), MultiSelectionMode, Qt::AutoText); |
|
507 |
} |
|
508 |
||
509 |
void QDesignerTaskMenu::changeWhatsThis() |
|
510 |
{ |
|
511 |
changeTextProperty(QLatin1String("whatsThis"), tr("Edit WhatsThis"), MultiSelectionMode, Qt::AutoText); |
|
512 |
} |
|
513 |
||
514 |
void QDesignerTaskMenu::changeStyleSheet() |
|
515 |
{ |
|
516 |
if (QDesignerFormWindowInterface *fw = formWindow()) { |
|
517 |
StyleSheetPropertyEditorDialog dlg(fw, fw, d->m_widget); |
|
518 |
dlg.exec(); |
|
519 |
} |
|
520 |
} |
|
521 |
||
522 |
void QDesignerTaskMenu::changeScript() |
|
523 |
{ |
|
524 |
QDesignerFormWindowInterface *fw = formWindow(); |
|
525 |
if (!fw) |
|
526 |
return; |
|
527 |
||
528 |
MetaDataBase *metaDataBase = qobject_cast<MetaDataBase*>(fw->core()->metaDataBase()); |
|
529 |
if (!metaDataBase) |
|
530 |
return; |
|
531 |
||
532 |
const MetaDataBaseItem* item = metaDataBase->metaDataBaseItem(d->m_widget); |
|
533 |
if (!item) |
|
534 |
return; |
|
535 |
||
536 |
const QString oldScript = item->script(); |
|
537 |
QString newScript = oldScript; |
|
538 |
||
539 |
ScriptDialog scriptDialog(fw->core()->dialogGui(), fw); |
|
540 |
if (!scriptDialog.editScript(newScript)) |
|
541 |
return; |
|
542 |
||
543 |
// compile list of selected objects |
|
544 |
ScriptCommand *scriptCommand = new ScriptCommand(fw); |
|
545 |
if (!scriptCommand->init(applicableObjects(fw, MultiSelectionMode), newScript)) { |
|
546 |
delete scriptCommand; |
|
547 |
return; |
|
548 |
} |
|
549 |
||
550 |
fw->commandHistory()->push(scriptCommand); |
|
551 |
} |
|
552 |
||
553 |
void QDesignerTaskMenu::containerFakeMethods() |
|
554 |
{ |
|
555 |
QDesignerFormWindowInterface *fw = formWindow(); |
|
556 |
if (!fw) |
|
557 |
return; |
|
558 |
SignalSlotDialog::editMetaDataBase(fw, d->m_widget, fw); |
|
559 |
} |
|
560 |
||
561 |
static QString declaredInClass(const QDesignerMetaObjectInterface *metaObject, const QString &member) |
|
562 |
{ |
|
563 |
// Find class whose superclass does not contain the method. |
|
564 |
const QDesignerMetaObjectInterface *meta = metaObject; |
|
565 |
||
566 |
for (;;) { |
|
567 |
const QDesignerMetaObjectInterface *tmpMeta = meta->superClass(); |
|
568 |
if (tmpMeta == 0) |
|
569 |
break; |
|
570 |
if (tmpMeta->indexOfMethod(member) == -1) |
|
571 |
break; |
|
572 |
meta = tmpMeta; |
|
573 |
} |
|
574 |
return meta->className(); |
|
575 |
} |
|
576 |
||
577 |
bool QDesignerTaskMenu::isSlotNavigationEnabled(const QDesignerFormEditorInterface *core) |
|
578 |
{ |
|
579 |
if (QDesignerIntegration *integr = integration(core)) |
|
580 |
return integr->isSlotNavigationEnabled(); |
|
581 |
return false; |
|
582 |
} |
|
583 |
||
584 |
void QDesignerTaskMenu::slotNavigateToSlot() |
|
585 |
{ |
|
586 |
QDesignerFormEditorInterface *core = formWindow()->core(); |
|
587 |
Q_ASSERT(core); |
|
588 |
navigateToSlot(core, widget()); |
|
589 |
} |
|
590 |
||
591 |
void QDesignerTaskMenu::navigateToSlot(QDesignerFormEditorInterface *core, |
|
592 |
QObject *object, |
|
593 |
const QString &defaultSignal) |
|
594 |
{ |
|
595 |
const QString objectName = objName(core, object); |
|
596 |
QMap<QString, QMap<QString, QStringList> > classToSignalList; |
|
597 |
||
598 |
QDesignerIntegration *integr = integration(core); |
|
599 |
||
600 |
// "real" signals |
|
601 |
if (const QDesignerMetaObjectInterface *metaObject = core->introspection()->metaObject(object)) { |
|
602 |
const int methodCount = metaObject->methodCount(); |
|
603 |
for (int i = 0; i < methodCount; ++i) { |
|
604 |
const QDesignerMetaMethodInterface *metaMethod = metaObject->method(i); |
|
605 |
if (metaMethod->methodType() == QDesignerMetaMethodInterface::Signal) { |
|
606 |
const QString signature = metaMethod->signature(); |
|
607 |
const QStringList parameterNames = metaMethod->parameterNames(); |
|
608 |
classToSignalList[declaredInClass(metaObject, signature)][signature] = parameterNames; |
|
609 |
} |
|
610 |
} |
|
611 |
} |
|
612 |
||
613 |
// fake signals |
|
614 |
if (qdesigner_internal::MetaDataBase *metaDataBase |
|
615 |
= qobject_cast<qdesigner_internal::MetaDataBase *>(core->metaDataBase())) { |
|
616 |
qdesigner_internal::MetaDataBaseItem *item = metaDataBase->metaDataBaseItem(object); |
|
617 |
Q_ASSERT(item); |
|
618 |
const QStringList fakeSignals = item->fakeSignals(); |
|
619 |
foreach (const QString &fakeSignal, fakeSignals) |
|
620 |
classToSignalList[item->customClassName()][fakeSignal] = QStringList(); |
|
621 |
} |
|
622 |
||
623 |
if (object->isWidgetType()) { |
|
624 |
QWidget *widget = static_cast<QWidget *>(object); |
|
625 |
if (WidgetDataBase *db = qobject_cast<WidgetDataBase *>(core->widgetDataBase())) { |
|
626 |
const QString promotedClassName = promotedCustomClassName(core, widget); |
|
627 |
const int index = core->widgetDataBase()->indexOfClassName(promotedClassName); |
|
628 |
if (index >= 0) { |
|
629 |
WidgetDataBaseItem* item = static_cast<WidgetDataBaseItem*>(db->item(index)); |
|
630 |
const QStringList fakeSignals = item->fakeSignals(); |
|
631 |
foreach (const QString &fakeSignal, fakeSignals) |
|
632 |
classToSignalList[promotedClassName][fakeSignal] = QStringList(); |
|
633 |
} |
|
634 |
} |
|
635 |
} |
|
636 |
||
637 |
Ui::SelectSignalDialog dialogUi; |
|
638 |
QDialog selectSignalDialog(0, Qt::WindowTitleHint | Qt::WindowSystemMenuHint); |
|
639 |
dialogUi.setupUi(&selectSignalDialog); |
|
640 |
||
641 |
QMap<QString, QMap<QString, QStringList> >::const_iterator iter(classToSignalList.constBegin()); |
|
642 |
for (; iter != classToSignalList.constEnd(); ++iter) { |
|
643 |
const QString className = iter.key(); |
|
644 |
QMap<QString, QStringList> signalNames = iter.value(); |
|
645 |
||
646 |
QMap<QString, QStringList>::const_iterator itSignal(signalNames.constBegin()); |
|
647 |
for (; itSignal != signalNames.constEnd(); ++itSignal) { |
|
648 |
const QString signalName = itSignal.key(); |
|
649 |
QTreeWidgetItem *row = new QTreeWidgetItem(QStringList() << signalName << className); |
|
650 |
row->setData(0, Qt::UserRole, itSignal.value()); |
|
651 |
dialogUi.signalList->addTopLevelItem(row); |
|
652 |
} |
|
653 |
} |
|
654 |
if (dialogUi.signalList->topLevelItemCount() == 0) { |
|
655 |
QTreeWidgetItem *row = new QTreeWidgetItem(QStringList() << tr("no signals available")); |
|
656 |
dialogUi.signalList->addTopLevelItem(row); |
|
657 |
dialogUi.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); |
|
658 |
} else { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
659 |
connect(dialogUi.signalList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), |
0 | 660 |
&selectSignalDialog, SLOT(accept())); |
661 |
} |
|
662 |
||
663 |
if (defaultSignal.isEmpty()) { |
|
664 |
dialogUi.signalList->setCurrentItem(dialogUi.signalList->topLevelItem(0)); |
|
665 |
} else { |
|
666 |
const QList<QTreeWidgetItem *> items = dialogUi.signalList->findItems (defaultSignal, Qt::MatchExactly, 0); |
|
667 |
if (!items.empty()) |
|
668 |
dialogUi.signalList->setCurrentItem(items.front()); |
|
669 |
} |
|
670 |
||
671 |
dialogUi.signalList->resizeColumnToContents(0); |
|
672 |
||
673 |
if (selectSignalDialog.exec() == QDialog::Accepted) { |
|
674 |
QTreeWidgetItem *selectedItem = dialogUi.signalList->selectedItems().first(); |
|
675 |
const QString signalSignature = selectedItem->text(0); |
|
676 |
const QStringList parameterNames = qVariantValue<QStringList>(selectedItem->data(0, Qt::UserRole)); |
|
677 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
678 |
// TODO: Check whether signal is connected to slot |
0 | 679 |
integr->emitNavigateToSlot(objectName, signalSignature, parameterNames); |
680 |
} |
|
681 |
} |
|
682 |
||
683 |
// Add a command that takes over the value of the current geometry as |
|
684 |
// minimum/maximum size according to the flags. |
|
685 |
static void createSizeCommand(QDesignerFormWindowInterface *fw, QWidget *w, int flags) |
|
686 |
{ |
|
687 |
const QSize size = w->size(); |
|
688 |
if (flags & (ApplyMinimumWidth|ApplyMinimumHeight)) { |
|
689 |
QSize minimumSize = w-> minimumSize(); |
|
690 |
if (flags & ApplyMinimumWidth) |
|
691 |
minimumSize.setWidth(size.width()); |
|
692 |
if (flags & ApplyMinimumHeight) |
|
693 |
minimumSize.setHeight(size.height()); |
|
694 |
SetPropertyCommand* cmd = new SetPropertyCommand(fw); |
|
695 |
cmd->init(w, QLatin1String("minimumSize"), minimumSize); |
|
696 |
fw->commandHistory()->push(cmd); |
|
697 |
} |
|
698 |
if (flags & (ApplyMaximumWidth|ApplyMaximumHeight)) { |
|
699 |
QSize maximumSize = w-> maximumSize(); |
|
700 |
if (flags & ApplyMaximumWidth) |
|
701 |
maximumSize.setWidth(size.width()); |
|
702 |
if (flags & ApplyMaximumHeight) |
|
703 |
maximumSize.setHeight(size.height()); |
|
704 |
SetPropertyCommand* cmd = new SetPropertyCommand(fw); |
|
705 |
cmd->init(w, QLatin1String("maximumSize"), maximumSize); |
|
706 |
fw->commandHistory()->push(cmd); |
|
707 |
} |
|
708 |
} |
|
709 |
||
710 |
void QDesignerTaskMenu::applySize(QAction *a) |
|
711 |
{ |
|
712 |
QDesignerFormWindowInterface *fw = formWindow(); |
|
713 |
if (!fw) |
|
714 |
return; |
|
715 |
||
716 |
const QWidgetList selection = applicableWidgets(fw, MultiSelectionMode); |
|
717 |
if (selection.isEmpty()) |
|
718 |
return; |
|
719 |
||
720 |
const int mask = a->data().toInt(); |
|
721 |
const int size = selection.size(); |
|
722 |
fw->commandHistory()->beginMacro(tr("Set size constraint on %n widget(s)", 0, size)); |
|
723 |
for (int i = 0; i < size; i++) |
|
724 |
createSizeCommand(fw, selection.at(i), mask); |
|
725 |
fw->commandHistory()->endMacro(); |
|
726 |
} |
|
727 |
||
728 |
template <class Container> |
|
729 |
static void getApplicableObjects(const QDesignerFormWindowInterface *fw, QWidget *current, |
|
730 |
QDesignerTaskMenu::PropertyMode pm, Container *c) |
|
731 |
{ |
|
732 |
// Current is always first |
|
733 |
c->push_back(current); |
|
734 |
if (pm == QDesignerTaskMenu::CurrentWidgetMode) |
|
735 |
return; |
|
736 |
QDesignerObjectInspector *designerObjectInspector = qobject_cast<QDesignerObjectInspector *>(fw->core()->objectInspector()); |
|
737 |
if (!designerObjectInspector) |
|
738 |
return; // Ooops, someone plugged an old-style Object Inspector |
|
739 |
// Add managed or unmanaged selection according to current type, make current first |
|
740 |
Selection s; |
|
741 |
designerObjectInspector->getSelection(s); |
|
742 |
const QWidgetList &source = fw->isManaged(current) ? s.managed : s.unmanaged; |
|
743 |
const QWidgetList::const_iterator cend = source.constEnd(); |
|
744 |
for ( QWidgetList::const_iterator it = source.constBegin(); it != cend; ++it) |
|
745 |
if (*it != current) // was first |
|
746 |
c->push_back(*it); |
|
747 |
} |
|
748 |
||
749 |
QObjectList QDesignerTaskMenu::applicableObjects(const QDesignerFormWindowInterface *fw, PropertyMode pm) const |
|
750 |
{ |
|
751 |
QObjectList rc; |
|
752 |
getApplicableObjects(fw, d->m_widget, pm, &rc); |
|
753 |
return rc; |
|
754 |
} |
|
755 |
||
756 |
QWidgetList QDesignerTaskMenu::applicableWidgets(const QDesignerFormWindowInterface *fw, PropertyMode pm) const |
|
757 |
{ |
|
758 |
QWidgetList rc; |
|
759 |
getApplicableObjects(fw, d->m_widget, pm, &rc); |
|
760 |
return rc; |
|
761 |
} |
|
762 |
||
763 |
void QDesignerTaskMenu::setProperty(QDesignerFormWindowInterface *fw, PropertyMode pm, const QString &name, const QVariant &newValue) |
|
764 |
{ |
|
765 |
SetPropertyCommand* setPropertyCommand = new SetPropertyCommand(fw); |
|
766 |
if (setPropertyCommand->init(applicableObjects(fw, pm), name, newValue, d->m_widget)) { |
|
767 |
fw->commandHistory()->push(setPropertyCommand); |
|
768 |
} else { |
|
769 |
delete setPropertyCommand; |
|
770 |
qDebug() << "Unable to set property " << name << '.'; |
|
771 |
} |
|
772 |
} |
|
773 |
||
774 |
||
775 |
} // namespace qdesigner_internal |
|
776 |
||
777 |
QT_END_NAMESPACE |