diff --git a/src/plugins/qmldesigner/designersettings.cpp b/src/plugins/qmldesigner/designersettings.cpp new file mode 100644 index 00000000000..a059c3f449f --- /dev/null +++ b/src/plugins/qmldesigner/designersettings.cpp @@ -0,0 +1,67 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "designersettings.h" + +#include + +using namespace QmlDesigner; + +static const char *qmlGroup = "Qml"; +static const char *qmlDesignerGroup = "Designer"; +static const char *snapToGridKey = "SnapToGrid"; +static const char *showBoundingRectanglesKey = "ShowBoundingRectangles"; + +void DesignerSettings::fromSettings(QSettings *settings) +{ + settings->beginGroup(QLatin1String(qmlGroup)); + settings->beginGroup(QLatin1String(qmlDesignerGroup)); + snapToGrid = settings->value(QLatin1String(snapToGridKey), false).toBool(); + showBoundingRectangles = settings->value( + QLatin1String(showBoundingRectanglesKey), false).toBool(); + settings->endGroup(); + settings->endGroup(); +} + +void DesignerSettings::toSettings(QSettings *settings) const +{ + settings->beginGroup(QLatin1String(qmlGroup)); + settings->beginGroup(QLatin1String(qmlDesignerGroup)); + settings->setValue(QLatin1String(snapToGridKey), snapToGrid); + settings->setValue(QLatin1String(showBoundingRectanglesKey), + showBoundingRectangles); + settings->endGroup(); + settings->endGroup(); +} + +bool DesignerSettings::equals(const DesignerSettings &other) const +{ + return snapToGrid == other.snapToGrid + && showBoundingRectangles == other.showBoundingRectangles; +} diff --git a/src/plugins/qmldesigner/designersettings.h b/src/plugins/qmldesigner/designersettings.h new file mode 100644 index 00000000000..db0829db034 --- /dev/null +++ b/src/plugins/qmldesigner/designersettings.h @@ -0,0 +1,59 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + + +#ifndef DESIGNERSETTINGS_H +#define DESIGNERSETTINGS_H + +#include + +QT_BEGIN_NAMESPACE +class QSettings; +QT_END_NAMESPACE + +namespace QmlDesigner { + +struct DesignerSettings { + void fromSettings(QSettings *); + void toSettings(QSettings *) const; + + bool equals(const DesignerSettings &other) const; + + bool snapToGrid; + bool showBoundingRectangles; +}; + +inline bool operator==(const DesignerSettings &s1, const DesignerSettings &s2) +{ return s1.equals(s2); } +inline bool operator!=(const DesignerSettings &s1, const DesignerSettings &s2) +{ return !s1.equals(s2); } + +} // namespace QmlDesigner + +#endif // DESIGNERSETTINGS_H diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index 89f501bd4fd..4a40842e85e 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -51,6 +51,8 @@ namespace QmlDesigner { namespace Internal { +BauhausPlugin *BauhausPlugin::m_pluginInstance = 0; + BauhausPlugin::BauhausPlugin() : m_designerCore(0) { @@ -85,6 +87,8 @@ bool BauhausPlugin::initialize(const QStringList & /*arguments*/, QString *error m_designerCore = new QmlDesigner::IntegrationCore; + m_pluginInstance = this; + #ifdef Q_OS_MAC const QString pluginPath = QCoreApplication::applicationDirPath() + "/../PlugIns/QmlDesigner"; #else @@ -105,6 +109,25 @@ void BauhausPlugin::extensionsInitialized() { } +BauhausPlugin *BauhausPlugin::pluginInstance() +{ + return m_pluginInstance; +} + +DesignerSettings BauhausPlugin::settings() const +{ + return m_settings; +} + +void BauhausPlugin::setSettings(const DesignerSettings &s) +{ + if (s != m_settings) { + m_settings = s; + if (QSettings *settings = Core::ICore::instance()->settings()) + m_settings.toSettings(settings); + } +} + } } diff --git a/src/plugins/qmldesigner/qmldesignerplugin.h b/src/plugins/qmldesigner/qmldesignerplugin.h index d95386789e4..3ef88fbae0b 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.h +++ b/src/plugins/qmldesigner/qmldesignerplugin.h @@ -30,6 +30,8 @@ #ifndef QMLDESIGNERPLUGIN_H #define QMLDESIGNERPLUGIN_H +#include + #include namespace Core { @@ -58,8 +60,15 @@ public: virtual bool initialize(const QStringList &arguments, QString *error_message = 0); virtual void extensionsInitialized(); + static BauhausPlugin *pluginInstance(); + + DesignerSettings settings() const; + void setSettings(const DesignerSettings &s); + private: QmlDesigner::IntegrationCore *m_designerCore; + static BauhausPlugin *m_pluginInstance; + DesignerSettings m_settings; }; } // namespace Internal diff --git a/src/plugins/qmldesigner/qmldesignerplugin.pro b/src/plugins/qmldesigner/qmldesignerplugin.pro index ad820316be9..814f1952e64 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.pro +++ b/src/plugins/qmldesigner/qmldesignerplugin.pro @@ -19,11 +19,16 @@ HEADERS += qmldesignerconstants.h \ qmldesignerplugin.h \ designmode.h \ designmodewidget.h \ - application.h + application.h \ + designersettings.h \ + settingspage.h SOURCES += qmldesignerplugin.cpp \ designmode.cpp \ designmodewidget.cpp \ - application.cpp + application.cpp \ + designersettings.cpp \ + settingspage.cpp +FORMS += settingspage.ui OTHER_FILES += QmlDesigner.pluginspec RESOURCES += qmldesignerplugin.qrc diff --git a/src/plugins/qmldesigner/settingspage.cpp b/src/plugins/qmldesigner/settingspage.cpp new file mode 100644 index 00000000000..f1b943cf1f1 --- /dev/null +++ b/src/plugins/qmldesigner/settingspage.cpp @@ -0,0 +1,114 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "designersettings.h" +#include "qmldesignerconstants.h" +#include "qmldesignerplugin.h" +#include "settingspage.h" + +#include +#include + +using namespace QmlDesigner; +using namespace QmlDesigner::Internal; + +SettingsPageWidget::SettingsPageWidget(QWidget *parent) : + QWidget(parent) +{ + m_ui.setupUi(this); +} + +DesignerSettings SettingsPageWidget::settings() const +{ + DesignerSettings ds; + ds.snapToGrid = m_ui.snapToGridCheckbox->isChecked(); + ds.showBoundingRectangles = m_ui.showBoundingRectanglesCheckbox->isChecked(); + return ds; +} + +void SettingsPageWidget::setSettings(const DesignerSettings &s) +{ + m_ui.snapToGridCheckbox->setChecked(s.snapToGrid); + m_ui.showBoundingRectanglesCheckbox->setChecked(s.showBoundingRectangles); +} + +QString SettingsPageWidget::searchKeywords() const +{ + QString rc; + QTextStream(&rc) + << m_ui.snapToGridCheckbox->text() + << m_ui.showBoundingRectanglesCheckbox->text() + << ' ' << m_ui.groupBox->title(); + rc.remove(QLatin1Char('&')); + return rc; +} + +SettingsPage::SettingsPage() : + m_widget(0) +{ +} + +QString SettingsPage::id() const +{ + return QLatin1String("QmlDesigner"); +} + +QString SettingsPage::displayName() const +{ + return tr("Designer"); +} + +QString SettingsPage::category() const +{ + return QLatin1String("Qml"); +} + +QString SettingsPage::displayCategory() const +{ + return QCoreApplication::translate("Qml", "QML"); +} + +QWidget *SettingsPage::createPage(QWidget *parent) +{ + m_widget = new SettingsPageWidget(parent); + m_widget->setSettings(BauhausPlugin::pluginInstance()->settings()); + if (m_searchKeywords.isEmpty()) + m_searchKeywords = m_widget->searchKeywords(); + return m_widget; +} + +void SettingsPage::apply() +{ + BauhausPlugin::pluginInstance()->setSettings(m_widget->settings()); +} + +bool SettingsPage::matches(const QString &s) const +{ + return m_searchKeywords.contains(s, Qt::CaseInsensitive); +} diff --git a/src/plugins/qmldesigner/settingspage.h b/src/plugins/qmldesigner/settingspage.h new file mode 100644 index 00000000000..112b2dfd550 --- /dev/null +++ b/src/plugins/qmldesigner/settingspage.h @@ -0,0 +1,91 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + + +#ifndef SETTINGSPAGE_H +#define SETTINGSPAGE_H + +#include "ui_settingspage.h" + +#include + +#include + +QT_BEGIN_NAMESPACE +class QSettings; +QT_END_NAMESPACE + +namespace QmlDesigner { + +class DesignerSettings; + +namespace Internal { + +class SettingsPageWidget : public QWidget +{ + Q_OBJECT +public: + explicit SettingsPageWidget(QWidget *parent = 0); + + DesignerSettings settings() const; + void setSettings(const DesignerSettings &); + + QString searchKeywords() const; + +private: + Ui::SettingsPage m_ui; +}; + + +class SettingsPage : public Core::IOptionsPage +{ + Q_OBJECT + +public: + SettingsPage(); + + QString id() const; + QString displayName() const; + QString category() const; + QString displayCategory() const; + + QWidget *createPage(QWidget *parent); + void apply(); + void finish() { } + virtual bool matches(const QString &) const; + +private: + QString m_searchKeywords; + SettingsPageWidget* m_widget; +}; + +} // namespace Internal +} // namespace QmlDesigner + +#endif // SETTINGSPAGE_H diff --git a/src/plugins/qmldesigner/settingspage.ui b/src/plugins/qmldesigner/settingspage.ui new file mode 100644 index 00000000000..dfdf3b3805b --- /dev/null +++ b/src/plugins/qmldesigner/settingspage.ui @@ -0,0 +1,57 @@ + + + QmlDesigner::Internal::SettingsPage + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + GroupBox + + + + + + &Snap to Grid + + + + + + + Show Bounding Rectangles + + + + + + + + + + Qt::Vertical + + + + 20 + 207 + + + + + + + + +