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@47
|
81
|
Chris@185
|
82 Layer *layer = dynamic_cast<Layer *>(container);
|
Chris@185
|
83 if (layer) {
|
Chris@185
|
84 box->layerVisibilityChanged(!layer->isLayerDormant(m_client));
|
Chris@185
|
85 }
|
Chris@185
|
86
|
Chris@0
|
87 QIcon icon(QString(":/icons/%1.png").arg(iconName));
|
Chris@0
|
88 if (icon.isNull()) {
|
Chris@0
|
89 addTab(box, name);
|
Chris@0
|
90 } else {
|
Chris@0
|
91 addTab(box, icon, QString("&%1").arg(i + 1));
|
Chris@0
|
92 setTabToolTip(count() - 1, name);
|
Chris@0
|
93 }
|
Chris@0
|
94
|
Chris@0
|
95 m_boxes.push_back(box);
|
Chris@0
|
96 }
|
Chris@0
|
97
|
Chris@0
|
98 blockSignals(false);
|
Chris@0
|
99 }
|
Chris@0
|
100
|
Chris@0
|
101 bool
|
Chris@0
|
102 PropertyStack::containsContainer(PropertyContainer *pc) const
|
Chris@0
|
103 {
|
Chris@0
|
104 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
|
Chris@0
|
105 PropertyContainer *container = m_client->getPropertyContainer(i);
|
Chris@0
|
106 if (pc == container) return true;
|
Chris@0
|
107 }
|
Chris@0
|
108
|
Chris@0
|
109 return false;
|
Chris@0
|
110 }
|
Chris@0
|
111
|
Chris@19
|
112 int
|
Chris@19
|
113 PropertyStack::getContainerIndex(PropertyContainer *pc) const
|
Chris@19
|
114 {
|
Chris@19
|
115 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
|
Chris@19
|
116 PropertyContainer *container = m_client->getPropertyContainer(i);
|
Chris@19
|
117 if (pc == container) return i;
|
Chris@19
|
118 }
|
Chris@19
|
119
|
Chris@19
|
120 return false;
|
Chris@19
|
121 }
|
Chris@19
|
122
|
Chris@0
|
123 void
|
Chris@0
|
124 PropertyStack::propertyContainerAdded(PropertyContainer *)
|
Chris@0
|
125 {
|
Chris@0
|
126 if (sender() != m_client) return;
|
Chris@0
|
127 repopulate();
|
Chris@0
|
128 }
|
Chris@0
|
129
|
Chris@0
|
130 void
|
Chris@0
|
131 PropertyStack::propertyContainerRemoved(PropertyContainer *)
|
Chris@0
|
132 {
|
Chris@0
|
133 if (sender() != m_client) return;
|
Chris@0
|
134 repopulate();
|
Chris@0
|
135 }
|
Chris@0
|
136
|
Chris@0
|
137 void
|
Chris@0
|
138 PropertyStack::propertyContainerPropertyChanged(PropertyContainer *pc)
|
Chris@0
|
139 {
|
Chris@0
|
140 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
|
Chris@0
|
141 if (pc == m_boxes[i]->getContainer()) {
|
Chris@0
|
142 m_boxes[i]->propertyContainerPropertyChanged(pc);
|
Chris@0
|
143 }
|
Chris@0
|
144 }
|
Chris@0
|
145 }
|
Chris@0
|
146
|
Chris@0
|
147 void
|
Chris@0
|
148 PropertyStack::propertyContainerNameChanged(PropertyContainer *pc)
|
Chris@0
|
149 {
|
Chris@0
|
150 if (sender() != m_client) return;
|
Chris@0
|
151 repopulate();
|
Chris@0
|
152 }
|
Chris@0
|
153
|
Chris@0
|
154 void
|
Chris@47
|
155 PropertyStack::showLayer(bool show)
|
Chris@47
|
156 {
|
Chris@47
|
157 QObject *obj = sender();
|
Chris@47
|
158
|
Chris@47
|
159 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
|
Chris@47
|
160 if (obj == m_boxes[i]) {
|
Chris@47
|
161 Layer *layer = dynamic_cast<Layer *>(m_boxes[i]->getContainer());
|
Chris@47
|
162 if (layer) {
|
Chris@47
|
163 layer->showLayer(m_client, show);
|
Chris@47
|
164 return;
|
Chris@47
|
165 }
|
Chris@47
|
166 }
|
Chris@47
|
167 }
|
Chris@47
|
168 }
|
Chris@47
|
169
|
Chris@47
|
170 void
|
Chris@0
|
171 PropertyStack::selectedContainerChanged(int n)
|
Chris@0
|
172 {
|
Chris@0
|
173 if (n >= int(m_boxes.size())) return;
|
Chris@52
|
174 emit propertyContainerSelected(m_client, m_boxes[n]->getContainer());
|
Chris@0
|
175 }
|
Chris@0
|
176
|
Chris@0
|
177 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
178 #include "PropertyStack.moc.cpp"
|
Chris@0
|
179 #endif
|
Chris@0
|
180
|