annotate view/View.cpp @ 1327:646e713a4632 zoom

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