comparison widgets/PaneStack.cpp @ 52:f2fe98a7c57e

* Use commands for add/delete pane in main window * Add compound command collection to command history (for add pane, import file etc) * Add hide/show pane and hidden pane list to PaneStack * Various other fixes
author Chris Cannam
date Mon, 13 Mar 2006 17:55:19 +0000
parents 651e4e868bcc
children 01ab51f72e84
comparison
equal deleted inserted replaced
51:d2eac322d71b 52:f2fe98a7c57e
43 QLabel *currentIndicator = new QLabel(frame); 43 QLabel *currentIndicator = new QLabel(frame);
44 currentIndicator->setFixedWidth(QPainter(this).fontMetrics().width("x")); 44 currentIndicator->setFixedWidth(QPainter(this).fontMetrics().width("x"));
45 layout->addWidget(currentIndicator); 45 layout->addWidget(currentIndicator);
46 layout->setStretchFactor(currentIndicator, 1); 46 layout->setStretchFactor(currentIndicator, 1);
47 currentIndicator->setScaledContents(true); 47 currentIndicator->setScaledContents(true);
48 m_currentIndicators.push_back(currentIndicator);
49 48
50 Pane *pane = new Pane(frame); 49 Pane *pane = new Pane(frame);
51 pane->setViewManager(m_viewManager); 50 pane->setViewManager(m_viewManager);
52 layout->addWidget(pane); 51 layout->addWidget(pane);
53 layout->setStretchFactor(pane, 10); 52 layout->setStretchFactor(pane, 10);
54 m_panes.push_back(pane);
55 53
56 QWidget *properties = 0; 54 QWidget *properties = 0;
57 if (suppressPropertyBox) { 55 if (suppressPropertyBox) {
58 properties = new QFrame(); 56 properties = new QFrame();
59 } else { 57 } else {
60 properties = new PropertyStack(frame, pane); 58 properties = new PropertyStack(frame, pane);
61 connect(properties, SIGNAL(propertyContainerSelected(PropertyContainer *)), 59 connect(properties, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
62 this, SLOT(propertyContainerSelected(PropertyContainer *))); 60 this, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
63 } 61 }
64 layout->addWidget(properties); 62 layout->addWidget(properties);
65 layout->setStretchFactor(properties, 1); 63 layout->setStretchFactor(properties, 1);
66 m_propertyStacks.push_back(properties); 64
65 PaneRec rec;
66 rec.pane = pane;
67 rec.propertyStack = properties;
68 rec.currentIndicator = currentIndicator;
69 m_panes.push_back(rec);
67 70
68 frame->setLayout(layout); 71 frame->setLayout(layout);
69 addWidget(frame); 72 addWidget(frame);
70 73
71 connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)), 74 connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)),
83 } 86 }
84 87
85 Pane * 88 Pane *
86 PaneStack::getPane(int n) 89 PaneStack::getPane(int n)
87 { 90 {
88 return m_panes[n]; 91 return m_panes[n].pane;
92 }
93
94 Pane *
95 PaneStack::getHiddenPane(int n)
96 {
97 return m_hiddenPanes[n].pane;
89 } 98 }
90 99
91 void 100 void
92 PaneStack::deletePane(Pane *pane) 101 PaneStack::deletePane(Pane *pane)
93 { 102 {
94 int n = 0; 103 std::vector<PaneRec>::iterator i;
95 std::vector<Pane *>::iterator i = m_panes.begin(); 104 bool found = false;
96 std::vector<QWidget *>::iterator j = m_propertyStacks.begin(); 105
97 std::vector<QLabel *>::iterator k = m_currentIndicators.begin(); 106 for (i = m_panes.begin(); i != m_panes.end(); ++i) {
98 107 if (i->pane == pane) {
99 while (i != m_panes.end()) { 108 m_panes.erase(i);
100 if (*i == pane) break; 109 found = true;
101 ++i; 110 break;
102 ++j; 111 }
103 ++k; 112 }
104 ++n; 113
105 } 114 if (!found) {
106 if (n >= int(m_panes.size())) return; 115
107 116 for (i = m_hiddenPanes.begin(); i != m_hiddenPanes.end(); ++i) {
108 m_panes.erase(i); 117 if (i->pane == pane) {
109 m_propertyStacks.erase(j); 118 m_hiddenPanes.erase(i);
110 m_currentIndicators.erase(k); 119 found = true;
111 delete widget(n); 120 break;
121 }
122 }
123
124 if (!found) {
125 std::cerr << "WARNING: PaneStack::deletePane(" << pane << "): Pane not found in visible or hidden panes, not deleting" << std::endl;
126 return;
127 }
128 }
129
130 delete pane->parent();
112 131
113 if (m_currentPane == pane) { 132 if (m_currentPane == pane) {
114 if (m_panes.size() > 0) { 133 if (m_panes.size() > 0) {
115 setCurrentPane(m_panes[0]); 134 setCurrentPane(m_panes[0].pane);
116 } else { 135 } else {
117 setCurrentPane(0); 136 setCurrentPane(0);
118 } 137 }
119 } 138 }
120 } 139 }
123 PaneStack::getPaneCount() const 142 PaneStack::getPaneCount() const
124 { 143 {
125 return m_panes.size(); 144 return m_panes.size();
126 } 145 }
127 146
147 int
148 PaneStack::getHiddenPaneCount() const
149 {
150 return m_hiddenPanes.size();
151 }
152
153 void
154 PaneStack::hidePane(Pane *pane)
155 {
156 std::vector<PaneRec>::iterator i = m_panes.begin();
157
158 while (i != m_panes.end()) {
159 if (i->pane == pane) {
160
161 m_hiddenPanes.push_back(*i);
162 m_panes.erase(i);
163
164 QWidget *pw = dynamic_cast<QWidget *>(pane->parent());
165 if (pw) pw->hide();
166
167 if (m_currentPane == pane) {
168 if (m_panes.size() > 0) {
169 setCurrentPane(m_panes[0].pane);
170 } else {
171 setCurrentPane(0);
172 }
173 }
174
175 return;
176 }
177 ++i;
178 }
179
180 std::cerr << "WARNING: PaneStack::hidePane(" << pane << "): Pane not found in visible panes" << std::endl;
181 }
182
183 void
184 PaneStack::showPane(Pane *pane)
185 {
186 std::vector<PaneRec>::iterator i = m_hiddenPanes.begin();
187
188 while (i != m_hiddenPanes.end()) {
189 if (i->pane == pane) {
190 m_panes.push_back(*i);
191 m_hiddenPanes.erase(i);
192 QWidget *pw = dynamic_cast<QWidget *>(pane->parent());
193 if (pw) pw->show();
194
195 //!!! update current pane
196
197 return;
198 }
199 ++i;
200 }
201
202 std::cerr << "WARNING: PaneStack::showPane(" << pane << "): Pane not found in hidden panes" << std::endl;
203 }
204
128 void 205 void
129 PaneStack::setCurrentPane(Pane *pane) // may be null 206 PaneStack::setCurrentPane(Pane *pane) // may be null
130 { 207 {
131 if (m_currentPane == pane) return; 208 if (m_currentPane == pane) return;
132 209
133 std::vector<Pane *>::iterator i = m_panes.begin(); 210 std::vector<PaneRec>::iterator i = m_panes.begin();
134 std::vector<QLabel *>::iterator k = m_currentIndicators.begin();
135 211
136 // We used to do this by setting the foreground and background 212 // We used to do this by setting the foreground and background
137 // role, but it seems the background role is ignored and the 213 // role, but it seems the background role is ignored and the
138 // background drawn transparent in Qt 4.1 -- I can't quite see why 214 // background drawn transparent in Qt 4.1 -- I can't quite see why
139 215
141 selectedMap.fill(QApplication::palette().color(QPalette::Foreground)); 217 selectedMap.fill(QApplication::palette().color(QPalette::Foreground));
142 218
143 QPixmap unselectedMap(1, 1); 219 QPixmap unselectedMap(1, 1);
144 unselectedMap.fill(QApplication::palette().color(QPalette::Background)); 220 unselectedMap.fill(QApplication::palette().color(QPalette::Background));
145 221
222 bool found = false;
223
146 while (i != m_panes.end()) { 224 while (i != m_panes.end()) {
147 if (*i == pane) { 225 if (i->pane == pane) {
148 (*k)->setPixmap(selectedMap); 226 i->currentIndicator->setPixmap(selectedMap);
227 found = true;
149 } else { 228 } else {
150 (*k)->setPixmap(unselectedMap); 229 i->currentIndicator->setPixmap(unselectedMap);
151 } 230 }
152 ++i; 231 ++i;
153 ++k; 232 }
154 } 233
155 m_currentPane = pane; 234 if (found || pane == 0) {
156 235 m_currentPane = pane;
157 emit currentPaneChanged(m_currentPane); 236 emit currentPaneChanged(m_currentPane);
237 } else {
238 std::cerr << "WARNING: PaneStack::setCurrentPane(" << pane << "): pane is not a visible pane in this stack" << std::endl;
239 }
158 } 240 }
159 241
160 void 242 void
161 PaneStack::setCurrentLayer(Pane *pane, Layer *layer) // may be null 243 PaneStack::setCurrentLayer(Pane *pane, Layer *layer) // may be null
162 { 244 {
163 setCurrentPane(pane); 245 setCurrentPane(pane);
164 246
165 if (m_currentPane) { 247 if (m_currentPane) {
166 248
167 std::vector<Pane *>::iterator i = m_panes.begin(); 249 std::vector<PaneRec>::iterator i = m_panes.begin();
168 std::vector<QWidget *>::iterator j = m_propertyStacks.begin();
169 250
170 while (i != m_panes.end()) { 251 while (i != m_panes.end()) {
171 252
172 if (*i == pane) { 253 if (i->pane == pane) {
173 PropertyStack *stack = dynamic_cast<PropertyStack *>(*j); 254 PropertyStack *stack = dynamic_cast<PropertyStack *>
255 (i->propertyStack);
174 if (stack) { 256 if (stack) {
175 if (stack->containsContainer(layer)) { 257 if (stack->containsContainer(layer)) {
176 stack->setCurrentIndex(stack->getContainerIndex(layer)); 258 stack->setCurrentIndex(stack->getContainerIndex(layer));
177 emit currentLayerChanged(pane, layer); 259 emit currentLayerChanged(pane, layer);
178 } else { 260 } else {
183 } 265 }
184 } 266 }
185 break; 267 break;
186 } 268 }
187 ++i; 269 ++i;
188 ++j;
189 } 270 }
190 } 271 }
191 } 272 }
192 273
193 Pane * 274 Pane *
207 { 288 {
208 sizePropertyStacks(); 289 sizePropertyStacks();
209 } 290 }
210 291
211 void 292 void
212 PaneStack::propertyContainerSelected(PropertyContainer *pc) 293 PaneStack::propertyContainerSelected(View *client, PropertyContainer *pc)
213 { 294 {
214 std::vector<Pane *>::iterator i = m_panes.begin(); 295 std::vector<PaneRec>::iterator i = m_panes.begin();
215 std::vector<QWidget *>::iterator j = m_propertyStacks.begin();
216 296
217 while (i != m_panes.end()) { 297 while (i != m_panes.end()) {
218 PropertyStack *stack = dynamic_cast<PropertyStack *>(*j); 298 PropertyStack *stack = dynamic_cast<PropertyStack *>(i->propertyStack);
219 if (stack && stack->containsContainer(pc)) { 299 if (stack &&
220 setCurrentPane(*i); 300 stack->getClient() == client &&
301 stack->containsContainer(pc)) {
302 setCurrentPane(i->pane);
221 break; 303 break;
222 } 304 }
223 ++i; 305 ++i;
224 ++j;
225 } 306 }
226 307
227 Layer *layer = dynamic_cast<Layer *>(pc); 308 Layer *layer = dynamic_cast<Layer *>(pc);
228 if (layer) emit currentLayerChanged(m_currentPane, layer); 309 if (layer) emit currentLayerChanged(m_currentPane, layer);
229 else emit currentLayerChanged(m_currentPane, 0); 310 else emit currentLayerChanged(m_currentPane, 0);
240 void 321 void
241 PaneStack::sizePropertyStacks() 322 PaneStack::sizePropertyStacks()
242 { 323 {
243 int maxMinWidth = 0; 324 int maxMinWidth = 0;
244 325
245 for (unsigned int i = 0; i < m_propertyStacks.size(); ++i) { 326 for (size_t i = 0; i < m_panes.size(); ++i) {
246 if (!m_propertyStacks[i]) continue; 327 if (!m_panes[i].propertyStack) continue;
247 std::cerr << "PaneStack::sizePropertyStacks: " << i << ": min " 328 std::cerr << "PaneStack::sizePropertyStacks: " << i << ": min "
248 << m_propertyStacks[i]->minimumSizeHint().width() << ", current " 329 << m_panes[i].propertyStack->minimumSizeHint().width() << ", current "
249 << m_propertyStacks[i]->width() << std::endl; 330 << m_panes[i].propertyStack->width() << std::endl;
250 331
251 if (m_propertyStacks[i]->minimumSizeHint().width() > maxMinWidth) { 332 if (m_panes[i].propertyStack->minimumSizeHint().width() > maxMinWidth) {
252 maxMinWidth = m_propertyStacks[i]->minimumSizeHint().width(); 333 maxMinWidth = m_panes[i].propertyStack->minimumSizeHint().width();
253 } 334 }
254 } 335 }
255 336
256 std::cerr << "PaneStack::sizePropertyStacks: max min width " << maxMinWidth << std::endl; 337 std::cerr << "PaneStack::sizePropertyStacks: max min width " << maxMinWidth << std::endl;
257 338
261 int setWidth = maxMinWidth * 3 / 2; 342 int setWidth = maxMinWidth * 3 / 2;
262 #else 343 #else
263 int setWidth = maxMinWidth; 344 int setWidth = maxMinWidth;
264 #endif 345 #endif
265 346
266 for (unsigned int i = 0; i < m_propertyStacks.size(); ++i) { 347 for (size_t i = 0; i < m_panes.size(); ++i) {
267 if (!m_propertyStacks[i]) continue; 348 if (!m_panes[i].propertyStack) continue;
268 m_propertyStacks[i]->setMinimumWidth(setWidth); 349 m_panes[i].propertyStack->setMinimumWidth(setWidth);
269 } 350 }
270 } 351 }
271 352
272 353
273 #ifdef INCLUDE_MOCFILES 354 #ifdef INCLUDE_MOCFILES