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