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:
Thomas Hartmann
2011-04-28 17:12:45 +02:00
parent 10708af70f
commit 3cc491f45a
11 changed files with 182 additions and 7 deletions

View File

@@ -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)