comparison widgets/Pane.cpp @ 55:128ebfeeebee

* Add Insert Instant function in main window * Ensure selections and window geometry are saved in session file * Add wait cursor on session file save * Various improvements to display of texts in pane (clearer readability) * Use commands for setting properties on layers and panes (still need to batch up multiple sets on the same property) * Fix failure of spectrogram to refresh when initial part became visible * Some fixes & paint optimisations in View &c * Make curve mode for time value layers work properly when resolution == 1 * Some vague improvements for time value layer vertical scale
author Chris Cannam
date Thu, 16 Mar 2006 18:46:00 +0000
parents d2eac322d71b
children fedaf3ffe80a
comparison
equal deleted inserted replaced
54:8dae7f6732c1 55:128ebfeeebee
133 } 133 }
134 134
135 const Model *waveformModel = 0; // just for reporting purposes 135 const Model *waveformModel = 0; // just for reporting purposes
136 int verticalScaleWidth = 0; 136 int verticalScaleWidth = 0;
137 137
138 int fontHeight = paint.fontMetrics().height();
139 int fontAscent = paint.fontMetrics().ascent();
140
138 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { 141 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
139 --vi; 142 --vi;
140 143
141 if (dynamic_cast<WaveformLayer *>(*vi)) { 144 if (dynamic_cast<WaveformLayer *>(*vi)) {
142 waveformModel = (*vi)->getModel(); 145 waveformModel = (*vi)->getModel();
215 } 218 }
216 219
217 break; 220 break;
218 } 221 }
219 222
223 int sampleRate = getModelsSampleRate();
224 paint.setBrush(Qt::NoBrush);
225
220 if (m_centreLineVisible) { 226 if (m_centreLineVisible) {
221 227
222 if (hasLightBackground()) { 228 if (hasLightBackground()) {
223 paint.setPen(QColor(50, 50, 50)); 229 paint.setPen(QColor(50, 50, 50));
224 } else { 230 } else {
225 paint.setPen(QColor(200, 200, 200)); 231 paint.setPen(QColor(200, 200, 200));
226 } 232 }
227 paint.setBrush(Qt::NoBrush);
228 paint.drawLine(width() / 2, 0, width() / 2, height() - 1); 233 paint.drawLine(width() / 2, 0, width() / 2, height() - 1);
229 234
230 // QFont font(paint.font()); 235 paint.setPen(QColor(50, 50, 50));
231 // font.setBold(true); 236
232 // paint.setFont(font); 237 int y = height() - fontHeight
233 238 + fontAscent - 6;
234 int sampleRate = getModelsSampleRate();
235 int y = height() - paint.fontMetrics().height()
236 + paint.fontMetrics().ascent() - 6;
237 239
238 LayerList::iterator vi = m_layers.end(); 240 LayerList::iterator vi = m_layers.end();
239 241
240 if (vi != m_layers.begin()) { 242 if (vi != m_layers.begin()) {
241 243
242 switch ((*--vi)->getPreferredFrameCountPosition()) { 244 switch ((*--vi)->getPreferredFrameCountPosition()) {
243 245
244 case Layer::PositionTop: 246 case Layer::PositionTop:
245 y = paint.fontMetrics().ascent() + 6; 247 y = fontAscent + 6;
246 break; 248 break;
247 249
248 case Layer::PositionMiddle: 250 case Layer::PositionMiddle:
249 y = (height() - paint.fontMetrics().height()) / 2 251 y = (height() - fontHeight) / 2
250 + paint.fontMetrics().ascent(); 252 + fontAscent;
251 break; 253 break;
252 254
253 case Layer::PositionBottom: 255 case Layer::PositionBottom:
254 // y already set correctly 256 // y already set correctly
255 break; 257 break;
263 (m_centreFrame, sampleRate).toText(true))); 265 (m_centreFrame, sampleRate).toText(true)));
264 266
265 int tw = paint.fontMetrics().width(text); 267 int tw = paint.fontMetrics().width(text);
266 int x = width()/2 - 4 - tw; 268 int x = width()/2 - 4 - tw;
267 269
268 if (hasLightBackground()) { 270 drawVisibleText(paint, x, y, text, OutlinedText);
269 paint.setPen(palette().background().color());
270 for (int dx = -1; dx <= 1; ++dx) {
271 for (int dy = -1; dy <= 1; ++dy) {
272 if ((dx && dy) || !(dx || dy)) continue;
273 paint.drawText(x + dx, y + dy, text);
274 }
275 }
276 paint.setPen(QColor(50, 50, 50));
277 } else {
278 paint.setPen(QColor(200, 200, 200));
279 }
280
281 paint.drawText(x, y, text);
282 } 271 }
283 272
284 QString text = QString("%1").arg(m_centreFrame); 273 QString text = QString("%1").arg(m_centreFrame);
285 274
286 int tw = paint.fontMetrics().width(text); 275 int tw = paint.fontMetrics().width(text);
287 int x = width()/2 + 4; 276 int x = width()/2 + 4;
288 277
289 if (hasLightBackground()) { 278 drawVisibleText(paint, x, y, text, OutlinedText);
290 paint.setPen(palette().background().color()); 279
291 for (int dx = -1; dx <= 1; ++dx) { 280 } else {
292 for (int dy = -1; dy <= 1; ++dy) { 281
293 if ((dx && dy) || !(dx || dy)) continue; 282 paint.setPen(QColor(50, 50, 50));
294 paint.drawText(x + dx, y + dy, text); 283 }
295 } 284
296 } 285 if (waveformModel &&
297 paint.setPen(QColor(50, 50, 50)); 286 r.y() + r.height() >= height() - fontHeight - 6) {
287
288 size_t mainModelRate = m_manager->getMainModelSampleRate();
289 size_t playbackRate = m_manager->getPlaybackSampleRate();
290
291 QString srNote = "";
292
293 // Show (R) for waveform models that will be resampled on
294 // playback, and (X) for waveform models that will be played
295 // at the wrong rate because their rate differs from that of
296 // the main model.
297
298 if (sampleRate == mainModelRate) {
299 if (sampleRate != playbackRate) srNote = " " + tr("(R)");
298 } else { 300 } else {
299 paint.setPen(QColor(200, 200, 200)); 301 std::cerr << "Sample rate = " << sampleRate << ", main model rate = " << mainModelRate << std::endl;
300 } 302 srNote = " " + tr("(X)");
301 paint.drawText(x, y, text); 303 }
302 304
303 if (waveformModel) { 305 QString desc = tr("%1 / %2Hz%3")
304 306 .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(),
305 size_t mainModelRate = m_manager->getMainModelSampleRate(); 307 sampleRate)
306 size_t playbackRate = m_manager->getPlaybackSampleRate(); 308 .toText(false).c_str())
307 309 .arg(sampleRate)
308 QString srNote = ""; 310 .arg(srNote);
309 311
310 // Show (R) for waveform models that will be resampled on 312 if (r.x() < verticalScaleWidth + 5 + paint.fontMetrics().width(desc)) {
311 // playback, and (X) for waveform models that will be 313 drawVisibleText(paint, verticalScaleWidth + 5,
312 // played at the wrong rate because their rate differs 314 height() - fontHeight + fontAscent - 6,
313 // from that of the main model. 315 desc, OutlinedText);
314 316 }
315 if (sampleRate == mainModelRate) { 317 }
316 if (sampleRate != playbackRate) srNote = " " + tr("(R)"); 318
317 } else { 319 if (r.y() + r.height() >= height() - m_layers.size() * fontHeight - 6) {
318 std::cerr << "Sample rate = " << sampleRate << ", main model rate = " << mainModelRate << std::endl;
319 srNote = " " + tr("(X)");
320 }
321
322 QString desc = tr("%1 / %2Hz%3")
323 .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(),
324 sampleRate)
325 .toText(false).c_str())
326 .arg(sampleRate)
327 .arg(srNote);
328
329 paint.drawText(verticalScaleWidth + 5,
330 //width() - paint.fontMetrics().width(desc) - 5,
331 height() - paint.fontMetrics().height() +
332 paint.fontMetrics().ascent() - 6,
333 desc);
334 }
335 320
336 std::vector<QString> texts; 321 std::vector<QString> texts;
337 int maxTextWidth = 0; 322 int maxTextWidth = 0;
338 323
339 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 324 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
346 if (modelName != "") { 331 if (modelName != "") {
347 text = QString("%1: %2").arg(modelName).arg(layerName); 332 text = QString("%1: %2").arg(modelName).arg(layerName);
348 } else { 333 } else {
349 text = layerName; 334 text = layerName;
350 } 335 }
351 336
352 texts.push_back(text); 337 texts.push_back(text);
353 int tw = paint.fontMetrics().width(text); 338 int tw = paint.fontMetrics().width(text);
354 if (tw > maxTextWidth) maxTextWidth = tw; 339 if (tw > maxTextWidth) maxTextWidth = tw;
355 } 340 }
356 341
357 int lly = height() - 6; 342 int lly = height() - 6;
358 343
359 for (int i = 0; i < texts.size(); ++i) { 344 if (r.x() + r.width() >= width() - maxTextWidth - 5) {
360 345
361 if (i == texts.size() - 1) { 346 for (int i = 0; i < texts.size(); ++i) {
362 if (m_lightBackground) { 347
348 if (i == texts.size() - 1) {
363 paint.setPen(Qt::black); 349 paint.setPen(Qt::black);
364 } else {
365 paint.setPen(Qt::white);
366 } 350 }
367 } 351
368 352 drawVisibleText(paint, width() - maxTextWidth - 5,
369 paint.drawText(width() - maxTextWidth - 5, 353 lly - fontHeight + fontAscent,
370 lly - paint.fontMetrics().height() + 354 texts[i], OutlinedText);
371 paint.fontMetrics().ascent(), 355
372 texts[i]); 356 lly -= fontHeight;
373 357 }
374 lly -= paint.fontMetrics().height();
375 } 358 }
376 } 359 }
377 360
378 if (m_clickedInRange && m_shiftPressed) { 361 if (m_clickedInRange && m_shiftPressed) {
379 if (m_manager && (m_manager->getToolMode() == ViewManager::NavigateMode)) { 362 if (m_manager && (m_manager->getToolMode() == ViewManager::NavigateMode)) {
661 } 644 }
662 } 645 }
663 646
664 //!!! if (mode != ViewManager::DrawMode) { 647 //!!! if (mode != ViewManager::DrawMode) {
665 648
649 if (getSelectedLayer()) {
650
666 bool previouslyIdentifying = m_identifyFeatures; 651 bool previouslyIdentifying = m_identifyFeatures;
667 m_identifyFeatures = true; 652 m_identifyFeatures = true;
668 653
669 if (m_identifyFeatures != previouslyIdentifying || 654 if (m_identifyFeatures != previouslyIdentifying ||
670 m_identifyPoint != prevPoint) { 655 m_identifyPoint != prevPoint) {
671 update(); 656 update();
672 } 657 }
658 }
659
673 // } 660 // }
674 661
675 return; 662 return;
676 } 663 }
677 664
984 QString 971 QString
985 Pane::toXmlString(QString indent, QString extraAttributes) const 972 Pane::toXmlString(QString indent, QString extraAttributes) const
986 { 973 {
987 return View::toXmlString 974 return View::toXmlString
988 (indent, 975 (indent,
989 QString("type=\"pane\" centreLineVisible=\"%1\" %2") 976 QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3")
990 .arg(m_centreLineVisible).arg(extraAttributes)); 977 .arg(m_centreLineVisible).arg(height()).arg(extraAttributes));
991 } 978 }
992 979
993 980
994 #ifdef INCLUDE_MOCFILES 981 #ifdef INCLUDE_MOCFILES
995 #include "Pane.moc.cpp" 982 #include "Pane.moc.cpp"