3 #include "branchitem.h"
4 #include "dockeditor.h"
5 #include "mainwindow.h"
7 #include "slideeditor.h"
8 #include "treedelegate.h"
9 #include "treeeditor.h"
11 extern Main *mainWindow;
12 extern Settings settings;
14 VymView::VymView(VymModel *m)
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"),
36 de->setWidget(treeEditor);
37 de->setAllowedAreas(Qt::AllDockWidgetAreas);
38 addDockWidget(Qt::LeftDockWidgetArea, de);
41 connect(treeEditorDE, SIGNAL(visibilityChanged(bool)), mainWindow,
42 SLOT(updateActions()));
44 // Create good old MapEditor
45 mapEditor = model->getMapEditor();
47 mapEditor = new MapEditor(model);
48 setCentralWidget(mapEditor);
51 slideEditor = new SlideEditor(model);
53 de = new DockEditor(tr("Slide Editor", "Title of dockable editor widget"),
55 de->setWidget(slideEditor);
56 de->setAllowedAreas(Qt::AllDockWidgetAreas);
57 addDockWidget(Qt::RightDockWidgetArea, de);
59 slideEditorDE->hide();
60 connect(slideEditorDE, SIGNAL(visibilityChanged(bool)), mainWindow,
61 SLOT(updateActions()));
65 // Selection in Model changed
68 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
70 SLOT(changeSelection(const QItemSelection &, const QItemSelection &)));
72 // Needed to update selbox during animation
76 selectionChanged(const QItemSelection &, const QItemSelection &)),
78 SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
80 // Connect data changed signals
82 SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
83 mapEditor, SLOT(updateData(const QModelIndex &)));
86 SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this,
87 SLOT(updateDockWidgetTitles())); // FIXME-3 connect directly to
88 // MainWindow and rename method
89 // (also updates selection in BPE)
92 SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
93 mainWindow, SLOT(updateHeadingEditor())); // FIXME-2 introduced new to update BG color when frameBrush changes
95 connect(model, SIGNAL(updateQueries(VymModel *)), mainWindow,
96 SLOT(updateQueries(VymModel *)));
98 connect(model, SIGNAL(expandAll()), this, SLOT(expandAll()));
100 connect(model, SIGNAL(expandOneLevel()), this, SLOT(expandOneLevel()));
102 connect(model, SIGNAL(collapseOneLevel()), this, SLOT(collapseOneLevel()));
104 connect(model, SIGNAL(collapseUnselected()), this,
105 SLOT(collapseUnselected()));
107 connect(model, SIGNAL(showSelection(bool)), this, SLOT(showSelection(bool)));
109 connect(model, SIGNAL(updateLayout()), mapEditor, SLOT(autoLayout()));
111 mapEditor->setAntiAlias(mainWindow->isAliased());
112 mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
119 settings.setLocalValue(model->getFilePath(), "/treeEditor/visible",
120 treeEditorIsVisible());
121 settings.setLocalValue(model->getFilePath(), "/slideEditor/visible",
122 slideEditorIsVisible());
125 void VymView::readSettings()
128 .localValue(model->getFilePath(), "/slideEditor/visible", "false")
130 slideEditorDE->show();
132 slideEditorDE->hide();
134 if (settings.localValue(model->getFilePath(), "/treeEditor/visible", "true")
136 treeEditorDE->show();
138 treeEditorDE->hide();
141 VymModel *VymView::getModel() { return model; }
143 MapEditor *VymView::getMapEditor() { return mapEditor; }
145 bool VymView::treeEditorIsVisible() { return treeEditorDE->isVisible(); }
147 bool VymView::slideEditorIsVisible() { return slideEditorDE->isVisible(); }
149 void VymView::initFocus() { mapEditor->setFocus(); }
151 void VymView::nextSlide() { slideEditor->nextSlide(); }
153 void VymView::previousSlide() { slideEditor->previousSlide(); }
155 void VymView::setSelectionBrush(const QBrush &brush)
157 mapEditor->setSelectionBrush(brush);
158 treeEditor->setStyleSheet(
159 "selection-background-color: " + brush.color().name(QColor::HexArgb) + ";" +
160 "background-color: " + mapEditor->getScene()->backgroundBrush().color().name());
163 void VymView::setBackgroundColor(const QColor &col)
165 mapEditor->getScene()->setBackgroundBrush(col);
166 treeEditor->setStyleSheet(
167 "selection-background-color: " + mapEditor->getSelectionBrush().color().name() + ";" +
168 "background-color: " + col.name());
169 mainWindow->updateHeadingEditor();
172 void VymView::setLinkColor(const QColor &col)
174 // Set color for "link arrows" in TreeEditor
176 // Alternatively one could use stylesheets
177 // https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qtreeview
178 QPalette palette = treeEditor->palette();
179 palette.setColor(QPalette::Text, col);
180 treeEditor->setPalette(palette);
183 void VymView::changeSelection(const QItemSelection &newsel,
184 const QItemSelection &desel)
186 // Update note editor and heading editor // FIXME-3 improve this, evtl. move
187 // from mainwindow to here
188 model->updateSelection(newsel, desel);
189 mainWindow->changeSelection(model, newsel, desel);
190 mainWindow->updateDockWidgetTitles(model);
191 mapEditor->updateSelection(newsel, desel);
193 showSelection(false);
196 void VymView::updateDockWidgetTitles()
198 mainWindow->updateDockWidgetTitles(model);
201 void VymView::expandAll() { treeEditor->expandAll(); }
203 void VymView::expandOneLevel()
207 BranchItem *cur = NULL;
208 BranchItem *prev = NULL;
211 // Find level to expand
212 model->nextBranch(cur, prev);
214 pix = model->index(cur);
216 if (!treeEditor->isExpanded(pix) && d < level)
218 model->nextBranch(cur, prev);
221 // Expand all to level
224 model->nextBranch(cur, prev);
226 pix = model->index(cur);
228 if (!treeEditor->isExpanded(pix) && d <= level &&
229 cur->branchCount() > 0)
230 treeEditor->setExpanded(pix, true);
231 model->nextBranch(cur, prev);
235 void VymView::collapseOneLevel()
239 BranchItem *cur = NULL;
240 BranchItem *prev = NULL;
243 // Find level to collapse
244 model->nextBranch(cur, prev);
246 pix = model->index(cur);
248 if (treeEditor->isExpanded(pix) && d > level)
250 model->nextBranch(cur, prev);
253 // collapse all to level
256 model->nextBranch(cur, prev);
258 pix = model->index(cur);
260 if (treeEditor->isExpanded(pix) && d >= level)
261 treeEditor->setExpanded(pix, false);
262 model->nextBranch(cur, prev);
266 void VymView::collapseUnselected()
270 // Find level to collapse
271 BranchItem *selbi = model->getSelectedBranch();
275 QList<BranchItem *> itemPath;
277 // Do not include selected branch,
278 // this one also should be collapsed later
279 BranchItem *cur = selbi->parentBranch();
280 BranchItem *prev = NULL;
282 while (cur->parentBranch()) {
284 cur = cur->parentBranch();
289 // collapse all to level
290 model->nextBranch(cur, prev);
292 pix = model->index(cur);
293 if (treeEditor->isExpanded(pix) && itemPath.indexOf(cur) < 0) {
294 treeEditor->setExpanded(pix, false);
296 model->nextBranch(cur, prev);
300 void VymView::showSelection(bool scaled)
302 QModelIndex ix = model->getSelectedIndex();
303 treeEditor->scrollTo(ix, QAbstractItemView::EnsureVisible);
304 mapEditor->ensureSelectionVisibleAnimated(scaled);
307 void VymView::toggleTreeEditor()
309 if (treeEditorDE->isVisible()) {
310 treeEditorDE->hide();
311 settings.setLocalValue(model->getFilePath(), "/treeEditor/visible",
315 treeEditorDE->show();
316 settings.setLocalValue(model->getFilePath(), "/treeEditor/visible",
322 void VymView::toggleSlideEditor()
324 if (slideEditorDE->isVisible()) {
325 slideEditorDE->hide();
326 settings.setLocalValue(model->getFilePath(), "/slideEditor/visible",
330 slideEditorDE->show();
331 settings.setLocalValue(model->getFilePath(), "/slideEditor/visible",
336 void VymView::setFocusMapEditor() { mapEditor->setFocus(); }