annotate view/View.cpp @ 1044:4e5c1c326794 3.0-integration

Make ViewProxy objects share the ids of their Views; fixes incorrect colour scale drawing
author Chris Cannam
date Tue, 09 Feb 2016 10:59:36 +0000
parents 69c4f8403ebf
children ee01a4062747
rev   line source
Chris@127 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@127 2
Chris@127 3 /*
Chris@127 4 Sonic Visualiser
Chris@127 5 An audio file viewer and annotation editor.
Chris@127 6 Centre for Digital Music, Queen Mary, University of London.
Chris@127 7 This file copyright 2006 Chris Cannam.
Chris@127 8
Chris@127 9 This program is free software; you can redistribute it and/or
Chris@127 10 modify it under the terms of the GNU General Public License as
Chris@127 11 published by the Free Software Foundation; either version 2 of the
Chris@127 12 License, or (at your option) any later version. See the file
Chris@127 13 COPYING included with this distribution for more information.
Chris@127 14 */
Chris@127 15
Chris@128 16 #include "View.h"
Chris@128 17 #include "layer/Layer.h"
Chris@128 18 #include "data/model/Model.h"
Chris@127 19 #include "base/ZoomConstraint.h"
Chris@127 20 #include "base/Profiler.h"
Chris@278 21 #include "base/Pitch.h"
Chris@338 22 #include "base/Preferences.h"
Chris@919 23 #include "ViewProxy.h"
Chris@127 24
Chris@301 25 #include "layer/TimeRulerLayer.h"
Chris@287 26 #include "layer/SingleColourLayer.h"
Chris@301 27 #include "data/model/PowerOfSqrtTwoZoomConstraint.h"
Chris@301 28 #include "data/model/RangeSummarisableTimeValueModel.h"
Chris@127 29
Chris@797 30 #include "widgets/IconLoader.h"
Chris@797 31
Chris@127 32 #include <QPainter>
Chris@127 33 #include <QPaintEvent>
Chris@127 34 #include <QRect>
Chris@127 35 #include <QApplication>
Chris@226 36 #include <QProgressDialog>
Chris@316 37 #include <QTextStream>
Chris@338 38 #include <QFont>
Chris@583 39 #include <QMessageBox>
Chris@797 40 #include <QPushButton>
Chris@956 41 #include <QSettings>
Chris@127 42
Chris@127 43 #include <iostream>
Chris@127 44 #include <cassert>
Chris@520 45 #include <cmath>
Chris@127 46
Chris@545 47 #include <unistd.h>
Chris@545 48
Chris@1003 49 //#define DEBUG_VIEW 1
Chris@1003 50 //#define DEBUG_VIEW_WIDGET_PAINT 1
Chris@127 51
Chris@127 52 View::View(QWidget *w, bool showProgress) :
Chris@127 53 QFrame(w),
Chris@1044 54 m_id(getNextId()),
Chris@127 55 m_centreFrame(0),
Chris@127 56 m_zoomLevel(1024),
Chris@127 57 m_followPan(true),
Chris@127 58 m_followZoom(true),
Chris@815 59 m_followPlay(PlaybackScrollPageWithCentre),
Chris@789 60 m_followPlayIsDetached(false),
Chris@153 61 m_playPointerFrame(0),
Chris@127 62 m_showProgress(showProgress),
Chris@127 63 m_cache(0),
Chris@952 64 m_buffer(0),
Chris@127 65 m_cacheCentreFrame(0),
Chris@127 66 m_cacheZoomLevel(1024),
Chris@127 67 m_selectionCached(false),
Chris@127 68 m_deleting(false),
Chris@127 69 m_haveSelectedLayer(false),
Chris@127 70 m_manager(0),
Chris@127 71 m_propertyContainer(new ViewPropertyContainer(this))
Chris@127 72 {
Chris@728 73 // cerr << "View::View(" << this << ")" << endl;
Chris@127 74 }
Chris@127 75
Chris@127 76 View::~View()
Chris@127 77 {
Chris@728 78 // cerr << "View::~View(" << this << ")" << endl;
Chris@127 79
Chris@127 80 m_deleting = true;
Chris@127 81 delete m_propertyContainer;
Chris@127 82 }
Chris@127 83
Chris@127 84 PropertyContainer::PropertyList
Chris@127 85 View::getProperties() const
Chris@127 86 {
Chris@127 87 PropertyContainer::PropertyList list;
Chris@127 88 list.push_back("Global Scroll");
Chris@127 89 list.push_back("Global Zoom");
Chris@127 90 list.push_back("Follow Playback");
Chris@127 91 return list;
Chris@127 92 }
Chris@127 93
Chris@127 94 QString
Chris@127 95 View::getPropertyLabel(const PropertyName &pn) const
Chris@127 96 {
Chris@127 97 if (pn == "Global Scroll") return tr("Global Scroll");
Chris@127 98 if (pn == "Global Zoom") return tr("Global Zoom");
Chris@127 99 if (pn == "Follow Playback") return tr("Follow Playback");
Chris@127 100 return "";
Chris@127 101 }
Chris@127 102
Chris@127 103 PropertyContainer::PropertyType
Chris@127 104 View::getPropertyType(const PropertyContainer::PropertyName &name) const
Chris@127 105 {
Chris@127 106 if (name == "Global Scroll") return PropertyContainer::ToggleProperty;
Chris@127 107 if (name == "Global Zoom") return PropertyContainer::ToggleProperty;
Chris@127 108 if (name == "Follow Playback") return PropertyContainer::ValueProperty;
Chris@127 109 return PropertyContainer::InvalidProperty;
Chris@127 110 }
Chris@127 111
Chris@127 112 int
Chris@127 113 View::getPropertyRangeAndValue(const PropertyContainer::PropertyName &name,
Chris@216 114 int *min, int *max, int *deflt) const
Chris@127 115 {
Chris@216 116 if (deflt) *deflt = 1;
Chris@127 117 if (name == "Global Scroll") return m_followPan;
Chris@127 118 if (name == "Global Zoom") return m_followZoom;
Chris@127 119 if (name == "Follow Playback") {
Chris@127 120 if (min) *min = 0;
Chris@127 121 if (max) *max = 2;
Chris@815 122 if (deflt) *deflt = int(PlaybackScrollPageWithCentre);
Chris@815 123 switch (m_followPlay) {
Chris@815 124 case PlaybackScrollContinuous: return 0;
Chris@815 125 case PlaybackScrollPageWithCentre: case PlaybackScrollPage: return 1;
Chris@815 126 case PlaybackIgnore: return 2;
Chris@815 127 }
Chris@127 128 }
Chris@127 129 if (min) *min = 0;
Chris@127 130 if (max) *max = 0;
Chris@216 131 if (deflt) *deflt = 0;
Chris@127 132 return 0;
Chris@127 133 }
Chris@127 134
Chris@127 135 QString
Chris@127 136 View::getPropertyValueLabel(const PropertyContainer::PropertyName &name,
Chris@127 137 int value) const
Chris@127 138 {
Chris@127 139 if (name == "Follow Playback") {
Chris@127 140 switch (value) {
Chris@127 141 default:
Chris@127 142 case 0: return tr("Scroll");
Chris@127 143 case 1: return tr("Page");
Chris@127 144 case 2: return tr("Off");
Chris@127 145 }
Chris@127 146 }
Chris@127 147 return tr("<unknown>");
Chris@127 148 }
Chris@127 149
Chris@127 150 void
Chris@127 151 View::setProperty(const PropertyContainer::PropertyName &name, int value)
Chris@127 152 {
Chris@127 153 if (name == "Global Scroll") {
Chris@127 154 setFollowGlobalPan(value != 0);
Chris@127 155 } else if (name == "Global Zoom") {
Chris@127 156 setFollowGlobalZoom(value != 0);
Chris@127 157 } else if (name == "Follow Playback") {
Chris@127 158 switch (value) {
Chris@127 159 default:
Chris@127 160 case 0: setPlaybackFollow(PlaybackScrollContinuous); break;
Chris@815 161 case 1: setPlaybackFollow(PlaybackScrollPageWithCentre); break;
Chris@127 162 case 2: setPlaybackFollow(PlaybackIgnore); break;
Chris@127 163 }
Chris@127 164 }
Chris@127 165 }
Chris@127 166
Chris@806 167 int
Chris@127 168 View::getPropertyContainerCount() const
Chris@127 169 {
Chris@908 170 return int(m_fixedOrderLayers.size()) + 1; // the 1 is for me
Chris@127 171 }
Chris@127 172
Chris@127 173 const PropertyContainer *
Chris@806 174 View::getPropertyContainer(int i) const
Chris@127 175 {
Chris@127 176 return (const PropertyContainer *)(((View *)this)->
Chris@127 177 getPropertyContainer(i));
Chris@127 178 }
Chris@127 179
Chris@127 180 PropertyContainer *
Chris@806 181 View::getPropertyContainer(int i)
Chris@127 182 {
Chris@127 183 if (i == 0) return m_propertyContainer;
Chris@837 184 return m_fixedOrderLayers[i-1];
Chris@127 185 }
Chris@127 186
Chris@127 187 bool
Chris@904 188 View::getValueExtents(QString unit, double &min, double &max, bool &log) const
Chris@127 189 {
Chris@127 190 bool have = false;
Chris@127 191
Chris@835 192 for (LayerList::const_iterator i = m_layerStack.begin();
Chris@835 193 i != m_layerStack.end(); ++i) {
Chris@127 194
Chris@127 195 QString layerUnit;
Chris@904 196 double layerMin = 0.0, layerMax = 0.0;
Chris@904 197 double displayMin = 0.0, displayMax = 0.0;
Chris@127 198 bool layerLog = false;
Chris@127 199
Chris@127 200 if ((*i)->getValueExtents(layerMin, layerMax, layerLog, layerUnit) &&
Chris@127 201 layerUnit.toLower() == unit.toLower()) {
Chris@127 202
Chris@127 203 if ((*i)->getDisplayExtents(displayMin, displayMax)) {
Chris@127 204
Chris@127 205 min = displayMin;
Chris@127 206 max = displayMax;
Chris@127 207 log = layerLog;
Chris@127 208 have = true;
Chris@127 209 break;
Chris@127 210
Chris@127 211 } else {
Chris@127 212
Chris@127 213 if (!have || layerMin < min) min = layerMin;
Chris@127 214 if (!have || layerMax > max) max = layerMax;
Chris@127 215 if (layerLog) log = true;
Chris@127 216 have = true;
Chris@127 217 }
Chris@127 218 }
Chris@127 219 }
Chris@127 220
Chris@127 221 return have;
Chris@127 222 }
Chris@127 223
Chris@127 224 int
Chris@127 225 View::getTextLabelHeight(const Layer *layer, QPainter &paint) const
Chris@127 226 {
Chris@127 227 std::map<int, Layer *> sortedLayers;
Chris@127 228
Chris@835 229 for (LayerList::const_iterator i = m_layerStack.begin();
Chris@835 230 i != m_layerStack.end(); ++i) {
Chris@127 231 if ((*i)->needsTextLabelHeight()) {
Chris@127 232 sortedLayers[getObjectExportId(*i)] = *i;
Chris@127 233 }
Chris@127 234 }
Chris@127 235
Chris@127 236 int y = 15 + paint.fontMetrics().ascent();
Chris@127 237
Chris@127 238 for (std::map<int, Layer *>::const_iterator i = sortedLayers.begin();
Chris@127 239 i != sortedLayers.end(); ++i) {
Chris@127 240 if (i->second == layer) return y;
Chris@127 241 y += paint.fontMetrics().height();
Chris@127 242 }
Chris@127 243
Chris@127 244 return y;
Chris@127 245 }
Chris@127 246
Chris@127 247 void
Chris@127 248 View::propertyContainerSelected(View *client, PropertyContainer *pc)
Chris@127 249 {
Chris@127 250 if (client != this) return;
Chris@127 251
Chris@127 252 if (pc == m_propertyContainer) {
Chris@127 253 if (m_haveSelectedLayer) {
Chris@127 254 m_haveSelectedLayer = false;
Chris@127 255 update();
Chris@127 256 }
Chris@127 257 return;
Chris@127 258 }
Chris@127 259
Chris@127 260 delete m_cache;
Chris@127 261 m_cache = 0;
Chris@127 262
Chris@127 263 Layer *selectedLayer = 0;
Chris@127 264
Chris@835 265 for (LayerList::iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
Chris@127 266 if (*i == pc) {
Chris@127 267 selectedLayer = *i;
Chris@835 268 m_layerStack.erase(i);
Chris@127 269 break;
Chris@127 270 }
Chris@127 271 }
Chris@127 272
Chris@127 273 if (selectedLayer) {
Chris@127 274 m_haveSelectedLayer = true;
Chris@835 275 m_layerStack.push_back(selectedLayer);
Chris@127 276 update();
Chris@127 277 } else {
Chris@127 278 m_haveSelectedLayer = false;
Chris@127 279 }
Chris@298 280
Chris@298 281 emit propertyContainerSelected(pc);
Chris@127 282 }
Chris@127 283
Chris@127 284 void
Chris@127 285 View::toolModeChanged()
Chris@127 286 {
Chris@587 287 // SVDEBUG << "View::toolModeChanged(" << m_manager->getToolMode() << ")" << endl;
Chris@127 288 }
Chris@127 289
Chris@133 290 void
Chris@133 291 View::overlayModeChanged()
Chris@133 292 {
Chris@206 293 delete m_cache;
Chris@206 294 m_cache = 0;
Chris@133 295 update();
Chris@133 296 }
Chris@133 297
Chris@133 298 void
Chris@133 299 View::zoomWheelsEnabledChanged()
Chris@133 300 {
Chris@133 301 // subclass might override this
Chris@133 302 }
Chris@133 303
Chris@908 304 sv_frame_t
Chris@127 305 View::getStartFrame() const
Chris@127 306 {
Chris@313 307 return getFrameForX(0);
Chris@127 308 }
Chris@127 309
Chris@908 310 sv_frame_t
Chris@127 311 View::getEndFrame() const
Chris@127 312 {
Chris@127 313 return getFrameForX(width()) - 1;
Chris@127 314 }
Chris@127 315
Chris@127 316 void
Chris@908 317 View::setStartFrame(sv_frame_t f)
Chris@127 318 {
Chris@127 319 setCentreFrame(f + m_zoomLevel * (width() / 2));
Chris@127 320 }
Chris@127 321
Chris@127 322 bool
Chris@908 323 View::setCentreFrame(sv_frame_t f, bool e)
Chris@127 324 {
Chris@127 325 bool changeVisible = false;
Chris@127 326
Chris@127 327 if (m_centreFrame != f) {
Chris@127 328
Chris@908 329 int formerPixel = int(m_centreFrame / m_zoomLevel);
Chris@127 330
Chris@127 331 m_centreFrame = f;
Chris@127 332
Chris@908 333 int newPixel = int(m_centreFrame / m_zoomLevel);
Chris@127 334
Chris@127 335 if (newPixel != formerPixel) {
Chris@127 336
Chris@127 337 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 338 cout << "View(" << this << ")::setCentreFrame: newPixel " << newPixel << ", formerPixel " << formerPixel << endl;
Chris@127 339 #endif
Chris@127 340 update();
Chris@127 341
Chris@127 342 changeVisible = true;
Chris@127 343 }
Chris@127 344
Chris@333 345 if (e) {
Chris@908 346 sv_frame_t rf = alignToReference(f);
Chris@830 347 #ifdef DEBUG_VIEW
Chris@682 348 cerr << "View[" << this << "]::setCentreFrame(" << f
Chris@333 349 << "): emitting centreFrameChanged("
Chris@682 350 << rf << ")" << endl;
Chris@355 351 #endif
Chris@333 352 emit centreFrameChanged(rf, m_followPan, m_followPlay);
Chris@333 353 }
Chris@127 354 }
Chris@127 355
Chris@127 356 return changeVisible;
Chris@127 357 }
Chris@127 358
Chris@127 359 int
Chris@908 360 View::getXForFrame(sv_frame_t frame) const
Chris@127 361 {
Chris@908 362 return int((frame - getStartFrame()) / m_zoomLevel);
Chris@127 363 }
Chris@127 364
Chris@908 365 sv_frame_t
Chris@127 366 View::getFrameForX(int x) const
Chris@127 367 {
Chris@1020 368 sv_frame_t z = m_zoomLevel; // nb not just int, or multiplication may overflow
Chris@908 369 sv_frame_t frame = m_centreFrame - (width()/2) * z;
Chris@354 370
Chris@1020 371 frame = (frame / z) * z; // this is start frame
Chris@1020 372 frame = frame + x * z;
Chris@1020 373
Chris@355 374 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@1020 375 cerr << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl;
Chris@355 376 #endif
Chris@354 377
Chris@1020 378 return frame;
Chris@127 379 }
Chris@127 380
Chris@904 381 double
Chris@904 382 View::getYForFrequency(double frequency,
Chris@904 383 double minf,
Chris@904 384 double maxf,
Chris@127 385 bool logarithmic) const
Chris@127 386 {
Chris@382 387 Profiler profiler("View::getYForFrequency");
Chris@382 388
Chris@127 389 int h = height();
Chris@127 390
Chris@127 391 if (logarithmic) {
Chris@127 392
Chris@904 393 static double lastminf = 0.0, lastmaxf = 0.0;
Chris@904 394 static double logminf = 0.0, logmaxf = 0.0;
Chris@127 395
Chris@127 396 if (lastminf != minf) {
Chris@127 397 lastminf = (minf == 0.0 ? 1.0 : minf);
Chris@908 398 logminf = log10(minf);
Chris@127 399 }
Chris@127 400 if (lastmaxf != maxf) {
Chris@127 401 lastmaxf = (maxf < lastminf ? lastminf : maxf);
Chris@908 402 logmaxf = log10(maxf);
Chris@127 403 }
Chris@127 404
Chris@127 405 if (logminf == logmaxf) return 0;
Chris@908 406 return h - (h * (log10(frequency) - logminf)) / (logmaxf - logminf);
Chris@127 407
Chris@127 408 } else {
Chris@127 409
Chris@127 410 if (minf == maxf) return 0;
Chris@127 411 return h - (h * (frequency - minf)) / (maxf - minf);
Chris@127 412 }
Chris@127 413 }
Chris@127 414
Chris@904 415 double
Chris@127 416 View::getFrequencyForY(int y,
Chris@904 417 double minf,
Chris@904 418 double maxf,
Chris@127 419 bool logarithmic) const
Chris@127 420 {
Chris@127 421 int h = height();
Chris@127 422
Chris@127 423 if (logarithmic) {
Chris@127 424
Chris@904 425 static double lastminf = 0.0, lastmaxf = 0.0;
Chris@904 426 static double logminf = 0.0, logmaxf = 0.0;
Chris@127 427
Chris@127 428 if (lastminf != minf) {
Chris@127 429 lastminf = (minf == 0.0 ? 1.0 : minf);
Chris@908 430 logminf = log10(minf);
Chris@127 431 }
Chris@127 432 if (lastmaxf != maxf) {
Chris@127 433 lastmaxf = (maxf < lastminf ? lastminf : maxf);
Chris@908 434 logmaxf = log10(maxf);
Chris@127 435 }
Chris@127 436
Chris@127 437 if (logminf == logmaxf) return 0;
Chris@908 438 return pow(10.0, logminf + ((logmaxf - logminf) * (h - y)) / h);
Chris@127 439
Chris@127 440 } else {
Chris@127 441
Chris@127 442 if (minf == maxf) return 0;
Chris@127 443 return minf + ((h - y) * (maxf - minf)) / h;
Chris@127 444 }
Chris@127 445 }
Chris@127 446
Chris@127 447 int
Chris@127 448 View::getZoomLevel() const
Chris@127 449 {
Chris@127 450 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 451 // cout << "zoom level: " << m_zoomLevel << endl;
Chris@127 452 #endif
Chris@127 453 return m_zoomLevel;
Chris@127 454 }
Chris@127 455
Chris@956 456 int
Chris@956 457 View::effectiveDevicePixelRatio() const
Chris@956 458 {
Chris@956 459 #ifdef Q_OS_MAC
Chris@956 460 int dpratio = devicePixelRatio();
Chris@956 461 if (dpratio > 1) {
Chris@956 462 QSettings settings;
Chris@956 463 settings.beginGroup("Preferences");
Chris@956 464 if (!settings.value("scaledHiDpi", true).toBool()) {
Chris@956 465 dpratio = 1;
Chris@956 466 }
Chris@956 467 settings.endGroup();
Chris@956 468 }
Chris@956 469 return dpratio;
Chris@956 470 #else
Chris@956 471 return 1;
Chris@956 472 #endif
Chris@956 473 }
Chris@956 474
Chris@127 475 void
Chris@806 476 View::setZoomLevel(int z)
Chris@127 477 {
Chris@956 478 int dpratio = effectiveDevicePixelRatio();
Chris@950 479 if (z < dpratio) return;
Chris@462 480 if (z < 1) z = 1;
Chris@127 481 if (m_zoomLevel != int(z)) {
Chris@127 482 m_zoomLevel = z;
Chris@222 483 emit zoomLevelChanged(z, m_followZoom);
Chris@127 484 update();
Chris@127 485 }
Chris@127 486 }
Chris@127 487
Chris@224 488 bool
Chris@224 489 View::hasLightBackground() const
Chris@224 490 {
Chris@287 491 bool darkPalette = false;
Chris@292 492 if (m_manager) darkPalette = m_manager->getGlobalDarkBackground();
Chris@287 493
Chris@287 494 Layer::ColourSignificance maxSignificance = Layer::ColourAbsent;
Chris@287 495 bool mostSignificantHasDarkBackground = false;
Chris@287 496
Chris@835 497 for (LayerList::const_iterator i = m_layerStack.begin();
Chris@835 498 i != m_layerStack.end(); ++i) {
Chris@287 499
Chris@287 500 Layer::ColourSignificance s = (*i)->getLayerColourSignificance();
Chris@287 501 bool light = (*i)->hasLightBackground();
Chris@287 502
Chris@287 503 if (int(s) > int(maxSignificance)) {
Chris@287 504 maxSignificance = s;
Chris@287 505 mostSignificantHasDarkBackground = !light;
Chris@287 506 } else if (s == maxSignificance && !light) {
Chris@287 507 mostSignificantHasDarkBackground = true;
Chris@287 508 }
Chris@224 509 }
Chris@287 510
Chris@287 511 if (int(maxSignificance) >= int(Layer::ColourAndBackgroundSignificant)) {
Chris@287 512 return !mostSignificantHasDarkBackground;
Chris@287 513 } else {
Chris@287 514 return !darkPalette;
Chris@287 515 }
Chris@287 516 }
Chris@287 517
Chris@287 518 QColor
Chris@287 519 View::getBackground() const
Chris@287 520 {
Chris@287 521 bool light = hasLightBackground();
Chris@287 522
Chris@287 523 QColor widgetbg = palette().window().color();
Chris@287 524 bool widgetLight =
Chris@287 525 (widgetbg.red() + widgetbg.green() + widgetbg.blue()) > 384;
Chris@287 526
Chris@296 527 if (widgetLight == light) {
Chris@296 528 if (widgetLight) {
Chris@296 529 return widgetbg.light();
Chris@296 530 } else {
Chris@296 531 return widgetbg.dark();
Chris@296 532 }
Chris@296 533 }
Chris@287 534 else if (light) return Qt::white;
Chris@287 535 else return Qt::black;
Chris@287 536 }
Chris@287 537
Chris@287 538 QColor
Chris@287 539 View::getForeground() const
Chris@287 540 {
Chris@287 541 bool light = hasLightBackground();
Chris@287 542
Chris@287 543 QColor widgetfg = palette().text().color();
Chris@287 544 bool widgetLight =
Chris@287 545 (widgetfg.red() + widgetfg.green() + widgetfg.blue()) > 384;
Chris@287 546
Chris@287 547 if (widgetLight != light) return widgetfg;
Chris@287 548 else if (light) return Qt::black;
Chris@287 549 else return Qt::white;
Chris@224 550 }
Chris@224 551
Chris@127 552 void
Chris@127 553 View::addLayer(Layer *layer)
Chris@127 554 {
Chris@127 555 delete m_cache;
Chris@127 556 m_cache = 0;
Chris@127 557
Chris@287 558 SingleColourLayer *scl = dynamic_cast<SingleColourLayer *>(layer);
Chris@287 559 if (scl) scl->setDefaultColourFor(this);
Chris@287 560
Chris@836 561 m_fixedOrderLayers.push_back(layer);
Chris@835 562 m_layerStack.push_back(layer);
Chris@127 563
Chris@555 564 QProgressBar *pb = new QProgressBar(this);
Chris@555 565 pb->setMinimum(0);
Chris@555 566 pb->setMaximum(0);
Chris@555 567 pb->setFixedWidth(80);
Chris@555 568 pb->setTextVisible(false);
Chris@555 569
Chris@797 570 QPushButton *cancel = new QPushButton(this);
Chris@797 571 cancel->setIcon(IconLoader().load("fileclose"));
Chris@797 572 cancel->setFlat(true);
Chris@797 573 cancel->setFixedSize(QSize(20, 20));
Chris@797 574 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Chris@797 575
Chris@555 576 ProgressBarRec pbr;
Chris@797 577 pbr.cancel = cancel;
Chris@555 578 pbr.bar = pb;
Chris@555 579 pbr.lastCheck = 0;
Chris@555 580 pbr.checkTimer = new QTimer();
Chris@555 581 connect(pbr.checkTimer, SIGNAL(timeout()), this,
Chris@555 582 SLOT(progressCheckStalledTimerElapsed()));
Chris@555 583
Chris@555 584 m_progressBars[layer] = pbr;
Chris@555 585
Chris@555 586 QFont f(pb->font());
Chris@339 587 int fs = Preferences::getInstance()->getViewFontSize();
Chris@339 588 f.setPointSize(std::min(fs, int(ceil(fs * 0.85))));
Chris@339 589
Chris@797 590 cancel->hide();
Chris@797 591
Chris@555 592 pb->setFont(f);
Chris@555 593 pb->hide();
Chris@127 594
Chris@127 595 connect(layer, SIGNAL(layerParametersChanged()),
Chris@127 596 this, SLOT(layerParametersChanged()));
Chris@197 597 connect(layer, SIGNAL(layerParameterRangesChanged()),
Chris@197 598 this, SLOT(layerParameterRangesChanged()));
Chris@268 599 connect(layer, SIGNAL(layerMeasurementRectsChanged()),
Chris@268 600 this, SLOT(layerMeasurementRectsChanged()));
Chris@127 601 connect(layer, SIGNAL(layerNameChanged()),
Chris@127 602 this, SLOT(layerNameChanged()));
Chris@127 603 connect(layer, SIGNAL(modelChanged()),
Chris@127 604 this, SLOT(modelChanged()));
Chris@127 605 connect(layer, SIGNAL(modelCompletionChanged()),
Chris@127 606 this, SLOT(modelCompletionChanged()));
Chris@320 607 connect(layer, SIGNAL(modelAlignmentCompletionChanged()),
Chris@320 608 this, SLOT(modelAlignmentCompletionChanged()));
Chris@908 609 connect(layer, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
Chris@908 610 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
Chris@127 611 connect(layer, SIGNAL(modelReplaced()),
Chris@127 612 this, SLOT(modelReplaced()));
Chris@127 613
Chris@127 614 update();
Chris@127 615
Chris@127 616 emit propertyContainerAdded(layer);
Chris@127 617 }
Chris@127 618
Chris@127 619 void
Chris@127 620 View::removeLayer(Layer *layer)
Chris@127 621 {
Chris@127 622 if (m_deleting) {
Chris@127 623 return;
Chris@127 624 }
Chris@127 625
Chris@127 626 delete m_cache;
Chris@127 627 m_cache = 0;
Chris@127 628
Chris@836 629 for (LayerList::iterator i = m_fixedOrderLayers.begin();
Chris@836 630 i != m_fixedOrderLayers.end();
Chris@836 631 ++i) {
Chris@836 632 if (*i == layer) {
Chris@836 633 m_fixedOrderLayers.erase(i);
Chris@836 634 break;
Chris@836 635 }
Chris@836 636 }
Chris@836 637
Chris@836 638 for (LayerList::iterator i = m_layerStack.begin();
Chris@836 639 i != m_layerStack.end();
Chris@836 640 ++i) {
Chris@127 641 if (*i == layer) {
Chris@835 642 m_layerStack.erase(i);
Chris@127 643 if (m_progressBars.find(layer) != m_progressBars.end()) {
Chris@555 644 delete m_progressBars[layer].bar;
Chris@797 645 delete m_progressBars[layer].cancel;
Chris@555 646 delete m_progressBars[layer].checkTimer;
Chris@127 647 m_progressBars.erase(layer);
Chris@127 648 }
Chris@127 649 break;
Chris@127 650 }
Chris@127 651 }
Chris@127 652
Chris@197 653 disconnect(layer, SIGNAL(layerParametersChanged()),
Chris@197 654 this, SLOT(layerParametersChanged()));
Chris@197 655 disconnect(layer, SIGNAL(layerParameterRangesChanged()),
Chris@197 656 this, SLOT(layerParameterRangesChanged()));
Chris@197 657 disconnect(layer, SIGNAL(layerNameChanged()),
Chris@197 658 this, SLOT(layerNameChanged()));
Chris@197 659 disconnect(layer, SIGNAL(modelChanged()),
Chris@197 660 this, SLOT(modelChanged()));
Chris@197 661 disconnect(layer, SIGNAL(modelCompletionChanged()),
Chris@197 662 this, SLOT(modelCompletionChanged()));
Chris@320 663 disconnect(layer, SIGNAL(modelAlignmentCompletionChanged()),
Chris@320 664 this, SLOT(modelAlignmentCompletionChanged()));
Chris@908 665 disconnect(layer, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
Chris@908 666 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
Chris@197 667 disconnect(layer, SIGNAL(modelReplaced()),
Chris@197 668 this, SLOT(modelReplaced()));
Chris@197 669
Chris@127 670 update();
Chris@127 671
Chris@127 672 emit propertyContainerRemoved(layer);
Chris@127 673 }
Chris@127 674
Chris@127 675 Layer *
Chris@834 676 View::getInteractionLayer()
Chris@834 677 {
Chris@834 678 Layer *sl = getSelectedLayer();
Chris@834 679 if (sl && !(sl->isLayerDormant(this))) {
Chris@834 680 return sl;
Chris@834 681 }
Chris@835 682 if (!m_layerStack.empty()) {
Chris@834 683 int n = getLayerCount();
Chris@834 684 while (n > 0) {
Chris@834 685 --n;
Chris@834 686 Layer *layer = getLayer(n);
Chris@834 687 if (!(layer->isLayerDormant(this))) {
Chris@834 688 return layer;
Chris@834 689 }
Chris@834 690 }
Chris@834 691 }
Chris@834 692 return 0;
Chris@834 693 }
Chris@834 694
Chris@841 695 const Layer *
Chris@841 696 View::getInteractionLayer() const
Chris@841 697 {
Chris@841 698 return const_cast<const Layer *>(const_cast<View *>(this)->getInteractionLayer());
Chris@841 699 }
Chris@841 700
Chris@834 701 Layer *
Chris@127 702 View::getSelectedLayer()
Chris@127 703 {
Chris@835 704 if (m_haveSelectedLayer && !m_layerStack.empty()) {
Chris@839 705 return getLayer(getLayerCount() - 1);
Chris@127 706 } else {
Chris@127 707 return 0;
Chris@127 708 }
Chris@127 709 }
Chris@127 710
Chris@127 711 const Layer *
Chris@127 712 View::getSelectedLayer() const
Chris@127 713 {
Chris@127 714 return const_cast<const Layer *>(const_cast<View *>(this)->getSelectedLayer());
Chris@127 715 }
Chris@127 716
Chris@127 717 void
Chris@127 718 View::setViewManager(ViewManager *manager)
Chris@127 719 {
Chris@127 720 if (m_manager) {
Chris@908 721 m_manager->disconnect(this, SLOT(globalCentreFrameChanged(sv_frame_t)));
Chris@908 722 m_manager->disconnect(this, SLOT(viewCentreFrameChanged(View *, sv_frame_t)));
Chris@908 723 m_manager->disconnect(this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t)));
Chris@806 724 m_manager->disconnect(this, SLOT(viewZoomLevelChanged(View *, int, bool)));
Chris@211 725 m_manager->disconnect(this, SLOT(toolModeChanged()));
Chris@211 726 m_manager->disconnect(this, SLOT(selectionChanged()));
Chris@211 727 m_manager->disconnect(this, SLOT(overlayModeChanged()));
Chris@211 728 m_manager->disconnect(this, SLOT(zoomWheelsEnabledChanged()));
Chris@908 729 disconnect(m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode)));
Chris@806 730 disconnect(m_manager, SLOT(zoomLevelChanged(int, bool)));
Chris@127 731 }
Chris@127 732
Chris@127 733 m_manager = manager;
Chris@127 734
Chris@908 735 connect(m_manager, SIGNAL(globalCentreFrameChanged(sv_frame_t)),
Chris@908 736 this, SLOT(globalCentreFrameChanged(sv_frame_t)));
Chris@908 737 connect(m_manager, SIGNAL(viewCentreFrameChanged(View *, sv_frame_t)),
Chris@908 738 this, SLOT(viewCentreFrameChanged(View *, sv_frame_t)));
Chris@908 739 connect(m_manager, SIGNAL(playbackFrameChanged(sv_frame_t)),
Chris@908 740 this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t)));
Chris@806 741
Chris@806 742 connect(m_manager, SIGNAL(viewZoomLevelChanged(View *, int, bool)),
Chris@806 743 this, SLOT(viewZoomLevelChanged(View *, int, bool)));
Chris@211 744
Chris@127 745 connect(m_manager, SIGNAL(toolModeChanged()),
Chris@127 746 this, SLOT(toolModeChanged()));
Chris@127 747 connect(m_manager, SIGNAL(selectionChanged()),
Chris@127 748 this, SLOT(selectionChanged()));
Chris@127 749 connect(m_manager, SIGNAL(inProgressSelectionChanged()),
Chris@127 750 this, SLOT(selectionChanged()));
Chris@127 751 connect(m_manager, SIGNAL(overlayModeChanged()),
Chris@133 752 this, SLOT(overlayModeChanged()));
Chris@607 753 connect(m_manager, SIGNAL(showCentreLineChanged()),
Chris@607 754 this, SLOT(overlayModeChanged()));
Chris@133 755 connect(m_manager, SIGNAL(zoomWheelsEnabledChanged()),
Chris@133 756 this, SLOT(zoomWheelsEnabledChanged()));
Chris@127 757
Chris@908 758 connect(this, SIGNAL(centreFrameChanged(sv_frame_t, bool,
Chris@211 759 PlaybackFollowMode)),
Chris@908 760 m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool,
Chris@211 761 PlaybackFollowMode)));
Chris@211 762
Chris@806 763 connect(this, SIGNAL(zoomLevelChanged(int, bool)),
Chris@806 764 m_manager, SLOT(viewZoomLevelChanged(int, bool)));
Chris@127 765
Chris@815 766 switch (m_followPlay) {
Chris@815 767
Chris@815 768 case PlaybackScrollPage:
Chris@815 769 case PlaybackScrollPageWithCentre:
Chris@364 770 setCentreFrame(m_manager->getGlobalCentreFrame(), false);
Chris@815 771 break;
Chris@815 772
Chris@815 773 case PlaybackScrollContinuous:
Chris@236 774 setCentreFrame(m_manager->getPlaybackFrame(), false);
Chris@815 775 break;
Chris@815 776
Chris@815 777 case PlaybackIgnore:
Chris@815 778 if (m_followPan) {
Chris@815 779 setCentreFrame(m_manager->getGlobalCentreFrame(), false);
Chris@815 780 }
Chris@815 781 break;
Chris@236 782 }
Chris@516 783
Chris@236 784 if (m_followZoom) setZoomLevel(m_manager->getGlobalZoom());
Chris@236 785
Chris@511 786 movePlayPointer(getAlignedPlaybackFrame());
Chris@511 787
Chris@127 788 toolModeChanged();
Chris@127 789 }
Chris@127 790
Chris@127 791 void
Chris@908 792 View::setViewManager(ViewManager *vm, sv_frame_t initialCentreFrame)
Chris@516 793 {
Chris@516 794 setViewManager(vm);
Chris@516 795 setCentreFrame(initialCentreFrame, false);
Chris@516 796 }
Chris@516 797
Chris@516 798 void
Chris@127 799 View::setFollowGlobalPan(bool f)
Chris@127 800 {
Chris@127 801 m_followPan = f;
Chris@127 802 emit propertyContainerPropertyChanged(m_propertyContainer);
Chris@127 803 }
Chris@127 804
Chris@127 805 void
Chris@127 806 View::setFollowGlobalZoom(bool f)
Chris@127 807 {
Chris@127 808 m_followZoom = f;
Chris@127 809 emit propertyContainerPropertyChanged(m_propertyContainer);
Chris@127 810 }
Chris@127 811
Chris@127 812 void
Chris@267 813 View::drawVisibleText(QPainter &paint, int x, int y, QString text, TextStyle style) const
Chris@127 814 {
Chris@630 815 if (style == OutlinedText || style == OutlinedItalicText) {
Chris@127 816
Chris@279 817 paint.save();
Chris@279 818
Chris@630 819 if (style == OutlinedItalicText) {
Chris@630 820 QFont f(paint.font());
Chris@630 821 f.setItalic(true);
Chris@630 822 paint.setFont(f);
Chris@630 823 }
Chris@630 824
Chris@575 825 QColor penColour, surroundColour, boxColour;
Chris@279 826
Chris@287 827 penColour = getForeground();
Chris@287 828 surroundColour = getBackground();
Chris@575 829 boxColour = surroundColour;
Chris@575 830 boxColour.setAlpha(127);
Chris@575 831
Chris@575 832 paint.setPen(Qt::NoPen);
Chris@575 833 paint.setBrush(boxColour);
Chris@630 834
Chris@575 835 QRect r = paint.fontMetrics().boundingRect(text);
Chris@575 836 r.translate(QPoint(x, y));
Chris@682 837 // cerr << "drawVisibleText: r = " << r.x() << "," <<r.y() << " " << r.width() << "x" << r.height() << endl;
Chris@575 838 paint.drawRect(r);
Chris@575 839 paint.setBrush(Qt::NoBrush);
Chris@279 840
Chris@127 841 paint.setPen(surroundColour);
Chris@127 842
Chris@127 843 for (int dx = -1; dx <= 1; ++dx) {
Chris@127 844 for (int dy = -1; dy <= 1; ++dy) {
Chris@127 845 if (!(dx || dy)) continue;
Chris@127 846 paint.drawText(x + dx, y + dy, text);
Chris@127 847 }
Chris@127 848 }
Chris@127 849
Chris@127 850 paint.setPen(penColour);
Chris@127 851
Chris@127 852 paint.drawText(x, y, text);
Chris@287 853
Chris@279 854 paint.restore();
Chris@127 855
Chris@127 856 } else {
Chris@127 857
Chris@682 858 cerr << "ERROR: View::drawVisibleText: Boxed style not yet implemented!" << endl;
Chris@127 859 }
Chris@127 860 }
Chris@127 861
Chris@127 862 void
Chris@127 863 View::setPlaybackFollow(PlaybackFollowMode m)
Chris@127 864 {
Chris@127 865 m_followPlay = m;
Chris@127 866 emit propertyContainerPropertyChanged(m_propertyContainer);
Chris@127 867 }
Chris@127 868
Chris@127 869 void
Chris@127 870 View::modelChanged()
Chris@127 871 {
Chris@127 872 QObject *obj = sender();
Chris@127 873
Chris@127 874 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 875 cerr << "View(" << this << ")::modelChanged()" << endl;
Chris@127 876 #endif
Chris@127 877
Chris@127 878 // If the model that has changed is not used by any of the cached
Chris@127 879 // layers, we won't need to recreate the cache
Chris@127 880
Chris@127 881 bool recreate = false;
Chris@127 882
Chris@127 883 bool discard;
Chris@127 884 LayerList scrollables = getScrollableBackLayers(false, discard);
Chris@127 885 for (LayerList::const_iterator i = scrollables.begin();
Chris@127 886 i != scrollables.end(); ++i) {
Chris@127 887 if (*i == obj || (*i)->getModel() == obj) {
Chris@127 888 recreate = true;
Chris@127 889 break;
Chris@127 890 }
Chris@127 891 }
Chris@127 892
Chris@127 893 if (recreate) {
Chris@127 894 delete m_cache;
Chris@127 895 m_cache = 0;
Chris@127 896 }
Chris@127 897
Chris@336 898 emit layerModelChanged();
Chris@336 899
Chris@127 900 checkProgress(obj);
Chris@127 901
Chris@127 902 update();
Chris@127 903 }
Chris@127 904
Chris@127 905 void
Chris@908 906 View::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
Chris@127 907 {
Chris@127 908 QObject *obj = sender();
Chris@127 909
Chris@908 910 sv_frame_t myStartFrame = getStartFrame();
Chris@908 911 sv_frame_t myEndFrame = getEndFrame();
Chris@127 912
Chris@127 913 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@806 914 cerr << "View(" << this << ")::modelChangedWithin(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << endl;
Chris@127 915 #endif
Chris@127 916
Chris@908 917 if (myStartFrame > 0 && endFrame < myStartFrame) {
Chris@127 918 checkProgress(obj);
Chris@127 919 return;
Chris@127 920 }
Chris@127 921 if (startFrame > myEndFrame) {
Chris@127 922 checkProgress(obj);
Chris@127 923 return;
Chris@127 924 }
Chris@127 925
Chris@127 926 // If the model that has changed is not used by any of the cached
Chris@127 927 // layers, we won't need to recreate the cache
Chris@127 928
Chris@127 929 bool recreate = false;
Chris@127 930
Chris@127 931 bool discard;
Chris@127 932 LayerList scrollables = getScrollableBackLayers(false, discard);
Chris@127 933 for (LayerList::const_iterator i = scrollables.begin();
Chris@127 934 i != scrollables.end(); ++i) {
Chris@127 935 if (*i == obj || (*i)->getModel() == obj) {
Chris@127 936 recreate = true;
Chris@127 937 break;
Chris@127 938 }
Chris@127 939 }
Chris@127 940
Chris@127 941 if (recreate) {
Chris@127 942 delete m_cache;
Chris@127 943 m_cache = 0;
Chris@127 944 }
Chris@127 945
Chris@806 946 if (startFrame < myStartFrame) startFrame = myStartFrame;
Chris@127 947 if (endFrame > myEndFrame) endFrame = myEndFrame;
Chris@127 948
Chris@127 949 checkProgress(obj);
Chris@127 950
Chris@127 951 update();
Chris@127 952 }
Chris@127 953
Chris@127 954 void
Chris@127 955 View::modelCompletionChanged()
Chris@127 956 {
Chris@682 957 // cerr << "View(" << this << ")::modelCompletionChanged()" << endl;
Chris@301 958
Chris@127 959 QObject *obj = sender();
Chris@127 960 checkProgress(obj);
Chris@127 961 }
Chris@127 962
Chris@127 963 void
Chris@320 964 View::modelAlignmentCompletionChanged()
Chris@320 965 {
Chris@682 966 // cerr << "View(" << this << ")::modelAlignmentCompletionChanged()" << endl;
Chris@320 967
Chris@320 968 QObject *obj = sender();
Chris@320 969 checkProgress(obj);
Chris@320 970 }
Chris@320 971
Chris@320 972 void
Chris@127 973 View::modelReplaced()
Chris@127 974 {
Chris@127 975 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 976 cerr << "View(" << this << ")::modelReplaced()" << endl;
Chris@127 977 #endif
Chris@127 978 delete m_cache;
Chris@127 979 m_cache = 0;
Chris@127 980
Chris@127 981 update();
Chris@127 982 }
Chris@127 983
Chris@127 984 void
Chris@127 985 View::layerParametersChanged()
Chris@127 986 {
Chris@127 987 Layer *layer = dynamic_cast<Layer *>(sender());
Chris@127 988
Chris@127 989 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@587 990 SVDEBUG << "View::layerParametersChanged()" << endl;
Chris@127 991 #endif
Chris@127 992
Chris@127 993 delete m_cache;
Chris@127 994 m_cache = 0;
Chris@127 995 update();
Chris@127 996
Chris@127 997 if (layer) {
Chris@127 998 emit propertyContainerPropertyChanged(layer);
Chris@127 999 }
Chris@127 1000 }
Chris@127 1001
Chris@127 1002 void
Chris@197 1003 View::layerParameterRangesChanged()
Chris@197 1004 {
Chris@197 1005 Layer *layer = dynamic_cast<Layer *>(sender());
Chris@197 1006 if (layer) emit propertyContainerPropertyRangeChanged(layer);
Chris@197 1007 }
Chris@197 1008
Chris@197 1009 void
Chris@268 1010 View::layerMeasurementRectsChanged()
Chris@268 1011 {
Chris@268 1012 Layer *layer = dynamic_cast<Layer *>(sender());
Chris@268 1013 if (layer) update();
Chris@268 1014 }
Chris@268 1015
Chris@268 1016 void
Chris@127 1017 View::layerNameChanged()
Chris@127 1018 {
Chris@127 1019 Layer *layer = dynamic_cast<Layer *>(sender());
Chris@127 1020 if (layer) emit propertyContainerNameChanged(layer);
Chris@127 1021 }
Chris@127 1022
Chris@127 1023 void
Chris@908 1024 View::globalCentreFrameChanged(sv_frame_t rf)
Chris@127 1025 {
Chris@211 1026 if (m_followPan) {
Chris@908 1027 sv_frame_t f = alignFromReference(rf);
Chris@830 1028 #ifdef DEBUG_VIEW
Chris@682 1029 cerr << "View[" << this << "]::globalCentreFrameChanged(" << rf
Chris@682 1030 << "): setting centre frame to " << f << endl;
Chris@363 1031 #endif
Chris@333 1032 setCentreFrame(f, false);
Chris@127 1033 }
Chris@127 1034 }
Chris@127 1035
Chris@127 1036 void
Chris@908 1037 View::viewCentreFrameChanged(View *, sv_frame_t )
Chris@211 1038 {
Chris@211 1039 // We do nothing with this, but a subclass might
Chris@211 1040 }
Chris@211 1041
Chris@211 1042 void
Chris@908 1043 View::viewManagerPlaybackFrameChanged(sv_frame_t f)
Chris@127 1044 {
Chris@127 1045 if (m_manager) {
Chris@127 1046 if (sender() != m_manager) return;
Chris@127 1047 }
Chris@127 1048
Chris@830 1049 #ifdef DEBUG_VIEW
Chris@830 1050 cerr << "View::viewManagerPlaybackFrameChanged(" << f << ")" << endl;
Chris@830 1051 #endif
Chris@830 1052
Chris@301 1053 f = getAlignedPlaybackFrame();
Chris@301 1054
Chris@830 1055 #ifdef DEBUG_VIEW
Chris@951 1056 cerr << " -> aligned frame = " << f << endl;
Chris@830 1057 #endif
Chris@830 1058
Chris@511 1059 movePlayPointer(f);
Chris@511 1060 }
Chris@511 1061
Chris@511 1062 void
Chris@908 1063 View::movePlayPointer(sv_frame_t newFrame)
Chris@511 1064 {
Chris@830 1065 #ifdef DEBUG_VIEW
Chris@830 1066 cerr << "View(" << this << ")::movePlayPointer(" << newFrame << ")" << endl;
Chris@830 1067 #endif
Chris@830 1068
Chris@511 1069 if (m_playPointerFrame == newFrame) return;
Chris@511 1070 bool visibleChange =
Chris@511 1071 (getXForFrame(m_playPointerFrame) != getXForFrame(newFrame));
Chris@908 1072 sv_frame_t oldPlayPointerFrame = m_playPointerFrame;
Chris@511 1073 m_playPointerFrame = newFrame;
Chris@511 1074 if (!visibleChange) return;
Chris@127 1075
Chris@513 1076 bool somethingGoingOn =
Chris@513 1077 ((QApplication::mouseButtons() != Qt::NoButton) ||
Chris@513 1078 (QApplication::keyboardModifiers() & Qt::AltModifier));
Chris@513 1079
Chris@789 1080 bool pointerInVisibleArea =
Chris@789 1081 long(m_playPointerFrame) >= getStartFrame() &&
Chris@789 1082 (m_playPointerFrame < getEndFrame() ||
Chris@789 1083 // include old pointer location so we know to refresh when moving out
Chris@789 1084 oldPlayPointerFrame < getEndFrame());
Chris@789 1085
Chris@127 1086 switch (m_followPlay) {
Chris@127 1087
Chris@127 1088 case PlaybackScrollContinuous:
Chris@513 1089 if (!somethingGoingOn) {
Chris@511 1090 setCentreFrame(m_playPointerFrame, false);
Chris@127 1091 }
Chris@127 1092 break;
Chris@127 1093
Chris@127 1094 case PlaybackScrollPage:
Chris@815 1095 case PlaybackScrollPageWithCentre:
Chris@789 1096
Chris@789 1097 if (!pointerInVisibleArea && somethingGoingOn) {
Chris@789 1098
Chris@789 1099 m_followPlayIsDetached = true;
Chris@789 1100
Chris@789 1101 } else if (!pointerInVisibleArea && m_followPlayIsDetached) {
Chris@789 1102
Chris@789 1103 // do nothing; we aren't tracking until the pointer comes back in
Chris@789 1104
Chris@789 1105 } else {
Chris@789 1106
Chris@789 1107 int xold = getXForFrame(oldPlayPointerFrame);
Chris@789 1108 update(xold - 4, 0, 9, height());
Chris@789 1109
Chris@908 1110 sv_frame_t w = getEndFrame() - getStartFrame();
Chris@789 1111 w -= w/5;
Chris@908 1112 sv_frame_t sf = (m_playPointerFrame / w) * w - w/8;
Chris@789 1113
Chris@789 1114 if (m_manager &&
Chris@789 1115 m_manager->isPlaying() &&
Chris@789 1116 m_manager->getPlaySelectionMode()) {
Chris@789 1117 MultiSelection::SelectionList selections = m_manager->getSelections();
Chris@789 1118 if (!selections.empty()) {
Chris@908 1119 sv_frame_t selectionStart = selections.begin()->getStartFrame();
Chris@808 1120 if (sf < selectionStart - w / 10) {
Chris@808 1121 sf = selectionStart - w / 10;
Chris@789 1122 }
Chris@789 1123 }
Chris@789 1124 }
Chris@127 1125
Chris@127 1126 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@789 1127 cerr << "PlaybackScrollPage: f = " << m_playPointerFrame << ", sf = " << sf << ", start frame "
Chris@789 1128 << getStartFrame() << endl;
Chris@127 1129 #endif
Chris@127 1130
Chris@789 1131 // We don't consider scrolling unless the pointer is outside
Chris@789 1132 // the central visible range already
Chris@789 1133
Chris@789 1134 int xnew = getXForFrame(m_playPointerFrame);
Chris@127 1135
Chris@127 1136 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@789 1137 cerr << "xnew = " << xnew << ", width = " << width() << endl;
Chris@127 1138 #endif
Chris@127 1139
Chris@789 1140 bool shouldScroll = (xnew > (width() * 7) / 8);
Chris@789 1141
Chris@789 1142 if (!m_followPlayIsDetached && (xnew < width() / 8)) {
Chris@789 1143 shouldScroll = true;
Chris@789 1144 }
Chris@789 1145
Chris@789 1146 if (xnew > width() / 8) {
Chris@789 1147 m_followPlayIsDetached = false;
Chris@791 1148 } else if (somethingGoingOn) {
Chris@791 1149 m_followPlayIsDetached = true;
Chris@789 1150 }
Chris@789 1151
Chris@789 1152 if (!somethingGoingOn && shouldScroll) {
Chris@908 1153 sv_frame_t offset = getFrameForX(width()/2) - getStartFrame();
Chris@908 1154 sv_frame_t newCentre = sf + offset;
Chris@789 1155 bool changed = setCentreFrame(newCentre, false);
Chris@789 1156 if (changed) {
Chris@789 1157 xold = getXForFrame(oldPlayPointerFrame);
Chris@789 1158 update(xold - 4, 0, 9, height());
Chris@789 1159 }
Chris@789 1160 }
Chris@789 1161
Chris@789 1162 update(xnew - 4, 0, 9, height());
Chris@789 1163 }
Chris@789 1164 break;
Chris@127 1165
Chris@127 1166 case PlaybackIgnore:
Chris@806 1167 if (m_playPointerFrame >= getStartFrame() &&
Chris@511 1168 m_playPointerFrame < getEndFrame()) {
Chris@127 1169 update();
Chris@127 1170 }
Chris@127 1171 break;
Chris@127 1172 }
Chris@127 1173 }
Chris@127 1174
Chris@127 1175 void
Chris@806 1176 View::viewZoomLevelChanged(View *p, int z, bool locked)
Chris@127 1177 {
Chris@244 1178 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 1179 cerr << "View[" << this << "]: viewZoomLevelChanged(" << p << ", " << z << ", " << locked << ")" << endl;
Chris@244 1180 #endif
Chris@127 1181 if (m_followZoom && p != this && locked) {
Chris@222 1182 setZoomLevel(z);
Chris@127 1183 }
Chris@127 1184 }
Chris@127 1185
Chris@127 1186 void
Chris@127 1187 View::selectionChanged()
Chris@127 1188 {
Chris@127 1189 if (m_selectionCached) {
Chris@127 1190 delete m_cache;
Chris@127 1191 m_cache = 0;
Chris@127 1192 m_selectionCached = false;
Chris@127 1193 }
Chris@127 1194 update();
Chris@127 1195 }
Chris@127 1196
Chris@908 1197 sv_frame_t
Chris@222 1198 View::getFirstVisibleFrame() const
Chris@222 1199 {
Chris@908 1200 sv_frame_t f0 = getStartFrame();
Chris@908 1201 sv_frame_t f = getModelsStartFrame();
Chris@806 1202 if (f0 < 0 || f0 < f) return f;
Chris@222 1203 return f0;
Chris@222 1204 }
Chris@222 1205
Chris@908 1206 sv_frame_t
Chris@222 1207 View::getLastVisibleFrame() const
Chris@222 1208 {
Chris@908 1209 sv_frame_t f0 = getEndFrame();
Chris@908 1210 sv_frame_t f = getModelsEndFrame();
Chris@222 1211 if (f0 > f) return f;
Chris@222 1212 return f0;
Chris@222 1213 }
Chris@222 1214
Chris@908 1215 sv_frame_t
Chris@127 1216 View::getModelsStartFrame() const
Chris@127 1217 {
Chris@127 1218 bool first = true;
Chris@908 1219 sv_frame_t startFrame = 0;
Chris@127 1220
Chris@835 1221 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
Chris@127 1222
Chris@127 1223 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
Chris@127 1224
Chris@908 1225 sv_frame_t thisStartFrame = (*i)->getModel()->getStartFrame();
Chris@127 1226
Chris@127 1227 if (first || thisStartFrame < startFrame) {
Chris@127 1228 startFrame = thisStartFrame;
Chris@127 1229 }
Chris@127 1230 first = false;
Chris@127 1231 }
Chris@127 1232 }
Chris@127 1233 return startFrame;
Chris@127 1234 }
Chris@127 1235
Chris@908 1236 sv_frame_t
Chris@127 1237 View::getModelsEndFrame() const
Chris@127 1238 {
Chris@127 1239 bool first = true;
Chris@908 1240 sv_frame_t endFrame = 0;
Chris@127 1241
Chris@835 1242 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
Chris@127 1243
Chris@127 1244 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
Chris@127 1245
Chris@908 1246 sv_frame_t thisEndFrame = (*i)->getModel()->getEndFrame();
Chris@127 1247
Chris@127 1248 if (first || thisEndFrame > endFrame) {
Chris@127 1249 endFrame = thisEndFrame;
Chris@127 1250 }
Chris@127 1251 first = false;
Chris@127 1252 }
Chris@127 1253 }
Chris@127 1254
Chris@127 1255 if (first) return getModelsStartFrame();
Chris@127 1256 return endFrame;
Chris@127 1257 }
Chris@127 1258
Chris@908 1259 sv_samplerate_t
Chris@127 1260 View::getModelsSampleRate() const
Chris@127 1261 {
Chris@127 1262 //!!! Just go for the first, for now. If we were supporting
Chris@127 1263 // multiple samplerates, we'd probably want to do frame/time
Chris@127 1264 // conversion in the model
Chris@127 1265
Chris@159 1266 //!!! nah, this wants to always return the sr of the main model!
Chris@159 1267
Chris@835 1268 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
Chris@127 1269 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
Chris@127 1270 return (*i)->getModel()->getSampleRate();
Chris@127 1271 }
Chris@127 1272 }
Chris@127 1273 return 0;
Chris@127 1274 }
Chris@127 1275
Chris@315 1276 View::ModelSet
Chris@315 1277 View::getModels()
Chris@315 1278 {
Chris@315 1279 ModelSet models;
Chris@315 1280
Chris@315 1281 for (int i = 0; i < getLayerCount(); ++i) {
Chris@315 1282
Chris@315 1283 Layer *layer = getLayer(i);
Chris@315 1284
Chris@315 1285 if (dynamic_cast<TimeRulerLayer *>(layer)) {
Chris@315 1286 continue;
Chris@315 1287 }
Chris@315 1288
Chris@315 1289 if (layer && layer->getModel()) {
Chris@315 1290 Model *model = layer->getModel();
Chris@315 1291 models.insert(model);
Chris@315 1292 }
Chris@315 1293 }
Chris@315 1294
Chris@315 1295 return models;
Chris@315 1296 }
Chris@315 1297
Chris@320 1298 Model *
Chris@320 1299 View::getAligningModel() const
Chris@301 1300 {
Chris@320 1301 if (!m_manager ||
Chris@320 1302 !m_manager->getAlignMode() ||
Chris@314 1303 !m_manager->getPlaybackModel()) {
Chris@320 1304 return 0;
Chris@314 1305 }
Chris@301 1306
Chris@320 1307 Model *anyModel = 0;
Chris@359 1308 Model *alignedModel = 0;
Chris@320 1309 Model *goodModel = 0;
Chris@301 1310
Chris@835 1311 for (LayerList::const_iterator i = m_layerStack.begin();
Chris@835 1312 i != m_layerStack.end(); ++i) {
Chris@320 1313
Chris@320 1314 Layer *layer = *i;
Chris@320 1315
Chris@320 1316 if (!layer) continue;
Chris@320 1317 if (dynamic_cast<TimeRulerLayer *>(layer)) continue;
Chris@301 1318
Chris@301 1319 Model *model = (*i)->getModel();
Chris@301 1320 if (!model) continue;
Chris@301 1321
Chris@359 1322 anyModel = model;
Chris@359 1323
Chris@320 1324 if (model->getAlignmentReference()) {
Chris@359 1325 alignedModel = model;
Chris@320 1326 if (layer->isLayerOpaque() ||
Chris@320 1327 dynamic_cast<RangeSummarisableTimeValueModel *>(model)) {
Chris@320 1328 goodModel = model;
Chris@320 1329 }
Chris@301 1330 }
Chris@320 1331 }
Chris@301 1332
Chris@320 1333 if (goodModel) return goodModel;
Chris@359 1334 else if (alignedModel) return alignedModel;
Chris@320 1335 else return anyModel;
Chris@320 1336 }
Chris@320 1337
Chris@908 1338 sv_frame_t
Chris@908 1339 View::alignFromReference(sv_frame_t f) const
Chris@320 1340 {
Chris@856 1341 if (!m_manager || !m_manager->getAlignMode()) return f;
Chris@320 1342 Model *aligningModel = getAligningModel();
Chris@320 1343 if (!aligningModel) return f;
Chris@320 1344 return aligningModel->alignFromReference(f);
Chris@320 1345 }
Chris@320 1346
Chris@908 1347 sv_frame_t
Chris@908 1348 View::alignToReference(sv_frame_t f) const
Chris@320 1349 {
Chris@321 1350 if (!m_manager->getAlignMode()) return f;
Chris@320 1351 Model *aligningModel = getAligningModel();
Chris@320 1352 if (!aligningModel) return f;
Chris@320 1353 return aligningModel->alignToReference(f);
Chris@320 1354 }
Chris@320 1355
Chris@908 1356 sv_frame_t
Chris@320 1357 View::getAlignedPlaybackFrame() const
Chris@320 1358 {
Chris@856 1359 if (!m_manager) return 0;
Chris@908 1360 sv_frame_t pf = m_manager->getPlaybackFrame();
Chris@321 1361 if (!m_manager->getAlignMode()) return pf;
Chris@321 1362
Chris@320 1363 Model *aligningModel = getAligningModel();
Chris@320 1364 if (!aligningModel) return pf;
Chris@830 1365
Chris@908 1366 sv_frame_t af = aligningModel->alignFromReference(pf);
Chris@301 1367
Chris@301 1368 return af;
Chris@301 1369 }
Chris@301 1370
Chris@127 1371 bool
Chris@127 1372 View::areLayersScrollable() const
Chris@127 1373 {
Chris@127 1374 // True iff all views are scrollable
Chris@835 1375 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
Chris@127 1376 if (!(*i)->isLayerScrollable(this)) return false;
Chris@127 1377 }
Chris@127 1378 return true;
Chris@127 1379 }
Chris@127 1380
Chris@127 1381 View::LayerList
Chris@127 1382 View::getScrollableBackLayers(bool testChanged, bool &changed) const
Chris@127 1383 {
Chris@127 1384 changed = false;
Chris@127 1385
Chris@127 1386 // We want a list of all the scrollable layers that are behind the
Chris@127 1387 // backmost non-scrollable layer.
Chris@127 1388
Chris@127 1389 LayerList scrollables;
Chris@127 1390 bool metUnscrollable = false;
Chris@127 1391
Chris@835 1392 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
Chris@587 1393 // SVDEBUG << "View::getScrollableBackLayers: calling isLayerDormant on layer " << *i << endl;
Chris@682 1394 // cerr << "(name is " << (*i)->objectName() << ")"
Chris@682 1395 // << endl;
Chris@587 1396 // SVDEBUG << "View::getScrollableBackLayers: I am " << this << endl;
Chris@127 1397 if ((*i)->isLayerDormant(this)) continue;
Chris@127 1398 if ((*i)->isLayerOpaque()) {
Chris@127 1399 // You can't see anything behind an opaque layer!
Chris@127 1400 scrollables.clear();
Chris@127 1401 if (metUnscrollable) break;
Chris@127 1402 }
Chris@127 1403 if (!metUnscrollable && (*i)->isLayerScrollable(this)) {
Chris@127 1404 scrollables.push_back(*i);
Chris@127 1405 } else {
Chris@127 1406 metUnscrollable = true;
Chris@127 1407 }
Chris@127 1408 }
Chris@127 1409
Chris@127 1410 if (testChanged && scrollables != m_lastScrollableBackLayers) {
Chris@127 1411 m_lastScrollableBackLayers = scrollables;
Chris@127 1412 changed = true;
Chris@127 1413 }
Chris@127 1414 return scrollables;
Chris@127 1415 }
Chris@127 1416
Chris@127 1417 View::LayerList
Chris@127 1418 View::getNonScrollableFrontLayers(bool testChanged, bool &changed) const
Chris@127 1419 {
Chris@127 1420 changed = false;
Chris@127 1421 LayerList nonScrollables;
Chris@127 1422
Chris@127 1423 // Everything in front of the first non-scrollable from the back
Chris@127 1424 // should also be considered non-scrollable
Chris@127 1425
Chris@127 1426 bool started = false;
Chris@127 1427
Chris@835 1428 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
Chris@127 1429 if ((*i)->isLayerDormant(this)) continue;
Chris@127 1430 if (!started && (*i)->isLayerScrollable(this)) {
Chris@127 1431 continue;
Chris@127 1432 }
Chris@127 1433 started = true;
Chris@127 1434 if ((*i)->isLayerOpaque()) {
Chris@127 1435 // You can't see anything behind an opaque layer!
Chris@127 1436 nonScrollables.clear();
Chris@127 1437 }
Chris@127 1438 nonScrollables.push_back(*i);
Chris@127 1439 }
Chris@127 1440
Chris@127 1441 if (testChanged && nonScrollables != m_lastNonScrollableBackLayers) {
Chris@127 1442 m_lastNonScrollableBackLayers = nonScrollables;
Chris@127 1443 changed = true;
Chris@127 1444 }
Chris@127 1445
Chris@127 1446 return nonScrollables;
Chris@127 1447 }
Chris@127 1448
Chris@806 1449 int
Chris@806 1450 View::getZoomConstraintBlockSize(int blockSize,
Chris@127 1451 ZoomConstraint::RoundingDirection dir)
Chris@127 1452 const
Chris@127 1453 {
Chris@806 1454 int candidate = blockSize;
Chris@127 1455 bool haveCandidate = false;
Chris@127 1456
Chris@127 1457 PowerOfSqrtTwoZoomConstraint defaultZoomConstraint;
Chris@127 1458
Chris@835 1459 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
Chris@127 1460
Chris@127 1461 const ZoomConstraint *zoomConstraint = (*i)->getZoomConstraint();
Chris@127 1462 if (!zoomConstraint) zoomConstraint = &defaultZoomConstraint;
Chris@127 1463
Chris@806 1464 int thisBlockSize =
Chris@127 1465 zoomConstraint->getNearestBlockSize(blockSize, dir);
Chris@127 1466
Chris@127 1467 // Go for the block size that's furthest from the one
Chris@127 1468 // passed in. Most of the time, that's what we want.
Chris@127 1469 if (!haveCandidate ||
Chris@127 1470 (thisBlockSize > blockSize && thisBlockSize > candidate) ||
Chris@127 1471 (thisBlockSize < blockSize && thisBlockSize < candidate)) {
Chris@127 1472 candidate = thisBlockSize;
Chris@127 1473 haveCandidate = true;
Chris@127 1474 }
Chris@127 1475 }
Chris@127 1476
Chris@127 1477 return candidate;
Chris@127 1478 }
Chris@127 1479
Chris@183 1480 bool
Chris@183 1481 View::areLayerColoursSignificant() const
Chris@183 1482 {
Chris@835 1483 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
Chris@287 1484 if ((*i)->getLayerColourSignificance() ==
Chris@287 1485 Layer::ColourHasMeaningfulValue) return true;
Chris@183 1486 if ((*i)->isLayerOpaque()) break;
Chris@183 1487 }
Chris@183 1488 return false;
Chris@183 1489 }
Chris@183 1490
Chris@217 1491 bool
Chris@217 1492 View::hasTopLayerTimeXAxis() const
Chris@217 1493 {
Chris@835 1494 LayerList::const_iterator i = m_layerStack.end();
Chris@835 1495 if (i == m_layerStack.begin()) return false;
Chris@217 1496 --i;
Chris@217 1497 return (*i)->hasTimeXAxis();
Chris@217 1498 }
Chris@217 1499
Chris@127 1500 void
Chris@127 1501 View::zoom(bool in)
Chris@127 1502 {
Chris@127 1503 int newZoomLevel = m_zoomLevel;
Chris@127 1504
Chris@127 1505 if (in) {
Chris@127 1506 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
Chris@127 1507 ZoomConstraint::RoundDown);
Chris@127 1508 } else {
Chris@127 1509 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
Chris@127 1510 ZoomConstraint::RoundUp);
Chris@127 1511 }
Chris@127 1512
Chris@127 1513 if (newZoomLevel != m_zoomLevel) {
Chris@127 1514 setZoomLevel(newZoomLevel);
Chris@127 1515 }
Chris@127 1516 }
Chris@127 1517
Chris@127 1518 void
Chris@510 1519 View::scroll(bool right, bool lots, bool e)
Chris@127 1520 {
Chris@908 1521 sv_frame_t delta;
Chris@127 1522 if (lots) {
Chris@127 1523 delta = (getEndFrame() - getStartFrame()) / 2;
Chris@127 1524 } else {
Chris@127 1525 delta = (getEndFrame() - getStartFrame()) / 20;
Chris@127 1526 }
Chris@127 1527 if (right) delta = -delta;
Chris@127 1528
Chris@908 1529 if (m_centreFrame < delta) {
Chris@510 1530 setCentreFrame(0, e);
Chris@908 1531 } else if (m_centreFrame - delta >= getModelsEndFrame()) {
Chris@510 1532 setCentreFrame(getModelsEndFrame(), e);
Chris@127 1533 } else {
Chris@510 1534 setCentreFrame(m_centreFrame - delta, e);
Chris@127 1535 }
Chris@127 1536 }
Chris@127 1537
Chris@127 1538 void
Chris@797 1539 View::cancelClicked()
Chris@797 1540 {
Chris@797 1541 QPushButton *cancel = qobject_cast<QPushButton *>(sender());
Chris@797 1542 if (!cancel) return;
Chris@797 1543
Chris@797 1544 for (ProgressMap::iterator i = m_progressBars.begin();
Chris@797 1545 i != m_progressBars.end(); ++i) {
Chris@797 1546
Chris@797 1547 if (i->second.cancel == cancel) {
Chris@797 1548
Chris@797 1549 Layer *layer = i->first;
Chris@797 1550 Model *model = layer->getModel();
Chris@797 1551
Chris@797 1552 if (model) model->abandon();
Chris@797 1553 }
Chris@797 1554 }
Chris@797 1555 }
Chris@797 1556
Chris@797 1557 void
Chris@127 1558 View::checkProgress(void *object)
Chris@127 1559 {
Chris@127 1560 if (!m_showProgress) return;
Chris@127 1561
Chris@127 1562 int ph = height();
Chris@127 1563
Chris@555 1564 for (ProgressMap::iterator i = m_progressBars.begin();
Chris@127 1565 i != m_progressBars.end(); ++i) {
Chris@127 1566
Chris@555 1567 QProgressBar *pb = i->second.bar;
Chris@797 1568 QPushButton *cancel = i->second.cancel;
Chris@555 1569
Chris@127 1570 if (i->first == object) {
Chris@127 1571
Chris@555 1572 // The timer is used to test for stalls. If the progress
Chris@555 1573 // bar does not get updated for some length of time, the
Chris@555 1574 // timer prompts it to go back into "indeterminate" mode
Chris@555 1575 QTimer *timer = i->second.checkTimer;
Chris@555 1576
Chris@127 1577 int completion = i->first->getCompletion(this);
Chris@301 1578 QString text = i->first->getPropertyContainerName();
Chris@583 1579 QString error = i->first->getError(this);
Chris@583 1580
Chris@583 1581 if (error != "" && error != m_lastError) {
Chris@583 1582 QMessageBox::critical(this, tr("Layer rendering error"), error);
Chris@583 1583 m_lastError = error;
Chris@583 1584 }
Chris@301 1585
Chris@387 1586 Model *model = i->first->getModel();
Chris@387 1587 RangeSummarisableTimeValueModel *wfm =
Chris@387 1588 dynamic_cast<RangeSummarisableTimeValueModel *>(model);
Chris@387 1589
Chris@388 1590 if (completion > 0) {
Chris@555 1591 pb->setMaximum(100); // was 0, for indeterminate start
Chris@388 1592 }
Chris@388 1593
Chris@301 1594 if (completion >= 100) {
Chris@301 1595
Chris@301 1596 //!!!
Chris@326 1597 if (wfm ||
Chris@776 1598 (model &&
Chris@776 1599 (wfm = dynamic_cast<RangeSummarisableTimeValueModel *>
Chris@776 1600 (model->getSourceModel())))) {
Chris@301 1601 completion = wfm->getAlignmentCompletion();
Chris@587 1602 // SVDEBUG << "View::checkProgress: Alignment completion = " << completion << endl;
Chris@301 1603 if (completion < 100) {
Chris@301 1604 text = tr("Alignment");
Chris@301 1605 }
Chris@301 1606 }
Chris@387 1607
Chris@387 1608 } else if (wfm) {
Chris@387 1609 update(); // ensure duration &c gets updated
Chris@301 1610 }
Chris@127 1611
Chris@127 1612 if (completion >= 100) {
Chris@127 1613
Chris@555 1614 pb->hide();
Chris@797 1615 cancel->hide();
Chris@555 1616 timer->stop();
Chris@127 1617
Chris@127 1618 } else {
Chris@127 1619
Chris@682 1620 // cerr << "progress = " << completion << endl;
Chris@555 1621
Chris@555 1622 if (!pb->isVisible()) {
Chris@555 1623 i->second.lastCheck = 0;
Chris@555 1624 timer->setInterval(2000);
Chris@555 1625 timer->start();
Chris@555 1626 }
Chris@555 1627
Chris@797 1628 cancel->move(0, ph - pb->height()/2 - 10);
Chris@797 1629 cancel->show();
Chris@797 1630
Chris@555 1631 pb->setValue(completion);
Chris@797 1632 pb->move(20, ph - pb->height());
Chris@555 1633
Chris@555 1634 pb->show();
Chris@555 1635 pb->update();
Chris@555 1636
Chris@555 1637 ph -= pb->height();
Chris@127 1638 }
Chris@127 1639 } else {
Chris@555 1640 if (pb->isVisible()) {
Chris@555 1641 ph -= pb->height();
Chris@127 1642 }
Chris@127 1643 }
Chris@127 1644 }
Chris@127 1645 }
Chris@127 1646
Chris@555 1647 void
Chris@555 1648 View::progressCheckStalledTimerElapsed()
Chris@555 1649 {
Chris@555 1650 QObject *s = sender();
Chris@555 1651 QTimer *t = qobject_cast<QTimer *>(s);
Chris@555 1652 if (!t) return;
Chris@555 1653 for (ProgressMap::iterator i = m_progressBars.begin();
Chris@555 1654 i != m_progressBars.end(); ++i) {
Chris@555 1655 if (i->second.checkTimer == t) {
Chris@555 1656 int value = i->second.bar->value();
Chris@555 1657 if (value > 0 && value == i->second.lastCheck) {
Chris@555 1658 i->second.bar->setMaximum(0); // indeterminate
Chris@555 1659 }
Chris@555 1660 i->second.lastCheck = value;
Chris@555 1661 return;
Chris@555 1662 }
Chris@555 1663 }
Chris@555 1664 }
Chris@555 1665
Chris@384 1666 int
Chris@384 1667 View::getProgressBarWidth() const
Chris@384 1668 {
Chris@384 1669 for (ProgressMap::const_iterator i = m_progressBars.begin();
Chris@384 1670 i != m_progressBars.end(); ++i) {
Chris@555 1671 if (i->second.bar && i->second.bar->isVisible()) {
Chris@555 1672 return i->second.bar->width();
Chris@555 1673 }
Chris@384 1674 }
Chris@384 1675
Chris@384 1676 return 0;
Chris@384 1677 }
Chris@384 1678
Chris@127 1679 void
Chris@339 1680 View::setPaintFont(QPainter &paint)
Chris@339 1681 {
Chris@955 1682 int scaleFactor = 1;
Chris@956 1683 int dpratio = effectiveDevicePixelRatio();
Chris@955 1684 if (dpratio > 1) {
Chris@955 1685 QPaintDevice *dev = paint.device();
Chris@955 1686 if (dynamic_cast<QPixmap *>(dev) || dynamic_cast<QImage *>(dev)) {
Chris@955 1687 scaleFactor = dpratio;
Chris@955 1688 }
Chris@955 1689 }
Chris@955 1690
Chris@339 1691 QFont font(paint.font());
Chris@955 1692 font.setPointSize(Preferences::getInstance()->getViewFontSize()
Chris@955 1693 * scaleFactor);
Chris@339 1694 paint.setFont(font);
Chris@339 1695 }
Chris@339 1696
Chris@915 1697 QRect
Chris@915 1698 View::getPaintRect() const
Chris@915 1699 {
Chris@919 1700 return rect();
Chris@915 1701 }
Chris@915 1702
Chris@339 1703 void
Chris@127 1704 View::paintEvent(QPaintEvent *e)
Chris@127 1705 {
Chris@127 1706 // Profiler prof("View::paintEvent", false);
Chris@800 1707 // cerr << "View::paintEvent: centre frame is " << m_centreFrame << endl;
matthiasm@785 1708
Chris@835 1709 if (m_layerStack.empty()) {
Chris@127 1710 QFrame::paintEvent(e);
Chris@127 1711 return;
Chris@127 1712 }
Chris@127 1713
Chris@127 1714 // ensure our constraints are met
Chris@137 1715
Chris@137 1716 /*!!! Should we do this only if we have layers that can't support other
Chris@137 1717 zoom levels?
Chris@137 1718
Chris@127 1719 m_zoomLevel = getZoomConstraintBlockSize(m_zoomLevel,
Chris@127 1720 ZoomConstraint::RoundUp);
Chris@137 1721 */
Chris@127 1722
Chris@127 1723 QPainter paint;
Chris@127 1724 bool repaintCache = false;
Chris@127 1725 bool paintedCacheRect = false;
Chris@127 1726
Chris@127 1727 QRect cacheRect(rect());
Chris@127 1728
Chris@127 1729 if (e) {
Chris@127 1730 cacheRect &= e->rect();
Chris@127 1731 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 1732 cerr << "paint rect " << cacheRect.width() << "x" << cacheRect.height()
Chris@682 1733 << ", my rect " << width() << "x" << height() << endl;
Chris@127 1734 #endif
Chris@127 1735 }
Chris@127 1736
Chris@127 1737 QRect nonCacheRect(cacheRect);
Chris@127 1738
Chris@956 1739 int dpratio = effectiveDevicePixelRatio();
Chris@953 1740
Chris@127 1741 // If not all layers are scrollable, but some of the back layers
Chris@127 1742 // are, we should store only those in the cache.
Chris@127 1743
Chris@127 1744 bool layersChanged = false;
Chris@127 1745 LayerList scrollables = getScrollableBackLayers(true, layersChanged);
Chris@127 1746 LayerList nonScrollables = getNonScrollableFrontLayers(true, layersChanged);
Chris@127 1747 bool selectionCacheable = nonScrollables.empty();
Chris@127 1748 bool haveSelections = m_manager && !m_manager->getSelections().empty();
Chris@127 1749
Chris@127 1750 // If all the non-scrollable layers are non-opaque, then we draw
Chris@127 1751 // the selection rectangle behind them and cache it. If any are
Chris@953 1752 // opaque, however, or if our device-pixel ratio is not 1 (so we
Chris@953 1753 // need to paint direct to the widget), then we can't cache.
Chris@127 1754 //
Chris@953 1755 if (dpratio == 1) {
Chris@953 1756
Chris@953 1757 if (!selectionCacheable) {
Chris@953 1758 selectionCacheable = true;
Chris@953 1759 for (LayerList::const_iterator i = nonScrollables.begin();
Chris@953 1760 i != nonScrollables.end(); ++i) {
Chris@953 1761 if ((*i)->isLayerOpaque()) {
Chris@953 1762 selectionCacheable = false;
Chris@953 1763 break;
Chris@953 1764 }
Chris@953 1765 }
Chris@953 1766 }
Chris@953 1767
Chris@953 1768 if (selectionCacheable) {
Chris@953 1769 QPoint localPos;
Chris@953 1770 bool closeToLeft, closeToRight;
Chris@953 1771 if (shouldIlluminateLocalSelection
Chris@953 1772 (localPos, closeToLeft, closeToRight)) {
Chris@953 1773 selectionCacheable = false;
Chris@953 1774 }
Chris@953 1775 }
Chris@953 1776
Chris@953 1777 } else {
Chris@953 1778
Chris@953 1779 selectionCacheable = false;
Chris@127 1780 }
Chris@127 1781
Chris@127 1782 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 1783 cerr << "View(" << this << ")::paintEvent: have " << scrollables.size()
Chris@127 1784 << " scrollable back layers and " << nonScrollables.size()
Chris@682 1785 << " non-scrollable front layers" << endl;
Chris@682 1786 cerr << "haveSelections " << haveSelections << ", selectionCacheable "
Chris@682 1787 << selectionCacheable << ", m_selectionCached " << m_selectionCached << endl;
Chris@127 1788 #endif
Chris@127 1789
Chris@127 1790 if (layersChanged || scrollables.empty() ||
Chris@127 1791 (haveSelections && (selectionCacheable != m_selectionCached))) {
Chris@127 1792 delete m_cache;
Chris@127 1793 m_cache = 0;
Chris@127 1794 m_selectionCached = false;
Chris@127 1795 }
Chris@127 1796
Chris@952 1797 QSize scaledCacheSize(scaledSize(size(), dpratio));
Chris@952 1798 QRect scaledCacheRect(scaledRect(cacheRect, dpratio));
Chris@952 1799
Chris@952 1800 if (!m_buffer || scaledCacheSize != m_buffer->size()) {
Chris@952 1801 delete m_buffer;
Chris@952 1802 m_buffer = new QPixmap(scaledCacheSize);
Chris@952 1803 }
Chris@952 1804
Chris@127 1805 if (!scrollables.empty()) {
Chris@244 1806
Chris@244 1807 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 1808 cerr << "View(" << this << "): cache " << m_cache << ", cache zoom "
Chris@682 1809 << m_cacheZoomLevel << ", zoom " << m_zoomLevel << endl;
Chris@244 1810 #endif
Chris@244 1811
Chris@127 1812 if (!m_cache ||
Chris@127 1813 m_cacheZoomLevel != m_zoomLevel ||
Chris@914 1814 scaledCacheSize != m_cache->size()) {
Chris@127 1815
Chris@127 1816 // cache is not valid
Chris@127 1817
Chris@127 1818 if (cacheRect.width() < width()/10) {
Chris@244 1819 delete m_cache;
Chris@244 1820 m_cache = 0;
Chris@127 1821 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 1822 cerr << "View(" << this << ")::paintEvent: small repaint, not bothering to recreate cache" << endl;
Chris@127 1823 #endif
Chris@127 1824 } else {
Chris@127 1825 delete m_cache;
Chris@914 1826 m_cache = new QPixmap(scaledCacheSize);
Chris@127 1827 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 1828 cerr << "View(" << this << ")::paintEvent: recreated cache" << endl;
Chris@127 1829 #endif
Chris@127 1830 cacheRect = rect();
Chris@127 1831 repaintCache = true;
Chris@127 1832 }
Chris@127 1833
Chris@127 1834 } else if (m_cacheCentreFrame != m_centreFrame) {
Chris@127 1835
Chris@806 1836 int dx =
Chris@127 1837 getXForFrame(m_cacheCentreFrame) -
Chris@127 1838 getXForFrame(m_centreFrame);
Chris@127 1839
Chris@127 1840 if (dx > -width() && dx < width()) {
Chris@127 1841 static QPixmap *tmpPixmap = 0;
Chris@914 1842 if (!tmpPixmap || tmpPixmap->size() != scaledCacheSize) {
Chris@127 1843 delete tmpPixmap;
Chris@914 1844 tmpPixmap = new QPixmap(scaledCacheSize);
Chris@127 1845 }
Chris@127 1846 paint.begin(tmpPixmap);
Chris@127 1847 paint.drawPixmap(0, 0, *m_cache);
Chris@127 1848 paint.end();
Chris@127 1849 paint.begin(m_cache);
Chris@127 1850 paint.drawPixmap(dx, 0, *tmpPixmap);
Chris@127 1851 paint.end();
Chris@127 1852 if (dx < 0) {
Chris@127 1853 cacheRect = QRect(width() + dx, 0, -dx, height());
Chris@127 1854 } else {
Chris@127 1855 cacheRect = QRect(0, 0, dx, height());
Chris@127 1856 }
Chris@127 1857 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 1858 cerr << "View(" << this << ")::paintEvent: scrolled cache by " << dx << endl;
Chris@127 1859 #endif
Chris@127 1860 } else {
Chris@127 1861 cacheRect = rect();
Chris@127 1862 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 1863 cerr << "View(" << this << ")::paintEvent: scrolling too far" << endl;
Chris@127 1864 #endif
Chris@127 1865 }
Chris@127 1866 repaintCache = true;
Chris@127 1867
Chris@127 1868 } else {
Chris@127 1869 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 1870 cerr << "View(" << this << ")::paintEvent: cache is good" << endl;
Chris@127 1871 #endif
Chris@952 1872 paint.begin(m_buffer);
Chris@952 1873 paint.drawPixmap(scaledCacheRect, *m_cache, scaledCacheRect);
Chris@127 1874 paint.end();
Chris@127 1875 QFrame::paintEvent(e);
Chris@127 1876 paintedCacheRect = true;
Chris@127 1877 }
Chris@127 1878
Chris@127 1879 m_cacheCentreFrame = m_centreFrame;
Chris@127 1880 m_cacheZoomLevel = m_zoomLevel;
Chris@127 1881 }
Chris@127 1882
Chris@127 1883 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@682 1884 // cerr << "View(" << this << ")::paintEvent: cacheRect " << cacheRect << ", nonCacheRect " << (nonCacheRect | cacheRect) << ", repaintCache " << repaintCache << ", paintedCacheRect " << paintedCacheRect << endl;
Chris@127 1885 #endif
Chris@127 1886
Chris@127 1887 // Scrollable (cacheable) items first
Chris@127 1888
Chris@919 1889 ViewProxy proxy(this, dpratio);
Chris@919 1890
Chris@127 1891 if (!paintedCacheRect) {
Chris@127 1892
Chris@914 1893 QRect rectToPaint;
Chris@914 1894
Chris@914 1895 if (repaintCache) {
Chris@914 1896 paint.begin(m_cache);
Chris@914 1897 rectToPaint = scaledCacheRect;
Chris@914 1898 } else {
Chris@952 1899 paint.begin(m_buffer);
Chris@952 1900 rectToPaint = scaledCacheRect;
Chris@914 1901 }
Chris@914 1902
Chris@339 1903 setPaintFont(paint);
Chris@914 1904 paint.setClipRect(rectToPaint);
Chris@287 1905
Chris@287 1906 paint.setPen(getBackground());
Chris@287 1907 paint.setBrush(getBackground());
Chris@914 1908 paint.drawRect(rectToPaint);
Chris@127 1909
Chris@287 1910 paint.setPen(getForeground());
Chris@127 1911 paint.setBrush(Qt::NoBrush);
Chris@127 1912
Chris@127 1913 for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) {
Chris@127 1914 paint.setRenderHint(QPainter::Antialiasing, false);
Chris@127 1915 paint.save();
Chris@951 1916 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@951 1917 cerr << "Painting scrollable layer " << *i << " using proxy with repaintCache = " << repaintCache << ", dpratio = " << dpratio << ", rectToPaint = " << rectToPaint.x() << "," << rectToPaint.y() << " " << rectToPaint.width() << "x" << rectToPaint.height() << endl;
Chris@951 1918 #endif
Chris@919 1919 (*i)->paint(&proxy, paint, rectToPaint);
Chris@127 1920 paint.restore();
Chris@127 1921 }
Chris@127 1922
Chris@127 1923 if (haveSelections && selectionCacheable) {
Chris@127 1924 drawSelections(paint);
Chris@127 1925 m_selectionCached = repaintCache;
Chris@127 1926 }
Chris@127 1927
Chris@127 1928 paint.end();
Chris@127 1929
Chris@127 1930 if (repaintCache) {
Chris@127 1931 cacheRect |= (e ? e->rect() : rect());
Chris@952 1932 scaledCacheRect = scaledRect(cacheRect, dpratio);
Chris@952 1933 paint.begin(m_buffer);
Chris@952 1934 paint.drawPixmap(scaledCacheRect, *m_cache, scaledCacheRect);
Chris@127 1935 paint.end();
Chris@127 1936 }
Chris@127 1937 }
Chris@127 1938
Chris@127 1939 // Now non-cacheable items. We always need to redraw the
Chris@127 1940 // non-cacheable items across at least the area we drew of the
Chris@127 1941 // cacheable items.
Chris@127 1942
Chris@127 1943 nonCacheRect |= cacheRect;
Chris@127 1944
Chris@952 1945 QRect scaledNonCacheRect = scaledRect(nonCacheRect, dpratio);
Chris@952 1946
Chris@952 1947 paint.begin(m_buffer);
Chris@952 1948 paint.setClipRect(scaledNonCacheRect);
Chris@339 1949 setPaintFont(paint);
Chris@127 1950 if (scrollables.empty()) {
Chris@287 1951 paint.setPen(getBackground());
Chris@287 1952 paint.setBrush(getBackground());
Chris@952 1953 paint.drawRect(scaledNonCacheRect);
Chris@127 1954 }
Chris@127 1955
Chris@287 1956 paint.setPen(getForeground());
Chris@127 1957 paint.setBrush(Qt::NoBrush);
Chris@127 1958
Chris@127 1959 for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) {
Chris@127 1960 // Profiler profiler2("View::paintEvent non-cacheable");
Chris@951 1961 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@951 1962 cerr << "Painting non-scrollable layer " << *i << " without proxy with repaintCache = " << repaintCache << ", dpratio = " << dpratio << ", rectToPaint = " << nonCacheRect.x() << "," << nonCacheRect.y() << " " << nonCacheRect.width() << "x" << nonCacheRect.height() << endl;
Chris@951 1963 #endif
Chris@952 1964 (*i)->paint(&proxy, paint, scaledNonCacheRect);
Chris@127 1965 }
Chris@127 1966
Chris@127 1967 paint.end();
Chris@953 1968
Chris@953 1969 paint.begin(this);
Chris@953 1970 QRect finalPaintRect = e ? e->rect() : rect();
Chris@953 1971 paint.drawPixmap(finalPaintRect, *m_buffer, scaledRect(finalPaintRect, dpratio));
Chris@953 1972 paint.end();
Chris@953 1973
Chris@953 1974 paint.begin(this);
Chris@339 1975 setPaintFont(paint);
Chris@953 1976 if (e) paint.setClipRect(e->rect());
Chris@127 1977 if (!m_selectionCached) {
Chris@127 1978 drawSelections(paint);
Chris@127 1979 }
Chris@127 1980 paint.end();
Chris@127 1981
Chris@211 1982 bool showPlayPointer = true;
Chris@211 1983 if (m_followPlay == PlaybackScrollContinuous) {
Chris@211 1984 showPlayPointer = false;
Chris@806 1985 } else if (m_playPointerFrame <= getStartFrame() ||
Chris@211 1986 m_playPointerFrame >= getEndFrame()) {
Chris@211 1987 showPlayPointer = false;
Chris@211 1988 } else if (m_manager && !m_manager->isPlaying()) {
Chris@211 1989 if (m_playPointerFrame == getCentreFrame() &&
Chris@787 1990 m_manager->shouldShowCentreLine() &&
Chris@211 1991 m_followPlay != PlaybackIgnore) {
Chris@787 1992 // Don't show the play pointer when it is redundant with
Chris@787 1993 // the centre line
Chris@211 1994 showPlayPointer = false;
Chris@211 1995 }
Chris@211 1996 }
Chris@952 1997
Chris@211 1998 if (showPlayPointer) {
Chris@127 1999
Chris@127 2000 paint.begin(this);
Chris@127 2001
Chris@211 2002 int playx = getXForFrame(m_playPointerFrame);
Chris@211 2003
Chris@287 2004 paint.setPen(getForeground());
Chris@211 2005 paint.drawLine(playx - 1, 0, playx - 1, height() - 1);
Chris@211 2006 paint.drawLine(playx + 1, 0, playx + 1, height() - 1);
Chris@211 2007 paint.drawPoint(playx, 0);
Chris@211 2008 paint.drawPoint(playx, height() - 1);
Chris@287 2009 paint.setPen(getBackground());
Chris@211 2010 paint.drawLine(playx, 1, playx, height() - 2);
Chris@127 2011
Chris@127 2012 paint.end();
Chris@127 2013 }
Chris@127 2014
Chris@127 2015 QFrame::paintEvent(e);
Chris@127 2016 }
Chris@127 2017
Chris@127 2018 void
Chris@127 2019 View::drawSelections(QPainter &paint)
Chris@127 2020 {
Chris@217 2021 if (!hasTopLayerTimeXAxis()) return;
Chris@217 2022
Chris@127 2023 MultiSelection::SelectionList selections;
Chris@127 2024
Chris@127 2025 if (m_manager) {
Chris@127 2026 selections = m_manager->getSelections();
Chris@127 2027 if (m_manager->haveInProgressSelection()) {
Chris@127 2028 bool exclusive;
Chris@127 2029 Selection inProgressSelection =
Chris@127 2030 m_manager->getInProgressSelection(exclusive);
Chris@127 2031 if (exclusive) selections.clear();
Chris@127 2032 selections.insert(inProgressSelection);
Chris@127 2033 }
Chris@127 2034 }
Chris@127 2035
Chris@127 2036 paint.save();
Chris@183 2037
Chris@183 2038 bool translucent = !areLayerColoursSignificant();
Chris@183 2039
Chris@183 2040 if (translucent) {
Chris@183 2041 paint.setBrush(QColor(150, 150, 255, 80));
Chris@183 2042 } else {
Chris@183 2043 paint.setBrush(Qt::NoBrush);
Chris@183 2044 }
Chris@127 2045
Chris@908 2046 sv_samplerate_t sampleRate = getModelsSampleRate();
Chris@127 2047
Chris@127 2048 QPoint localPos;
Chris@908 2049 sv_frame_t illuminateFrame = -1;
Chris@127 2050 bool closeToLeft, closeToRight;
Chris@127 2051
Chris@127 2052 if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) {
Chris@127 2053 illuminateFrame = getFrameForX(localPos.x());
Chris@127 2054 }
Chris@127 2055
Chris@127 2056 const QFontMetrics &metrics = paint.fontMetrics();
Chris@127 2057
Chris@127 2058 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@127 2059 i != selections.end(); ++i) {
Chris@127 2060
Chris@333 2061 int p0 = getXForFrame(alignFromReference(i->getStartFrame()));
Chris@333 2062 int p1 = getXForFrame(alignFromReference(i->getEndFrame()));
Chris@127 2063
Chris@127 2064 if (p1 < 0 || p0 > width()) continue;
Chris@127 2065
Chris@127 2066 #ifdef DEBUG_VIEW_WIDGET_PAINT
Chris@587 2067 SVDEBUG << "View::drawSelections: " << p0 << ",-1 [" << (p1-p0) << "x" << (height()+1) << "]" << endl;
Chris@127 2068 #endif
Chris@127 2069
Chris@127 2070 bool illuminateThis =
Chris@127 2071 (illuminateFrame >= 0 && i->contains(illuminateFrame));
Chris@127 2072
Chris@127 2073 paint.setPen(QColor(150, 150, 255));
Chris@183 2074
Chris@183 2075 if (translucent && shouldLabelSelections()) {
Chris@183 2076 paint.drawRect(p0, -1, p1 - p0, height() + 1);
Chris@183 2077 } else {
Chris@183 2078 // Make the top & bottom lines of the box visible if we
Chris@183 2079 // are lacking some of the other visual cues. There's no
Chris@183 2080 // particular logic to this, it's just a question of what
Chris@183 2081 // I happen to think looks nice.
Chris@183 2082 paint.drawRect(p0, 0, p1 - p0, height() - 1);
Chris@183 2083 }
Chris@127 2084
Chris@127 2085 if (illuminateThis) {
Chris@127 2086 paint.save();
Chris@287 2087 paint.setPen(QPen(getForeground(), 2));
Chris@127 2088 if (closeToLeft) {
Chris@127 2089 paint.drawLine(p0, 1, p1, 1);
Chris@127 2090 paint.drawLine(p0, 0, p0, height());
Chris@127 2091 paint.drawLine(p0, height() - 1, p1, height() - 1);
Chris@127 2092 } else if (closeToRight) {
Chris@127 2093 paint.drawLine(p0, 1, p1, 1);
Chris@127 2094 paint.drawLine(p1, 0, p1, height());
Chris@127 2095 paint.drawLine(p0, height() - 1, p1, height() - 1);
Chris@127 2096 } else {
Chris@127 2097 paint.setBrush(Qt::NoBrush);
Chris@127 2098 paint.drawRect(p0, 1, p1 - p0, height() - 2);
Chris@127 2099 }
Chris@127 2100 paint.restore();
Chris@127 2101 }
Chris@127 2102
Chris@127 2103 if (sampleRate && shouldLabelSelections() && m_manager &&
Chris@189 2104 m_manager->shouldShowSelectionExtents()) {
Chris@127 2105
Chris@127 2106 QString startText = QString("%1 / %2")
Chris@127 2107 .arg(QString::fromStdString
Chris@127 2108 (RealTime::frame2RealTime
Chris@127 2109 (i->getStartFrame(), sampleRate).toText(true)))
Chris@127 2110 .arg(i->getStartFrame());
Chris@127 2111
Chris@127 2112 QString endText = QString(" %1 / %2")
Chris@127 2113 .arg(QString::fromStdString
Chris@127 2114 (RealTime::frame2RealTime
Chris@127 2115 (i->getEndFrame(), sampleRate).toText(true)))
Chris@127 2116 .arg(i->getEndFrame());
Chris@127 2117
Chris@127 2118 QString durationText = QString("(%1 / %2) ")
Chris@127 2119 .arg(QString::fromStdString
Chris@127 2120 (RealTime::frame2RealTime
Chris@127 2121 (i->getEndFrame() - i->getStartFrame(), sampleRate)
Chris@127 2122 .toText(true)))
Chris@127 2123 .arg(i->getEndFrame() - i->getStartFrame());
Chris@127 2124
Chris@127 2125 int sw = metrics.width(startText),
Chris@127 2126 ew = metrics.width(endText),
Chris@127 2127 dw = metrics.width(durationText);
Chris@127 2128
Chris@127 2129 int sy = metrics.ascent() + metrics.height() + 4;
Chris@127 2130 int ey = sy;
Chris@127 2131 int dy = sy + metrics.height();
Chris@127 2132
Chris@127 2133 int sx = p0 + 2;
Chris@127 2134 int ex = sx;
Chris@127 2135 int dx = sx;
Chris@127 2136
Chris@501 2137 bool durationBothEnds = true;
Chris@501 2138
Chris@127 2139 if (sw + ew > (p1 - p0)) {
Chris@127 2140 ey += metrics.height();
Chris@127 2141 dy += metrics.height();
Chris@501 2142 durationBothEnds = false;
Chris@127 2143 }
Chris@127 2144
Chris@127 2145 if (ew < (p1 - p0)) {
Chris@127 2146 ex = p1 - 2 - ew;
Chris@127 2147 }
Chris@127 2148
Chris@127 2149 if (dw < (p1 - p0)) {
Chris@127 2150 dx = p1 - 2 - dw;
Chris@127 2151 }
Chris@127 2152
Chris@127 2153 paint.drawText(sx, sy, startText);
Chris@127 2154 paint.drawText(ex, ey, endText);
Chris@127 2155 paint.drawText(dx, dy, durationText);
Chris@501 2156 if (durationBothEnds) {
Chris@501 2157 paint.drawText(sx, dy, durationText);
Chris@501 2158 }
Chris@127 2159 }
Chris@127 2160 }
Chris@127 2161
Chris@127 2162 paint.restore();
Chris@127 2163 }
Chris@127 2164
Chris@267 2165 void
Chris@270 2166 View::drawMeasurementRect(QPainter &paint, const Layer *topLayer, QRect r,
Chris@270 2167 bool focus) const
Chris@267 2168 {
Chris@587 2169 // SVDEBUG << "View::drawMeasurementRect(" << r.x() << "," << r.y() << " "
Chris@585 2170 // << r.width() << "x" << r.height() << ")" << endl;
Chris@268 2171
Chris@267 2172 if (r.x() + r.width() < 0 || r.x() >= width()) return;
Chris@267 2173
Chris@270 2174 if (r.width() != 0 || r.height() != 0) {
Chris@270 2175 paint.save();
Chris@270 2176 if (focus) {
Chris@270 2177 paint.setPen(Qt::NoPen);
Chris@272 2178 QColor brushColour(Qt::black);
Chris@272 2179 brushColour.setAlpha(hasLightBackground() ? 15 : 40);
Chris@270 2180 paint.setBrush(brushColour);
Chris@270 2181 if (r.x() > 0) {
Chris@270 2182 paint.drawRect(0, 0, r.x(), height());
Chris@270 2183 }
Chris@270 2184 if (r.x() + r.width() < width()) {
Chris@270 2185 paint.drawRect(r.x() + r.width(), 0, width()-r.x()-r.width(), height());
Chris@270 2186 }
Chris@270 2187 if (r.y() > 0) {
Chris@270 2188 paint.drawRect(r.x(), 0, r.width(), r.y());
Chris@270 2189 }
Chris@270 2190 if (r.y() + r.height() < height()) {
Chris@270 2191 paint.drawRect(r.x(), r.y() + r.height(), r.width(), height()-r.y()-r.height());
Chris@270 2192 }
Chris@270 2193 paint.setBrush(Qt::NoBrush);
Chris@270 2194 }
Chris@270 2195 paint.setPen(Qt::green);
Chris@270 2196 paint.drawRect(r);
Chris@270 2197 paint.restore();
Chris@270 2198 } else {
Chris@270 2199 paint.save();
Chris@270 2200 paint.setPen(Qt::green);
Chris@270 2201 paint.drawPoint(r.x(), r.y());
Chris@270 2202 paint.restore();
Chris@270 2203 }
Chris@270 2204
Chris@270 2205 if (!focus) return;
Chris@270 2206
Chris@278 2207 paint.save();
Chris@278 2208 QFont fn = paint.font();
Chris@278 2209 if (fn.pointSize() > 8) {
Chris@278 2210 fn.setPointSize(fn.pointSize() - 1);
Chris@278 2211 paint.setFont(fn);
Chris@278 2212 }
Chris@278 2213
Chris@267 2214 int fontHeight = paint.fontMetrics().height();
Chris@267 2215 int fontAscent = paint.fontMetrics().ascent();
Chris@267 2216
Chris@904 2217 double v0, v1;
Chris@267 2218 QString u0, u1;
Chris@267 2219 bool b0 = false, b1 = false;
Chris@267 2220
Chris@267 2221 QString axs, ays, bxs, bys, dxs, dys;
Chris@267 2222
Chris@267 2223 int axx, axy, bxx, bxy, dxx, dxy;
Chris@267 2224 int aw = 0, bw = 0, dw = 0;
Chris@267 2225
Chris@267 2226 int labelCount = 0;
Chris@267 2227
Chris@362 2228 // top-left point, x-coord
Chris@362 2229
Chris@267 2230 if ((b0 = topLayer->getXScaleValue(this, r.x(), v0, u0))) {
Chris@267 2231 axs = QString("%1 %2").arg(v0).arg(u0);
Chris@278 2232 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) {
Chris@278 2233 axs = QString("%1 (%2)").arg(axs)
Chris@278 2234 .arg(Pitch::getPitchLabelForFrequency(v0));
Chris@278 2235 }
Chris@267 2236 aw = paint.fontMetrics().width(axs);
Chris@267 2237 ++labelCount;
Chris@267 2238 }
Chris@362 2239
Chris@362 2240 // bottom-right point, x-coord
Chris@267 2241
Chris@267 2242 if (r.width() > 0) {
Chris@267 2243 if ((b1 = topLayer->getXScaleValue(this, r.x() + r.width(), v1, u1))) {
Chris@267 2244 bxs = QString("%1 %2").arg(v1).arg(u1);
Chris@278 2245 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) {
Chris@278 2246 bxs = QString("%1 (%2)").arg(bxs)
Chris@278 2247 .arg(Pitch::getPitchLabelForFrequency(v1));
Chris@278 2248 }
Chris@267 2249 bw = paint.fontMetrics().width(bxs);
Chris@267 2250 }
Chris@267 2251 }
Chris@362 2252
Chris@362 2253 // dimension, width
Chris@267 2254
Chris@283 2255 if (b0 && b1 && v1 != v0 && u0 == u1) {
Chris@362 2256 dxs = QString("[%1 %2]").arg(fabs(v1 - v0)).arg(u1);
Chris@267 2257 dw = paint.fontMetrics().width(dxs);
Chris@267 2258 }
Chris@267 2259
Chris@267 2260 b0 = false;
Chris@267 2261 b1 = false;
Chris@267 2262
Chris@362 2263 // top-left point, y-coord
Chris@362 2264
Chris@267 2265 if ((b0 = topLayer->getYScaleValue(this, r.y(), v0, u0))) {
Chris@267 2266 ays = QString("%1 %2").arg(v0).arg(u0);
Chris@278 2267 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) {
Chris@278 2268 ays = QString("%1 (%2)").arg(ays)
Chris@278 2269 .arg(Pitch::getPitchLabelForFrequency(v0));
Chris@278 2270 }
Chris@267 2271 aw = std::max(aw, paint.fontMetrics().width(ays));
Chris@267 2272 ++labelCount;
Chris@267 2273 }
Chris@267 2274
Chris@362 2275 // bottom-right point, y-coord
Chris@362 2276
Chris@267 2277 if (r.height() > 0) {
Chris@267 2278 if ((b1 = topLayer->getYScaleValue(this, r.y() + r.height(), v1, u1))) {
Chris@267 2279 bys = QString("%1 %2").arg(v1).arg(u1);
Chris@278 2280 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) {
Chris@278 2281 bys = QString("%1 (%2)").arg(bys)
Chris@278 2282 .arg(Pitch::getPitchLabelForFrequency(v1));
Chris@278 2283 }
Chris@267 2284 bw = std::max(bw, paint.fontMetrics().width(bys));
Chris@267 2285 }
Chris@267 2286 }
Chris@274 2287
Chris@274 2288 bool bd = false;
Chris@904 2289 double dy = 0.f;
Chris@274 2290 QString du;
Chris@274 2291
Chris@362 2292 // dimension, height
Chris@362 2293
Chris@274 2294 if ((bd = topLayer->getYScaleDifference(this, r.y(), r.y() + r.height(),
Chris@283 2295 dy, du)) &&
Chris@283 2296 dy != 0) {
Chris@274 2297 if (du != "") {
Chris@362 2298 if (du == "Hz") {
Chris@362 2299 int semis;
Chris@904 2300 double cents;
Chris@362 2301 semis = Pitch::getPitchForFrequencyDifference(v0, v1, &cents);
Chris@362 2302 dys = QString("[%1 %2 (%3)]")
Chris@362 2303 .arg(dy).arg(du)
Chris@362 2304 .arg(Pitch::getLabelForPitchRange(semis, cents));
Chris@362 2305 } else {
Chris@362 2306 dys = QString("[%1 %2]").arg(dy).arg(du);
Chris@362 2307 }
Chris@274 2308 } else {
Chris@362 2309 dys = QString("[%1]").arg(dy);
Chris@274 2310 }
Chris@267 2311 dw = std::max(dw, paint.fontMetrics().width(dys));
Chris@267 2312 }
Chris@267 2313
Chris@267 2314 int mw = r.width();
Chris@267 2315 int mh = r.height();
Chris@267 2316
Chris@267 2317 bool edgeLabelsInside = false;
Chris@267 2318 bool sizeLabelsInside = false;
Chris@267 2319
Chris@267 2320 if (mw < std::max(aw, std::max(bw, dw)) + 4) {
Chris@267 2321 // defaults stand
Chris@267 2322 } else if (mw < aw + bw + 4) {
Chris@267 2323 if (mh > fontHeight * labelCount * 3 + 4) {
Chris@267 2324 edgeLabelsInside = true;
Chris@267 2325 sizeLabelsInside = true;
Chris@267 2326 } else if (mh > fontHeight * labelCount * 2 + 4) {
Chris@267 2327 edgeLabelsInside = true;
Chris@267 2328 }
Chris@267 2329 } else if (mw < aw + bw + dw + 4) {
Chris@267 2330 if (mh > fontHeight * labelCount * 3 + 4) {
Chris@267 2331 edgeLabelsInside = true;
Chris@267 2332 sizeLabelsInside = true;
Chris@267 2333 } else if (mh > fontHeight * labelCount + 4) {
Chris@267 2334 edgeLabelsInside = true;
Chris@267 2335 }
Chris@267 2336 } else {
Chris@267 2337 if (mh > fontHeight * labelCount + 4) {
Chris@267 2338 edgeLabelsInside = true;
Chris@267 2339 sizeLabelsInside = true;
Chris@267 2340 }
Chris@267 2341 }
Chris@267 2342
Chris@267 2343 if (edgeLabelsInside) {
Chris@267 2344
Chris@267 2345 axx = r.x() + 2;
Chris@267 2346 axy = r.y() + fontAscent + 2;
Chris@267 2347
Chris@267 2348 bxx = r.x() + r.width() - bw - 2;
Chris@267 2349 bxy = r.y() + r.height() - (labelCount-1) * fontHeight - 2;
Chris@267 2350
Chris@267 2351 } else {
Chris@267 2352
Chris@267 2353 axx = r.x() - aw - 2;
Chris@267 2354 axy = r.y() + fontAscent;
Chris@267 2355
Chris@267 2356 bxx = r.x() + r.width() + 2;
Chris@267 2357 bxy = r.y() + r.height() - (labelCount-1) * fontHeight;
Chris@267 2358 }
Chris@267 2359
Chris@267 2360 dxx = r.width()/2 + r.x() - dw/2;
Chris@267 2361
Chris@267 2362 if (sizeLabelsInside) {
Chris@267 2363
Chris@267 2364 dxy = r.height()/2 + r.y() - (labelCount * fontHeight)/2 + fontAscent;
Chris@267 2365
Chris@267 2366 } else {
Chris@267 2367
Chris@267 2368 dxy = r.y() + r.height() + fontAscent + 2;
Chris@267 2369 }
Chris@267 2370
Chris@267 2371 if (axs != "") {
Chris@267 2372 drawVisibleText(paint, axx, axy, axs, OutlinedText);
Chris@267 2373 axy += fontHeight;
Chris@267 2374 }
Chris@267 2375
Chris@267 2376 if (ays != "") {
Chris@267 2377 drawVisibleText(paint, axx, axy, ays, OutlinedText);
Chris@267 2378 axy += fontHeight;
Chris@267 2379 }
Chris@267 2380
Chris@267 2381 if (bxs != "") {
Chris@267 2382 drawVisibleText(paint, bxx, bxy, bxs, OutlinedText);
Chris@267 2383 bxy += fontHeight;
Chris@267 2384 }
Chris@267 2385
Chris@267 2386 if (bys != "") {
Chris@267 2387 drawVisibleText(paint, bxx, bxy, bys, OutlinedText);
Chris@267 2388 bxy += fontHeight;
Chris@267 2389 }
Chris@267 2390
Chris@267 2391 if (dxs != "") {
Chris@267 2392 drawVisibleText(paint, dxx, dxy, dxs, OutlinedText);
Chris@267 2393 dxy += fontHeight;
Chris@267 2394 }
Chris@267 2395
Chris@267 2396 if (dys != "") {
Chris@267 2397 drawVisibleText(paint, dxx, dxy, dys, OutlinedText);
Chris@267 2398 dxy += fontHeight;
Chris@267 2399 }
Chris@278 2400
Chris@278 2401 paint.restore();
Chris@267 2402 }
Chris@267 2403
Chris@227 2404 bool
Chris@908 2405 View::render(QPainter &paint, int xorigin, sv_frame_t f0, sv_frame_t f1)
Chris@227 2406 {
Chris@908 2407 int x0 = int(f0 / m_zoomLevel);
Chris@908 2408 int x1 = int(f1 / m_zoomLevel);
Chris@806 2409
Chris@806 2410 int w = x1 - x0;
Chris@806 2411
Chris@908 2412 sv_frame_t origCentreFrame = m_centreFrame;
Chris@227 2413
Chris@227 2414 bool someLayersIncomplete = false;
Chris@227 2415
Chris@835 2416 for (LayerList::iterator i = m_layerStack.begin();
Chris@835 2417 i != m_layerStack.end(); ++i) {
Chris@227 2418
Chris@227 2419 int c = (*i)->getCompletion(this);
Chris@227 2420 if (c < 100) {
Chris@227 2421 someLayersIncomplete = true;
Chris@227 2422 break;
Chris@227 2423 }
Chris@227 2424 }
Chris@227 2425
Chris@227 2426 if (someLayersIncomplete) {
Chris@227 2427
Chris@227 2428 QProgressDialog progress(tr("Waiting for layers to be ready..."),
Chris@227 2429 tr("Cancel"), 0, 100, this);
Chris@227 2430
Chris@227 2431 int layerCompletion = 0;
Chris@227 2432
Chris@227 2433 while (layerCompletion < 100) {
Chris@227 2434
Chris@835 2435 for (LayerList::iterator i = m_layerStack.begin();
Chris@835 2436 i != m_layerStack.end(); ++i) {
Chris@227 2437
Chris@227 2438 int c = (*i)->getCompletion(this);
Chris@835 2439 if (i == m_layerStack.begin() || c < layerCompletion) {
Chris@227 2440 layerCompletion = c;
Chris@227 2441 }
Chris@227 2442 }
Chris@227 2443
Chris@227 2444 if (layerCompletion >= 100) break;
Chris@227 2445
Chris@227 2446 progress.setValue(layerCompletion);
Chris@227 2447 qApp->processEvents();
Chris@227 2448 if (progress.wasCanceled()) {
Chris@227 2449 update();
Chris@227 2450 return false;
Chris@227 2451 }
Chris@227 2452
Chris@227 2453 usleep(50000);
Chris@227 2454 }
Chris@227 2455 }
Chris@227 2456
Chris@227 2457 QProgressDialog progress(tr("Rendering image..."),
Chris@227 2458 tr("Cancel"), 0, w / width(), this);
Chris@227 2459
Chris@806 2460 for (int x = 0; x < w; x += width()) {
Chris@227 2461
Chris@227 2462 progress.setValue(x / width());
Chris@227 2463 qApp->processEvents();
Chris@227 2464 if (progress.wasCanceled()) {
Chris@227 2465 m_centreFrame = origCentreFrame;
Chris@227 2466 update();
Chris@227 2467 return false;
Chris@227 2468 }
Chris@227 2469
Chris@229 2470 m_centreFrame = f0 + (x + width()/2) * m_zoomLevel;
Chris@227 2471
Chris@227 2472 QRect chunk(0, 0, width(), height());
Chris@227 2473
Chris@287 2474 paint.setPen(getBackground());
Chris@287 2475 paint.setBrush(getBackground());
Chris@227 2476
Chris@229 2477 paint.drawRect(QRect(xorigin + x, 0, width(), height()));
Chris@227 2478
Chris@287 2479 paint.setPen(getForeground());
Chris@227 2480 paint.setBrush(Qt::NoBrush);
Chris@227 2481
Chris@835 2482 for (LayerList::iterator i = m_layerStack.begin();
Chris@835 2483 i != m_layerStack.end(); ++i) {
Chris@919 2484 if (!((*i)->isLayerDormant(this))){
Chris@919 2485
Chris@919 2486 paint.setRenderHint(QPainter::Antialiasing, false);
Chris@919 2487
Chris@919 2488 paint.save();
Chris@919 2489 paint.translate(xorigin + x, 0);
Chris@919 2490
Chris@919 2491 cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() + x + xorigin << ", " << chunk.width() << endl;
Chris@919 2492
Chris@919 2493 (*i)->setSynchronousPainting(true);
Chris@919 2494
Chris@919 2495 (*i)->paint(this, paint, chunk);
Chris@919 2496
Chris@919 2497 (*i)->setSynchronousPainting(false);
Chris@919 2498
Chris@919 2499 paint.restore();
Chris@919 2500 }
Chris@227 2501 }
Chris@227 2502 }
Chris@227 2503
Chris@227 2504 m_centreFrame = origCentreFrame;
Chris@227 2505 update();
Chris@227 2506 return true;
Chris@227 2507 }
Chris@227 2508
Chris@227 2509 QImage *
Chris@227 2510 View::toNewImage()
Chris@227 2511 {
Chris@908 2512 sv_frame_t f0 = getModelsStartFrame();
Chris@908 2513 sv_frame_t f1 = getModelsEndFrame();
Chris@227 2514
Chris@229 2515 return toNewImage(f0, f1);
Chris@229 2516 }
Chris@229 2517
Chris@229 2518 QImage *
Chris@908 2519 View::toNewImage(sv_frame_t f0, sv_frame_t f1)
Chris@229 2520 {
Chris@908 2521 int x0 = int(f0 / getZoomLevel());
Chris@908 2522 int x1 = int(f1 / getZoomLevel());
Chris@227 2523
Chris@227 2524 QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32);
Chris@227 2525
Chris@227 2526 QPainter *paint = new QPainter(image);
Chris@229 2527 if (!render(*paint, 0, f0, f1)) {
Chris@227 2528 delete paint;
Chris@227 2529 delete image;
Chris@227 2530 return 0;
Chris@227 2531 } else {
Chris@227 2532 delete paint;
Chris@227 2533 return image;
Chris@227 2534 }
Chris@227 2535 }
Chris@227 2536
Chris@229 2537 QSize
Chris@229 2538 View::getImageSize()
Chris@229 2539 {
Chris@908 2540 sv_frame_t f0 = getModelsStartFrame();
Chris@908 2541 sv_frame_t f1 = getModelsEndFrame();
Chris@229 2542
Chris@229 2543 return getImageSize(f0, f1);
Chris@229 2544 }
Chris@229 2545
Chris@229 2546 QSize
Chris@908 2547 View::getImageSize(sv_frame_t f0, sv_frame_t f1)
Chris@229 2548 {
Chris@908 2549 int x0 = int(f0 / getZoomLevel());
Chris@908 2550 int x1 = int(f1 / getZoomLevel());
Chris@229 2551
Chris@229 2552 return QSize(x1 - x0, height());
Chris@229 2553 }
Chris@229 2554
Chris@316 2555 void
Chris@316 2556 View::toXml(QTextStream &stream,
Chris@316 2557 QString indent, QString extraAttributes) const
Chris@127 2558 {
Chris@316 2559 stream << indent;
Chris@127 2560
Chris@316 2561 stream << QString("<view "
Chris@316 2562 "centre=\"%1\" "
Chris@316 2563 "zoom=\"%2\" "
Chris@316 2564 "followPan=\"%3\" "
Chris@316 2565 "followZoom=\"%4\" "
Chris@316 2566 "tracking=\"%5\" "
Chris@316 2567 " %6>\n")
Chris@127 2568 .arg(m_centreFrame)
Chris@127 2569 .arg(m_zoomLevel)
Chris@127 2570 .arg(m_followPan)
Chris@127 2571 .arg(m_followZoom)
Chris@127 2572 .arg(m_followPlay == PlaybackScrollContinuous ? "scroll" :
Chris@815 2573 m_followPlay == PlaybackScrollPageWithCentre ? "page" :
Chris@815 2574 m_followPlay == PlaybackScrollPage ? "daw" :
Chris@815 2575 "ignore")
Chris@127 2576 .arg(extraAttributes);
Chris@127 2577
Chris@838 2578 for (int i = 0; i < (int)m_fixedOrderLayers.size(); ++i) {
Chris@838 2579 bool visible = !m_fixedOrderLayers[i]->isLayerDormant(this);
Chris@838 2580 m_fixedOrderLayers[i]->toBriefXml(stream, indent + " ",
Chris@838 2581 QString("visible=\"%1\"")
Chris@838 2582 .arg(visible ? "true" : "false"));
Chris@127 2583 }
Chris@127 2584
Chris@316 2585 stream << indent + "</view>\n";
Chris@127 2586 }
Chris@127 2587
Chris@127 2588 ViewPropertyContainer::ViewPropertyContainer(View *v) :
Chris@127 2589 m_v(v)
Chris@127 2590 {
Chris@728 2591 // cerr << "ViewPropertyContainer: " << this << " is owned by View " << v << endl;
Chris@127 2592 connect(m_v, SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
Chris@127 2593 this, SIGNAL(propertyChanged(PropertyContainer::PropertyName)));
Chris@127 2594 }
Chris@127 2595
Chris@728 2596 ViewPropertyContainer::~ViewPropertyContainer()
Chris@728 2597 {
Chris@728 2598 }