changeset 2466:2197ba438a3f background-mode

Add support for picking up overview colour from desktop theme
author Chris Cannam
date Fri, 24 Jan 2020 12:44:49 +0000
parents 3d8bbe7a900f
children a0d0657aabfc
files main/MainWindow.cpp main/PreferencesDialog.cpp main/PreferencesDialog.h
diffstat 3 files changed, 51 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/main/MainWindow.cpp	Fri Jan 24 12:44:37 2020 +0000
+++ b/main/MainWindow.cpp	Fri Jan 24 12:44:49 2020 +0000
@@ -196,7 +196,7 @@
     cdb->setUseDarkBackground(cdb->addColour(Qt::white, tr("White")), true);
     cdb->setUseDarkBackground(cdb->addColour(Qt::red, tr("Bright Red")), true);
     cdb->setUseDarkBackground(cdb->addColour(QColor(30, 150, 255), tr("Bright Blue")), true);
-    cdb->setUseDarkBackground(cdb->addColour(Qt::green, tr("Bright Green")), true);
+    cdb->setUseDarkBackground(cdb->addColour(QColor(20, 255, 90), tr("Bright Green")), true);
     cdb->setUseDarkBackground(cdb->addColour(QColor(225, 74, 255), tr("Bright Purple")), true);
     cdb->setUseDarkBackground(cdb->addColour(QColor(255, 188, 80), tr("Bright Orange")), true);
 
@@ -3913,17 +3913,27 @@
 {
     QSettings settings;
     settings.beginGroup("Preferences");
-    QString defaultColourName(tr("Green"));
-    if (m_viewManager && m_viewManager->getGlobalDarkBackground()) {
-        defaultColourName = tr("Bright Green");
-    }
+
+    bool haveDarkBackground = (m_viewManager &&
+                               m_viewManager->getGlobalDarkBackground());
+    QColor highlight = QApplication::palette().color(QPalette::Highlight);
     ColourDatabase *cdb = ColourDatabase::getInstance();
+    int nearestIndex = cdb->getNearbyColourIndex
+        (highlight,
+         haveDarkBackground ?
+         ColourDatabase::WithDarkBackground :
+         ColourDatabase::WithLightBackground);
+    QString defaultColourName = cdb->getColourName(nearestIndex);
+    
     QColor colour = QColor
         (settings.value("overview-colour",
                         cdb->getColour(defaultColourName).name()).toString());
     settings.endGroup();
 
     int index = cdb->getColourIndex(colour);
+
+    SVCERR << "MainWindow::coloursChanged: haveDarkBackground = " << haveDarkBackground << ", highlight = " << highlight.name() << ", nearestIndex = " << nearestIndex << ", defaultColourName = " << defaultColourName << ", colour = " << colour.name() << ", index = " << index << endl;
+
     if (index >= 0) {
         m_panLayer->setBaseColour(index);
     }
--- a/main/PreferencesDialog.cpp	Fri Jan 24 12:44:37 2020 +0000
+++ b/main/PreferencesDialog.cpp	Fri Jan 24 12:44:49 2020 +0000
@@ -149,12 +149,14 @@
                                            int(ColourMapper::Sunset)).toInt());
     m_colour3DColour = (settings.value("colour-3d-plot-colour",
                                        int(ColourMapper::Green)).toInt());
+    m_overviewColourIsSet = false;
     m_overviewColour = ColourDatabase::getInstance()->getColour(tr("Green"));
     if (settings.contains("overview-colour")) {
         QString qcolorName =
             settings.value("overview-colour", m_overviewColour.name())
             .toString();
         m_overviewColour.setNamedColor(qcolorName);
+        m_overviewColourIsSet = true;
         SVCERR << "loaded colour " << m_overviewColour.name() << " from settings" << endl;
     }
     settings.endGroup();
@@ -170,11 +172,15 @@
 
     // can't have "add new colour", as it gets saved in the session not in prefs
     m_overviewColourCombo = new ColourComboBox(false);
-    int overviewColourIndex =
-        ColourDatabase::getInstance()->getColourIndex(m_overviewColour);
-    SVCERR << "index = " << overviewColourIndex << " for colour " << m_overviewColour.name() << endl;
-    if (overviewColourIndex >= 0) {
-        m_overviewColourCombo->setCurrentIndex(overviewColourIndex);
+    m_overviewColourCombo->includeUnsetEntry(tr("Follow desktop theme"));
+    if (m_overviewColourIsSet) {
+        int overviewColourIndex =
+            ColourDatabase::getInstance()->getColourIndex(m_overviewColour);
+        if (overviewColourIndex >= 0) {
+            m_overviewColourCombo->setCurrentIndex(overviewColourIndex + 1);
+        }
+    } else {
+        m_overviewColourCombo->setCurrentIndex(0);
     }
 
     connect(spectrogramGColour, SIGNAL(colourMapChanged(int)),
@@ -747,7 +753,10 @@
 void
 PreferencesDialog::overviewColourChanged(int colour)
 {
-    m_overviewColour = ColourDatabase::getInstance()->getColour(colour);
+    m_overviewColourIsSet = (colour >= 0);
+    if (m_overviewColourIsSet) {
+        m_overviewColour = ColourDatabase::getInstance()->getColour(colour);
+    }
     m_coloursChanged = true;
     m_applyButton->setEnabled(true);
 }
@@ -889,18 +898,23 @@
     // (dark/light), also default the overview colour preference to
     // something sensible
     
-    int overviewColour = m_overviewColourCombo->currentIndex();
-    int plainColours = 6; // we happen to know there are 6 "light" and 6 "dark"
+    int overviewColour = m_overviewColourCombo->getCurrentColourIndex();
+
+    if (overviewColour >= 0) {
+        int plainColours = 6; // we happen to know there are 6 light and 6 dark
     
-    if (mode == Preferences::DarkBackground && overviewColour < plainColours) {
-        overviewColour += plainColours;
+        if (mode == Preferences::DarkBackground &&
+            overviewColour < plainColours) {
+            overviewColour += plainColours;
+        }
+        if (mode == Preferences::LightBackground &&
+            overviewColour >= plainColours) {
+            overviewColour -= plainColours;
+        }
+
+        m_overviewColourCombo->setCurrentIndex(overviewColour + 1);
+        overviewColourChanged(overviewColour);
     }
-    if (mode == Preferences::LightBackground && overviewColour >= plainColours) {
-        overviewColour -= plainColours;
-    }
-
-    m_overviewColourCombo->setCurrentIndex(overviewColour);
-    overviewColourChanged(overviewColour);
 }
 
 void
@@ -1016,7 +1030,11 @@
     settings.setValue("spectrogram-colour", m_spectrogramGColour);
     settings.setValue("spectrogram-melodic-colour", m_spectrogramMColour);
     settings.setValue("colour-3d-plot-colour", m_colour3DColour);
-    settings.setValue("overview-colour", m_overviewColour.name());
+    if (m_overviewColourIsSet) {
+        settings.setValue("overview-colour", m_overviewColour.name());
+    } else {
+        settings.remove("overview-colour");
+    }
     settings.endGroup();
 
     settings.beginGroup("MainWindow");
--- a/main/PreferencesDialog.h	Fri Jan 24 12:44:37 2020 +0000
+++ b/main/PreferencesDialog.h	Fri Jan 24 12:44:49 2020 +0000
@@ -118,6 +118,7 @@
     int m_spectrogramGColour;
     int m_spectrogramMColour;
     int m_colour3DColour;
+    bool m_overviewColourIsSet;
     QColor m_overviewColour;
     int m_propertyLayout;
     double m_tuningFrequency;