Mercurial > hg > svgui
comparison widgets/PropertyStack.cpp @ 0:2a4f26e85b4c
initial import
author | Chris Cannam |
---|---|
date | Tue, 10 Jan 2006 16:33:16 +0000 |
parents | |
children | 37b110168acf |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2a4f26e85b4c |
---|---|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 A waveform viewer and audio annotation editor. | |
5 Chris Cannam, Queen Mary University of London, 2005 | |
6 | |
7 This is experimental software. Not for distribution. | |
8 */ | |
9 | |
10 #include "PropertyStack.h" | |
11 #include "PropertyBox.h" | |
12 #include "base/PropertyContainer.h" | |
13 #include "base/View.h" | |
14 | |
15 #include <QIcon> | |
16 #include <QTabWidget> | |
17 | |
18 #include <iostream> | |
19 | |
20 #define DEBUG_PROPERTY_STACK 1 | |
21 | |
22 PropertyStack::PropertyStack(QWidget *parent, View *client) : | |
23 QTabWidget(parent), | |
24 m_client(client) | |
25 { | |
26 repopulate(); | |
27 | |
28 connect(this, SIGNAL(currentChanged(int)), | |
29 this, SLOT(selectedContainerChanged(int))); | |
30 | |
31 connect(m_client, SIGNAL(propertyContainerAdded(PropertyContainer *)), | |
32 this, SLOT(propertyContainerAdded(PropertyContainer *))); | |
33 | |
34 connect(m_client, SIGNAL(propertyContainerRemoved(PropertyContainer *)), | |
35 this, SLOT(propertyContainerRemoved(PropertyContainer *))); | |
36 | |
37 connect(m_client, SIGNAL(propertyContainerPropertyChanged(PropertyContainer *)), | |
38 this, SLOT(propertyContainerPropertyChanged(PropertyContainer *))); | |
39 | |
40 connect(m_client, SIGNAL(propertyContainerNameChanged(PropertyContainer *)), | |
41 this, SLOT(propertyContainerNameChanged(PropertyContainer *))); | |
42 | |
43 connect(this, SIGNAL(propertyContainerSelected(PropertyContainer *)), | |
44 m_client, SLOT(propertyContainerSelected(PropertyContainer *))); | |
45 } | |
46 | |
47 void | |
48 PropertyStack::repopulate() | |
49 { | |
50 blockSignals(true); | |
51 | |
52 #ifdef DEBUG_PROPERTY_STACK | |
53 std::cerr << "PropertyStack::repopulate" << std::endl; | |
54 #endif | |
55 | |
56 while (count() > 0) { | |
57 removeTab(0); | |
58 } | |
59 for (size_t i = 0; i < m_boxes.size(); ++i) { | |
60 delete m_boxes[i]; | |
61 } | |
62 m_boxes.clear(); | |
63 | |
64 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) { | |
65 | |
66 PropertyContainer *container = m_client->getPropertyContainer(i); | |
67 QString name = container->getPropertyContainerName(); | |
68 | |
69 QString iconName = container->getPropertyContainerIconName(); | |
70 | |
71 PropertyBox *box = new PropertyBox(container); | |
72 | |
73 QIcon icon(QString(":/icons/%1.png").arg(iconName)); | |
74 if (icon.isNull()) { | |
75 addTab(box, name); | |
76 } else { | |
77 addTab(box, icon, QString("&%1").arg(i + 1)); | |
78 setTabToolTip(count() - 1, name); | |
79 } | |
80 | |
81 m_boxes.push_back(box); | |
82 } | |
83 | |
84 blockSignals(false); | |
85 } | |
86 | |
87 bool | |
88 PropertyStack::containsContainer(PropertyContainer *pc) const | |
89 { | |
90 for (size_t i = 0; i < m_client->getPropertyContainerCount(); ++i) { | |
91 PropertyContainer *container = m_client->getPropertyContainer(i); | |
92 if (pc == container) return true; | |
93 } | |
94 | |
95 return false; | |
96 } | |
97 | |
98 void | |
99 PropertyStack::propertyContainerAdded(PropertyContainer *) | |
100 { | |
101 if (sender() != m_client) return; | |
102 repopulate(); | |
103 } | |
104 | |
105 void | |
106 PropertyStack::propertyContainerRemoved(PropertyContainer *) | |
107 { | |
108 if (sender() != m_client) return; | |
109 repopulate(); | |
110 } | |
111 | |
112 void | |
113 PropertyStack::propertyContainerPropertyChanged(PropertyContainer *pc) | |
114 { | |
115 for (unsigned int i = 0; i < m_boxes.size(); ++i) { | |
116 if (pc == m_boxes[i]->getContainer()) { | |
117 m_boxes[i]->propertyContainerPropertyChanged(pc); | |
118 } | |
119 } | |
120 } | |
121 | |
122 void | |
123 PropertyStack::propertyContainerNameChanged(PropertyContainer *pc) | |
124 { | |
125 if (sender() != m_client) return; | |
126 repopulate(); | |
127 } | |
128 | |
129 void | |
130 PropertyStack::selectedContainerChanged(int n) | |
131 { | |
132 if (n >= int(m_boxes.size())) return; | |
133 emit propertyContainerSelected(m_boxes[n]->getContainer()); | |
134 } | |
135 | |
136 #ifdef INCLUDE_MOCFILES | |
137 #include "PropertyStack.moc.cpp" | |
138 #endif | |
139 |