Files
qt-creator/src/plugins/qmldesigner/settingspage.cpp

132 lines
3.7 KiB
C++
Raw Normal View History

2010-02-09 11:09:11 +01:00
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
2010-02-09 11:09:11 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
2010-02-09 11:09:11 +01:00
**
**
** GNU Lesser General Public License Usage
**
2011-04-13 08:42:33 +02:00
** 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.
2010-02-09 11:09:11 +01:00
**
2010-12-17 16:01:08 +01:00
** In addition, as a special exception, Nokia gives you certain additional
2011-04-13 08:42:33 +02:00
** rights. These rights are described in the Nokia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
2011-04-13 08:42:33 +02:00
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
2010-12-17 16:01:08 +01:00
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
2010-02-09 11:09:11 +01:00
**
**************************************************************************/
#include "designersettings.h"
#include "qmldesignerconstants.h"
#include "qmldesignerplugin.h"
#include "settingspage.h"
#include <qmljseditor/qmljseditorconstants.h>
2010-02-09 11:09:11 +01:00
#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.itemSpacing = m_ui.spinItemSpacing->value();
ds.snapMargin = m_ui.spinSnapMargin->value();
ds.canvasWidth = m_ui.spinCanvasWidth->value();
ds.canvasHeight = m_ui.spinCanvasHeight->value();
2010-02-09 11:09:11 +01:00
return ds;
}
void SettingsPageWidget::setSettings(const DesignerSettings &s)
{
m_ui.spinItemSpacing->setValue(s.itemSpacing);
m_ui.spinSnapMargin->setValue(s.snapMargin);
m_ui.spinCanvasWidth->setValue(s.canvasWidth);
m_ui.spinCanvasHeight->setValue(s.canvasHeight);
2010-02-09 11:09:11 +01:00
}
QString SettingsPageWidget::searchKeywords() const
{
QString rc;
QTextStream(&rc)
<< ' ' << m_ui.snapMarginLabel->text()
<< ' ' << m_ui.itemSpacingLabel->text()
<< ' ' << m_ui.canvasWidthLabel->text()
<< ' ' << m_ui.canvasHeightLabel->text();
2010-02-09 11:09:11 +01:00
rc.remove(QLatin1Char('&'));
return rc;
}
SettingsPage::SettingsPage() :
m_widget(0)
{
}
QString SettingsPage::id() const
{
return QLatin1String("B.QmlDesigner");
2010-02-09 11:09:11 +01:00
}
QString SettingsPage::displayName() const
{
return tr("Qt Quick Designer");
2010-02-09 11:09:11 +01:00
}
QString SettingsPage::category() const
{
return QLatin1String(QmlJSEditor::Constants::SETTINGS_CATEGORY_QML);
2010-02-09 11:09:11 +01:00
}
QString SettingsPage::displayCategory() const
{
return QCoreApplication::translate("QmlJSEditor", QmlJSEditor::Constants::SETTINGS_TR_CATEGORY_QML);
2010-02-09 11:09:11 +01:00
}
QIcon SettingsPage::categoryIcon() const
{
2010-05-14 11:03:30 +02:00
return QIcon(QLatin1String(Constants::SETTINGS_CATEGORY_QML_ICON));
}
2010-02-09 11:09:11 +01:00
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()
{
if (!m_widget) // page was never shown
return;
2010-02-09 11:09:11 +01:00
BauhausPlugin::pluginInstance()->setSettings(m_widget->settings());
}
bool SettingsPage::matches(const QString &s) const
{
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
}