annotate view/View.cpp @ 1353:86429ff00f05

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