designmodewidget.cpp 20.9 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
18 19 20 21 22
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
25 26

#include "designmodewidget.h"
27
#include "styledoutputpaneplaceholder.h"
Marco Bubke's avatar
Marco Bubke committed
28
#include "qmldesignerplugin.h"
29
#include "crumblebar.h"
30 31

#include <rewriterview.h>
32
#include <nodeinstanceview.h>
Marco Bubke's avatar
Marco Bubke committed
33
#include <itemlibrarywidget.h>
34

35
#include <coreplugin/coreconstants.h>
36
#include <coreplugin/designmode.h>
37
#include <coreplugin/modemanager.h>
38 39 40
#include <coreplugin/icore.h>
#include <coreplugin/minisplitter.h>
#include <coreplugin/sidebar.h>
41
#include <coreplugin/editortoolbar.h>
42
#include <coreplugin/editormanager/editormanager.h>
43
#include <coreplugin/idocument.h>
44 45
#include <coreplugin/inavigationwidgetfactory.h>
#include <extensionsystem/pluginmanager.h>
46

47
#include <utils/fileutils.h>
48

49 50 51 52
#include <QSettings>
#include <QVBoxLayout>
#include <QToolButton>
#include <QLabel>
53
#include <QTabWidget>
54
#include <QToolBar>
55 56 57 58 59 60 61 62 63 64 65

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

using namespace QmlDesigner;

enum {
    debug = false
};

66 67 68
const char SB_PROJECTS[] = "Projects";
const char SB_FILESYSTEM[] = "FileSystem";
const char SB_OPENDOCUMENTS[] = "OpenDocuments";
69

70 71 72
namespace QmlDesigner {
namespace Internal {

73
DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) :
74
        Utils::FakeToolTip(parent),
75
        m_errorMessage(new QLabel(tr("Placeholder"), this)),
76
        m_goToError(new QLabel(this)),
77
        m_designModeWidget(parent)
78
{
79
    setWindowFlags(Qt::Widget); //We only want the visual style from a ToolTip
80 81 82 83 84 85 86
    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);
87 88 89 90
    connect(m_goToError, &QLabel::linkActivated, this, [=]() {
        m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column() - 1);
        Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
    });
91 92 93 94 95 96 97 98

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

99
void DocumentWarningWidget::setError(const RewriterError &error)
100 101
{
    m_error = error;
102
    QString str;
103
    if (error.type() == RewriterError::ParseError) {
104
        str = tr("%3 (%1:%2)").arg(QString::number(error.line()), QString::number(error.column()), error.description());
105
        m_goToError->show();
106
    }  else if (error.type() == RewriterError::InternalError) {
107 108
        str = tr("Internal error (%1)").arg(error.description());
        m_goToError->hide();
109
    }
110

111 112
    str.prepend(tr("Cannot open this QML document because of an error in the QML file:\n\n"));

113 114 115 116
    m_errorMessage->setText(str);
    resize(layout()->totalSizeHint());
}

117 118 119
class ItemLibrarySideBarItem : public Core::SideBarItem
{
public:
Marco Bubke's avatar
Marco Bubke committed
120
    explicit ItemLibrarySideBarItem(QWidget *widget, const QString &id);
121 122 123 124 125
    virtual ~ItemLibrarySideBarItem();

    virtual QList<QToolButton *> createToolBarWidgets();
};

Marco Bubke's avatar
Marco Bubke committed
126
ItemLibrarySideBarItem::ItemLibrarySideBarItem(QWidget *widget, const QString &id) : Core::SideBarItem(widget, id) {}
127 128 129 130 131 132 133 134 135 136 137

ItemLibrarySideBarItem::~ItemLibrarySideBarItem()
{

}

QList<QToolButton *> ItemLibrarySideBarItem::createToolBarWidgets()
{
    return qobject_cast<ItemLibraryWidget*>(widget())->createToolBarWidgets();
}

138
class DesignerSideBarItem : public Core::SideBarItem
139 140
{
public:
141 142
    explicit DesignerSideBarItem(QWidget *widget, WidgetInfo::ToolBarWidgetFactoryInterface *createToolBarWidgets, const QString &id);
    virtual ~DesignerSideBarItem();
143 144 145

    virtual QList<QToolButton *> createToolBarWidgets();

146 147 148 149
private:
    WidgetInfo::ToolBarWidgetFactoryInterface *m_toolBarWidgetFactory;

};
150

151 152
DesignerSideBarItem::DesignerSideBarItem(QWidget *widget, WidgetInfo::ToolBarWidgetFactoryInterface *toolBarWidgetFactory, const QString &id)
    : Core::SideBarItem(widget, id) , m_toolBarWidgetFactory(toolBarWidgetFactory)
153
{
154
}
155

156 157 158
DesignerSideBarItem::~DesignerSideBarItem()
{
    delete m_toolBarWidgetFactory;
159 160
}

161
QList<QToolButton *> DesignerSideBarItem::createToolBarWidgets()
162
{
163 164 165 166
    if (m_toolBarWidgetFactory)
        return m_toolBarWidgetFactory->createToolBarWidgets();

    return QList<QToolButton *>();
167 168
}

169
// ---------- DesignModeWidget
Lasse Holmstedt's avatar
Lasse Holmstedt committed
170
DesignModeWidget::DesignModeWidget(QWidget *parent) :
171
    QWidget(parent),
172
    m_mainSplitter(0),
173
    m_toolBar(new Core::EditorToolBar(this)),
174
    m_crumbleBar(new CrumbleBar(this)),
175 176
    m_isDisabled(false),
    m_showSidebars(true),
Kai Koehne's avatar
Kai Koehne committed
177
    m_initStatus(NotInitialized),
178 179 180
    m_warningWidget(0),
    m_navigatorHistoryCounter(-1),
    m_keepNavigatorHistory(false)
181
{
182
    QObject::connect(viewManager().nodeInstanceView(), SIGNAL(qmlPuppetCrashed()), this, SLOT(showQmlPuppetCrashedError()));
183 184
}

185 186
DesignModeWidget::~DesignModeWidget()
{
187 188 189 190 191 192 193
    m_leftSideBar.reset();
    m_rightSideBar.reset();

    foreach (QPointer<QWidget> widget, m_viewWidgets) {
        if (widget)
            widget.clear();
    }
194 195
}

196 197
void DesignModeWidget::restoreDefaultView()
{
hjk's avatar
hjk committed
198
    QSettings *settings = Core::ICore::settings();
199 200 201 202 203 204 205 206
    m_leftSideBar->closeAllWidgets();
    m_rightSideBar->closeAllWidgets();
    m_leftSideBar->readSettings(settings,  "none.LeftSideBar");
    m_rightSideBar->readSettings(settings, "none.RightSideBar");
    m_leftSideBar->show();
    m_rightSideBar->show();
}

207 208 209 210 211 212 213 214 215 216 217 218
void DesignModeWidget::toggleLeftSidebar()
{
    if (m_leftSideBar)
        m_leftSideBar->setVisible(!m_leftSideBar->isVisible());
}

void DesignModeWidget::toggleRightSidebar()
{
    if (m_rightSideBar)
        m_rightSideBar->setVisible(!m_rightSideBar->isVisible());
}

219 220 221 222 223 224 225 226 227 228 229
void DesignModeWidget::toggleSidebars()
{
    if (m_initStatus == Initializing)
        return;

    m_showSidebars = !m_showSidebars;

    if (m_leftSideBar)
        m_leftSideBar->setVisible(m_showSidebars);
    if (m_rightSideBar)
        m_rightSideBar->setVisible(m_showSidebars);
230 231
    if (m_topSideBar)
        m_topSideBar->setVisible(m_showSidebars);
232
}
233

234 235
void DesignModeWidget::readSettings()
{
hjk's avatar
hjk committed
236
    QSettings *settings = Core::ICore::settings();
237 238

    settings->beginGroup("Bauhaus");
239 240
    m_leftSideBar->readSettings(settings, QStringLiteral("LeftSideBar"));
    m_rightSideBar->readSettings(settings, QStringLiteral("RightSideBar"));
241 242 243
    if (settings->contains("MainSplitter")) {
        const QByteArray splitterState = settings->value("MainSplitter").toByteArray();
        m_mainSplitter->restoreState(splitterState);
244
        m_mainSplitter->setOpaqueResize(); // force opaque resize since it used to be off
245 246 247 248 249 250
    }
    settings->endGroup();
}

void DesignModeWidget::saveSettings()
{
hjk's avatar
hjk committed
251
    QSettings *settings = Core::ICore::settings();
252 253

    settings->beginGroup("Bauhaus");
254 255
    m_leftSideBar->saveSettings(settings, QStringLiteral("LeftSideBar"));
    m_rightSideBar->saveSettings(settings, QStringLiteral("RightSideBar"));
256 257 258 259
    settings->setValue("MainSplitter", m_mainSplitter->saveState());
    settings->endGroup();
}

Marco Bubke's avatar
Marco Bubke committed
260
void DesignModeWidget::enableWidgets()
261 262
{
    if (debug)
263 264
        qDebug() << Q_FUNC_INFO;
    m_warningWidget->setVisible(false);
265
    viewManager().enableWidgets();
266 267 268 269
    m_leftSideBar->setEnabled(true);
    m_rightSideBar->setEnabled(true);
    m_isDisabled = false;
}
270

Marco Bubke's avatar
Marco Bubke committed
271
void DesignModeWidget::disableWidgets()
272 273 274
{
    if (debug)
        qDebug() << Q_FUNC_INFO;
Marco Bubke's avatar
Marco Bubke committed
275

276
    viewManager().disableWidgets();
277 278 279 280
    m_leftSideBar->setEnabled(false);
    m_rightSideBar->setEnabled(false);
    m_isDisabled = true;
}
281

282
void DesignModeWidget::updateErrorStatus(const QList<RewriterError> &errors)
283 284 285 286
{
    if (debug)
        qDebug() << Q_FUNC_INFO << errors.count();

Marco Bubke's avatar
Marco Bubke committed
287 288 289 290 291 292
    if (m_isDisabled && errors.isEmpty()) {
        enableWidgets();
     } else if (!errors.isEmpty()) {
        disableWidgets();
        showErrorMessage(errors);
    }
293
}
294

295
TextEditor::BaseTextEditor *DesignModeWidget::textEditor() const
296
{
Marco Bubke's avatar
Marco Bubke committed
297
    return currentDesignDocument()->textEditor();
298 299
}

Marco Bubke's avatar
Marco Bubke committed
300
void DesignModeWidget::setCurrentDesignDocument(DesignDocument *newDesignDocument)
301 302
{
    if (debug)
Marco Bubke's avatar
Marco Bubke committed
303
        qDebug() << Q_FUNC_INFO << newDesignDocument;
304

Marco Bubke's avatar
Marco Bubke committed
305
    //viewManager().setDesignDocument(newDesignDocument);
306 307


308 309
}

310
static void hideToolButtons(QList<QToolButton*> &buttons)
311
{
312 313
    foreach (QToolButton *button, buttons)
        button->hide();
314 315
}

316 317
void DesignModeWidget::setup()
{
318 319
    QList<Core::INavigationWidgetFactory *> factories =
            ExtensionSystem::PluginManager::getObjects<Core::INavigationWidgetFactory>();
320 321 322 323 324

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

325
    foreach (Core::INavigationWidgetFactory *factory, factories) {
326 327
        Core::NavigationView navigationView;
        navigationView.widget = 0;
328
        if (factory->id() == "Projects") {
329 330
            navigationView = factory->createWidget();
            projectsExplorer = navigationView.widget;
331
            hideToolButtons(navigationView.dockToolBarWidgets);
332
            projectsExplorer->setWindowTitle(tr("Projects"));
333
        } else if (factory->id() == "File System") {
334 335
            navigationView = factory->createWidget();
            fileSystemExplorer = navigationView.widget;
336
            hideToolButtons(navigationView.dockToolBarWidgets);
337
            fileSystemExplorer->setWindowTitle(tr("File System"));
338
        } else if (factory->id() == "Open Documents") {
339 340
            navigationView = factory->createWidget();
            openDocumentsWidget = navigationView.widget;
341
            hideToolButtons(navigationView.dockToolBarWidgets);
342 343 344
            openDocumentsWidget->setWindowTitle(tr("Open Documents"));
        }

345 346 347 348
        if (navigationView.widget) {
            QByteArray sheet = Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css");
            sheet += Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css");
            sheet += "QLabel { background-color: #4f4f4f; }";
349
            navigationView.widget->setStyleSheet(QString::fromUtf8(sheet));
350
        }
351 352
    }

353

354 355

    QToolBar *toolBar = new QToolBar;
356 357

    toolBar->addAction(viewManager().componentViewAction());
358 359

    toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
360
    m_toolBar->addCenterToolBar(toolBar);
361 362 363 364 365 366 367 368

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

369 370 371
    QList<Core::SideBarItem*> sideBarItems;
    QList<Core::SideBarItem*> leftSideBarItems;
    QList<Core::SideBarItem*> rightSideBarItems;
372

373 374
    foreach (const WidgetInfo &widgetInfo, viewManager().widgetInfos()) {
        if (widgetInfo.placementHint == widgetInfo.LeftPane) {
375
            Core::SideBarItem *sideBarItem = new DesignerSideBarItem(widgetInfo.widget, widgetInfo.toolBarWidgetFactory, widgetInfo.uniqueId);
376 377 378 379 380
            sideBarItems.append(sideBarItem);
            leftSideBarItems.append(sideBarItem);
        }

        if (widgetInfo.placementHint == widgetInfo.RightPane) {
381
            Core::SideBarItem *sideBarItem = new DesignerSideBarItem(widgetInfo.widget, widgetInfo.toolBarWidgetFactory, widgetInfo.uniqueId);
382 383
            sideBarItems.append(sideBarItem);
            rightSideBarItems.append(sideBarItem);
384

385
        }
386
        m_viewWidgets.append(widgetInfo.widget);
387
    }
388 389

    if (projectsExplorer) {
390
        Core::SideBarItem *projectExplorerItem = new Core::SideBarItem(projectsExplorer, QLatin1String(SB_PROJECTS));
391
        sideBarItems.append(projectExplorerItem);
392 393 394
    }

    if (fileSystemExplorer) {
395
        Core::SideBarItem *fileSystemExplorerItem = new Core::SideBarItem(fileSystemExplorer, QLatin1String(SB_FILESYSTEM));
396
        sideBarItems.append(fileSystemExplorerItem);
397 398
    }

399
    if (openDocumentsWidget) {
400
        Core::SideBarItem *openDocumentsItem = new Core::SideBarItem(openDocumentsWidget, QLatin1String(SB_OPENDOCUMENTS));
401
        sideBarItems.append(openDocumentsItem);
402 403
    }

404 405
    m_leftSideBar.reset(new Core::SideBar(sideBarItems, leftSideBarItems));
    m_rightSideBar.reset(new Core::SideBar(sideBarItems, rightSideBarItems));
406

407 408
    connect(m_leftSideBar.data(), SIGNAL(availableItemsChanged()), SLOT(updateAvailableSidebarItemsRight()));
    connect(m_rightSideBar.data(), SIGNAL(availableItemsChanged()), SLOT(updateAvailableSidebarItemsLeft()));
409

Kai Koehne's avatar
Kai Koehne committed
410 411 412
    connect(Core::ICore::instance(), SIGNAL(coreAboutToClose()),
            this, SLOT(deleteSidebarWidgets()));

Marco Bubke's avatar
Marco Bubke committed
413 414
    m_toolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
    m_toolBar->setNavigationVisible(true);
415

Montel Laurent's avatar
Montel Laurent committed
416 417
    connect(m_toolBar, &Core::EditorToolBar::goForwardClicked, this, &DesignModeWidget::toolBarOnGoForwardClicked);
    connect(m_toolBar, &Core::EditorToolBar::goBackClicked, this, &DesignModeWidget::toolBarOnGoBackClicked);
Marco Bubke's avatar
Marco Bubke committed
418 419 420

    if (currentDesignDocument())
        setupNavigatorHistory(currentDesignDocument()->textEditor());
421 422

    // m_mainSplitter area:
423
    m_mainSplitter->addWidget(m_leftSideBar.data());
424
    m_mainSplitter->addWidget(createCenterWidget());
425
    m_mainSplitter->addWidget(m_rightSideBar.data());
426 427 428 429 430 431 432 433 434 435 436

    // Finishing touches:
    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);
437
    viewManager().enableWidgets();
438 439
    m_leftSideBar->setEnabled(true);
    m_rightSideBar->setEnabled(true);
440 441
    m_leftSideBar->setCloseWhenEmpty(false);
    m_rightSideBar->setCloseWhenEmpty(false);
442 443 444 445 446 447

    readSettings();

    show();
}

448 449 450
void DesignModeWidget::updateAvailableSidebarItemsRight()
{
    // event comes from m_leftSidebar, so update right side.
451
    m_rightSideBar->setUnavailableItemIds(m_leftSideBar->unavailableItemIds());
452 453 454 455 456
}

void DesignModeWidget::updateAvailableSidebarItemsLeft()
{
    // event comes from m_rightSidebar, so update left side.
457
    m_leftSideBar->setUnavailableItemIds(m_rightSideBar->unavailableItemIds());
458 459
}

Kai Koehne's avatar
Kai Koehne committed
460 461
void DesignModeWidget::deleteSidebarWidgets()
{
462 463
    m_leftSideBar.reset();
    m_rightSideBar.reset();
Kai Koehne's avatar
Kai Koehne committed
464 465
}

466
void DesignModeWidget::showQmlPuppetCrashedError()
467
{
468 469
    QList<RewriterError> errorList;
    RewriterError error(tr("Qt Quick emulation layer crashed"));
Marco Bubke's avatar
Marco Bubke committed
470 471 472 473
    errorList.append(error);

    disableWidgets();
    showErrorMessage(errorList);
474 475
}

Marco Bubke's avatar
Marco Bubke committed
476
void DesignModeWidget::toolBarOnGoBackClicked()
477 478 479 480
{
    if (m_navigatorHistoryCounter > 0) {
        --m_navigatorHistoryCounter;
        m_keepNavigatorHistory = true;
Eike Ziller's avatar
Eike Ziller committed
481 482
        Core::EditorManager::openEditor(m_navigatorHistory.at(m_navigatorHistoryCounter),
                                        Core::Id(), Core::EditorManager::DoNotMakeVisible);
483 484 485 486
        m_keepNavigatorHistory = false;
    }
}

Marco Bubke's avatar
Marco Bubke committed
487
void DesignModeWidget::toolBarOnGoForwardClicked()
488 489 490 491
{
    if (m_navigatorHistoryCounter < (m_navigatorHistory.size() - 1)) {
        ++m_navigatorHistoryCounter;
        m_keepNavigatorHistory = true;
Eike Ziller's avatar
Eike Ziller committed
492 493
        Core::EditorManager::openEditor(m_navigatorHistory.at(m_navigatorHistoryCounter),
                                        Core::Id(), Core::EditorManager::DoNotMakeVisible);
494 495 496 497
        m_keepNavigatorHistory = false;
    }
}

Marco Bubke's avatar
Marco Bubke committed
498
DesignDocument *DesignModeWidget::currentDesignDocument() const
499
{
Marco Bubke's avatar
Marco Bubke committed
500
    return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument();
501 502
}

Marco Bubke's avatar
Marco Bubke committed
503
ViewManager &DesignModeWidget::viewManager()
504
{
Marco Bubke's avatar
Marco Bubke committed
505
    return QmlDesignerPlugin::instance()->viewManager();
506 507
}

508 509
void DesignModeWidget::resizeEvent(QResizeEvent *event)
{
510 511 512 513
    if (m_warningWidget) {
        QPoint warningWidgetCenterPoint = m_warningWidget->rect().center();
        m_warningWidget->move(QPoint(event->size().width() / 2, event->size().height() / 2) - warningWidgetCenterPoint);
    }
514 515 516
    QWidget::resizeEvent(event);
}

Marco Bubke's avatar
Marco Bubke committed
517
void DesignModeWidget::setupNavigatorHistory(Core::IEditor *editor)
518
{
Marco Bubke's avatar
Marco Bubke committed
519
    if (!m_keepNavigatorHistory)
520
        addNavigatorHistoryEntry(editor->document()->filePath().toString());
521

522 523
    const bool canGoBack = m_navigatorHistoryCounter > 0;
    const bool canGoForward = m_navigatorHistoryCounter < (m_navigatorHistory.size() - 1);
Marco Bubke's avatar
Marco Bubke committed
524 525 526
    m_toolBar->setCanGoBack(canGoBack);
    m_toolBar->setCanGoForward(canGoForward);
    m_toolBar->setCurrentEditor(editor);
527 528 529 530 531 532 533 534 535 536 537 538
}

void DesignModeWidget::addNavigatorHistoryEntry(const QString &fileName)
{
    if (m_navigatorHistoryCounter > 0)
        m_navigatorHistory.insert(m_navigatorHistoryCounter + 1, fileName);
    else
        m_navigatorHistory.append(fileName);

    ++m_navigatorHistoryCounter;
}

539 540 541 542 543 544 545 546 547 548
static QWidget *createWidgetsInTabWidget(const QList<WidgetInfo> &widgetInfos)
{
    QTabWidget *tabWidget = new QTabWidget;

    foreach (const WidgetInfo &widgetInfo, widgetInfos)
        tabWidget->addTab(widgetInfo.widget, widgetInfo.tabName);

    return tabWidget;
}

549
static QWidget *createTopSideBarWidget(const QList<WidgetInfo> &widgetInfos)
550 551
{
    //### we now own these here
552
    QList<WidgetInfo> topWidgetInfos;
553
    foreach (const WidgetInfo &widgetInfo, widgetInfos) {
554 555 556
        if (widgetInfo.placementHint == widgetInfo.TopPane)
            topWidgetInfos.append(widgetInfo);
    }
557

558
    if (topWidgetInfos.count() == 1)
559
        return topWidgetInfos.first().widget;
560
    else
561 562
        return createWidgetsInTabWidget(topWidgetInfos);
}
563

564
static Core::MiniSplitter *createCentralSplitter(const QList<WidgetInfo> &widgetInfos)
565
{
566
    QList<WidgetInfo> centralWidgetInfos;
567
    foreach (const WidgetInfo &widgetInfo, widgetInfos) {
568 569 570
        if (widgetInfo.placementHint == widgetInfo.CentralPane)
            centralWidgetInfos.append(widgetInfo);
    }
571 572

    // editor and output panes
573 574 575 576 577
    Core::MiniSplitter *outputPlaceholderSplitter = new Core::MiniSplitter;
    outputPlaceholderSplitter->setStretchFactor(0, 10);
    outputPlaceholderSplitter->setStretchFactor(1, 0);
    outputPlaceholderSplitter->setOrientation(Qt::Vertical);

hjk's avatar
hjk committed
578
    auto outputPanePlaceholder = new StyledOutputpanePlaceHolder(Core::Constants::MODE_DESIGN, outputPlaceholderSplitter);
579

580
    if (centralWidgetInfos.count() == 1)
581
        outputPlaceholderSplitter->addWidget(centralWidgetInfos.first().widget);
582
    else
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
         outputPlaceholderSplitter->addWidget(createWidgetsInTabWidget(centralWidgetInfos));

    outputPlaceholderSplitter->addWidget(outputPanePlaceholder);

    return outputPlaceholderSplitter;
}

QWidget *DesignModeWidget::createCenterWidget()
{
    QWidget *centerWidget = new QWidget;

    QVBoxLayout *horizontalLayout = new QVBoxLayout(centerWidget);
    horizontalLayout->setMargin(0);
    horizontalLayout->setSpacing(0);

    horizontalLayout->addWidget(m_toolBar);
    horizontalLayout->addWidget(createCrumbleBarFrame());
600

601 602
    m_topSideBar = createTopSideBarWidget(viewManager().widgetInfos());
    horizontalLayout->addWidget(m_topSideBar.data());
603

604
    horizontalLayout->addWidget(createCentralSplitter(viewManager().widgetInfos()));
605 606 607 608

    return centerWidget;
}

609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
QWidget *DesignModeWidget::createCrumbleBarFrame()
{
    QFrame *frame = new QFrame(this);
    frame->setStyleSheet("background-color: #4e4e4e;");
    frame->setFrameShape(QFrame::NoFrame);
    QHBoxLayout *layout = new QHBoxLayout(frame);
    layout->setMargin(0);
    layout->setSpacing(0);
    frame->setLayout(layout);
    layout->addWidget(m_crumbleBar->crumblePath());
    frame->setProperty("panelwidget", true);
    frame->setProperty("panelwidget_singlerow", false);

    return frame;
}

625
void DesignModeWidget::showErrorMessage(const QList<RewriterError> &errors)
Marco Bubke's avatar
Marco Bubke committed
626 627 628 629 630 631
{
    Q_ASSERT(!errors.isEmpty());
    m_warningWidget->setError(errors.first());
    m_warningWidget->setVisible(true);
    m_warningWidget->move(width() / 2, height() / 2);
}
632

633 634 635 636 637
CrumbleBar *DesignModeWidget::crumbleBar() const
{
    return m_crumbleBar;
}

638 639
QString DesignModeWidget::contextHelpId() const
{
Marco Bubke's avatar
Marco Bubke committed
640 641
    if (currentDesignDocument())
        return currentDesignDocument()->contextHelpId();
642 643 644
    return QString();
}

Marco Bubke's avatar
Marco Bubke committed
645 646 647 648 649 650 651 652 653 654
void DesignModeWidget::initialize()
{
    if (m_initStatus == NotInitialized) {
        m_initStatus = Initializing;
        setup();
    }

    m_initStatus = Initialized;
}

655 656
} // namespace Internal
} // namespace Designer