Commit cacdcf71 authored by Tim Jenssen's avatar Tim Jenssen

QmlDesigner: improve warning widget code

 - the "move" code needs to be inside the warning widget,
   this also fixes the problem of wrong position at startup
 - the patch removes knowledge about the DesignModeWidget and
   uses a signal

Change-Id: I9a861ab955d16e85d7af36f1b56ddb82578b8da4
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@theqtcompany.com>
parent 62e3c0db
...@@ -30,9 +30,11 @@ ...@@ -30,9 +30,11 @@
#include "crumblebar.h" #include "crumblebar.h"
#include "documentwarningwidget.h" #include "documentwarningwidget.h"
#include <texteditor/textdocument.h>
#include <nodeinstanceview.h> #include <nodeinstanceview.h>
#include <itemlibrarywidget.h> #include <itemlibrarywidget.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/designmode.h> #include <coreplugin/designmode.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
...@@ -316,6 +318,13 @@ void DesignModeWidget::setup() ...@@ -316,6 +318,13 @@ void DesignModeWidget::setup()
// warning frame should be not in layout, but still child of the widget // warning frame should be not in layout, but still child of the widget
m_warningWidget = new DocumentWarningWidget(this); m_warningWidget = new DocumentWarningWidget(this);
m_warningWidget->setVisible(false); m_warningWidget->setVisible(false);
connect(m_warningWidget, &DocumentWarningWidget::gotoCodeClicked, [=]
(const QString &filePath, int codeLine, int codeColumn) {
Q_ASSERT(textEditor()->textDocument()->filePath().toString() == filePath);
textEditor()->gotoLine(codeLine, codeColumn);
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
}
);
QList<Core::SideBarItem*> sideBarItems; QList<Core::SideBarItem*> sideBarItems;
QList<Core::SideBarItem*> leftSideBarItems; QList<Core::SideBarItem*> leftSideBarItems;
...@@ -447,15 +456,6 @@ ViewManager &DesignModeWidget::viewManager() ...@@ -447,15 +456,6 @@ ViewManager &DesignModeWidget::viewManager()
return QmlDesignerPlugin::instance()->viewManager(); return QmlDesignerPlugin::instance()->viewManager();
} }
void DesignModeWidget::resizeEvent(QResizeEvent *event)
{
if (m_warningWidget) {
QPoint warningWidgetCenterPoint = m_warningWidget->rect().center();
m_warningWidget->move(QPoint(event->size().width() / 2, event->size().height() / 2) - warningWidgetCenterPoint);
}
QWidget::resizeEvent(event);
}
void DesignModeWidget::setupNavigatorHistory(Core::IEditor *editor) void DesignModeWidget::setupNavigatorHistory(Core::IEditor *editor)
{ {
if (!m_keepNavigatorHistory) if (!m_keepNavigatorHistory)
...@@ -569,7 +569,6 @@ void DesignModeWidget::showMessageBox(const QList<RewriterError> &errors) ...@@ -569,7 +569,6 @@ void DesignModeWidget::showMessageBox(const QList<RewriterError> &errors)
Q_ASSERT(!errors.isEmpty()); Q_ASSERT(!errors.isEmpty());
m_warningWidget->setError(errors.first()); m_warningWidget->setError(errors.first());
m_warningWidget->setVisible(true); m_warningWidget->setVisible(true);
m_warningWidget->move(width() / 2, height() / 2);
} }
CrumbleBar *DesignModeWidget::crumbleBar() const CrumbleBar *DesignModeWidget::crumbleBar() const
......
...@@ -94,9 +94,6 @@ private slots: ...@@ -94,9 +94,6 @@ private slots:
void toolBarOnGoBackClicked(); void toolBarOnGoBackClicked();
void toolBarOnGoForwardClicked(); void toolBarOnGoForwardClicked();
protected:
void resizeEvent(QResizeEvent *event);
private: // functions private: // functions
enum InitializeStatus { NotInitialized, Initializing, Initialized }; enum InitializeStatus { NotInitialized, Initializing, Initialized };
......
...@@ -25,22 +25,19 @@ ...@@ -25,22 +25,19 @@
#include "documentwarningwidget.h" #include "documentwarningwidget.h"
#include "designmodewidget.h"
#include <coreplugin/modemanager.h>
#include <coreplugin/coreconstants.h>
#include <QLabel> #include <QLabel>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QEvent>
#include <QDebug>
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal { namespace Internal {
DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) : DocumentWarningWidget::DocumentWarningWidget(QWidget *parent) :
Utils::FakeToolTip(parent), Utils::FakeToolTip(parent),
m_errorMessage(new QLabel(tr("Placeholder"), this)), m_errorMessage(new QLabel(this)),
m_goToError(new QLabel(this)), m_goToError(new QLabel(this))
m_designModeWidget(parent)
{ {
setWindowFlags(Qt::Widget); //We only want the visual style from a ToolTip setWindowFlags(Qt::Widget); //We only want the visual style from a ToolTip
setForegroundRole(QPalette::ToolTipText); setForegroundRole(QPalette::ToolTipText);
...@@ -50,9 +47,8 @@ DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) : ...@@ -50,9 +47,8 @@ DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) :
m_errorMessage->setForegroundRole(QPalette::ToolTipText); m_errorMessage->setForegroundRole(QPalette::ToolTipText);
m_goToError->setText(tr("<a href=\"goToError\">Go to error</a>")); m_goToError->setText(tr("<a href=\"goToError\">Go to error</a>"));
m_goToError->setForegroundRole(QPalette::Link); m_goToError->setForegroundRole(QPalette::Link);
connect(m_goToError, &QLabel::linkActivated, this, [=]() { connect(m_goToError, &QLabel::linkActivated, this, [=](const QString &/*link*/) {
m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column() - 1); emit gotoCodeClicked(m_error.url().toLocalFile(), m_error.line(), m_error.column() - 1);
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
}); });
QVBoxLayout *layout = new QVBoxLayout(this); QVBoxLayout *layout = new QVBoxLayout(this);
...@@ -60,6 +56,27 @@ DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) : ...@@ -60,6 +56,27 @@ DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) :
layout->setSpacing(5); layout->setSpacing(5);
layout->addWidget(m_errorMessage); layout->addWidget(m_errorMessage);
layout->addWidget(m_goToError, 1, Qt::AlignRight); layout->addWidget(m_goToError, 1, Qt::AlignRight);
parent->installEventFilter(this);
}
void DocumentWarningWidget::moveToParentCenter()
{
move(parentWidget()->rect().center() - rect().center());
}
bool DocumentWarningWidget::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::Resize) {
moveToParentCenter();
}
return QObject::eventFilter(object, event);
}
void DocumentWarningWidget::showEvent(QShowEvent *event)
{
moveToParentCenter();
Utils::FakeToolTip::showEvent(event);
} }
void DocumentWarningWidget::setError(const RewriterError &error) void DocumentWarningWidget::setError(const RewriterError &error)
...@@ -67,7 +84,7 @@ void DocumentWarningWidget::setError(const RewriterError &error) ...@@ -67,7 +84,7 @@ void DocumentWarningWidget::setError(const RewriterError &error)
m_error = error; m_error = error;
QString str; QString str;
if (error.type() == RewriterError::ParseError) { if (error.type() == RewriterError::ParseError) {
str = tr("%3 (%1:%2)").arg(QString::number(error.line()), QString::number(error.column()), error.description()); str = QString("%3 (%1:%2)").arg(error.line()).arg(error.column()).arg(error.description());
m_goToError->show(); m_goToError->show();
} else if (error.type() == RewriterError::InternalError) { } else if (error.type() == RewriterError::InternalError) {
str = tr("Internal error (%1)").arg(error.description()); str = tr("Internal error (%1)").arg(error.description());
......
...@@ -36,22 +36,25 @@ QT_END_NAMESPACE ...@@ -36,22 +36,25 @@ QT_END_NAMESPACE
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal { namespace Internal {
class DesignModeWidget;
class DocumentWarningWidget : public Utils::FakeToolTip class DocumentWarningWidget : public Utils::FakeToolTip
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DocumentWarningWidget(DesignModeWidget *parent = 0); explicit DocumentWarningWidget(QWidget *parent);
void setError(const RewriterError &error); void setError(const RewriterError &error);
signals:
void gotoCodeClicked(const QString filePath, int codeLine, int codeColumn);
protected:
bool eventFilter(QObject *object, QEvent *event) override;
void showEvent(QShowEvent *event) override;
private: private:
void moveToParentCenter();
QLabel *m_errorMessage; QLabel *m_errorMessage;
QLabel *m_goToError; QLabel *m_goToError;
RewriterError m_error; RewriterError m_error;
DesignModeWidget *m_designModeWidget;
}; };
} // namespace Internal } // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment