~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/components/formeditor/widgetselection.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the designer application of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "widgetselection.h"
 
30
#include "formwindow.h"
 
31
#include "formwindowmanager.h"
 
32
 
 
33
// sdk
 
34
#include <QtDesigner/QtDesigner>
 
35
#include <QtDesigner/QExtensionManager>
 
36
 
 
37
// shared
 
38
#include <qdesigner_command_p.h>
 
39
#include <layout_p.h>
 
40
#include <layoutinfo_p.h>
 
41
 
 
42
#include <QtGui/QMenu>
 
43
#include <QtGui/QWidget>
 
44
#include <QtGui/QApplication>
 
45
#include <QtGui/QLabel>
 
46
#include <QtGui/QPainter>
 
47
#include <QtGui/QMouseEvent>
 
48
#include <QtGui/QStylePainter>
 
49
#include <QtGui/QGridLayout>
 
50
 
 
51
#include <QtCore/QVariant>
 
52
#include <QtCore/qdebug.h>
 
53
 
 
54
#define NO_TOPWIDGET
 
55
 
 
56
#ifndef Q_MOC_RUN
 
57
using namespace qdesigner_internal;
 
58
#endif
 
59
 
 
60
class TopWidget: public InvisibleWidget
 
61
{
 
62
    Q_OBJECT
 
63
public:
 
64
    TopWidget(QWidget *parent)
 
65
        : InvisibleWidget(parent)
 
66
    {
 
67
        setAttribute(Qt::WA_TransparentForMouseEvents);
 
68
    }
 
69
};
 
70
 
 
71
WidgetHandle::WidgetHandle(FormWindow *parent, WidgetHandle::Type t, WidgetSelection *s)
 
72
    : InvisibleWidget(parent)
 
73
{
 
74
    active = true;
 
75
    widget = 0;
 
76
    type = t;
 
77
    setMouseTracking(false);
 
78
    formWindow = parent;
 
79
    sel = s;
 
80
 
 
81
    if (type == TaskMenu) {
 
82
        setBackgroundRole(QPalette::Button);
 
83
        setFixedSize(12, 12);
 
84
    } else {
 
85
        setBackgroundRole(active ? QPalette::Text : QPalette::Dark);
 
86
        setFixedSize(6, 6);
 
87
    }
 
88
 
 
89
    updateCursor();
 
90
}
 
91
 
 
92
void WidgetHandle::updateCursor()
 
93
{
 
94
    if (!active) {
 
95
        setCursor(Qt::ArrowCursor);
 
96
        return;
 
97
    }
 
98
 
 
99
    switch (type) {
 
100
    case LeftTop:
 
101
        setCursor(Qt::SizeFDiagCursor);
 
102
        break;
 
103
    case Top:
 
104
        setCursor(Qt::SizeVerCursor);
 
105
        break;
 
106
    case RightTop:
 
107
        setCursor(Qt::SizeBDiagCursor);
 
108
        break;
 
109
    case Right:
 
110
        setCursor(Qt::SizeHorCursor);
 
111
        break;
 
112
    case RightBottom:
 
113
        setCursor(Qt::SizeFDiagCursor);
 
114
        break;
 
115
    case Bottom:
 
116
        setCursor(Qt::SizeVerCursor);
 
117
        break;
 
118
    case LeftBottom:
 
119
        setCursor(Qt::SizeBDiagCursor);
 
120
        break;
 
121
    case Left:
 
122
        setCursor(Qt::SizeHorCursor);
 
123
        break;
 
124
    case TaskMenu:
 
125
        setCursor(Qt::ArrowCursor);
 
126
        break;
 
127
    default:
 
128
        Q_ASSERT(0);
 
129
    }
 
130
}
 
131
 
 
132
QDesignerFormEditorInterface *WidgetHandle::core() const
 
133
{
 
134
    if (QDesignerFormWindowInterface *fw = formWindow)
 
135
        return fw->core();
 
136
 
 
137
    return 0;
 
138
}
 
139
 
 
140
void WidgetHandle::setActive(bool a)
 
141
{
 
142
    active = a;
 
143
    if (type != TaskMenu) {
 
144
        setBackgroundRole(active ? QPalette::Text : QPalette::Dark);
 
145
    }
 
146
    updateCursor();
 
147
}
 
148
 
 
149
void WidgetHandle::setWidget(QWidget *w)
 
150
{
 
151
    widget = w;
 
152
}
 
153
 
 
154
void WidgetHandle::paintEvent(QPaintEvent *)
 
155
{
 
156
    FormWindow *fw = formWindow;
 
157
    QDesignerFormWindowManagerInterface *m = fw->core()->formWindowManager();
 
158
 
 
159
    QStylePainter p(this);
 
160
    if (type == TaskMenu) {
 
161
        QStyleOptionToolButton option;
 
162
        option.init(this);
 
163
        option.state |= QStyle::State_Raised;
 
164
        option.arrowType = Qt::RightArrow;
 
165
        option.toolButtonStyle = Qt::ToolButtonIconOnly;
 
166
        option.features = QStyleOptionToolButton::Arrow;
 
167
        option.subControls = QStyle::SC_ToolButton;
 
168
        p.drawComplexControl(QStyle::CC_ToolButton, option);
 
169
    } else if (fw->currentWidget() == widget) {
 
170
        p.setPen(m->activeFormWindow() == fw ? Qt::blue : Qt::red);
 
171
        p.drawRect(0, 0, width() - 1, height() - 1);
 
172
    }
 
173
}
 
174
 
 
175
void WidgetHandle::mousePressEvent(QMouseEvent *e)
 
176
{
 
177
    e->accept();
 
178
 
 
179
    if (!formWindow->hasFeature(FormWindow::EditFeature))
 
180
        return;
 
181
 
 
182
    if (!(widget && e->button() == Qt::LeftButton))
 
183
        return;
 
184
 
 
185
    if (!(active || type == TaskMenu))
 
186
        return;
 
187
 
 
188
    QWidget *container = widget->parentWidget();
 
189
 
 
190
    oldPressPos = container->mapFromGlobal(e->globalPos());
 
191
    geom = origGeom = widget->geometry();
 
192
 
 
193
    if (type == TaskMenu && e->button() == Qt::LeftButton) {
 
194
        Q_ASSERT(sel->taskMenuExtension());
 
195
 
 
196
        QMenu m(this);
 
197
        foreach (QAction *a, sel->taskMenuExtension()->taskActions()) {
 
198
            m.addAction(a);
 
199
        }
 
200
        m.exec(e->globalPos());
 
201
    }
 
202
 
 
203
}
 
204
 
 
205
int WidgetHandle::adjustPoint(int x, int dx)
 
206
{ return (x / dx) * dx + 1; }
 
207
 
 
208
void WidgetHandle::mouseMoveEvent(QMouseEvent *e)
 
209
{
 
210
    if (!(widget && active && e->buttons() & Qt::LeftButton))
 
211
        return;
 
212
 
 
213
    if (type == TaskMenu)
 
214
        return;
 
215
 
 
216
    e->accept();
 
217
 
 
218
    QWidget *container = widget->parentWidget();
 
219
 
 
220
    QPoint rp = container->mapFromGlobal(e->globalPos());
 
221
    QPoint d = rp - oldPressPos;
 
222
    oldPressPos = rp;
 
223
 
 
224
    QRect pr = container->rect();
 
225
    QPoint grid = formWindow->grid();
 
226
 
 
227
    switch (type) {
 
228
 
 
229
    case TaskMenu:
 
230
        break;
 
231
 
 
232
    case LeftTop: {
 
233
        if (rp.x() > pr.width() - 2 * width() || rp.y() > pr.height() - 2 * height())
 
234
            return;
 
235
 
 
236
        int w = geom.width() - d.x();
 
237
        geom.setWidth(w);
 
238
        w = adjustPoint(w, grid.x());
 
239
 
 
240
        int h = geom.height() - d.y();
 
241
        geom.setHeight(h);
 
242
        h = adjustPoint(h, grid.y());
 
243
 
 
244
        int dx = widget->width() - w;
 
245
        int dy = widget->height() - h;
 
246
 
 
247
        trySetGeometry(widget, widget->x() + dx, widget->y() + dy, w, h);
 
248
    } break;
 
249
 
 
250
    case Top: {
 
251
        if (rp.y() > pr.height() - 2 * height())
 
252
            return;
 
253
 
 
254
        int h = geom.height() - d.y();
 
255
        geom.setHeight(h);
 
256
        h = adjustPoint(h, grid.y());
 
257
 
 
258
        int dy = widget->height() - h;
 
259
        trySetGeometry(widget, widget->x(), widget->y() + dy, widget->width(), h);
 
260
    } break;
 
261
 
 
262
    case RightTop: {
 
263
        if (rp.x() < 2 * width() || rp.y() > pr.height() - 2 * height())
 
264
            return;
 
265
 
 
266
        int h = geom.height() - d.y();
 
267
        geom.setHeight(h);
 
268
        h = adjustPoint(h, grid.y());
 
269
 
 
270
        int dy = widget->height() - h;
 
271
 
 
272
        int w = geom.width() + d.x();
 
273
        geom.setWidth(w);
 
274
        w = adjustPoint(w, grid.x());
 
275
 
 
276
        trySetGeometry(widget, widget->x(), widget->y() + dy, w, h);
 
277
    } break;
 
278
 
 
279
    case Right: {
 
280
        if (rp.x() < 2 * width())
 
281
            return;
 
282
 
 
283
        int w = geom.width() + d.x();
 
284
        geom.setWidth(w);
 
285
        w = adjustPoint(w, grid.x());
 
286
 
 
287
        tryResize(widget, w, widget->height());
 
288
    } break;
 
289
 
 
290
    case RightBottom: {
 
291
        if (rp.x() < 2 * width() || rp.y() < 2 * height())
 
292
            return;
 
293
 
 
294
        int w = geom.width() + d.x();
 
295
        geom.setWidth(w);
 
296
        w = adjustPoint(w, grid.x());
 
297
 
 
298
        int h = geom.height() + d.y();
 
299
        geom.setHeight(h);
 
300
        h = adjustPoint(h, grid.y());
 
301
 
 
302
        tryResize(widget, w, h);
 
303
    } break;
 
304
 
 
305
    case Bottom: {
 
306
        if (rp.y() < 2 * height())
 
307
            return;
 
308
 
 
309
        int h = geom.height() + d.y();
 
310
        geom.setHeight(h);
 
311
        h = adjustPoint(h, grid.y());
 
312
 
 
313
        tryResize(widget, widget->width(), h);
 
314
    } break;
 
315
 
 
316
    case LeftBottom: {
 
317
        if (rp.x() > pr.width() - 2 * width() || rp.y() < 2 * height())
 
318
            return;
 
319
 
 
320
        int w = geom.width() - d.x();
 
321
        geom.setWidth(w);
 
322
        w = adjustPoint(w, grid.x());
 
323
 
 
324
        int h = geom.height() + d.y();
 
325
        geom.setHeight(h);
 
326
        h = adjustPoint(h, grid.y());
 
327
 
 
328
        int dx = widget->width() - w;
 
329
 
 
330
        trySetGeometry(widget, widget->x() + dx, widget->y(), w, h);
 
331
    } break;
 
332
 
 
333
    case Left: {
 
334
        if (rp.x() > pr.width() - 2 * width())
 
335
            return;
 
336
 
 
337
        int w = geom.width() - d.x();
 
338
        geom.setWidth(w);
 
339
        w = adjustPoint(w, grid.x());
 
340
 
 
341
        int dx = widget->width() - w;
 
342
 
 
343
        trySetGeometry(widget, widget->x() + dx, widget->y(), w, widget->height());
 
344
    } break;
 
345
 
 
346
    default: break;
 
347
 
 
348
    } // end switch
 
349
 
 
350
    sel->updateGeometry();
 
351
 
 
352
    if (LayoutInfo::layoutType(formWindow->core(), widget) != LayoutInfo::NoLayout)
 
353
        formWindow->updateChildSelections(widget);
 
354
}
 
355
 
 
356
void WidgetHandle::mouseReleaseEvent(QMouseEvent *e)
 
357
{
 
358
    if (e->button() != Qt::LeftButton || !active)
 
359
        return;
 
360
 
 
361
    if (type == TaskMenu)
 
362
        return;
 
363
 
 
364
    e->accept();
 
365
 
 
366
    if (!formWindow->hasFeature(FormWindow::EditFeature))
 
367
        return;
 
368
 
 
369
    LayoutInfo::Type layoutType = widget->parentWidget()
 
370
            ? LayoutInfo::layoutType(formWindow->core(), widget->parentWidget())
 
371
            : LayoutInfo::NoLayout;
 
372
 
 
373
    if (layoutType == LayoutInfo::Grid) {
 
374
        QSize size = widget->parentWidget()->size();
 
375
        QGridLayout *grid = static_cast<QGridLayout*>(widget->parentWidget()->layout());
 
376
 
 
377
        QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core()->extensionManager(), widget->parentWidget());
 
378
 
 
379
        int index = deco->indexOf(widget);
 
380
        QRect info = deco->itemInfo(index);
 
381
        int top = deco->findItemAt(info.top() - 1, info.left());
 
382
        int left = deco->findItemAt(info.top(), info.left() - 1);
 
383
        int bottom = deco->findItemAt(info.bottom() + 1, info.left());
 
384
        int right = deco->findItemAt(info.top(), info.right() + 1);
 
385
 
 
386
        QPoint pt = origGeom.center() - widget->geometry().center();
 
387
 
 
388
        ChangeLayoutItemGeometry *cmd = 0;
 
389
 
 
390
        switch (type) {
 
391
            default: break;
 
392
 
 
393
            case WidgetHandle::Top: {
 
394
                if (pt.y() < 0 && info.height() > 1) {
 
395
                    cmd = new ChangeLayoutItemGeometry(formWindow);
 
396
                    cmd->init(widget, info.y() + 1, info.x(), info.height() - 1, info.width());
 
397
                } else if (pt.y() > 0 && top != -1 && grid->itemAt(top)->spacerItem()) {
 
398
                    cmd = new ChangeLayoutItemGeometry(formWindow);
 
399
                    cmd->init(widget, info.y() - 1, info.x(), info.height() + 1, info.width());
 
400
                }
 
401
            } break;
 
402
 
 
403
            case WidgetHandle::Left: {
 
404
                if (pt.x() < 0 && info.width() > 1) {
 
405
                    cmd = new ChangeLayoutItemGeometry(formWindow);
 
406
                    cmd->init(widget, info.y(), info.x() + 1, info.height(), info.width() - 1);
 
407
                } else if (pt.x() > 0 && left != -1 && grid->itemAt(left)->spacerItem()) {
 
408
                    cmd = new ChangeLayoutItemGeometry(formWindow);
 
409
                    cmd->init(widget, info.y(), info.x() - 1, info.height(), info.width() + 1);
 
410
                }
 
411
            } break;
 
412
 
 
413
            case WidgetHandle::Right: {
 
414
                if (pt.x() > 0 && info.width() > 1) {
 
415
                    cmd = new ChangeLayoutItemGeometry(formWindow);
 
416
                    cmd->init(widget, info.y(), info.x(), info.height(), info.width() - 1);
 
417
                } else if (pt.x() < 0 && right != -1 && grid->itemAt(right)->spacerItem()) {
 
418
                    cmd = new ChangeLayoutItemGeometry(formWindow);
 
419
                    cmd->init(widget, info.y(), info.x(), info.height(), info.width() + 1);
 
420
                }
 
421
            } break;
 
422
 
 
423
            case WidgetHandle::Bottom: {
 
424
                if (pt.y() > 0 && info.width() > 1) {
 
425
                    cmd = new ChangeLayoutItemGeometry(formWindow);
 
426
                    cmd->init(widget, info.y(), info.x(), info.height() - 1, info.width());
 
427
                } else if (pt.y() < 0 && bottom != -1 && grid->itemAt(bottom)->spacerItem()) {
 
428
                    cmd = new ChangeLayoutItemGeometry(formWindow);
 
429
                    cmd->init(widget, info.y(), info.x(), info.height() + 1, info.width());
 
430
                }
 
431
            } break;
 
432
        }
 
433
 
 
434
        if (cmd != 0) {
 
435
            formWindow->commandHistory()->push(cmd);
 
436
        } else {
 
437
            grid->invalidate();
 
438
            grid->activate();
 
439
            formWindow->clearSelection(false);
 
440
            formWindow->selectWidget(widget);
 
441
        }
 
442
    } else if (geom != widget->geometry()) {
 
443
        SetPropertyCommand *cmd = new SetPropertyCommand(formWindow);
 
444
        cmd->init(widget, QLatin1String("geometry"), widget->geometry());
 
445
        cmd->setOldValue(origGeom);
 
446
        formWindow->commandHistory()->push(cmd);
 
447
        formWindow->emitSelectionChanged();
 
448
    }
 
449
}
 
450
 
 
451
void WidgetHandle::trySetGeometry(QWidget *w, int x, int y, int width, int height)
 
452
{
 
453
    if (!formWindow->hasFeature(FormWindow::EditFeature))
 
454
        return;
 
455
 
 
456
    int minw = qMax(w->minimumSizeHint().width(), w->minimumSize().width());
 
457
    minw = qMax(minw, 2 * formWindow->grid().x());
 
458
 
 
459
    int minh = qMax(w->minimumSizeHint().height(), w->minimumSize().height());
 
460
    minh = qMax(minh, 2 * formWindow->grid().y());
 
461
 
 
462
    if (qMax(minw, width) > w->maximumWidth() ||
 
463
         qMax(minh, height) > w->maximumHeight())
 
464
        return;
 
465
 
 
466
    if (width < minw && x != w->x())
 
467
        x -= minw - width;
 
468
 
 
469
    if (height < minh && y != w->y())
 
470
        y -= minh - height;
 
471
 
 
472
    w->setGeometry(x, y, qMax(minw, width), qMax(minh, height));
 
473
}
 
474
 
 
475
void WidgetHandle::tryResize(QWidget *w, int width, int height)
 
476
{
 
477
    int minw = qMax(w->minimumSizeHint().width(), w->minimumSize().width());
 
478
    minw = qMax(minw, 16);
 
479
 
 
480
    int minh = qMax(w->minimumSizeHint().height(), w->minimumSize().height());
 
481
    minh = qMax(minh, 16);
 
482
 
 
483
    w->resize(qMax(minw, width), qMax(minh, height));
 
484
}
 
485
 
 
486
// ------------------------------------------------------------------------
 
487
 
 
488
WidgetSelection::WidgetSelection(FormWindow *parent, QHash<QWidget *, WidgetSelection *> *selDict)
 
489
    : selectionDict(selDict)
 
490
{
 
491
    wid = 0;
 
492
    taskMenu = 0;
 
493
    formWindow = parent;
 
494
    for (int i = WidgetHandle::LeftTop; i < WidgetHandle::TypeCount; ++i) {
 
495
        handles.insert(i, new WidgetHandle(formWindow, (WidgetHandle::Type)i, this));
 
496
    }
 
497
 
 
498
    m_topWidget = 0;
 
499
 
 
500
    hide();
 
501
}
 
502
 
 
503
void WidgetSelection::setWidget(QWidget *w, bool updateDict)
 
504
{
 
505
    taskMenu = 0; // ### qt_extension<QDesignerTaskMenuExtension*>(core()->extensionManager(), w);
 
506
 
 
507
#ifndef NO_TOPWIDGET
 
508
    if (m_topWidget) {
 
509
        Q_ASSERT(m_topWidget->parentWidget() != 0);
 
510
        m_topWidget->parentWidget()->setAttribute(Qt::WA_ContentsPropagated, false);
 
511
    }
 
512
 
 
513
    delete m_topWidget;
 
514
    m_topWidget = 0;
 
515
#endif
 
516
 
 
517
    if (wid != 0)
 
518
        wid->removeEventFilter(this);
 
519
 
 
520
    if (w == 0) {
 
521
        hide();
 
522
        if (updateDict)
 
523
            selectionDict->remove(wid);
 
524
        wid = 0;
 
525
        return;
 
526
    }
 
527
 
 
528
    wid = w;
 
529
 
 
530
    wid->installEventFilter(this);
 
531
 
 
532
    bool active = LayoutInfo::isWidgetLaidout(formWindow->core(), wid) == false;
 
533
 
 
534
    for (int i = WidgetHandle::LeftTop; i < WidgetHandle::TypeCount; ++i) {
 
535
        if (WidgetHandle *h = handles[i]) {
 
536
            h->setWidget(wid);
 
537
            h->setActive(active);
 
538
        }
 
539
    }
 
540
 
 
541
    QLayout *layout = LayoutInfo::managedLayout(formWindow->core(), formWindow->designerWidget(wid->parentWidget()));
 
542
    if (QGridLayout *grid = qobject_cast<QGridLayout*>(layout)) {
 
543
        int index = grid->indexOf(wid);
 
544
        if (index == -1) {
 
545
#if defined(QD_DEBUG)
 
546
            qWarning() << "unexpected call to WidgetSelection::setWidget()" << "widget:" << wid << "grid:"<< grid;
 
547
#endif
 
548
            return;
 
549
        }
 
550
 
 
551
        Q_ASSERT(index != -1);
 
552
 
 
553
        QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core()->extensionManager(), wid->parentWidget());
 
554
        if (deco == 0) {
 
555
            // try with the actual layout
 
556
            deco = qt_extension<QDesignerLayoutDecorationExtension*>(core()->extensionManager(), layout);
 
557
        }
 
558
 
 
559
        if (deco != 0) {
 
560
            // bottom cell
 
561
            handles[WidgetHandle::Bottom]->setActive(true);
 
562
            // top cell
 
563
            handles[WidgetHandle::Top]->setActive(true);
 
564
            // left cell
 
565
            handles[WidgetHandle::Left]->setActive(true);
 
566
            // right cell
 
567
            handles[WidgetHandle::Right]->setActive(true);
 
568
        } else {
 
569
            qWarning() << "no QDesignerLayoutDecorationExtension for widget:" << wid;
 
570
        }
 
571
    }
 
572
 
 
573
#ifndef NO_TOPWIDGET
 
574
    wid->setAttribute(Qt::WA_ContentsPropagated, true);
 
575
    m_topWidget = new TopWidget(wid);
 
576
    QPalette p = m_topWidget->palette();
 
577
    p.setColor(m_topWidget->backgroundRole(), QColor(255, 0, 0, 32));
 
578
    m_topWidget->setPalette(p);
 
579
#endif
 
580
 
 
581
    updateGeometry();
 
582
    show();
 
583
 
 
584
    if (updateDict)
 
585
        selectionDict->insert(w, this);
 
586
}
 
587
 
 
588
bool WidgetSelection::isUsed() const
 
589
{
 
590
    return wid != 0;
 
591
}
 
592
 
 
593
void WidgetSelection::updateGeometry()
 
594
{
 
595
    if (!wid || !wid->parentWidget())
 
596
        return;
 
597
 
 
598
    QPoint p = wid->parentWidget()->mapToGlobal(wid->pos());
 
599
    p = formWindow->mapFromGlobal(p);
 
600
    QRect r(p, wid->size());
 
601
 
 
602
    int w = 6;
 
603
    int h = 6;
 
604
 
 
605
    for (int i = WidgetHandle::LeftTop; i < WidgetHandle::TypeCount; ++i) {
 
606
        WidgetHandle *hndl = handles[ i ];
 
607
        if (!hndl)
 
608
            continue;
 
609
        switch (i) {
 
610
        case WidgetHandle::LeftTop:
 
611
            hndl->move(r.x() - w / 2, r.y() - h / 2);
 
612
            break;
 
613
        case WidgetHandle::Top:
 
614
            hndl->move(r.x() + r.width() / 2 - w / 2, r.y() - h / 2);
 
615
            break;
 
616
        case WidgetHandle::RightTop:
 
617
            hndl->move(r.x() + r.width() - w / 2, r.y() - h / 2);
 
618
            break;
 
619
        case WidgetHandle::Right:
 
620
            hndl->move(r.x() + r.width() - w / 2, r.y() + r.height() / 2 - h / 2);
 
621
            break;
 
622
        case WidgetHandle::RightBottom:
 
623
            hndl->move(r.x() + r.width() - w / 2, r.y() + r.height() - h / 2);
 
624
            break;
 
625
        case WidgetHandle::Bottom:
 
626
            hndl->move(r.x() + r.width() / 2 - w / 2, r.y() + r.height() - h / 2);
 
627
            break;
 
628
        case WidgetHandle::LeftBottom:
 
629
            hndl->move(r.x() - w / 2, r.y() + r.height() - h / 2);
 
630
            break;
 
631
        case WidgetHandle::Left:
 
632
            hndl->move(r.x() - w / 2, r.y() + r.height() / 2 - h / 2);
 
633
            break;
 
634
        case WidgetHandle::TaskMenu:
 
635
            hndl->move(r.x() + r.width() - w / 2, r.y() + h - h / 2);
 
636
            break;
 
637
        default:
 
638
            break;
 
639
        }
 
640
    }
 
641
 
 
642
#ifndef NO_TOPWIDGET
 
643
    if (m_topWidget) {
 
644
        m_topWidget->setGeometry(wid->rect());
 
645
    }
 
646
#endif
 
647
}
 
648
 
 
649
void WidgetSelection::hide()
 
650
{
 
651
    for (int i = WidgetHandle::LeftTop; i < WidgetHandle::TypeCount; ++i) {
 
652
        WidgetHandle *h = handles[ i ];
 
653
        if (h)
 
654
            h->hide();
 
655
    }
 
656
 
 
657
#ifndef NO_TOPWIDGET
 
658
    if (m_topWidget)
 
659
        m_topWidget->hide();
 
660
#endif
 
661
}
 
662
 
 
663
void WidgetSelection::show()
 
664
{
 
665
    for (int i = WidgetHandle::LeftTop; i < WidgetHandle::TypeCount; ++i) {
 
666
        WidgetHandle *h = handles[ i ];
 
667
        if (h) {
 
668
            if (i == WidgetHandle::TaskMenu) {
 
669
                h->setVisible(taskMenuExtension() != 0);
 
670
                h->raise();
 
671
            } else {
 
672
                h->show();
 
673
                h->raise();
 
674
            }
 
675
        }
 
676
    }
 
677
 
 
678
#ifndef NO_TOPWIDGET
 
679
    if (m_topWidget) {
 
680
        m_topWidget->show();
 
681
        m_topWidget->raise();
 
682
    }
 
683
#endif
 
684
}
 
685
 
 
686
void WidgetSelection::update()
 
687
{
 
688
    for (int i = WidgetHandle::LeftTop; i < WidgetHandle::TypeCount; ++i) {
 
689
        WidgetHandle *h = handles[ i ];
 
690
        if (h)
 
691
            h->update();
 
692
    }
 
693
 
 
694
#ifndef NO_TOPWIDGET
 
695
    if (m_topWidget)
 
696
        m_topWidget->update();
 
697
#endif
 
698
}
 
699
 
 
700
QWidget *WidgetSelection::widget() const
 
701
{
 
702
    return wid;
 
703
}
 
704
 
 
705
QDesignerFormEditorInterface *WidgetSelection::core() const
 
706
{
 
707
    if (formWindow)
 
708
        return formWindow->core();
 
709
 
 
710
    return 0;
 
711
}
 
712
 
 
713
bool WidgetSelection::eventFilter(QObject *object, QEvent *event)
 
714
{
 
715
    if (object != widget())
 
716
        return false;
 
717
 
 
718
    switch (event->type()) {
 
719
        default: break;
 
720
 
 
721
        case QEvent::Move:
 
722
        case QEvent::Resize:
 
723
            updateGeometry();
 
724
            break;
 
725
    } // end switch
 
726
 
 
727
    return false;
 
728
}
 
729
 
 
730
#include "widgetselection.moc"