1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "formwindowmanager.h"
30
#include "formwindow_dnditem.h"
31
#include "widgetdatabase_p.h"
32
#include "iconloader_p.h"
33
#include "widgetselection.h"
34
#include "qdesigner_resource.h"
35
#include "connectionedit_p.h"
37
#include <QtDesigner/QtDesigner>
38
#include <qdesigner_promotedwidget_p.h>
39
#include <qdesigner_command_p.h>
40
#include <layoutinfo_p.h>
42
#include <QtGui/QAction>
43
#include <QtGui/QLayout>
44
#include <QtGui/QMouseEvent>
45
#include <QtGui/QApplication>
46
#include <QtGui/QIcon>
47
#include <QtGui/QBitmap>
48
#include <QtGui/QPainter>
49
#include <QtGui/QSizeGrip>
50
#include <QtGui/QAbstractButton>
51
#include <QtGui/QToolBox>
52
#include <QtGui/QMainWindow>
53
#include <QtGui/QMenuBar>
54
#include <QtGui/QClipboard>
55
#include <QtGui/QWorkspace>
56
#include <QtGui/QDesktopWidget>
58
#include <QtCore/qdebug.h>
60
using namespace qdesigner_internal;
62
static QString whatsThisFrom(const QString &str)
64
Q_UNUSED(str); /// ### implement me!
68
FormWindowManager::FormWindowManager(QDesignerFormEditorInterface *core, QObject *parent)
69
: QDesignerFormWindowManagerInterface(parent),
73
m_layoutChilds = false;
76
qApp->installEventFilter(this);
79
m_last_widget_under_mouse = 0;
80
m_last_form_under_mouse = 0;
81
m_widget_box_under_mouse = 0;
84
FormWindowManager::~FormWindowManager()
86
qDeleteAll(m_formWindows);
89
QDesignerFormEditorInterface *FormWindowManager::core() const
94
QDesignerFormWindowInterface *FormWindowManager::activeFormWindow() const
96
return m_activeFormWindow;
99
int FormWindowManager::formWindowCount() const
101
return m_formWindows.size();
104
QDesignerFormWindowInterface *FormWindowManager::formWindow(int index) const
106
return m_formWindows.at(index);
109
static bool isMouseMoveOrRelease(QEvent *e)
111
return e->type() == QEvent::MouseButtonRelease || e->type() == QEvent::MouseMove;
114
bool FormWindowManager::eventFilter(QObject *o, QEvent *e)
118
o == m_core->topLevel() &&
120
!m_drag_item_list.isEmpty() && isMouseMoveOrRelease(e)) {
122
QMouseEvent *me = static_cast<QMouseEvent*>(e);
125
if (me->type() == QEvent::MouseButtonRelease)
126
endDrag(me->globalPos());
128
setItemsPos(me->globalPos());
132
if (!o->isWidgetType())
135
QWidget *widget = static_cast<QWidget*>(o);
137
if (qobject_cast<WidgetHandle*>(widget)) { // ### remove me
141
FormWindow *fw = FormWindow::findFormWindow(widget);
146
if (QWidget *managedWidget = findManagedWidget(fw, widget)) {
149
if (widget == managedWidget && fw->isWidgetSelected(managedWidget))
150
fw->hideSelection(widget);
153
case QEvent::WindowActivate: {
154
if (fw->isMainContainer(managedWidget)) {
155
core()->formWindowManager()->setActiveFormWindow(fw);
159
case QEvent::WindowDeactivate: {
160
fw->repaintSelection();
164
if (fw->handleEvent(widget, managedWidget, e)) {
175
void FormWindowManager::addFormWindow(QDesignerFormWindowInterface *w)
177
FormWindow *formWindow = qobject_cast<FormWindow*>(w);
178
if (!formWindow || m_formWindows.contains(formWindow))
181
connect(formWindow, SIGNAL(selectionChanged()), this, SLOT(slotUpdateActions()));
182
connect(formWindow->commandHistory(), SIGNAL(commandExecuted()), this, SLOT(slotUpdateActions()));
183
connect(formWindow, SIGNAL(toolChanged(int)), this, SLOT(slotUpdateActions()));
185
m_formWindows.append(formWindow);
186
emit formWindowAdded(formWindow);
189
void FormWindowManager::removeFormWindow(QDesignerFormWindowInterface *w)
191
FormWindow *formWindow = qobject_cast<FormWindow*>(w);
193
int idx = m_formWindows.indexOf(formWindow);
194
if (!formWindow || idx == -1)
197
formWindow->disconnect(this);
198
m_formWindows.removeAt(idx);
199
emit formWindowRemoved(formWindow);
201
if (formWindow == m_activeFormWindow)
202
setActiveFormWindow(0);
205
void FormWindowManager::setActiveFormWindow(QDesignerFormWindowInterface *w)
207
FormWindow *formWindow = qobject_cast<FormWindow*>(w);
209
if (formWindow == m_activeFormWindow)
212
FormWindow *old = m_activeFormWindow;
214
m_activeFormWindow = formWindow;
218
if (m_activeFormWindow) {
219
m_activeFormWindow->repaintSelection();
221
old->repaintSelection();
224
emit activeFormWindowChanged(m_activeFormWindow);
226
if (m_activeFormWindow) {
227
m_activeFormWindow->emitSelectionChanged();
228
m_activeFormWindow->commandHistory()->setCurrent();
230
QWidget *parent = m_activeFormWindow->parentWidget();
231
QWorkspace *workspace = 0;
232
while (parent != 0) {
233
if ((workspace = qobject_cast<QWorkspace*>(parent)))
235
parent = parent->parentWidget();
238
workspace->setActiveWindow(m_activeFormWindow->parentWidget());
242
QWidget *FormWindowManager::findManagedWidget(FormWindow *fw, QWidget *w)
244
while (w && w != fw) {
245
if (fw->isManaged(w))
247
w = w->parentWidget();
250
QWidget *parent = w->parentWidget();
251
if (parent != 0 && qobject_cast<QDesignerPromotedWidget*>(parent) != 0)
257
void FormWindowManager::setupActions()
259
m_actionCut = new QAction(createIconSet(QLatin1String("editcut.png")), tr("Cu&t"), this);
260
m_actionCut->setShortcut(Qt::CTRL + Qt::Key_X);
261
m_actionCut->setStatusTip(tr("Cuts the selected widgets and puts them on the clipboard"));
262
m_actionCut->setWhatsThis(whatsThisFrom(QLatin1String("Edit|Cut")));
263
connect(m_actionCut, SIGNAL(triggered()), this, SLOT(slotActionCutActivated()));
264
m_actionCut->setEnabled(false);
266
m_actionCopy = new QAction(createIconSet(QLatin1String("editcopy.png")), tr("&Copy"), this);
267
m_actionCopy->setShortcut(Qt::CTRL + Qt::Key_C);
268
m_actionCopy->setStatusTip(tr("Copies the selected widgets to the clipboard"));
269
m_actionCopy->setWhatsThis(whatsThisFrom(QLatin1String("Edit|Copy")));
270
connect(m_actionCopy, SIGNAL(triggered()), this, SLOT(slotActionCopyActivated()));
271
m_actionCopy->setEnabled(false);
273
m_actionPaste = new QAction(createIconSet(QLatin1String("editpaste.png")), tr("&Paste"), this);
274
m_actionPaste->setShortcut(Qt::CTRL + Qt::Key_V);
275
m_actionPaste->setStatusTip(tr("Pastes the clipboard's contents"));
276
m_actionPaste->setWhatsThis(whatsThisFrom(QLatin1String("Edit|Paste")));
277
connect(m_actionPaste, SIGNAL(triggered()), this, SLOT(slotActionPasteActivated()));
278
m_actionPaste->setEnabled(false);
280
m_actionDelete = new QAction(tr("&Delete"), this);
281
m_actionDelete->setStatusTip(tr("Deletes the selected widgets"));
282
m_actionDelete->setWhatsThis(whatsThisFrom(QLatin1String("Edit|Delete")));
283
connect(m_actionDelete, SIGNAL(triggered()), this, SLOT(slotActionDeleteActivated()));
284
m_actionDelete->setEnabled(false);
286
m_actionSelectAll = new QAction(tr("Select &All"), this);
287
m_actionSelectAll->setShortcut(Qt::CTRL + Qt::Key_A);
288
m_actionSelectAll->setStatusTip(tr("Selects all widgets"));
289
m_actionSelectAll->setWhatsThis(whatsThisFrom(QLatin1String("Edit|Select All")));
290
connect(m_actionSelectAll, SIGNAL(triggered()), this, SLOT(slotActionSelectAllActivated()));
291
m_actionSelectAll->setEnabled(false);
293
m_actionRaise = new QAction(createIconSet(QLatin1String("editraise.png")), tr("Bring to &Front"), this);
294
m_actionRaise->setStatusTip(tr("Raises the selected widgets"));
295
m_actionRaise->setWhatsThis(tr("Raises the selected widgets"));
296
connect(m_actionRaise, SIGNAL(triggered()), this, SLOT(slotActionRaiseActivated()));
297
m_actionRaise->setEnabled(false);
299
m_actionLower = new QAction(createIconSet(QLatin1String("editlower.png")), tr("Send to &Back"), this);
300
m_actionLower->setStatusTip(tr("Lowers the selected widgets"));
301
m_actionLower->setWhatsThis(tr("Lowers the selected widgets"));
302
connect(m_actionLower, SIGNAL(triggered()), this, SLOT(slotActionLowerActivated()));
303
m_actionLower->setEnabled(false);
306
m_actionAdjustSize = new QAction(createIconSet(QLatin1String("adjustsize.png")), tr("Adjust &Size"), this);
307
m_actionAdjustSize->setShortcut(Qt::CTRL + Qt::Key_J);
308
m_actionAdjustSize->setStatusTip(tr("Adjusts the size of the selected widget"));
309
m_actionAdjustSize->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Adjust Size")));
310
connect(m_actionAdjustSize, SIGNAL(triggered()), this, SLOT(slotActionAdjustSizeActivated()));
311
m_actionAdjustSize->setEnabled(false);
313
m_actionHorizontalLayout = new QAction(createIconSet(QLatin1String("edithlayout.png")), tr("Lay Out &Horizontally"), this);
314
m_actionHorizontalLayout->setShortcut(Qt::CTRL + Qt::Key_H);
315
m_actionHorizontalLayout->setStatusTip(tr("Lays out the selected widgets horizontally"));
316
m_actionHorizontalLayout->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Lay Out Horizontally")));
317
connect(m_actionHorizontalLayout, SIGNAL(triggered()), this, SLOT(slotActionHorizontalLayoutActivated()));
318
m_actionHorizontalLayout->setEnabled(false);
320
m_actionVerticalLayout = new QAction(createIconSet(QLatin1String("editvlayout.png")), tr("Lay Out &Vertically"), this);
321
m_actionVerticalLayout->setShortcut(Qt::CTRL + Qt::Key_L);
322
m_actionVerticalLayout->setStatusTip(tr("Lays out the selected widgets vertically"));
323
m_actionVerticalLayout->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Lay Out Vertically")));
324
connect(m_actionVerticalLayout, SIGNAL(triggered()), this, SLOT(slotActionVerticalLayoutActivated()));
325
m_actionVerticalLayout->setEnabled(false);
327
m_actionGridLayout = new QAction(createIconSet(QLatin1String("editgrid.png")), tr("Lay Out in a &Grid"), this);
328
m_actionGridLayout->setShortcut(Qt::CTRL + Qt::Key_G);
329
m_actionGridLayout->setStatusTip(tr("Lays out the selected widgets in a grid"));
330
m_actionGridLayout->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Lay Out in a Grid")));
331
connect(m_actionGridLayout, SIGNAL(triggered()), this, SLOT(slotActionGridLayoutActivated()));
332
m_actionGridLayout->setEnabled(false);
334
m_actionSplitHorizontal = new QAction(createIconSet(QLatin1String("editvlayoutsplit.png")),
335
tr("Lay Out Horizontally in S&plitter"), this);
336
m_actionSplitHorizontal->setStatusTip(tr("Lays out the selected widgets horizontally in a splitter"));
337
m_actionSplitHorizontal->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Lay Out Horizontally in Splitter")));
338
connect(m_actionSplitHorizontal, SIGNAL(triggered()), this, SLOT(slotActionSplitHorizontalActivated()));
339
m_actionSplitHorizontal->setEnabled(false);
341
m_actionSplitVertical = new QAction(createIconSet(QLatin1String("edithlayoutsplit.png")),
342
tr("Lay Out Vertically in Sp&litter"), this);
343
m_actionSplitVertical->setStatusTip(tr("Lays out the selected widgets vertically in a splitter"));
344
m_actionSplitVertical->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Lay Out Vertically in Splitter")));
345
connect(m_actionSplitVertical, SIGNAL(triggered()), this, SLOT(slotActionSplitVerticalActivated()));
346
m_actionSplitVertical->setEnabled(false);
348
m_actionBreakLayout = new QAction(createIconSet(QLatin1String("editbreaklayout.png")), tr("&Break Layout"), this);
349
m_actionBreakLayout->setShortcut(Qt::CTRL + Qt::Key_B);
350
m_actionBreakLayout->setStatusTip(tr("Breaks the selected layout"));
351
m_actionBreakLayout->setWhatsThis(whatsThisFrom(QLatin1String("Layout|Break Layout")));
352
connect(m_actionBreakLayout, SIGNAL(triggered()), this, SLOT(slotActionBreakLayoutActivated()));
353
m_actionBreakLayout->setEnabled(false);
355
m_actionUndo = new QAction(tr("Undo"), this);
356
m_actionUndo->setShortcut(Qt::CTRL + Qt::Key_Z);
357
m_actionUndo->setEnabled(false);
358
m_actionRedo = new QAction(tr("Redo"), this);
359
m_actionRedo->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Z);
360
m_actionRedo->setEnabled(false);
363
void FormWindowManager::slotActionCutActivated()
365
m_activeFormWindow->cut();
368
void FormWindowManager::slotActionCopyActivated()
370
m_activeFormWindow->copy();
374
void FormWindowManager::slotActionPasteActivated()
376
m_activeFormWindow->paste();
379
void FormWindowManager::slotActionDeleteActivated()
381
m_activeFormWindow->deleteWidgets();
384
void FormWindowManager::slotActionLowerActivated()
386
m_activeFormWindow->lowerWidgets();
389
void FormWindowManager::slotActionRaiseActivated()
391
m_activeFormWindow->lowerWidgets();
394
void FormWindowManager::slotActionHorizontalLayoutActivated()
397
layoutContainerHorizontal();
399
m_activeFormWindow->layoutHorizontal();
402
void FormWindowManager::slotActionVerticalLayoutActivated()
405
layoutContainerVertical();
407
m_activeFormWindow->layoutVertical();
410
void FormWindowManager::slotActionGridLayoutActivated()
413
layoutContainerGrid();
415
m_activeFormWindow->layoutGrid();
418
void FormWindowManager::slotActionSplitHorizontalActivated()
421
; // no way to do that
423
m_activeFormWindow->layoutHorizontalSplit();
426
void FormWindowManager::slotActionSplitVerticalActivated()
429
; // no way to do that
431
m_activeFormWindow->layoutVerticalSplit();
434
void FormWindowManager::slotActionBreakLayoutActivated()
436
QList<QWidget*> widgets = m_activeFormWindow->selectedWidgets();
438
if (widgets.isEmpty())
439
widgets.append(m_activeFormWindow->mainContainer());
441
m_activeFormWindow->simplifySelection(&widgets);
443
QList<QWidget*> layoutBaseList;
445
foreach (QWidget *widget, widgets) {
446
QWidget *currentWidget = core()->widgetFactory()->containerOfWidget(widget);
448
while (currentWidget && currentWidget != m_activeFormWindow) {
449
if (QLayout *layout = LayoutInfo::managedLayout(core(), currentWidget)) {
450
if (!layoutBaseList.contains(layout->parentWidget())) {
451
layoutBaseList.prepend(layout->parentWidget());
454
currentWidget = currentWidget->parentWidget();
458
if (layoutBaseList.isEmpty()) {
463
m_activeFormWindow->beginCommand(tr("Break Layout"));
464
foreach (QWidget *layoutBase, layoutBaseList) {
465
m_activeFormWindow->breakLayout(layoutBase);
467
m_activeFormWindow->endCommand();
470
void FormWindowManager::slotActionAdjustSizeActivated()
472
Q_ASSERT(m_activeFormWindow != 0);
474
m_activeFormWindow->beginCommand(tr("Adjust Size"));
476
QList<QWidget*> selectedWidgets = m_activeFormWindow->selectedWidgets();
477
m_activeFormWindow->simplifySelection(&selectedWidgets);
479
if (selectedWidgets.isEmpty()) {
480
Q_ASSERT(m_activeFormWindow->mainContainer() != 0);
481
selectedWidgets.append(m_activeFormWindow->mainContainer());
484
foreach (QWidget *widget, selectedWidgets) {
485
bool unlaidout = LayoutInfo::layoutType(core(), widget->parentWidget()) == LayoutInfo::NoLayout;
486
bool isMainContainer = m_activeFormWindow->isMainContainer(widget);
488
if (unlaidout || isMainContainer) {
489
AdjustWidgetSizeCommand *cmd = new AdjustWidgetSizeCommand(m_activeFormWindow);
491
m_activeFormWindow->commandHistory()->push(cmd);
495
m_activeFormWindow->endCommand();
498
void FormWindowManager::slotActionSelectAllActivated()
500
m_activeFormWindow->selectAll();
503
void FormWindowManager::slotUpdateActions()
505
m_layoutChilds = false;
507
int selectedWidgetCount = 0;
508
int laidoutWidgetCount = 0;
509
int unlaidoutWidgetCount = 0;
510
bool pasteAvailable = false;
511
bool layoutAvailable = false;
512
bool breakAvailable = false;
513
bool layoutContainer = false;
515
if (m_activeFormWindow != 0 && m_activeFormWindow->currentTool() == 0) {
516
QList<QWidget*> simplifiedSelection = m_activeFormWindow->selectedWidgets();
517
selectedWidgetCount = simplifiedSelection.count();
518
pasteAvailable = qApp->clipboard()->mimeData() && qApp->clipboard()->mimeData()->hasText();
520
m_activeFormWindow->simplifySelection(&simplifiedSelection);
521
if (simplifiedSelection.isEmpty())
522
simplifiedSelection.append(m_activeFormWindow->mainContainer());
524
foreach (QWidget *widget, simplifiedSelection) {
525
if (LayoutInfo::isWidgetLaidout(m_core, widget))
526
++laidoutWidgetCount;
528
++unlaidoutWidgetCount;
531
if (simplifiedSelection.count() == 1) {
532
m_layoutChilds = false;
534
QWidget *widget = core()->widgetFactory()->containerOfWidget(simplifiedSelection.first());
535
QDesignerWidgetDataBaseInterface *db = m_core->widgetDataBase();
536
if (QDesignerWidgetDataBaseItemInterface *item = db->item(db->indexOfObject(widget))) {
537
QLayout *layout = LayoutInfo::managedLayout(m_core, widget);
538
layoutContainer = (item->isContainer() || m_activeFormWindow->isMainContainer(widget));
540
layoutAvailable = layoutContainer
541
&& m_activeFormWindow->hasInsertedChildren(widget)
544
m_layoutChilds = layoutAvailable;
545
breakAvailable = layout != 0 || LayoutInfo::isWidgetLaidout(m_core, widget);
548
layoutAvailable = unlaidoutWidgetCount > 1;
549
breakAvailable = false;
553
m_actionCut->setEnabled(selectedWidgetCount > 0);
554
m_actionCopy->setEnabled(selectedWidgetCount > 0);
555
m_actionDelete->setEnabled(selectedWidgetCount > 0);
556
m_actionLower->setEnabled(selectedWidgetCount > 0);
557
m_actionRaise->setEnabled(selectedWidgetCount > 0);
559
m_actionPaste->setEnabled(pasteAvailable);
561
m_actionSelectAll->setEnabled(m_activeFormWindow != 0);
563
m_actionAdjustSize->setEnabled(unlaidoutWidgetCount > 0);
565
m_actionHorizontalLayout->setEnabled(layoutAvailable);
566
m_actionVerticalLayout->setEnabled(layoutAvailable);
567
m_actionSplitHorizontal->setEnabled(layoutAvailable && !layoutContainer);
568
m_actionSplitVertical->setEnabled(layoutAvailable && !layoutContainer);
569
m_actionGridLayout->setEnabled(layoutAvailable);
571
m_actionBreakLayout->setEnabled(breakAvailable);
574
void FormWindowManager::layoutContainerHorizontal()
576
QWidget *w = m_activeFormWindow->mainContainer();
577
QList<QWidget*> l(m_activeFormWindow->selectedWidgets());
582
m_activeFormWindow->layoutHorizontalContainer(w);
585
void FormWindowManager::layoutContainerVertical()
587
QWidget *w = m_activeFormWindow->mainContainer();
588
QList<QWidget*> l(m_activeFormWindow->selectedWidgets());
593
m_activeFormWindow->layoutVerticalContainer(w);
596
void FormWindowManager::layoutContainerGrid()
598
QWidget *w = m_activeFormWindow->mainContainer();
599
QList<QWidget*> l(m_activeFormWindow->selectedWidgets());
604
m_activeFormWindow->layoutGridContainer(w);
607
QDesignerFormWindowInterface *FormWindowManager::createFormWindow(QWidget *parentWidget, Qt::WindowFlags flags)
609
FormWindow *formWindow = new FormWindow(qobject_cast<FormEditor*>(core()), parentWidget, flags);
610
addFormWindow(formWindow);
614
QAction *FormWindowManager::actionUndo() const
619
QAction *FormWindowManager::actionRedo() const
626
void FormWindowManager::dragItems(const QList<QDesignerDnDItemInterface*> &item_list)
628
if (!m_drag_item_list.isEmpty()) {
629
qWarning("FormWindowManager::dragItem(): called while already dragging");
633
beginDrag(item_list, QCursor::pos());
636
void FormWindowManager::beginDrag(const QList<QDesignerDnDItemInterface*> &item_list, const QPoint &globalPos)
638
Q_ASSERT(m_drag_item_list.isEmpty());
640
m_drag_item_list = item_list;
642
setItemsPos(globalPos);
644
foreach(QDesignerDnDItemInterface *item, m_drag_item_list) {
645
QWidget *deco = item->decoration();
646
QBitmap bitmap(deco->size());
648
p.fillRect(bitmap.rect(), Qt::color1);
649
p.setPen(Qt::color0);
650
p.drawPoint(deco->mapFromGlobal(globalPos));
652
deco->setMask(bitmap);
653
QPoint pos = deco->pos();
654
QRect ag = qApp->desktop()->availableGeometry(deco);
655
deco->move(qMin(qMax(pos.x(), ag.left()), ag.right()), qMin(qMax(pos.y(), ag.top()), ag.bottom()));
658
deco->setWindowOpacity(0.8);
662
m_core->topLevel()->grabMouse();
666
static QDesignerWidgetBoxInterface *widgetBoxAt(const QPoint &global_pos)
668
QWidget *w = qApp->widgetAt(global_pos);
670
QDesignerWidgetBoxInterface *wb = qobject_cast<QDesignerWidgetBoxInterface*>(w);
673
w = w->parentWidget();
678
void FormWindowManager::setItemsPos(const QPoint &globalPos)
680
foreach(QDesignerDnDItemInterface *item, m_drag_item_list)
681
item->decoration()->move(globalPos - item->hotSpot());
683
QWidget *widget_under_mouse = qApp->widgetAt(globalPos);
685
while (max_try && widget_under_mouse && isDecoration(widget_under_mouse)) {
687
widget_under_mouse = qApp->widgetAt(widget_under_mouse->pos() - QPoint(1,1));
688
Q_ASSERT(!qobject_cast<ConnectionEdit*>(widget_under_mouse));
691
FormWindow *form_under_mouse
692
= qobject_cast<FormWindow*>(QDesignerFormWindowInterface::findFormWindow(widget_under_mouse));
693
if (form_under_mouse != 0 && !form_under_mouse->hasFeature(QDesignerFormWindowInterface::EditFeature))
694
form_under_mouse = 0;
695
if (form_under_mouse != 0) {
696
// widget_under_mouse might be some temporary thing like the dropLine. We need
697
// the actual widget that's part of the edited GUI.
699
= form_under_mouse->widgetAt(form_under_mouse->mapFromGlobal(globalPos));
701
Q_ASSERT(!qobject_cast<ConnectionEdit*>(widget_under_mouse));
704
if (m_last_form_under_mouse != 0 && widget_under_mouse != m_last_widget_under_mouse) {
705
m_last_form_under_mouse->highlightWidget(m_last_widget_under_mouse,
706
m_last_widget_under_mouse->mapFromGlobal(globalPos),
707
FormWindow::Restore);
710
FormWindow *source_form = qobject_cast<FormWindow*>(m_drag_item_list.first()->source());
711
if (form_under_mouse != 0
712
&& (source_form == 0 || widget_under_mouse != source_form->mainContainer())) {
714
form_under_mouse->highlightWidget(widget_under_mouse,
715
widget_under_mouse->mapFromGlobal(globalPos),
716
FormWindow::Highlight);
719
m_last_widget_under_mouse = widget_under_mouse;
720
m_last_form_under_mouse = form_under_mouse;
721
if (m_last_form_under_mouse == 0)
722
m_widget_box_under_mouse = widgetBoxAt(globalPos);
724
m_widget_box_under_mouse = 0;
727
void FormWindowManager::endDrag(const QPoint &pos)
730
m_core->topLevel()->releaseMouse();
733
Q_ASSERT(!m_drag_item_list.isEmpty());
735
foreach (QDesignerDnDItemInterface *item, m_drag_item_list)
736
item->decoration()->hide();
738
// ugly, but you can't qobject_cast from interfaces
739
if (m_last_form_under_mouse != 0 &&
740
m_last_form_under_mouse->hasFeature(QDesignerFormWindowInterface::EditFeature)) {
741
m_last_form_under_mouse->dropWidgets(m_drag_item_list, m_last_widget_under_mouse, pos);
742
} else if (m_widget_box_under_mouse != 0) {
743
m_widget_box_under_mouse->dropWidgets(m_drag_item_list, pos);
744
foreach (QDesignerDnDItemInterface *item, m_drag_item_list) {
745
if (item->type() == QDesignerDnDItemInterface::CopyDrop)
747
FormWindow *source = qobject_cast<FormWindow*>(item->source());
750
QWidget *widget = item->widget();
753
source->deleteWidgets(QList<QWidget*>() << widget);
756
foreach (QDesignerDnDItemInterface *item, m_drag_item_list) {
757
if (item->widget() != 0)
758
item->widget()->show();
762
foreach (QDesignerDnDItemInterface *item, m_drag_item_list)
765
m_drag_item_list.clear();
766
m_last_widget_under_mouse = 0;
767
m_last_form_under_mouse = 0;
768
m_widget_box_under_mouse = 0;
771
bool FormWindowManager::isDecoration(QWidget *widget) const
773
foreach (QDesignerDnDItemInterface *item, m_drag_item_list) {
774
if (item->decoration() == widget)