Mercurial > hg > easaier-soundaccess
comparison widgets/PropertyStack.cpp @ 0:fc9323a41f5a
start base : Sonic Visualiser sv1-1.0rc1
author | lbajardsilogic |
---|---|
date | Fri, 11 May 2007 09:08:14 +0000 |
parents | |
children | 8e5f9a9aa43f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc9323a41f5a |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "PropertyStack.h" | |
17 #include "PropertyBox.h" | |
18 #include "base/PropertyContainer.h" | |
19 #include "view/View.h" | |
20 #include "layer/Layer.h" | |
21 #include "layer/LayerFactory.h" | |
22 #include "widgets/NotifyingTabBar.h" | |
23 | |
24 #include <QIcon> | |
25 #include <QTabWidget> | |
26 | |
27 #include <iostream> | |
28 | |
29 //#define DEBUG_PROPERTY_STACK 1 | |
30 | |
31 PropertyStack::PropertyStack(QWidget *parent, View *client) : | |
32 QTabWidget(parent), | |
33 m_client(client) | |
34 { | |
35 NotifyingTabBar *bar = new NotifyingTabBar(); | |
36 bar->setDrawBase(false); | |
37 | |
38 connect(bar, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredTabBar())); | |
39 connect(bar, SIGNAL(mouseLeft()), this, SLOT(mouseLeftTabBar())); | |
40 connect(bar, SIGNAL(activeTabClicked()), this, SLOT(activeTabClicked())); | |
41 | |
42 setTabBar(bar); | |
43 | |
44 #if (QT_VERSION >= 0x0402) | |
45 setElideMode(Qt::ElideNone); | |
46 tabBar()->setUsesScrollButtons(true); | |
47 tabBar()->setIconSize(QSize(16, 16)); | |
48 #endif | |
49 | |
50 repopulate(); | |
51 | |
52 connect(this, SIGNAL(currentChanged(int)), | |
53 this, SLOT(selectedContainerChanged(int))); | |
54 | |
55 connect(m_client, SIGNAL(propertyContainerAdded(PropertyContainer *)), | |
56 this, SLOT(propertyContainerAdded(PropertyContainer *))); | |
57 | |
58 connect(m_client, SIGNAL(propertyContainerRemoved(PropertyContainer *)), | |
59 this, SLOT(propertyContainerRemoved(PropertyContainer *))); | |
60 | |
61 connect(m_client, SIGNAL(propertyContainerPropertyChanged(PropertyContainer *)), | |
62 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *))); | |
63 | |
64 connect(m_client, SIGNAL(propertyContainerPropertyRangeChanged(PropertyContainer *)), | |
65 this, SLOT(propertyContainerPropertyRangeChanged(PropertyContainer *))); | |
66 | |
67 connect(m_client, SIGNAL(propertyContainerNameChanged(PropertyContainer *)), | |
68 this, SLOT(propertyContainerNameChanged(PropertyContainer *))); | |
69 | |
70 connect(this, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)), | |
71 m_client, SLOT(propertyContainerSelected(View *, PropertyContainer *))); | |
72 } | |
73 | |
74 void | |
75 PropertyStack::repopulate() | |
76 { | |
77 blockSignals(true); | |
78 | |
79 #ifdef DEBUG_PROPERTY_STACK | |
80 std::cerr << "PropertyStack::repopulate" << std::endl; | |
81 #endif | |
82 | |
83 while (count() > 0) { | |
84 removeTab(0); | |
85 } | |
86 for (size_t i = 0; i < m_boxes.size(); ++i) { | |
87 delete m_boxes[i]; | |
88 } | |
89 m_boxes.clear(); | |
90 | |
91 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) { | |
92 | |
93 PropertyContainer *container = m_client->getPropertyContainer(i); | |
94 QString name = container->getPropertyContainerName(); | |
95 | |
96 PropertyBox *box = new PropertyBox(container); | |
97 | |
98 connect(box, SIGNAL(showLayer(bool)), this, SLOT(showLayer(bool))); | |
99 connect(box, SIGNAL(contextHelpChanged(const QString &)), | |
100 this, SIGNAL(contextHelpChanged(const QString &))); | |
101 | |
102 Layer *layer = dynamic_cast<Layer *>(container); | |
103 if (layer) { | |
104 box->layerVisibilityChanged(!layer->isLayerDormant(m_client)); | |
105 } | |
106 | |
107 QString shortName = name; | |
108 | |
109 if (layer) { | |
110 shortName = LayerFactory::getInstance()->getLayerPresentationName | |
111 (LayerFactory::getInstance()->getLayerType(layer)); | |
112 } | |
113 | |
114 shortName = QString("&%1 %2").arg(i + 1).arg(shortName); | |
115 | |
116 #ifdef Q_WS_MAC | |
117 | |
118 // Qt 4.2 on OS/X doesn't show the icons in the tab bar, and | |
119 // I'm not sure why -- use labels instead | |
120 | |
121 addTab(box, shortName); | |
122 | |
123 #else | |
124 | |
125 // Icons on other platforms | |
126 | |
127 QString iconName = container->getPropertyContainerIconName(); | |
128 | |
129 QIcon icon(QString(":/icons/%1.png").arg(iconName)); | |
130 if (icon.isNull()) { | |
131 addTab(box, shortName); | |
132 } else { | |
133 addTab(box, icon, QString("&%1").arg(i + 1)); | |
134 setTabToolTip(i, name); | |
135 } | |
136 | |
137 #endif | |
138 | |
139 m_boxes.push_back(box); | |
140 } | |
141 | |
142 blockSignals(false); | |
143 } | |
144 | |
145 bool | |
146 PropertyStack::containsContainer(PropertyContainer *pc) const | |
147 { | |
148 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) { | |
149 PropertyContainer *container = m_client->getPropertyContainer(i); | |
150 if (pc == container) return true; | |
151 } | |
152 | |
153 return false; | |
154 } | |
155 | |
156 int | |
157 PropertyStack::getContainerIndex(PropertyContainer *pc) const | |
158 { | |
159 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) { | |
160 PropertyContainer *container = m_client->getPropertyContainer(i); | |
161 if (pc == container) return i; | |
162 } | |
163 | |
164 return false; | |
165 } | |
166 | |
167 void | |
168 PropertyStack::propertyContainerAdded(PropertyContainer *) | |
169 { | |
170 if (sender() != m_client) return; | |
171 repopulate(); | |
172 } | |
173 | |
174 void | |
175 PropertyStack::propertyContainerRemoved(PropertyContainer *) | |
176 { | |
177 if (sender() != m_client) return; | |
178 repopulate(); | |
179 } | |
180 | |
181 void | |
182 PropertyStack::propertyContainerPropertyChanged(PropertyContainer *pc) | |
183 { | |
184 for (unsigned int i = 0; i < m_boxes.size(); ++i) { | |
185 if (pc == m_boxes[i]->getContainer()) { | |
186 m_boxes[i]->propertyContainerPropertyChanged(pc); | |
187 } | |
188 } | |
189 } | |
190 | |
191 void | |
192 PropertyStack::propertyContainerPropertyRangeChanged(PropertyContainer *pc) | |
193 { | |
194 for (unsigned int i = 0; i < m_boxes.size(); ++i) { | |
195 if (pc == m_boxes[i]->getContainer()) { | |
196 m_boxes[i]->propertyContainerPropertyRangeChanged(pc); | |
197 } | |
198 } | |
199 } | |
200 | |
201 void | |
202 PropertyStack::propertyContainerNameChanged(PropertyContainer *) | |
203 { | |
204 if (sender() != m_client) return; | |
205 repopulate(); | |
206 } | |
207 | |
208 void | |
209 PropertyStack::showLayer(bool show) | |
210 { | |
211 QObject *obj = sender(); | |
212 | |
213 for (unsigned int i = 0; i < m_boxes.size(); ++i) { | |
214 if (obj == m_boxes[i]) { | |
215 Layer *layer = dynamic_cast<Layer *>(m_boxes[i]->getContainer()); | |
216 if (layer) { | |
217 layer->showLayer(m_client, show); | |
218 return; | |
219 } | |
220 } | |
221 } | |
222 } | |
223 | |
224 void | |
225 PropertyStack::selectedContainerChanged(int n) | |
226 { | |
227 if (n >= int(m_boxes.size())) return; | |
228 emit propertyContainerSelected(m_client, m_boxes[n]->getContainer()); | |
229 } | |
230 | |
231 void | |
232 PropertyStack::mouseEnteredTabBar() | |
233 { | |
234 emit contextHelpChanged(tr("Click to change the current active layer")); | |
235 } | |
236 | |
237 void | |
238 PropertyStack::mouseLeftTabBar() | |
239 { | |
240 emit contextHelpChanged(""); | |
241 } | |
242 | |
243 void | |
244 PropertyStack::activeTabClicked() | |
245 { | |
246 emit viewSelected(m_client); | |
247 } | |
248 |