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