]> git.sven.stormbind.net Git - sven/vym.git/blob - treeeditor.cpp
9e4ee9b500a53a7ada0ffbba39374b8464b091f1
[sven/vym.git] / treeeditor.cpp
1 #include "treeeditor.h"
2
3 #include <QAction>
4 #include <QRegExp>
5
6 #include "mainwindow.h"
7 #include "vymmodel.h"
8
9 extern Main *mainWindow;
10
11 ///////////////////////////////////////////////////////////////////////
12 ///////////////////////////////////////////////////////////////////////
13 TreeEditor::TreeEditor(VymModel *m)
14 {
15     model=m;
16     if (model) setModel(model);
17     init();
18 }
19
20 void TreeEditor::init()
21 {
22     setSelectionMode (QAbstractItemView::ExtendedSelection);
23     header()->hide();
24
25     QAction *a;
26     // Shortcuts for navigating with cursor:
27     a = new QAction(tr( "Select upper object","Tree Editor" ), this);
28     a->setShortcut (Qt::Key_Up );
29     a->setShortcutContext (Qt::WidgetShortcut);
30     addAction (a);
31     connect( a, SIGNAL( triggered() ), this, SLOT( cursorUp() ) );
32
33     a = new QAction( tr( "Select lower object","Tree Editor" ),this);
34     a->setShortcut ( Qt::Key_Down );
35     a->setShortcutContext (Qt::WidgetShortcut);
36     addAction (a);
37     connect( a, SIGNAL( triggered() ), this, SLOT( cursorDown() ) );
38
39     a = new QAction( this);
40     a->setShortcut ( Qt::Key_PageUp);
41     a->setShortcutContext (Qt::WidgetShortcut);
42     addAction (a);
43     connect( a, SIGNAL( triggered() ), mainWindow, SLOT( editMoveUp() ) );
44
45     a = new QAction( this);
46     a->setShortcut ( Qt::Key_PageDown );
47     a->setShortcutContext (Qt::WidgetShortcut);
48     addAction (a);
49     connect( a, SIGNAL( triggered() ), mainWindow, SLOT( editMoveDown() ) );
50 }
51
52 TreeEditor::~TreeEditor()
53 {
54     //qDebug()<<"Destructor TreeEditor for "<<model->getMapName();
55 }
56
57 QModelIndex TreeEditor::getSelectedIndex()
58 {
59     QModelIndexList list=selectionModel()->selectedIndexes();
60     if (list.isEmpty() )
61         return QModelIndex();
62     else
63         return list.first();
64 }
65
66 void TreeEditor::cursorUp()
67 {
68     QModelIndex ix=getSelectedIndex();
69     ix=indexAbove (ix);
70     if (ix.isValid())
71         model->select (ix );
72 }
73
74 void TreeEditor::cursorDown()
75 {
76     QModelIndex ix=getSelectedIndex();
77     ix=indexBelow (ix);
78     if (ix.isValid())
79         model->select (ix );
80 }
81