3 #include "branchitem.h"
4 #include "mainwindow.h"
6 #include "treeeditor.h"
8 extern Main *mainWindow;
11 VymView::VymView(VymModel *m)
16 treeEditor=new TreeEditor (model);
17 //treeEditor->setModel ((QAbstractItemModel*)model);
18 //treeEditor->setMinimumWidth (50);
20 treeEditor->setColumnWidth (0,150);
21 treeEditor->setAnimated (true);
23 selModel=new QItemSelectionModel (model);
25 model->setSelectionModel (selModel);
26 treeEditor->setSelectionModel (selModel);
28 // Create good old MapEditor
29 mapEditor=model->getMapEditor();
30 if (!mapEditor) mapEditor=new MapEditor (model);
33 QVBoxLayout* mainLayout = new QVBoxLayout (this); //FIXME-4 not needed
34 QSplitter *splitter= new QSplitter (this);
36 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
37 splitter->setSizePolicy(sizePolicy);
38 mainLayout->addWidget (splitter);
42 // Selection in Model changed
44 selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
45 this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
47 // Tell MapEditor to update selection
48 /* FIXME-3 done implicit here in VymView
50 selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
51 mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
54 // Needed to update selbox during animation
56 model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
57 mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
59 // Connect data changed signals
61 model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)),
62 mapEditor,SLOT (updateData(const QModelIndex &) ) );
65 model, SIGNAL (sortFilterChanged (const QString &)),
66 treeEditor, SLOT (setSortFilter (const QString &) ) );
69 model, SIGNAL (noteHasChanged(QModelIndex) ),
70 mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
73 model, SIGNAL (expandAll() ),
74 this, SLOT (expandAll () ) );
77 model, SIGNAL (expandOneLevel() ),
78 this, SLOT (expandOneLevel() ) );
81 model, SIGNAL (collapseOneLevel() ),
82 this, SLOT (collapseOneLevel() ) );
85 model, SIGNAL (showSelection() ),
86 this, SLOT (showSelection() ) );
89 model, SIGNAL (updateLayout() ),
90 mapEditor, SLOT (autoLayout() ) );
92 mapEditor->setAntiAlias (mainWindow->isAliased());
93 mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
95 splitter->addWidget (treeEditor);
96 splitter->addWidget (mapEditor);
102 splitter->setSizes(widths);
107 //cout << "Destructor VymView\n";
110 VymModel* VymView::getModel()
115 MapEditor* VymView::getMapEditor()
120 void VymView::initFocus()
122 mapEditor->setFocus();
125 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
127 //cout << "VV::changeSelection newsel.count="<<newsel.indexes().count()<<endl;
129 mainWindow->changeSelection (model,newsel,oldsel);
130 mapEditor->updateSelection (newsel,oldsel);
132 if (newsel.indexes().count()>0)
136 QModelIndex ix=newsel.indexes().first();
137 selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect );
138 treeEditor->setCurrentIndex (ix);
144 void VymView::expandAll()
146 treeEditor->expandAll();
149 void VymView::expandOneLevel()
153 BranchItem *cur=NULL;
154 BranchItem *prev=NULL;
157 // Find level to expand
158 model->nextBranch(cur,prev);
161 pix=model->index (cur);
163 if (!treeEditor->isExpanded(pix) && d < level)
165 model->nextBranch(cur,prev);
168 // Expand all to level
171 model->nextBranch(cur,prev);
174 pix=model->index (cur);
176 if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
177 treeEditor->setExpanded(pix,true);
178 model->nextBranch(cur,prev);
180 /* FIXME-3 optimize expanding by using flat version of next
181 model->nextBranch(cur,prev,false);
184 cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
186 model->nextBranch(cur,prev,false);
191 void VymView::collapseOneLevel()
195 BranchItem *cur=NULL;
196 BranchItem *prev=NULL;
199 // Find level to collapse
200 model->nextBranch(cur,prev);
203 pix=model->index (cur);
205 if (treeEditor->isExpanded(pix) && d > level)
207 model->nextBranch(cur,prev);
210 // collapse all to level
213 model->nextBranch(cur,prev);
216 pix=model->index (cur);
218 if (treeEditor->isExpanded(pix) && d >= level)
219 treeEditor->setExpanded(pix,false);
220 model->nextBranch(cur,prev);
224 void VymView::showSelection()
226 QModelIndex ix=model->getSelectedIndex();
227 treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
228 mapEditor->scrollTo ( ix); // FIXME-3 also called from MapEditor::updateSelection...
231 void VymView::toggleTreeEditor()
233 if (treeEditor->isVisible() )