1 #include "treeeditor.h"
7 #include "mainwindow.h"
10 extern Main *mainWindow;
11 extern QString editorFocusStyle;
13 extern QMenu *branchContextMenu;
14 extern QMenu *canvasContextMenu;
15 extern QMenu *floatimageContextMenu;
17 ///////////////////////////////////////////////////////////////////////
18 ///////////////////////////////////////////////////////////////////////
19 TreeEditor::TreeEditor(VymModel *m)
27 void TreeEditor::init()
29 setSelectionMode(QAbstractItemView::ExtendedSelection);
33 // Shortcuts for navigating with cursor:
34 a = new QAction(tr("Select upper object", "Tree Editor"), this);
35 a->setShortcut(Qt::Key_Up);
36 a->setShortcutContext(Qt::WidgetShortcut);
38 connect(a, SIGNAL(triggered()), this, SLOT(cursorUp()));
40 a = new QAction(tr("Select lower object", "Tree Editor"), this);
41 a->setShortcut(Qt::Key_Down);
42 a->setShortcutContext(Qt::WidgetShortcut);
44 connect(a, SIGNAL(triggered()), this, SLOT(cursorDown()));
46 a = new QAction(this);
47 a->setShortcut(Qt::Key_PageUp);
48 a->setShortcutContext(Qt::WidgetShortcut);
50 connect(a, SIGNAL(triggered()), mainWindow, SLOT(editMoveUp()));
52 a = new QAction(this);
53 a->setShortcut(Qt::Key_PageDown);
54 a->setShortcutContext(Qt::WidgetShortcut);
56 connect(a, SIGNAL(triggered()), mainWindow, SLOT(editMoveDown()));
58 a = new QAction(this);
59 a->setShortcut(Qt::Key_Return);
60 a->setShortcutContext(Qt::WidgetShortcut);
62 connect(a, SIGNAL(triggered()), this, SLOT(startEdit()));
64 // Clone actions defined in MainWindow
65 foreach (QAction *qa, mainWindow->mapEditorActions) {
66 a = new QAction(this);
67 a->setShortcut(qa->shortcut());
68 a->setShortcutContext(qa->shortcutContext());
69 connect(a, SIGNAL(triggered()), qa, SLOT(trigger()));
73 setStyleSheet("QTreeView:focus {" + editorFocusStyle + "}");
76 TreeEditor::~TreeEditor()
78 // qDebug()<<"Destructor TreeEditor for "<<model->getMapName();
81 QModelIndex TreeEditor::getSelectedIndex()
83 QModelIndexList list = selectionModel()->selectedIndexes();
90 void TreeEditor::contextMenuEvent(QContextMenuEvent *e) {
91 if (model->getSelectedBranch())
92 branchContextMenu->popup(e->globalPos());
93 else if (model->getSelectedImage())
94 floatimageContextMenu->popup(e->globalPos());
95 else if (model->getSelectedXLink())
98 canvasContextMenu->exec(e->globalPos());
103 void TreeEditor::cursorUp()
105 QModelIndex ix = getSelectedIndex();
111 void TreeEditor::cursorDown()
113 QModelIndex ix = getSelectedIndex();
119 void TreeEditor::startEdit()
122 QModelIndex ix = getSelectedIndex();