annotate view/PaneStack.cpp @ 767:e93c6ae12526

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