annotate view/View.cpp @ 1344:13d03ae0c6e0 zoom

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