diff options
author | Tim Jenssen <tim.jenssen@theqtcompany.com> | 2016-04-29 22:15:30 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@theqtcompany.com> | 2016-05-10 13:04:04 +0000 |
commit | cacdcf7160ddfdb74a0cd5a6fa1c395b430e2cf5 (patch) | |
tree | d7db28dc4553bafaf84c5acff8c03429de527728 /src/plugins/qmldesigner/documentwarningwidget.cpp | |
parent | 62e3c0dbf4bbe59e477556d32cc6fb6a1a8e868d (diff) |
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: Thomas Hartmann <Thomas.Hartmann@theqtcompany.com>
Diffstat (limited to 'src/plugins/qmldesigner/documentwarningwidget.cpp')
-rw-r--r-- | src/plugins/qmldesigner/documentwarningwidget.cpp | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/plugins/qmldesigner/documentwarningwidget.cpp b/src/plugins/qmldesigner/documentwarningwidget.cpp index fb320a1d73..0be331b73f 100644 --- a/src/plugins/qmldesigner/documentwarningwidget.cpp +++ b/src/plugins/qmldesigner/documentwarningwidget.cpp @@ -25,22 +25,19 @@ #include "documentwarningwidget.h" -#include "designmodewidget.h" - -#include <coreplugin/modemanager.h> -#include <coreplugin/coreconstants.h> - #include <QLabel> #include <QVBoxLayout> +#include <QEvent> + +#include <QDebug> namespace QmlDesigner { namespace Internal { -DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) : +DocumentWarningWidget::DocumentWarningWidget(QWidget *parent) : Utils::FakeToolTip(parent), - m_errorMessage(new QLabel(tr("Placeholder"), this)), - m_goToError(new QLabel(this)), - m_designModeWidget(parent) + m_errorMessage(new QLabel(this)), + m_goToError(new QLabel(this)) { setWindowFlags(Qt::Widget); //We only want the visual style from a ToolTip setForegroundRole(QPalette::ToolTipText); @@ -50,9 +47,8 @@ DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) : 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); + connect(m_goToError, &QLabel::linkActivated, this, [=](const QString &/*link*/) { + emit gotoCodeClicked(m_error.url().toLocalFile(), m_error.line(), m_error.column() - 1); }); QVBoxLayout *layout = new QVBoxLayout(this); @@ -60,6 +56,27 @@ DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) : layout->setSpacing(5); layout->addWidget(m_errorMessage); 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) @@ -67,7 +84,7 @@ 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()); + str = QString("%3 (%1:%2)").arg(error.line()).arg(error.column()).arg(error.description()); m_goToError->show(); } else if (error.type() == RewriterError::InternalError) { str = tr("Internal error (%1)").arg(error.description()); |