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