designmodewidget.cpp 22.1 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
{
    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;
106 107 108
    QString str;
    if (error.type() == RewriterView::Error::ParseError) {
        str = tr("%3 (%1:%2)").arg(QString::number(error.line()), QString::number(error.column()), error.description());
109
        m_goToError->show();
110
    }  else if (error.type() == RewriterView::Error::InternalError) {
111 112
        str = tr("Internal error (%1)").arg(error.description());
        m_goToError->hide();
113
    }
114 115 116 117 118 119 120

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

void DocumentWarningWidget::goToError()
{
121
    m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column());
122 123 124 125
    Core::EditorManager::instance()->ensureEditorManagerVisible();
}

// ---------- DesignModeWidget
Lasse Holmstedt's avatar
Lasse Holmstedt committed
126
DesignModeWidget::DesignModeWidget(QWidget *parent) :
127
    QWidget(parent),
128 129 130 131
    m_syncWithTextEdit(false),
    m_mainSplitter(0),
    m_leftSideBar(0),
    m_rightSideBar(0),
Kai Koehne's avatar
Kai Koehne committed
132
    m_initStatus(NotInitialized),
133
    m_warningWidget(0)
134 135 136 137 138 139 140 141 142 143 144 145 146
{
    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()));
147 148
    m_selectAllAction = new Utils::ParameterAction(tr("Select &All"), tr("Select All \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    connect(m_selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));
149 150 151 152 153 154 155 156
}

DesignModeWidget::~DesignModeWidget()
{
};

void DesignModeWidget::showEditor(Core::IEditor *editor)
{
Kai Koehne's avatar
Kai Koehne committed
157 158 159 160 161 162 163 164 165 166 167
    //
    // 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();
    }
168

169 170 171 172 173 174 175 176
    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);
177 178
        if (textEditor)
            m_fakeToolBar->addEditor(textEditor);
179 180 181 182 183
    }

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

184 185 186 187 188 189
    if (textEdit)
        m_currentTextEdit = textEdit;

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

191
    if (textEdit && textEditor && fileName.endsWith(QLatin1String(".qml"))) {
192
        if (m_documentHash.contains(textEdit)) {
193
            document = m_documentHash.value(textEdit).data();
194
        } else {
195 196 197 198 199 200 201 202
            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());

203 204
            newDocument->setFileName(fileName);

205
            document = newDocument;          
206

207
            m_documentHash.insert(textEdit, document);
208 209
        }
    }
210
    setCurrentDocument(document);
Kai Koehne's avatar
Kai Koehne committed
211 212

    m_initStatus = Initialized;
213 214 215 216 217 218
}

void DesignModeWidget::closeEditors(QList<Core::IEditor*> editors)
{
    foreach (Core::IEditor* editor, editors) {
        if (QPlainTextEdit *textEdit = qobject_cast<QPlainTextEdit*>(editor->widget())) {
219 220
            if (m_currentTextEdit.data() == textEdit) {
                setCurrentDocument(0);
221 222 223 224
            }
            if (m_documentHash.contains(textEdit)) {
                if (debug)
                    qDebug() << Q_FUNC_INFO << editor->file()->fileName();
225
                DesignDocumentController *document = m_documentHash.take(textEdit).data();
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 255 256 257 258 259 260 261
                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;
}

262 263 264 265 266
QAction *DesignModeWidget::selectAllAction() const
{
    return m_selectAllAction;
}

267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
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();
}

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

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

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

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

void DesignModeWidget::copySelected()
{
318 319
    if (m_currentDesignDocumentController)
        m_currentDesignDocumentController->copySelected();
320 321 322 323
}

void DesignModeWidget::paste()
{
324 325
    if (m_currentDesignDocumentController)
        m_currentDesignDocumentController->paste();
326 327
}

328 329
void DesignModeWidget::selectAll()
{
330 331 332 333 334 335
    if (m_currentDesignDocumentController)
        m_currentDesignDocumentController->selectAll();
}

void DesignModeWidget::closeCurrentEditor()
{
336 337
}

338 339 340
void DesignModeWidget::undoAvailable(bool isAvailable)
{
    DesignDocumentController *documentController = qobject_cast<DesignDocumentController*>(sender());
341 342
    if (m_currentDesignDocumentController &&
        m_currentDesignDocumentController.data() == documentController) {
343 344 345 346 347 348 349
        m_undoAction->setEnabled(isAvailable);
    }
}

void DesignModeWidget::redoAvailable(bool isAvailable)
{
    DesignDocumentController *documentController = qobject_cast<DesignDocumentController*>(sender());
350 351
    if (m_currentDesignDocumentController &&
        m_currentDesignDocumentController.data() == documentController) {
352 353 354 355
        m_redoAction->setEnabled(isAvailable);
    }
}

356 357

void DesignModeWidget::enable()
358 359
{
    if (debug)
360 361 362 363 364 365 366 367
        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;
}
368

369 370 371 372 373 374 375 376 377 378 379 380 381 382
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;
}
383

384 385 386 387 388 389 390 391 392
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);
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 420 421 422 423 424 425 426
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>)));
427 428

    } else {
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 460 461 462 463 464 465 466
        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
467 468 469 470 471 472
    if (currentDesignDocumentController()) {
        disconnect(currentDesignDocumentController(), SIGNAL(undoAvailable(bool)),
            this, SLOT(undoAvailable(bool)));
        disconnect(currentDesignDocumentController(), SIGNAL(redoAvailable(bool)),
            this, SLOT(redoAvailable(bool)));
    }
473 474 475

    m_currentDesignDocumentController = newDesignDocumentController;

476 477
    if (currentDesignDocumentController()) {
        connect(currentDesignDocumentController(), SIGNAL(undoAvailable(bool)),
478
            this, SLOT(undoAvailable(bool)));
479
        connect(currentDesignDocumentController(), SIGNAL(redoAvailable(bool)),
480
            this, SLOT(redoAvailable(bool)));
481
    }
482 483 484 485 486 487 488 489

    if (m_currentDesignDocumentController) {

        setAutoSynchronization(true);
        m_undoAction->setEnabled(m_currentDesignDocumentController->isUndoAvailable());
        m_redoAction->setEnabled(m_currentDesignDocumentController->isRedoAvailable());
    } else {
        //detach all views
490 491 492 493 494
        m_undoAction->setEnabled(false);
        m_redoAction->setEnabled(false);
    }
}

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 524 525 526 527 528 529 530
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);

531
            QString labelStyle = QLatin1String("QLabel { background-color: #4f4f4f; }");
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546

            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);

547
    //m_designToolBar = new QToolBar;
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 659 660 661 662 663 664 665
    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;
}


666 667
QString DesignModeWidget::contextHelpId() const
{
668 669
    if (m_currentDesignDocumentController)
        return m_currentDesignDocumentController->contextHelpId();
670 671 672
    return QString();
}

673 674
} // namespace Internal
} // namespace Designer