annotate view/ViewManager.cpp @ 824:22fe9bcb7206 tonioni

compile fix
author Chris Cannam
date Fri, 18 Jul 2014 11:07:13 +0100
parents d974ed657176
children 8bb9320f78a4
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@182 7 This file copyright 2006 Chris Cannam and QMUL.
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@127 16 #include "ViewManager.h"
Chris@128 17 #include "base/AudioPlaySource.h"
Chris@502 18 #include "base/RealTime.h"
Chris@128 19 #include "data/model/Model.h"
Chris@376 20 #include "widgets/CommandHistory.h"
Chris@211 21 #include "View.h"
Chris@503 22 #include "Overview.h"
Chris@127 23
Chris@133 24 #include <QSettings>
Chris@292 25 #include <QApplication>
Chris@133 26
Chris@127 27 #include <iostream>
Chris@127 28
Chris@643 29 //#define DEBUG_VIEW_MANAGER 1
Chris@127 30
Chris@127 31 ViewManager::ViewManager() :
Chris@127 32 m_playSource(0),
Chris@127 33 m_globalCentreFrame(0),
Chris@127 34 m_globalZoom(1024),
Chris@127 35 m_playbackFrame(0),
Chris@301 36 m_playbackModel(0),
Chris@127 37 m_mainModelSampleRate(0),
Chris@127 38 m_lastLeft(0),
Chris@127 39 m_lastRight(0),
Chris@127 40 m_inProgressExclusive(true),
Chris@127 41 m_toolMode(NavigateMode),
Chris@127 42 m_playLoopMode(false),
Chris@127 43 m_playSelectionMode(false),
Chris@301 44 m_playSoloMode(false),
Chris@314 45 m_alignMode(false),
Chris@741 46 m_overlayMode(StandardOverlays),
Chris@292 47 m_zoomWheelsEnabled(true),
Chris@607 48 m_showCentreLine(true),
Chris@326 49 m_illuminateLocalFeatures(true),
Chris@326 50 m_showWorkTitle(false),
matthiasm@822 51 m_showDuration(true),
Chris@292 52 m_lightPalette(QApplication::palette()),
Chris@292 53 m_darkPalette(QApplication::palette())
Chris@127 54 {
Chris@133 55 QSettings settings;
Chris@133 56 settings.beginGroup("MainWindow");
Chris@133 57 m_overlayMode = OverlayMode
Chris@133 58 (settings.value("overlay-mode", int(m_overlayMode)).toInt());
Chris@607 59
Chris@607 60 if (m_overlayMode != NoOverlays &&
Chris@741 61 m_overlayMode != StandardOverlays &&
Chris@607 62 m_overlayMode != AllOverlays) {
Chris@741 63 m_overlayMode = StandardOverlays;
Chris@607 64 }
Chris@607 65
Chris@133 66 m_zoomWheelsEnabled =
Chris@133 67 settings.value("zoom-wheels-enabled", m_zoomWheelsEnabled).toBool();
Chris@607 68 m_showCentreLine =
Chris@607 69 settings.value("show-centre-line", m_showCentreLine).toBool();
Chris@133 70 settings.endGroup();
Chris@292 71
Chris@292 72 if (getGlobalDarkBackground()) {
Chris@343 73 /*
Chris@682 74 cerr << "dark palette:" << endl;
Chris@682 75 cerr << "window = " << QApplication::palette().color(QPalette::Window).name() << endl;
Chris@682 76 cerr << "windowtext = " << QApplication::palette().color(QPalette::WindowText).name() << endl;
Chris@682 77 cerr << "base = " << QApplication::palette().color(QPalette::Base).name() << endl;
Chris@682 78 cerr << "alternatebase = " << QApplication::palette().color(QPalette::AlternateBase).name() << endl;
Chris@682 79 cerr << "text = " << QApplication::palette().color(QPalette::Text).name() << endl;
Chris@682 80 cerr << "button = " << QApplication::palette().color(QPalette::Button).name() << endl;
Chris@682 81 cerr << "buttontext = " << QApplication::palette().color(QPalette::ButtonText).name() << endl;
Chris@682 82 cerr << "brighttext = " << QApplication::palette().color(QPalette::BrightText).name() << endl;
Chris@682 83 cerr << "light = " << QApplication::palette().color(QPalette::Light).name() << endl;
Chris@682 84 cerr << "dark = " << QApplication::palette().color(QPalette::Dark).name() << endl;
Chris@682 85 cerr << "mid = " << QApplication::palette().color(QPalette::Mid).name() << endl;
Chris@343 86 */
Chris@293 87 m_lightPalette = QPalette(QColor("#000000"), // WindowText
Chris@293 88 QColor("#dddfe4"), // Button
Chris@293 89 QColor("#ffffff"), // Light
Chris@293 90 QColor("#555555"), // Dark
Chris@293 91 QColor("#c7c7c7"), // Mid
Chris@293 92 QColor("#000000"), // Text
Chris@293 93 QColor("#ffffff"), // BrightText
Chris@293 94 QColor("#ffffff"), // Base
Chris@293 95 QColor("#efefef")); // Window
Chris@293 96
Chris@293 97
Chris@292 98 } else {
Chris@343 99 /*
Chris@682 100 cerr << "light palette:" << endl;
Chris@682 101 cerr << "window = " << QApplication::palette().color(QPalette::Window).name() << endl;
Chris@682 102 cerr << "windowtext = " << QApplication::palette().color(QPalette::WindowText).name() << endl;
Chris@682 103 cerr << "base = " << QApplication::palette().color(QPalette::Base).name() << endl;
Chris@682 104 cerr << "alternatebase = " << QApplication::palette().color(QPalette::AlternateBase).name() << endl;
Chris@682 105 cerr << "text = " << QApplication::palette().color(QPalette::Text).name() << endl;
Chris@682 106 cerr << "button = " << QApplication::palette().color(QPalette::Button).name() << endl;
Chris@682 107 cerr << "buttontext = " << QApplication::palette().color(QPalette::ButtonText).name() << endl;
Chris@682 108 cerr << "brighttext = " << QApplication::palette().color(QPalette::BrightText).name() << endl;
Chris@682 109 cerr << "light = " << QApplication::palette().color(QPalette::Light).name() << endl;
Chris@682 110 cerr << "dark = " << QApplication::palette().color(QPalette::Dark).name() << endl;
Chris@682 111 cerr << "mid = " << QApplication::palette().color(QPalette::Mid).name() << endl;
Chris@343 112 */
Chris@293 113 m_darkPalette = QPalette(QColor("#ffffff"), // WindowText
Chris@293 114 QColor("#3e3e3e"), // Button
Chris@293 115 QColor("#808080"), // Light
Chris@293 116 QColor("#1e1e1e"), // Dark
Chris@293 117 QColor("#404040"), // Mid
Chris@293 118 QColor("#ffffff"), // Text
Chris@293 119 QColor("#ffffff"), // BrightText
Chris@293 120 QColor("#000000"), // Base
Chris@293 121 QColor("#202020")); // Window
Chris@292 122 }
Chris@127 123 }
Chris@127 124
Chris@127 125 ViewManager::~ViewManager()
Chris@127 126 {
Chris@127 127 }
Chris@127 128
Chris@806 129 int
Chris@127 130 ViewManager::getGlobalCentreFrame() const
Chris@127 131 {
Chris@127 132 #ifdef DEBUG_VIEW_MANAGER
Chris@682 133 cerr << "ViewManager::getGlobalCentreFrame: returning " << m_globalCentreFrame << endl;
Chris@127 134 #endif
Chris@127 135 return m_globalCentreFrame;
Chris@127 136 }
Chris@127 137
Chris@180 138 void
Chris@806 139 ViewManager::setGlobalCentreFrame(int f)
Chris@180 140 {
Chris@180 141 #ifdef DEBUG_VIEW_MANAGER
Chris@682 142 cerr << "ViewManager::setGlobalCentreFrame to " << f << endl;
Chris@180 143 #endif
Chris@180 144 m_globalCentreFrame = f;
Chris@211 145 emit globalCentreFrameChanged(f);
Chris@180 146 }
Chris@180 147
Chris@806 148 int
Chris@127 149 ViewManager::getGlobalZoom() const
Chris@127 150 {
Chris@127 151 #ifdef DEBUG_VIEW_MANAGER
Chris@682 152 cerr << "ViewManager::getGlobalZoom: returning " << m_globalZoom << endl;
Chris@127 153 #endif
Chris@127 154 return m_globalZoom;
Chris@127 155 }
Chris@127 156
Chris@806 157 int
Chris@127 158 ViewManager::getPlaybackFrame() const
Chris@127 159 {
Chris@127 160 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 161 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 162 }
Chris@127 163 return m_playbackFrame;
Chris@127 164 }
Chris@127 165
Chris@127 166 void
Chris@806 167 ViewManager::setPlaybackFrame(int f)
Chris@127 168 {
Chris@127 169 if (m_playbackFrame != f) {
Chris@127 170 m_playbackFrame = f;
Chris@127 171 emit playbackFrameChanged(f);
Chris@127 172 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 173 m_playSource->play(f);
Chris@127 174 }
Chris@127 175 }
Chris@127 176 }
Chris@127 177
Chris@301 178 Model *
Chris@301 179 ViewManager::getPlaybackModel() const
Chris@301 180 {
Chris@301 181 return m_playbackModel;
Chris@301 182 }
Chris@301 183
Chris@301 184 void
Chris@301 185 ViewManager::setPlaybackModel(Model *model)
Chris@301 186 {
Chris@301 187 m_playbackModel = model;
Chris@301 188 }
Chris@301 189
Chris@806 190 int
Chris@806 191 ViewManager::alignPlaybackFrameToReference(int frame) const
Chris@333 192 {
Chris@333 193 if (!m_playbackModel) return frame;
Chris@333 194 else return m_playbackModel->alignToReference(frame);
Chris@333 195 }
Chris@333 196
Chris@806 197 int
Chris@806 198 ViewManager::alignReferenceToPlaybackFrame(int frame) const
Chris@333 199 {
Chris@333 200 if (!m_playbackModel) return frame;
Chris@333 201 else return m_playbackModel->alignFromReference(frame);
Chris@333 202 }
Chris@333 203
Chris@127 204 bool
Chris@127 205 ViewManager::haveInProgressSelection() const
Chris@127 206 {
Chris@127 207 return !m_inProgressSelection.isEmpty();
Chris@127 208 }
Chris@127 209
Chris@127 210 const Selection &
Chris@127 211 ViewManager::getInProgressSelection(bool &exclusive) const
Chris@127 212 {
Chris@127 213 exclusive = m_inProgressExclusive;
Chris@127 214 return m_inProgressSelection;
Chris@127 215 }
Chris@127 216
Chris@127 217 void
Chris@127 218 ViewManager::setInProgressSelection(const Selection &selection, bool exclusive)
Chris@127 219 {
Chris@127 220 m_inProgressExclusive = exclusive;
Chris@127 221 m_inProgressSelection = selection;
Chris@127 222 if (exclusive) clearSelections();
Chris@127 223 emit inProgressSelectionChanged();
Chris@127 224 }
Chris@127 225
Chris@127 226 void
Chris@127 227 ViewManager::clearInProgressSelection()
Chris@127 228 {
Chris@127 229 m_inProgressSelection = Selection();
Chris@127 230 emit inProgressSelectionChanged();
Chris@127 231 }
Chris@127 232
Chris@127 233 const MultiSelection &
Chris@127 234 ViewManager::getSelection() const
Chris@127 235 {
Chris@127 236 return m_selections;
Chris@127 237 }
Chris@127 238
Chris@127 239 const MultiSelection::SelectionList &
Chris@127 240 ViewManager::getSelections() const
Chris@127 241 {
Chris@127 242 return m_selections.getSelections();
Chris@127 243 }
Chris@127 244
Chris@127 245 void
Chris@127 246 ViewManager::setSelection(const Selection &selection)
Chris@127 247 {
Chris@127 248 MultiSelection ms(m_selections);
Chris@127 249 ms.setSelection(selection);
Chris@127 250 setSelections(ms);
Chris@127 251 }
Chris@127 252
Chris@127 253 void
Chris@127 254 ViewManager::addSelection(const Selection &selection)
Chris@127 255 {
Chris@127 256 MultiSelection ms(m_selections);
Chris@127 257 ms.addSelection(selection);
Chris@127 258 setSelections(ms);
Chris@127 259 }
Chris@127 260
Chris@127 261 void
Chris@762 262 ViewManager::addSelectionQuietly(const Selection &selection)
Chris@762 263 {
Chris@762 264 MultiSelection ms(m_selections);
Chris@762 265 ms.addSelection(selection);
Chris@762 266 setSelections(ms, true);
Chris@762 267 }
Chris@762 268
Chris@762 269 void
Chris@127 270 ViewManager::removeSelection(const Selection &selection)
Chris@127 271 {
Chris@127 272 MultiSelection ms(m_selections);
Chris@127 273 ms.removeSelection(selection);
Chris@127 274 setSelections(ms);
Chris@127 275 }
Chris@127 276
Chris@127 277 void
Chris@127 278 ViewManager::clearSelections()
Chris@127 279 {
Chris@127 280 MultiSelection ms(m_selections);
Chris@127 281 ms.clearSelections();
Chris@127 282 setSelections(ms);
Chris@127 283 }
Chris@127 284
Chris@127 285 void
Chris@762 286 ViewManager::setSelections(const MultiSelection &ms, bool quietly)
Chris@127 287 {
Chris@127 288 if (m_selections.getSelections() == ms.getSelections()) return;
Chris@127 289 SetSelectionCommand *command = new SetSelectionCommand(this, ms);
Chris@127 290 CommandHistory::getInstance()->addCommand(command);
Chris@762 291 if (!quietly) {
Chris@762 292 emit selectionChangedByUser();
Chris@762 293 }
Chris@127 294 }
Chris@127 295
Chris@806 296 int
Chris@806 297 ViewManager::constrainFrameToSelection(int frame) const
Chris@271 298 {
Chris@271 299 MultiSelection::SelectionList sl = getSelections();
Chris@271 300 if (sl.empty()) return frame;
Chris@271 301
Chris@368 302 for (MultiSelection::SelectionList::const_iterator i = sl.begin();
Chris@368 303 i != sl.end(); ++i) {
Chris@368 304
Chris@368 305 if (frame < i->getEndFrame()) {
Chris@368 306 if (frame < i->getStartFrame()) {
Chris@368 307 return i->getStartFrame();
Chris@368 308 } else {
Chris@368 309 return frame;
Chris@368 310 }
Chris@368 311 }
Chris@271 312 }
Chris@271 313
Chris@368 314 return sl.begin()->getStartFrame();
Chris@271 315 }
Chris@271 316
Chris@127 317 void
Chris@127 318 ViewManager::signalSelectionChange()
Chris@127 319 {
Chris@127 320 emit selectionChanged();
Chris@127 321 }
Chris@127 322
Chris@127 323 ViewManager::SetSelectionCommand::SetSelectionCommand(ViewManager *vm,
Chris@127 324 const MultiSelection &ms) :
Chris@127 325 m_vm(vm),
Chris@127 326 m_oldSelection(vm->m_selections),
Chris@127 327 m_newSelection(ms)
Chris@127 328 {
Chris@127 329 }
Chris@127 330
Chris@127 331 ViewManager::SetSelectionCommand::~SetSelectionCommand() { }
Chris@127 332
Chris@127 333 void
Chris@127 334 ViewManager::SetSelectionCommand::execute()
Chris@127 335 {
Chris@127 336 m_vm->m_selections = m_newSelection;
Chris@127 337 m_vm->signalSelectionChange();
Chris@127 338 }
Chris@127 339
Chris@127 340 void
Chris@127 341 ViewManager::SetSelectionCommand::unexecute()
Chris@127 342 {
Chris@127 343 m_vm->m_selections = m_oldSelection;
Chris@127 344 m_vm->signalSelectionChange();
Chris@127 345 }
Chris@127 346
Chris@127 347 QString
Chris@127 348 ViewManager::SetSelectionCommand::getName() const
Chris@127 349 {
Chris@127 350 if (m_newSelection.getSelections().empty()) return tr("Clear Selection");
Chris@502 351 if (m_newSelection.getSelections().size() > 1) return tr("Select Multiple Regions");
Chris@502 352 else return tr("Select Region");
Chris@127 353 }
Chris@127 354
Chris@127 355 Selection
Chris@806 356 ViewManager::getContainingSelection(int frame, bool defaultToFollowing) const
Chris@127 357 {
Chris@127 358 return m_selections.getContainingSelection(frame, defaultToFollowing);
Chris@127 359 }
Chris@127 360
Chris@127 361 void
Chris@127 362 ViewManager::setToolMode(ToolMode mode)
Chris@127 363 {
Chris@127 364 m_toolMode = mode;
Chris@127 365
Chris@127 366 emit toolModeChanged();
Chris@502 367
Chris@502 368 switch (mode) {
Chris@502 369 case NavigateMode: emit activity(tr("Enter Navigate mode")); break;
Chris@502 370 case SelectMode: emit activity(tr("Enter Select mode")); break;
Chris@502 371 case EditMode: emit activity(tr("Enter Edit mode")); break;
Chris@502 372 case DrawMode: emit activity(tr("Enter Draw mode")); break;
Chris@502 373 case EraseMode: emit activity(tr("Enter Erase mode")); break;
Chris@502 374 case MeasureMode: emit activity(tr("Enter Measure mode")); break;
gyorgyf@645 375 case NoteEditMode: emit activity(tr("Enter NoteEdit mode")); break; // GF: NoteEditMode activity (I'm not yet certain why we need to emit this.)
Chris@502 376 };
Chris@127 377 }
Chris@127 378
Chris@711 379 ViewManager::ToolMode
Chris@711 380 ViewManager::getToolModeFor(const View *v) const
Chris@711 381 {
Chris@711 382 if (m_toolModeOverrides.find(v) == m_toolModeOverrides.end()) {
Chris@711 383 return getToolMode();
Chris@711 384 } else {
Chris@711 385 return m_toolModeOverrides.find(v)->second;
Chris@711 386 }
Chris@711 387 }
Chris@711 388
Chris@711 389 void
Chris@711 390 ViewManager::setToolModeFor(const View *v, ToolMode mode)
Chris@711 391 {
Chris@711 392 m_toolModeOverrides[v] = mode;
Chris@711 393 }
Chris@711 394
Chris@711 395 void
Chris@711 396 ViewManager::clearToolModeOverrides()
Chris@711 397 {
Chris@711 398 m_toolModeOverrides.clear();
Chris@711 399 }
Chris@711 400
Chris@127 401 void
Chris@127 402 ViewManager::setPlayLoopMode(bool mode)
Chris@127 403 {
Chris@177 404 if (m_playLoopMode != mode) {
Chris@127 405
Chris@177 406 m_playLoopMode = mode;
Chris@177 407
Chris@177 408 emit playLoopModeChanged();
Chris@177 409 emit playLoopModeChanged(mode);
Chris@502 410
Chris@502 411 if (mode) emit activity(tr("Switch on Loop mode"));
Chris@502 412 else emit activity(tr("Switch off Loop mode"));
Chris@177 413 }
Chris@127 414 }
Chris@127 415
Chris@127 416 void
Chris@127 417 ViewManager::setPlaySelectionMode(bool mode)
Chris@127 418 {
Chris@177 419 if (m_playSelectionMode != mode) {
Chris@127 420
Chris@177 421 m_playSelectionMode = mode;
Chris@177 422
Chris@177 423 emit playSelectionModeChanged();
Chris@177 424 emit playSelectionModeChanged(mode);
Chris@502 425
Chris@502 426 if (mode) emit activity(tr("Switch on Play Selection mode"));
Chris@502 427 else emit activity(tr("Switch off Play Selection mode"));
Chris@177 428 }
Chris@127 429 }
Chris@127 430
Chris@301 431 void
Chris@301 432 ViewManager::setPlaySoloMode(bool mode)
Chris@301 433 {
Chris@301 434 if (m_playSoloMode != mode) {
Chris@301 435
Chris@301 436 m_playSoloMode = mode;
Chris@301 437
Chris@301 438 emit playSoloModeChanged();
Chris@301 439 emit playSoloModeChanged(mode);
Chris@502 440
Chris@502 441 if (mode) emit activity(tr("Switch on Play Solo mode"));
Chris@502 442 else emit activity(tr("Switch off Play Solo mode"));
Chris@301 443 }
Chris@301 444 }
Chris@301 445
Chris@314 446 void
Chris@314 447 ViewManager::setAlignMode(bool mode)
Chris@314 448 {
Chris@314 449 if (m_alignMode != mode) {
Chris@314 450
Chris@314 451 m_alignMode = mode;
Chris@314 452
Chris@314 453 emit alignModeChanged();
Chris@314 454 emit alignModeChanged(mode);
Chris@502 455
Chris@502 456 if (mode) emit activity(tr("Switch on Alignment mode"));
Chris@502 457 else emit activity(tr("Switch off Alignment mode"));
Chris@314 458 }
Chris@314 459 }
Chris@314 460
Chris@806 461 int
Chris@224 462 ViewManager::getPlaybackSampleRate() const
Chris@224 463 {
Chris@224 464 if (m_playSource) {
Chris@224 465 return m_playSource->getSourceSampleRate();
Chris@224 466 }
Chris@224 467 return 0;
Chris@224 468 }
Chris@224 469
Chris@806 470 int
Chris@224 471 ViewManager::getOutputSampleRate() const
Chris@127 472 {
Chris@127 473 if (m_playSource) {
Chris@127 474 return m_playSource->getTargetSampleRate();
Chris@127 475 }
Chris@127 476 return 0;
Chris@127 477 }
Chris@127 478
Chris@127 479 void
Chris@127 480 ViewManager::setAudioPlaySource(AudioPlaySource *source)
Chris@127 481 {
Chris@127 482 if (!m_playSource) {
Chris@127 483 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
Chris@127 484 }
Chris@127 485 m_playSource = source;
Chris@127 486 }
Chris@127 487
Chris@127 488 void
Chris@248 489 ViewManager::playStatusChanged(bool /* playing */)
Chris@127 490 {
Chris@689 491 #ifdef DEBUG_VIEW_MANAGER
Chris@689 492 cerr << "ViewManager::playStatusChanged" << endl;
Chris@689 493 #endif
Chris@127 494 checkPlayStatus();
Chris@127 495 }
Chris@127 496
Chris@127 497 void
Chris@127 498 ViewManager::checkPlayStatus()
Chris@127 499 {
Chris@127 500 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 501
Chris@127 502 float left = 0, right = 0;
Chris@127 503 if (m_playSource->getOutputLevels(left, right)) {
Chris@127 504 if (left != m_lastLeft || right != m_lastRight) {
Chris@127 505 emit outputLevelsChanged(left, right);
Chris@127 506 m_lastLeft = left;
Chris@127 507 m_lastRight = right;
Chris@127 508 }
Chris@127 509 }
Chris@127 510
Chris@127 511 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 512
Chris@127 513 #ifdef DEBUG_VIEW_MANAGER
Chris@682 514 cerr << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
Chris@127 515 #endif
Chris@127 516
Chris@127 517 emit playbackFrameChanged(m_playbackFrame);
Chris@127 518
Chris@127 519 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
Chris@127 520
Chris@127 521 } else {
Chris@127 522
Chris@127 523 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
Chris@127 524 emit outputLevelsChanged(0.0, 0.0);
Chris@127 525 m_lastLeft = 0.0;
Chris@127 526 m_lastRight = 0.0;
Chris@127 527 }
Chris@127 528
Chris@127 529 #ifdef DEBUG_VIEW_MANAGER
Chris@689 530 cerr << "ViewManager::checkPlayStatus: Not playing" << endl;
Chris@127 531 #endif
Chris@127 532 }
Chris@127 533 }
Chris@127 534
Chris@127 535 bool
Chris@127 536 ViewManager::isPlaying() const
Chris@127 537 {
Chris@127 538 return m_playSource && m_playSource->isPlaying();
Chris@127 539 }
Chris@127 540
Chris@127 541 void
Chris@806 542 ViewManager::viewCentreFrameChanged(int f, bool locked,
Chris@211 543 PlaybackFollowMode mode)
Chris@127 544 {
Chris@211 545 View *v = dynamic_cast<View *>(sender());
Chris@211 546
Chris@398 547 #ifdef DEBUG_VIEW_MANAGER
Chris@682 548 cerr << "ViewManager::viewCentreFrameChanged(" << f << ", " << locked << ", " << mode << "), view is " << v << endl;
Chris@398 549 #endif
Chris@394 550
Chris@127 551 if (locked) {
Chris@211 552 m_globalCentreFrame = f;
Chris@211 553 emit globalCentreFrameChanged(f);
Chris@211 554 } else {
Chris@211 555 if (v) emit viewCentreFrameChanged(v, f);
Chris@127 556 }
Chris@127 557
Chris@815 558 if (!dynamic_cast<Overview *>(v) || (mode != PlaybackIgnore)) {
Chris@527 559 if (m_mainModelSampleRate != 0) {
Chris@527 560 emit activity(tr("Scroll to %1")
Chris@527 561 .arg(RealTime::frame2RealTime
Chris@527 562 (f, m_mainModelSampleRate).toText().c_str()));
Chris@527 563 }
Chris@503 564 }
Chris@502 565
Chris@815 566 if (mode == PlaybackScrollPageWithCentre ||
Chris@815 567 mode == PlaybackScrollContinuous) {
Chris@815 568 seek(f);
Chris@211 569 }
Chris@211 570 }
Chris@211 571
Chris@211 572 void
Chris@806 573 ViewManager::seek(int f)
Chris@211 574 {
Chris@127 575 #ifdef DEBUG_VIEW_MANAGER
Chris@682 576 cerr << "ViewManager::seek(" << f << ")" << endl;
Chris@127 577 #endif
Chris@127 578
Chris@127 579 if (m_playSource && m_playSource->isPlaying()) {
Chris@806 580 int playFrame = m_playSource->getCurrentPlayingFrame();
Chris@806 581 int diff = std::max(f, playFrame) - std::min(f, playFrame);
Chris@127 582 if (diff > 20000) {
Chris@127 583 m_playbackFrame = f;
Chris@127 584 m_playSource->play(f);
Chris@127 585 #ifdef DEBUG_VIEW_MANAGER
Chris@682 586 cerr << "ViewManager::considerSeek: reseeking from " << playFrame << " to " << f << endl;
Chris@127 587 #endif
Chris@211 588 emit playbackFrameChanged(f);
Chris@127 589 }
Chris@127 590 } else {
Chris@211 591 if (m_playbackFrame != f) {
Chris@211 592 m_playbackFrame = f;
Chris@211 593 emit playbackFrameChanged(f);
Chris@211 594 }
Chris@127 595 }
Chris@127 596 }
Chris@127 597
Chris@127 598 void
Chris@806 599 ViewManager::viewZoomLevelChanged(int z, bool locked)
Chris@127 600 {
Chris@222 601 View *v = dynamic_cast<View *>(sender());
Chris@222 602
Chris@222 603 if (!v) {
Chris@587 604 SVDEBUG << "ViewManager::viewZoomLevelChanged: WARNING: sender is not a view" << endl;
Chris@222 605 return;
Chris@222 606 }
Chris@222 607
Chris@222 608 //!!! emit zoomLevelChanged();
Chris@133 609
Chris@127 610 if (locked) {
Chris@127 611 m_globalZoom = z;
Chris@127 612 }
Chris@127 613
Chris@127 614 #ifdef DEBUG_VIEW_MANAGER
Chris@682 615 cerr << "ViewManager::viewZoomLevelChanged(" << v << ", " << z << ", " << locked << ")" << endl;
Chris@127 616 #endif
Chris@222 617
Chris@222 618 emit viewZoomLevelChanged(v, z, locked);
Chris@503 619
Chris@503 620 if (!dynamic_cast<Overview *>(v)) {
Chris@503 621 emit activity(tr("Zoom to %n sample(s) per pixel", "", z));
Chris@503 622 }
Chris@127 623 }
Chris@127 624
Chris@127 625 void
Chris@127 626 ViewManager::setOverlayMode(OverlayMode mode)
Chris@127 627 {
Chris@127 628 if (m_overlayMode != mode) {
Chris@127 629 m_overlayMode = mode;
Chris@127 630 emit overlayModeChanged();
Chris@502 631 emit activity(tr("Change overlay level"));
Chris@127 632 }
Chris@133 633
Chris@133 634 QSettings settings;
Chris@133 635 settings.beginGroup("MainWindow");
Chris@133 636 settings.setValue("overlay-mode", int(m_overlayMode));
Chris@133 637 settings.endGroup();
Chris@127 638 }
Chris@127 639
Chris@133 640 void
Chris@133 641 ViewManager::setZoomWheelsEnabled(bool enabled)
Chris@133 642 {
Chris@133 643 if (m_zoomWheelsEnabled != enabled) {
Chris@133 644 m_zoomWheelsEnabled = enabled;
Chris@133 645 emit zoomWheelsEnabledChanged();
Chris@502 646 if (enabled) emit activity("Show zoom wheels");
Chris@502 647 else emit activity("Hide zoom wheels");
Chris@133 648 }
Chris@127 649
Chris@133 650 QSettings settings;
Chris@133 651 settings.beginGroup("MainWindow");
Chris@133 652 settings.setValue("zoom-wheels-enabled", m_zoomWheelsEnabled);
Chris@133 653 settings.endGroup();
Chris@133 654 }
Chris@133 655
Chris@292 656 void
Chris@607 657 ViewManager::setShowCentreLine(bool show)
Chris@607 658 {
Chris@607 659 if (m_showCentreLine != show) {
Chris@607 660 m_showCentreLine = show;
Chris@607 661 emit showCentreLineChanged();
Chris@607 662 if (show) emit activity("Show centre line");
Chris@607 663 else emit activity("Hide centre line");
Chris@607 664 }
Chris@607 665
Chris@607 666 QSettings settings;
Chris@607 667 settings.beginGroup("MainWindow");
Chris@607 668 settings.setValue("show-centre-line", int(m_showCentreLine));
Chris@607 669 settings.endGroup();
Chris@607 670 }
Chris@607 671
Chris@607 672 void
Chris@292 673 ViewManager::setGlobalDarkBackground(bool dark)
Chris@292 674 {
Chris@292 675 // also save the current palette, in case the user has changed it
Chris@292 676 // since construction
Chris@292 677 if (getGlobalDarkBackground()) {
Chris@292 678 m_darkPalette = QApplication::palette();
Chris@292 679 } else {
Chris@292 680 m_lightPalette = QApplication::palette();
Chris@292 681 }
Chris@292 682
Chris@737 683 #ifndef Q_OS_MAC
Chris@292 684 if (dark) {
Chris@292 685 QApplication::setPalette(m_darkPalette);
Chris@292 686 } else {
Chris@292 687 QApplication::setPalette(m_lightPalette);
Chris@292 688 }
Chris@737 689 #endif
Chris@292 690 }
Chris@292 691
Chris@292 692 bool
Chris@292 693 ViewManager::getGlobalDarkBackground() const
Chris@292 694 {
Chris@292 695 bool dark = false;
Chris@292 696 QColor windowBg = QApplication::palette().color(QPalette::Window);
Chris@292 697 if (windowBg.red() + windowBg.green() + windowBg.blue() < 384) {
Chris@292 698 dark = true;
Chris@292 699 }
Chris@292 700 return dark;
Chris@292 701 }
Chris@292 702