forked from qt-creator/qt-creator
QmlJSEditor: Add QuickToolBar to QmlJSEditor
QmlDesigner is not needed anymore for the QuickToolBar QmlJSEditor has a depends now on libs/qmleditorwidgets
This commit is contained in:
@@ -28,7 +28,10 @@ HEADERS += \
|
|||||||
qmloutlinemodel.h \
|
qmloutlinemodel.h \
|
||||||
qmltaskmanager.h \
|
qmltaskmanager.h \
|
||||||
qmljseditorcodeformatter.h \
|
qmljseditorcodeformatter.h \
|
||||||
qmljsoutlinetreeview.h
|
qmljsoutlinetreeview.h \
|
||||||
|
quicktoolbarsettingspage.h \
|
||||||
|
quicktoolbar.h
|
||||||
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
qmljscodecompletion.cpp \
|
qmljscodecompletion.cpp \
|
||||||
@@ -50,7 +53,13 @@ SOURCES += \
|
|||||||
qmltaskmanager.cpp \
|
qmltaskmanager.cpp \
|
||||||
qmljsquickfixes.cpp \
|
qmljsquickfixes.cpp \
|
||||||
qmljseditorcodeformatter.cpp \
|
qmljseditorcodeformatter.cpp \
|
||||||
qmljsoutlinetreeview.cpp
|
qmljsoutlinetreeview.cpp \
|
||||||
|
quicktoolbarsettingspage.cpp \
|
||||||
|
quicktoolbar.cpp
|
||||||
|
|
||||||
|
|
||||||
RESOURCES += qmljseditor.qrc
|
RESOURCES += qmljseditor.qrc
|
||||||
OTHER_FILES += QmlJSEditor.pluginspec QmlJSEditor.mimetypes.xml
|
OTHER_FILES += QmlJSEditor.pluginspec QmlJSEditor.mimetypes.xml
|
||||||
|
|
||||||
|
FORMS += \
|
||||||
|
quicktoolbarsettingspage.ui
|
||||||
|
@@ -3,3 +3,4 @@ include(../../plugins/texteditor/texteditor.pri)
|
|||||||
include(../../plugins/projectexplorer/projectexplorer.pri)
|
include(../../plugins/projectexplorer/projectexplorer.pri)
|
||||||
include(../../libs/qmljs/qmljs.pri)
|
include(../../libs/qmljs/qmljs.pri)
|
||||||
include(../../libs/utils/utils.pri)
|
include(../../libs/utils/utils.pri)
|
||||||
|
include(../../libs/qmleditorwidgets/qmleditorwidgets.pri)
|
||||||
|
@@ -41,6 +41,8 @@
|
|||||||
#include "qmljsquickfix.h"
|
#include "qmljsquickfix.h"
|
||||||
#include "qmljs/qmljsicons.h"
|
#include "qmljs/qmljsicons.h"
|
||||||
#include "qmltaskmanager.h"
|
#include "qmltaskmanager.h"
|
||||||
|
#include "quicktoolbar.h"
|
||||||
|
#include "quicktoolbarsettingspage.h"
|
||||||
|
|
||||||
#include <qmldesigner/qmldesignerconstants.h>
|
#include <qmldesigner/qmldesignerconstants.h>
|
||||||
|
|
||||||
@@ -197,6 +199,9 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
|||||||
connect(m_modelManager, SIGNAL(aboutToRemoveFiles(QStringList)),
|
connect(m_modelManager, SIGNAL(aboutToRemoveFiles(QStringList)),
|
||||||
m_qmlTaskManager, SLOT(documentsRemoved(QStringList)));
|
m_qmlTaskManager, SLOT(documentsRemoved(QStringList)));
|
||||||
|
|
||||||
|
addAutoReleasedObject(new QuickToolBar);
|
||||||
|
addAutoReleasedObject(new Internal::QuickToolBarSettingsPage);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
386
src/plugins/qmljseditor/quicktoolbar.cpp
Normal file
386
src/plugins/qmljseditor/quicktoolbar.cpp
Normal file
@@ -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
|
59
src/plugins/qmljseditor/quicktoolbar.h
Normal file
59
src/plugins/qmljseditor/quicktoolbar.h
Normal file
@@ -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
|
170
src/plugins/qmljseditor/quicktoolbarsettingspage.cpp
Normal file
170
src/plugins/qmljseditor/quicktoolbarsettingspage.cpp
Normal file
@@ -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);
|
||||||
|
}
|
113
src/plugins/qmljseditor/quicktoolbarsettingspage.h
Normal file
113
src/plugins/qmljseditor/quicktoolbarsettingspage.h
Normal file
@@ -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
|
60
src/plugins/qmljseditor/quicktoolbarsettingspage.ui
Normal file
60
src/plugins/qmljseditor/quicktoolbarsettingspage.ui
Normal file
@@ -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>
|
Reference in New Issue
Block a user