qdeclarativedesignview.cpp 24.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

30
#include "qdeclarativedesignview.h"
31
#include "qdeclarativedesignview_p.h"
32
33
34
35
36
37
38
39
#include "qdeclarativedesigndebugserver.h"
#include "selectiontool.h"
#include "zoomtool.h"
#include "colorpickertool.h"
#include "layeritem.h"
#include "boundingrecthighlighter.h"
#include "subcomponenteditortool.h"
#include "qmltoolbar.h"
40
#include "jsdebuggeragent.h"
41
42

#include <QDeclarativeItem>
43
44
45
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <QDeclarativeExpression>
46
#include <QWidget>
47
#include <QMouseEvent>
48
49
50
51
#include <QGraphicsObject>
#include <QApplication>

#include <QAbstractAnimation>
52
#include <private/qdeclarativeengine_p.h>
53
54
55
56
#include <private/qabstractanimation_p.h>

namespace QmlViewer {

57
58
const int SceneChangeUpdateInterval = 5000;

59
60
Q_GLOBAL_STATIC(QDeclarativeDesignDebugServer, qmlDesignDebugServer)

61
62
QDeclarativeDesignViewPrivate::QDeclarativeDesignViewPrivate(QDeclarativeDesignView *q) :
    q(q),
63
64
65
    designModeBehavior(false),
    executionPaused(false),
    slowdownFactor(1.0f),
66
    jsDebuggerAgent(0),
67
    toolbar(0)
68
{
69
70
    sceneChangedTimer.setInterval(SceneChangeUpdateInterval);
    sceneChangedTimer.setSingleShot(true);
71
72
73
74
75
76
}

QDeclarativeDesignViewPrivate::~QDeclarativeDesignViewPrivate()
{
}

77
QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) :
78
    QDeclarativeView(parent), data(new QDeclarativeDesignViewPrivate(this))
79
80
81
82
83
84
85
86
{
    data->manipulatorLayer = new LayerItem(scene());
    data->selectionTool = new SelectionTool(this);
    data->zoomTool = new ZoomTool(this);
    data->colorPickerTool = new ColorPickerTool(this);
    data->boundingRectHighlighter = new BoundingRectHighlighter(this);
    data->subcomponentEditorTool = new SubcomponentEditorTool(this);
    data->currentTool = data->selectionTool;
87

88
    connect(scene(), SIGNAL(changed(QList<QRectF>)), SLOT(_q_sceneChanged(QList<QRectF>)));
89
90
    setMouseTracking(true);

91
    connect(qmlDesignDebugServer(), SIGNAL(designModeBehaviorChanged(bool)), SLOT(setDesignModeBehavior(bool)));
92
    connect(qmlDesignDebugServer(), SIGNAL(reloadRequested()), SLOT(_q_reloadView()));
93
94
    connect(qmlDesignDebugServer(),
            SIGNAL(currentObjectsChanged(QList<QObject*>)),
95
            SLOT(_q_onCurrentObjectsChanged(QList<QObject*>)));
96
    connect(qmlDesignDebugServer(), SIGNAL(animationSpeedChangeRequested(qreal)), SLOT(changeAnimationSpeed(qreal)));
97
98
99
100
    connect(qmlDesignDebugServer(), SIGNAL(colorPickerToolRequested()), SLOT(_q_changeToColorPickerTool()));
    connect(qmlDesignDebugServer(), SIGNAL(selectMarqueeToolRequested()), SLOT(_q_changeToMarqueeSelectTool()));
    connect(qmlDesignDebugServer(), SIGNAL(selectToolRequested()), SLOT(_q_changeToSingleSelectTool()));
    connect(qmlDesignDebugServer(), SIGNAL(zoomToolRequested()), SLOT(_q_changeToZoomTool()));
101
102
    connect(qmlDesignDebugServer(),
            SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString)),
103
            SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString)));
104
    connect(qmlDesignDebugServer(), SIGNAL(contextPathIndexChanged(int)), SLOT(_q_changeContextPathIndex(int)));
105
    connect(qmlDesignDebugServer(), SIGNAL(clearComponentCacheRequested()), SLOT(_q_clearComponentCache()));
106
    connect(this, SIGNAL(statusChanged(QDeclarativeView::Status)), SLOT(_q_onStatusChanged(QDeclarativeView::Status)));
107

108
109
    connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor)));
    connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)),
110
            qmlDesignDebugServer(), SLOT(selectedColorChanged(QColor)));
111

Lasse Holmstedt's avatar
Lasse Holmstedt committed
112
113
114
    connect(data->subcomponentEditorTool, SIGNAL(cleared()), SIGNAL(inspectorContextCleared()));
    connect(data->subcomponentEditorTool, SIGNAL(contextPushed(QString)), SIGNAL(inspectorContextPushed(QString)));
    connect(data->subcomponentEditorTool, SIGNAL(contextPopped()), SIGNAL(inspectorContextPopped()));
115
    connect(data->subcomponentEditorTool, SIGNAL(contextPathChanged(QStringList)), qmlDesignDebugServer(), SLOT(contextPathUpdated(QStringList)));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
116

117
118
    connect(&(data->sceneChangedTimer), SIGNAL(timeout()), SLOT(_q_checkSceneItemCount()));

119
    data->createToolbar();
120
121

    data->_q_changeToSingleSelectTool();
122
123
124

    // always start debug mode - that's what this design view is for.
    setDebugMode(true);
125
126
127
128
129
130
}

QDeclarativeDesignView::~QDeclarativeDesignView()
{
}

Lasse Holmstedt's avatar
Lasse Holmstedt committed
131
132
void QDeclarativeDesignView::setInspectorContext(int contextIndex)
{
133
134
135
136
137
    if (data->subcomponentEditorTool->contextIndex() != contextIndex) {
        QGraphicsObject *object = data->subcomponentEditorTool->setContext(contextIndex);
        if (object)
            qmlDesignDebugServer()->setCurrentObjects(QList<QObject*>() << object);
    }
Lasse Holmstedt's avatar
Lasse Holmstedt committed
138
139
}

140
void QDeclarativeDesignViewPrivate::_q_reloadView()
141
{
142
    subcomponentEditorTool->clear();
143
    clearHighlight();
144
    emit q->reloadRequested();
145
146
}

147
void QDeclarativeDesignViewPrivate::clearEditorItems()
148
149
150
151
152
{
    clearHighlight();
    setSelectedItems(QList<QGraphicsItem*>());
}

153
154
void QDeclarativeDesignView::leaveEvent(QEvent *event)
{
155
    if (!data->designModeBehavior) {
156
157
158
        QDeclarativeView::leaveEvent(event);
        return;
    }
159
    data->clearHighlight();
160
161
}

162
163
void QDeclarativeDesignView::mousePressEvent(QMouseEvent *event)
{
164
    if (!data->designModeBehavior) {
165
166
167
        QDeclarativeView::mousePressEvent(event);
        return;
    }
168
169
    data->cursorPos = event->pos();
    data->currentTool->mousePressEvent(event);
170
171
172
173
}

void QDeclarativeDesignView::mouseMoveEvent(QMouseEvent *event)
{
174
175
    if (!data->designModeBehavior) {
        data->clearEditorItems();
176
177
178
        QDeclarativeView::mouseMoveEvent(event);
        return;
    }
179
    data->cursorPos = event->pos();
180

181
    QList<QGraphicsItem*> selItems = data->selectableItems(event->pos());
182
183
184
185
186
187
    if (!selItems.isEmpty()) {
        setToolTip(AbstractFormEditorTool::titleForItem(selItems.first()));
    } else {
        setToolTip(QString());
    }
    if (event->buttons()) {
188
189
        data->subcomponentEditorTool->mouseMoveEvent(event);
        data->currentTool->mouseMoveEvent(event);
190
    } else {
191
192
        data->subcomponentEditorTool->hoverMoveEvent(event);
        data->currentTool->hoverMoveEvent(event);
193
194
195
196
197
    }
}

void QDeclarativeDesignView::mouseReleaseEvent(QMouseEvent *event)
{
198
    if (!data->designModeBehavior) {
199
200
201
        QDeclarativeView::mouseReleaseEvent(event);
        return;
    }
202
    data->subcomponentEditorTool->mouseReleaseEvent(event);
203

204
205
    data->cursorPos = event->pos();
    data->currentTool->mouseReleaseEvent(event);
206

207
    qmlDesignDebugServer()->setCurrentObjects(AbstractFormEditorTool::toObjectList(selectedItems()));
208
209
210
211
}

void QDeclarativeDesignView::keyPressEvent(QKeyEvent *event)
{
212
    if (!data->designModeBehavior) {
213
214
215
        QDeclarativeView::keyPressEvent(event);
        return;
    }
216
    data->currentTool->keyPressEvent(event);
217
218
219
220
}

void QDeclarativeDesignView::keyReleaseEvent(QKeyEvent *event)
{
221
    if (!data->designModeBehavior) {
222
223
224
225
226
227
        QDeclarativeView::keyReleaseEvent(event);
        return;
    }

    switch(event->key()) {
    case Qt::Key_V:
228
        data->_q_changeToSingleSelectTool();
229
230
        break;
    case Qt::Key_M:
231
        data->_q_changeToMarqueeSelectTool();
232
        break;
233
    case Qt::Key_I:
234
        data->_q_changeToColorPickerTool();
235
236
        break;
    case Qt::Key_Z:
237
        data->_q_changeToZoomTool();
238
        break;
239
240
    case Qt::Key_Enter:
    case Qt::Key_Return:
241
242
        if (!data->selectedItems().isEmpty())
            data->subcomponentEditorTool->setCurrentItem(data->selectedItems().first());
243
244
        break;
    case Qt::Key_Space:
245
246
        if (data->executionPaused) {
            continueExecution(data->slowdownFactor);
247
248
249
250
251
252
253
254
        } else {
            pauseExecution();
        }
        break;
    default:
        break;
    }

255
    data->currentTool->keyReleaseEvent(event);
256
257
}

258
void QDeclarativeDesignViewPrivate::_q_createQmlObject(const QString &qml, QObject *parent, const QStringList &importList, const QString &filename)
259
260
261
262
263
264
265
266
267
{
    if (!parent)
        return;

    QString imports;
    foreach(const QString &s, importList) {
        imports += s + "\n";
    }

268
269
    QDeclarativeContext *parentContext = q->engine()->contextForObject(parent);
    QDeclarativeComponent component(q->engine(), q);
270
271
272
273
274
275
    QByteArray constructedQml = QString(imports + qml).toLatin1();

    component.setData(constructedQml, filename);
    QObject *newObject = component.create(parentContext);
    if (newObject) {
        newObject->setParent(parent);
276
277
        QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent);
        QDeclarativeItem *newItem    = qobject_cast<QDeclarativeItem*>(newObject);
278
279
280
281
282
283
        if (parentItem && newItem) {
            newItem->setParentItem(parentItem);
        }
    }
}

284
285
286
287
288
void QDeclarativeDesignViewPrivate::_q_clearComponentCache()
{
    q->engine()->clearComponentCache();
}

289
QGraphicsItem *QDeclarativeDesignViewPrivate::currentRootItem() const
290
{
291
    return subcomponentEditorTool->currentRootItem();
292
293
294
295
}

void QDeclarativeDesignView::mouseDoubleClickEvent(QMouseEvent *event)
{
296
    if (!data->designModeBehavior) {
297
298
299
        QDeclarativeView::mouseDoubleClickEvent(event);
        return;
    }
300
301
302
303
304
305
306

    if (data->currentToolMode != Constants::SelectionToolMode
     && data->currentToolMode != Constants::MarqueeSelectionToolMode)
    {
        return;
    }

307
    QGraphicsItem *itemToEnter = 0;
308
    QList<QGraphicsItem*> itemList = items(event->pos());
309
    data->filterForSelection(itemList);
310

311
    if (data->selectedItems().isEmpty() && !itemList.isEmpty()) {
312
        itemToEnter = itemList.first();
313
    } else if (!data->selectedItems().isEmpty() && !itemList.isEmpty()) {
314
315
316
        itemToEnter = itemList.first();
    }

317
    if (itemToEnter)
318
        itemToEnter = data->subcomponentEditorTool->firstChildOfContext(itemToEnter);
319

320
321
    data->subcomponentEditorTool->setCurrentItem(itemToEnter);
    data->subcomponentEditorTool->mouseDoubleClickEvent(event);
322
323
324
325
326
327
328
329
330
331

    if ((event->buttons() & Qt::LeftButton) && itemToEnter) {
        QGraphicsObject *objectToEnter = itemToEnter->toGraphicsObject();
        if (objectToEnter)
            qmlDesignDebugServer()->setCurrentObjects(QList<QObject*>() << objectToEnter);
    }

}
void QDeclarativeDesignView::wheelEvent(QWheelEvent *event)
{
332
    if (!data->designModeBehavior) {
333
334
335
        QDeclarativeView::wheelEvent(event);
        return;
    }
336
    data->currentTool->wheelEvent(event);
337
338
339
340
}

void QDeclarativeDesignView::setDesignModeBehavior(bool value)
{
341
342
    emit designModeBehaviorChanged(value);

343
    data->toolbar->setDesignModeBehavior(value);
344
    qmlDesignDebugServer()->setDesignModeBehavior(value);
345

346
347
348
    data->designModeBehavior = value;
    if (data->subcomponentEditorTool) {
        data->subcomponentEditorTool->clear();
349
350
        data->clearHighlight();
        data->setSelectedItems(QList<QGraphicsItem*>());
351

352
        if (rootObject())
353
            data->subcomponentEditorTool->pushContext(rootObject());
354
    }
355

356
    if (!data->designModeBehavior)
357
        data->clearEditorItems();
358
359
}

360
bool QDeclarativeDesignView::designModeBehavior()
361
{
362
    return data->designModeBehavior;
363
364
}

365
void QDeclarativeDesignViewPrivate::changeTool(Constants::DesignTool tool, Constants::ToolFlags /*flags*/)
366
367
368
{
    switch(tool) {
    case Constants::SelectionToolMode:
369
        _q_changeToSingleSelectTool();
370
371
372
        break;
    case Constants::NoTool:
    default:
373
        currentTool = 0;
374
375
376
377
        break;
    }
}

378
void QDeclarativeDesignViewPrivate::setSelectedItemsForTools(QList<QGraphicsItem *> items)
379
{
380
    currentSelection.clear();
381
382
383
384
    foreach(QGraphicsItem *item, items) {
        if (item) {
            QGraphicsObject *obj = item->toGraphicsObject();
            if (obj)
385
                currentSelection << obj;
386
387
        }
    }
388
    currentTool->updateSelectedItems();
389
390
391
392
393
}

void QDeclarativeDesignViewPrivate::setSelectedItems(QList<QGraphicsItem *> items)
{
    setSelectedItemsForTools(items);
394
    qmlDesignDebugServer()->setCurrentObjects(AbstractFormEditorTool::toObjectList(items));
395
396
}

397
QList<QGraphicsItem *> QDeclarativeDesignViewPrivate::selectedItems()
398
{
399
    QList<QGraphicsItem *> selection;
400
    foreach(const QWeakPointer<QGraphicsObject> &selectedObject, currentSelection) {
401
        if (selectedObject.isNull()) {
402
            currentSelection.removeOne(selectedObject);
403
404
405
406
407
408
        } else {
            selection << selectedObject.data();
        }
    }

    return selection;
409
410
}

411
412
413
414
415
416
417
418
419
420
421
void QDeclarativeDesignView::setSelectedItems(QList<QGraphicsItem *> items)
{
    data->setSelectedItems(items);
}

QList<QGraphicsItem *> QDeclarativeDesignView::selectedItems()
{
    return data->selectedItems();
}

void QDeclarativeDesignViewPrivate::clearHighlight()
422
{
423
    boundingRectHighlighter->clear();
424
425
}

426
void QDeclarativeDesignViewPrivate::highlight(QGraphicsObject * item, ContextFlags flags)
427
{
428
    highlight(QList<QGraphicsObject*>() << item, flags);
429
430
}

431
void QDeclarativeDesignViewPrivate::highlight(QList<QGraphicsObject *> items, ContextFlags flags)
432
433
{
    if (items.isEmpty())
434
435
        return;

436
437
    QList<QGraphicsObject*> objectList;
    foreach(QGraphicsItem *item, items) {
438
439
        QGraphicsItem *child = item;
        if (flags & ContextSensitive)
440
            child = subcomponentEditorTool->firstChildOfContext(item);
441

442
443
444
445
446
        if (child) {
            QGraphicsObject *childObject = child->toGraphicsObject();
            if (childObject)
                objectList << childObject;
        }
447
    }
448

449
    boundingRectHighlighter->highlight(objectList);
450
451
}

452
bool QDeclarativeDesignViewPrivate::mouseInsideContextItem() const
453
{
454
    return subcomponentEditorTool->containsCursor(cursorPos.toPoint());
455
456
}

457
QList<QGraphicsItem*> QDeclarativeDesignViewPrivate::selectableItems(const QPointF &scenePos) const
458
{
459
    QList<QGraphicsItem*> itemlist = q->scene()->items(scenePos);
460
    return filterForCurrentContext(itemlist);
461
462
}

463
QList<QGraphicsItem*> QDeclarativeDesignViewPrivate::selectableItems(const QPoint &pos) const
464
{
465
    QList<QGraphicsItem*> itemlist = q->items(pos);
466
    return filterForCurrentContext(itemlist);
467
468
}

469
QList<QGraphicsItem*> QDeclarativeDesignViewPrivate::selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const
470
{
471
    QList<QGraphicsItem*> itemlist = q->scene()->items(sceneRect, selectionMode);
472

473
    return filterForCurrentContext(itemlist);
474
475
}

476
void QDeclarativeDesignViewPrivate::_q_changeToSingleSelectTool()
477
{
478
479
    currentToolMode = Constants::SelectionToolMode;
    selectionTool->setRubberbandSelectionMode(false);
480
481
482

    changeToSelectTool();

483
    emit q->selectToolActivated();
484
485
486
    qmlDesignDebugServer()->setCurrentTool(Constants::SelectionToolMode);
}

487
void QDeclarativeDesignViewPrivate::changeToSelectTool()
488
{
489
    if (currentTool == selectionTool)
490
491
        return;

492
493
494
495
    currentTool->clear();
    currentTool = selectionTool;
    currentTool->clear();
    currentTool->updateSelectedItems();
496
497
}

498
void QDeclarativeDesignViewPrivate::_q_changeToMarqueeSelectTool()
499
500
{
    changeToSelectTool();
501
502
    currentToolMode = Constants::MarqueeSelectionToolMode;
    selectionTool->setRubberbandSelectionMode(true);
503

504
    emit q->marqueeSelectToolActivated();
505
506
507
    qmlDesignDebugServer()->setCurrentTool(Constants::MarqueeSelectionToolMode);
}

508
void QDeclarativeDesignViewPrivate::_q_changeToZoomTool()
509
{
510
511
512
513
    currentToolMode = Constants::ZoomMode;
    currentTool->clear();
    currentTool = zoomTool;
    currentTool->clear();
514

515
    emit q->zoomToolActivated();
516
517
518
    qmlDesignDebugServer()->setCurrentTool(Constants::ZoomMode);
}

519
void QDeclarativeDesignViewPrivate::_q_changeToColorPickerTool()
520
{
521
    if (currentTool == colorPickerTool)
522
523
        return;

524
525
526
527
    currentToolMode = Constants::ColorPickerMode;
    currentTool->clear();
    currentTool = colorPickerTool;
    currentTool->clear();
528

529
    emit q->colorPickerActivated();
530
531
532
    qmlDesignDebugServer()->setCurrentTool(Constants::ColorPickerMode);
}

533
534
535
536
537
void QDeclarativeDesignViewPrivate::_q_changeContextPathIndex(int index)
{
    subcomponentEditorTool->setContext(index);
}

538
539
540
541
542
void QDeclarativeDesignViewPrivate::_q_sceneChanged(const QList<QRectF> & /*areas*/)
{
    if (designModeBehavior)
        return;

543
544
    if (!sceneChangedTimer.isActive())
        sceneChangedTimer.start();
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
}

void QDeclarativeDesignViewPrivate::_q_checkSceneItemCount()
{
    bool hasNewItems = hasNewGraphicsObjects(q->rootObject());

    if (hasNewItems) {
        qmlDesignDebugServer()->sceneItemCountChanged();
    }
}

static bool hasNewGraphicsObjectsRecur(QGraphicsObject *object,
                                  QSet<QGraphicsObject *> &newItems,
                                  const QSet<QGraphicsObject *> &previousItems)
{
    bool hasNew = false;

    newItems << object;

    foreach(QGraphicsItem *item, object->childItems()) {
        QGraphicsObject *gfxObject = item->toGraphicsObject();
        if (gfxObject) {
            newItems << gfxObject;

            hasNew = hasNewGraphicsObjectsRecur(gfxObject, newItems, previousItems) || hasNew;
            if (!previousItems.contains(gfxObject))
                hasNew = true;
        }
    }

    return hasNew;
}

bool QDeclarativeDesignViewPrivate::hasNewGraphicsObjects(QGraphicsObject *object)
{
    QSet<QGraphicsObject *> newItems;
    bool ret = hasNewGraphicsObjectsRecur(object, newItems, sceneGraphicsObjects);
    sceneGraphicsObjects = newItems;

    return ret;
}

587
588
void QDeclarativeDesignView::changeAnimationSpeed(qreal slowdownFactor)
{
589
    data->slowdownFactor = slowdownFactor;
590

591
592
    if (data->slowdownFactor != 0) {
        continueExecution(data->slowdownFactor);
593
594
595
596
597
598
599
600
601
    } else {
        pauseExecution();
    }
}

void QDeclarativeDesignView::continueExecution(qreal slowdownFactor)
{
    Q_ASSERT(slowdownFactor > 0);

602
    data->slowdownFactor = slowdownFactor;
603
    static const qreal animSpeedSnapDelta = 0.01f;
604
    bool useStandardSpeed = (qAbs(1.0f - data->slowdownFactor) < animSpeedSnapDelta);
605
606

    QUnifiedTimer *timer = QUnifiedTimer::instance();
607
    timer->setSlowdownFactor(data->slowdownFactor);
608
    timer->setSlowModeEnabled(!useStandardSpeed);
609
    data->executionPaused = false;
610

611
612
    emit executionStarted(data->slowdownFactor);
    qmlDesignDebugServer()->setAnimationSpeed(data->slowdownFactor);
613
614
615
616
617
}

void QDeclarativeDesignView::pauseExecution()
{
    QUnifiedTimer *timer = QUnifiedTimer::instance();
618
    timer->setSlowdownFactor(0);
619
    timer->setSlowModeEnabled(true);
620
    data->executionPaused = true;
621
622

    emit executionPaused();
623
    qmlDesignDebugServer()->setAnimationSpeed(0);
624
625
}

626
void QDeclarativeDesignViewPrivate::_q_applyChangesFromClient()
627
628
629
630
631
{

}


632
QList<QGraphicsItem*> QDeclarativeDesignViewPrivate::filterForSelection(QList<QGraphicsItem*> &itemlist) const
633
634
{
    foreach(QGraphicsItem *item, itemlist) {
635
        if (isEditorItem(item) || !subcomponentEditorTool->isChildOfContext(item))
636
            itemlist.removeOne(item);
637
638
639
640
641
    }

    return itemlist;
}

642
QList<QGraphicsItem*> QDeclarativeDesignViewPrivate::filterForCurrentContext(QList<QGraphicsItem*> &itemlist) const
643
644
645
{
    foreach(QGraphicsItem *item, itemlist) {

646
        if (isEditorItem(item) || !subcomponentEditorTool->isDirectChildOfContext(item)) {
647
648

            // if we're a child, but not directly, replace with the parent that is directly in context.
649
            if (QGraphicsItem *contextParent = subcomponentEditorTool->firstChildOfContext(item)) {
650
651
652
653
654
655
                if (contextParent != item) {
                    if (itemlist.contains(contextParent)) {
                        itemlist.removeOne(item);
                    } else {
                        itemlist.replace(itemlist.indexOf(item), contextParent);
                    }
656
657
                }
            } else {
658
                itemlist.removeOne(item);
659
            }
660
661
662
663
664
665
        }
    }

    return itemlist;
}

666
bool QDeclarativeDesignViewPrivate::isEditorItem(QGraphicsItem *item) const
667
668
669
670
671
{
    return (item->type() == Constants::EditorItemType
         || item->type() == Constants::ResizeHandleItemType
         || item->data(Constants::EditorItemDataKey).toBool());
}
672

673
void QDeclarativeDesignViewPrivate::_q_onStatusChanged(QDeclarativeView::Status status)
674
675
{
    if (status == QDeclarativeView::Ready) {
676
        if (q->rootObject()) {
677
            hasNewGraphicsObjects(q->rootObject());
678
679
            if (subcomponentEditorTool->contextIndex() != -1)
                subcomponentEditorTool->clear();
680
681
            subcomponentEditorTool->pushContext(q->rootObject());
            emit q->executionStarted(1.0f);
682

683
        }
684
        qmlDesignDebugServer()->reloaded();
685
686
687
    }
}

688
void QDeclarativeDesignViewPrivate::_q_onCurrentObjectsChanged(QList<QObject*> objects)
689
690
{
    QList<QGraphicsItem*> items;
691
    QList<QGraphicsObject*> gfxObjects;
692
693
    foreach(QObject *obj, objects) {
        QDeclarativeItem* declarativeItem = qobject_cast<QDeclarativeItem*>(obj);
694
        if (declarativeItem) {
695
            items << declarativeItem;
696
697
698
699
            QGraphicsObject *gfxObj = declarativeItem->toGraphicsObject();
            if (gfxObj)
                gfxObjects << gfxObj;
        }
700
    }
701
    setSelectedItemsForTools(items);
702
    clearHighlight();
703
    highlight(gfxObjects, QDeclarativeDesignViewPrivate::IgnoreContext);
704
705
}

706
707
708
709
710
QString QDeclarativeDesignView::idStringForObject(QObject *obj)
{
    return qmlDesignDebugServer()->idStringForObject(obj);
}

711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
// adjusts bounding boxes on edges of screen to be visible
QRectF QDeclarativeDesignView::adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace)
{
    int marginFromEdge = 1;
    QRectF boundingRect(boundingRectInSceneSpace);
    if (qAbs(boundingRect.left()) - 1 < 2) {
        boundingRect.setLeft(marginFromEdge);
    }

    if (boundingRect.right() >= rect().right() ) {
        boundingRect.setRight(rect().right() - marginFromEdge);
    }

    if (qAbs(boundingRect.top()) - 1 < 2) {
        boundingRect.setTop(marginFromEdge);
    }

    if (boundingRect.bottom() >= rect().bottom() ) {
        boundingRect.setBottom(rect().bottom() - marginFromEdge);
    }

    return boundingRect;
}

735
736
QToolBar *QDeclarativeDesignView::toolbar() const
{
737
    return data->toolbar;
738
739
}

740
void QDeclarativeDesignViewPrivate::createToolbar()
741
{
742
743
    toolbar = new QmlToolbar(q);
    QObject::connect(q, SIGNAL(selectedColorChanged(QColor)), toolbar, SLOT(setColorBoxColor(QColor)));
744

745
    QObject::connect(q, SIGNAL(designModeBehaviorChanged(bool)), toolbar, SLOT(setDesignModeBehavior(bool)));
746

747
748
749
750
751
752
753
    QObject::connect(toolbar, SIGNAL(designModeBehaviorChanged(bool)), q, SLOT(setDesignModeBehavior(bool)));
    QObject::connect(toolbar, SIGNAL(executionStarted()), q, SLOT(continueExecution()));
    QObject::connect(toolbar, SIGNAL(executionPaused()), q, SLOT(pauseExecution()));
    QObject::connect(toolbar, SIGNAL(colorPickerSelected()), q, SLOT(_q_changeToColorPickerTool()));
    QObject::connect(toolbar, SIGNAL(zoomToolSelected()), q, SLOT(_q_changeToZoomTool()));
    QObject::connect(toolbar, SIGNAL(selectToolSelected()), q, SLOT(_q_changeToSingleSelectTool()));
    QObject::connect(toolbar, SIGNAL(marqueeSelectToolSelected()), q, SLOT(_q_changeToMarqueeSelectTool()));
754

755
    QObject::connect(toolbar, SIGNAL(applyChangesFromQmlFileSelected()), q, SLOT(_q_applyChangesFromClient()));
756

757
758
    QObject::connect(q, SIGNAL(executionStarted(qreal)), toolbar, SLOT(startExecution()));
    QObject::connect(q, SIGNAL(executionPaused()), toolbar, SLOT(pauseExecution()));
759

760
    QObject::connect(q, SIGNAL(selectToolActivated()), toolbar, SLOT(activateSelectTool()));
761
762

    // disabled features
763
    //connect(d->m_toolbar, SIGNAL(applyChangesToQmlFileSelected()), SLOT(applyChangesToClient()));
764
765
    //connect(q, SIGNAL(resizeToolActivated()), d->m_toolbar, SLOT(activateSelectTool()));
    //connect(q, SIGNAL(moveToolActivated()),   d->m_toolbar, SLOT(activateSelectTool()));
766

767
768
769
    QObject::connect(q, SIGNAL(colorPickerActivated()), toolbar, SLOT(activateColorPicker()));
    QObject::connect(q, SIGNAL(zoomToolActivated()), toolbar, SLOT(activateZoom()));
    QObject::connect(q, SIGNAL(marqueeSelectToolActivated()), toolbar, SLOT(activateMarqueeSelectTool()));
770
771
}

772
773
774
775
776
777
void QDeclarativeDesignView::setDebugMode(bool isDebugMode)
{
    if (isDebugMode && !data->jsDebuggerAgent)
        data->jsDebuggerAgent = new JSDebuggerAgent(QDeclarativeEnginePrivate::getScriptEngine(engine()));
}

778
} //namespace QmlViewer
779
780

#include <moc_qdeclarativedesignview.cpp>