annotate view/ViewManager.cpp @ 1574:dd7166cdf6bc background-mode

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