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-2 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 // FIXME-2 testing, if that reenables updating 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 (nextButton (QString) ),
116 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-2 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-2 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-2 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-2 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-2 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-2 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::findNext (QString s)
299 BranchItem *bi=model->findText(s, cs);
301 findWidget->setStatus (FindWidget::Success);
303 findWidget->setStatus (FindWidget::Failed);