/**************************************************************************** ** ** 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 "settingspage.h" #include "qmldesignerconstants.h" #include "qmldesignerplugin.h" #include "designersettings.h" #include "puppetcreator.h" #include #include #include #include #include #include using namespace QmlDesigner; using namespace QmlDesigner::Internal; SettingsPageWidget::SettingsPageWidget(QWidget *parent) : QWidget(parent) { m_ui.setupUi(this); connect(m_ui.designerEnableDebuggerCheckBox, &QCheckBox::toggled, this, &SettingsPageWidget::debugViewEnabledToggled); m_ui.resetFallbackPuppetPathButton->hide(); connect(m_ui.resetFallbackPuppetPathButton, &QPushButton::clicked, this, &SettingsPageWidget::resetFallbackPuppetPath); connect(m_ui.resetQmlPuppetBuildPathButton, &QPushButton::clicked, this, &SettingsPageWidget::resetQmlPuppetBuildPath); connect(m_ui.useDefaultPuppetRadioButton, &QRadioButton::toggled, m_ui.fallbackPuppetPathLineEdit, &QLineEdit::setEnabled); connect(m_ui.useQtRelatedPuppetRadioButton, &QRadioButton::toggled, m_ui.puppetBuildPathLineEdit, &QLineEdit::setEnabled); connect(m_ui.resetStyle, &QPushButton::clicked, this, &SettingsPageWidget::resetQmlStyle); } DesignerSettings SettingsPageWidget::settings() const { DesignerSettings settings = QmlDesignerPlugin::instance()->settings(); settings.insert(DesignerSettingsKey::ITEMSPACING, m_ui.spinItemSpacing->value()); settings.insert(DesignerSettingsKey::CONTAINERPADDING, m_ui.spinSnapMargin->value()); settings.insert(DesignerSettingsKey::CANVASWIDTH, m_ui.spinCanvasWidth->value()); settings.insert(DesignerSettingsKey::CANVASHEIGHT, m_ui.spinCanvasHeight->value()); settings.insert(DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER, m_ui.designerWarningsCheckBox->isChecked()); settings.insert(DesignerSettingsKey::WARNING_FOR_DESIGNER_FEATURES_IN_EDITOR, m_ui.designerWarningsInEditorCheckBox->isChecked()); settings.insert(DesignerSettingsKey::SHOW_DEBUGVIEW, m_ui.designerShowDebuggerCheckBox->isChecked()); settings.insert(DesignerSettingsKey::ENABLE_DEBUGVIEW, m_ui.designerEnableDebuggerCheckBox->isChecked()); settings.insert(DesignerSettingsKey::USE_ONLY_FALLBACK_PUPPET, m_ui.useDefaultPuppetRadioButton->isChecked()); settings.insert(DesignerSettingsKey::USE_QSTR_FUNCTION, m_ui.useQsTrFunctionRadioButton->isChecked()); settings.insert(DesignerSettingsKey::CONTROLS_STYLE, m_ui.styleLineEdit->text()); if (!m_ui.fallbackPuppetPathLineEdit->path().isEmpty() && m_ui.fallbackPuppetPathLineEdit->path() != PuppetCreator::defaultPuppetFallbackDirectory()) { settings.insert(DesignerSettingsKey::PUPPET_FALLBACK_DIRECTORY, m_ui.fallbackPuppetPathLineEdit->path()); } if (!m_ui.puppetBuildPathLineEdit->path().isEmpty() && m_ui.puppetBuildPathLineEdit->path() != PuppetCreator::defaultPuppetToplevelBuildDirectory()) { settings.insert(DesignerSettingsKey::PUPPET_TOPLEVEL_BUILD_DIRECTORY, m_ui.puppetBuildPathLineEdit->path()); } return settings; } void SettingsPageWidget::setSettings(const DesignerSettings &settings) { m_ui.spinItemSpacing->setValue(settings.value( DesignerSettingsKey::ITEMSPACING).toInt()); m_ui.spinSnapMargin->setValue(settings.value( DesignerSettingsKey::CONTAINERPADDING).toInt()); m_ui.spinCanvasWidth->setValue(settings.value( DesignerSettingsKey::CANVASWIDTH).toInt()); m_ui.spinCanvasHeight->setValue(settings.value( DesignerSettingsKey::CANVASHEIGHT).toInt()); m_ui.designerWarningsCheckBox->setChecked(settings.value( DesignerSettingsKey::WARNING_FOR_FEATURES_IN_DESIGNER).toBool()); m_ui.designerWarningsInEditorCheckBox->setChecked(settings.value( DesignerSettingsKey::WARNING_FOR_DESIGNER_FEATURES_IN_EDITOR).toBool()); m_ui.designerShowDebuggerCheckBox->setChecked(settings.value( DesignerSettingsKey::SHOW_DEBUGVIEW).toBool()); m_ui.designerEnableDebuggerCheckBox->setChecked(settings.value( DesignerSettingsKey::ENABLE_DEBUGVIEW).toBool()); m_ui.useDefaultPuppetRadioButton->setChecked(settings.value( DesignerSettingsKey::USE_ONLY_FALLBACK_PUPPET).toBool()); m_ui.useQtRelatedPuppetRadioButton->setChecked(!settings.value( DesignerSettingsKey::USE_ONLY_FALLBACK_PUPPET).toBool()); m_ui.useQsTrFunctionRadioButton->setChecked(settings.value( DesignerSettingsKey::USE_QSTR_FUNCTION).toBool()); m_ui.useQsTrIdFunctionRadioButton->setChecked(!settings.value( DesignerSettingsKey::USE_QSTR_FUNCTION).toBool()); m_ui.styleLineEdit->setText(settings.value( DesignerSettingsKey::CONTROLS_STYLE).toString()); QString puppetFallbackDirectory = settings.value( DesignerSettingsKey::PUPPET_FALLBACK_DIRECTORY).toString(); if (puppetFallbackDirectory.isEmpty()) resetFallbackPuppetPath(); else m_ui.fallbackPuppetPathLineEdit->setPath(puppetFallbackDirectory); QString puppetToplevelBuildDirectory = settings.value( DesignerSettingsKey::PUPPET_TOPLEVEL_BUILD_DIRECTORY).toString(); if (puppetToplevelBuildDirectory.isEmpty()) resetQmlPuppetBuildPath(); else m_ui.puppetBuildPathLineEdit->setPath(puppetToplevelBuildDirectory); } void SettingsPageWidget::resetFallbackPuppetPath() { m_ui.fallbackPuppetPathLineEdit->setPath(PuppetCreator::defaultPuppetFallbackDirectory()); } void SettingsPageWidget::resetQmlPuppetBuildPath() { m_ui.puppetBuildPathLineEdit->setPath(PuppetCreator::defaultPuppetToplevelBuildDirectory()); } void SettingsPageWidget::resetQmlStyle() { m_ui.styleLineEdit->setText(QString()); } void SettingsPageWidget::debugViewEnabledToggled(bool b) { if (b && ! m_ui.designerShowDebuggerCheckBox->isChecked()) m_ui.designerShowDebuggerCheckBox->setChecked(true); } SettingsPage::SettingsPage() : m_widget(0) { setId("B.QmlDesigner"); setDisplayName(tr("Qt Quick Designer")); setCategory(QmlJSEditor::Constants::SETTINGS_CATEGORY_QML); setDisplayCategory(QCoreApplication::translate("QmlJSEditor", QmlJSEditor::Constants::SETTINGS_TR_CATEGORY_QML)); setCategoryIcon(QLatin1String(QmlJSTools::Constants::SETTINGS_CATEGORY_QML_ICON)); } QWidget *SettingsPage::widget() { if (!m_widget) { m_widget = new SettingsPageWidget; m_widget->setSettings(QmlDesignerPlugin::instance()->settings()); } return m_widget; } void SettingsPage::apply() { if (!m_widget) // page was never shown return; DesignerSettings currentSettings(QmlDesignerPlugin::instance()->settings()); DesignerSettings newSettings(m_widget->settings()); if (currentSettings.value(DesignerSettingsKey::PUPPET_FALLBACK_DIRECTORY) != newSettings.value(DesignerSettingsKey::PUPPET_FALLBACK_DIRECTORY) || currentSettings.value(DesignerSettingsKey::PUPPET_TOPLEVEL_BUILD_DIRECTORY) != newSettings.value(DesignerSettingsKey::PUPPET_TOPLEVEL_BUILD_DIRECTORY)) { QMessageBox::information(Core::ICore::mainWindow(), tr("Restart Required"), tr("The QML emulation layer path changes will take effect after a " "restart of the QML Emulation layer or Qt Creator.")); } QmlDesignerPlugin::instance()->setSettings(newSettings); } void SettingsPage::finish() { delete m_widget; }