annotate widgets/PropertyStack.cpp @ 55:128ebfeeebee

* Add Insert Instant function in main window * Ensure selections and window geometry are saved in session file * Add wait cursor on session file save * Various improvements to display of texts in pane (clearer readability) * Use commands for setting properties on layers and panes (still need to batch up multiple sets on the same property) * Fix failure of spectrogram to refresh when initial part became visible * Some fixes & paint optimisations in View &c * Make curve mode for time value layers work properly when resolution == 1 * Some vague improvements for time value layer vertical scale
author Chris Cannam
date Thu, 16 Mar 2006 18:46:00 +0000
parents f2fe98a7c57e
children 01ab51f72e84
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 A waveform viewer and audio annotation editor.
Chris@5 5 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@0 6
Chris@0 7 This is experimental software. Not for distribution.
Chris@0 8 */
Chris@0 9
Chris@0 10 #include "PropertyStack.h"
Chris@0 11 #include "PropertyBox.h"
Chris@0 12 #include "base/PropertyContainer.h"
Chris@0 13 #include "base/View.h"
Chris@47 14 #include "base/Layer.h"
Chris@0 15
Chris@0 16 #include <QIcon>
Chris@0 17 #include <QTabWidget>
Chris@0 18
Chris@0 19 #include <iostream>
Chris@0 20
Chris@36 21 //#define DEBUG_PROPERTY_STACK 1
Chris@0 22
Chris@0 23 PropertyStack::PropertyStack(QWidget *parent, View *client) :
Chris@0 24 QTabWidget(parent),
Chris@0 25 m_client(client)
Chris@0 26 {
Chris@0 27 repopulate();
Chris@0 28
Chris@0 29 connect(this, SIGNAL(currentChanged(int)),
Chris@0 30 this, SLOT(selectedContainerChanged(int)));
Chris@0 31
Chris@0 32 connect(m_client, SIGNAL(propertyContainerAdded(PropertyContainer *)),
Chris@0 33 this, SLOT(propertyContainerAdded(PropertyContainer *)));
Chris@0 34
Chris@0 35 connect(m_client, SIGNAL(propertyContainerRemoved(PropertyContainer *)),
Chris@0 36 this, SLOT(propertyContainerRemoved(PropertyContainer *)));
Chris@0 37
Chris@0 38 connect(m_client, SIGNAL(propertyContainerPropertyChanged(PropertyContainer *)),
Chris@0 39 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *)));
Chris@0 40
Chris@0 41 connect(m_client, SIGNAL(propertyContainerNameChanged(PropertyContainer *)),
Chris@0 42 this, SLOT(propertyContainerNameChanged(PropertyContainer *)));
Chris@0 43
Chris@52 44 connect(this, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
Chris@52 45 m_client, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
Chris@0 46 }
Chris@0 47
Chris@0 48 void
Chris@0 49 PropertyStack::repopulate()
Chris@0 50 {
Chris@0 51 blockSignals(true);
Chris@0 52
Chris@0 53 #ifdef DEBUG_PROPERTY_STACK
Chris@0 54 std::cerr << "PropertyStack::repopulate" << std::endl;
Chris@0 55 #endif
Chris@0 56
Chris@0 57 while (count() > 0) {
Chris@0 58 removeTab(0);
Chris@0 59 }
Chris@0 60 for (size_t i = 0; i < m_boxes.size(); ++i) {
Chris@0 61 delete m_boxes[i];
Chris@0 62 }
Chris@0 63 m_boxes.clear();
Chris@0 64
Chris@0 65 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@0 66
Chris@0 67 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@0 68 QString name = container->getPropertyContainerName();
Chris@0 69
Chris@0 70 QString iconName = container->getPropertyContainerIconName();
Chris@0 71
Chris@0 72 PropertyBox *box = new PropertyBox(container);
Chris@0 73
Chris@47 74 connect(box, SIGNAL(showLayer(bool)), this, SLOT(showLayer(bool)));
Chris@47 75
Chris@0 76 QIcon icon(QString(":/icons/%1.png").arg(iconName));
Chris@0 77 if (icon.isNull()) {
Chris@0 78 addTab(box, name);
Chris@0 79 } else {
Chris@0 80 addTab(box, icon, QString("&%1").arg(i + 1));
Chris@0 81 setTabToolTip(count() - 1, name);
Chris@0 82 }
Chris@0 83
Chris@0 84 m_boxes.push_back(box);
Chris@0 85 }
Chris@0 86
Chris@0 87 blockSignals(false);
Chris@0 88 }
Chris@0 89
Chris@0 90 bool
Chris@0 91 PropertyStack::containsContainer(PropertyContainer *pc) const
Chris@0 92 {
Chris@0 93 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@0 94 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@0 95 if (pc == container) return true;
Chris@0 96 }
Chris@0 97
Chris@0 98 return false;
Chris@0 99 }
Chris@0 100
Chris@19 101 int
Chris@19 102 PropertyStack::getContainerIndex(PropertyContainer *pc) const
Chris@19 103 {
Chris@19 104 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@19 105 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@19 106 if (pc == container) return i;
Chris@19 107 }
Chris@19 108
Chris@19 109 return false;
Chris@19 110 }
Chris@19 111
Chris@0 112 void
Chris@0 113 PropertyStack::propertyContainerAdded(PropertyContainer *)
Chris@0 114 {
Chris@0 115 if (sender() != m_client) return;
Chris@0 116 repopulate();
Chris@0 117 }
Chris@0 118
Chris@0 119 void
Chris@0 120 PropertyStack::propertyContainerRemoved(PropertyContainer *)
Chris@0 121 {
Chris@0 122 if (sender() != m_client) return;
Chris@0 123 repopulate();
Chris@0 124 }
Chris@0 125
Chris@0 126 void
Chris@0 127 PropertyStack::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 128 {
Chris@0 129 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
Chris@0 130 if (pc == m_boxes[i]->getContainer()) {
Chris@0 131 m_boxes[i]->propertyContainerPropertyChanged(pc);
Chris@0 132 }
Chris@0 133 }
Chris@0 134 }
Chris@0 135
Chris@0 136 void
Chris@0 137 PropertyStack::propertyContainerNameChanged(PropertyContainer *pc)
Chris@0 138 {
Chris@0 139 if (sender() != m_client) return;
Chris@0 140 repopulate();
Chris@0 141 }
Chris@0 142
Chris@0 143 void
Chris@47 144 PropertyStack::showLayer(bool show)
Chris@47 145 {
Chris@47 146 QObject *obj = sender();
Chris@47 147
Chris@47 148 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
Chris@47 149 if (obj == m_boxes[i]) {
Chris@47 150 Layer *layer = dynamic_cast<Layer *>(m_boxes[i]->getContainer());
Chris@47 151 if (layer) {
Chris@47 152 layer->showLayer(m_client, show);
Chris@47 153 return;
Chris@47 154 }
Chris@47 155 }
Chris@47 156 }
Chris@47 157 }
Chris@47 158
Chris@47 159 void
Chris@0 160 PropertyStack::selectedContainerChanged(int n)
Chris@0 161 {
Chris@0 162 if (n >= int(m_boxes.size())) return;
Chris@52 163 emit propertyContainerSelected(m_client, m_boxes[n]->getContainer());
Chris@0 164 }
Chris@0 165
Chris@0 166 #ifdef INCLUDE_MOCFILES
Chris@0 167 #include "PropertyStack.moc.cpp"
Chris@0 168 #endif
Chris@0 169