2016-04-28 14:21:33 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** 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"
|
|
|
|
|
|
2016-05-18 17:27:45 +02:00
|
|
|
#include <qmldesignerplugin.h>
|
|
|
|
|
|
2016-10-07 13:50:17 +02:00
|
|
|
|
|
|
|
|
#include <utils/theme/theme.h>
|
|
|
|
|
#include <utils/stylehelper.h>
|
|
|
|
|
|
2016-04-28 14:21:33 +02:00
|
|
|
#include <QLabel>
|
2016-05-18 17:27:45 +02:00
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QBoxLayout>
|
2016-04-29 22:15:30 +02:00
|
|
|
#include <QEvent>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
2016-04-28 14:21:33 +02:00
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
2016-05-18 17:27:45 +02:00
|
|
|
|
2017-01-10 17:08:14 +01:00
|
|
|
static QString errorToString(const DocumentMessage &error)
|
2016-05-18 17:27:45 +02:00
|
|
|
{
|
|
|
|
|
return QString("Line: %1: %2").arg(error.line()).arg(error.description());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DocumentWarningWidget::DocumentWarningWidget(QWidget *parent)
|
|
|
|
|
: Utils::FakeToolTip(parent)
|
|
|
|
|
, m_headerLabel(new QLabel(this))
|
|
|
|
|
, m_messageLabel(new QLabel(this))
|
|
|
|
|
, m_navigateLabel(new QLabel(this))
|
|
|
|
|
, m_ignoreWarningsCheckBox(new QCheckBox(this))
|
|
|
|
|
, m_continueButton(new QPushButton(this))
|
2016-04-28 14:21:33 +02:00
|
|
|
{
|
2016-07-29 10:20:36 +02:00
|
|
|
// this "tooltip" should behave like a widget with parent child relation to the designer mode
|
|
|
|
|
setWindowFlags(Qt::Widget);
|
|
|
|
|
|
2016-05-18 17:27:45 +02:00
|
|
|
QFont boldFont = font();
|
|
|
|
|
boldFont.setBold(true);
|
|
|
|
|
m_headerLabel->setFont(boldFont);
|
|
|
|
|
m_messageLabel->setForegroundRole(QPalette::ToolTipText);
|
|
|
|
|
m_messageLabel->setWordWrap(true);
|
|
|
|
|
|
|
|
|
|
m_ignoreWarningsCheckBox->setText("Ignore always these unsupported Qt Quick Designer warnings.");
|
|
|
|
|
|
|
|
|
|
connect(m_navigateLabel, &QLabel::linkActivated, this, [=](const QString &link) {
|
|
|
|
|
if (link == QLatin1String("goToCode")) {
|
2016-10-05 12:16:58 +02:00
|
|
|
emitGotoCodeClicked(m_messages.at(m_currentMessage));
|
2016-05-18 17:27:45 +02:00
|
|
|
} else if (link == QLatin1String("previous")) {
|
|
|
|
|
--m_currentMessage;
|
|
|
|
|
refreshContent();
|
|
|
|
|
} else if (link == QLatin1String("next")) {
|
|
|
|
|
++m_currentMessage;
|
|
|
|
|
refreshContent();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_continueButton, &QPushButton::clicked, this, [=]() {
|
2016-10-05 12:16:58 +02:00
|
|
|
if (m_mode == ErrorMode)
|
|
|
|
|
emitGotoCodeClicked(m_messages.at(m_currentMessage));
|
2017-01-10 16:36:55 +01:00
|
|
|
else
|
|
|
|
|
hide();
|
2016-04-28 14:21:33 +02:00
|
|
|
});
|
|
|
|
|
|
2016-06-23 14:38:39 +02:00
|
|
|
connect(m_ignoreWarningsCheckBox, &QCheckBox::toggled, this, &DocumentWarningWidget::ignoreCheckBoxToggled);
|
|
|
|
|
|
2016-04-28 14:21:33 +02:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
2016-05-18 17:27:45 +02:00
|
|
|
layout->addWidget(m_headerLabel);
|
|
|
|
|
QVBoxLayout *messageLayout = new QVBoxLayout;
|
|
|
|
|
messageLayout->setMargin(20);
|
|
|
|
|
messageLayout->setSpacing(5);
|
|
|
|
|
messageLayout->addWidget(m_navigateLabel);
|
|
|
|
|
messageLayout->addWidget(m_messageLabel);
|
|
|
|
|
layout->addLayout(messageLayout);
|
|
|
|
|
layout->addWidget(m_ignoreWarningsCheckBox);
|
|
|
|
|
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
|
|
|
|
buttonLayout->addStretch();
|
|
|
|
|
buttonLayout->addWidget(m_continueButton);
|
|
|
|
|
layout->addLayout(buttonLayout);
|
2016-04-29 22:15:30 +02:00
|
|
|
|
|
|
|
|
parent->installEventFilter(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocumentWarningWidget::moveToParentCenter()
|
|
|
|
|
{
|
|
|
|
|
move(parentWidget()->rect().center() - rect().center());
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 17:27:45 +02:00
|
|
|
void DocumentWarningWidget::refreshContent()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (m_mode == ErrorMode) {
|
|
|
|
|
m_headerLabel->setText(tr("Cannot open this QML document because of an error in the QML file:"));
|
|
|
|
|
m_ignoreWarningsCheckBox->hide();
|
|
|
|
|
m_continueButton->setText(tr("OK"));
|
|
|
|
|
} else {
|
|
|
|
|
m_headerLabel->setText(tr("This QML file contains features which are not supported by Qt Quick Designer at:"));
|
2016-06-23 14:38:39 +02:00
|
|
|
bool block = m_ignoreWarningsCheckBox->blockSignals(true);
|
2016-05-18 17:27:45 +02:00
|
|
|
m_ignoreWarningsCheckBox->setChecked(!warningsEnabled());
|
2016-06-23 14:38:39 +02:00
|
|
|
m_ignoreWarningsCheckBox->blockSignals(block);
|
2016-05-18 17:27:45 +02:00
|
|
|
m_ignoreWarningsCheckBox->show();
|
|
|
|
|
m_continueButton->setText(tr("Ignore"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString messageString;
|
2017-01-10 17:08:14 +01:00
|
|
|
DocumentMessage message = m_messages.at(m_currentMessage);
|
|
|
|
|
if (message.type() == DocumentMessage::ParseError) {
|
2016-05-18 17:27:45 +02:00
|
|
|
messageString += errorToString(message);
|
|
|
|
|
m_navigateLabel->setText(generateNavigateLinks());
|
|
|
|
|
m_navigateLabel->show();
|
|
|
|
|
} else {
|
|
|
|
|
messageString += message.toString();
|
|
|
|
|
m_navigateLabel->hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_messageLabel->setText(messageString);
|
|
|
|
|
resize(layout()->totalSizeHint());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DocumentWarningWidget::generateNavigateLinks()
|
|
|
|
|
{
|
2016-09-23 15:46:41 +02:00
|
|
|
static const QString link("<a href=\"%1\">%2</a>");
|
2016-05-18 17:27:45 +02:00
|
|
|
QStringList links;
|
|
|
|
|
if (m_messages.count() > 1) {
|
|
|
|
|
if (m_currentMessage != 0)
|
|
|
|
|
links << link.arg(QLatin1String("previous"), tr("Previous"));
|
|
|
|
|
else
|
|
|
|
|
links << tr("Previous");
|
|
|
|
|
|
|
|
|
|
if (m_messages.count() - 1 > m_currentMessage)
|
|
|
|
|
links << link.arg(QLatin1String("next"), tr("Next"));
|
|
|
|
|
else
|
|
|
|
|
links << tr("Next");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_mode == ErrorMode)
|
|
|
|
|
links << link.arg(QLatin1String("goToCode"), tr("Go to error"));
|
|
|
|
|
else
|
|
|
|
|
links << link.arg(QLatin1String("goToCode"), tr("Go to warning"));
|
|
|
|
|
return links.join(QLatin1String(" | "));
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-29 22:15:30 +02:00
|
|
|
bool DocumentWarningWidget::eventFilter(QObject *object, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->type() == QEvent::Resize) {
|
|
|
|
|
moveToParentCenter();
|
|
|
|
|
}
|
|
|
|
|
return QObject::eventFilter(object, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocumentWarningWidget::showEvent(QShowEvent *event)
|
|
|
|
|
{
|
2016-10-07 13:50:17 +02:00
|
|
|
const QColor backgroundColor = Utils::creatorTheme()->color(Utils::Theme::QmlDesigner_BackgroundColor);
|
|
|
|
|
QPalette pal = palette();
|
|
|
|
|
QColor color = pal.color(QPalette::ToolTipBase);
|
|
|
|
|
const QColor backgroundNoAlpha = Utils::StyleHelper::alphaBlendedColors(color, backgroundColor);
|
|
|
|
|
color.setAlpha(255);
|
|
|
|
|
pal.setColor(QPalette::ToolTipBase, backgroundNoAlpha);
|
|
|
|
|
setPalette(pal);
|
2016-10-05 12:16:58 +02:00
|
|
|
m_gotoCodeWasClicked = false;
|
2016-04-29 22:15:30 +02:00
|
|
|
moveToParentCenter();
|
2016-05-18 17:27:45 +02:00
|
|
|
refreshContent();
|
2016-04-29 22:15:30 +02:00
|
|
|
Utils::FakeToolTip::showEvent(event);
|
2016-04-28 14:21:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-05 12:16:58 +02:00
|
|
|
bool DocumentWarningWidget::gotoCodeWasClicked()
|
|
|
|
|
{
|
|
|
|
|
return m_gotoCodeWasClicked;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-10 17:08:14 +01:00
|
|
|
void DocumentWarningWidget::emitGotoCodeClicked(const DocumentMessage &message)
|
2016-10-05 12:16:58 +02:00
|
|
|
{
|
|
|
|
|
m_gotoCodeWasClicked = true;
|
|
|
|
|
emit gotoCodeClicked(message.url().toLocalFile(), message.line(), message.column() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 17:27:45 +02:00
|
|
|
bool DocumentWarningWidget::warningsEnabled() const
|
2016-04-28 14:21:33 +02:00
|
|
|
{
|
2016-05-18 17:27:45 +02:00
|
|
|
DesignerSettings settings = QmlDesignerPlugin::instance()->settings();
|
|
|
|
|
return settings.value(DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER).toBool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocumentWarningWidget::ignoreCheckBoxToggled(bool b)
|
|
|
|
|
{
|
|
|
|
|
DesignerSettings settings = QmlDesignerPlugin::instance()->settings();
|
2016-06-23 14:38:39 +02:00
|
|
|
settings.insert(DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER, !b);
|
2016-05-18 17:27:45 +02:00
|
|
|
QmlDesignerPlugin::instance()->setSettings(settings);
|
|
|
|
|
}
|
2016-04-28 14:21:33 +02:00
|
|
|
|
2017-01-10 17:08:14 +01:00
|
|
|
void DocumentWarningWidget::setErrors(const QList<DocumentMessage> &errors)
|
2016-05-18 17:27:45 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(!errors.empty());
|
|
|
|
|
m_mode = ErrorMode;
|
|
|
|
|
setMessages(errors);
|
|
|
|
|
}
|
2016-04-28 14:21:33 +02:00
|
|
|
|
2017-01-10 17:08:14 +01:00
|
|
|
void DocumentWarningWidget::setWarnings(const QList<DocumentMessage> &warnings)
|
2016-05-18 17:27:45 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(!warnings.empty());
|
|
|
|
|
m_mode = WarningMode;
|
|
|
|
|
setMessages(warnings);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-10 17:08:14 +01:00
|
|
|
void DocumentWarningWidget::setMessages(const QList<DocumentMessage> &messages)
|
2016-05-18 17:27:45 +02:00
|
|
|
{
|
|
|
|
|
m_messages.clear();
|
|
|
|
|
m_messages = messages;
|
|
|
|
|
m_currentMessage = 0;
|
|
|
|
|
refreshContent();
|
2016-04-28 14:21:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Designer
|