From 5d70f9f0788956cc7b4859c8625ba6ccfd075764 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Sat, 2 May 2020 14:29:04 +0200 Subject: [PATCH] add a dark_theme flag to the mupp_startup.xml. This is can help if mupp at runtime cannot decide on the used theme. --- src/musredit_qt5/mupp/PmuppAdmin.cpp | 10 +++++++++- src/musredit_qt5/mupp/PmuppAdmin.h | 8 +++++++- src/musredit_qt5/mupp/PmuppGui.cpp | 10 ++++++++++ src/musredit_qt5/mupp/mupp_startup.xml.in | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/musredit_qt5/mupp/PmuppAdmin.cpp b/src/musredit_qt5/mupp/PmuppAdmin.cpp index 459fbabd..b1c55301 100644 --- a/src/musredit_qt5/mupp/PmuppAdmin.cpp +++ b/src/musredit_qt5/mupp/PmuppAdmin.cpp @@ -109,6 +109,8 @@ bool PmuppAdminXMLParser::startElement( const QString&, const QString&, { if (qName == "path_file_name") { fKeyWord = eRecentFile; + } else if (qName == "dark_theme") { + fKeyWord = eDarkTheme; } else if (qName == "marker") { fKeyWord = eMarker; } else if (qName == "color") { @@ -152,6 +154,12 @@ bool PmuppAdminXMLParser::characters(const QString& str) case eRecentFile: fAdmin->addRecentFile(QString(str.toLatin1()).trimmed()); break; + case eDarkTheme: + if ((str == "yes") || (str == "1") || (str == "true")) + fAdmin->setTheme(true); + else + fAdmin->setTheme(false); + break; case eMarker: tok = str.split(",", QString::SkipEmptyParts); @@ -277,7 +285,7 @@ bool PmuppAdminXMLParser::fatalError( const QXmlParseException & exception ) *

Initializes that PmuppAdmin object, and calls the XML parser which feeds * the object variables. */ -PmuppAdmin::PmuppAdmin() : QObject() +PmuppAdmin::PmuppAdmin() : QObject(), fDarkTheme(false) { // XML Parser part // 1st: check local directory diff --git a/src/musredit_qt5/mupp/PmuppAdmin.h b/src/musredit_qt5/mupp/PmuppAdmin.h index 8238b2a1..5f831e27 100644 --- a/src/musredit_qt5/mupp/PmuppAdmin.h +++ b/src/musredit_qt5/mupp/PmuppAdmin.h @@ -98,7 +98,7 @@ class PmuppAdminXMLParser : public QXmlDefaultHandler virtual ~PmuppAdminXMLParser() {} private: - enum EAdminKeyWords {eEmpty, eRecentFile, eMarker, eColor}; + enum EAdminKeyWords {eEmpty, eRecentFile, eDarkTheme, eMarker, eColor}; bool startDocument(); bool startElement( const QString&, const QString&, const QString& , @@ -133,6 +133,8 @@ class PmuppAdmin : public QObject int getNumRecentFiles() { return fRecentFile.size(); } QString getRecentFile(int idx); + + int getNoOfMarkers() { return fMarker.size(); } QVector getMarkers() { return fMarker; } PmuppMarker getMarker(int idx); @@ -142,6 +144,9 @@ class PmuppAdmin : public QObject void getColor(QString name, int &r, int &g, int &b); void getColor(int idx, int &r, int &g, int &b); + bool isDarkTheme() { return fDarkTheme; } + + void setTheme(bool theme) { fDarkTheme = theme; } void setMarker(int marker, double size); void setColor(int r, int g, int b, QString name=""); @@ -150,6 +155,7 @@ class PmuppAdmin : public QObject QVector fRecentFile; ///< keep vector of recent path-file names + bool fDarkTheme; QVector fMarker; QVector fColor; diff --git a/src/musredit_qt5/mupp/PmuppGui.cpp b/src/musredit_qt5/mupp/PmuppGui.cpp index 3fa3c223..fc62be8f 100644 --- a/src/musredit_qt5/mupp/PmuppGui.cpp +++ b/src/musredit_qt5/mupp/PmuppGui.cpp @@ -827,6 +827,14 @@ void PmuppGui::getTheme() QString str = QIcon::themeName(); + if (str.isEmpty()) { + if (fAdmin->isDarkTheme()) { + fDarkTheme = true; + fDarkToolBarIcon = true; + } + return; + } + if (str.contains("dark", Qt::CaseInsensitive)) { fDarkTheme = true; if (str.contains("ubuntu", Qt::CaseInsensitive)) { @@ -835,6 +843,8 @@ void PmuppGui::getTheme() fDarkToolBarIcon = true; } } + + QMessageBox::information(0, "INFO", QString("str='%1', fDarkTheme=%2").arg(str).arg(fDarkTheme)); } //---------------------------------------------------------------------------------------------------- diff --git a/src/musredit_qt5/mupp/mupp_startup.xml.in b/src/musredit_qt5/mupp/mupp_startup.xml.in index 365e94d1..f7e218c3 100644 --- a/src/musredit_qt5/mupp/mupp_startup.xml.in +++ b/src/musredit_qt5/mupp/mupp_startup.xml.in @@ -5,6 +5,7 @@ + no