annotate widgets/PropertyStack.cpp @ 236:90122740323f

* Fix alignment of new pane added after play position has changed (but global centre frame has not been explicitly moved)
author Chris Cannam
date Mon, 16 Apr 2007 15:16:10 +0000
parents 6969f21da18a
children 6e59a60139b7
rev   line source
Chris@58 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@59 4 Sonic Visualiser
Chris@59 5 An audio file viewer and annotation editor.
Chris@59 6 Centre for Digital Music, Queen Mary, University of London.
Chris@59 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@59 9 This program is free software; you can redistribute it and/or
Chris@59 10 modify it under the terms of the GNU General Public License as
Chris@59 11 published by the Free Software Foundation; either version 2 of the
Chris@59 12 License, or (at your option) any later version. See the file
Chris@59 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "PropertyStack.h"
Chris@0 17 #include "PropertyBox.h"
Chris@0 18 #include "base/PropertyContainer.h"
Chris@128 19 #include "view/View.h"
Chris@128 20 #include "layer/Layer.h"
Chris@190 21 #include "widgets/NotifyingTabBar.h"
Chris@0 22
Chris@0 23 #include <QIcon>
Chris@0 24 #include <QTabWidget>
Chris@0 25
Chris@0 26 #include <iostream>
Chris@0 27
Chris@36 28 //#define DEBUG_PROPERTY_STACK 1
Chris@0 29
Chris@0 30 PropertyStack::PropertyStack(QWidget *parent, View *client) :
Chris@0 31 QTabWidget(parent),
Chris@0 32 m_client(client)
Chris@0 33 {
Chris@190 34 NotifyingTabBar *bar = new NotifyingTabBar();
Chris@190 35 bar->setDrawBase(false);
Chris@190 36
Chris@190 37 connect(bar, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredTabBar()));
Chris@190 38 connect(bar, SIGNAL(mouseLeft()), this, SLOT(mouseLeftTabBar()));
Chris@190 39 connect(bar, SIGNAL(activeTabClicked()), this, SLOT(activeTabClicked()));
Chris@190 40
Chris@190 41 setTabBar(bar);
Chris@190 42
Chris@0 43 repopulate();
Chris@0 44
Chris@0 45 connect(this, SIGNAL(currentChanged(int)),
Chris@0 46 this, SLOT(selectedContainerChanged(int)));
Chris@0 47
Chris@0 48 connect(m_client, SIGNAL(propertyContainerAdded(PropertyContainer *)),
Chris@0 49 this, SLOT(propertyContainerAdded(PropertyContainer *)));
Chris@0 50
Chris@0 51 connect(m_client, SIGNAL(propertyContainerRemoved(PropertyContainer *)),
Chris@0 52 this, SLOT(propertyContainerRemoved(PropertyContainer *)));
Chris@0 53
Chris@0 54 connect(m_client, SIGNAL(propertyContainerPropertyChanged(PropertyContainer *)),
Chris@0 55 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *)));
Chris@0 56
Chris@197 57 connect(m_client, SIGNAL(propertyContainerPropertyRangeChanged(PropertyContainer *)),
Chris@197 58 this, SLOT(propertyContainerPropertyRangeChanged(PropertyContainer *)));
Chris@197 59
Chris@0 60 connect(m_client, SIGNAL(propertyContainerNameChanged(PropertyContainer *)),
Chris@0 61 this, SLOT(propertyContainerNameChanged(PropertyContainer *)));
Chris@0 62
Chris@52 63 connect(this, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
Chris@52 64 m_client, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
Chris@0 65 }
Chris@0 66
Chris@0 67 void
Chris@0 68 PropertyStack::repopulate()
Chris@0 69 {
Chris@0 70 blockSignals(true);
Chris@0 71
Chris@0 72 #ifdef DEBUG_PROPERTY_STACK
Chris@0 73 std::cerr << "PropertyStack::repopulate" << std::endl;
Chris@0 74 #endif
Chris@0 75
Chris@0 76 while (count() > 0) {
Chris@0 77 removeTab(0);
Chris@0 78 }
Chris@0 79 for (size_t i = 0; i < m_boxes.size(); ++i) {
Chris@0 80 delete m_boxes[i];
Chris@0 81 }
Chris@0 82 m_boxes.clear();
Chris@0 83
Chris@0 84 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@0 85
Chris@0 86 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@0 87 QString name = container->getPropertyContainerName();
Chris@0 88
Chris@0 89 QString iconName = container->getPropertyContainerIconName();
Chris@0 90
Chris@0 91 PropertyBox *box = new PropertyBox(container);
Chris@0 92
Chris@47 93 connect(box, SIGNAL(showLayer(bool)), this, SLOT(showLayer(bool)));
Chris@189 94 connect(box, SIGNAL(contextHelpChanged(const QString &)),
Chris@189 95 this, SIGNAL(contextHelpChanged(const QString &)));
Chris@47 96
Chris@185 97 Layer *layer = dynamic_cast<Layer *>(container);
Chris@185 98 if (layer) {
Chris@185 99 box->layerVisibilityChanged(!layer->isLayerDormant(m_client));
Chris@185 100 }
Chris@185 101
Chris@0 102 QIcon icon(QString(":/icons/%1.png").arg(iconName));
Chris@0 103 if (icon.isNull()) {
Chris@0 104 addTab(box, name);
Chris@0 105 } else {
Chris@0 106 addTab(box, icon, QString("&%1").arg(i + 1));
Chris@0 107 setTabToolTip(count() - 1, name);
Chris@0 108 }
Chris@0 109
Chris@0 110 m_boxes.push_back(box);
Chris@0 111 }
Chris@0 112
Chris@0 113 blockSignals(false);
Chris@0 114 }
Chris@0 115
Chris@0 116 bool
Chris@0 117 PropertyStack::containsContainer(PropertyContainer *pc) const
Chris@0 118 {
Chris@0 119 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@0 120 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@0 121 if (pc == container) return true;
Chris@0 122 }
Chris@0 123
Chris@0 124 return false;
Chris@0 125 }
Chris@0 126
Chris@19 127 int
Chris@19 128 PropertyStack::getContainerIndex(PropertyContainer *pc) const
Chris@19 129 {
Chris@19 130 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@19 131 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@19 132 if (pc == container) return i;
Chris@19 133 }
Chris@19 134
Chris@19 135 return false;
Chris@19 136 }
Chris@19 137
Chris@0 138 void
Chris@0 139 PropertyStack::propertyContainerAdded(PropertyContainer *)
Chris@0 140 {
Chris@0 141 if (sender() != m_client) return;
Chris@0 142 repopulate();
Chris@0 143 }
Chris@0 144
Chris@0 145 void
Chris@0 146 PropertyStack::propertyContainerRemoved(PropertyContainer *)
Chris@0 147 {
Chris@0 148 if (sender() != m_client) return;
Chris@0 149 repopulate();
Chris@0 150 }
Chris@0 151
Chris@0 152 void
Chris@0 153 PropertyStack::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 154 {
Chris@0 155 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
Chris@0 156 if (pc == m_boxes[i]->getContainer()) {
Chris@0 157 m_boxes[i]->propertyContainerPropertyChanged(pc);
Chris@0 158 }
Chris@0 159 }
Chris@0 160 }
Chris@0 161
Chris@0 162 void
Chris@197 163 PropertyStack::propertyContainerPropertyRangeChanged(PropertyContainer *pc)
Chris@197 164 {
Chris@197 165 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
Chris@197 166 if (pc == m_boxes[i]->getContainer()) {
Chris@197 167 m_boxes[i]->propertyContainerPropertyRangeChanged(pc);
Chris@197 168 }
Chris@197 169 }
Chris@197 170 }
Chris@197 171
Chris@197 172 void
Chris@0 173 PropertyStack::propertyContainerNameChanged(PropertyContainer *pc)
Chris@0 174 {
Chris@0 175 if (sender() != m_client) return;
Chris@0 176 repopulate();
Chris@0 177 }
Chris@0 178
Chris@0 179 void
Chris@47 180 PropertyStack::showLayer(bool show)
Chris@47 181 {
Chris@47 182 QObject *obj = sender();
Chris@47 183
Chris@47 184 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
Chris@47 185 if (obj == m_boxes[i]) {
Chris@47 186 Layer *layer = dynamic_cast<Layer *>(m_boxes[i]->getContainer());
Chris@47 187 if (layer) {
Chris@47 188 layer->showLayer(m_client, show);
Chris@47 189 return;
Chris@47 190 }
Chris@47 191 }
Chris@47 192 }
Chris@47 193 }
Chris@47 194
Chris@47 195 void
Chris@0 196 PropertyStack::selectedContainerChanged(int n)
Chris@0 197 {
Chris@0 198 if (n >= int(m_boxes.size())) return;
Chris@52 199 emit propertyContainerSelected(m_client, m_boxes[n]->getContainer());
Chris@0 200 }
Chris@0 201
Chris@190 202 void
Chris@190 203 PropertyStack::mouseEnteredTabBar()
Chris@190 204 {
Chris@190 205 emit contextHelpChanged(tr("Click to change the current active layer"));
Chris@190 206 }
Chris@190 207
Chris@190 208 void
Chris@190 209 PropertyStack::mouseLeftTabBar()
Chris@190 210 {
Chris@190 211 emit contextHelpChanged("");
Chris@190 212 }
Chris@190 213
Chris@190 214 void
Chris@190 215 PropertyStack::activeTabClicked()
Chris@190 216 {
Chris@190 217 emit viewSelected(m_client);
Chris@190 218 }
Chris@190 219