annotate widgets/PropertyStack.cpp @ 190:53835534a9d3

* Allow user to activate a pane by clicking on the tab for its currently active layer. Formerly nothing happened if you clicked on the tab that was already topmost in a given property stack, because the tab widget only emitted a signal if the current tab changed. We want this to switch focus back to the pane if another one has been active in the mean time. * Make the thumbwheels look a bit round.
author Chris Cannam
date Mon, 22 Jan 2007 15:42:00 +0000
parents 5b7472db612b
children 6b023411087b
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@0 57 connect(m_client, SIGNAL(propertyContainerNameChanged(PropertyContainer *)),
Chris@0 58 this, SLOT(propertyContainerNameChanged(PropertyContainer *)));
Chris@0 59
Chris@52 60 connect(this, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
Chris@52 61 m_client, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
Chris@0 62 }
Chris@0 63
Chris@0 64 void
Chris@0 65 PropertyStack::repopulate()
Chris@0 66 {
Chris@0 67 blockSignals(true);
Chris@0 68
Chris@0 69 #ifdef DEBUG_PROPERTY_STACK
Chris@0 70 std::cerr << "PropertyStack::repopulate" << std::endl;
Chris@0 71 #endif
Chris@0 72
Chris@0 73 while (count() > 0) {
Chris@0 74 removeTab(0);
Chris@0 75 }
Chris@0 76 for (size_t i = 0; i < m_boxes.size(); ++i) {
Chris@0 77 delete m_boxes[i];
Chris@0 78 }
Chris@0 79 m_boxes.clear();
Chris@0 80
Chris@0 81 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@0 82
Chris@0 83 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@0 84 QString name = container->getPropertyContainerName();
Chris@0 85
Chris@0 86 QString iconName = container->getPropertyContainerIconName();
Chris@0 87
Chris@0 88 PropertyBox *box = new PropertyBox(container);
Chris@0 89
Chris@47 90 connect(box, SIGNAL(showLayer(bool)), this, SLOT(showLayer(bool)));
Chris@189 91 connect(box, SIGNAL(contextHelpChanged(const QString &)),
Chris@189 92 this, SIGNAL(contextHelpChanged(const QString &)));
Chris@47 93
Chris@185 94 Layer *layer = dynamic_cast<Layer *>(container);
Chris@185 95 if (layer) {
Chris@185 96 box->layerVisibilityChanged(!layer->isLayerDormant(m_client));
Chris@185 97 }
Chris@185 98
Chris@0 99 QIcon icon(QString(":/icons/%1.png").arg(iconName));
Chris@0 100 if (icon.isNull()) {
Chris@0 101 addTab(box, name);
Chris@0 102 } else {
Chris@0 103 addTab(box, icon, QString("&%1").arg(i + 1));
Chris@0 104 setTabToolTip(count() - 1, name);
Chris@0 105 }
Chris@0 106
Chris@0 107 m_boxes.push_back(box);
Chris@0 108 }
Chris@0 109
Chris@0 110 blockSignals(false);
Chris@0 111 }
Chris@0 112
Chris@0 113 bool
Chris@0 114 PropertyStack::containsContainer(PropertyContainer *pc) const
Chris@0 115 {
Chris@0 116 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@0 117 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@0 118 if (pc == container) return true;
Chris@0 119 }
Chris@0 120
Chris@0 121 return false;
Chris@0 122 }
Chris@0 123
Chris@19 124 int
Chris@19 125 PropertyStack::getContainerIndex(PropertyContainer *pc) const
Chris@19 126 {
Chris@19 127 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@19 128 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@19 129 if (pc == container) return i;
Chris@19 130 }
Chris@19 131
Chris@19 132 return false;
Chris@19 133 }
Chris@19 134
Chris@0 135 void
Chris@0 136 PropertyStack::propertyContainerAdded(PropertyContainer *)
Chris@0 137 {
Chris@0 138 if (sender() != m_client) return;
Chris@0 139 repopulate();
Chris@0 140 }
Chris@0 141
Chris@0 142 void
Chris@0 143 PropertyStack::propertyContainerRemoved(PropertyContainer *)
Chris@0 144 {
Chris@0 145 if (sender() != m_client) return;
Chris@0 146 repopulate();
Chris@0 147 }
Chris@0 148
Chris@0 149 void
Chris@0 150 PropertyStack::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 151 {
Chris@0 152 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
Chris@0 153 if (pc == m_boxes[i]->getContainer()) {
Chris@0 154 m_boxes[i]->propertyContainerPropertyChanged(pc);
Chris@0 155 }
Chris@0 156 }
Chris@0 157 }
Chris@0 158
Chris@0 159 void
Chris@0 160 PropertyStack::propertyContainerNameChanged(PropertyContainer *pc)
Chris@0 161 {
Chris@0 162 if (sender() != m_client) return;
Chris@0 163 repopulate();
Chris@0 164 }
Chris@0 165
Chris@0 166 void
Chris@47 167 PropertyStack::showLayer(bool show)
Chris@47 168 {
Chris@47 169 QObject *obj = sender();
Chris@47 170
Chris@47 171 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
Chris@47 172 if (obj == m_boxes[i]) {
Chris@47 173 Layer *layer = dynamic_cast<Layer *>(m_boxes[i]->getContainer());
Chris@47 174 if (layer) {
Chris@47 175 layer->showLayer(m_client, show);
Chris@47 176 return;
Chris@47 177 }
Chris@47 178 }
Chris@47 179 }
Chris@47 180 }
Chris@47 181
Chris@47 182 void
Chris@0 183 PropertyStack::selectedContainerChanged(int n)
Chris@0 184 {
Chris@0 185 if (n >= int(m_boxes.size())) return;
Chris@52 186 emit propertyContainerSelected(m_client, m_boxes[n]->getContainer());
Chris@0 187 }
Chris@0 188
Chris@190 189 void
Chris@190 190 PropertyStack::mouseEnteredTabBar()
Chris@190 191 {
Chris@190 192 emit contextHelpChanged(tr("Click to change the current active layer"));
Chris@190 193 }
Chris@190 194
Chris@190 195 void
Chris@190 196 PropertyStack::mouseLeftTabBar()
Chris@190 197 {
Chris@190 198 emit contextHelpChanged("");
Chris@190 199 }
Chris@190 200
Chris@190 201 void
Chris@190 202 PropertyStack::activeTabClicked()
Chris@190 203 {
Chris@190 204 emit viewSelected(m_client);
Chris@190 205 }
Chris@190 206
Chris@0 207 #ifdef INCLUDE_MOCFILES
Chris@0 208 #include "PropertyStack.moc.cpp"
Chris@0 209 #endif
Chris@0 210