annotate view/ViewManager.cpp @ 1575:3761d1ea5015 background-mode

More sensible approach to colour setting on Windows
author Chris Cannam
date Mon, 20 Jan 2020 17:18:42 +0000
parents dd7166cdf6bc
children 9c4a057302ff
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@1210 18 #include "base/AudioRecordTarget.h"
Chris@502 19 #include "base/RealTime.h"
Chris@128 20 #include "data/model/Model.h"
Chris@376 21 #include "widgets/CommandHistory.h"
Chris@211 22 #include "View.h"
Chris@503 23 #include "Overview.h"
Chris@127 24
Chris@133 25 #include <QSettings>
Chris@292 26 #include <QApplication>
Chris@1575 27 #include <QStyleFactory>
Chris@133 28
Chris@127 29 #include <iostream>
Chris@127 30
Chris@643 31 //#define DEBUG_VIEW_MANAGER 1
Chris@127 32
Chris@127 33 ViewManager::ViewManager() :
Chris@1408 34 m_playSource(nullptr),
Chris@1408 35 m_recordTarget(nullptr),
Chris@127 36 m_globalCentreFrame(0),
Chris@1327 37 m_globalZoom(ZoomLevel::FramesPerPixel, 1024),
Chris@127 38 m_playbackFrame(0),
Chris@127 39 m_mainModelSampleRate(0),
Chris@127 40 m_lastLeft(0),
Chris@127 41 m_lastRight(0),
Chris@127 42 m_inProgressExclusive(true),
Chris@127 43 m_toolMode(NavigateMode),
Chris@127 44 m_playLoopMode(false),
Chris@127 45 m_playSelectionMode(false),
Chris@301 46 m_playSoloMode(false),
Chris@314 47 m_alignMode(false),
Chris@741 48 m_overlayMode(StandardOverlays),
Chris@292 49 m_zoomWheelsEnabled(true),
Chris@1468 50 m_opportunisticEditingEnabled(true),
Chris@607 51 m_showCentreLine(true),
Chris@326 52 m_illuminateLocalFeatures(true),
Chris@326 53 m_showWorkTitle(false),
matthiasm@822 54 m_showDuration(true),
Chris@292 55 m_lightPalette(QApplication::palette()),
Chris@292 56 m_darkPalette(QApplication::palette())
Chris@127 57 {
Chris@133 58 QSettings settings;
Chris@133 59 settings.beginGroup("MainWindow");
Chris@133 60 m_overlayMode = OverlayMode
Chris@133 61 (settings.value("overlay-mode", int(m_overlayMode)).toInt());
Chris@607 62
Chris@607 63 if (m_overlayMode != NoOverlays &&
Chris@741 64 m_overlayMode != StandardOverlays &&
Chris@607 65 m_overlayMode != AllOverlays) {
Chris@741 66 m_overlayMode = StandardOverlays;
Chris@607 67 }
Chris@607 68
Chris@133 69 m_zoomWheelsEnabled =
Chris@133 70 settings.value("zoom-wheels-enabled", m_zoomWheelsEnabled).toBool();
Chris@607 71 m_showCentreLine =
Chris@607 72 settings.value("show-centre-line", m_showCentreLine).toBool();
Chris@133 73 settings.endGroup();
Chris@292 74
Chris@292 75 if (getGlobalDarkBackground()) {
Chris@1573 76 // i.e. widgets are already dark; create a light palette in
Chris@1573 77 // case we are asked to switch to it, but don't create a dark
Chris@1573 78 // one because it will be assigned from the actual application
Chris@1573 79 // palette if we switch
Chris@1573 80
Chris@293 81 m_lightPalette = QPalette(QColor("#000000"), // WindowText
Chris@293 82 QColor("#dddfe4"), // Button
Chris@293 83 QColor("#ffffff"), // Light
Chris@293 84 QColor("#555555"), // Dark
Chris@293 85 QColor("#c7c7c7"), // Mid
Chris@293 86 QColor("#000000"), // Text
Chris@293 87 QColor("#ffffff"), // BrightText
Chris@293 88 QColor("#ffffff"), // Base
Chris@293 89 QColor("#efefef")); // Window
Chris@293 90
Chris@293 91
Chris@292 92 } else {
Chris@1573 93 // i.e. widgets are currently light; create a dark palette in
Chris@1573 94 // case we are asked to switch to it, but don't create a light
Chris@1573 95 // one because it will be assigned from the actual application
Chris@1573 96 // palette if we switch
Chris@1573 97
Chris@1573 98 m_darkPalette = QPalette(QColor("#f0f0f0"), // WindowText
Chris@293 99 QColor("#3e3e3e"), // Button
Chris@293 100 QColor("#808080"), // Light
Chris@293 101 QColor("#1e1e1e"), // Dark
Chris@293 102 QColor("#404040"), // Mid
Chris@1573 103 QColor("#f0f0f0"), // Text
Chris@293 104 QColor("#ffffff"), // BrightText
Chris@293 105 QColor("#000000"), // Base
Chris@293 106 QColor("#202020")); // Window
Chris@1573 107
Chris@1573 108 m_darkPalette.setColor(QPalette::Disabled, QPalette::WindowText,
Chris@1573 109 QColor("#808080"));
Chris@1573 110 m_darkPalette.setColor(QPalette::Disabled, QPalette::Text,
Chris@1573 111 QColor("#808080"));
Chris@1573 112 m_darkPalette.setColor(QPalette::Disabled, QPalette::Shadow,
Chris@1573 113 QColor("#000000"));
Chris@292 114 }
Chris@127 115 }
Chris@127 116
Chris@127 117 ViewManager::~ViewManager()
Chris@127 118 {
Chris@127 119 }
Chris@127 120
Chris@902 121 sv_frame_t
Chris@127 122 ViewManager::getGlobalCentreFrame() const
Chris@127 123 {
Chris@127 124 #ifdef DEBUG_VIEW_MANAGER
Chris@682 125 cerr << "ViewManager::getGlobalCentreFrame: returning " << m_globalCentreFrame << endl;
Chris@127 126 #endif
Chris@127 127 return m_globalCentreFrame;
Chris@127 128 }
Chris@127 129
Chris@180 130 void
Chris@902 131 ViewManager::setGlobalCentreFrame(sv_frame_t f)
Chris@180 132 {
Chris@180 133 #ifdef DEBUG_VIEW_MANAGER
Chris@682 134 cerr << "ViewManager::setGlobalCentreFrame to " << f << endl;
Chris@180 135 #endif
Chris@180 136 m_globalCentreFrame = f;
Chris@211 137 emit globalCentreFrameChanged(f);
Chris@180 138 }
Chris@180 139
Chris@1327 140 ZoomLevel
Chris@127 141 ViewManager::getGlobalZoom() const
Chris@127 142 {
Chris@127 143 #ifdef DEBUG_VIEW_MANAGER
Chris@682 144 cerr << "ViewManager::getGlobalZoom: returning " << m_globalZoom << endl;
Chris@127 145 #endif
Chris@127 146 return m_globalZoom;
Chris@127 147 }
Chris@127 148
Chris@902 149 sv_frame_t
Chris@127 150 ViewManager::getPlaybackFrame() const
Chris@127 151 {
Chris@1210 152 if (isRecording()) {
Chris@1210 153 m_playbackFrame = m_recordTarget->getRecordDuration();
Chris@1210 154 #ifdef DEBUG_VIEW_MANAGER
Chris@1210 155 cout << "ViewManager::getPlaybackFrame(recording) -> " << m_playbackFrame << endl;
Chris@1210 156 #endif
Chris@1210 157 } else if (isPlaying()) {
Chris@1266 158 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@1185 159 #ifdef DEBUG_VIEW_MANAGER
Chris@1185 160 cout << "ViewManager::getPlaybackFrame(playing) -> " << m_playbackFrame << endl;
Chris@1185 161 #endif
Chris@1185 162 } else {
Chris@1185 163 #ifdef DEBUG_VIEW_MANAGER
Chris@1185 164 cout << "ViewManager::getPlaybackFrame(not playing) -> " << m_playbackFrame << endl;
Chris@1185 165 #endif
Chris@127 166 }
Chris@127 167 return m_playbackFrame;
Chris@127 168 }
Chris@127 169
Chris@127 170 void
Chris@902 171 ViewManager::setPlaybackFrame(sv_frame_t f)
Chris@127 172 {
Chris@1185 173 #ifdef DEBUG_VIEW_MANAGER
Chris@1185 174 cerr << "ViewManager::setPlaybackFrame(" << f << ")" << endl;
Chris@1185 175 #endif
Chris@968 176 if (f < 0) f = 0;
Chris@127 177 if (m_playbackFrame != f) {
Chris@1266 178 m_playbackFrame = f;
Chris@1266 179 emit playbackFrameChanged(f);
Chris@1266 180 if (isPlaying()) {
Chris@1266 181 m_playSource->play(f);
Chris@1266 182 }
Chris@127 183 }
Chris@127 184 }
Chris@127 185
Chris@1479 186 ModelId
Chris@301 187 ViewManager::getPlaybackModel() const
Chris@301 188 {
Chris@301 189 return m_playbackModel;
Chris@301 190 }
Chris@301 191
Chris@301 192 void
Chris@1479 193 ViewManager::setPlaybackModel(ModelId model)
Chris@301 194 {
Chris@301 195 m_playbackModel = model;
Chris@301 196 }
Chris@301 197
Chris@902 198 sv_frame_t
Chris@902 199 ViewManager::alignPlaybackFrameToReference(sv_frame_t frame) const
Chris@333 200 {
Chris@830 201 #ifdef DEBUG_VIEW_MANAGER
Chris@830 202 cerr << "ViewManager::alignPlaybackFrameToReference(" << frame << "): playback model is " << m_playbackModel << endl;
Chris@830 203 #endif
Chris@1479 204 if (m_playbackModel.isNone() || !m_alignMode) {
Chris@830 205 return frame;
Chris@830 206 } else {
Chris@1479 207 auto playbackModel = ModelById::get(m_playbackModel);
Chris@1479 208 if (!playbackModel) {
Chris@1479 209 return frame;
Chris@1479 210 }
Chris@1479 211 sv_frame_t f = playbackModel->alignToReference(frame);
Chris@830 212 #ifdef DEBUG_VIEW_MANAGER
Chris@830 213 cerr << "aligned frame = " << f << endl;
Chris@830 214 #endif
Chris@830 215 return f;
Chris@830 216 }
Chris@333 217 }
Chris@333 218
Chris@902 219 sv_frame_t
Chris@902 220 ViewManager::alignReferenceToPlaybackFrame(sv_frame_t frame) const
Chris@333 221 {
Chris@830 222 #ifdef DEBUG_VIEW_MANAGER
Chris@830 223 cerr << "ViewManager::alignReferenceToPlaybackFrame(" << frame << "): playback model is " << m_playbackModel << endl;
Chris@830 224 #endif
Chris@1479 225 if (m_playbackModel.isNone() || !m_alignMode) {
Chris@830 226 return frame;
Chris@830 227 } else {
Chris@1479 228 auto playbackModel = ModelById::get(m_playbackModel);
Chris@1479 229 if (!playbackModel) {
Chris@1479 230 return frame;
Chris@1479 231 }
Chris@1479 232 sv_frame_t f = playbackModel->alignFromReference(frame);
Chris@830 233 #ifdef DEBUG_VIEW_MANAGER
Chris@830 234 cerr << "aligned frame = " << f << endl;
Chris@830 235 #endif
Chris@830 236 return f;
Chris@830 237 }
Chris@333 238 }
Chris@333 239
Chris@127 240 bool
Chris@127 241 ViewManager::haveInProgressSelection() const
Chris@127 242 {
Chris@127 243 return !m_inProgressSelection.isEmpty();
Chris@127 244 }
Chris@127 245
Chris@127 246 const Selection &
Chris@127 247 ViewManager::getInProgressSelection(bool &exclusive) const
Chris@127 248 {
Chris@127 249 exclusive = m_inProgressExclusive;
Chris@127 250 return m_inProgressSelection;
Chris@127 251 }
Chris@127 252
Chris@127 253 void
Chris@127 254 ViewManager::setInProgressSelection(const Selection &selection, bool exclusive)
Chris@127 255 {
Chris@127 256 m_inProgressExclusive = exclusive;
Chris@127 257 m_inProgressSelection = selection;
Chris@127 258 if (exclusive) clearSelections();
Chris@127 259 emit inProgressSelectionChanged();
Chris@127 260 }
Chris@127 261
Chris@127 262 void
Chris@127 263 ViewManager::clearInProgressSelection()
Chris@127 264 {
Chris@127 265 m_inProgressSelection = Selection();
Chris@127 266 emit inProgressSelectionChanged();
Chris@127 267 }
Chris@127 268
Chris@127 269 const MultiSelection &
Chris@127 270 ViewManager::getSelection() const
Chris@127 271 {
Chris@127 272 return m_selections;
Chris@127 273 }
Chris@127 274
Chris@127 275 const MultiSelection::SelectionList &
Chris@127 276 ViewManager::getSelections() const
Chris@127 277 {
Chris@127 278 return m_selections.getSelections();
Chris@127 279 }
Chris@127 280
Chris@127 281 void
Chris@127 282 ViewManager::setSelection(const Selection &selection)
Chris@127 283 {
Chris@127 284 MultiSelection ms(m_selections);
Chris@127 285 ms.setSelection(selection);
Chris@127 286 setSelections(ms);
Chris@127 287 }
Chris@127 288
Chris@127 289 void
Chris@127 290 ViewManager::addSelection(const Selection &selection)
Chris@127 291 {
Chris@127 292 MultiSelection ms(m_selections);
Chris@127 293 ms.addSelection(selection);
Chris@127 294 setSelections(ms);
Chris@127 295 }
Chris@127 296
Chris@127 297 void
Chris@762 298 ViewManager::addSelectionQuietly(const Selection &selection)
Chris@762 299 {
Chris@762 300 MultiSelection ms(m_selections);
Chris@762 301 ms.addSelection(selection);
Chris@762 302 setSelections(ms, true);
Chris@762 303 }
Chris@762 304
Chris@762 305 void
Chris@127 306 ViewManager::removeSelection(const Selection &selection)
Chris@127 307 {
Chris@127 308 MultiSelection ms(m_selections);
Chris@127 309 ms.removeSelection(selection);
Chris@127 310 setSelections(ms);
Chris@127 311 }
Chris@127 312
Chris@127 313 void
Chris@127 314 ViewManager::clearSelections()
Chris@127 315 {
Chris@127 316 MultiSelection ms(m_selections);
Chris@127 317 ms.clearSelections();
Chris@127 318 setSelections(ms);
Chris@127 319 }
Chris@127 320
Chris@127 321 void
Chris@762 322 ViewManager::setSelections(const MultiSelection &ms, bool quietly)
Chris@127 323 {
Chris@127 324 if (m_selections.getSelections() == ms.getSelections()) return;
Chris@127 325 SetSelectionCommand *command = new SetSelectionCommand(this, ms);
Chris@127 326 CommandHistory::getInstance()->addCommand(command);
Chris@762 327 if (!quietly) {
Chris@762 328 emit selectionChangedByUser();
Chris@762 329 }
Chris@127 330 }
Chris@127 331
Chris@902 332 sv_frame_t
Chris@902 333 ViewManager::constrainFrameToSelection(sv_frame_t frame) const
Chris@271 334 {
Chris@271 335 MultiSelection::SelectionList sl = getSelections();
Chris@271 336 if (sl.empty()) return frame;
Chris@271 337
Chris@368 338 for (MultiSelection::SelectionList::const_iterator i = sl.begin();
Chris@368 339 i != sl.end(); ++i) {
Chris@368 340
Chris@368 341 if (frame < i->getEndFrame()) {
Chris@368 342 if (frame < i->getStartFrame()) {
Chris@368 343 return i->getStartFrame();
Chris@368 344 } else {
Chris@368 345 return frame;
Chris@368 346 }
Chris@368 347 }
Chris@271 348 }
Chris@271 349
Chris@368 350 return sl.begin()->getStartFrame();
Chris@271 351 }
Chris@271 352
Chris@127 353 void
Chris@127 354 ViewManager::signalSelectionChange()
Chris@127 355 {
Chris@127 356 emit selectionChanged();
Chris@127 357 }
Chris@127 358
Chris@127 359 ViewManager::SetSelectionCommand::SetSelectionCommand(ViewManager *vm,
Chris@1266 360 const MultiSelection &ms) :
Chris@127 361 m_vm(vm),
Chris@127 362 m_oldSelection(vm->m_selections),
Chris@127 363 m_newSelection(ms)
Chris@127 364 {
Chris@127 365 }
Chris@127 366
Chris@127 367 ViewManager::SetSelectionCommand::~SetSelectionCommand() { }
Chris@127 368
Chris@127 369 void
Chris@127 370 ViewManager::SetSelectionCommand::execute()
Chris@127 371 {
Chris@127 372 m_vm->m_selections = m_newSelection;
Chris@127 373 m_vm->signalSelectionChange();
Chris@127 374 }
Chris@127 375
Chris@127 376 void
Chris@127 377 ViewManager::SetSelectionCommand::unexecute()
Chris@127 378 {
Chris@127 379 m_vm->m_selections = m_oldSelection;
Chris@127 380 m_vm->signalSelectionChange();
Chris@127 381 }
Chris@127 382
Chris@127 383 QString
Chris@127 384 ViewManager::SetSelectionCommand::getName() const
Chris@127 385 {
Chris@127 386 if (m_newSelection.getSelections().empty()) return tr("Clear Selection");
Chris@502 387 if (m_newSelection.getSelections().size() > 1) return tr("Select Multiple Regions");
Chris@502 388 else return tr("Select Region");
Chris@127 389 }
Chris@127 390
Chris@127 391 Selection
Chris@902 392 ViewManager::getContainingSelection(sv_frame_t frame, bool defaultToFollowing) const
Chris@127 393 {
Chris@127 394 return m_selections.getContainingSelection(frame, defaultToFollowing);
Chris@127 395 }
Chris@127 396
Chris@127 397 void
Chris@127 398 ViewManager::setToolMode(ToolMode mode)
Chris@127 399 {
Chris@127 400 m_toolMode = mode;
Chris@127 401
Chris@127 402 emit toolModeChanged();
Chris@502 403
Chris@502 404 switch (mode) {
Chris@502 405 case NavigateMode: emit activity(tr("Enter Navigate mode")); break;
Chris@502 406 case SelectMode: emit activity(tr("Enter Select mode")); break;
Chris@502 407 case EditMode: emit activity(tr("Enter Edit mode")); break;
Chris@502 408 case DrawMode: emit activity(tr("Enter Draw mode")); break;
Chris@502 409 case EraseMode: emit activity(tr("Enter Erase mode")); break;
Chris@502 410 case MeasureMode: emit activity(tr("Enter Measure mode")); break;
gyorgyf@645 411 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 412 };
Chris@127 413 }
Chris@127 414
Chris@711 415 ViewManager::ToolMode
Chris@711 416 ViewManager::getToolModeFor(const View *v) const
Chris@711 417 {
Chris@711 418 if (m_toolModeOverrides.find(v) == m_toolModeOverrides.end()) {
Chris@711 419 return getToolMode();
Chris@711 420 } else {
Chris@711 421 return m_toolModeOverrides.find(v)->second;
Chris@711 422 }
Chris@711 423 }
Chris@711 424
Chris@711 425 void
Chris@711 426 ViewManager::setToolModeFor(const View *v, ToolMode mode)
Chris@711 427 {
Chris@711 428 m_toolModeOverrides[v] = mode;
Chris@711 429 }
Chris@711 430
Chris@711 431 void
Chris@711 432 ViewManager::clearToolModeOverrides()
Chris@711 433 {
Chris@711 434 m_toolModeOverrides.clear();
Chris@711 435 }
Chris@711 436
Chris@127 437 void
Chris@127 438 ViewManager::setPlayLoopMode(bool mode)
Chris@127 439 {
Chris@177 440 if (m_playLoopMode != mode) {
Chris@127 441
Chris@177 442 m_playLoopMode = mode;
Chris@177 443
Chris@177 444 emit playLoopModeChanged();
Chris@177 445 emit playLoopModeChanged(mode);
Chris@502 446
Chris@502 447 if (mode) emit activity(tr("Switch on Loop mode"));
Chris@502 448 else emit activity(tr("Switch off Loop mode"));
Chris@177 449 }
Chris@127 450 }
Chris@127 451
Chris@127 452 void
Chris@127 453 ViewManager::setPlaySelectionMode(bool mode)
Chris@127 454 {
Chris@177 455 if (m_playSelectionMode != mode) {
Chris@127 456
Chris@177 457 m_playSelectionMode = mode;
Chris@177 458
Chris@177 459 emit playSelectionModeChanged();
Chris@177 460 emit playSelectionModeChanged(mode);
Chris@502 461
Chris@502 462 if (mode) emit activity(tr("Switch on Play Selection mode"));
Chris@502 463 else emit activity(tr("Switch off Play Selection mode"));
Chris@177 464 }
Chris@127 465 }
Chris@127 466
Chris@301 467 void
Chris@301 468 ViewManager::setPlaySoloMode(bool mode)
Chris@301 469 {
Chris@301 470 if (m_playSoloMode != mode) {
Chris@301 471
Chris@301 472 m_playSoloMode = mode;
Chris@301 473
Chris@301 474 emit playSoloModeChanged();
Chris@301 475 emit playSoloModeChanged(mode);
Chris@502 476
Chris@502 477 if (mode) emit activity(tr("Switch on Play Solo mode"));
Chris@502 478 else emit activity(tr("Switch off Play Solo mode"));
Chris@301 479 }
Chris@301 480 }
Chris@301 481
Chris@314 482 void
Chris@314 483 ViewManager::setAlignMode(bool mode)
Chris@314 484 {
Chris@314 485 if (m_alignMode != mode) {
Chris@314 486
Chris@314 487 m_alignMode = mode;
Chris@314 488
Chris@314 489 emit alignModeChanged();
Chris@314 490 emit alignModeChanged(mode);
Chris@502 491
Chris@502 492 if (mode) emit activity(tr("Switch on Alignment mode"));
Chris@502 493 else emit activity(tr("Switch off Alignment mode"));
Chris@314 494 }
Chris@314 495 }
Chris@314 496
Chris@902 497 sv_samplerate_t
Chris@224 498 ViewManager::getPlaybackSampleRate() const
Chris@224 499 {
Chris@224 500 if (m_playSource) {
Chris@224 501 return m_playSource->getSourceSampleRate();
Chris@224 502 }
Chris@224 503 return 0;
Chris@224 504 }
Chris@224 505
Chris@902 506 sv_samplerate_t
Chris@1181 507 ViewManager::getDeviceSampleRate() const
Chris@127 508 {
Chris@127 509 if (m_playSource) {
Chris@1266 510 return m_playSource->getDeviceSampleRate();
Chris@127 511 }
Chris@127 512 return 0;
Chris@127 513 }
Chris@127 514
Chris@127 515 void
Chris@127 516 ViewManager::setAudioPlaySource(AudioPlaySource *source)
Chris@127 517 {
Chris@127 518 if (!m_playSource) {
Chris@1266 519 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
Chris@127 520 }
Chris@127 521 m_playSource = source;
Chris@127 522 }
Chris@127 523
Chris@127 524 void
Chris@1210 525 ViewManager::setAudioRecordTarget(AudioRecordTarget *target)
Chris@1210 526 {
Chris@1210 527 if (!m_recordTarget) {
Chris@1266 528 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
Chris@1210 529 }
Chris@1210 530 m_recordTarget = target;
Chris@1210 531 }
Chris@1210 532
Chris@1210 533 void
Chris@248 534 ViewManager::playStatusChanged(bool /* playing */)
Chris@127 535 {
Chris@689 536 #ifdef DEBUG_VIEW_MANAGER
Chris@689 537 cerr << "ViewManager::playStatusChanged" << endl;
Chris@689 538 #endif
Chris@127 539 checkPlayStatus();
Chris@127 540 }
Chris@127 541
Chris@127 542 void
Chris@1210 543 ViewManager::recordStatusChanged(bool /* recording */)
Chris@1210 544 {
Chris@1210 545 #ifdef DEBUG_VIEW_MANAGER
Chris@1210 546 cerr << "ViewManager::recordStatusChanged" << endl;
Chris@1210 547 #endif
Chris@1210 548 checkPlayStatus();
Chris@1210 549 }
Chris@1210 550
Chris@1210 551 void
Chris@127 552 ViewManager::checkPlayStatus()
Chris@127 553 {
Chris@1210 554 if (isRecording()) {
Chris@1210 555
Chris@1266 556 float left = 0, right = 0;
Chris@1266 557 if (m_recordTarget->getInputLevels(left, right)) {
Chris@1266 558 if (left != m_lastLeft || right != m_lastRight) {
Chris@1266 559 emit monitoringLevelsChanged(left, right);
Chris@1266 560 m_lastLeft = left;
Chris@1266 561 m_lastRight = right;
Chris@1266 562 }
Chris@1266 563 }
Chris@1210 564
Chris@1266 565 m_playbackFrame = m_recordTarget->getRecordDuration();
Chris@1210 566
Chris@1210 567 #ifdef DEBUG_VIEW_MANAGER
Chris@1266 568 cerr << "ViewManager::checkPlayStatus: Recording, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
Chris@1210 569 #endif
Chris@1210 570
Chris@1266 571 emit playbackFrameChanged(m_playbackFrame);
Chris@1210 572
Chris@1266 573 QTimer::singleShot(500, this, SLOT(checkPlayStatus()));
Chris@1210 574
Chris@1210 575 } else if (isPlaying()) {
Chris@127 576
Chris@1266 577 float left = 0, right = 0;
Chris@1266 578 if (m_playSource->getOutputLevels(left, right)) {
Chris@1266 579 if (left != m_lastLeft || right != m_lastRight) {
Chris@1266 580 emit monitoringLevelsChanged(left, right);
Chris@1266 581 m_lastLeft = left;
Chris@1266 582 m_lastRight = right;
Chris@1266 583 }
Chris@1266 584 }
Chris@127 585
Chris@1266 586 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 587
Chris@127 588 #ifdef DEBUG_VIEW_MANAGER
Chris@1266 589 cerr << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
Chris@127 590 #endif
Chris@127 591
Chris@1266 592 emit playbackFrameChanged(m_playbackFrame);
Chris@127 593
Chris@1266 594 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
Chris@127 595
Chris@127 596 } else {
Chris@127 597
Chris@1266 598 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
Chris@1266 599 emit monitoringLevelsChanged(0.0, 0.0);
Chris@1266 600 m_lastLeft = 0.0;
Chris@1266 601 m_lastRight = 0.0;
Chris@1266 602 }
Chris@127 603
Chris@127 604 #ifdef DEBUG_VIEW_MANAGER
Chris@1266 605 cerr << "ViewManager::checkPlayStatus: Not playing or recording" << endl;
Chris@127 606 #endif
Chris@127 607 }
Chris@127 608 }
Chris@127 609
Chris@127 610 bool
Chris@127 611 ViewManager::isPlaying() const
Chris@127 612 {
Chris@127 613 return m_playSource && m_playSource->isPlaying();
Chris@127 614 }
Chris@127 615
Chris@1210 616 bool
Chris@1210 617 ViewManager::isRecording() const
Chris@1210 618 {
Chris@1210 619 return m_recordTarget && m_recordTarget->isRecording();
Chris@1210 620 }
Chris@1210 621
Chris@127 622 void
Chris@902 623 ViewManager::viewCentreFrameChanged(sv_frame_t f, bool locked,
Chris@211 624 PlaybackFollowMode mode)
Chris@127 625 {
Chris@211 626 View *v = dynamic_cast<View *>(sender());
Chris@211 627
Chris@398 628 #ifdef DEBUG_VIEW_MANAGER
Chris@682 629 cerr << "ViewManager::viewCentreFrameChanged(" << f << ", " << locked << ", " << mode << "), view is " << v << endl;
Chris@398 630 #endif
Chris@394 631
Chris@127 632 if (locked) {
Chris@211 633 m_globalCentreFrame = f;
Chris@211 634 emit globalCentreFrameChanged(f);
Chris@211 635 } else {
Chris@211 636 if (v) emit viewCentreFrameChanged(v, f);
Chris@127 637 }
Chris@127 638
Chris@815 639 if (!dynamic_cast<Overview *>(v) || (mode != PlaybackIgnore)) {
Chris@527 640 if (m_mainModelSampleRate != 0) {
Chris@527 641 emit activity(tr("Scroll to %1")
Chris@527 642 .arg(RealTime::frame2RealTime
Chris@527 643 (f, m_mainModelSampleRate).toText().c_str()));
Chris@527 644 }
Chris@503 645 }
Chris@502 646
Chris@815 647 if (mode == PlaybackScrollPageWithCentre ||
Chris@815 648 mode == PlaybackScrollContinuous) {
Chris@815 649 seek(f);
Chris@211 650 }
Chris@211 651 }
Chris@211 652
Chris@211 653 void
Chris@902 654 ViewManager::seek(sv_frame_t f)
Chris@211 655 {
Chris@127 656 #ifdef DEBUG_VIEW_MANAGER
Chris@682 657 cerr << "ViewManager::seek(" << f << ")" << endl;
Chris@127 658 #endif
Chris@127 659
Chris@1210 660 if (isRecording()) {
Chris@1210 661 // ignore
Chris@1210 662 #ifdef DEBUG_VIEW_MANAGER
Chris@1210 663 cerr << "ViewManager::seek: Ignoring during recording" << endl;
Chris@1210 664 #endif
Chris@1210 665 return;
Chris@1210 666 }
Chris@1210 667
Chris@1210 668 if (isPlaying()) {
Chris@1266 669 sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame();
Chris@1266 670 sv_frame_t diff = std::max(f, playFrame) - std::min(f, playFrame);
Chris@1266 671 if (diff > 20000) {
Chris@1266 672 m_playbackFrame = f;
Chris@1266 673 m_playSource->play(f);
Chris@127 674 #ifdef DEBUG_VIEW_MANAGER
Chris@1266 675 cerr << "ViewManager::seek: reseeking from " << playFrame << " to " << f << endl;
Chris@127 676 #endif
Chris@211 677 emit playbackFrameChanged(f);
Chris@1266 678 }
Chris@127 679 } else {
Chris@211 680 if (m_playbackFrame != f) {
Chris@211 681 m_playbackFrame = f;
Chris@211 682 emit playbackFrameChanged(f);
Chris@211 683 }
Chris@127 684 }
Chris@127 685 }
Chris@127 686
Chris@127 687 void
Chris@1327 688 ViewManager::viewZoomLevelChanged(ZoomLevel z, bool locked)
Chris@127 689 {
Chris@222 690 View *v = dynamic_cast<View *>(sender());
Chris@222 691
Chris@222 692 if (!v) {
Chris@587 693 SVDEBUG << "ViewManager::viewZoomLevelChanged: WARNING: sender is not a view" << endl;
Chris@222 694 return;
Chris@222 695 }
Chris@222 696
Chris@222 697 //!!! emit zoomLevelChanged();
Chris@133 698
Chris@127 699 if (locked) {
Chris@1266 700 m_globalZoom = z;
Chris@127 701 }
Chris@127 702
Chris@127 703 #ifdef DEBUG_VIEW_MANAGER
Chris@682 704 cerr << "ViewManager::viewZoomLevelChanged(" << v << ", " << z << ", " << locked << ")" << endl;
Chris@127 705 #endif
Chris@222 706
Chris@222 707 emit viewZoomLevelChanged(v, z, locked);
Chris@503 708
Chris@503 709 if (!dynamic_cast<Overview *>(v)) {
Chris@1327 710 if (z.zone == ZoomLevel::FramesPerPixel) {
Chris@1327 711 emit activity(tr("Zoom to %n sample(s) per pixel", "", z.level));
Chris@1327 712 } else {
Chris@1327 713 emit activity(tr("Zoom to %n pixels per sample", "", z.level));
Chris@1327 714 }
Chris@503 715 }
Chris@127 716 }
Chris@127 717
Chris@127 718 void
Chris@127 719 ViewManager::setOverlayMode(OverlayMode mode)
Chris@127 720 {
Chris@127 721 if (m_overlayMode != mode) {
Chris@127 722 m_overlayMode = mode;
Chris@127 723 emit overlayModeChanged();
Chris@502 724 emit activity(tr("Change overlay level"));
Chris@127 725 }
Chris@133 726
Chris@133 727 QSettings settings;
Chris@133 728 settings.beginGroup("MainWindow");
Chris@133 729 settings.setValue("overlay-mode", int(m_overlayMode));
Chris@133 730 settings.endGroup();
Chris@127 731 }
Chris@127 732
Chris@133 733 void
Chris@133 734 ViewManager::setZoomWheelsEnabled(bool enabled)
Chris@133 735 {
Chris@133 736 if (m_zoomWheelsEnabled != enabled) {
Chris@133 737 m_zoomWheelsEnabled = enabled;
Chris@133 738 emit zoomWheelsEnabledChanged();
Chris@502 739 if (enabled) emit activity("Show zoom wheels");
Chris@502 740 else emit activity("Hide zoom wheels");
Chris@133 741 }
Chris@127 742
Chris@133 743 QSettings settings;
Chris@133 744 settings.beginGroup("MainWindow");
Chris@133 745 settings.setValue("zoom-wheels-enabled", m_zoomWheelsEnabled);
Chris@133 746 settings.endGroup();
Chris@133 747 }
Chris@133 748
Chris@292 749 void
Chris@1468 750 ViewManager::setOpportunisticEditingEnabled(bool enabled)
Chris@1468 751 {
Chris@1468 752 if (m_opportunisticEditingEnabled != enabled) {
Chris@1468 753 m_opportunisticEditingEnabled = enabled;
Chris@1468 754 emit opportunisticEditingEnabledChanged();
Chris@1468 755 }
Chris@1468 756 }
Chris@1468 757
Chris@1468 758 void
Chris@607 759 ViewManager::setShowCentreLine(bool show)
Chris@607 760 {
Chris@607 761 if (m_showCentreLine != show) {
Chris@607 762 m_showCentreLine = show;
Chris@607 763 emit showCentreLineChanged();
Chris@607 764 if (show) emit activity("Show centre line");
Chris@607 765 else emit activity("Hide centre line");
Chris@607 766 }
Chris@607 767
Chris@607 768 QSettings settings;
Chris@607 769 settings.beginGroup("MainWindow");
Chris@607 770 settings.setValue("show-centre-line", int(m_showCentreLine));
Chris@607 771 settings.endGroup();
Chris@607 772 }
Chris@607 773
Chris@607 774 void
Chris@292 775 ViewManager::setGlobalDarkBackground(bool dark)
Chris@292 776 {
Chris@292 777 // also save the current palette, in case the user has changed it
Chris@292 778 // since construction
Chris@292 779 if (getGlobalDarkBackground()) {
Chris@292 780 m_darkPalette = QApplication::palette();
Chris@292 781 } else {
Chris@292 782 m_lightPalette = QApplication::palette();
Chris@292 783 }
Chris@292 784
Chris@1574 785 #ifdef Q_OS_MAC
Chris@1574 786 return;
Chris@1574 787 #endif
Chris@1574 788
Chris@292 789 if (dark) {
Chris@1574 790
Chris@1574 791 #ifdef Q_OS_WIN32
Chris@1575 792 // The Windows Vista style doesn't use the palette for many of
Chris@1575 793 // its controls. They can be styled with stylesheets, but that
Chris@1575 794 // takes a lot of fiddly and fragile custom bits. Easier and
Chris@1575 795 // more reliable to switch to a non-Vista style which does use
Chris@1575 796 // the palette.
Chris@1574 797
Chris@1575 798 QStyle *plainWindowsStyle = QStyleFactory::create("windows");
Chris@1575 799 if (!plainWindowsStyle) {
Chris@1575 800 SVCERR << "Failed to load plain Windows style" << endl;
Chris@1575 801 } else {
Chris@1575 802 qApp->setStyle(plainWindowsStyle);
Chris@1574 803 }
Chris@1574 804 #endif
Chris@1574 805
Chris@292 806 QApplication::setPalette(m_darkPalette);
Chris@1574 807
Chris@292 808 } else {
Chris@1574 809
Chris@1574 810 #ifdef Q_OS_WIN32
Chris@1575 811 // Switch back to Vista style
Chris@1575 812
Chris@1575 813 QStyle *fancyWindowsStyle = QStyleFactory::create("windowsvista");
Chris@1575 814 if (!fancyWindowsStyle) {
Chris@1575 815 SVCERR << "Failed to load fancy Windows style" << endl;
Chris@1575 816 } else {
Chris@1575 817 qApp->setStyle(fancyWindowsStyle);
Chris@1575 818 }
Chris@1574 819 #endif
Chris@1574 820
Chris@292 821 QApplication::setPalette(m_lightPalette);
Chris@292 822 }
Chris@292 823 }
Chris@292 824
Chris@292 825 bool
Chris@292 826 ViewManager::getGlobalDarkBackground() const
Chris@292 827 {
Chris@292 828 bool dark = false;
Chris@292 829 QColor windowBg = QApplication::palette().color(QPalette::Window);
Chris@292 830 if (windowBg.red() + windowBg.green() + windowBg.blue() < 384) {
Chris@292 831 dark = true;
Chris@292 832 }
Chris@292 833 return dark;
Chris@292 834 }
Chris@292 835
Chris@894 836 int
Chris@894 837 ViewManager::scalePixelSize(int pixels)
Chris@894 838 {
Chris@908 839 static double ratio = 0.0;
Chris@908 840 if (ratio == 0.0) {
Chris@908 841 double baseEm;
Chris@894 842 #ifdef Q_OS_MAC
Chris@908 843 baseEm = 17.0;
Chris@894 844 #else
Chris@908 845 baseEm = 15.0;
Chris@894 846 #endif
Chris@908 847 double em = QFontMetrics(QFont()).height();
Chris@894 848 ratio = em / baseEm;
Chris@1224 849
Chris@1224 850 SVDEBUG << "ViewManager::scalePixelSize: ratio is " << ratio
Chris@1224 851 << " (em = " << em << ")" << endl;
Chris@894 852 }
Chris@894 853
Chris@894 854 int scaled = int(pixels * ratio + 0.5);
Chris@1273 855 // SVDEBUG << "scaledSize: " << pixels << " -> " << scaled << " at ratio " << ratio << endl;
Chris@894 856 if (pixels != 0 && scaled == 0) scaled = 1;
Chris@894 857 return scaled;
Chris@894 858 }
Chris@946 859