forked from qt-creator/qt-creator
QmlDesigner: move DocumentWarningWidget to extra file
Change-Id: I6ea87a224565b77ff42f187461094ca258dcdb01 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@theqtcompany.com>
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
#include "styledoutputpaneplaceholder.h"
|
#include "styledoutputpaneplaceholder.h"
|
||||||
#include "qmldesignerplugin.h"
|
#include "qmldesignerplugin.h"
|
||||||
#include "crumblebar.h"
|
#include "crumblebar.h"
|
||||||
|
#include "documentwarningwidget.h"
|
||||||
|
|
||||||
#include <rewriterview.h>
|
#include <rewriterview.h>
|
||||||
#include <nodeinstanceview.h>
|
#include <nodeinstanceview.h>
|
||||||
@@ -34,7 +35,6 @@
|
|||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/designmode.h>
|
#include <coreplugin/designmode.h>
|
||||||
#include <coreplugin/modemanager.h>
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/minisplitter.h>
|
#include <coreplugin/minisplitter.h>
|
||||||
#include <coreplugin/sidebar.h>
|
#include <coreplugin/sidebar.h>
|
||||||
@@ -47,10 +47,6 @@
|
|||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QToolButton>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QTabWidget>
|
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
|
|
||||||
using Core::MiniSplitter;
|
using Core::MiniSplitter;
|
||||||
@@ -70,50 +66,6 @@ const char SB_OPENDOCUMENTS[] = "OpenDocuments";
|
|||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) :
|
|
||||||
Utils::FakeToolTip(parent),
|
|
||||||
m_errorMessage(new QLabel(tr("Placeholder"), this)),
|
|
||||||
m_goToError(new QLabel(this)),
|
|
||||||
m_designModeWidget(parent)
|
|
||||||
{
|
|
||||||
setWindowFlags(Qt::Widget); //We only want the visual style from a ToolTip
|
|
||||||
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, &QLabel::linkActivated, this, [=]() {
|
|
||||||
m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column() - 1);
|
|
||||||
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
|
||||||
});
|
|
||||||
|
|
||||||
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 RewriterError &error)
|
|
||||||
{
|
|
||||||
m_error = error;
|
|
||||||
QString str;
|
|
||||||
if (error.type() == RewriterError::ParseError) {
|
|
||||||
str = tr("%3 (%1:%2)").arg(QString::number(error.line()), QString::number(error.column()), error.description());
|
|
||||||
m_goToError->show();
|
|
||||||
} else if (error.type() == RewriterError::InternalError) {
|
|
||||||
str = tr("Internal error (%1)").arg(error.description());
|
|
||||||
m_goToError->hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
str.prepend(tr("Cannot open this QML document because of an error in the QML file:\n\n"));
|
|
||||||
|
|
||||||
m_errorMessage->setText(str);
|
|
||||||
resize(layout()->totalSizeHint());
|
|
||||||
}
|
|
||||||
|
|
||||||
class ItemLibrarySideBarItem : public Core::SideBarItem
|
class ItemLibrarySideBarItem : public Core::SideBarItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -32,16 +32,8 @@
|
|||||||
#include <modelnode.h>
|
#include <modelnode.h>
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QLabel>
|
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QStackedWidget;
|
|
||||||
class QTabWidget;
|
|
||||||
class QVBoxLayout;
|
|
||||||
class QToolButton;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class SideBar;
|
class SideBar;
|
||||||
class SideBarItem;
|
class SideBarItem;
|
||||||
@@ -59,22 +51,7 @@ namespace Internal {
|
|||||||
class DesignMode;
|
class DesignMode;
|
||||||
class DocumentWidget;
|
class DocumentWidget;
|
||||||
class DesignModeWidget;
|
class DesignModeWidget;
|
||||||
|
class DocumentWarningWidget;
|
||||||
class DocumentWarningWidget : public Utils::FakeToolTip
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit DocumentWarningWidget(DesignModeWidget *parent = 0);
|
|
||||||
|
|
||||||
void setError(const RewriterError &error);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QLabel *m_errorMessage;
|
|
||||||
QLabel *m_goToError;
|
|
||||||
RewriterError m_error;
|
|
||||||
DesignModeWidget *m_designModeWidget;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DesignModeWidget : public QWidget
|
class DesignModeWidget : public QWidget
|
||||||
{
|
{
|
||||||
|
84
src/plugins/qmldesigner/documentwarningwidget.cpp
Normal file
84
src/plugins/qmldesigner/documentwarningwidget.cpp
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2016 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** 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
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "documentwarningwidget.h"
|
||||||
|
|
||||||
|
#include "designmodewidget.h"
|
||||||
|
|
||||||
|
#include <coreplugin/modemanager.h>
|
||||||
|
#include <coreplugin/coreconstants.h>
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) :
|
||||||
|
Utils::FakeToolTip(parent),
|
||||||
|
m_errorMessage(new QLabel(tr("Placeholder"), this)),
|
||||||
|
m_goToError(new QLabel(this)),
|
||||||
|
m_designModeWidget(parent)
|
||||||
|
{
|
||||||
|
setWindowFlags(Qt::Widget); //We only want the visual style from a ToolTip
|
||||||
|
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, &QLabel::linkActivated, this, [=]() {
|
||||||
|
m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column() - 1);
|
||||||
|
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
||||||
|
});
|
||||||
|
|
||||||
|
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 RewriterError &error)
|
||||||
|
{
|
||||||
|
m_error = error;
|
||||||
|
QString str;
|
||||||
|
if (error.type() == RewriterError::ParseError) {
|
||||||
|
str = tr("%3 (%1:%2)").arg(QString::number(error.line()), QString::number(error.column()), error.description());
|
||||||
|
m_goToError->show();
|
||||||
|
} else if (error.type() == RewriterError::InternalError) {
|
||||||
|
str = tr("Internal error (%1)").arg(error.description());
|
||||||
|
m_goToError->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
str.prepend(tr("Cannot open this QML document because of an error in the QML file:\n\n"));
|
||||||
|
|
||||||
|
m_errorMessage->setText(str);
|
||||||
|
resize(layout()->totalSizeHint());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Designer
|
58
src/plugins/qmldesigner/documentwarningwidget.h
Normal file
58
src/plugins/qmldesigner/documentwarningwidget.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2016 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** 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
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <utils/faketooltip.h>
|
||||||
|
#include <rewriterview.h>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QLabel;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class DesignModeWidget;
|
||||||
|
|
||||||
|
class DocumentWarningWidget : public Utils::FakeToolTip
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DocumentWarningWidget(DesignModeWidget *parent = 0);
|
||||||
|
|
||||||
|
void setError(const RewriterError &error);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QLabel *m_errorMessage;
|
||||||
|
QLabel *m_goToError;
|
||||||
|
RewriterError m_error;
|
||||||
|
DesignModeWidget *m_designModeWidget;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Designer
|
@@ -6,6 +6,7 @@ HEADERS += $$PWD/qmldesignerconstants.h \
|
|||||||
$$PWD/settingspage.h \
|
$$PWD/settingspage.h \
|
||||||
$$PWD/designmodecontext.h \
|
$$PWD/designmodecontext.h \
|
||||||
$$PWD/documentmanager.h \
|
$$PWD/documentmanager.h \
|
||||||
|
$$PWD/documentwarningwidget.h \
|
||||||
$$PWD/styledoutputpaneplaceholder.h \
|
$$PWD/styledoutputpaneplaceholder.h \
|
||||||
$$PWD/qmldesignericons.h
|
$$PWD/qmldesignericons.h
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ SOURCES += $$PWD/qmldesignerplugin.cpp \
|
|||||||
$$PWD/settingspage.cpp \
|
$$PWD/settingspage.cpp \
|
||||||
$$PWD/designmodecontext.cpp \
|
$$PWD/designmodecontext.cpp \
|
||||||
$$PWD/documentmanager.cpp \
|
$$PWD/documentmanager.cpp \
|
||||||
|
$$PWD/documentwarningwidget.cpp \
|
||||||
$$PWD/styledoutputpaneplaceholder.cpp
|
$$PWD/styledoutputpaneplaceholder.cpp
|
||||||
|
|
||||||
FORMS += $$PWD/settingspage.ui
|
FORMS += $$PWD/settingspage.ui
|
||||||
|
Reference in New Issue
Block a user