annotate view/ViewManager.cpp @ 753:09e2677e34e7 tonioni

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