annotate view/ViewManager.cpp @ 298:226cb289bdf4

* Layer tree view updating when visibility / audibility changed (and layers updating when they are changed in view) -- still some problems when a model is loaded while the tree is visible * FFTW_MEASURE throughout -- it does turn out to make an appreciable difference sometimes
author Chris Cannam
date Thu, 16 Aug 2007 16:47:07 +0000
parents 15b8a4bfe855
children 5636eeacc467
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@128 18 #include "data/model/Model.h"
Chris@128 19 #include "base/CommandHistory.h"
Chris@211 20 #include "View.h"
Chris@127 21
Chris@133 22 #include <QSettings>
Chris@292 23 #include <QApplication>
Chris@133 24
Chris@127 25 #include <iostream>
Chris@127 26
Chris@180 27 //#define DEBUG_VIEW_MANAGER 1
Chris@127 28
Chris@127 29 ViewManager::ViewManager() :
Chris@127 30 m_playSource(0),
Chris@127 31 m_globalCentreFrame(0),
Chris@127 32 m_globalZoom(1024),
Chris@127 33 m_playbackFrame(0),
Chris@127 34 m_mainModelSampleRate(0),
Chris@127 35 m_lastLeft(0),
Chris@127 36 m_lastRight(0),
Chris@127 37 m_inProgressExclusive(true),
Chris@127 38 m_toolMode(NavigateMode),
Chris@127 39 m_playLoopMode(false),
Chris@127 40 m_playSelectionMode(false),
Chris@189 41 m_overlayMode(StandardOverlays),
Chris@292 42 m_zoomWheelsEnabled(true),
Chris@292 43 m_lightPalette(QApplication::palette()),
Chris@292 44 m_darkPalette(QApplication::palette())
Chris@127 45 {
Chris@133 46 QSettings settings;
Chris@133 47 settings.beginGroup("MainWindow");
Chris@133 48 m_overlayMode = OverlayMode
Chris@133 49 (settings.value("overlay-mode", int(m_overlayMode)).toInt());
Chris@133 50 m_zoomWheelsEnabled =
Chris@133 51 settings.value("zoom-wheels-enabled", m_zoomWheelsEnabled).toBool();
Chris@133 52 settings.endGroup();
Chris@292 53
Chris@292 54 if (getGlobalDarkBackground()) {
Chris@293 55
Chris@293 56 std::cerr << "dark palette:" << std::endl;
Chris@293 57 std::cerr << "window = " << QApplication::palette().color(QPalette::Window).name().toStdString() << std::endl;
Chris@293 58 std::cerr << "windowtext = " << QApplication::palette().color(QPalette::WindowText).name().toStdString() << std::endl;
Chris@293 59 std::cerr << "base = " << QApplication::palette().color(QPalette::Base).name().toStdString() << std::endl;
Chris@293 60 std::cerr << "alternatebase = " << QApplication::palette().color(QPalette::AlternateBase).name().toStdString() << std::endl;
Chris@293 61 std::cerr << "text = " << QApplication::palette().color(QPalette::Text).name().toStdString() << std::endl;
Chris@293 62 std::cerr << "button = " << QApplication::palette().color(QPalette::Button).name().toStdString() << std::endl;
Chris@293 63 std::cerr << "buttontext = " << QApplication::palette().color(QPalette::ButtonText).name().toStdString() << std::endl;
Chris@293 64 std::cerr << "brighttext = " << QApplication::palette().color(QPalette::BrightText).name().toStdString() << std::endl;
Chris@293 65 std::cerr << "light = " << QApplication::palette().color(QPalette::Light).name().toStdString() << std::endl;
Chris@293 66 std::cerr << "dark = " << QApplication::palette().color(QPalette::Dark).name().toStdString() << std::endl;
Chris@293 67 std::cerr << "mid = " << QApplication::palette().color(QPalette::Mid).name().toStdString() << std::endl;
Chris@293 68
Chris@293 69 m_lightPalette = QPalette(QColor("#000000"), // WindowText
Chris@293 70 QColor("#dddfe4"), // Button
Chris@293 71 QColor("#ffffff"), // Light
Chris@293 72 QColor("#555555"), // Dark
Chris@293 73 QColor("#c7c7c7"), // Mid
Chris@293 74 QColor("#000000"), // Text
Chris@293 75 QColor("#ffffff"), // BrightText
Chris@293 76 QColor("#ffffff"), // Base
Chris@293 77 QColor("#efefef")); // Window
Chris@293 78
Chris@293 79
Chris@292 80 } else {
Chris@293 81 std::cerr << "light palette:" << std::endl;
Chris@293 82 std::cerr << "window = " << QApplication::palette().color(QPalette::Window).name().toStdString() << std::endl;
Chris@293 83 std::cerr << "windowtext = " << QApplication::palette().color(QPalette::WindowText).name().toStdString() << std::endl;
Chris@293 84 std::cerr << "base = " << QApplication::palette().color(QPalette::Base).name().toStdString() << std::endl;
Chris@293 85 std::cerr << "alternatebase = " << QApplication::palette().color(QPalette::AlternateBase).name().toStdString() << std::endl;
Chris@293 86 std::cerr << "text = " << QApplication::palette().color(QPalette::Text).name().toStdString() << std::endl;
Chris@293 87 std::cerr << "button = " << QApplication::palette().color(QPalette::Button).name().toStdString() << std::endl;
Chris@293 88 std::cerr << "buttontext = " << QApplication::palette().color(QPalette::ButtonText).name().toStdString() << std::endl;
Chris@293 89 std::cerr << "brighttext = " << QApplication::palette().color(QPalette::BrightText).name().toStdString() << std::endl;
Chris@293 90 std::cerr << "light = " << QApplication::palette().color(QPalette::Light).name().toStdString() << std::endl;
Chris@293 91 std::cerr << "dark = " << QApplication::palette().color(QPalette::Dark).name().toStdString() << std::endl;
Chris@293 92 std::cerr << "mid = " << QApplication::palette().color(QPalette::Mid).name().toStdString() << std::endl;
Chris@293 93
Chris@293 94 m_darkPalette = QPalette(QColor("#ffffff"), // WindowText
Chris@293 95 QColor("#3e3e3e"), // Button
Chris@293 96 QColor("#808080"), // Light
Chris@293 97 QColor("#1e1e1e"), // Dark
Chris@293 98 QColor("#404040"), // Mid
Chris@293 99 QColor("#ffffff"), // Text
Chris@293 100 QColor("#ffffff"), // BrightText
Chris@293 101 QColor("#000000"), // Base
Chris@293 102 QColor("#202020")); // Window
Chris@292 103 }
Chris@127 104 }
Chris@127 105
Chris@127 106 ViewManager::~ViewManager()
Chris@127 107 {
Chris@127 108 }
Chris@127 109
Chris@127 110 unsigned long
Chris@127 111 ViewManager::getGlobalCentreFrame() const
Chris@127 112 {
Chris@127 113 #ifdef DEBUG_VIEW_MANAGER
Chris@127 114 std::cout << "ViewManager::getGlobalCentreFrame: returning " << m_globalCentreFrame << std::endl;
Chris@127 115 #endif
Chris@127 116 return m_globalCentreFrame;
Chris@127 117 }
Chris@127 118
Chris@180 119 void
Chris@180 120 ViewManager::setGlobalCentreFrame(unsigned long f)
Chris@180 121 {
Chris@180 122 #ifdef DEBUG_VIEW_MANAGER
Chris@180 123 std::cout << "ViewManager::setGlobalCentreFrame to " << f << std::endl;
Chris@180 124 #endif
Chris@180 125 m_globalCentreFrame = f;
Chris@211 126 emit globalCentreFrameChanged(f);
Chris@180 127 }
Chris@180 128
Chris@127 129 unsigned long
Chris@127 130 ViewManager::getGlobalZoom() const
Chris@127 131 {
Chris@127 132 #ifdef DEBUG_VIEW_MANAGER
Chris@127 133 std::cout << "ViewManager::getGlobalZoom: returning " << m_globalZoom << std::endl;
Chris@127 134 #endif
Chris@127 135 return m_globalZoom;
Chris@127 136 }
Chris@127 137
Chris@127 138 unsigned long
Chris@127 139 ViewManager::getPlaybackFrame() const
Chris@127 140 {
Chris@127 141 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 142 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 143 }
Chris@127 144 return m_playbackFrame;
Chris@127 145 }
Chris@127 146
Chris@127 147 void
Chris@127 148 ViewManager::setPlaybackFrame(unsigned long f)
Chris@127 149 {
Chris@127 150 if (m_playbackFrame != f) {
Chris@127 151 m_playbackFrame = f;
Chris@127 152 emit playbackFrameChanged(f);
Chris@127 153 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 154 m_playSource->play(f);
Chris@127 155 }
Chris@127 156 }
Chris@127 157 }
Chris@127 158
Chris@127 159 bool
Chris@127 160 ViewManager::haveInProgressSelection() const
Chris@127 161 {
Chris@127 162 return !m_inProgressSelection.isEmpty();
Chris@127 163 }
Chris@127 164
Chris@127 165 const Selection &
Chris@127 166 ViewManager::getInProgressSelection(bool &exclusive) const
Chris@127 167 {
Chris@127 168 exclusive = m_inProgressExclusive;
Chris@127 169 return m_inProgressSelection;
Chris@127 170 }
Chris@127 171
Chris@127 172 void
Chris@127 173 ViewManager::setInProgressSelection(const Selection &selection, bool exclusive)
Chris@127 174 {
Chris@127 175 m_inProgressExclusive = exclusive;
Chris@127 176 m_inProgressSelection = selection;
Chris@127 177 if (exclusive) clearSelections();
Chris@127 178 emit inProgressSelectionChanged();
Chris@127 179 }
Chris@127 180
Chris@127 181 void
Chris@127 182 ViewManager::clearInProgressSelection()
Chris@127 183 {
Chris@127 184 m_inProgressSelection = Selection();
Chris@127 185 emit inProgressSelectionChanged();
Chris@127 186 }
Chris@127 187
Chris@127 188 const MultiSelection &
Chris@127 189 ViewManager::getSelection() const
Chris@127 190 {
Chris@127 191 return m_selections;
Chris@127 192 }
Chris@127 193
Chris@127 194 const MultiSelection::SelectionList &
Chris@127 195 ViewManager::getSelections() const
Chris@127 196 {
Chris@127 197 return m_selections.getSelections();
Chris@127 198 }
Chris@127 199
Chris@127 200 void
Chris@127 201 ViewManager::setSelection(const Selection &selection)
Chris@127 202 {
Chris@127 203 MultiSelection ms(m_selections);
Chris@127 204 ms.setSelection(selection);
Chris@127 205 setSelections(ms);
Chris@127 206 }
Chris@127 207
Chris@127 208 void
Chris@127 209 ViewManager::addSelection(const Selection &selection)
Chris@127 210 {
Chris@127 211 MultiSelection ms(m_selections);
Chris@127 212 ms.addSelection(selection);
Chris@127 213 setSelections(ms);
Chris@127 214 }
Chris@127 215
Chris@127 216 void
Chris@127 217 ViewManager::removeSelection(const Selection &selection)
Chris@127 218 {
Chris@127 219 MultiSelection ms(m_selections);
Chris@127 220 ms.removeSelection(selection);
Chris@127 221 setSelections(ms);
Chris@127 222 }
Chris@127 223
Chris@127 224 void
Chris@127 225 ViewManager::clearSelections()
Chris@127 226 {
Chris@127 227 MultiSelection ms(m_selections);
Chris@127 228 ms.clearSelections();
Chris@127 229 setSelections(ms);
Chris@127 230 }
Chris@127 231
Chris@127 232 void
Chris@127 233 ViewManager::setSelections(const MultiSelection &ms)
Chris@127 234 {
Chris@127 235 if (m_selections.getSelections() == ms.getSelections()) return;
Chris@127 236 SetSelectionCommand *command = new SetSelectionCommand(this, ms);
Chris@127 237 CommandHistory::getInstance()->addCommand(command);
Chris@127 238 }
Chris@127 239
Chris@271 240 size_t
Chris@271 241 ViewManager::constrainFrameToSelection(size_t frame) const
Chris@271 242 {
Chris@271 243 MultiSelection::SelectionList sl = getSelections();
Chris@271 244 if (sl.empty()) return frame;
Chris@271 245
Chris@271 246 size_t selectionStartFrame = sl.begin()->getStartFrame();
Chris@271 247 if (frame < selectionStartFrame) {
Chris@271 248 frame = selectionStartFrame;
Chris@271 249 return frame;
Chris@271 250 }
Chris@271 251
Chris@271 252 MultiSelection::SelectionList::iterator i = sl.end();
Chris@271 253 --i;
Chris@271 254 size_t selectionEndFrame = i->getEndFrame();
Chris@271 255 if (frame > selectionEndFrame) frame = selectionEndFrame;
Chris@271 256
Chris@271 257 return frame;
Chris@271 258 }
Chris@271 259
Chris@127 260 void
Chris@127 261 ViewManager::signalSelectionChange()
Chris@127 262 {
Chris@127 263 emit selectionChanged();
Chris@127 264 }
Chris@127 265
Chris@127 266 ViewManager::SetSelectionCommand::SetSelectionCommand(ViewManager *vm,
Chris@127 267 const MultiSelection &ms) :
Chris@127 268 m_vm(vm),
Chris@127 269 m_oldSelection(vm->m_selections),
Chris@127 270 m_newSelection(ms)
Chris@127 271 {
Chris@127 272 }
Chris@127 273
Chris@127 274 ViewManager::SetSelectionCommand::~SetSelectionCommand() { }
Chris@127 275
Chris@127 276 void
Chris@127 277 ViewManager::SetSelectionCommand::execute()
Chris@127 278 {
Chris@127 279 m_vm->m_selections = m_newSelection;
Chris@127 280 m_vm->signalSelectionChange();
Chris@127 281 }
Chris@127 282
Chris@127 283 void
Chris@127 284 ViewManager::SetSelectionCommand::unexecute()
Chris@127 285 {
Chris@127 286 m_vm->m_selections = m_oldSelection;
Chris@127 287 m_vm->signalSelectionChange();
Chris@127 288 }
Chris@127 289
Chris@127 290 QString
Chris@127 291 ViewManager::SetSelectionCommand::getName() const
Chris@127 292 {
Chris@127 293 if (m_newSelection.getSelections().empty()) return tr("Clear Selection");
Chris@127 294 else return tr("Select");
Chris@127 295 }
Chris@127 296
Chris@127 297 Selection
Chris@127 298 ViewManager::getContainingSelection(size_t frame, bool defaultToFollowing) const
Chris@127 299 {
Chris@127 300 return m_selections.getContainingSelection(frame, defaultToFollowing);
Chris@127 301 }
Chris@127 302
Chris@127 303 void
Chris@127 304 ViewManager::setToolMode(ToolMode mode)
Chris@127 305 {
Chris@127 306 m_toolMode = mode;
Chris@127 307
Chris@127 308 emit toolModeChanged();
Chris@127 309 }
Chris@127 310
Chris@127 311 void
Chris@127 312 ViewManager::setPlayLoopMode(bool mode)
Chris@127 313 {
Chris@177 314 if (m_playLoopMode != mode) {
Chris@127 315
Chris@177 316 m_playLoopMode = mode;
Chris@177 317
Chris@177 318 emit playLoopModeChanged();
Chris@177 319 emit playLoopModeChanged(mode);
Chris@177 320 }
Chris@127 321 }
Chris@127 322
Chris@127 323 void
Chris@127 324 ViewManager::setPlaySelectionMode(bool mode)
Chris@127 325 {
Chris@177 326 if (m_playSelectionMode != mode) {
Chris@127 327
Chris@177 328 m_playSelectionMode = mode;
Chris@177 329
Chris@177 330 emit playSelectionModeChanged();
Chris@177 331 emit playSelectionModeChanged(mode);
Chris@177 332 }
Chris@127 333 }
Chris@127 334
Chris@224 335 size_t
Chris@224 336 ViewManager::getPlaybackSampleRate() const
Chris@224 337 {
Chris@224 338 if (m_playSource) {
Chris@224 339 return m_playSource->getSourceSampleRate();
Chris@224 340 }
Chris@224 341 return 0;
Chris@224 342 }
Chris@224 343
Chris@127 344 size_t
Chris@224 345 ViewManager::getOutputSampleRate() const
Chris@127 346 {
Chris@127 347 if (m_playSource) {
Chris@127 348 return m_playSource->getTargetSampleRate();
Chris@127 349 }
Chris@127 350 return 0;
Chris@127 351 }
Chris@127 352
Chris@127 353 void
Chris@127 354 ViewManager::setAudioPlaySource(AudioPlaySource *source)
Chris@127 355 {
Chris@127 356 if (!m_playSource) {
Chris@127 357 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
Chris@127 358 }
Chris@127 359 m_playSource = source;
Chris@127 360 }
Chris@127 361
Chris@127 362 void
Chris@248 363 ViewManager::playStatusChanged(bool /* playing */)
Chris@127 364 {
Chris@127 365 checkPlayStatus();
Chris@127 366 }
Chris@127 367
Chris@127 368 void
Chris@127 369 ViewManager::checkPlayStatus()
Chris@127 370 {
Chris@127 371 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 372
Chris@127 373 float left = 0, right = 0;
Chris@127 374 if (m_playSource->getOutputLevels(left, right)) {
Chris@127 375 if (left != m_lastLeft || right != m_lastRight) {
Chris@127 376 emit outputLevelsChanged(left, right);
Chris@127 377 m_lastLeft = left;
Chris@127 378 m_lastRight = right;
Chris@127 379 }
Chris@127 380 }
Chris@127 381
Chris@127 382 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 383
Chris@127 384 #ifdef DEBUG_VIEW_MANAGER
Chris@127 385 std::cout << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << std::endl;
Chris@127 386 #endif
Chris@127 387
Chris@127 388 emit playbackFrameChanged(m_playbackFrame);
Chris@127 389
Chris@127 390 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
Chris@127 391
Chris@127 392 } else {
Chris@127 393
Chris@127 394 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
Chris@127 395
Chris@127 396 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
Chris@127 397 emit outputLevelsChanged(0.0, 0.0);
Chris@127 398 m_lastLeft = 0.0;
Chris@127 399 m_lastRight = 0.0;
Chris@127 400 }
Chris@127 401
Chris@127 402 #ifdef DEBUG_VIEW_MANAGER
Chris@127 403 // std::cout << "ViewManager::checkPlayStatus: Not playing" << std::endl;
Chris@127 404 #endif
Chris@127 405 }
Chris@127 406 }
Chris@127 407
Chris@127 408 bool
Chris@127 409 ViewManager::isPlaying() const
Chris@127 410 {
Chris@127 411 return m_playSource && m_playSource->isPlaying();
Chris@127 412 }
Chris@127 413
Chris@127 414 void
Chris@211 415 ViewManager::viewCentreFrameChanged(unsigned long f, bool locked,
Chris@211 416 PlaybackFollowMode mode)
Chris@127 417 {
Chris@211 418 View *v = dynamic_cast<View *>(sender());
Chris@211 419
Chris@127 420 if (locked) {
Chris@211 421 m_globalCentreFrame = f;
Chris@211 422 emit globalCentreFrameChanged(f);
Chris@211 423 } else {
Chris@211 424 if (v) emit viewCentreFrameChanged(v, f);
Chris@127 425 }
Chris@127 426
Chris@211 427 if (mode == PlaybackIgnore) {
Chris@211 428 return;
Chris@211 429 }
Chris@211 430
Chris@211 431 seek(f);
Chris@211 432 }
Chris@211 433
Chris@211 434 void
Chris@211 435 ViewManager::seek(unsigned long f)
Chris@211 436 {
Chris@127 437 #ifdef DEBUG_VIEW_MANAGER
Chris@211 438 std::cout << "ViewManager::seek(" << f << ")" << std::endl;
Chris@127 439 #endif
Chris@127 440
Chris@127 441 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 442 unsigned long playFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 443 unsigned long diff = std::max(f, playFrame) - std::min(f, playFrame);
Chris@127 444 if (diff > 20000) {
Chris@127 445 m_playbackFrame = f;
Chris@127 446 m_playSource->play(f);
Chris@127 447 #ifdef DEBUG_VIEW_MANAGER
Chris@127 448 std::cout << "ViewManager::considerSeek: reseeking from " << playFrame << " to " << f << std::endl;
Chris@127 449 #endif
Chris@211 450 emit playbackFrameChanged(f);
Chris@127 451 }
Chris@127 452 } else {
Chris@211 453 if (m_playbackFrame != f) {
Chris@211 454 m_playbackFrame = f;
Chris@211 455 emit playbackFrameChanged(f);
Chris@211 456 }
Chris@127 457 }
Chris@127 458 }
Chris@127 459
Chris@127 460 void
Chris@222 461 ViewManager::viewZoomLevelChanged(unsigned long z, bool locked)
Chris@127 462 {
Chris@222 463 View *v = dynamic_cast<View *>(sender());
Chris@222 464
Chris@222 465 if (!v) {
Chris@222 466 std::cerr << "ViewManager::viewZoomLevelChanged: WARNING: sender is not a view" << std::endl;
Chris@222 467 return;
Chris@222 468 }
Chris@222 469
Chris@222 470 //!!! emit zoomLevelChanged();
Chris@133 471
Chris@127 472 if (locked) {
Chris@127 473 m_globalZoom = z;
Chris@127 474 }
Chris@127 475
Chris@127 476 #ifdef DEBUG_VIEW_MANAGER
Chris@222 477 std::cout << "ViewManager::viewZoomLevelChanged(" << v << ", " << z << ", " << locked << ")" << std::endl;
Chris@127 478 #endif
Chris@222 479
Chris@222 480 emit viewZoomLevelChanged(v, z, locked);
Chris@127 481 }
Chris@127 482
Chris@127 483 void
Chris@127 484 ViewManager::setOverlayMode(OverlayMode mode)
Chris@127 485 {
Chris@127 486 if (m_overlayMode != mode) {
Chris@127 487 m_overlayMode = mode;
Chris@127 488 emit overlayModeChanged();
Chris@127 489 }
Chris@133 490
Chris@133 491 QSettings settings;
Chris@133 492 settings.beginGroup("MainWindow");
Chris@133 493 settings.setValue("overlay-mode", int(m_overlayMode));
Chris@133 494 settings.endGroup();
Chris@127 495 }
Chris@127 496
Chris@133 497 void
Chris@133 498 ViewManager::setZoomWheelsEnabled(bool enabled)
Chris@133 499 {
Chris@133 500 if (m_zoomWheelsEnabled != enabled) {
Chris@133 501 m_zoomWheelsEnabled = enabled;
Chris@133 502 emit zoomWheelsEnabledChanged();
Chris@133 503 }
Chris@127 504
Chris@133 505 QSettings settings;
Chris@133 506 settings.beginGroup("MainWindow");
Chris@133 507 settings.setValue("zoom-wheels-enabled", m_zoomWheelsEnabled);
Chris@133 508 settings.endGroup();
Chris@133 509 }
Chris@133 510
Chris@292 511 void
Chris@292 512 ViewManager::setGlobalDarkBackground(bool dark)
Chris@292 513 {
Chris@292 514 // also save the current palette, in case the user has changed it
Chris@292 515 // since construction
Chris@292 516 if (getGlobalDarkBackground()) {
Chris@292 517 m_darkPalette = QApplication::palette();
Chris@292 518 } else {
Chris@292 519 m_lightPalette = QApplication::palette();
Chris@292 520 }
Chris@292 521
Chris@292 522 if (dark) {
Chris@292 523 QApplication::setPalette(m_darkPalette);
Chris@292 524 } else {
Chris@292 525 QApplication::setPalette(m_lightPalette);
Chris@292 526 }
Chris@292 527 }
Chris@292 528
Chris@292 529 bool
Chris@292 530 ViewManager::getGlobalDarkBackground() const
Chris@292 531 {
Chris@292 532 bool dark = false;
Chris@292 533 QColor windowBg = QApplication::palette().color(QPalette::Window);
Chris@292 534 if (windowBg.red() + windowBg.green() + windowBg.blue() < 384) {
Chris@292 535 dark = true;
Chris@292 536 }
Chris@292 537 return dark;
Chris@292 538 }
Chris@292 539