diff --git a/src/plugins/qmljseditor/qmljseditor.pro b/src/plugins/qmljseditor/qmljseditor.pro index 7695cbf94806fc92bdb7ecc3bebc82079427d1e7..f976a7b02371f5f4612b514ae6e55ffea0c14a22 100644 --- a/src/plugins/qmljseditor/qmljseditor.pro +++ b/src/plugins/qmljseditor/qmljseditor.pro @@ -28,7 +28,10 @@ HEADERS += \ qmloutlinemodel.h \ qmltaskmanager.h \ qmljseditorcodeformatter.h \ - qmljsoutlinetreeview.h + qmljsoutlinetreeview.h \ + quicktoolbarsettingspage.h \ + quicktoolbar.h + SOURCES += \ qmljscodecompletion.cpp \ @@ -50,7 +53,13 @@ SOURCES += \ qmltaskmanager.cpp \ qmljsquickfixes.cpp \ qmljseditorcodeformatter.cpp \ - qmljsoutlinetreeview.cpp + qmljsoutlinetreeview.cpp \ + quicktoolbarsettingspage.cpp \ + quicktoolbar.cpp + RESOURCES += qmljseditor.qrc OTHER_FILES += QmlJSEditor.pluginspec QmlJSEditor.mimetypes.xml + +FORMS += \ + quicktoolbarsettingspage.ui diff --git a/src/plugins/qmljseditor/qmljseditor_dependencies.pri b/src/plugins/qmljseditor/qmljseditor_dependencies.pri index c0d9f42682596ff8e88f03ec4ef91d17337e2363..97beaaa74601f9a983607ab72f22ff0091e865a8 100644 --- a/src/plugins/qmljseditor/qmljseditor_dependencies.pri +++ b/src/plugins/qmljseditor/qmljseditor_dependencies.pri @@ -3,3 +3,4 @@ include(../../plugins/texteditor/texteditor.pri) include(../../plugins/projectexplorer/projectexplorer.pri) include(../../libs/qmljs/qmljs.pri) include(../../libs/utils/utils.pri) +include(../../libs/qmleditorwidgets/qmleditorwidgets.pri) diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index 7b4ba9e138ea2d188024753ff7cd70d37f292e4e..413bcb9346feda5ca383e57430b409fa133388e1 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -41,6 +41,8 @@ #include "qmljsquickfix.h" #include "qmljs/qmljsicons.h" #include "qmltaskmanager.h" +#include "quicktoolbar.h" +#include "quicktoolbarsettingspage.h" #include <qmldesigner/qmldesignerconstants.h> @@ -197,6 +199,9 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e connect(m_modelManager, SIGNAL(aboutToRemoveFiles(QStringList)), m_qmlTaskManager, SLOT(documentsRemoved(QStringList))); + addAutoReleasedObject(new QuickToolBar); + addAutoReleasedObject(new Internal::QuickToolBarSettingsPage); + return true; } diff --git a/src/plugins/qmljseditor/quicktoolbar.cpp b/src/plugins/qmljseditor/quicktoolbar.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8eab13aa2293248aa21be9a8b75c4b7452a246fc --- /dev/null +++ b/src/plugins/qmljseditor/quicktoolbar.cpp @@ -0,0 +1,386 @@ +#include "quicktoolbar.h" +#include <contextpanewidget.h> +#include <quicktoolbarsettingspage.h> + +#include <utils/changeset.h> +#include <qmljs/parser/qmljsast_p.h> +#include <qmljs/qmljsdocument.h> +#include <qmljs/qmljspropertyreader.h> +#include <qmljs/qmljsrewriter.h> +#include <qmljs/qmljsindenter.h> +#include <qmljs/qmljslookupcontext.h> +#include <qmljs/qmljsinterpreter.h> +#include <qmljs/qmljsbind.h> +#include <qmljs/qmljsscopebuilder.h> +#include <texteditor/basetexteditor.h> +#include <texteditor/tabsettings.h> +#include <coreplugin/icore.h> +#include <customcolordialog.h> +#include <QDebug> + +using namespace QmlJS; +using namespace AST; +using namespace QmlEditorWidgets; + +namespace QmlJSEditor { + +static inline QString textAt(const Document* doc, + const SourceLocation &from, + const SourceLocation &to) +{ + return doc->source().mid(from.offset, to.end() - from.begin()); +} + +QuickToolBar::QuickToolBar(QObject *parent) : ::QmlJS::IContextPane(parent), m_blockWriting(false) +{ + m_node = 0; + contextWidget(); + + m_propertyOrder + << QLatin1String("id") + << QLatin1String("name") + << QLatin1String("target") + << QLatin1String("property") + << QLatin1String("x") + << QLatin1String("y") + << QLatin1String("width") + << QLatin1String("height") + << QLatin1String("position") + << QLatin1String("color") + << QLatin1String("radius") + << QLatin1String("text") + << QLatin1String("font.family") + << QLatin1String("font.bold") + << QLatin1String("font.italic") + << QLatin1String("font.underline") + << QLatin1String("font.strikeout") + << QString::null + << QLatin1String("states") + << QLatin1String("transitions") + ; +} + +QuickToolBar::~QuickToolBar() +{ + //if the pane was never activated the widget is not in a widget tree + if (!m_widget.isNull()) + delete m_widget.data(); + m_widget.clear(); +} + +void QuickToolBar::apply(TextEditor::BaseTextEditorEditable *editor, Document::Ptr doc, const QmlJS::Snapshot &snapshot, AST::Node *node, bool update, bool force) +{ + if (!QuickToolBarSettings::get().enableContextPane && !force && !update) { + contextWidget()->hide(); + return; + } + + if (doc.isNull()) + return; + + if (update && editor != m_editor) + return; //do not update for different editor + + m_blockWriting = true; + + LookupContext::Ptr lookupContext = LookupContext::create(doc, snapshot, QList<Node*>()); + const Interpreter::ObjectValue *scopeObject = doc->bind()->findQmlObject(node); + + QStringList prototypes; + while (scopeObject) { + prototypes.append(scopeObject->className()); + scopeObject = scopeObject->prototype(lookupContext->context()); + } + + setEnabled(doc->isParsedCorrectly()); + m_editor = editor; + contextWidget()->setParent(editor->widget()->parentWidget()); + contextWidget()->colorDialog()->setParent(editor->widget()->parentWidget()); + + if (cast<UiObjectDefinition*>(node) || cast<UiObjectBinding*>(node)) { + UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(node); + UiObjectBinding *objectBinding = cast<UiObjectBinding*>(node); + + QString name; + quint32 offset; + quint32 end; + UiObjectInitializer *initializer; + if (objectDefinition) { + name = objectDefinition->qualifiedTypeNameId->name->asString(); + initializer = objectDefinition->initializer; + offset = objectDefinition->firstSourceLocation().offset; + end = objectDefinition->lastSourceLocation().end(); + } else if (objectBinding) { + name = objectBinding->qualifiedTypeNameId->name->asString(); + initializer = objectBinding->initializer; + offset = objectBinding->firstSourceLocation().offset; + end = objectBinding->lastSourceLocation().end(); + } + + int line1; + int column1; + int line2; + int column2; + m_editor->convertPosition(offset, &line1, &column1); //get line + m_editor->convertPosition(end, &line2, &column2); //get line + + QRegion reg; + if (line1 > -1 && line2 > -1) + reg = m_editor->editor()->translatedLineRegion(line1 - 1, line2); + + QRect rect; + rect.setHeight(widget()->height() + 10); + rect.setWidth(reg.boundingRect().width() - reg.boundingRect().left()); + rect.moveTo(reg.boundingRect().topLeft()); + reg = reg.intersect(rect); + + if (contextWidget()->acceptsType(prototypes)) { + m_node = 0; + PropertyReader propertyReader(doc, initializer); + QTextCursor tc(editor->editor()->document()); + tc.setPosition(offset); + QPoint p1 = editor->editor()->mapToParent(editor->editor()->viewport()->mapToParent(editor->editor()->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10)); + tc.setPosition(end); + QPoint p2 = editor->editor()->mapToParent(editor->editor()->viewport()->mapToParent(editor->editor()->cursorRect(tc).bottomLeft()) + QPoint(0, 10)); + QPoint offset = QPoint(10, 0); + if (reg.boundingRect().width() < 400) + offset = QPoint(400 - reg.boundingRect().width() + 10 ,0); + QPoint p3 = editor->editor()->mapToParent(editor->editor()->viewport()->mapToParent(reg.boundingRect().topRight()) + offset); + p2.setX(p1.x()); + contextWidget()->setType(prototypes); + if (!update) + contextWidget()->activate(p3 , p1, p2, QuickToolBarSettings::get().pinContextPane); + else + contextWidget()->rePosition(p3 , p1, p2, QuickToolBarSettings::get().pinContextPane); + contextWidget()->setOptions(QuickToolBarSettings::get().enableContextPane, QuickToolBarSettings::get().pinContextPane); + contextWidget()->setPath(doc->path()); + contextWidget()->setProperties(&propertyReader); + m_doc = doc; + m_node = node; + } else { + contextWidget()->setParent(0); + contextWidget()->hide(); + contextWidget()->colorDialog()->hide(); + } + } else { + contextWidget()->setParent(0); + contextWidget()->hide(); + contextWidget()->colorDialog()->hide(); + } + + m_blockWriting = false; + +} + +bool QuickToolBar::isAvailable(TextEditor::BaseTextEditorEditable *, Document::Ptr doc, const QmlJS::Snapshot &snapshot, AST::Node *node) +{ + if (doc.isNull()) + return false; + + if (!node) + return false; + + LookupContext::Ptr lookupContext = LookupContext::create(doc, snapshot, QList<Node*>()); + const Interpreter::ObjectValue *scopeObject = doc->bind()->findQmlObject(node); + + QStringList prototypes; + + while (scopeObject) { + prototypes.append(scopeObject->className()); + scopeObject = scopeObject->prototype(lookupContext->context()); + } + + if (prototypes.contains("Rectangle") || + prototypes.contains("Image") || + prototypes.contains("BorderImage") || + prototypes.contains("TextEdit") || + prototypes.contains("TextInput") || + prototypes.contains("PropertyAnimation") || + prototypes.contains("Text")) + return true; + + return false; +} + +void QuickToolBar::setProperty(const QString &propertyName, const QVariant &value) +{ + + QString stringValue = value.toString(); + if (value.type() == QVariant::Color) + stringValue = QChar('\"') + value.toString() + QChar('\"'); + + if (cast<UiObjectDefinition*>(m_node) || cast<UiObjectBinding*>(m_node)) { + UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(m_node); + UiObjectBinding *objectBinding = cast<UiObjectBinding*>(m_node); + + UiObjectInitializer *initializer; + if (objectDefinition) + initializer = objectDefinition->initializer; + else if (objectBinding) + initializer = objectBinding->initializer; + + Utils::ChangeSet changeSet; + Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder); + + int line = -1; + int endLine; + + Rewriter::BindingType bindingType = Rewriter::ScriptBinding; + + if (stringValue.contains("{") && stringValue.contains("}")) + bindingType = Rewriter::ObjectBinding; + + PropertyReader propertyReader(m_doc, initializer); + if (propertyReader.hasProperty(propertyName)) { + rewriter.changeBinding(initializer, propertyName, stringValue, bindingType); + } else { + rewriter.addBinding(initializer, propertyName, stringValue, bindingType); + } + + int column; + + int changeSetPos = changeSet.operationList().last().pos1; + int changeSetLength = changeSet.operationList().last().text.length(); + QTextCursor tc = m_editor->editor()->textCursor(); + tc.beginEditBlock(); + changeSet.apply(&tc); + + m_editor->convertPosition(changeSetPos, &line, &column); //get line + m_editor->convertPosition(changeSetPos + changeSetLength, &endLine, &column); //get line + + if (line > 0) { + TextEditor::TabSettings ts = m_editor->editor()->tabSettings(); + QmlJSIndenter indenter; + indenter.setTabSize(ts.m_tabSize); + indenter.setIndentSize(ts.m_indentSize); + + for (int i=line;i<=endLine;i++) { + QTextBlock start = m_editor->editor()->document()->findBlockByNumber(i); + QTextBlock end = m_editor->editor()->document()->findBlockByNumber(i); + + if (end.isValid()) { + const int indent = indenter.indentForBottomLine(m_editor->editor()->document()->begin(), end.next(), QChar::Null); + ts.indentLine(start, indent); + } + } + } + tc.endEditBlock(); + } +} + +void QuickToolBar::removeProperty(const QString &propertyName) +{ + if (cast<UiObjectDefinition*>(m_node) || cast<UiObjectBinding*>(m_node)) { + UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(m_node); + UiObjectBinding *objectBinding = cast<UiObjectBinding*>(m_node); + + UiObjectInitializer *initializer; + if (objectDefinition) + initializer = objectDefinition->initializer; + else if (objectBinding) + initializer = objectBinding->initializer; + + PropertyReader propertyReader(m_doc, initializer); + if (propertyReader.hasProperty(propertyName)) { + Utils::ChangeSet changeSet; + Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder); + rewriter.removeBindingByName(initializer, propertyName); + QTextCursor tc(m_editor->editor()->document()); + changeSet.apply(&tc); + } + } +} + +void QuickToolBar::setEnabled(bool b) +{ + if (m_widget) + contextWidget()->currentWidget()->setEnabled(b); + if (!b) + widget()->hide(); +} + + +QWidget* QuickToolBar::widget() +{ + return contextWidget(); +} + + +void QuickToolBar::onPropertyChanged(const QString &name, const QVariant &value) +{ + if (m_blockWriting) + return; + if (!m_doc) + return; + + setProperty(name, value); + m_doc.clear(); //the document is outdated +} + +void QuickToolBar::onPropertyRemovedAndChange(const QString &remove, const QString &change, const QVariant &value, bool removeFirst) +{ + if (m_blockWriting) + return; + + if (!m_doc) + return; + + QTextCursor tc(m_editor->editor()->document()); + tc.beginEditBlock(); + + if (removeFirst) { + removeProperty(remove); + setProperty(change, value); + } else { + setProperty(change, value); + removeProperty(remove); + } + + + tc.endEditBlock(); + + m_doc.clear(); //the document is outdated + +} + +void QuickToolBar::onPinnedChanged(bool b) +{ + QuickToolBarSettings settings = QuickToolBarSettings::get(); + settings.pinContextPane = b; + settings.set(); +} + +void QuickToolBar::onEnabledChanged(bool b) +{ + QuickToolBarSettings settings = QuickToolBarSettings::get(); + settings.pinContextPane = b; + settings.enableContextPane = b; + settings.set(); +} + +ContextPaneWidget* QuickToolBar::contextWidget() +{ + if (m_widget.isNull()) { //lazily recreate widget + m_widget = new ContextPaneWidget; + connect(m_widget.data(), SIGNAL(propertyChanged(QString,QVariant)), this, SLOT(onPropertyChanged(QString,QVariant))); + connect(m_widget.data(), SIGNAL(removeProperty(QString)), this, SLOT(onPropertyRemoved(QString))); + connect(m_widget.data(), SIGNAL(removeAndChangeProperty(QString,QString,QVariant, bool)), this, SLOT(onPropertyRemovedAndChange(QString,QString,QVariant, bool))); + connect(m_widget.data(), SIGNAL(enabledChanged(bool)), this, SLOT(onEnabledChanged(bool))); + connect(m_widget.data(), SIGNAL(pinnedChanged(bool)), this, SLOT(onPinnedChanged(bool))); + } + return m_widget.data(); +} + +void QuickToolBar::onPropertyRemoved(const QString &propertyName) +{ + if (m_blockWriting) + return; + + if (!m_doc) + return; + + removeProperty(propertyName); + m_doc.clear(); //the document is outdated +} + +} //QmlDesigner diff --git a/src/plugins/qmljseditor/quicktoolbar.h b/src/plugins/qmljseditor/quicktoolbar.h new file mode 100644 index 0000000000000000000000000000000000000000..75ea8d54c11faa4697c795cea7a8b17b8927bf1b --- /dev/null +++ b/src/plugins/qmljseditor/quicktoolbar.h @@ -0,0 +1,59 @@ +#ifndef QUICKTOOLBAR_H +#define QUICKTOOLBAR_H + +#include <QLabel> +#include <QToolBar> +#include <QPushButton> +#include <QToolButton> +#include <QGridLayout> +#include <QGroupBox> +#include <QVariant> +#include <QGraphicsDropShadowEffect> +#include <QWeakPointer> + +#include <qmljs/qmljsicontextpane.h> + +namespace TextEditor { +class BaseTextEditorEditable; +} + +namespace QmlEditorWidgets { +class ContextPaneWidget; +} + +namespace QmlJSEditor { + +class QuickToolBar : public QmlJS::IContextPane +{ + Q_OBJECT + +public: + QuickToolBar(QObject *parent = 0); + ~QuickToolBar(); + void apply(TextEditor::BaseTextEditorEditable *editor, QmlJS::Document::Ptr doc, const QmlJS::Snapshot &snapshot, QmlJS::AST::Node *node, bool update, bool force = 0); + bool isAvailable(TextEditor::BaseTextEditorEditable *editor, QmlJS::Document::Ptr doc, const QmlJS::Snapshot &snapshot, QmlJS::AST::Node *node); + void setProperty(const QString &propertyName, const QVariant &value); + void removeProperty(const QString &propertyName); + void setEnabled(bool); + QWidget* widget(); + +public slots: + void onPropertyChanged(const QString &, const QVariant &); + void onPropertyRemoved(const QString &); + void onPropertyRemovedAndChange(const QString &, const QString &, const QVariant &, bool removeFirst = true); + void onPinnedChanged(bool); + void onEnabledChanged(bool); + +private: + QmlEditorWidgets::ContextPaneWidget* contextWidget(); + QWeakPointer<QmlEditorWidgets::ContextPaneWidget> m_widget; + QmlJS::Document::Ptr m_doc; + QmlJS::AST::Node *m_node; + TextEditor::BaseTextEditorEditable *m_editor; + bool m_blockWriting; + QStringList m_propertyOrder; +}; + +} //QmlDesigner + +#endif // QUICKTOOLBAR_H diff --git a/src/plugins/qmljseditor/quicktoolbarsettingspage.cpp b/src/plugins/qmljseditor/quicktoolbarsettingspage.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3e5e8409e7a25aa6b12c79fdcd07b646cfc653de --- /dev/null +++ b/src/plugins/qmljseditor/quicktoolbarsettingspage.cpp @@ -0,0 +1,170 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 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 <qmldesigner/qmldesignerconstants.h> +#include "quicktoolbarsettingspage.h" + +#include <coreplugin/icore.h> + +#include <QtCore/QSettings> +#include <QtCore/QTextStream> +#include <QtGui/QCheckBox> + + +using namespace QmlJSEditor; +using namespace QmlJSEditor::Internal; + +QuickToolBarSettings::QuickToolBarSettings() + : enableContextPane(false), + pinContextPane(false) +{} + +void QuickToolBarSettings::set() +{ + if (get() != *this) { + if (QSettings *settings = Core::ICore::instance()->settings()) + toSettings(settings); + } +} + +void QuickToolBarSettings::fromSettings(QSettings *settings) +{ + settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_SETTINGS_GROUP)); + settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_DESIGNER_SETTINGS_GROUP)); + enableContextPane = settings->value( + QLatin1String(QmlDesigner::Constants::QML_CONTEXTPANE_KEY), QVariant(false)).toBool(); + pinContextPane = settings->value( + QLatin1String(QmlDesigner::Constants::QML_CONTEXTPANEPIN_KEY), QVariant(false)).toBool(); + settings->endGroup(); + settings->endGroup(); +} + +void QuickToolBarSettings::toSettings(QSettings *settings) const +{ + settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_SETTINGS_GROUP)); + settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_DESIGNER_SETTINGS_GROUP)); + settings->setValue(QLatin1String(QmlDesigner::Constants::QML_CONTEXTPANE_KEY), enableContextPane); + settings->setValue(QLatin1String(QmlDesigner::Constants::QML_CONTEXTPANEPIN_KEY), pinContextPane); + settings->endGroup(); + settings->endGroup(); +} + +bool QuickToolBarSettings::equals(const QuickToolBarSettings &other) const +{ + return enableContextPane == other.enableContextPane + && pinContextPane == other.pinContextPane; +} + + +QuickToolBarSettingsPageWidget::QuickToolBarSettingsPageWidget(QWidget *parent) : + QWidget(parent) +{ + m_ui.setupUi(this); +} + +QuickToolBarSettings QuickToolBarSettingsPageWidget::settings() const +{ + QuickToolBarSettings ds; + ds.enableContextPane = m_ui.textEditHelperCheckBox->isChecked(); + ds.pinContextPane = m_ui.textEditHelperCheckBoxPin->isChecked(); + return ds; +} + +void QuickToolBarSettingsPageWidget::setSettings(const QuickToolBarSettings &s) +{ + m_ui.textEditHelperCheckBox->setChecked(s.enableContextPane); + m_ui.textEditHelperCheckBoxPin->setChecked(s.pinContextPane); +} + +QString QuickToolBarSettingsPageWidget::searchKeywords() const +{ + QString rc; + QTextStream(&rc) + << ' ' << m_ui.textEditHelperCheckBox + << ' ' << m_ui.textEditHelperCheckBoxPin; + rc.remove(QLatin1Char('&')); + return rc; +} + +QuickToolBarSettings QuickToolBarSettings::get() +{ + Core::ICore *core = Core::ICore::instance(); + QuickToolBarSettings settings; + settings.fromSettings(core->settings()); + return settings; +} + +QuickToolBarSettingsPage::QuickToolBarSettingsPage() : + m_widget(0) +{ +} + +QString QuickToolBarSettingsPage::id() const +{ + return QLatin1String("QmlToolbar"); +} + +QString QuickToolBarSettingsPage::displayName() const +{ + return tr("Qt Quick ToolBar"); +} + +QString QuickToolBarSettingsPage::category() const +{ + return QLatin1String("Qt Quick"); +} + +QString QuickToolBarSettingsPage::displayCategory() const +{ + return QCoreApplication::translate("Qt Quick", "Qt Quick"); +} + +QIcon QuickToolBarSettingsPage::categoryIcon() const +{ + return QIcon(QLatin1String(QmlDesigner::Constants::SETTINGS_CATEGORY_QML_ICON)); +} + +QWidget *QuickToolBarSettingsPage::createPage(QWidget *parent) +{ + m_widget = new QuickToolBarSettingsPageWidget(parent); + m_widget->setSettings(QuickToolBarSettings::get()); + if (m_searchKeywords.isEmpty()) + m_searchKeywords = m_widget->searchKeywords(); + return m_widget; +} + +void QuickToolBarSettingsPage::apply() +{ + m_widget->settings().set(); +} + +bool QuickToolBarSettingsPage::matches(const QString &s) const +{ + return m_searchKeywords.contains(s, Qt::CaseInsensitive); +} diff --git a/src/plugins/qmljseditor/quicktoolbarsettingspage.h b/src/plugins/qmljseditor/quicktoolbarsettingspage.h new file mode 100644 index 0000000000000000000000000000000000000000..da25bb320e0f7d5820e0113676bbb8c2c7dbd0eb --- /dev/null +++ b/src/plugins/qmljseditor/quicktoolbarsettingspage.h @@ -0,0 +1,113 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 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 QUICKTOOLBARSETTINGSPAGE_H +#define QUICKTOOLBARSETTINGSPAGE_H + +#include "ui_quicktoolbarsettingspage.h" +#include <coreplugin/dialogs/ioptionspage.h> +#include <QtGui/QWidget> + +QT_BEGIN_NAMESPACE +class QSettings; +QT_END_NAMESPACE + +namespace QmlJSEditor { + + class QuickToolBarSettings { + public: + QuickToolBarSettings(); + + static QuickToolBarSettings get(); + void set(); + + void fromSettings(QSettings *); + void toSettings(QSettings *) const; + + bool equals(const QuickToolBarSettings &other) const; + bool enableContextPane; + bool pinContextPane; + }; + + inline bool operator==(const QuickToolBarSettings &s1, const QuickToolBarSettings &s2) + { return s1.equals(s2); } + inline bool operator!=(const QuickToolBarSettings &s1, const QuickToolBarSettings &s2) + { return !s1.equals(s2); } + + +class QuickToolBarSettings; + +namespace Internal { + +class QuickToolBarSettingsPageWidget : public QWidget +{ + Q_OBJECT + +public: + explicit QuickToolBarSettingsPageWidget(QWidget *parent = 0); + + QuickToolBarSettings settings() const; + void setSettings(const QuickToolBarSettings &); + + QString searchKeywords() const; + static QuickToolBarSettings get(); + +private: + Ui::QuickToolBarSettingsPage m_ui; +}; + + +class QuickToolBarSettingsPage : public Core::IOptionsPage +{ + Q_OBJECT + +public: + QuickToolBarSettingsPage(); + + QString id() const; + QString displayName() const; + QString category() const; + QString displayCategory() const; + QIcon categoryIcon() const; + + QWidget *createPage(QWidget *parent); + void apply(); + void finish() { } + virtual bool matches(const QString &) const; + +private: + QString m_searchKeywords; + QuickToolBarSettingsPageWidget* m_widget; +}; + +} // namespace Internal +} // namespace QmlDesigner + +#endif // QUICKTOOLBARSETTINGSPAGE_H diff --git a/src/plugins/qmljseditor/quicktoolbarsettingspage.ui b/src/plugins/qmljseditor/quicktoolbarsettingspage.ui new file mode 100644 index 0000000000000000000000000000000000000000..ba36ba712c177a5f0c0166e56cdaeeee82a57b7f --- /dev/null +++ b/src/plugins/qmljseditor/quicktoolbarsettingspage.ui @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>QmlJSEditor::Internal::QuickToolBarSettingsPage</class> + <widget class="QWidget" name="QmlJSEditor::Internal::QuickToolBarSettingsPage"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>433</width> + <height>428</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Quick Toolbars</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QCheckBox" name="textEditHelperCheckBox"> + <property name="text"> + <string>Always show Quick Toolbar</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="textEditHelperCheckBoxPin"> + <property name="toolTip"> + <string>If enabled the toolbar will remain pinned to an absolute position.</string> + </property> + <property name="text"> + <string>Pin Quick Toolbar</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="0"> + <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>