forked from qt-creator/qt-creator
QmlDesigner.navigator: add tool buttons for sliding/reparenting
This patch adds for tool buttons that allow sliding and reparenting in the navigator.
This commit is contained in:
BIN
src/plugins/qmldesigner/components/navigator/arrowdown.png
Normal file
BIN
src/plugins/qmldesigner/components/navigator/arrowdown.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 390 B |
BIN
src/plugins/qmldesigner/components/navigator/arrowleft.png
Normal file
BIN
src/plugins/qmldesigner/components/navigator/arrowleft.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 471 B |
BIN
src/plugins/qmldesigner/components/navigator/arrowright.png
Normal file
BIN
src/plugins/qmldesigner/components/navigator/arrowright.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 455 B |
BIN
src/plugins/qmldesigner/components/navigator/arrowup.png
Normal file
BIN
src/plugins/qmldesigner/components/navigator/arrowup.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 376 B |
@@ -8,3 +8,5 @@ HEADERS += navigatorview.h \
|
|||||||
navigatortreemodel.h \
|
navigatortreemodel.h \
|
||||||
navigatorwidget.h \
|
navigatorwidget.h \
|
||||||
navigatortreeview.h
|
navigatortreeview.h
|
||||||
|
|
||||||
|
RESOURCES += navigator.qrc
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/navigator/icon">
|
||||||
|
<file>arrowdown.png</file>
|
||||||
|
<file>arrowleft.png</file>
|
||||||
|
<file>arrowright.png</file>
|
||||||
|
<file>arrowup.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
@@ -46,12 +46,18 @@ namespace QmlDesigner {
|
|||||||
NavigatorView::NavigatorView(QObject* parent) :
|
NavigatorView::NavigatorView(QObject* parent) :
|
||||||
AbstractView(parent),
|
AbstractView(parent),
|
||||||
m_blockSelectionChangedSignal(false),
|
m_blockSelectionChangedSignal(false),
|
||||||
m_widget(new NavigatorWidget),
|
m_widget(new NavigatorWidget(this)),
|
||||||
m_treeModel(new NavigatorTreeModel(this))
|
m_treeModel(new NavigatorTreeModel(this))
|
||||||
{
|
{
|
||||||
m_widget->setTreeModel(m_treeModel.data());
|
m_widget->setTreeModel(m_treeModel.data());
|
||||||
|
|
||||||
connect(treeWidget()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(changeSelection(QItemSelection,QItemSelection)));
|
connect(treeWidget()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(changeSelection(QItemSelection,QItemSelection)));
|
||||||
|
|
||||||
|
connect(m_widget.data(), SIGNAL(leftButtonClicked()), this, SLOT(leftButtonClicked()));
|
||||||
|
connect(m_widget.data(), SIGNAL(rightButtonClicked()), this, SLOT(rightButtonClicked()));
|
||||||
|
connect(m_widget.data(), SIGNAL(downButtonClicked()), this, SLOT(downButtonClicked()));
|
||||||
|
connect(m_widget.data(), SIGNAL(upButtonClicked()), this, SLOT(upButtonClicked()));
|
||||||
|
|
||||||
treeWidget()->setIndentation(treeWidget()->indentation() * 0.5);
|
treeWidget()->setIndentation(treeWidget()->indentation() * 0.5);
|
||||||
|
|
||||||
NameItemDelegate *idDelegate = new NameItemDelegate(this,m_treeModel.data());
|
NameItemDelegate *idDelegate = new NameItemDelegate(this,m_treeModel.data());
|
||||||
@@ -80,7 +86,7 @@ NavigatorView::~NavigatorView()
|
|||||||
delete m_widget.data();
|
delete m_widget.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *NavigatorView::widget()
|
NavigatorWidget *NavigatorView::widget()
|
||||||
{
|
{
|
||||||
return m_widget.data();
|
return m_widget.data();
|
||||||
}
|
}
|
||||||
@@ -256,6 +262,75 @@ void NavigatorView::changeToComponent(const QModelIndex &index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NavigatorView::leftButtonClicked()
|
||||||
|
{
|
||||||
|
if (selectedModelNodes().count() > 1)
|
||||||
|
return; //Semantics are unclear for multi selection.
|
||||||
|
|
||||||
|
bool blocked = blockSelectionChangedSignal(true);
|
||||||
|
|
||||||
|
foreach (const ModelNode &node, selectedModelNodes()) {
|
||||||
|
if (!node.isRootNode() && !node.parentProperty().parentModelNode().isRootNode())
|
||||||
|
node.parentProperty().parentModelNode().parentProperty().reparentHere(node);
|
||||||
|
}
|
||||||
|
updateItemSelection();
|
||||||
|
blockSelectionChangedSignal(blocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigatorView::rightButtonClicked()
|
||||||
|
{
|
||||||
|
if (selectedModelNodes().count() > 1)
|
||||||
|
return; //Semantics are unclear for multi selection.
|
||||||
|
|
||||||
|
bool blocked = blockSelectionChangedSignal(true);
|
||||||
|
foreach (const ModelNode &node, selectedModelNodes()) {
|
||||||
|
if (!node.isRootNode() && node.parentProperty().isNodeListProperty() && node.parentProperty().toNodeListProperty().count() > 1) {
|
||||||
|
int index = node.parentProperty().toNodeListProperty().indexOf(node);
|
||||||
|
index--;
|
||||||
|
if (index >= 0) { //for the first node the semantics are not clear enough. Wrapping would be irritating.
|
||||||
|
ModelNode newParent = node.parentProperty().toNodeListProperty().at(index);
|
||||||
|
newParent.nodeAbstractProperty(newParent.metaInfo().defaultPropertyName()).reparentHere(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateItemSelection();
|
||||||
|
blockSelectionChangedSignal(blocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigatorView::upButtonClicked()
|
||||||
|
{
|
||||||
|
bool blocked = blockSelectionChangedSignal(true);
|
||||||
|
foreach (const ModelNode &node, selectedModelNodes()) {
|
||||||
|
if (!node.isRootNode() && node.parentProperty().isNodeListProperty()) {
|
||||||
|
int oldIndex = node.parentProperty().toNodeListProperty().indexOf(node);
|
||||||
|
int index = oldIndex;
|
||||||
|
index--;
|
||||||
|
if (index < 0)
|
||||||
|
index = node.parentProperty().toNodeListProperty().count() - 1; //wrap around
|
||||||
|
node.parentProperty().toNodeListProperty().slide(oldIndex, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateItemSelection();
|
||||||
|
blockSelectionChangedSignal(blocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigatorView::downButtonClicked()
|
||||||
|
{
|
||||||
|
bool blocked = blockSelectionChangedSignal(true);
|
||||||
|
foreach (const ModelNode &node, selectedModelNodes()) {
|
||||||
|
if (!node.isRootNode() && node.parentProperty().isNodeListProperty()) {
|
||||||
|
int oldIndex = node.parentProperty().toNodeListProperty().indexOf(node);
|
||||||
|
int index = oldIndex;
|
||||||
|
index++;
|
||||||
|
if (index >= node.parentProperty().toNodeListProperty().count())
|
||||||
|
index = 0; //wrap around
|
||||||
|
node.parentProperty().toNodeListProperty().slide(oldIndex, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateItemSelection();
|
||||||
|
blockSelectionChangedSignal(blocked);
|
||||||
|
}
|
||||||
|
|
||||||
void NavigatorView::changeSelection(const QItemSelection & /*newSelection*/, const QItemSelection &/*deselected*/)
|
void NavigatorView::changeSelection(const QItemSelection & /*newSelection*/, const QItemSelection &/*deselected*/)
|
||||||
{
|
{
|
||||||
if (m_blockSelectionChangedSignal)
|
if (m_blockSelectionChangedSignal)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
NavigatorView(QObject* parent = 0);
|
NavigatorView(QObject* parent = 0);
|
||||||
~NavigatorView();
|
~NavigatorView();
|
||||||
|
|
||||||
QWidget *widget();
|
NavigatorWidget *widget();
|
||||||
|
|
||||||
// AbstractView
|
// AbstractView
|
||||||
void modelAttached(Model *model);
|
void modelAttached(Model *model);
|
||||||
@@ -104,6 +104,11 @@ private slots:
|
|||||||
void updateItemSelection();
|
void updateItemSelection();
|
||||||
void changeToComponent(const QModelIndex &index);
|
void changeToComponent(const QModelIndex &index);
|
||||||
|
|
||||||
|
void leftButtonClicked();
|
||||||
|
void rightButtonClicked();
|
||||||
|
void upButtonClicked();
|
||||||
|
void downButtonClicked();
|
||||||
|
|
||||||
protected: //functions
|
protected: //functions
|
||||||
QTreeView *treeWidget();
|
QTreeView *treeWidget();
|
||||||
NavigatorTreeModel *treeModel();
|
NavigatorTreeModel *treeModel();
|
||||||
|
|||||||
@@ -36,15 +36,17 @@
|
|||||||
#include <model.h>
|
#include <model.h>
|
||||||
|
|
||||||
#include "navigatorwidget.h"
|
#include "navigatorwidget.h"
|
||||||
|
#include "navigatorview.h"
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
NavigatorWidget::NavigatorWidget(QWidget* parent) :
|
NavigatorWidget::NavigatorWidget(NavigatorView *view) :
|
||||||
QFrame(parent),
|
QFrame(),
|
||||||
m_treeView(new NavigatorTreeView)
|
m_treeView(new NavigatorTreeView),
|
||||||
|
m_navigatorView(view)
|
||||||
{
|
{
|
||||||
m_treeView->setDragEnabled(true);
|
m_treeView->setDragEnabled(true);
|
||||||
m_treeView->setAcceptDrops(true);
|
m_treeView->setAcceptDrops(true);
|
||||||
@@ -79,4 +81,54 @@ void NavigatorWidget::setTreeModel(QAbstractItemModel* model)
|
|||||||
m_treeView->setModel(model);
|
m_treeView->setModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QToolButton *> NavigatorWidget::createToolBarWidgets()
|
||||||
|
{
|
||||||
|
QList<QToolButton *> buttons;
|
||||||
|
|
||||||
|
buttons << new QToolButton();
|
||||||
|
buttons.last()->setIcon(QIcon(":/navigator/icon/arrowleft.png"));
|
||||||
|
buttons.last()->setToolTip(tr("Become first sibling of parent (CTRL + Left)"));
|
||||||
|
buttons.last()->setShortcut(QKeySequence(Qt::Key_Left | Qt::CTRL));
|
||||||
|
connect(buttons.last(), SIGNAL(clicked()), this, SIGNAL(leftButtonClicked()));
|
||||||
|
buttons << new QToolButton();
|
||||||
|
buttons.last()->setIcon(QIcon(":/navigator/icon/arrowright.png"));
|
||||||
|
buttons.last()->setToolTip(tr("Become child of first silbing (CTRL + Right)"));
|
||||||
|
buttons.last()->setShortcut(QKeySequence(Qt::Key_Right | Qt::CTRL));
|
||||||
|
connect(buttons.last(), SIGNAL(clicked()), this, SIGNAL(rightButtonClicked()));
|
||||||
|
|
||||||
|
buttons << new QToolButton();
|
||||||
|
buttons.last()->setIcon(QIcon(":/navigator/icon/arrowdown.png"));
|
||||||
|
buttons.last()->setToolTip(tr("Move down (CTRL + Down)"));
|
||||||
|
buttons.last()->setShortcut(QKeySequence(Qt::Key_Down | Qt::CTRL));
|
||||||
|
connect(buttons.last(), SIGNAL(clicked()), this, SIGNAL(downButtonClicked()));
|
||||||
|
|
||||||
|
buttons << new QToolButton();
|
||||||
|
buttons.last()->setIcon(QIcon(":/navigator/icon/arrowup.png"));
|
||||||
|
buttons.last()->setToolTip(tr("Move up (CTRL + Up)"));
|
||||||
|
buttons.last()->setShortcut(QKeySequence(Qt::Key_Up | Qt::CTRL));
|
||||||
|
connect(buttons.last(), SIGNAL(clicked()), this, SIGNAL(upButtonClicked()));
|
||||||
|
|
||||||
|
return buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString NavigatorWidget::contextHelpId() const
|
||||||
|
{
|
||||||
|
if (!navigatorView())
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
QList<ModelNode> nodes = navigatorView()->selectedModelNodes();
|
||||||
|
QString helpId;
|
||||||
|
if (!nodes.isEmpty()) {
|
||||||
|
helpId = nodes.first().type();
|
||||||
|
helpId.replace("QtQuick", "QML");
|
||||||
|
}
|
||||||
|
|
||||||
|
return helpId;
|
||||||
|
}
|
||||||
|
|
||||||
|
NavigatorView *NavigatorWidget::navigatorView() const
|
||||||
|
{
|
||||||
|
return m_navigatorView.data();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,25 +35,37 @@
|
|||||||
|
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
#include <QtGui/QToolButton>
|
||||||
|
|
||||||
#include "navigatortreeview.h"
|
#include "navigatortreeview.h"
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class Model;
|
class Model;
|
||||||
|
class NavigatorView;
|
||||||
|
|
||||||
class NavigatorWidget: public QFrame
|
class NavigatorWidget: public QFrame
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
NavigatorWidget(QWidget* parent = 0);
|
NavigatorWidget(NavigatorView *view);
|
||||||
virtual ~NavigatorWidget();
|
virtual ~NavigatorWidget();
|
||||||
|
|
||||||
void setTreeModel(QAbstractItemModel *model);
|
void setTreeModel(QAbstractItemModel *model);
|
||||||
QTreeView *treeView() const { return m_treeView; }
|
QTreeView *treeView() const { return m_treeView; }
|
||||||
|
QList<QToolButton *> createToolBarWidgets();
|
||||||
|
QString contextHelpId() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void leftButtonClicked();
|
||||||
|
void rightButtonClicked();
|
||||||
|
void upButtonClicked();
|
||||||
|
void downButtonClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
NavigatorView *navigatorView() const;
|
||||||
NavigatorTreeView *m_treeView;
|
NavigatorTreeView *m_treeView;
|
||||||
|
QWeakPointer<NavigatorView> m_navigatorView;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,6 +153,27 @@ QList<QToolButton *> ItemLibrarySideBarItem::createToolBarWidgets()
|
|||||||
return qobject_cast<ItemLibraryWidget*>(widget())->createToolBarWidgets();
|
return qobject_cast<ItemLibraryWidget*>(widget())->createToolBarWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NavigatorSideBarItem : public Core::SideBarItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit NavigatorSideBarItem(NavigatorWidget *widget, const QString &id);
|
||||||
|
virtual ~NavigatorSideBarItem();
|
||||||
|
|
||||||
|
virtual QList<QToolButton *> createToolBarWidgets();
|
||||||
|
};
|
||||||
|
|
||||||
|
NavigatorSideBarItem::NavigatorSideBarItem(NavigatorWidget *widget, const QString &id) : Core::SideBarItem(widget, id) {}
|
||||||
|
|
||||||
|
NavigatorSideBarItem::~NavigatorSideBarItem()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QToolButton *> NavigatorSideBarItem::createToolBarWidgets()
|
||||||
|
{
|
||||||
|
return qobject_cast<NavigatorWidget*>(widget())->createToolBarWidgets();
|
||||||
|
}
|
||||||
|
|
||||||
void DocumentWarningWidget::goToError()
|
void DocumentWarningWidget::goToError()
|
||||||
{
|
{
|
||||||
m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column() - 1);
|
m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column() - 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user