Chris@127
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@127
|
2
|
Chris@127
|
3 /*
|
Chris@127
|
4 Sonic Visualiser
|
Chris@127
|
5 An audio file viewer and annotation editor.
|
Chris@127
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@182
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@127
|
8
|
Chris@127
|
9 This program is free software; you can redistribute it and/or
|
Chris@127
|
10 modify it under the terms of the GNU General Public License as
|
Chris@127
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@127
|
12 License, or (at your option) any later version. See the file
|
Chris@127
|
13 COPYING included with this distribution for more information.
|
Chris@127
|
14 */
|
Chris@127
|
15
|
Chris@127
|
16 #include "PaneStack.h"
|
Chris@127
|
17
|
Chris@128
|
18 #include "Pane.h"
|
Chris@127
|
19 #include "widgets/PropertyStack.h"
|
Chris@323
|
20 #include "widgets/IconLoader.h"
|
Chris@500
|
21 #include "widgets/ClickableLabel.h"
|
Chris@128
|
22 #include "layer/Layer.h"
|
Chris@128
|
23 #include "ViewManager.h"
|
Chris@867
|
24 #include "AlignmentView.h"
|
Chris@127
|
25
|
Chris@127
|
26 #include <QApplication>
|
Chris@127
|
27 #include <QHBoxLayout>
|
Chris@323
|
28 #include <QVBoxLayout>
|
Chris@127
|
29 #include <QPainter>
|
Chris@127
|
30 #include <QPalette>
|
Chris@127
|
31 #include <QLabel>
|
Chris@323
|
32 #include <QPushButton>
|
Chris@127
|
33 #include <QSplitter>
|
Chris@127
|
34 #include <QStackedWidget>
|
Chris@127
|
35
|
Chris@127
|
36 #include <iostream>
|
Chris@127
|
37
|
Chris@247
|
38 //#define DEBUG_PANE_STACK 1
|
Chris@247
|
39
|
Chris@127
|
40 PaneStack::PaneStack(QWidget *parent, ViewManager *viewManager) :
|
Chris@127
|
41 QFrame(parent),
|
Chris@1408
|
42 m_currentPane(nullptr),
|
Chris@712
|
43 m_showAccessories(true),
|
Chris@867
|
44 m_showAlignmentViews(false),
|
Chris@127
|
45 m_splitter(new QSplitter),
|
Chris@127
|
46 m_propertyStackStack(new QStackedWidget),
|
Chris@127
|
47 m_viewManager(viewManager),
|
Chris@615
|
48 m_propertyStackMinWidth(100),
|
Chris@127
|
49 m_layoutStyle(PropertyStackPerPaneLayout)
|
Chris@127
|
50 {
|
Chris@127
|
51 QHBoxLayout *layout = new QHBoxLayout;
|
Chris@127
|
52 layout->setMargin(0);
|
Chris@127
|
53 layout->setSpacing(0);
|
Chris@127
|
54
|
Chris@127
|
55 m_splitter->setOrientation(Qt::Vertical);
|
Chris@127
|
56 m_splitter->setOpaqueResize(false);
|
Chris@127
|
57
|
Chris@127
|
58 layout->addWidget(m_splitter);
|
Chris@127
|
59 layout->setStretchFactor(m_splitter, 1);
|
Chris@127
|
60 layout->addWidget(m_propertyStackStack);
|
Chris@127
|
61 m_propertyStackStack->hide();
|
Chris@127
|
62
|
Chris@127
|
63 setLayout(layout);
|
Chris@127
|
64 }
|
Chris@127
|
65
|
Chris@712
|
66 void
|
Chris@712
|
67 PaneStack::setShowPaneAccessories(bool show)
|
Chris@712
|
68 {
|
Chris@712
|
69 m_showAccessories = show;
|
Chris@712
|
70 }
|
Chris@712
|
71
|
Chris@867
|
72 void
|
Chris@867
|
73 PaneStack::setShowAlignmentViews(bool show)
|
Chris@867
|
74 {
|
Chris@867
|
75 m_showAlignmentViews = show;
|
cannam@1444
|
76 for (int i = 0; in_range_for(m_panes, i); ++i) {
|
cannam@1444
|
77 m_panes[i].alignmentView->setVisible(m_showAlignmentViews &&
|
cannam@1444
|
78 in_range_for(m_panes, i+1));
|
Chris@867
|
79 }
|
Chris@867
|
80 }
|
Chris@867
|
81
|
Chris@127
|
82 Pane *
|
Chris@127
|
83 PaneStack::addPane(bool suppressPropertyBox)
|
Chris@127
|
84 {
|
Chris@539
|
85 return insertPane(getPaneCount(), suppressPropertyBox);
|
Chris@539
|
86 }
|
Chris@539
|
87
|
Chris@539
|
88 Pane *
|
Chris@539
|
89 PaneStack::insertPane(int index, bool suppressPropertyBox)
|
Chris@539
|
90 {
|
Chris@127
|
91 QFrame *frame = new QFrame;
|
Chris@495
|
92
|
Chris@495
|
93 QGridLayout *layout = new QGridLayout;
|
Chris@127
|
94 layout->setMargin(0);
|
Chris@127
|
95 layout->setSpacing(2);
|
Chris@127
|
96
|
Chris@323
|
97 QPushButton *xButton = new QPushButton(frame);
|
Chris@323
|
98 xButton->setIcon(IconLoader().load("cross"));
|
Chris@323
|
99 xButton->setFixedSize(QSize(16, 16));
|
Chris@497
|
100 xButton->setFlat(true);
|
Chris@712
|
101 xButton->setVisible(m_showAccessories);
|
Chris@495
|
102 layout->addWidget(xButton, 0, 0);
|
Chris@323
|
103 connect(xButton, SIGNAL(clicked()), this, SLOT(paneDeleteButtonClicked()));
|
Chris@323
|
104
|
Chris@500
|
105 ClickableLabel *currentIndicator = new ClickableLabel(frame);
|
Chris@500
|
106 connect(currentIndicator, SIGNAL(clicked()), this, SLOT(indicatorClicked()));
|
Chris@495
|
107 layout->addWidget(currentIndicator, 1, 0);
|
Chris@495
|
108 layout->setRowStretch(1, 20);
|
Chris@497
|
109 currentIndicator->setMinimumWidth(8);
|
Chris@127
|
110 currentIndicator->setScaledContents(true);
|
Chris@712
|
111 currentIndicator->setVisible(m_showAccessories);
|
Chris@127
|
112
|
Chris@908
|
113 sv_frame_t initialCentreFrame = -1;
|
Chris@855
|
114 if (!m_panes.empty()) {
|
Chris@855
|
115 initialCentreFrame = m_panes[0].pane->getCentreFrame();
|
Chris@516
|
116 }
|
Chris@516
|
117
|
Chris@127
|
118 Pane *pane = new Pane(frame);
|
Chris@516
|
119 if (initialCentreFrame >= 0) {
|
Chris@516
|
120 pane->setViewManager(m_viewManager, initialCentreFrame);
|
Chris@516
|
121 } else {
|
Chris@516
|
122 pane->setViewManager(m_viewManager);
|
Chris@516
|
123 }
|
Chris@495
|
124 layout->addWidget(pane, 0, 1, 2, 1);
|
Chris@495
|
125 layout->setColumnStretch(1, 20);
|
Chris@127
|
126
|
Chris@867
|
127 AlignmentView *av = new AlignmentView(frame);
|
Chris@1446
|
128 av->setFixedHeight(ViewManager::scalePixelSize(20));
|
Chris@867
|
129 av->setViewManager(m_viewManager);
|
cannam@1444
|
130 av->setVisible(false); // for now
|
Chris@867
|
131 layout->addWidget(av, 2, 1);
|
Chris@867
|
132
|
Chris@1408
|
133 QWidget *properties = nullptr;
|
Chris@127
|
134 if (suppressPropertyBox) {
|
Chris@1266
|
135 properties = new QFrame();
|
Chris@127
|
136 } else {
|
Chris@1266
|
137 properties = new PropertyStack(frame, pane);
|
Chris@1266
|
138 connect(properties, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
|
Chris@1266
|
139 this, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
|
Chris@190
|
140 connect(properties, SIGNAL(viewSelected(View *)),
|
Chris@190
|
141 this, SLOT(viewSelected(View *)));
|
Chris@189
|
142 connect(properties, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@189
|
143 this, SIGNAL(contextHelpChanged(const QString &)));
|
Chris@127
|
144 }
|
Chris@127
|
145 if (m_layoutStyle == PropertyStackPerPaneLayout) {
|
Chris@495
|
146 layout->addWidget(properties, 0, 2, 2, 1);
|
Chris@127
|
147 } else {
|
Chris@127
|
148 properties->setParent(m_propertyStackStack);
|
Chris@127
|
149 m_propertyStackStack->addWidget(properties);
|
Chris@127
|
150 }
|
Chris@606
|
151 layout->setColumnStretch(2, 0);
|
Chris@127
|
152
|
Chris@127
|
153 PaneRec rec;
|
Chris@127
|
154 rec.pane = pane;
|
Chris@127
|
155 rec.propertyStack = properties;
|
Chris@605
|
156 rec.xButton = xButton;
|
Chris@127
|
157 rec.currentIndicator = currentIndicator;
|
Chris@127
|
158 rec.frame = frame;
|
Chris@127
|
159 rec.layout = layout;
|
Chris@867
|
160 rec.alignmentView = av;
|
Chris@127
|
161 m_panes.push_back(rec);
|
Chris@127
|
162
|
Chris@127
|
163 frame->setLayout(layout);
|
Chris@539
|
164 m_splitter->insertWidget(index, frame);
|
Chris@127
|
165
|
Chris@127
|
166 connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)),
|
Chris@1266
|
167 this, SLOT(propertyContainerAdded(PropertyContainer *)));
|
Chris@127
|
168 connect(pane, SIGNAL(propertyContainerRemoved(PropertyContainer *)),
|
Chris@1266
|
169 this, SLOT(propertyContainerRemoved(PropertyContainer *)));
|
Chris@127
|
170 connect(pane, SIGNAL(paneInteractedWith()),
|
Chris@1266
|
171 this, SLOT(paneInteractedWith()));
|
Chris@127
|
172 connect(pane, SIGNAL(rightButtonMenuRequested(QPoint)),
|
Chris@127
|
173 this, SLOT(rightButtonMenuRequested(QPoint)));
|
Chris@312
|
174 connect(pane, SIGNAL(dropAccepted(QStringList)),
|
Chris@312
|
175 this, SLOT(paneDropAccepted(QStringList)));
|
Chris@312
|
176 connect(pane, SIGNAL(dropAccepted(QString)),
|
Chris@312
|
177 this, SLOT(paneDropAccepted(QString)));
|
Chris@908
|
178 connect(pane, SIGNAL(doubleClickSelectInvoked(sv_frame_t)),
|
Chris@908
|
179 this, SIGNAL(doubleClickSelectInvoked(sv_frame_t)));
|
Chris@127
|
180
|
Chris@271
|
181 emit paneAdded(pane);
|
Chris@271
|
182 emit paneAdded();
|
Chris@271
|
183
|
Chris@127
|
184 if (!m_currentPane) {
|
Chris@1266
|
185 setCurrentPane(pane);
|
Chris@127
|
186 }
|
Chris@127
|
187
|
Chris@605
|
188 showOrHidePaneAccessories();
|
Chris@867
|
189 relinkAlignmentViews();
|
Chris@605
|
190
|
Chris@127
|
191 return pane;
|
Chris@127
|
192 }
|
Chris@127
|
193
|
Chris@127
|
194 void
|
Chris@867
|
195 PaneStack::relinkAlignmentViews()
|
Chris@867
|
196 {
|
Chris@867
|
197 for (int i = 0; i < (int)m_panes.size(); ++i) {
|
Chris@867
|
198 m_panes[i].alignmentView->setViewAbove(m_panes[i].pane);
|
Chris@867
|
199 if (i + 1 < (int)m_panes.size()) {
|
Chris@867
|
200 m_panes[i].alignmentView->setViewBelow(m_panes[i+1].pane);
|
cannam@1444
|
201 m_panes[i].alignmentView->setVisible(true);
|
Chris@867
|
202 } else {
|
Chris@1408
|
203 m_panes[i].alignmentView->setViewBelow(nullptr);
|
cannam@1444
|
204 m_panes[i].alignmentView->setVisible(false);
|
Chris@867
|
205 }
|
Chris@867
|
206 }
|
Chris@867
|
207 }
|
Chris@867
|
208
|
Chris@867
|
209 void
|
Chris@867
|
210 PaneStack::unlinkAlignmentViews()
|
Chris@867
|
211 {
|
Chris@867
|
212 for (int i = 0; i < (int)m_panes.size(); ++i) {
|
Chris@1408
|
213 m_panes[i].alignmentView->setViewAbove(nullptr);
|
Chris@1408
|
214 m_panes[i].alignmentView->setViewBelow(nullptr);
|
Chris@867
|
215 }
|
Chris@867
|
216 }
|
Chris@867
|
217
|
Chris@867
|
218 void
|
Chris@235
|
219 PaneStack::setPropertyStackMinWidth(int mw)
|
Chris@235
|
220 {
|
Chris@235
|
221 for (std::vector<PaneRec>::iterator i = m_panes.begin();
|
Chris@235
|
222 i != m_panes.end(); ++i) {
|
Chris@235
|
223 i->propertyStack->setMinimumWidth(mw);
|
Chris@235
|
224 }
|
Chris@235
|
225 m_propertyStackMinWidth = mw;
|
Chris@235
|
226 }
|
Chris@235
|
227
|
Chris@235
|
228 void
|
Chris@127
|
229 PaneStack::setLayoutStyle(LayoutStyle style)
|
Chris@127
|
230 {
|
Chris@127
|
231 if (style == m_layoutStyle) return;
|
Chris@127
|
232 m_layoutStyle = style;
|
Chris@127
|
233
|
Chris@127
|
234 std::vector<PaneRec>::iterator i;
|
Chris@127
|
235
|
Chris@127
|
236 switch (style) {
|
Chris@127
|
237
|
Chris@179
|
238 case NoPropertyStacks:
|
Chris@127
|
239 case SinglePropertyStackLayout:
|
Chris@127
|
240
|
Chris@127
|
241 for (i = m_panes.begin(); i != m_panes.end(); ++i) {
|
Chris@127
|
242 i->layout->removeWidget(i->propertyStack);
|
Chris@127
|
243 i->propertyStack->setParent(m_propertyStackStack);
|
Chris@127
|
244 m_propertyStackStack->addWidget(i->propertyStack);
|
Chris@127
|
245 }
|
Chris@179
|
246 m_propertyStackStack->setVisible(style != NoPropertyStacks);
|
Chris@127
|
247 break;
|
Chris@127
|
248
|
Chris@127
|
249 case PropertyStackPerPaneLayout:
|
Chris@127
|
250
|
Chris@127
|
251 for (i = m_panes.begin(); i != m_panes.end(); ++i) {
|
Chris@127
|
252 m_propertyStackStack->removeWidget(i->propertyStack);
|
Chris@127
|
253 i->propertyStack->setParent(i->frame);
|
Chris@495
|
254 i->layout->addWidget(i->propertyStack, 0, 2, 2, 1);
|
Chris@127
|
255 i->propertyStack->show();
|
Chris@127
|
256 }
|
Chris@127
|
257 m_propertyStackStack->hide();
|
Chris@127
|
258 break;
|
Chris@127
|
259 }
|
Chris@127
|
260 }
|
Chris@127
|
261
|
Chris@127
|
262 Pane *
|
Chris@127
|
263 PaneStack::getPane(int n)
|
Chris@127
|
264 {
|
Chris@806
|
265 if (n < (int)m_panes.size()) {
|
Chris@277
|
266 return m_panes[n].pane;
|
Chris@277
|
267 } else {
|
Chris@1408
|
268 return nullptr;
|
Chris@277
|
269 }
|
Chris@277
|
270 }
|
Chris@277
|
271
|
Chris@277
|
272 int
|
Chris@277
|
273 PaneStack::getPaneIndex(Pane *pane)
|
Chris@277
|
274 {
|
Chris@277
|
275 for (int i = 0; i < getPaneCount(); ++i) {
|
Chris@277
|
276 if (pane == getPane(i)) {
|
Chris@277
|
277 return i;
|
Chris@277
|
278 }
|
Chris@277
|
279 }
|
Chris@277
|
280 return -1;
|
Chris@127
|
281 }
|
Chris@127
|
282
|
Chris@127
|
283 Pane *
|
Chris@127
|
284 PaneStack::getHiddenPane(int n)
|
Chris@127
|
285 {
|
Chris@127
|
286 return m_hiddenPanes[n].pane;
|
Chris@127
|
287 }
|
Chris@127
|
288
|
Chris@127
|
289 void
|
Chris@127
|
290 PaneStack::deletePane(Pane *pane)
|
Chris@127
|
291 {
|
Chris@1362
|
292 #ifdef DEBUG_PANE_STACK
|
Chris@1362
|
293 SVCERR << "PaneStack::deletePane(" << pane << ")" << endl;
|
Chris@1362
|
294 #endif
|
Chris@729
|
295
|
Chris@127
|
296 std::vector<PaneRec>::iterator i;
|
Chris@127
|
297 bool found = false;
|
Chris@127
|
298
|
Chris@1408
|
299 QWidget *stack = nullptr;
|
Chris@729
|
300
|
Chris@127
|
301 for (i = m_panes.begin(); i != m_panes.end(); ++i) {
|
Chris@1266
|
302 if (i->pane == pane) {
|
Chris@729
|
303 stack = i->propertyStack;
|
Chris@1266
|
304 m_panes.erase(i);
|
Chris@1266
|
305 found = true;
|
Chris@1266
|
306 break;
|
Chris@1266
|
307 }
|
Chris@127
|
308 }
|
Chris@127
|
309
|
Chris@127
|
310 if (!found) {
|
Chris@127
|
311
|
Chris@1266
|
312 for (i = m_hiddenPanes.begin(); i != m_hiddenPanes.end(); ++i) {
|
Chris@1266
|
313 if (i->pane == pane) {
|
Chris@729
|
314 stack = i->propertyStack;
|
Chris@1266
|
315 m_hiddenPanes.erase(i);
|
Chris@1266
|
316 found = true;
|
Chris@1266
|
317 break;
|
Chris@1266
|
318 }
|
Chris@1266
|
319 }
|
Chris@127
|
320
|
Chris@1266
|
321 if (!found) {
|
Chris@1266
|
322 cerr << "WARNING: PaneStack::deletePane(" << pane << "): Pane not found in visible or hidden panes, not deleting" << endl;
|
Chris@1266
|
323 return;
|
Chris@1266
|
324 }
|
Chris@127
|
325 }
|
Chris@127
|
326
|
Chris@271
|
327 emit paneAboutToBeDeleted(pane);
|
Chris@867
|
328 unlinkAlignmentViews();
|
Chris@271
|
329
|
Chris@1362
|
330 #ifdef DEBUG_PANE_STACK
|
Chris@1362
|
331 SVCERR << "PaneStack::deletePane: about to delete parent " << pane->parent() << " of pane " << pane << endl;
|
Chris@1362
|
332 #endif
|
Chris@729
|
333
|
Chris@729
|
334 // The property stack associated with the parent was initially
|
Chris@729
|
335 // created with the same parent as it, so it would be deleted when
|
Chris@729
|
336 // we delete the pane's parent in a moment -- but it may have been
|
Chris@729
|
337 // reparented depending on the layout. We'd better delete it
|
Chris@729
|
338 // separately first. (This fixes a crash on opening a new layer
|
Chris@729
|
339 // with a new unit type in it, when a long-defunct property box
|
Chris@729
|
340 // could be signalled from the unit database to tell it that a new
|
Chris@729
|
341 // unit had appeared.)
|
Chris@729
|
342 delete stack;
|
Chris@729
|
343
|
Chris@127
|
344 delete pane->parent();
|
Chris@127
|
345
|
Chris@127
|
346 if (m_currentPane == pane) {
|
Chris@1266
|
347 if (m_panes.size() > 0) {
|
Chris@127
|
348 setCurrentPane(m_panes[0].pane);
|
Chris@1266
|
349 } else {
|
Chris@1408
|
350 setCurrentPane(nullptr);
|
Chris@1266
|
351 }
|
Chris@127
|
352 }
|
Chris@271
|
353
|
Chris@605
|
354 showOrHidePaneAccessories();
|
Chris@867
|
355 relinkAlignmentViews();
|
Chris@605
|
356
|
Chris@271
|
357 emit paneDeleted();
|
Chris@127
|
358 }
|
Chris@127
|
359
|
Chris@605
|
360 void
|
Chris@605
|
361 PaneStack::showOrHidePaneAccessories()
|
Chris@605
|
362 {
|
Chris@1362
|
363 #ifdef DEBUG_PANE_STACK
|
Chris@1362
|
364 SVCERR << "PaneStack::showOrHidePaneAccessories: count == " << getPaneCount() << endl;
|
Chris@1362
|
365 #endif
|
Chris@605
|
366
|
Chris@605
|
367 bool multi = (getPaneCount() > 1);
|
Chris@605
|
368 for (std::vector<PaneRec>::iterator i = m_panes.begin();
|
Chris@605
|
369 i != m_panes.end(); ++i) {
|
Chris@712
|
370 i->xButton->setVisible(multi && m_showAccessories);
|
Chris@712
|
371 i->currentIndicator->setVisible(multi && m_showAccessories);
|
Chris@605
|
372 }
|
Chris@605
|
373 }
|
Chris@605
|
374
|
Chris@127
|
375 int
|
Chris@127
|
376 PaneStack::getPaneCount() const
|
Chris@127
|
377 {
|
Chris@908
|
378 return int(m_panes.size());
|
Chris@127
|
379 }
|
Chris@127
|
380
|
Chris@127
|
381 int
|
Chris@127
|
382 PaneStack::getHiddenPaneCount() const
|
Chris@127
|
383 {
|
Chris@908
|
384 return int(m_hiddenPanes.size());
|
Chris@127
|
385 }
|
Chris@127
|
386
|
Chris@127
|
387 void
|
Chris@127
|
388 PaneStack::hidePane(Pane *pane)
|
Chris@127
|
389 {
|
Chris@127
|
390 std::vector<PaneRec>::iterator i = m_panes.begin();
|
Chris@127
|
391
|
Chris@127
|
392 while (i != m_panes.end()) {
|
Chris@1266
|
393 if (i->pane == pane) {
|
Chris@127
|
394
|
Chris@1266
|
395 m_hiddenPanes.push_back(*i);
|
Chris@1266
|
396 m_panes.erase(i);
|
Chris@127
|
397
|
Chris@1266
|
398 QWidget *pw = dynamic_cast<QWidget *>(pane->parent());
|
Chris@1266
|
399 if (pw) pw->hide();
|
Chris@127
|
400
|
Chris@1266
|
401 if (m_currentPane == pane) {
|
Chris@1266
|
402 if (m_panes.size() > 0) {
|
Chris@1266
|
403 setCurrentPane(m_panes[0].pane);
|
Chris@1266
|
404 } else {
|
Chris@1408
|
405 setCurrentPane(nullptr);
|
Chris@1266
|
406 }
|
Chris@1266
|
407 }
|
Chris@1266
|
408
|
Chris@605
|
409 showOrHidePaneAccessories();
|
Chris@605
|
410 emit paneHidden(pane);
|
Chris@605
|
411 emit paneHidden();
|
cannam@1444
|
412 relinkAlignmentViews();
|
Chris@1266
|
413 return;
|
Chris@1266
|
414 }
|
Chris@1266
|
415 ++i;
|
Chris@127
|
416 }
|
Chris@127
|
417
|
Chris@1362
|
418 SVCERR << "WARNING: PaneStack::hidePane(" << pane << "): Pane not found in visible panes" << endl;
|
Chris@127
|
419 }
|
Chris@127
|
420
|
Chris@127
|
421 void
|
Chris@127
|
422 PaneStack::showPane(Pane *pane)
|
Chris@127
|
423 {
|
Chris@127
|
424 std::vector<PaneRec>::iterator i = m_hiddenPanes.begin();
|
Chris@127
|
425
|
Chris@127
|
426 while (i != m_hiddenPanes.end()) {
|
Chris@1266
|
427 if (i->pane == pane) {
|
Chris@1266
|
428 m_panes.push_back(*i);
|
Chris@1266
|
429 m_hiddenPanes.erase(i);
|
Chris@1266
|
430 QWidget *pw = dynamic_cast<QWidget *>(pane->parent());
|
Chris@1266
|
431 if (pw) pw->show();
|
Chris@127
|
432
|
Chris@1266
|
433 //!!! update current pane
|
Chris@127
|
434
|
Chris@605
|
435 showOrHidePaneAccessories();
|
cannam@1444
|
436 relinkAlignmentViews();
|
Chris@605
|
437
|
Chris@1266
|
438 return;
|
Chris@1266
|
439 }
|
Chris@1266
|
440 ++i;
|
Chris@127
|
441 }
|
Chris@127
|
442
|
Chris@1362
|
443 SVCERR << "WARNING: PaneStack::showPane(" << pane << "): Pane not found in hidden panes" << endl;
|
Chris@127
|
444 }
|
Chris@127
|
445
|
Chris@127
|
446 void
|
Chris@127
|
447 PaneStack::setCurrentPane(Pane *pane) // may be null
|
Chris@127
|
448 {
|
Chris@127
|
449 if (m_currentPane == pane) return;
|
Chris@127
|
450
|
Chris@127
|
451 std::vector<PaneRec>::iterator i = m_panes.begin();
|
Chris@127
|
452
|
Chris@127
|
453 // We used to do this by setting the foreground and background
|
Chris@127
|
454 // role, but it seems the background role is ignored and the
|
Chris@127
|
455 // background drawn transparent in Qt 4.1 -- I can't quite see why
|
Chris@127
|
456
|
Chris@127
|
457 QPixmap selectedMap(1, 1);
|
Chris@127
|
458 selectedMap.fill(QApplication::palette().color(QPalette::Foreground));
|
Chris@127
|
459
|
Chris@127
|
460 QPixmap unselectedMap(1, 1);
|
Chris@127
|
461 unselectedMap.fill(QApplication::palette().color(QPalette::Background));
|
Chris@127
|
462
|
Chris@127
|
463 bool found = false;
|
Chris@127
|
464
|
Chris@127
|
465 while (i != m_panes.end()) {
|
Chris@1266
|
466 if (i->pane == pane) {
|
Chris@1266
|
467 i->currentIndicator->setPixmap(selectedMap);
|
Chris@179
|
468 if (m_layoutStyle != PropertyStackPerPaneLayout) {
|
Chris@127
|
469 m_propertyStackStack->setCurrentWidget(i->propertyStack);
|
Chris@127
|
470 }
|
Chris@1266
|
471 found = true;
|
Chris@1266
|
472 } else {
|
Chris@1266
|
473 i->currentIndicator->setPixmap(unselectedMap);
|
Chris@1266
|
474 }
|
Chris@1266
|
475 ++i;
|
Chris@127
|
476 }
|
Chris@127
|
477
|
Chris@1408
|
478 if (found || pane == nullptr) {
|
Chris@1266
|
479 m_currentPane = pane;
|
Chris@1266
|
480 emit currentPaneChanged(m_currentPane);
|
Chris@127
|
481 } else {
|
Chris@1362
|
482 SVCERR << "WARNING: PaneStack::setCurrentPane(" << pane << "): pane is not a visible pane in this stack" << endl;
|
Chris@127
|
483 }
|
Chris@127
|
484 }
|
Chris@127
|
485
|
Chris@127
|
486 void
|
Chris@127
|
487 PaneStack::setCurrentLayer(Pane *pane, Layer *layer) // may be null
|
Chris@127
|
488 {
|
Chris@127
|
489 setCurrentPane(pane);
|
Chris@127
|
490
|
Chris@127
|
491 if (m_currentPane) {
|
Chris@127
|
492
|
Chris@1266
|
493 std::vector<PaneRec>::iterator i = m_panes.begin();
|
Chris@127
|
494
|
Chris@1266
|
495 while (i != m_panes.end()) {
|
Chris@127
|
496
|
Chris@1266
|
497 if (i->pane == pane) {
|
Chris@1266
|
498 PropertyStack *stack = dynamic_cast<PropertyStack *>
|
Chris@1266
|
499 (i->propertyStack);
|
Chris@1266
|
500 if (stack) {
|
Chris@1266
|
501 if (stack->containsContainer(layer)) {
|
Chris@1266
|
502 stack->setCurrentIndex(stack->getContainerIndex(layer));
|
Chris@1266
|
503 emit currentLayerChanged(pane, layer);
|
Chris@1266
|
504 } else {
|
Chris@1266
|
505 stack->setCurrentIndex
|
Chris@1266
|
506 (stack->getContainerIndex
|
Chris@1266
|
507 (pane->getPropertyContainer(0)));
|
Chris@1408
|
508 emit currentLayerChanged(pane, nullptr);
|
Chris@1266
|
509 }
|
Chris@1266
|
510 }
|
Chris@1266
|
511 break;
|
Chris@1266
|
512 }
|
Chris@1266
|
513 ++i;
|
Chris@1266
|
514 }
|
Chris@127
|
515 }
|
Chris@127
|
516 }
|
Chris@127
|
517
|
Chris@127
|
518 Pane *
|
Chris@127
|
519 PaneStack::getCurrentPane()
|
Chris@127
|
520 {
|
Chris@127
|
521 return m_currentPane;
|
Chris@127
|
522 }
|
Chris@127
|
523
|
Chris@127
|
524 void
|
Chris@127
|
525 PaneStack::propertyContainerAdded(PropertyContainer *)
|
Chris@127
|
526 {
|
Chris@127
|
527 sizePropertyStacks();
|
Chris@127
|
528 }
|
Chris@127
|
529
|
Chris@127
|
530 void
|
Chris@127
|
531 PaneStack::propertyContainerRemoved(PropertyContainer *)
|
Chris@127
|
532 {
|
Chris@127
|
533 sizePropertyStacks();
|
Chris@127
|
534 }
|
Chris@127
|
535
|
Chris@127
|
536 void
|
Chris@127
|
537 PaneStack::propertyContainerSelected(View *client, PropertyContainer *pc)
|
Chris@127
|
538 {
|
Chris@127
|
539 std::vector<PaneRec>::iterator i = m_panes.begin();
|
Chris@127
|
540
|
Chris@127
|
541 while (i != m_panes.end()) {
|
Chris@1266
|
542 PropertyStack *stack = dynamic_cast<PropertyStack *>(i->propertyStack);
|
Chris@1266
|
543 if (stack &&
|
Chris@1266
|
544 stack->getClient() == client &&
|
Chris@1266
|
545 stack->containsContainer(pc)) {
|
Chris@1266
|
546 setCurrentPane(i->pane);
|
Chris@1266
|
547 break;
|
Chris@1266
|
548 }
|
Chris@1266
|
549 ++i;
|
Chris@127
|
550 }
|
Chris@127
|
551
|
Chris@127
|
552 Layer *layer = dynamic_cast<Layer *>(pc);
|
Chris@127
|
553 if (layer) emit currentLayerChanged(m_currentPane, layer);
|
Chris@1408
|
554 else emit currentLayerChanged(m_currentPane, nullptr);
|
Chris@127
|
555 }
|
Chris@127
|
556
|
Chris@127
|
557 void
|
Chris@190
|
558 PaneStack::viewSelected(View *v)
|
Chris@190
|
559 {
|
Chris@190
|
560 Pane *p = dynamic_cast<Pane *>(v);
|
Chris@190
|
561 if (p) setCurrentPane(p);
|
Chris@190
|
562 }
|
Chris@190
|
563
|
Chris@190
|
564 void
|
Chris@127
|
565 PaneStack::paneInteractedWith()
|
Chris@127
|
566 {
|
Chris@127
|
567 Pane *pane = dynamic_cast<Pane *>(sender());
|
Chris@127
|
568 if (!pane) return;
|
Chris@127
|
569 setCurrentPane(pane);
|
Chris@127
|
570 }
|
Chris@127
|
571
|
Chris@127
|
572 void
|
Chris@127
|
573 PaneStack::rightButtonMenuRequested(QPoint position)
|
Chris@127
|
574 {
|
Chris@127
|
575 Pane *pane = dynamic_cast<Pane *>(sender());
|
Chris@127
|
576 if (!pane) return;
|
Chris@127
|
577 emit rightButtonMenuRequested(pane, position);
|
Chris@127
|
578 }
|
Chris@127
|
579
|
Chris@127
|
580 void
|
Chris@127
|
581 PaneStack::sizePropertyStacks()
|
Chris@127
|
582 {
|
Chris@127
|
583 int maxMinWidth = 0;
|
Chris@127
|
584
|
Chris@235
|
585 if (m_propertyStackMinWidth > 0) maxMinWidth = m_propertyStackMinWidth;
|
Chris@235
|
586
|
Chris@806
|
587 for (int i = 0; i < (int)m_panes.size(); ++i) {
|
Chris@1266
|
588 if (!m_panes[i].propertyStack) continue;
|
Chris@247
|
589 #ifdef DEBUG_PANE_STACK
|
Chris@1266
|
590 SVDEBUG << "PaneStack::sizePropertyStacks: " << i << ": min "
|
Chris@1266
|
591 << m_panes[i].propertyStack->minimumSizeHint().width() << ", hint "
|
Chris@243
|
592 << m_panes[i].propertyStack->sizeHint().width() << ", current "
|
Chris@1266
|
593 << m_panes[i].propertyStack->width() << endl;
|
Chris@247
|
594 #endif
|
Chris@127
|
595
|
Chris@1266
|
596 if (m_panes[i].propertyStack->sizeHint().width() > maxMinWidth) {
|
Chris@1266
|
597 maxMinWidth = m_panes[i].propertyStack->sizeHint().width();
|
Chris@1266
|
598 }
|
Chris@127
|
599 }
|
Chris@127
|
600
|
Chris@247
|
601 #ifdef DEBUG_PANE_STACK
|
Chris@587
|
602 SVDEBUG << "PaneStack::sizePropertyStacks: max min width " << maxMinWidth << endl;
|
Chris@247
|
603 #endif
|
Chris@127
|
604
|
Chris@127
|
605 int setWidth = maxMinWidth;
|
Chris@127
|
606
|
Chris@127
|
607 m_propertyStackStack->setMaximumWidth(setWidth + 10);
|
Chris@127
|
608
|
Chris@806
|
609 for (int i = 0; i < (int)m_panes.size(); ++i) {
|
Chris@1266
|
610 if (!m_panes[i].propertyStack) continue;
|
Chris@1266
|
611 m_panes[i].propertyStack->setMinimumWidth(setWidth);
|
Chris@127
|
612 }
|
Chris@180
|
613
|
Chris@363
|
614 emit propertyStacksResized(setWidth);
|
Chris@180
|
615 emit propertyStacksResized();
|
Chris@127
|
616 }
|
Chris@127
|
617
|
Chris@312
|
618 void
|
Chris@312
|
619 PaneStack::paneDropAccepted(QStringList uriList)
|
Chris@312
|
620 {
|
Chris@312
|
621 Pane *pane = dynamic_cast<Pane *>(sender());
|
Chris@312
|
622 emit dropAccepted(pane, uriList);
|
Chris@312
|
623 }
|
Chris@312
|
624
|
Chris@312
|
625 void
|
Chris@312
|
626 PaneStack::paneDropAccepted(QString text)
|
Chris@312
|
627 {
|
Chris@312
|
628 Pane *pane = dynamic_cast<Pane *>(sender());
|
Chris@312
|
629 emit dropAccepted(pane, text);
|
Chris@312
|
630 }
|
Chris@127
|
631
|
Chris@320
|
632 void
|
Chris@323
|
633 PaneStack::paneDeleteButtonClicked()
|
Chris@323
|
634 {
|
Chris@323
|
635 QObject *s = sender();
|
Chris@806
|
636 for (int i = 0; i < (int)m_panes.size(); ++i) {
|
Chris@1266
|
637 if (m_panes[i].xButton == s) {
|
Chris@605
|
638 emit paneDeleteButtonClicked(m_panes[i].pane);
|
Chris@323
|
639 }
|
Chris@323
|
640 }
|
Chris@323
|
641 }
|
Chris@323
|
642
|
Chris@323
|
643 void
|
Chris@500
|
644 PaneStack::indicatorClicked()
|
Chris@500
|
645 {
|
Chris@500
|
646 QObject *s = sender();
|
Chris@500
|
647
|
Chris@806
|
648 for (int i = 0; i < (int)m_panes.size(); ++i) {
|
Chris@1266
|
649 if (m_panes[i].currentIndicator == s) {
|
Chris@500
|
650 setCurrentPane(m_panes[i].pane);
|
Chris@500
|
651 return;
|
Chris@500
|
652 }
|
Chris@500
|
653 }
|
Chris@500
|
654 }
|
Chris@500
|
655
|
Chris@500
|
656 void
|
Chris@320
|
657 PaneStack::sizePanesEqually()
|
Chris@320
|
658 {
|
Chris@320
|
659 QList<int> sizes = m_splitter->sizes();
|
Chris@320
|
660 if (sizes.empty()) return;
|
Chris@320
|
661
|
Chris@320
|
662 int count = sizes.size();
|
Chris@320
|
663
|
Chris@687
|
664 int fixed = 0, variable = 0, total = 0;
|
Chris@687
|
665 int varicount = 0;
|
Chris@687
|
666
|
Chris@320
|
667 for (int i = 0; i < count; ++i) {
|
Chris@320
|
668 total += sizes[i];
|
Chris@320
|
669 }
|
Chris@320
|
670
|
Chris@687
|
671 variable = total;
|
Chris@687
|
672
|
Chris@687
|
673 for (int i = 0; i < count; ++i) {
|
Chris@687
|
674 int minh = m_panes[i].pane->minimumSize().height();
|
Chris@687
|
675 if (minh == m_panes[i].pane->maximumSize().height()) {
|
Chris@687
|
676 fixed += minh;
|
Chris@687
|
677 variable -= minh;
|
Chris@687
|
678 } else {
|
Chris@687
|
679 varicount++;
|
Chris@687
|
680 }
|
Chris@687
|
681 }
|
Chris@687
|
682
|
Chris@320
|
683 if (total == 0) return;
|
Chris@320
|
684
|
Chris@320
|
685 sizes.clear();
|
Chris@320
|
686
|
Chris@687
|
687 int each = (varicount > 0 ? (variable / varicount) : 0);
|
Chris@320
|
688 int remaining = total;
|
Chris@320
|
689
|
Chris@320
|
690 for (int i = 0; i < count; ++i) {
|
Chris@320
|
691 if (i == count - 1) {
|
Chris@320
|
692 sizes.push_back(remaining);
|
Chris@320
|
693 } else {
|
Chris@687
|
694 int minh = m_panes[i].pane->minimumSize().height();
|
Chris@687
|
695 if (minh == m_panes[i].pane->maximumSize().height()) {
|
Chris@687
|
696 sizes.push_back(minh);
|
Chris@687
|
697 remaining -= minh;
|
Chris@687
|
698 } else {
|
Chris@687
|
699 sizes.push_back(each);
|
Chris@687
|
700 remaining -= each;
|
Chris@687
|
701 }
|
Chris@320
|
702 }
|
Chris@320
|
703 }
|
Chris@320
|
704
|
Chris@320
|
705 /*
|
Chris@682
|
706 cerr << "sizes: ";
|
Chris@320
|
707 for (int i = 0; i < sizes.size(); ++i) {
|
Chris@682
|
708 cerr << sizes[i] << " ";
|
Chris@320
|
709 }
|
Chris@682
|
710 cerr << endl;
|
Chris@320
|
711 */
|
Chris@320
|
712
|
Chris@320
|
713 m_splitter->setSizes(sizes);
|
Chris@320
|
714 }
|
Chris@320
|
715
|