Commit 3cc491f4 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner.navigator: add tool buttons for sliding/reparenting

This patch adds for tool buttons that allow
sliding and reparenting in the navigator.
parent 10708af7
......@@ -8,3 +8,5 @@ HEADERS += navigatorview.h \
navigatortreemodel.h \
navigatorwidget.h \
navigatortreeview.h
RESOURCES += navigator.qrc
<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) :
AbstractView(parent),
m_blockSelectionChangedSignal(false),
m_widget(new NavigatorWidget),
m_widget(new NavigatorWidget(this)),
m_treeModel(new NavigatorTreeModel(this))
{
m_widget->setTreeModel(m_treeModel.data());
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);
NameItemDelegate *idDelegate = new NameItemDelegate(this,m_treeModel.data());
......@@ -80,7 +86,7 @@ NavigatorView::~NavigatorView()
delete m_widget.data();
}
QWidget *NavigatorView::widget()
NavigatorWidget *NavigatorView::widget()
{
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*/)
{
if (m_blockSelectionChangedSignal)
......
......@@ -59,7 +59,7 @@ public:
NavigatorView(QObject* parent = 0);
~NavigatorView();
QWidget *widget();
NavigatorWidget *widget();
// AbstractView
void modelAttached(Model *model);
......@@ -104,6 +104,11 @@ private slots:
void updateItemSelection();
void changeToComponent(const QModelIndex &index);
void leftButtonClicked();
void rightButtonClicked();
void upButtonClicked();
void downButtonClicked();
protected: //functions
QTreeView *treeWidget();
NavigatorTreeModel *treeModel();
......
......@@ -36,15 +36,17 @@
#include <model.h>
#include "navigatorwidget.h"
#include "navigatorview.h"
#include <utils/fileutils.h>
namespace QmlDesigner {
NavigatorWidget::NavigatorWidget(QWidget* parent) :
QFrame(parent),
m_treeView(new NavigatorTreeView)
NavigatorWidget::NavigatorWidget(NavigatorView *view) :
QFrame(),
m_treeView(new NavigatorTreeView),
m_navigatorView(view)
{
m_treeView->setDragEnabled(true);
m_treeView->setAcceptDrops(true);
......@@ -79,4 +81,54 @@ void NavigatorWidget::setTreeModel(QAbstractItemModel* 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 <QAbstractItemModel>
#include <QtGui/QToolButton>
#include "navigatortreeview.h"
namespace QmlDesigner {
class Model;
class NavigatorView;
class NavigatorWidget: public QFrame
{
Q_OBJECT
public:
NavigatorWidget(QWidget* parent = 0);
NavigatorWidget(NavigatorView *view);
virtual ~NavigatorWidget();
void setTreeModel(QAbstractItemModel *model);
QTreeView *treeView() const { return m_treeView; }
QList<QToolButton *> createToolBarWidgets();
QString contextHelpId() const;
signals:
void leftButtonClicked();
void rightButtonClicked();
void upButtonClicked();
void downButtonClicked();
private:
NavigatorView *navigatorView() const;
NavigatorTreeView *m_treeView;
QWeakPointer<NavigatorView> m_navigatorView;
};
}
......
......@@ -153,6 +153,27 @@ QList<QToolButton *> ItemLibrarySideBarItem::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()
{
m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column() - 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment