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 TreeEditor* VymView::getTreeEditor()
125 void VymView::initFocus()
127 mapEditor->setFocus();
130 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
132 //cout << "VV::changeSelection newsel.count="<<newsel.indexes().count()<<endl;
134 mainWindow->changeSelection (model,newsel,oldsel);
135 mapEditor->updateSelection (newsel,oldsel);
137 if (newsel.indexes().count()>0)
141 QModelIndex ix=newsel.indexes().first();
142 selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect );
143 treeEditor->setCurrentIndex (ix);
149 void VymView::expandAll()
151 treeEditor->expandAll();
154 void VymView::expandOneLevel()
158 BranchItem *cur=NULL;
159 BranchItem *prev=NULL;
162 // Find level to expand
163 model->nextBranch(cur,prev);
166 pix=model->index (cur);
168 if (!treeEditor->isExpanded(pix) && d < level)
170 model->nextBranch(cur,prev);
173 // Expand all to level
176 model->nextBranch(cur,prev);
179 pix=model->index (cur);
181 if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
182 treeEditor->setExpanded(pix,true);
183 model->nextBranch(cur,prev);
185 /* FIXME-3 optimize expanding by using flat version of next
186 model->nextBranch(cur,prev,false);
189 cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
191 model->nextBranch(cur,prev,false);
196 void VymView::collapseOneLevel()
200 BranchItem *cur=NULL;
201 BranchItem *prev=NULL;
204 // Find level to collapse
205 model->nextBranch(cur,prev);
208 pix=model->index (cur);
210 if (treeEditor->isExpanded(pix) && d > level)
212 model->nextBranch(cur,prev);
215 // collapse all to level
218 model->nextBranch(cur,prev);
221 pix=model->index (cur);
223 if (treeEditor->isExpanded(pix) && d >= level)
224 treeEditor->setExpanded(pix,false);
225 model->nextBranch(cur,prev);
229 void VymView::showSelection()
231 QModelIndex ix=model->getSelectedIndex();
232 treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
233 mapEditor->scrollTo ( ix); // FIXME-3 also called from MapEditor::updateSelection...
236 void VymView::toggleTreeEditor()
238 if (treeEditor->isVisible() )