annotate view/ViewManager.cpp @ 502:73a58a4dfebd

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