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() ) );
88 mapEditor->setAntiAlias (mainWindow->isAliased());
89 mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
91 splitter->addWidget (treeEditor);
92 splitter->addWidget (mapEditor);
98 splitter->setSizes(widths);
103 //cout << "Destructor VymView\n";
106 VymModel* VymView::getModel()
111 MapEditor* VymView::getMapEditor()
116 void VymView::initFocus()
118 mapEditor->setFocus();
121 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
123 //cout << "VV::changeSelection newsel.count="<<newsel.indexes().count()<<endl;
125 mainWindow->changeSelection (model,newsel,oldsel);
126 mapEditor->updateSelection (newsel,oldsel);
128 if (newsel.indexes().count()>0)
132 QModelIndex ix=newsel.indexes().first();
133 selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect );
134 treeEditor->setCurrentIndex (ix);
140 void VymView::expandAll()
142 treeEditor->expandAll();
145 void VymView::expandOneLevel()
149 BranchItem *cur=NULL;
150 BranchItem *prev=NULL;
153 // Find level to expand
154 model->nextBranch(cur,prev);
157 pix=model->index (cur);
159 if (!treeEditor->isExpanded(pix) && d < level)
161 model->nextBranch(cur,prev);
164 // Expand all to level
167 model->nextBranch(cur,prev);
170 pix=model->index (cur);
172 if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
173 treeEditor->setExpanded(pix,true);
174 model->nextBranch(cur,prev);
176 /* FIXME-3 optimize expanding by using flat version of next
177 model->nextBranch(cur,prev,false);
180 cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
182 model->nextBranch(cur,prev,false);
187 void VymView::collapseOneLevel()
191 BranchItem *cur=NULL;
192 BranchItem *prev=NULL;
195 // Find level to collapse
196 model->nextBranch(cur,prev);
199 pix=model->index (cur);
201 if (treeEditor->isExpanded(pix) && d > level)
203 model->nextBranch(cur,prev);
206 // collapse all to level
209 model->nextBranch(cur,prev);
212 pix=model->index (cur);
214 if (treeEditor->isExpanded(pix) && d >= level)
215 treeEditor->setExpanded(pix,false);
216 model->nextBranch(cur,prev);
220 void VymView::showSelection()
222 QModelIndex ix=model->getSelectedIndex();
223 treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
224 mapEditor->scrollTo ( ix); // FIXME-3 also called from MapEditor::updateSelection...
227 void VymView::toggleTreeEditor()
229 if (treeEditor->isVisible() )