forked from qt-creator/qt-creator
Added a QML designer settings page.
This commit is contained in:
67
src/plugins/qmldesigner/designersettings.cpp
Normal file
67
src/plugins/qmldesigner/designersettings.cpp
Normal file
@@ -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 <QtCore/QSettings>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
59
src/plugins/qmldesigner/designersettings.h
Normal file
59
src/plugins/qmldesigner/designersettings.h
Normal file
@@ -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 <QtCore/QtGlobal>
|
||||||
|
|
||||||
|
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
|
||||||
@@ -51,6 +51,8 @@
|
|||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
BauhausPlugin *BauhausPlugin::m_pluginInstance = 0;
|
||||||
|
|
||||||
BauhausPlugin::BauhausPlugin() :
|
BauhausPlugin::BauhausPlugin() :
|
||||||
m_designerCore(0)
|
m_designerCore(0)
|
||||||
{
|
{
|
||||||
@@ -85,6 +87,8 @@ bool BauhausPlugin::initialize(const QStringList & /*arguments*/, QString *error
|
|||||||
|
|
||||||
m_designerCore = new QmlDesigner::IntegrationCore;
|
m_designerCore = new QmlDesigner::IntegrationCore;
|
||||||
|
|
||||||
|
m_pluginInstance = this;
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
const QString pluginPath = QCoreApplication::applicationDirPath() + "/../PlugIns/QmlDesigner";
|
const QString pluginPath = QCoreApplication::applicationDirPath() + "/../PlugIns/QmlDesigner";
|
||||||
#else
|
#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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,8 @@
|
|||||||
#ifndef QMLDESIGNERPLUGIN_H
|
#ifndef QMLDESIGNERPLUGIN_H
|
||||||
#define QMLDESIGNERPLUGIN_H
|
#define QMLDESIGNERPLUGIN_H
|
||||||
|
|
||||||
|
#include <qmldesigner/designersettings.h>
|
||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -58,8 +60,15 @@ public:
|
|||||||
virtual bool initialize(const QStringList &arguments, QString *error_message = 0);
|
virtual bool initialize(const QStringList &arguments, QString *error_message = 0);
|
||||||
virtual void extensionsInitialized();
|
virtual void extensionsInitialized();
|
||||||
|
|
||||||
|
static BauhausPlugin *pluginInstance();
|
||||||
|
|
||||||
|
DesignerSettings settings() const;
|
||||||
|
void setSettings(const DesignerSettings &s);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QmlDesigner::IntegrationCore *m_designerCore;
|
QmlDesigner::IntegrationCore *m_designerCore;
|
||||||
|
static BauhausPlugin *m_pluginInstance;
|
||||||
|
DesignerSettings m_settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -19,11 +19,16 @@ HEADERS += qmldesignerconstants.h \
|
|||||||
qmldesignerplugin.h \
|
qmldesignerplugin.h \
|
||||||
designmode.h \
|
designmode.h \
|
||||||
designmodewidget.h \
|
designmodewidget.h \
|
||||||
application.h
|
application.h \
|
||||||
|
designersettings.h \
|
||||||
|
settingspage.h
|
||||||
SOURCES += qmldesignerplugin.cpp \
|
SOURCES += qmldesignerplugin.cpp \
|
||||||
designmode.cpp \
|
designmode.cpp \
|
||||||
designmodewidget.cpp \
|
designmodewidget.cpp \
|
||||||
application.cpp
|
application.cpp \
|
||||||
|
designersettings.cpp \
|
||||||
|
settingspage.cpp
|
||||||
|
FORMS += settingspage.ui
|
||||||
|
|
||||||
OTHER_FILES += QmlDesigner.pluginspec
|
OTHER_FILES += QmlDesigner.pluginspec
|
||||||
RESOURCES += qmldesignerplugin.qrc
|
RESOURCES += qmldesignerplugin.qrc
|
||||||
|
|||||||
114
src/plugins/qmldesigner/settingspage.cpp
Normal file
114
src/plugins/qmldesigner/settingspage.cpp
Normal file
@@ -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 <QtCore/QTextStream>
|
||||||
|
#include <QtGui/QCheckBox>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
91
src/plugins/qmldesigner/settingspage.h
Normal file
91
src/plugins/qmldesigner/settingspage.h
Normal file
@@ -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 <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
|
#include <QtGui/QWidget>
|
||||||
|
|
||||||
|
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
|
||||||
57
src/plugins/qmldesigner/settingspage.ui
Normal file
57
src/plugins/qmldesigner/settingspage.ui
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>QmlDesigner::Internal::SettingsPage</class>
|
||||||
|
<widget class="QWidget" name="QmlDesigner::Internal::SettingsPage">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>GroupBox</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="snapToGridCheckbox">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Snap to Grid</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="showBoundingRectanglesCheckbox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show Bounding Rectangles</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>207</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user