designmodewidget.cpp 21.8 KB
Newer Older
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
**
** 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.
**
**************************************************************************/

#include "designmodewidget.h"
#include "qmldesignerconstants.h"

#include <model.h>
#include <rewriterview.h>
35
#include <formeditorwidget.h>
36
37
38
39
40
41
42

#include <coreplugin/icore.h>
#include <coreplugin/minisplitter.h>
#include <coreplugin/sidebar.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/openeditorsmodel.h>
#include <coreplugin/editormanager/ieditor.h>
43
#include <coreplugin/editortoolbar.h>
44
45
#include <coreplugin/inavigationwidgetfactory.h>
#include <extensionsystem/pluginmanager.h>
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

#include <utils/parameteraction.h>
#include <utils/qtcassert.h>

#include <QtCore/QSettings>
#include <QtCore/QEvent>
#include <QtCore/QDir>
#include <QtGui/QApplication>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QScrollArea>
#include <QtGui/QTabWidget>
#include <QtGui/QToolButton>
#include <QtGui/QMenu>
#include <QtGui/QClipboard>
#include <QtGui/QLabel>
62
#include <QtGui/QProgressDialog>
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

using Core::MiniSplitter;
using Core::IEditor;
using Core::EditorManager;

using namespace QmlDesigner;

Q_DECLARE_METATYPE(Core::IEditor*)

enum {
    debug = false
};

namespace QmlDesigner {
namespace Internal {

79
DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) :
80
81
82
        QFrame(parent),
        m_errorMessage(new QLabel("Placeholder", this)),
        m_goToError(new QLabel(this)),
83
        m_designModeWidget(parent)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
    setFrameStyle(QFrame::Panel | QFrame::Raised);
    setLineWidth(1);
    setForegroundRole(QPalette::ToolTipText);
    setBackgroundRole(QPalette::ToolTipBase);
    setAutoFillBackground(true);

    m_errorMessage->setForegroundRole(QPalette::ToolTipText);
    m_goToError->setText(tr("<a href=\"goToError\">Go to error</a>"));
    m_goToError->setForegroundRole(QPalette::Link);
    connect(m_goToError, SIGNAL(linkActivated(QString)), this, SLOT(goToError()));

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setMargin(20);
    layout->setSpacing(5);
    layout->addWidget(m_errorMessage);
    layout->addWidget(m_goToError, 1, Qt::AlignRight);
}

void DocumentWarningWidget::setError(const RewriterView::Error &error)
{
    m_error = error;
    QString str = tr("%3 (%1:%2)").arg(QString::number(error.line()), QString::number(error.column()), error.description());

    m_errorMessage->setText(str);
    resize(layout()->totalSizeHint());
}

void DocumentWarningWidget::goToError()
{
114
    m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column());
115
116
117
118
    Core::EditorManager::instance()->ensureEditorManagerVisible();
}

// ---------- DesignModeWidget
Lasse Holmstedt's avatar
Lasse Holmstedt committed
119
DesignModeWidget::DesignModeWidget(QWidget *parent) :
120
    QWidget(parent),
121
122
123
124
    m_syncWithTextEdit(false),
    m_mainSplitter(0),
    m_leftSideBar(0),
    m_rightSideBar(0),
Kai Koehne's avatar
Kai Koehne committed
125
    m_initStatus(NotInitialized),
126
    m_warningWidget(0)
127
128
129
130
131
132
133
134
135
136
137
138
139
{
    m_undoAction = new QAction(tr("&Undo"), this);
    connect(m_undoAction, SIGNAL(triggered()), this, SLOT(undo()));
    m_redoAction = new QAction(tr("&Redo"), this);
    connect(m_redoAction, SIGNAL(triggered()), this, SLOT(redo()));
    m_deleteAction = new Utils::ParameterAction(tr("Delete"), tr("Delete \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deleteSelected()));
    m_cutAction = new Utils::ParameterAction(tr("Cu&t"), tr("Cut \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    connect(m_cutAction, SIGNAL(triggered()), this, SLOT(cutSelected()));
    m_copyAction = new Utils::ParameterAction(tr("&Copy"), tr("Copy \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    connect(m_copyAction, SIGNAL(triggered()), this, SLOT(copySelected()));
    m_pasteAction = new Utils::ParameterAction(tr("&Paste"), tr("Paste \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    connect(m_pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
140
141
    m_selectAllAction = new Utils::ParameterAction(tr("Select &All"), tr("Select All \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    connect(m_selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));
142
143
144
145
146
147
148
149
}

DesignModeWidget::~DesignModeWidget()
{
};

void DesignModeWidget::showEditor(Core::IEditor *editor)
{
Kai Koehne's avatar
Kai Koehne committed
150
151
152
153
154
155
156
157
158
159
160
    //
    // Prevent recursive calls to function by explicitly managing initialization status
    // (QApplication::processEvents is called explicitly at a number of places)
    //
    if (m_initStatus == Initializing)
        return;

    if (m_initStatus == NotInitialized) {
        m_initStatus = Initializing;
        setup();
    }
161

162
163
164
165
166
167
168
169
    QString fileName;
    QPlainTextEdit *textEdit = 0;
    TextEditor::ITextEditor *textEditor = 0;

    if (editor) {
        fileName = editor->file()->fileName();
        textEdit = qobject_cast<QPlainTextEdit*>(editor->widget());
        textEditor = qobject_cast<TextEditor::ITextEditor*>(editor);
170
171
        if (textEditor)
            m_fakeToolBar->addEditor(textEditor);
172
173
174
175
176
    }

    if (debug)
        qDebug() << Q_FUNC_INFO << fileName;

177
178
179
180
181
182
    if (textEdit)
        m_currentTextEdit = textEdit;

    if (textEditor)
        m_textEditor = textEditor;
    DesignDocumentController *document = 0;
183

184
    if (textEdit && textEditor && fileName.endsWith(QLatin1String(".qml"))) {
185
        if (m_documentHash.contains(textEdit)) {
186
            document = m_documentHash.value(textEdit).data();
187
        } else {
188
189
190
191
192
193
194
195
            DesignDocumentController *newDocument = new DesignDocumentController(this);

            newDocument->setAllPropertiesBox(m_allPropertiesBox.data());
            newDocument->setNavigator(m_navigator.data());
            newDocument->setStatesEditorWidget(m_statesEditorWidget.data());
            newDocument->setItemLibrary(m_itemLibrary.data());
            newDocument->setFormEditorView(m_formEditorView.data());

196
197
            newDocument->setFileName(fileName);

198
            document = newDocument;          
199

200
            m_documentHash.insert(textEdit, document);
201
202
        }
    }
203
    setCurrentDocument(document);
Kai Koehne's avatar
Kai Koehne committed
204
205

    m_initStatus = Initialized;
206
207
208
209
210
211
}

void DesignModeWidget::closeEditors(QList<Core::IEditor*> editors)
{
    foreach (Core::IEditor* editor, editors) {
        if (QPlainTextEdit *textEdit = qobject_cast<QPlainTextEdit*>(editor->widget())) {
212
213
            if (m_currentTextEdit.data() == textEdit) {
                setCurrentDocument(0);
214
215
216
217
            }
            if (m_documentHash.contains(textEdit)) {
                if (debug)
                    qDebug() << Q_FUNC_INFO << editor->file()->fileName();
218
                DesignDocumentController *document = m_documentHash.take(textEdit).data();
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
                delete document;
            }
        }
    }
}

QAction *DesignModeWidget::undoAction() const
{
    return m_undoAction;
}

QAction *DesignModeWidget::redoAction() const
{
    return m_redoAction;
}

QAction *DesignModeWidget::deleteAction() const
{
    return m_deleteAction;
}

QAction *DesignModeWidget::cutAction() const
{
    return m_cutAction;
}

QAction *DesignModeWidget::copyAction() const
{
    return m_copyAction;
}

QAction *DesignModeWidget::pasteAction() const
{
    return m_pasteAction;
}

255
256
257
258
259
QAction *DesignModeWidget::selectAllAction() const
{
    return m_selectAllAction;
}

260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
void DesignModeWidget::readSettings()
{
    QSettings *settings = Core::ICore::instance()->settings();

    settings->beginGroup("Bauhaus");
    m_leftSideBar->readSettings(settings, QLatin1String("LeftSideBar"));
    m_rightSideBar->readSettings(settings, QLatin1String("RightSideBar"));
    if (settings->contains("MainSplitter")) {
        const QByteArray splitterState = settings->value("MainSplitter").toByteArray();
        m_mainSplitter->restoreState(splitterState);
    }
    settings->endGroup();
}

void DesignModeWidget::saveSettings()
{
    QSettings *settings = Core::ICore::instance()->settings();

    settings->beginGroup("Bauhaus");
    m_leftSideBar->saveSettings(settings, QLatin1String("LeftSideBar"));
    m_rightSideBar->saveSettings(settings, QLatin1String("RightSideBar"));
    settings->setValue("MainSplitter", m_mainSplitter->saveState());
    settings->endGroup();
}

285
286
void DesignModeWidget::undo()
{
287
288
    if (m_currentDesignDocumentController)
        m_currentDesignDocumentController->undo();
289
290
291
292
}

void DesignModeWidget::redo()
{
293
294
    if (m_currentDesignDocumentController)
        m_currentDesignDocumentController->redo();
295
296
297
298
}

void DesignModeWidget::deleteSelected()
{
299
300
    if (m_currentDesignDocumentController)
        m_currentDesignDocumentController->deleteSelected();
301
302
303
304
}

void DesignModeWidget::cutSelected()
{
305
306
    if (m_currentDesignDocumentController)
        m_currentDesignDocumentController->cutSelected();
307
308
309
310
}

void DesignModeWidget::copySelected()
{
311
312
    if (m_currentDesignDocumentController)
        m_currentDesignDocumentController->copySelected();
313
314
315
316
}

void DesignModeWidget::paste()
{
317
318
    if (m_currentDesignDocumentController)
        m_currentDesignDocumentController->paste();
319
320
}

321
322
void DesignModeWidget::selectAll()
{
323
324
325
326
327
328
    if (m_currentDesignDocumentController)
        m_currentDesignDocumentController->selectAll();
}

void DesignModeWidget::closeCurrentEditor()
{
329
330
}

331
332
333
void DesignModeWidget::undoAvailable(bool isAvailable)
{
    DesignDocumentController *documentController = qobject_cast<DesignDocumentController*>(sender());
334
335
    if (m_currentDesignDocumentController &&
        m_currentDesignDocumentController.data() == documentController) {
336
337
338
339
340
341
342
        m_undoAction->setEnabled(isAvailable);
    }
}

void DesignModeWidget::redoAvailable(bool isAvailable)
{
    DesignDocumentController *documentController = qobject_cast<DesignDocumentController*>(sender());
343
344
    if (m_currentDesignDocumentController &&
        m_currentDesignDocumentController.data() == documentController) {
345
346
347
348
        m_redoAction->setEnabled(isAvailable);
    }
}

349
350

void DesignModeWidget::enable()
351
352
{
    if (debug)
353
354
355
356
357
358
359
360
        qDebug() << Q_FUNC_INFO;
    m_warningWidget->setVisible(false);
    m_formEditorView->widget()->setEnabled(true);
    m_statesEditorWidget->setEnabled(true);
    m_leftSideBar->setEnabled(true);
    m_rightSideBar->setEnabled(true);
    m_isDisabled = false;
}
361

362
363
364
365
366
367
368
369
370
371
372
373
374
375
void DesignModeWidget::disable(const QList<RewriterView::Error> &errors)
{
    if (debug)
        qDebug() << Q_FUNC_INFO;
    Q_ASSERT(!errors.isEmpty());
    m_warningWidget->setError(errors.first());
    m_warningWidget->setVisible(true);
    m_warningWidget->move(width() / 2, height() / 2);
    m_formEditorView->widget()->setEnabled(false);
    m_statesEditorWidget->setEnabled(false);
    m_leftSideBar->setEnabled(false);
    m_rightSideBar->setEnabled(false);
    m_isDisabled = true;
}
376

377
378
379
380
381
382
383
384
385
void DesignModeWidget::updateErrorStatus(const QList<RewriterView::Error> &errors)
{
    if (debug)
        qDebug() << Q_FUNC_INFO << errors.count();

    if (m_isDisabled && errors.isEmpty()) {
        enable();
    } else if (!errors.isEmpty()) {
        disable(errors);
386
    }
387
}
388

389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
void DesignModeWidget::setAutoSynchronization(bool sync)
{
    if (debug)
        qDebug() << Q_FUNC_INFO << sync;

    m_currentDesignDocumentController->blockModelSync(!sync);

    if (sync) {
        // text editor -> visual editor
        if (!m_currentDesignDocumentController->model()) {
            m_currentDesignDocumentController->loadMaster(m_currentTextEdit.data());
        } else {
            m_currentDesignDocumentController->loadCurrentModel();
        }

        QList<RewriterView::Error> errors = m_currentDesignDocumentController->qmlErrors();
        if (errors.isEmpty()) {
            // set selection to text cursor
            RewriterView *rewriter = m_currentDesignDocumentController->rewriterView();
            const int cursorPos = m_currentTextEdit->textCursor().position();
            ModelNode node = nodeForPosition(cursorPos);
            if (node.isValid()) {
                rewriter->setSelectedModelNodes(QList<ModelNode>() << node);
            }
            enable();
        } else {
            disable(errors);
        }

        connect(m_currentDesignDocumentController.data(), SIGNAL(qmlErrorsChanged(QList<RewriterView::Error>)),
                this, SLOT(updateErrorStatus(QList<RewriterView::Error>)));
420
421

    } else {
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
        if (m_currentDesignDocumentController->model() && m_currentDesignDocumentController->qmlErrors().isEmpty()) {
            RewriterView *rewriter = m_currentDesignDocumentController->rewriterView();
            // visual editor -> text editor
            ModelNode selectedNode;
            if (!rewriter->selectedModelNodes().isEmpty())
                selectedNode = rewriter->selectedModelNodes().first();

            if (selectedNode.isValid()) {
                const int nodeOffset = rewriter->nodeOffset(selectedNode);
                if (nodeOffset > 0) {
                    const ModelNode currentSelectedNode
                            = nodeForPosition(m_currentTextEdit->textCursor().position());
                    if (currentSelectedNode != selectedNode) {
                        int line, column;
                        m_textEditor->convertPosition(nodeOffset, &line, &column);
                        m_textEditor->gotoLine(line, column);
                    }
                }
            }
        }

        disconnect(m_currentDesignDocumentController.data(), SIGNAL(qmlErrorsChanged(QList<RewriterView::Error>)),
                this, SLOT(updateErrorStatus(QList<RewriterView::Error>)));
    }
}

void DesignModeWidget::setCurrentDocument(DesignDocumentController *newDesignDocumentController)
{
    if (debug)
        qDebug() << Q_FUNC_INFO << newDesignDocumentController;

    if (m_currentDesignDocumentController.data() == newDesignDocumentController)
        return;
    if (m_currentDesignDocumentController) {
        setAutoSynchronization(false);
        saveSettings();
    }

Thomas Hartmann's avatar
Thomas Hartmann committed
460
461
462
463
464
465
    if (currentDesignDocumentController()) {
        disconnect(currentDesignDocumentController(), SIGNAL(undoAvailable(bool)),
            this, SLOT(undoAvailable(bool)));
        disconnect(currentDesignDocumentController(), SIGNAL(redoAvailable(bool)),
            this, SLOT(redoAvailable(bool)));
    }
466
467
468

    m_currentDesignDocumentController = newDesignDocumentController;

469
470
    if (currentDesignDocumentController()) {
        connect(currentDesignDocumentController(), SIGNAL(undoAvailable(bool)),
471
            this, SLOT(undoAvailable(bool)));
472
        connect(currentDesignDocumentController(), SIGNAL(redoAvailable(bool)),
473
            this, SLOT(redoAvailable(bool)));
474
    }
475
476
477
478
479
480
481
482

    if (m_currentDesignDocumentController) {

        setAutoSynchronization(true);
        m_undoAction->setEnabled(m_currentDesignDocumentController->isUndoAvailable());
        m_redoAction->setEnabled(m_currentDesignDocumentController->isRedoAvailable());
    } else {
        //detach all views
483
484
485
486
487
        m_undoAction->setEnabled(false);
        m_redoAction->setEnabled(false);
    }
}

488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
void DesignModeWidget::setup()
{
    QList<Core::INavigationWidgetFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<Core::INavigationWidgetFactory>();

    QWidget *openDocumentsWidget = 0;
    QWidget *projectsExplorer = 0;
    QWidget *fileSystemExplorer = 0;


    foreach(Core::INavigationWidgetFactory *factory, factories)
    {
        Core::NavigationView navigationView;
        navigationView.widget = 0;
        if (factory->displayName() == QLatin1String("Projects")) {
            navigationView = factory->createWidget();
            projectsExplorer = navigationView.widget;
            projectsExplorer->setWindowTitle(tr("Projects"));
        }
        if (factory->displayName() == QLatin1String("File System")) {
            navigationView = factory->createWidget();
            fileSystemExplorer = navigationView.widget;
            fileSystemExplorer->setWindowTitle(tr("File System"));
        }
        if (factory->displayName() == QLatin1String("Open Documents")) {
            navigationView = factory->createWidget();
            openDocumentsWidget = navigationView.widget;
            openDocumentsWidget->setWindowTitle(tr("Open Documents"));
        }

        if (navigationView.widget)
        {
            QFile file(":/qmldesigner/stylesheet.css");
            file.open(QFile::ReadOnly);
            QFile file2(":/qmldesigner/scrollbar.css");
            file2.open(QFile::ReadOnly);

524
            QString labelStyle = QLatin1String("QLabel { background-color: #4f4f4f; }");
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539

            QString styleSheet = file.readAll() + file2.readAll() + labelStyle;
            navigationView.widget->setStyleSheet(styleSheet);
        }
    }

    m_navigator = new NavigatorView(this);

    m_allPropertiesBox = new AllPropertiesBox(this);
    m_statesEditorWidget = new StatesEditorWidget(this);
    
    m_formEditorView = new FormEditorView(this);

    m_itemLibrary = new ItemLibrary(this);

540
    //m_designToolBar = new QToolBar;
541
542
543
544
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
    m_fakeToolBar = Core::EditorManager::createToolBar(this);


    m_mainSplitter = new MiniSplitter(this);
    m_mainSplitter->setObjectName("mainSplitter");

    // warning frame should be not in layout, but still child of the widget
    m_warningWidget = new DocumentWarningWidget(this);
    m_warningWidget->setVisible(false);

    // Left area:

    Core::SideBarItem *navigatorItem = new Core::SideBarItem(m_navigator->widget());
    Core::SideBarItem *libraryItem = new Core::SideBarItem(m_itemLibrary.data());
    Core::SideBarItem *propertiesItem = new Core::SideBarItem(m_allPropertiesBox.data());


    QList<Core::SideBarItem*> leftSideBarItems, rightSideBarItems;
    leftSideBarItems << navigatorItem << libraryItem;
    rightSideBarItems << propertiesItem;

    if (projectsExplorer) {
        Core::SideBarItem *projectExplorerItem = new Core::SideBarItem(projectsExplorer);
        rightSideBarItems << projectExplorerItem;
    }

    if (fileSystemExplorer) {
        Core::SideBarItem *fileSystemExplorerItem = new Core::SideBarItem(fileSystemExplorer);
        rightSideBarItems << fileSystemExplorerItem;
    }

     if (openDocumentsWidget) {
        Core::SideBarItem *openDocumentsItem = new Core::SideBarItem(openDocumentsWidget);
        rightSideBarItems << openDocumentsItem;
    }

    m_leftSideBar = new Core::SideBar(leftSideBarItems, QList<Core::SideBarItem*>() << navigatorItem << libraryItem);
    m_rightSideBar = new Core::SideBar(rightSideBarItems, QList<Core::SideBarItem*>() << propertiesItem);

    m_fakeToolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
    //m_fakeToolBar->addEditor(textEditor()); ### what does this mean?
    m_fakeToolBar->setNavigationVisible(false);

    connect(m_fakeToolBar, SIGNAL(closeClicked()), this, SLOT(closeCurrentEditor()));

    // right area:
    QWidget *centerWidget = new QWidget;
    {
        QVBoxLayout *rightLayout = new QVBoxLayout(centerWidget);
        rightLayout->setMargin(0);
        rightLayout->setSpacing(0);
        rightLayout->addWidget(m_fakeToolBar);
        //### we now own these here
        rightLayout->addWidget(m_statesEditorWidget.data());
        rightLayout->addWidget(m_formEditorView->widget());
    }

    // m_mainSplitter area:
    m_mainSplitter->addWidget(m_leftSideBar);
    m_mainSplitter->addWidget(centerWidget);
    m_mainSplitter->addWidget(m_rightSideBar);

    // Finishing touches:
    m_mainSplitter->setOpaqueResize(false);
    m_mainSplitter->setStretchFactor(1, 1);
    m_mainSplitter->setSizes(QList<int>() << 150 << 300 << 150);

    QLayout *mainLayout = new QBoxLayout(QBoxLayout::RightToLeft, this);
    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);
    mainLayout->addWidget(m_mainSplitter);

    m_warningWidget->setVisible(false);
    m_statesEditorWidget->setEnabled(true);
    m_leftSideBar->setEnabled(true);
    m_rightSideBar->setEnabled(true);

    readSettings();

    show();
    QApplication::processEvents();
}

void DesignModeWidget::resizeEvent(QResizeEvent *event)
{
    if (m_warningWidget)
        m_warningWidget->move(QPoint(event->size().width() / 2, event->size().height() / 2));
    QWidget::resizeEvent(event);
}


bool DesignModeWidget::isInNodeDefinition(int nodeOffset, int nodeLength, int cursorPos) const {
    return (nodeOffset <= cursorPos) && (nodeOffset + nodeLength > cursorPos);
}


ModelNode DesignModeWidget::nodeForPosition(int cursorPos) const
{
    RewriterView *rewriter = m_currentDesignDocumentController->rewriterView();
    QList<ModelNode> nodes = rewriter->allModelNodes();

    ModelNode bestNode;
    int bestNodeOffset = -1;

    foreach (const ModelNode &node, nodes) {
        const int nodeOffset = rewriter->nodeOffset(node);
        const int nodeLength = rewriter->nodeLength(node);
        if (isInNodeDefinition(nodeOffset, nodeLength, cursorPos)
            && (nodeOffset > bestNodeOffset)) {
            bestNode = node;
            bestNodeOffset = nodeOffset;
        }
    }

    return bestNode;
}


659
660
QString DesignModeWidget::contextHelpId() const
{
661
662
    if (m_currentDesignDocumentController)
        return m_currentDesignDocumentController->contextHelpId();
663
664
665
    return QString();
}

666
667
} // namespace Internal
} // namespace Designer