6 #include "branchitem.h"
7 #include "findwidget.h"
8 #include "mainwindow.h"
10 #include "treeeditor.h"
12 extern Main *mainWindow;
15 VymView::VymView(VymModel *m)
20 findWidget=new FindWidget (this);
24 treeEditor=new TreeEditor (model);
25 //treeEditor->setModel ((QAbstractItemModel*)model);
26 //treeEditor->setMinimumWidth (50);
28 treeEditor->setColumnWidth (0,150);
29 treeEditor->setAnimated (true);
31 // FIXME-3 use proxySelModel=treeEditor->selectionModel();
32 selModel=new QItemSelectionModel (model);
34 //model->setSelectionModel (proxySelModel);
35 model->setSelectionModel (selModel);
36 treeEditor->setSelectionModel (selModel);
38 // Create good old MapEditor
39 mapEditor=model->getMapEditor();
40 if (!mapEditor) mapEditor=new MapEditor (model);
43 QVBoxLayout* mainLayout = new QVBoxLayout (this);
44 QSplitter *splitter= new QSplitter;
46 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
47 //sizePolicy.setHorizontalStretch(0);
48 //sizePolicy.setVerticalStretch(0);
49 //sizePolicy.setHeightForWidth(this->sizePolicy().hasHeightForWidth());
50 splitter->setSizePolicy(sizePolicy);
51 mainLayout->addWidget (splitter);
52 mainLayout->addWidget (findWidget);
59 proxySelModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
60 this,SLOT (changeProxySelection(const QItemSelection &,const QItemSelection &)));
63 // Selection in Model changed
65 selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
66 this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
68 // Tell MapEditor to update selection
69 /* FIXME-3 done implicit here in VymView
71 selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
72 mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
75 // Needed to update selbox during animation
77 model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
78 mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
80 // Connect data changed signals
82 model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)),
83 mapEditor,SLOT (updateData(const QModelIndex &) ) );
86 model, SIGNAL (sortFilterChanged (const QString &)),
87 treeEditor, SLOT (setSortFilter (const QString &) ) );
90 model, SIGNAL (noteHasChanged(QModelIndex) ),
91 mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
94 model, SIGNAL (expandAll() ),
95 this, SLOT (expandAll () ) );
98 model, SIGNAL (expandOneLevel() ),
99 this, SLOT (expandOneLevel() ) );
102 model, SIGNAL (collapseOneLevel() ),
103 this, SLOT (collapseOneLevel() ) );
106 model, SIGNAL (showSelection() ),
107 this, SLOT (showSelection() ) );
111 model, SIGNAL (showFindWidget() ),
112 this, SLOT (showFindWidget() ) );
115 findWidget , SIGNAL (hideFindWidget() ),
116 this, SLOT (hideFindWidget() ) );
119 findWidget, SIGNAL (nextButton (QString) ),
120 this, SLOT (findNext(QString) ) );
122 mapEditor->setAntiAlias (mainWindow->isAliased());
123 mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
125 splitter->addWidget (treeEditor);
126 splitter->addWidget (mapEditor);
132 splitter->setSizes(widths);
137 //cout << "Destructor VymView\n";
140 VymModel* VymView::getModel()
145 MapEditor* VymView::getMapEditor()
150 void VymView::initFocus()
152 mapEditor->setFocus();
155 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
157 //cout << "VV::changeSelection newsel.count="<<newsel.indexes().count()<<endl;
159 mainWindow->changeSelection (model,newsel,oldsel);
160 mapEditor->updateSelection (newsel,oldsel);
162 if (newsel.indexes().count()>0)
165 /* FIXME-3 use proxymodel
166 proxySelModel->select (
167 treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
168 QItemSelectionModel::ClearAndSelect );
171 QModelIndex ix=newsel.indexes().first();
172 selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect );
173 treeEditor->setCurrentIndex (ix);
179 void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &)
181 // Notify mainwindow to update satellites, but map selection to
182 // original model first
184 //cout << "VV::changeProxySelection newsel.count="<<newsel.indexes().count()<<endl;
185 if (!newsel.indexes().isEmpty())
187 /* FIXME-3 need to set current, too
189 proxySelModel->setCurrentIndex (
190 newsel.indexes().first(),
191 QItemSelectionModel::ClearAndSelect );
192 treeEditor->setCurrentIndex (newsel.indexes().first() );
195 // Re-emit but map selection first
197 treeEditor->getProxyModel()->mapSelectionToSource (newsel),
198 QItemSelectionModel::ClearAndSelect );
203 void VymView::expandAll()
205 treeEditor->expandAll();
208 void VymView::expandOneLevel()
212 BranchItem *cur=NULL;
213 BranchItem *prev=NULL;
216 // Find level to expand
217 model->nextBranch(cur,prev);
220 // FIXME-3 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
221 pix=model->index (cur);
223 if (!treeEditor->isExpanded(pix) && d < level)
225 model->nextBranch(cur,prev);
228 // Expand all to level
231 model->nextBranch(cur,prev);
234 // FIXME-3 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
235 pix=model->index (cur);
237 if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
238 treeEditor->setExpanded(pix,true);
239 model->nextBranch(cur,prev);
241 /* FIXME-3 optimize expanding by using flat version of next
242 model->nextBranch(cur,prev,false);
245 cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
247 model->nextBranch(cur,prev,false);
252 void VymView::collapseOneLevel()
256 BranchItem *cur=NULL;
257 BranchItem *prev=NULL;
260 // Find level to collapse
261 model->nextBranch(cur,prev);
264 // FIXME-3 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
265 pix=model->index (cur);
267 if (treeEditor->isExpanded(pix) && d > level)
269 model->nextBranch(cur,prev);
272 // collapse all to level
275 model->nextBranch(cur,prev);
278 // FIXME-3 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
279 pix=model->index (cur);
281 if (treeEditor->isExpanded(pix) && d >= level)
282 treeEditor->setExpanded(pix,false);
283 model->nextBranch(cur,prev);
287 void VymView::showSelection()
289 QModelIndex ix=model->getSelectedIndex();
290 treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
291 mapEditor->scrollTo ( ix); // FIXME-3 also called from MapEditor::updateSelection...
294 void VymView::showFindWidget()
299 void VymView::hideFindWidget()
301 // findWidget hides itself, but we want to have focus back at mapEditor usually
302 if (mapEditor) mapEditor->setFocus();
305 void VymView::findNext (QString s)
308 BranchItem *bi=model->findText(s, cs);
310 findWidget->setStatus (FindWidget::Success);
312 findWidget->setStatus (FindWidget::Failed);
316 void VymView::findReset()
319 if (mapEditor) mapEditor->setFocus();
322 void VymView::toggleTreeEditor()
324 if (treeEditor->isVisible() )