annotate view/PaneStack.cpp @ 324:1f67b110c1a3

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