annotate view/PaneStack.cpp @ 1528:14c07e445365

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