3 #include "branchitem.h"
4 #include "dockeditor.h"
5 #include "mainwindow.h"
7 #include "treedelegate.h"
8 #include "slideeditor.h"
9 #include "treeeditor.h"
11 extern Main *mainWindow;
12 extern Settings settings;
14 VymView::VymView(VymModel *m)
17 model->setView (this);
20 treeEditor=new TreeEditor (model);
22 selModel=new QItemSelectionModel (model);
23 model->setSelectionModel (selModel);
25 treeEditor->setSelectionModel (selModel);
26 treeEditor->setColumnWidth (0,150);
27 treeEditor->setAnimated (true);
28 treeEditor->resize ( 20,200);
30 TreeDelegate *delegate=new TreeDelegate (this);
31 treeEditor->setItemDelegate (delegate);
34 de = new DockEditor (tr("Tree Editor","Title of dockable editor widget"), this, model);
35 de->setWidget (treeEditor);
36 de->setAllowedAreas (Qt::AllDockWidgetAreas);
37 addDockWidget(Qt::LeftDockWidgetArea, de);
41 treeEditorDE, SIGNAL (visibilityChanged(bool) ),
42 mainWindow,SLOT (updateActions() ) );
44 // Create good old MapEditor
45 mapEditor=model->getMapEditor();
46 if (!mapEditor) mapEditor=new MapEditor (model);
47 setCentralWidget (mapEditor);
50 slideEditor=new SlideEditor (model);
52 de = new DockEditor (tr("Slide Editor","Title of dockable editor widget"), this, model);
53 de->setWidget (slideEditor);
54 de->setAllowedAreas (Qt::AllDockWidgetAreas);
55 addDockWidget(Qt::RightDockWidgetArea, de);
57 slideEditorDE->hide();
59 slideEditorDE, SIGNAL (visibilityChanged(bool) ),
60 mainWindow,SLOT (updateActions() ) );
64 QVBoxLayout* mainLayout = new QVBoxLayout (this);
65 QSplitter *splitter= new QSplitter (this);
67 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
68 splitter->setSizePolicy(sizePolicy);
69 mainLayout->addWidget (splitter);
74 // Selection in Model changed
76 selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
77 this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
79 // Needed to update selbox during animation
81 model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
82 mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
84 // Connect data changed signals
86 model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)),
87 mapEditor,SLOT (updateData(const QModelIndex &) ) );
90 model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)),
91 this, SLOT (updateDockWidgetTitles() ) );
94 model, SIGNAL (updateQueries (VymModel*)),
95 mainWindow,SLOT (updateQueries(VymModel*) ) );
98 model, SIGNAL (noteChanged(QModelIndex) ),
99 mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
102 model, SIGNAL (expandAll() ),
103 this, SLOT (expandAll () ) );
106 model, SIGNAL (expandOneLevel() ),
107 this, SLOT (expandOneLevel() ) );
110 model, SIGNAL (collapseOneLevel() ),
111 this, SLOT (collapseOneLevel() ) );
114 model, SIGNAL (collapseUnselected() ),
115 this, SLOT (collapseUnselected() ) );
118 model, SIGNAL (showSelection() ),
119 this, SLOT (showSelection() ) );
122 model, SIGNAL (updateLayout() ),
123 mapEditor, SLOT (autoLayout() ) );
125 mapEditor->setAntiAlias (mainWindow->isAliased());
126 mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
131 if (treeEditorIsVisible() )
132 settings.setLocalValue(model->getFilePath(),"/treeeditor/visible","true");
134 settings.setLocalValue(model->getFilePath(),"/treeeditor/visible","false");
137 void VymView::readSettings()
139 if (settings.localValue(model->getFilePath(),"/slideeditor/visible","false").toBool() )
140 slideEditorDE->show();
142 slideEditorDE->hide();
143 if (settings.localValue(model->getFilePath(),"/treeeditor/visible","true").toBool() )
144 treeEditorDE->show();
146 treeEditorDE->hide();
149 VymModel* VymView::getModel()
154 MapEditor* VymView::getMapEditor()
159 bool VymView::treeEditorIsVisible()
161 return treeEditorDE->isVisible();
164 bool VymView::slideEditorIsVisible()
166 return slideEditorDE->isVisible();
169 void VymView::initFocus()
171 mapEditor->setFocus();
174 void VymView::nextSlide()
176 slideEditor->nextSlide();
179 void VymView::previousSlide()
181 slideEditor->previousSlide();
184 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &desel)
186 // Update note editor and heading editor // FIXME-3 improve this, evtl. move from mainwindow to here
187 model->updateSelection (newsel,desel);
188 mainWindow->changeSelection (model,newsel,desel);
189 mainWindow->updateDockWidgetTitles( model );
190 mapEditor->updateSelection (newsel,desel);
194 void VymView::updateDockWidgetTitles()
196 mainWindow->updateDockWidgetTitles( model );
199 void VymView::expandAll()
201 treeEditor->expandAll();
204 void VymView::expandOneLevel()
208 BranchItem *cur=NULL;
209 BranchItem *prev=NULL;
212 // Find level to expand
213 model->nextBranch(cur,prev);
216 pix=model->index (cur);
218 if (!treeEditor->isExpanded(pix) && d < level)
220 model->nextBranch(cur,prev);
223 // Expand all to level
226 model->nextBranch(cur,prev);
229 pix=model->index (cur);
231 if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
232 treeEditor->setExpanded(pix,true);
233 model->nextBranch(cur,prev);
237 void VymView::collapseOneLevel()
241 BranchItem *cur=NULL;
242 BranchItem *prev=NULL;
245 // Find level to collapse
246 model->nextBranch(cur,prev);
249 pix=model->index (cur);
251 if (treeEditor->isExpanded(pix) && d > level)
253 model->nextBranch(cur,prev);
256 // collapse all to level
259 model->nextBranch(cur,prev);
262 pix=model->index (cur);
264 if (treeEditor->isExpanded(pix) && d >= level)
265 treeEditor->setExpanded(pix,false);
266 model->nextBranch(cur,prev);
270 void VymView::collapseUnselected()
272 BranchItem *cur=NULL;
273 BranchItem *prev=NULL;
276 // Find level to collapse
277 TreeItem *selti=model->getSelectedItem();
280 int level=selti->depth();
282 // collapse all to level
283 model->nextBranch(cur,prev);
287 pix=model->index (cur);
288 if (treeEditor->isExpanded(pix) && level <= cur->depth())
290 treeEditor->setExpanded(pix,false);
293 model->nextBranch(cur,prev);
296 /* FIXME-3 "collapse more" unimplemented yet
299 // If we didn't collapse anything so far collapse more
300 qDebug()<<"VM::collapse more";
304 // Find level to collapse
305 model->nextBranch(cur,prev);
308 pix=model->index (cur);
310 if (treeEditor->isExpanded(pix) && d > level && )
312 model->nextBranch(cur,prev);
315 // collapse all to level
316 model->nextBranch(cur,prev);
320 pix=model->index (cur);
321 if (treeEditor->isExpanded(pix) && level <= cur->depth())
323 treeEditor->setExpanded(pix,false);
326 model->nextBranch(cur,prev);
331 void VymView::showSelection()
333 QModelIndex ix=model->getSelectedIndex();
334 treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
335 mapEditor->scrollTo ( ix);
338 void VymView::toggleTreeEditor()
340 if (treeEditorDE->isVisible() )
342 treeEditorDE->hide();
343 settings.setLocalValue(model->getFilePath(),"/treeeditor/visible","false");
346 treeEditorDE->show();
347 settings.setLocalValue(model->getFilePath(),"/treeeditor/visible","true");
352 void VymView::toggleSlideEditor()
354 if (slideEditorDE->isVisible() )
356 slideEditorDE->hide();
357 settings.setLocalValue(model->getFilePath(),"/slideeditor/visible","false");
360 slideEditorDE->show();
361 settings.setLocalValue(model->getFilePath(),"/slideeditor/visible","true");
365 void VymView::setFocusMapEditor()
367 mapEditor->setFocus();