annotate widgets/PaneStack.cpp @ 56:fedaf3ffe80a

* Add menu for re-adding existing layers * Fix layer tree window so that it at least approximates correct * Add bundled operations in command history, for use with things like multiple consecutive changes to a parameter value * Disambiguate plugins that happen to have identical descriptions * Add spectral centroid plugin (could use some parameters!) * Some other fixes
author Chris Cannam
date Fri, 17 Mar 2006 17:38:28 +0000
parents f2fe98a7c57e
children 01ab51f72e84
rev   line source
Chris@0 1
Chris@0 2 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 3
Chris@0 4 /*
Chris@0 5 A waveform viewer and audio annotation editor.
Chris@5 6 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@0 7
Chris@0 8 This is experimental software. Not for distribution.
Chris@0 9 */
Chris@0 10
Chris@0 11 #include "PaneStack.h"
Chris@0 12
Chris@0 13 #include "widgets/Pane.h"
Chris@0 14 #include "widgets/PropertyStack.h"
Chris@0 15 #include "base/Layer.h"
Chris@0 16 #include "base/ViewManager.h"
Chris@0 17
Chris@0 18 #include <QApplication>
Chris@0 19 #include <QHBoxLayout>
Chris@0 20 #include <QPainter>
Chris@0 21 #include <QPalette>
Chris@0 22 #include <QLabel>
Chris@0 23
Chris@0 24 #include <iostream>
Chris@0 25
Chris@0 26 PaneStack::PaneStack(QWidget *parent, ViewManager *viewManager) :
Chris@0 27 QSplitter(parent),
Chris@0 28 m_currentPane(0),
Chris@0 29 m_viewManager(viewManager)
Chris@0 30 {
Chris@0 31 setOrientation(Qt::Vertical);
Chris@0 32 setOpaqueResize(false);
Chris@0 33 }
Chris@0 34
Chris@0 35 Pane *
Chris@0 36 PaneStack::addPane(bool suppressPropertyBox)
Chris@0 37 {
Chris@0 38 QFrame *frame = new QFrame;
Chris@0 39 QHBoxLayout *layout = new QHBoxLayout;
Chris@0 40 layout->setMargin(0);
Chris@0 41 layout->setSpacing(2);
Chris@0 42
Chris@0 43 QLabel *currentIndicator = new QLabel(frame);
Chris@0 44 currentIndicator->setFixedWidth(QPainter(this).fontMetrics().width("x"));
Chris@0 45 layout->addWidget(currentIndicator);
Chris@0 46 layout->setStretchFactor(currentIndicator, 1);
Chris@0 47 currentIndicator->setScaledContents(true);
Chris@0 48
Chris@0 49 Pane *pane = new Pane(frame);
Chris@0 50 pane->setViewManager(m_viewManager);
Chris@0 51 layout->addWidget(pane);
Chris@0 52 layout->setStretchFactor(pane, 10);
Chris@0 53
Chris@0 54 QWidget *properties = 0;
Chris@0 55 if (suppressPropertyBox) {
Chris@0 56 properties = new QFrame();
Chris@0 57 } else {
Chris@0 58 properties = new PropertyStack(frame, pane);
Chris@52 59 connect(properties, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
Chris@52 60 this, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
Chris@0 61 }
Chris@0 62 layout->addWidget(properties);
Chris@0 63 layout->setStretchFactor(properties, 1);
Chris@52 64
Chris@52 65 PaneRec rec;
Chris@52 66 rec.pane = pane;
Chris@52 67 rec.propertyStack = properties;
Chris@52 68 rec.currentIndicator = currentIndicator;
Chris@52 69 m_panes.push_back(rec);
Chris@0 70
Chris@0 71 frame->setLayout(layout);
Chris@0 72 addWidget(frame);
Chris@0 73
Chris@0 74 connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)),
Chris@0 75 this, SLOT(propertyContainerAdded(PropertyContainer *)));
Chris@0 76 connect(pane, SIGNAL(propertyContainerRemoved(PropertyContainer *)),
Chris@0 77 this, SLOT(propertyContainerRemoved(PropertyContainer *)));
Chris@0 78 connect(pane, SIGNAL(paneInteractedWith()),
Chris@0 79 this, SLOT(paneInteractedWith()));
Chris@0 80
Chris@0 81 if (!m_currentPane) {
Chris@0 82 setCurrentPane(pane);
Chris@0 83 }
Chris@0 84
Chris@0 85 return pane;
Chris@0 86 }
Chris@0 87
Chris@0 88 Pane *
Chris@0 89 PaneStack::getPane(int n)
Chris@0 90 {
Chris@52 91 return m_panes[n].pane;
Chris@52 92 }
Chris@52 93
Chris@52 94 Pane *
Chris@52 95 PaneStack::getHiddenPane(int n)
Chris@52 96 {
Chris@52 97 return m_hiddenPanes[n].pane;
Chris@0 98 }
Chris@0 99
Chris@0 100 void
Chris@0 101 PaneStack::deletePane(Pane *pane)
Chris@0 102 {
Chris@52 103 std::vector<PaneRec>::iterator i;
Chris@52 104 bool found = false;
Chris@0 105
Chris@52 106 for (i = m_panes.begin(); i != m_panes.end(); ++i) {
Chris@52 107 if (i->pane == pane) {
Chris@52 108 m_panes.erase(i);
Chris@52 109 found = true;
Chris@52 110 break;
Chris@52 111 }
Chris@0 112 }
Chris@0 113
Chris@52 114 if (!found) {
Chris@52 115
Chris@52 116 for (i = m_hiddenPanes.begin(); i != m_hiddenPanes.end(); ++i) {
Chris@52 117 if (i->pane == pane) {
Chris@52 118 m_hiddenPanes.erase(i);
Chris@52 119 found = true;
Chris@52 120 break;
Chris@52 121 }
Chris@52 122 }
Chris@52 123
Chris@52 124 if (!found) {
Chris@52 125 std::cerr << "WARNING: PaneStack::deletePane(" << pane << "): Pane not found in visible or hidden panes, not deleting" << std::endl;
Chris@52 126 return;
Chris@52 127 }
Chris@52 128 }
Chris@52 129
Chris@52 130 delete pane->parent();
Chris@0 131
Chris@0 132 if (m_currentPane == pane) {
Chris@0 133 if (m_panes.size() > 0) {
Chris@52 134 setCurrentPane(m_panes[0].pane);
Chris@0 135 } else {
Chris@0 136 setCurrentPane(0);
Chris@0 137 }
Chris@0 138 }
Chris@0 139 }
Chris@0 140
Chris@0 141 int
Chris@0 142 PaneStack::getPaneCount() const
Chris@0 143 {
Chris@0 144 return m_panes.size();
Chris@0 145 }
Chris@0 146
Chris@52 147 int
Chris@52 148 PaneStack::getHiddenPaneCount() const
Chris@52 149 {
Chris@52 150 return m_hiddenPanes.size();
Chris@52 151 }
Chris@52 152
Chris@52 153 void
Chris@52 154 PaneStack::hidePane(Pane *pane)
Chris@52 155 {
Chris@52 156 std::vector<PaneRec>::iterator i = m_panes.begin();
Chris@52 157
Chris@52 158 while (i != m_panes.end()) {
Chris@52 159 if (i->pane == pane) {
Chris@52 160
Chris@52 161 m_hiddenPanes.push_back(*i);
Chris@52 162 m_panes.erase(i);
Chris@52 163
Chris@52 164 QWidget *pw = dynamic_cast<QWidget *>(pane->parent());
Chris@52 165 if (pw) pw->hide();
Chris@52 166
Chris@52 167 if (m_currentPane == pane) {
Chris@52 168 if (m_panes.size() > 0) {
Chris@52 169 setCurrentPane(m_panes[0].pane);
Chris@52 170 } else {
Chris@52 171 setCurrentPane(0);
Chris@52 172 }
Chris@52 173 }
Chris@52 174
Chris@52 175 return;
Chris@52 176 }
Chris@52 177 ++i;
Chris@52 178 }
Chris@52 179
Chris@52 180 std::cerr << "WARNING: PaneStack::hidePane(" << pane << "): Pane not found in visible panes" << std::endl;
Chris@52 181 }
Chris@52 182
Chris@52 183 void
Chris@52 184 PaneStack::showPane(Pane *pane)
Chris@52 185 {
Chris@52 186 std::vector<PaneRec>::iterator i = m_hiddenPanes.begin();
Chris@52 187
Chris@52 188 while (i != m_hiddenPanes.end()) {
Chris@52 189 if (i->pane == pane) {
Chris@52 190 m_panes.push_back(*i);
Chris@52 191 m_hiddenPanes.erase(i);
Chris@52 192 QWidget *pw = dynamic_cast<QWidget *>(pane->parent());
Chris@52 193 if (pw) pw->show();
Chris@52 194
Chris@52 195 //!!! update current pane
Chris@52 196
Chris@52 197 return;
Chris@52 198 }
Chris@52 199 ++i;
Chris@52 200 }
Chris@52 201
Chris@52 202 std::cerr << "WARNING: PaneStack::showPane(" << pane << "): Pane not found in hidden panes" << std::endl;
Chris@52 203 }
Chris@52 204
Chris@0 205 void
Chris@0 206 PaneStack::setCurrentPane(Pane *pane) // may be null
Chris@0 207 {
Chris@0 208 if (m_currentPane == pane) return;
Chris@0 209
Chris@52 210 std::vector<PaneRec>::iterator i = m_panes.begin();
Chris@0 211
Chris@0 212 // We used to do this by setting the foreground and background
Chris@0 213 // role, but it seems the background role is ignored and the
Chris@0 214 // background drawn transparent in Qt 4.1 -- I can't quite see why
Chris@0 215
Chris@0 216 QPixmap selectedMap(1, 1);
Chris@0 217 selectedMap.fill(QApplication::palette().color(QPalette::Foreground));
Chris@0 218
Chris@0 219 QPixmap unselectedMap(1, 1);
Chris@0 220 unselectedMap.fill(QApplication::palette().color(QPalette::Background));
Chris@0 221
Chris@52 222 bool found = false;
Chris@52 223
Chris@0 224 while (i != m_panes.end()) {
Chris@52 225 if (i->pane == pane) {
Chris@52 226 i->currentIndicator->setPixmap(selectedMap);
Chris@52 227 found = true;
Chris@0 228 } else {
Chris@52 229 i->currentIndicator->setPixmap(unselectedMap);
Chris@0 230 }
Chris@0 231 ++i;
Chris@0 232 }
Chris@0 233
Chris@52 234 if (found || pane == 0) {
Chris@52 235 m_currentPane = pane;
Chris@52 236 emit currentPaneChanged(m_currentPane);
Chris@52 237 } else {
Chris@52 238 std::cerr << "WARNING: PaneStack::setCurrentPane(" << pane << "): pane is not a visible pane in this stack" << std::endl;
Chris@52 239 }
Chris@0 240 }
Chris@0 241
Chris@19 242 void
Chris@19 243 PaneStack::setCurrentLayer(Pane *pane, Layer *layer) // may be null
Chris@19 244 {
Chris@19 245 setCurrentPane(pane);
Chris@19 246
Chris@19 247 if (m_currentPane) {
Chris@19 248
Chris@52 249 std::vector<PaneRec>::iterator i = m_panes.begin();
Chris@19 250
Chris@19 251 while (i != m_panes.end()) {
Chris@19 252
Chris@52 253 if (i->pane == pane) {
Chris@52 254 PropertyStack *stack = dynamic_cast<PropertyStack *>
Chris@52 255 (i->propertyStack);
Chris@19 256 if (stack) {
Chris@19 257 if (stack->containsContainer(layer)) {
Chris@19 258 stack->setCurrentIndex(stack->getContainerIndex(layer));
Chris@19 259 emit currentLayerChanged(pane, layer);
Chris@19 260 } else {
Chris@33 261 stack->setCurrentIndex
Chris@33 262 (stack->getContainerIndex
Chris@33 263 (pane->getPropertyContainer(0)));
Chris@19 264 emit currentLayerChanged(pane, 0);
Chris@19 265 }
Chris@19 266 }
Chris@19 267 break;
Chris@19 268 }
Chris@19 269 ++i;
Chris@19 270 }
Chris@19 271 }
Chris@19 272 }
Chris@19 273
Chris@0 274 Pane *
Chris@0 275 PaneStack::getCurrentPane()
Chris@0 276 {
Chris@0 277 return m_currentPane;
Chris@0 278 }
Chris@0 279
Chris@0 280 void
Chris@0 281 PaneStack::propertyContainerAdded(PropertyContainer *)
Chris@0 282 {
Chris@0 283 sizePropertyStacks();
Chris@0 284 }
Chris@0 285
Chris@0 286 void
Chris@0 287 PaneStack::propertyContainerRemoved(PropertyContainer *)
Chris@0 288 {
Chris@0 289 sizePropertyStacks();
Chris@0 290 }
Chris@0 291
Chris@0 292 void
Chris@52 293 PaneStack::propertyContainerSelected(View *client, PropertyContainer *pc)
Chris@0 294 {
Chris@52 295 std::vector<PaneRec>::iterator i = m_panes.begin();
Chris@0 296
Chris@0 297 while (i != m_panes.end()) {
Chris@52 298 PropertyStack *stack = dynamic_cast<PropertyStack *>(i->propertyStack);
Chris@52 299 if (stack &&
Chris@52 300 stack->getClient() == client &&
Chris@52 301 stack->containsContainer(pc)) {
Chris@52 302 setCurrentPane(i->pane);
Chris@0 303 break;
Chris@0 304 }
Chris@0 305 ++i;
Chris@0 306 }
Chris@17 307
Chris@17 308 Layer *layer = dynamic_cast<Layer *>(pc);
Chris@17 309 if (layer) emit currentLayerChanged(m_currentPane, layer);
Chris@17 310 else emit currentLayerChanged(m_currentPane, 0);
Chris@0 311 }
Chris@0 312
Chris@0 313 void
Chris@0 314 PaneStack::paneInteractedWith()
Chris@0 315 {
Chris@0 316 Pane *pane = dynamic_cast<Pane *>(sender());
Chris@0 317 if (!pane) return;
Chris@0 318 setCurrentPane(pane);
Chris@0 319 }
Chris@0 320
Chris@0 321 void
Chris@0 322 PaneStack::sizePropertyStacks()
Chris@0 323 {
Chris@0 324 int maxMinWidth = 0;
Chris@0 325
Chris@52 326 for (size_t i = 0; i < m_panes.size(); ++i) {
Chris@52 327 if (!m_panes[i].propertyStack) continue;
Chris@0 328 std::cerr << "PaneStack::sizePropertyStacks: " << i << ": min "
Chris@52 329 << m_panes[i].propertyStack->minimumSizeHint().width() << ", current "
Chris@52 330 << m_panes[i].propertyStack->width() << std::endl;
Chris@0 331
Chris@52 332 if (m_panes[i].propertyStack->minimumSizeHint().width() > maxMinWidth) {
Chris@52 333 maxMinWidth = m_panes[i].propertyStack->minimumSizeHint().width();
Chris@0 334 }
Chris@0 335 }
Chris@0 336
Chris@0 337 std::cerr << "PaneStack::sizePropertyStacks: max min width " << maxMinWidth << std::endl;
Chris@0 338
Chris@0 339 #ifdef Q_WS_MAC
Chris@0 340 // This is necessary to compensate for cb->setMinimumSize(10, 10)
Chris@0 341 // in PropertyBox in the Mac version (to avoid a mysterious crash)
Chris@0 342 int setWidth = maxMinWidth * 3 / 2;
Chris@0 343 #else
Chris@0 344 int setWidth = maxMinWidth;
Chris@0 345 #endif
Chris@0 346
Chris@52 347 for (size_t i = 0; i < m_panes.size(); ++i) {
Chris@52 348 if (!m_panes[i].propertyStack) continue;
Chris@52 349 m_panes[i].propertyStack->setMinimumWidth(setWidth);
Chris@0 350 }
Chris@0 351 }
Chris@0 352
Chris@0 353
Chris@0 354 #ifdef INCLUDE_MOCFILES
Chris@0 355 #include "PaneStack.moc.cpp"
Chris@0 356 #endif
Chris@0 357