annotate view/View.cpp @ 1352:4949061fcb8c zoom

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