3 #include "branchitem.h"
4 #include "findwidget.h"
5 #include "mainwindow.h"
7 #include "treeeditor.h"
9 extern Main *mainWindow;
12 VymView::VymView(VymModel *m)
17 findWidget=new FindWidget (this);
21 treeEditor=new TreeEditor (model);
22 //treeEditor->setModel ((QAbstractItemModel*)model);
23 //treeEditor->setMinimumWidth (50);
25 treeEditor->setColumnWidth (0,150);
26 treeEditor->setAnimated (true);
28 // FIXME-3 use proxySelModel=treeEditor->selectionModel();
29 selModel=new QItemSelectionModel (model);
31 //model->setSelectionModel (proxySelModel);
32 model->setSelectionModel (selModel);
33 treeEditor->setSelectionModel (selModel);
35 // Create good old MapEditor
36 mapEditor=model->getMapEditor();
37 if (!mapEditor) mapEditor=new MapEditor (model);
40 QVBoxLayout* mainLayout = new QVBoxLayout (this);
41 QSplitter *splitter= new QSplitter;
43 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
44 //sizePolicy.setHorizontalStretch(0);
45 //sizePolicy.setVerticalStretch(0);
46 //sizePolicy.setHeightForWidth(this->sizePolicy().hasHeightForWidth());
47 splitter->setSizePolicy(sizePolicy);
48 mainLayout->addWidget (splitter);
49 mainLayout->addWidget (findWidget);
56 proxySelModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
57 this,SLOT (changeProxySelection(const QItemSelection &,const QItemSelection &)));
60 // Selection in Model changed
62 selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
63 this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
65 // Tell MapEditor to update selection
66 /* FIXME-3 done implicit here in VymView
68 selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
69 mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
72 // Needed to update selbox during animation
74 model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
75 mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
77 // Connect data changed signals
79 model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)),
80 mapEditor,SLOT (updateData(const QModelIndex &) ) );
83 model, SIGNAL (sortFilterChanged (const QString &)),
84 treeEditor, SLOT (setSortFilter (const QString &) ) );
87 model, SIGNAL (noteHasChanged(QModelIndex) ),
88 mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
91 model, SIGNAL (expandAll() ),
92 this, SLOT (expandAll () ) );
95 model, SIGNAL (expandOneLevel() ),
96 this, SLOT (expandOneLevel() ) );
99 model, SIGNAL (collapseOneLevel() ),
100 this, SLOT (collapseOneLevel() ) );
103 model, SIGNAL (showSelection() ),
104 this, SLOT (showSelection() ) );
108 model, SIGNAL (showFindWidget() ),
109 this, SLOT (showFindWidget() ) );
112 findWidget , SIGNAL (hideFindWidget() ),
113 this, SLOT (hideFindWidget() ) );
116 findWidget, SIGNAL (nextButton (QString) ),
117 this, SLOT (findNext(QString) ) );
119 mapEditor->setAntiAlias (mainWindow->isAliased());
120 mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
122 splitter->addWidget (treeEditor);
123 splitter->addWidget (mapEditor);
129 splitter->setSizes(widths);
134 //cout << "Destructor VymView\n";
137 VymModel* VymView::getModel()
142 MapEditor* VymView::getMapEditor()
147 void VymView::initFocus()
149 mapEditor->setFocus();
152 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
154 //cout << "VV::changeSelection newsel.count="<<newsel.indexes().count()<<endl;
156 mainWindow->changeSelection (model,newsel,oldsel);
157 mapEditor->updateSelection (newsel,oldsel);
159 if (newsel.indexes().count()>0)
162 /* FIXME-3 use proxymodel
163 proxySelModel->select (
164 treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
165 QItemSelectionModel::ClearAndSelect );
168 QModelIndex ix=newsel.indexes().first();
169 selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect );
170 treeEditor->setCurrentIndex (ix);
176 void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &)
178 // Notify mainwindow to update satellites, but map selection to
179 // original model first
181 //cout << "VV::changeProxySelection newsel.count="<<newsel.indexes().count()<<endl;
182 if (!newsel.indexes().isEmpty())
184 /* FIXME-3 need to set current, too
186 proxySelModel->setCurrentIndex (
187 newsel.indexes().first(),
188 QItemSelectionModel::ClearAndSelect );
189 treeEditor->setCurrentIndex (newsel.indexes().first() );
192 // Re-emit but map selection first
194 treeEditor->getProxyModel()->mapSelectionToSource (newsel),
195 QItemSelectionModel::ClearAndSelect );
200 void VymView::expandAll()
202 treeEditor->expandAll();
205 void VymView::expandOneLevel()
209 BranchItem *cur=NULL;
210 BranchItem *prev=NULL;
213 // Find level to expand
214 model->nextBranch(cur,prev);
217 // FIXME-3 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
218 pix=model->index (cur);
220 if (!treeEditor->isExpanded(pix) && d < level)
222 model->nextBranch(cur,prev);
225 // Expand all to level
228 model->nextBranch(cur,prev);
231 // FIXME-3 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
232 pix=model->index (cur);
234 if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
235 treeEditor->setExpanded(pix,true);
236 model->nextBranch(cur,prev);
238 /* FIXME-3 optimize expanding by using flat version of next
239 model->nextBranch(cur,prev,false);
242 cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
244 model->nextBranch(cur,prev,false);
249 void VymView::collapseOneLevel()
253 BranchItem *cur=NULL;
254 BranchItem *prev=NULL;
257 // Find level to collapse
258 model->nextBranch(cur,prev);
261 // FIXME-3 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
262 pix=model->index (cur);
264 if (treeEditor->isExpanded(pix) && d > level)
266 model->nextBranch(cur,prev);
269 // collapse all to level
272 model->nextBranch(cur,prev);
275 // FIXME-3 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
276 pix=model->index (cur);
278 if (treeEditor->isExpanded(pix) && d >= level)
279 treeEditor->setExpanded(pix,false);
280 model->nextBranch(cur,prev);
284 void VymView::showSelection()
286 QModelIndex ix=model->getSelectedIndex();
287 treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
288 mapEditor->scrollTo ( ix); // FIXME-3 also called from MapEditor::updateSelection...
291 void VymView::showFindWidget()
296 void VymView::hideFindWidget()
298 // findWidget hides itself, but we want to have focus back at mapEditor usually
299 if (mapEditor) mapEditor->setFocus();
302 void VymView::findNext (QString s)
305 BranchItem *bi=model->findText(s, cs);
307 findWidget->setStatus (FindWidget::Success);
309 findWidget->setStatus (FindWidget::Failed);
313 void VymView::findReset()
316 if (mapEditor) mapEditor->setFocus();
319 void VymView::toggleTreeEditor()
321 if (treeEditor->isVisible() )