annotate widgets/PropertyStack.cpp @ 43:78515b1e29eb

* Rejig project file a bit to do pkg-config detection &c and change some HAVE_* symbol names accordingly * Add selection move/resize/delete * First stubs for add layer / pane commands
author Chris Cannam
date Wed, 01 Mar 2006 18:13:01 +0000
parents c28ebb4ba4de
children 2e2ad8510e52
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@0 14
Chris@0 15 #include <QIcon>
Chris@0 16 #include <QTabWidget>
Chris@0 17
Chris@0 18 #include <iostream>
Chris@0 19
Chris@36 20 //#define DEBUG_PROPERTY_STACK 1
Chris@0 21
Chris@0 22 PropertyStack::PropertyStack(QWidget *parent, View *client) :
Chris@0 23 QTabWidget(parent),
Chris@0 24 m_client(client)
Chris@0 25 {
Chris@0 26 repopulate();
Chris@0 27
Chris@0 28 connect(this, SIGNAL(currentChanged(int)),
Chris@0 29 this, SLOT(selectedContainerChanged(int)));
Chris@0 30
Chris@0 31 connect(m_client, SIGNAL(propertyContainerAdded(PropertyContainer *)),
Chris@0 32 this, SLOT(propertyContainerAdded(PropertyContainer *)));
Chris@0 33
Chris@0 34 connect(m_client, SIGNAL(propertyContainerRemoved(PropertyContainer *)),
Chris@0 35 this, SLOT(propertyContainerRemoved(PropertyContainer *)));
Chris@0 36
Chris@0 37 connect(m_client, SIGNAL(propertyContainerPropertyChanged(PropertyContainer *)),
Chris@0 38 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *)));
Chris@0 39
Chris@0 40 connect(m_client, SIGNAL(propertyContainerNameChanged(PropertyContainer *)),
Chris@0 41 this, SLOT(propertyContainerNameChanged(PropertyContainer *)));
Chris@0 42
Chris@0 43 connect(this, SIGNAL(propertyContainerSelected(PropertyContainer *)),
Chris@0 44 m_client, SLOT(propertyContainerSelected(PropertyContainer *)));
Chris@0 45 }
Chris@0 46
Chris@0 47 void
Chris@0 48 PropertyStack::repopulate()
Chris@0 49 {
Chris@0 50 blockSignals(true);
Chris@0 51
Chris@0 52 #ifdef DEBUG_PROPERTY_STACK
Chris@0 53 std::cerr << "PropertyStack::repopulate" << std::endl;
Chris@0 54 #endif
Chris@0 55
Chris@0 56 while (count() > 0) {
Chris@0 57 removeTab(0);
Chris@0 58 }
Chris@0 59 for (size_t i = 0; i < m_boxes.size(); ++i) {
Chris@0 60 delete m_boxes[i];
Chris@0 61 }
Chris@0 62 m_boxes.clear();
Chris@0 63
Chris@0 64 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@0 65
Chris@0 66 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@0 67 QString name = container->getPropertyContainerName();
Chris@0 68
Chris@0 69 QString iconName = container->getPropertyContainerIconName();
Chris@0 70
Chris@0 71 PropertyBox *box = new PropertyBox(container);
Chris@0 72
Chris@0 73 QIcon icon(QString(":/icons/%1.png").arg(iconName));
Chris@0 74 if (icon.isNull()) {
Chris@0 75 addTab(box, name);
Chris@0 76 } else {
Chris@0 77 addTab(box, icon, QString("&%1").arg(i + 1));
Chris@0 78 setTabToolTip(count() - 1, name);
Chris@0 79 }
Chris@0 80
Chris@0 81 m_boxes.push_back(box);
Chris@0 82 }
Chris@0 83
Chris@0 84 blockSignals(false);
Chris@0 85 }
Chris@0 86
Chris@0 87 bool
Chris@0 88 PropertyStack::containsContainer(PropertyContainer *pc) const
Chris@0 89 {
Chris@0 90 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@0 91 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@0 92 if (pc == container) return true;
Chris@0 93 }
Chris@0 94
Chris@0 95 return false;
Chris@0 96 }
Chris@0 97
Chris@19 98 int
Chris@19 99 PropertyStack::getContainerIndex(PropertyContainer *pc) const
Chris@19 100 {
Chris@19 101 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
Chris@19 102 PropertyContainer *container = m_client->getPropertyContainer(i);
Chris@19 103 if (pc == container) return i;
Chris@19 104 }
Chris@19 105
Chris@19 106 return false;
Chris@19 107 }
Chris@19 108
Chris@0 109 void
Chris@0 110 PropertyStack::propertyContainerAdded(PropertyContainer *)
Chris@0 111 {
Chris@0 112 if (sender() != m_client) return;
Chris@0 113 repopulate();
Chris@0 114 }
Chris@0 115
Chris@0 116 void
Chris@0 117 PropertyStack::propertyContainerRemoved(PropertyContainer *)
Chris@0 118 {
Chris@0 119 if (sender() != m_client) return;
Chris@0 120 repopulate();
Chris@0 121 }
Chris@0 122
Chris@0 123 void
Chris@0 124 PropertyStack::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 125 {
Chris@0 126 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
Chris@0 127 if (pc == m_boxes[i]->getContainer()) {
Chris@0 128 m_boxes[i]->propertyContainerPropertyChanged(pc);
Chris@0 129 }
Chris@0 130 }
Chris@0 131 }
Chris@0 132
Chris@0 133 void
Chris@0 134 PropertyStack::propertyContainerNameChanged(PropertyContainer *pc)
Chris@0 135 {
Chris@0 136 if (sender() != m_client) return;
Chris@0 137 repopulate();
Chris@0 138 }
Chris@0 139
Chris@0 140 void
Chris@0 141 PropertyStack::selectedContainerChanged(int n)
Chris@0 142 {
Chris@0 143 if (n >= int(m_boxes.size())) return;
Chris@0 144 emit propertyContainerSelected(m_boxes[n]->getContainer());
Chris@0 145 }
Chris@0 146
Chris@0 147 #ifdef INCLUDE_MOCFILES
Chris@0 148 #include "PropertyStack.moc.cpp"
Chris@0 149 #endif
Chris@0 150