2010-01-07 12:14:35 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
** 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>
|
|
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
#include <coreplugin/modemanager.h>
|
2010-03-10 12:48:17 +01:00
|
|
|
#include <coreplugin/editortoolbar.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
|
|
|
|
|
using Core::MiniSplitter;
|
|
|
|
|
using Core::IEditor;
|
|
|
|
|
using Core::EditorManager;
|
|
|
|
|
|
|
|
|
|
using namespace QmlDesigner;
|
|
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Core::IEditor*)
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
debug = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
DocumentWarningWidget::DocumentWarningWidget(DocumentWidget *documentWidget, QWidget *parent) :
|
|
|
|
|
QFrame(parent),
|
|
|
|
|
m_errorMessage(new QLabel("Placeholder", this)),
|
|
|
|
|
m_goToError(new QLabel(this)),
|
|
|
|
|
m_documentWidget(documentWidget)
|
|
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
m_documentWidget->textEditor()->gotoLine(m_error.line(), m_error.column());
|
|
|
|
|
Core::EditorManager::instance()->ensureEditorManagerVisible();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DocumentWidget::DocumentWidget(TextEditor::ITextEditor *textEditor, QPlainTextEdit *textEdit, QmlDesigner::DesignDocumentController *document, DesignModeWidget *mainWidget) :
|
|
|
|
|
QWidget(),
|
|
|
|
|
m_textEditor(textEditor),
|
|
|
|
|
m_textBuffer(textEdit),
|
|
|
|
|
m_document(document),
|
|
|
|
|
m_mainWidget(mainWidget),
|
|
|
|
|
m_mainSplitter(0),
|
|
|
|
|
m_leftSideBar(0),
|
|
|
|
|
m_rightSideBar(0),
|
2010-03-09 09:42:22 +01:00
|
|
|
m_designToolBar(new QToolBar),
|
2010-03-09 17:40:55 +01:00
|
|
|
m_fakeToolBar(Core::EditorManager::createToolBar(this)),
|
2010-01-07 12:14:35 +01:00
|
|
|
m_isDisabled(false),
|
|
|
|
|
m_warningWidget(0)
|
|
|
|
|
{
|
|
|
|
|
setup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DocumentWidget::~DocumentWidget()
|
|
|
|
|
{
|
|
|
|
|
// Make sure component widgets are deleted first in SideBarItem::~SideBarItem
|
|
|
|
|
// before the DesignDocumentController runs (and deletes them again).
|
|
|
|
|
m_document->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlDesigner::DesignDocumentController *DocumentWidget::document() const
|
|
|
|
|
{
|
|
|
|
|
return m_document;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextEditor::ITextEditor *DocumentWidget::textEditor() const
|
|
|
|
|
{
|
|
|
|
|
return m_textEditor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocumentWidget::setAutoSynchronization(bool sync)
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << sync;
|
|
|
|
|
|
|
|
|
|
document()->blockModelSync(!sync);
|
|
|
|
|
|
|
|
|
|
if (sync) {
|
|
|
|
|
// text editor -> visual editor
|
2010-01-08 13:15:52 +01:00
|
|
|
if (!document()->model()) {
|
2010-01-18 14:33:53 +01:00
|
|
|
document()->loadMaster(m_textBuffer.data());
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
2010-01-18 14:33:53 +01:00
|
|
|
|
|
|
|
|
QList<RewriterView::Error> errors = document()->qmlErrors();
|
|
|
|
|
if (errors.isEmpty()) {
|
2010-01-07 12:14:35 +01:00
|
|
|
// set selection to text cursor
|
2010-01-08 13:15:52 +01:00
|
|
|
RewriterView *rewriter = document()->rewriterView();
|
2010-01-07 12:14:35 +01:00
|
|
|
const int cursorPos = m_textBuffer->textCursor().position();
|
|
|
|
|
ModelNode node = nodeForPosition(cursorPos);
|
|
|
|
|
if (node.isValid()) {
|
|
|
|
|
rewriter->setSelectedModelNodes(QList<ModelNode>() << node);
|
|
|
|
|
}
|
2010-01-08 13:15:52 +01:00
|
|
|
enable();
|
2010-01-18 14:33:53 +01:00
|
|
|
} else {
|
|
|
|
|
disable(errors);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
2010-01-08 13:15:52 +01:00
|
|
|
|
|
|
|
|
connect(document(), SIGNAL(qmlErrorsChanged(QList<RewriterView::Error>)),
|
|
|
|
|
this, SLOT(updateErrorStatus(QList<RewriterView::Error>)));
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
} else {
|
2010-01-08 13:15:52 +01:00
|
|
|
if (document()->model() && document()->qmlErrors().isEmpty()) {
|
|
|
|
|
RewriterView *rewriter = document()->rewriterView();
|
2010-01-07 12:14:35 +01:00
|
|
|
// visual editor -> text editor
|
|
|
|
|
ModelNode selectedNode;
|
|
|
|
|
if (!rewriter->selectedModelNodes().isEmpty())
|
|
|
|
|
selectedNode = rewriter->selectedModelNodes().first();
|
|
|
|
|
|
|
|
|
|
if (selectedNode.isValid()) {
|
2010-01-28 14:46:00 +01:00
|
|
|
const int nodeOffset = rewriter->nodeOffset(selectedNode);
|
|
|
|
|
if (nodeOffset > 0) {
|
|
|
|
|
const ModelNode currentSelectedNode
|
|
|
|
|
= nodeForPosition(m_textBuffer->textCursor().position());
|
|
|
|
|
if (currentSelectedNode != selectedNode) {
|
|
|
|
|
int line, column;
|
|
|
|
|
textEditor()->convertPosition(nodeOffset, &line, &column);
|
|
|
|
|
textEditor()->gotoLine(line, column);
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-08 13:15:52 +01:00
|
|
|
|
|
|
|
|
disconnect(document(), SIGNAL(qmlErrorsChanged(QList<RewriterView::Error>)),
|
|
|
|
|
this, SLOT(updateErrorStatus(QList<RewriterView::Error>)));
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocumentWidget::enable()
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO;
|
|
|
|
|
m_warningWidget->setVisible(false);
|
|
|
|
|
m_document->documentWidget()->setEnabled(true);
|
2010-01-11 12:54:05 +01:00
|
|
|
m_document->statesEditorWidget()->setEnabled(true);
|
2010-01-07 12:14:35 +01:00
|
|
|
m_leftSideBar->setEnabled(true);
|
|
|
|
|
m_rightSideBar->setEnabled(true);
|
|
|
|
|
m_isDisabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocumentWidget::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_document->documentWidget()->setEnabled(false);
|
2010-01-11 12:54:05 +01:00
|
|
|
m_document->statesEditorWidget()->setEnabled(false);
|
2010-01-07 12:14:35 +01:00
|
|
|
m_leftSideBar->setEnabled(false);
|
|
|
|
|
m_rightSideBar->setEnabled(false);
|
|
|
|
|
m_isDisabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocumentWidget::updateErrorStatus(const QList<RewriterView::Error> &errors)
|
|
|
|
|
{
|
2010-01-13 11:44:13 +01:00
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << errors.count();
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
if (m_isDisabled && errors.isEmpty()) {
|
|
|
|
|
enable();
|
2010-01-08 13:15:52 +01:00
|
|
|
} else if (!errors.isEmpty()) {
|
2010-01-07 12:14:35 +01:00
|
|
|
disable(errors);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocumentWidget::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 DocumentWidget::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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DocumentWidget::resizeEvent(QResizeEvent *event)
|
|
|
|
|
{
|
|
|
|
|
m_warningWidget->move(QPoint(event->size().width() / 2,
|
|
|
|
|
event->size().height() / 2));
|
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocumentWidget::setup()
|
|
|
|
|
{
|
|
|
|
|
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, this);
|
|
|
|
|
m_warningWidget->setVisible(false);
|
|
|
|
|
|
|
|
|
|
// Left area:
|
|
|
|
|
Core::SideBarItem *navigatorItem = new Core::SideBarItem(m_document->navigator());
|
|
|
|
|
Core::SideBarItem *libraryItem = new Core::SideBarItem(m_document->itemLibrary());
|
|
|
|
|
Core::SideBarItem *propertiesItem = new Core::SideBarItem(m_document->allPropertiesBox());
|
|
|
|
|
|
|
|
|
|
QList<Core::SideBarItem*> leftSideBarItems, rightSideBarItems;
|
|
|
|
|
leftSideBarItems << navigatorItem << libraryItem;
|
|
|
|
|
rightSideBarItems << propertiesItem;
|
|
|
|
|
|
|
|
|
|
m_leftSideBar = new Core::SideBar(leftSideBarItems, QList<Core::SideBarItem*>() << navigatorItem << libraryItem);
|
|
|
|
|
m_rightSideBar = new Core::SideBar(rightSideBarItems, QList<Core::SideBarItem*>() << propertiesItem);
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
m_designToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
|
|
|
|
|
2010-03-15 16:02:38 +01:00
|
|
|
m_fakeToolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
|
2010-03-10 10:50:11 +01:00
|
|
|
m_fakeToolBar->addEditor(textEditor());
|
2010-03-09 17:40:55 +01:00
|
|
|
m_fakeToolBar->addCenterToolBar(m_designToolBar);
|
|
|
|
|
m_fakeToolBar->setNavigationVisible(false);
|
2010-03-09 09:42:22 +01:00
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
// right area:
|
|
|
|
|
QWidget *centerWidget = new QWidget;
|
|
|
|
|
{
|
|
|
|
|
QVBoxLayout *rightLayout = new QVBoxLayout(centerWidget);
|
|
|
|
|
rightLayout->setMargin(0);
|
|
|
|
|
rightLayout->setSpacing(0);
|
2010-03-09 09:42:22 +01:00
|
|
|
rightLayout->addWidget(m_fakeToolBar);
|
2010-01-07 12:14:35 +01:00
|
|
|
rightLayout->addWidget(m_document->statesEditorWidget());
|
|
|
|
|
rightLayout->addWidget(m_document->documentWidget());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DocumentWidget::isInNodeDefinition(int nodeOffset, int nodeLength, int cursorPos) const {
|
|
|
|
|
return (nodeOffset <= cursorPos) && (nodeOffset + nodeLength > cursorPos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModelNode DocumentWidget::nodeForPosition(int cursorPos) const
|
|
|
|
|
{
|
|
|
|
|
RewriterView *rewriter = m_document->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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------- DesignModeWidget
|
2010-02-26 11:08:17 +01:00
|
|
|
DesignModeWidget::DesignModeWidget(QWidget *parent) :
|
2010-01-07 12:14:35 +01:00
|
|
|
QWidget(parent),
|
|
|
|
|
m_documentWidgetStack(new QStackedWidget),
|
|
|
|
|
m_currentDocumentWidget(0),
|
|
|
|
|
m_currentTextEdit(0),
|
|
|
|
|
m_syncWithTextEdit(false)
|
|
|
|
|
{
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
|
layout->setMargin(0);
|
|
|
|
|
layout->addWidget(m_documentWidgetStack);
|
|
|
|
|
|
|
|
|
|
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()));
|
2010-01-25 15:22:08 +01:00
|
|
|
m_selectAllAction = new Utils::ParameterAction(tr("Select &All"), tr("Select All \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
|
connect(m_selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-28 14:35:15 +01:00
|
|
|
QLabel *defaultBackground = new QLabel(tr("Loading ..."));
|
2010-01-07 12:14:35 +01:00
|
|
|
defaultBackground->setAlignment(Qt::AlignCenter);
|
|
|
|
|
|
|
|
|
|
m_documentWidgetStack->addWidget(defaultBackground);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DesignModeWidget::~DesignModeWidget()
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::showEditor(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << fileName;
|
|
|
|
|
|
|
|
|
|
m_currentTextEdit = textEdit;
|
|
|
|
|
DocumentWidget *documentWidget = 0;
|
|
|
|
|
|
2010-02-09 10:44:38 +01:00
|
|
|
if (textEdit && textEditor && fileName.endsWith(QLatin1String(".qml"))) {
|
2010-01-07 12:14:35 +01:00
|
|
|
if (m_documentHash.contains(textEdit)) {
|
|
|
|
|
documentWidget = m_documentHash.value(textEdit);
|
|
|
|
|
} else {
|
|
|
|
|
DesignDocumentController *newDocument = new DesignDocumentController(0);
|
|
|
|
|
newDocument->setFileName(fileName);
|
|
|
|
|
|
|
|
|
|
documentWidget = new DocumentWidget(textEditor, textEdit, newDocument, this);
|
|
|
|
|
connect(documentWidget->document(), SIGNAL(undoAvailable(bool)),
|
2010-03-01 13:10:32 +01:00
|
|
|
this, SLOT(undoAvailable(bool)));
|
2010-01-07 12:14:35 +01:00
|
|
|
connect(documentWidget->document(), SIGNAL(redoAvailable(bool)),
|
|
|
|
|
this, SLOT(redoAvailable(bool)));
|
|
|
|
|
// connect(documentWidget->document(), SIGNAL(deleteAvailable(bool)),
|
|
|
|
|
// this, SLOT(deleteAvailable(bool)));
|
|
|
|
|
|
|
|
|
|
m_documentHash.insert(textEdit, documentWidget);
|
|
|
|
|
m_documentWidgetStack->addWidget(documentWidget);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCurrentDocumentWidget(documentWidget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::closeEditors(QList<Core::IEditor*> editors)
|
|
|
|
|
{
|
|
|
|
|
foreach (Core::IEditor* editor, editors) {
|
|
|
|
|
if (QPlainTextEdit *textEdit = qobject_cast<QPlainTextEdit*>(editor->widget())) {
|
|
|
|
|
if (m_currentTextEdit == textEdit) {
|
|
|
|
|
setCurrentDocumentWidget(0);
|
|
|
|
|
}
|
|
|
|
|
if (m_documentHash.contains(textEdit)) {
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << editor->file()->fileName();
|
|
|
|
|
DocumentWidget *document = m_documentHash.take(textEdit);
|
|
|
|
|
m_documentWidgetStack->removeWidget(document);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-25 15:22:08 +01:00
|
|
|
QAction *DesignModeWidget::selectAllAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_selectAllAction;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void DesignModeWidget::undo()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentWidget)
|
|
|
|
|
m_currentDocumentWidget->document()->undo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::redo()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentWidget)
|
|
|
|
|
m_currentDocumentWidget->document()->redo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::deleteSelected()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentWidget)
|
|
|
|
|
m_currentDocumentWidget->document()->deleteSelected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::cutSelected()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentWidget)
|
|
|
|
|
m_currentDocumentWidget->document()->cutSelected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::copySelected()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentWidget)
|
|
|
|
|
m_currentDocumentWidget->document()->copySelected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::paste()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentWidget)
|
|
|
|
|
m_currentDocumentWidget->document()->paste();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-25 15:22:08 +01:00
|
|
|
void DesignModeWidget::selectAll()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentWidget)
|
|
|
|
|
m_currentDocumentWidget->document()->selectAll();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void DesignModeWidget::undoAvailable(bool isAvailable)
|
|
|
|
|
{
|
|
|
|
|
DesignDocumentController *documentController = qobject_cast<DesignDocumentController*>(sender());
|
|
|
|
|
if (m_currentDocumentWidget &&
|
|
|
|
|
m_currentDocumentWidget->document() == documentController) {
|
|
|
|
|
m_undoAction->setEnabled(isAvailable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::redoAvailable(bool isAvailable)
|
|
|
|
|
{
|
|
|
|
|
DesignDocumentController *documentController = qobject_cast<DesignDocumentController*>(sender());
|
|
|
|
|
if (m_currentDocumentWidget &&
|
|
|
|
|
m_currentDocumentWidget->document() == documentController) {
|
|
|
|
|
m_redoAction->setEnabled(isAvailable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::setCurrentDocumentWidget(DocumentWidget *newDocumentWidget)
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << newDocumentWidget;
|
2010-01-13 11:44:13 +01:00
|
|
|
|
|
|
|
|
if (m_currentDocumentWidget == newDocumentWidget)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
if (m_currentDocumentWidget) {
|
|
|
|
|
m_currentDocumentWidget->setAutoSynchronization(false);
|
|
|
|
|
m_currentDocumentWidget->saveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_currentDocumentWidget = newDocumentWidget;
|
|
|
|
|
|
|
|
|
|
if (m_currentDocumentWidget) {
|
|
|
|
|
m_currentDocumentWidget->setAutoSynchronization(true);
|
|
|
|
|
m_documentWidgetStack->setCurrentWidget(m_currentDocumentWidget);
|
|
|
|
|
m_currentDocumentWidget->readSettings();
|
|
|
|
|
m_undoAction->setEnabled(m_currentDocumentWidget->document()->isUndoAvailable());
|
|
|
|
|
m_redoAction->setEnabled(m_currentDocumentWidget->document()->isRedoAvailable());
|
|
|
|
|
} else {
|
|
|
|
|
m_documentWidgetStack->setCurrentIndex(0);
|
|
|
|
|
m_undoAction->setEnabled(false);
|
|
|
|
|
m_redoAction->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-08 09:47:45 +01:00
|
|
|
QString DesignModeWidget::contextHelpId() const
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentWidget)
|
|
|
|
|
return m_currentDocumentWidget->document()->contextHelpId();
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Designer
|