annotate widgets/PropertyStack.cpp @ 189:5b7472db612b

* Add large chunks of context help in the optional status bar * Add an extra overlay mode in which even the centre frame is disabled * Fixes to FTP retrieval
author Chris Cannam
date Fri, 19 Jan 2007 13:13:14 +0000
parents dd932fe5f3ff
children 53835534a9d3
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@0 21
Chris@0 22 #include <QIcon>
Chris@0 23 #include <QTabWidget>
Chris@0 24
Chris@0 25 #include <iostream>
Chris@0 26
Chris@36 27 //#define DEBUG_PROPERTY_STACK 1
Chris@0 28
Chris@0 29 PropertyStack::PropertyStack(QWidget *parent, View *client) :
Chris@0 30 QTabWidget(parent),
Chris@0 31 m_client(client)
Chris@0 32 {
Chris@0 33 repopulate();
Chris@0 34
Chris@0 35 connect(this, SIGNAL(currentChanged(int)),
Chris@0 36 this, SLOT(selectedContainerChanged(int)));
Chris@0 37
Chris@0 38 connect(m_client, SIGNAL(propertyContainerAdded(PropertyContainer *)),
Chris@0 39 this, SLOT(propertyContainerAdded(PropertyContainer *)));
Chris@0 40
Chris@0 41 connect(m_client, SIGNAL(propertyContainerRemoved(PropertyContainer *)),
Chris@0 42 this, SLOT(propertyContainerRemoved(PropertyContainer *)));
Chris@0 43
Chris@0 44 connect(m_client, SIGNAL(propertyContainerPropertyChanged(PropertyContainer *)),
Chris@0 45 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *)));
Chris@0 46
Chris@0 47 connect(m_client, SIGNAL(propertyContainerNameChanged(PropertyContainer *)),
Chris@0 48 this, SLOT(propertyContainerNameChanged(PropertyContainer *)));
Chris@0 49
Chris@52 50 connect(this, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
Chris@52 51 m_client, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
Chris@0 52 }
Chris@0 53
Chris@0 54 void
Chris@0 55 PropertyStack::repopulate()
Chris@0 56 {
Chris@0 57 blockSignals(true);
Chris@0 58
Chris@0 59 #ifdef DEBUG_PROPERTY_STACK
Chris@0 60 std::cerr << "PropertyStack::repopulate" << std::endl;
Chris@0 61 #endif
Chris@0 62
Chris@0 63 while (count() > 0) {
Chris@0 64 removeTab(0);
Chris@0 65 }
Chris@0 66 for (size_t i = 0; i < m_boxes.size(); ++i) {
Chris@0 67 delete m_boxes[i];
Chris@0 68 }
Chris@0 69 m_boxes.clear();
Chris@0 70
Chris@0 71 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@0 72
Chris@0 73 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@0 74 QString name = container->getPropertyContainerName();
Chris@0 75
Chris@0 76 QString iconName = container->getPropertyContainerIconName();
Chris@0 77
Chris@0 78 PropertyBox *box = new PropertyBox(container);
Chris@0 79
Chris@47 80 connect(box, SIGNAL(showLayer(bool)), this, SLOT(showLayer(bool)));
Chris@189 81 connect(box, SIGNAL(contextHelpChanged(const QString &)),
Chris@189 82 this, SIGNAL(contextHelpChanged(const QString &)));
Chris@47 83
Chris@185 84 Layer *layer = dynamic_cast<Layer *>(container);
Chris@185 85 if (layer) {
Chris@185 86 box->layerVisibilityChanged(!layer->isLayerDormant(m_client));
Chris@185 87 }
Chris@185 88
Chris@0 89 QIcon icon(QString(":/icons/%1.png").arg(iconName));
Chris@0 90 if (icon.isNull()) {
Chris@0 91 addTab(box, name);
Chris@0 92 } else {
Chris@0 93 addTab(box, icon, QString("&%1").arg(i + 1));
Chris@0 94 setTabToolTip(count() - 1, name);
Chris@0 95 }
Chris@0 96
Chris@0 97 m_boxes.push_back(box);
Chris@0 98 }
Chris@0 99
Chris@0 100 blockSignals(false);
Chris@0 101 }
Chris@0 102
Chris@0 103 bool
Chris@0 104 PropertyStack::containsContainer(PropertyContainer *pc) const
Chris@0 105 {
Chris@0 106 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@0 107 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@0 108 if (pc == container) return true;
Chris@0 109 }
Chris@0 110
Chris@0 111 return false;
Chris@0 112 }
Chris@0 113
Chris@19 114 int
Chris@19 115 PropertyStack::getContainerIndex(PropertyContainer *pc) const
Chris@19 116 {
Chris@19 117 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@19 118 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@19 119 if (pc == container) return i;
Chris@19 120 }
Chris@19 121
Chris@19 122 return false;
Chris@19 123 }
Chris@19 124
Chris@0 125 void
Chris@0 126 PropertyStack::propertyContainerAdded(PropertyContainer *)
Chris@0 127 {
Chris@0 128 if (sender() != m_client) return;
Chris@0 129 repopulate();
Chris@0 130 }
Chris@0 131
Chris@0 132 void
Chris@0 133 PropertyStack::propertyContainerRemoved(PropertyContainer *)
Chris@0 134 {
Chris@0 135 if (sender() != m_client) return;
Chris@0 136 repopulate();
Chris@0 137 }
Chris@0 138
Chris@0 139 void
Chris@0 140 PropertyStack::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 141 {
Chris@0 142 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
Chris@0 143 if (pc == m_boxes[i]->getContainer()) {
Chris@0 144 m_boxes[i]->propertyContainerPropertyChanged(pc);
Chris@0 145 }
Chris@0 146 }
Chris@0 147 }
Chris@0 148
Chris@0 149 void
Chris@0 150 PropertyStack::propertyContainerNameChanged(PropertyContainer *pc)
Chris@0 151 {
Chris@0 152 if (sender() != m_client) return;
Chris@0 153 repopulate();
Chris@0 154 }
Chris@0 155
Chris@0 156 void
Chris@47 157 PropertyStack::showLayer(bool show)
Chris@47 158 {
Chris@47 159 QObject *obj = sender();
Chris@47 160
Chris@47 161 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
Chris@47 162 if (obj == m_boxes[i]) {
Chris@47 163 Layer *layer = dynamic_cast<Layer *>(m_boxes[i]->getContainer());
Chris@47 164 if (layer) {
Chris@47 165 layer->showLayer(m_client, show);
Chris@47 166 return;
Chris@47 167 }
Chris@47 168 }
Chris@47 169 }
Chris@47 170 }
Chris@47 171
Chris@47 172 void
Chris@0 173 PropertyStack::selectedContainerChanged(int n)
Chris@0 174 {
Chris@0 175 if (n >= int(m_boxes.size())) return;
Chris@52 176 emit propertyContainerSelected(m_client, m_boxes[n]->getContainer());
Chris@0 177 }
Chris@0 178
Chris@0 179 #ifdef INCLUDE_MOCFILES
Chris@0 180 #include "PropertyStack.moc.cpp"
Chris@0 181 #endif
Chris@0 182