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@239
|
43 // setElideMode(Qt::ElideRight);
|
Chris@239
|
44 setUsesScrollButtons(true);
|
Chris@239
|
45 setIconSize(QSize(16, 16));
|
Chris@239
|
46
|
Chris@0
|
47 repopulate();
|
Chris@0
|
48
|
Chris@0
|
49 connect(this, SIGNAL(currentChanged(int)),
|
Chris@0
|
50 this, SLOT(selectedContainerChanged(int)));
|
Chris@0
|
51
|
Chris@0
|
52 connect(m_client, SIGNAL(propertyContainerAdded(PropertyContainer *)),
|
Chris@0
|
53 this, SLOT(propertyContainerAdded(PropertyContainer *)));
|
Chris@0
|
54
|
Chris@0
|
55 connect(m_client, SIGNAL(propertyContainerRemoved(PropertyContainer *)),
|
Chris@0
|
56 this, SLOT(propertyContainerRemoved(PropertyContainer *)));
|
Chris@0
|
57
|
Chris@0
|
58 connect(m_client, SIGNAL(propertyContainerPropertyChanged(PropertyContainer *)),
|
Chris@0
|
59 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *)));
|
Chris@0
|
60
|
Chris@197
|
61 connect(m_client, SIGNAL(propertyContainerPropertyRangeChanged(PropertyContainer *)),
|
Chris@197
|
62 this, SLOT(propertyContainerPropertyRangeChanged(PropertyContainer *)));
|
Chris@197
|
63
|
Chris@0
|
64 connect(m_client, SIGNAL(propertyContainerNameChanged(PropertyContainer *)),
|
Chris@0
|
65 this, SLOT(propertyContainerNameChanged(PropertyContainer *)));
|
Chris@0
|
66
|
Chris@52
|
67 connect(this, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
|
Chris@52
|
68 m_client, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
|
Chris@0
|
69 }
|
Chris@0
|
70
|
Chris@0
|
71 void
|
Chris@0
|
72 PropertyStack::repopulate()
|
Chris@0
|
73 {
|
Chris@0
|
74 blockSignals(true);
|
Chris@0
|
75
|
Chris@0
|
76 #ifdef DEBUG_PROPERTY_STACK
|
Chris@0
|
77 std::cerr << "PropertyStack::repopulate" << std::endl;
|
Chris@0
|
78 #endif
|
Chris@0
|
79
|
Chris@0
|
80 while (count() > 0) {
|
Chris@0
|
81 removeTab(0);
|
Chris@0
|
82 }
|
Chris@0
|
83 for (size_t i = 0; i < m_boxes.size(); ++i) {
|
Chris@0
|
84 delete m_boxes[i];
|
Chris@0
|
85 }
|
Chris@0
|
86 m_boxes.clear();
|
Chris@0
|
87
|
Chris@0
|
88 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
|
Chris@0
|
89
|
Chris@0
|
90 PropertyContainer *container = m_client->getPropertyContainer(i);
|
Chris@0
|
91 QString name = container->getPropertyContainerName();
|
Chris@0
|
92
|
Chris@0
|
93 QString iconName = container->getPropertyContainerIconName();
|
Chris@0
|
94
|
Chris@0
|
95 PropertyBox *box = new PropertyBox(container);
|
Chris@0
|
96
|
Chris@47
|
97 connect(box, SIGNAL(showLayer(bool)), this, SLOT(showLayer(bool)));
|
Chris@189
|
98 connect(box, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@189
|
99 this, SIGNAL(contextHelpChanged(const QString &)));
|
Chris@47
|
100
|
Chris@185
|
101 Layer *layer = dynamic_cast<Layer *>(container);
|
Chris@185
|
102 if (layer) {
|
Chris@185
|
103 box->layerVisibilityChanged(!layer->isLayerDormant(m_client));
|
Chris@185
|
104 }
|
Chris@185
|
105
|
Chris@0
|
106 QIcon icon(QString(":/icons/%1.png").arg(iconName));
|
Chris@0
|
107 if (icon.isNull()) {
|
Chris@0
|
108 addTab(box, name);
|
Chris@0
|
109 } else {
|
Chris@0
|
110 addTab(box, icon, QString("&%1").arg(i + 1));
|
Chris@0
|
111 setTabToolTip(count() - 1, name);
|
Chris@240
|
112 setTabIcon(count() - 1, icon);
|
Chris@0
|
113 }
|
Chris@0
|
114
|
Chris@0
|
115 m_boxes.push_back(box);
|
Chris@0
|
116 }
|
Chris@0
|
117
|
Chris@0
|
118 blockSignals(false);
|
Chris@0
|
119 }
|
Chris@0
|
120
|
Chris@0
|
121 bool
|
Chris@0
|
122 PropertyStack::containsContainer(PropertyContainer *pc) const
|
Chris@0
|
123 {
|
Chris@0
|
124 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
|
Chris@0
|
125 PropertyContainer *container = m_client->getPropertyContainer(i);
|
Chris@0
|
126 if (pc == container) return true;
|
Chris@0
|
127 }
|
Chris@0
|
128
|
Chris@0
|
129 return false;
|
Chris@0
|
130 }
|
Chris@0
|
131
|
Chris@19
|
132 int
|
Chris@19
|
133 PropertyStack::getContainerIndex(PropertyContainer *pc) const
|
Chris@19
|
134 {
|
Chris@19
|
135 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) {
|
Chris@19
|
136 PropertyContainer *container = m_client->getPropertyContainer(i);
|
Chris@19
|
137 if (pc == container) return i;
|
Chris@19
|
138 }
|
Chris@19
|
139
|
Chris@19
|
140 return false;
|
Chris@19
|
141 }
|
Chris@19
|
142
|
Chris@0
|
143 void
|
Chris@0
|
144 PropertyStack::propertyContainerAdded(PropertyContainer *)
|
Chris@0
|
145 {
|
Chris@0
|
146 if (sender() != m_client) return;
|
Chris@0
|
147 repopulate();
|
Chris@0
|
148 }
|
Chris@0
|
149
|
Chris@0
|
150 void
|
Chris@0
|
151 PropertyStack::propertyContainerRemoved(PropertyContainer *)
|
Chris@0
|
152 {
|
Chris@0
|
153 if (sender() != m_client) return;
|
Chris@0
|
154 repopulate();
|
Chris@0
|
155 }
|
Chris@0
|
156
|
Chris@0
|
157 void
|
Chris@0
|
158 PropertyStack::propertyContainerPropertyChanged(PropertyContainer *pc)
|
Chris@0
|
159 {
|
Chris@0
|
160 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
|
Chris@0
|
161 if (pc == m_boxes[i]->getContainer()) {
|
Chris@0
|
162 m_boxes[i]->propertyContainerPropertyChanged(pc);
|
Chris@0
|
163 }
|
Chris@0
|
164 }
|
Chris@0
|
165 }
|
Chris@0
|
166
|
Chris@0
|
167 void
|
Chris@197
|
168 PropertyStack::propertyContainerPropertyRangeChanged(PropertyContainer *pc)
|
Chris@197
|
169 {
|
Chris@197
|
170 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
|
Chris@197
|
171 if (pc == m_boxes[i]->getContainer()) {
|
Chris@197
|
172 m_boxes[i]->propertyContainerPropertyRangeChanged(pc);
|
Chris@197
|
173 }
|
Chris@197
|
174 }
|
Chris@197
|
175 }
|
Chris@197
|
176
|
Chris@197
|
177 void
|
Chris@0
|
178 PropertyStack::propertyContainerNameChanged(PropertyContainer *pc)
|
Chris@0
|
179 {
|
Chris@0
|
180 if (sender() != m_client) return;
|
Chris@0
|
181 repopulate();
|
Chris@0
|
182 }
|
Chris@0
|
183
|
Chris@0
|
184 void
|
Chris@47
|
185 PropertyStack::showLayer(bool show)
|
Chris@47
|
186 {
|
Chris@47
|
187 QObject *obj = sender();
|
Chris@47
|
188
|
Chris@47
|
189 for (unsigned int i = 0; i < m_boxes.size(); ++i) {
|
Chris@47
|
190 if (obj == m_boxes[i]) {
|
Chris@47
|
191 Layer *layer = dynamic_cast<Layer *>(m_boxes[i]->getContainer());
|
Chris@47
|
192 if (layer) {
|
Chris@47
|
193 layer->showLayer(m_client, show);
|
Chris@47
|
194 return;
|
Chris@47
|
195 }
|
Chris@47
|
196 }
|
Chris@47
|
197 }
|
Chris@47
|
198 }
|
Chris@47
|
199
|
Chris@47
|
200 void
|
Chris@0
|
201 PropertyStack::selectedContainerChanged(int n)
|
Chris@0
|
202 {
|
Chris@0
|
203 if (n >= int(m_boxes.size())) return;
|
Chris@52
|
204 emit propertyContainerSelected(m_client, m_boxes[n]->getContainer());
|
Chris@0
|
205 }
|
Chris@0
|
206
|
Chris@190
|
207 void
|
Chris@190
|
208 PropertyStack::mouseEnteredTabBar()
|
Chris@190
|
209 {
|
Chris@190
|
210 emit contextHelpChanged(tr("Click to change the current active layer"));
|
Chris@190
|
211 }
|
Chris@190
|
212
|
Chris@190
|
213 void
|
Chris@190
|
214 PropertyStack::mouseLeftTabBar()
|
Chris@190
|
215 {
|
Chris@190
|
216 emit contextHelpChanged("");
|
Chris@190
|
217 }
|
Chris@190
|
218
|
Chris@190
|
219 void
|
Chris@190
|
220 PropertyStack::activeTabClicked()
|
Chris@190
|
221 {
|
Chris@190
|
222 emit viewSelected(m_client);
|
Chris@190
|
223 }
|
Chris@190
|
224
|