annotate view/ViewManager.cpp @ 806:4c8ca536b54f warnfix_no_size_t

Some more unsigned/long removal
author Chris Cannam
date Tue, 17 Jun 2014 15:36:56 +0100
parents b75c95e7f906
children 40c6c9344ff6
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@806 128 int
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@806 138 ViewManager::setGlobalCentreFrame(int 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@806 147 int
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@806 156 int
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@806 166 ViewManager::setPlaybackFrame(int 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@806 189 int
Chris@806 190 ViewManager::alignPlaybackFrameToReference(int 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@806 196 int
Chris@806 197 ViewManager::alignReferenceToPlaybackFrame(int 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@762 261 ViewManager::addSelectionQuietly(const Selection &selection)
Chris@762 262 {
Chris@762 263 MultiSelection ms(m_selections);
Chris@762 264 ms.addSelection(selection);
Chris@762 265 setSelections(ms, true);
Chris@762 266 }
Chris@762 267
Chris@762 268 void
Chris@127 269 ViewManager::removeSelection(const Selection &selection)
Chris@127 270 {
Chris@127 271 MultiSelection ms(m_selections);
Chris@127 272 ms.removeSelection(selection);
Chris@127 273 setSelections(ms);
Chris@127 274 }
Chris@127 275
Chris@127 276 void
Chris@127 277 ViewManager::clearSelections()
Chris@127 278 {
Chris@127 279 MultiSelection ms(m_selections);
Chris@127 280 ms.clearSelections();
Chris@127 281 setSelections(ms);
Chris@127 282 }
Chris@127 283
Chris@127 284 void
Chris@762 285 ViewManager::setSelections(const MultiSelection &ms, bool quietly)
Chris@127 286 {
Chris@127 287 if (m_selections.getSelections() == ms.getSelections()) return;
Chris@127 288 SetSelectionCommand *command = new SetSelectionCommand(this, ms);
Chris@127 289 CommandHistory::getInstance()->addCommand(command);
Chris@762 290 if (!quietly) {
Chris@762 291 emit selectionChangedByUser();
Chris@762 292 }
Chris@127 293 }
Chris@127 294
Chris@806 295 int
Chris@806 296 ViewManager::constrainFrameToSelection(int frame) const
Chris@271 297 {
Chris@271 298 MultiSelection::SelectionList sl = getSelections();
Chris@271 299 if (sl.empty()) return frame;
Chris@271 300
Chris@368 301 for (MultiSelection::SelectionList::const_iterator i = sl.begin();
Chris@368 302 i != sl.end(); ++i) {
Chris@368 303
Chris@368 304 if (frame < i->getEndFrame()) {
Chris@368 305 if (frame < i->getStartFrame()) {
Chris@368 306 return i->getStartFrame();
Chris@368 307 } else {
Chris@368 308 return frame;
Chris@368 309 }
Chris@368 310 }
Chris@271 311 }
Chris@271 312
Chris@368 313 return sl.begin()->getStartFrame();
Chris@271 314 }
Chris@271 315
Chris@127 316 void
Chris@127 317 ViewManager::signalSelectionChange()
Chris@127 318 {
Chris@127 319 emit selectionChanged();
Chris@127 320 }
Chris@127 321
Chris@127 322 ViewManager::SetSelectionCommand::SetSelectionCommand(ViewManager *vm,
Chris@127 323 const MultiSelection &ms) :
Chris@127 324 m_vm(vm),
Chris@127 325 m_oldSelection(vm->m_selections),
Chris@127 326 m_newSelection(ms)
Chris@127 327 {
Chris@127 328 }
Chris@127 329
Chris@127 330 ViewManager::SetSelectionCommand::~SetSelectionCommand() { }
Chris@127 331
Chris@127 332 void
Chris@127 333 ViewManager::SetSelectionCommand::execute()
Chris@127 334 {
Chris@127 335 m_vm->m_selections = m_newSelection;
Chris@127 336 m_vm->signalSelectionChange();
Chris@127 337 }
Chris@127 338
Chris@127 339 void
Chris@127 340 ViewManager::SetSelectionCommand::unexecute()
Chris@127 341 {
Chris@127 342 m_vm->m_selections = m_oldSelection;
Chris@127 343 m_vm->signalSelectionChange();
Chris@127 344 }
Chris@127 345
Chris@127 346 QString
Chris@127 347 ViewManager::SetSelectionCommand::getName() const
Chris@127 348 {
Chris@127 349 if (m_newSelection.getSelections().empty()) return tr("Clear Selection");
Chris@502 350 if (m_newSelection.getSelections().size() > 1) return tr("Select Multiple Regions");
Chris@502 351 else return tr("Select Region");
Chris@127 352 }
Chris@127 353
Chris@127 354 Selection
Chris@806 355 ViewManager::getContainingSelection(int frame, bool defaultToFollowing) const
Chris@127 356 {
Chris@127 357 return m_selections.getContainingSelection(frame, defaultToFollowing);
Chris@127 358 }
Chris@127 359
Chris@127 360 void
Chris@127 361 ViewManager::setToolMode(ToolMode mode)
Chris@127 362 {
Chris@127 363 m_toolMode = mode;
Chris@127 364
Chris@127 365 emit toolModeChanged();
Chris@502 366
Chris@502 367 switch (mode) {
Chris@502 368 case NavigateMode: emit activity(tr("Enter Navigate mode")); break;
Chris@502 369 case SelectMode: emit activity(tr("Enter Select mode")); break;
Chris@502 370 case EditMode: emit activity(tr("Enter Edit mode")); break;
Chris@502 371 case DrawMode: emit activity(tr("Enter Draw mode")); break;
Chris@502 372 case EraseMode: emit activity(tr("Enter Erase mode")); break;
Chris@502 373 case MeasureMode: emit activity(tr("Enter Measure mode")); break;
gyorgyf@645 374 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 375 };
Chris@127 376 }
Chris@127 377
Chris@711 378 ViewManager::ToolMode
Chris@711 379 ViewManager::getToolModeFor(const View *v) const
Chris@711 380 {
Chris@711 381 if (m_toolModeOverrides.find(v) == m_toolModeOverrides.end()) {
Chris@711 382 return getToolMode();
Chris@711 383 } else {
Chris@711 384 return m_toolModeOverrides.find(v)->second;
Chris@711 385 }
Chris@711 386 }
Chris@711 387
Chris@711 388 void
Chris@711 389 ViewManager::setToolModeFor(const View *v, ToolMode mode)
Chris@711 390 {
Chris@711 391 m_toolModeOverrides[v] = mode;
Chris@711 392 }
Chris@711 393
Chris@711 394 void
Chris@711 395 ViewManager::clearToolModeOverrides()
Chris@711 396 {
Chris@711 397 m_toolModeOverrides.clear();
Chris@711 398 }
Chris@711 399
Chris@127 400 void
Chris@127 401 ViewManager::setPlayLoopMode(bool mode)
Chris@127 402 {
Chris@177 403 if (m_playLoopMode != mode) {
Chris@127 404
Chris@177 405 m_playLoopMode = mode;
Chris@177 406
Chris@177 407 emit playLoopModeChanged();
Chris@177 408 emit playLoopModeChanged(mode);
Chris@502 409
Chris@502 410 if (mode) emit activity(tr("Switch on Loop mode"));
Chris@502 411 else emit activity(tr("Switch off Loop mode"));
Chris@177 412 }
Chris@127 413 }
Chris@127 414
Chris@127 415 void
Chris@127 416 ViewManager::setPlaySelectionMode(bool mode)
Chris@127 417 {
Chris@177 418 if (m_playSelectionMode != mode) {
Chris@127 419
Chris@177 420 m_playSelectionMode = mode;
Chris@177 421
Chris@177 422 emit playSelectionModeChanged();
Chris@177 423 emit playSelectionModeChanged(mode);
Chris@502 424
Chris@502 425 if (mode) emit activity(tr("Switch on Play Selection mode"));
Chris@502 426 else emit activity(tr("Switch off Play Selection mode"));
Chris@177 427 }
Chris@127 428 }
Chris@127 429
Chris@301 430 void
Chris@301 431 ViewManager::setPlaySoloMode(bool mode)
Chris@301 432 {
Chris@301 433 if (m_playSoloMode != mode) {
Chris@301 434
Chris@301 435 m_playSoloMode = mode;
Chris@301 436
Chris@301 437 emit playSoloModeChanged();
Chris@301 438 emit playSoloModeChanged(mode);
Chris@502 439
Chris@502 440 if (mode) emit activity(tr("Switch on Play Solo mode"));
Chris@502 441 else emit activity(tr("Switch off Play Solo mode"));
Chris@301 442 }
Chris@301 443 }
Chris@301 444
Chris@314 445 void
Chris@314 446 ViewManager::setAlignMode(bool mode)
Chris@314 447 {
Chris@314 448 if (m_alignMode != mode) {
Chris@314 449
Chris@314 450 m_alignMode = mode;
Chris@314 451
Chris@314 452 emit alignModeChanged();
Chris@314 453 emit alignModeChanged(mode);
Chris@502 454
Chris@502 455 if (mode) emit activity(tr("Switch on Alignment mode"));
Chris@502 456 else emit activity(tr("Switch off Alignment mode"));
Chris@314 457 }
Chris@314 458 }
Chris@314 459
Chris@806 460 int
Chris@224 461 ViewManager::getPlaybackSampleRate() const
Chris@224 462 {
Chris@224 463 if (m_playSource) {
Chris@224 464 return m_playSource->getSourceSampleRate();
Chris@224 465 }
Chris@224 466 return 0;
Chris@224 467 }
Chris@224 468
Chris@806 469 int
Chris@224 470 ViewManager::getOutputSampleRate() const
Chris@127 471 {
Chris@127 472 if (m_playSource) {
Chris@127 473 return m_playSource->getTargetSampleRate();
Chris@127 474 }
Chris@127 475 return 0;
Chris@127 476 }
Chris@127 477
Chris@127 478 void
Chris@127 479 ViewManager::setAudioPlaySource(AudioPlaySource *source)
Chris@127 480 {
Chris@127 481 if (!m_playSource) {
Chris@127 482 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
Chris@127 483 }
Chris@127 484 m_playSource = source;
Chris@127 485 }
Chris@127 486
Chris@127 487 void
Chris@248 488 ViewManager::playStatusChanged(bool /* playing */)
Chris@127 489 {
Chris@689 490 #ifdef DEBUG_VIEW_MANAGER
Chris@689 491 cerr << "ViewManager::playStatusChanged" << endl;
Chris@689 492 #endif
Chris@127 493 checkPlayStatus();
Chris@127 494 }
Chris@127 495
Chris@127 496 void
Chris@127 497 ViewManager::checkPlayStatus()
Chris@127 498 {
Chris@127 499 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 500
Chris@127 501 float left = 0, right = 0;
Chris@127 502 if (m_playSource->getOutputLevels(left, right)) {
Chris@127 503 if (left != m_lastLeft || right != m_lastRight) {
Chris@127 504 emit outputLevelsChanged(left, right);
Chris@127 505 m_lastLeft = left;
Chris@127 506 m_lastRight = right;
Chris@127 507 }
Chris@127 508 }
Chris@127 509
Chris@127 510 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 511
Chris@127 512 #ifdef DEBUG_VIEW_MANAGER
Chris@682 513 cerr << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
Chris@127 514 #endif
Chris@127 515
Chris@127 516 emit playbackFrameChanged(m_playbackFrame);
Chris@127 517
Chris@127 518 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
Chris@127 519
Chris@127 520 } else {
Chris@127 521
Chris@127 522 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
Chris@127 523 emit outputLevelsChanged(0.0, 0.0);
Chris@127 524 m_lastLeft = 0.0;
Chris@127 525 m_lastRight = 0.0;
Chris@127 526 }
Chris@127 527
Chris@127 528 #ifdef DEBUG_VIEW_MANAGER
Chris@689 529 cerr << "ViewManager::checkPlayStatus: Not playing" << endl;
Chris@127 530 #endif
Chris@127 531 }
Chris@127 532 }
Chris@127 533
Chris@127 534 bool
Chris@127 535 ViewManager::isPlaying() const
Chris@127 536 {
Chris@127 537 return m_playSource && m_playSource->isPlaying();
Chris@127 538 }
Chris@127 539
Chris@127 540 void
Chris@806 541 ViewManager::viewCentreFrameChanged(int f, bool locked,
Chris@211 542 PlaybackFollowMode mode)
Chris@127 543 {
Chris@211 544 View *v = dynamic_cast<View *>(sender());
Chris@211 545
Chris@398 546 #ifdef DEBUG_VIEW_MANAGER
Chris@682 547 cerr << "ViewManager::viewCentreFrameChanged(" << f << ", " << locked << ", " << mode << "), view is " << v << endl;
Chris@398 548 #endif
Chris@394 549
Chris@127 550 if (locked) {
Chris@211 551 m_globalCentreFrame = f;
Chris@211 552 emit globalCentreFrameChanged(f);
Chris@211 553 } else {
Chris@211 554 if (v) emit viewCentreFrameChanged(v, f);
Chris@127 555 }
Chris@127 556
Chris@503 557 if (!dynamic_cast<Overview *>(v) || (mode != PlaybackIgnore)) {
Chris@527 558 if (m_mainModelSampleRate != 0) {
Chris@527 559 emit activity(tr("Scroll to %1")
Chris@527 560 .arg(RealTime::frame2RealTime
Chris@527 561 (f, m_mainModelSampleRate).toText().c_str()));
Chris@527 562 }
Chris@503 563 }
Chris@502 564
Chris@211 565 if (mode == PlaybackIgnore) {
Chris@211 566 return;
Chris@211 567 }
Chris@211 568
Chris@211 569 seek(f);
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