improved dark theme handling on mupp for qt5.

This commit is contained in:
suter_a 2025-03-29 20:54:03 +01:00
parent 71de742840
commit 6c82e88789
6 changed files with 73 additions and 40 deletions

View File

@ -156,8 +156,12 @@ bool PmuppAdminXMLParser::startElement()
if (qName == "path_file_name") { if (qName == "path_file_name") {
fKeyWord = eRecentFile; fKeyWord = eRecentFile;
} else if (qName == "dark_theme") { } else if (qName == "ignore_theme_auto_detection") {
fKeyWord = eDarkTheme; fKeyWord = eIgnoreThemeAutoDetection;
} else if (qName == "dark_theme_icons_menu") {
fKeyWord = eDarkThemeIconsMenu;
} else if (qName == "dark_theme_icons_toolbar") {
fKeyWord = eDarkThemeIconsToolbar;
} else if (qName == "marker") { } else if (qName == "marker") {
fKeyWord = eMarker; fKeyWord = eMarker;
} else if (qName == "color") { } else if (qName == "color") {
@ -201,11 +205,23 @@ bool PmuppAdminXMLParser::characters()
case eRecentFile: case eRecentFile:
fAdmin->addRecentFile(QString(str.toLatin1()).trimmed()); fAdmin->addRecentFile(QString(str.toLatin1()).trimmed());
break; break;
case eDarkTheme: case eIgnoreThemeAutoDetection:
if ((str == "yes") || (str == "1") || (str == "true")) if ((str == "yes") || (str == "y") || (str == "1") || (str == "true"))
fAdmin->setTheme(true); fAdmin->setIgnoreThemeAutoDetection(true);
else else
fAdmin->setTheme(false); fAdmin->setIgnoreThemeAutoDetection(false);
break;
case eDarkThemeIconsMenu:
if ((str == "yes") || (str == "y") || (str == "1") || (str == "true"))
fAdmin->setThemeIconsMenu(true);
else
fAdmin->setThemeIconsMenu(false);
break;
case eDarkThemeIconsToolbar:
if ((str == "yes") || (str == "y") || (str == "1") || (str == "true"))
fAdmin->setThemeIconsToolbar(true);
else
fAdmin->setThemeIconsToolbar(false);
break; break;
case eMarker: case eMarker:
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
@ -280,7 +296,7 @@ bool PmuppAdminXMLParser::endDocument()
* <p>Initializes that PmuppAdmin object, and calls the XML parser which feeds * <p>Initializes that PmuppAdmin object, and calls the XML parser which feeds
* the object variables. * the object variables.
*/ */
PmuppAdmin::PmuppAdmin() : QObject(), fDarkTheme(false) PmuppAdmin::PmuppAdmin() : QObject()
{ {
// XML Parser part // XML Parser part
// 1st: check local directory // 1st: check local directory

View File

@ -102,7 +102,9 @@ class PmuppAdminXMLParser
virtual bool isValid() { return fValid; } virtual bool isValid() { return fValid; }
private: private:
enum EAdminKeyWords {eEmpty, eRecentFile, eDarkTheme, eMarker, eColor}; enum EAdminKeyWords {eEmpty, eRecentFile,
eIgnoreThemeAutoDetection, eDarkThemeIconsMenu, eDarkThemeIconsToolbar,
eMarker, eColor};
bool parse(QIODevice *device); bool parse(QIODevice *device);
bool startDocument(); bool startDocument();
@ -145,18 +147,24 @@ class PmuppAdmin : public QObject
void getColor(QString name, int &r, int &g, int &b); void getColor(QString name, int &r, int &g, int &b);
void getColor(int idx, int &r, int &g, int &b); void getColor(int idx, int &r, int &g, int &b);
bool isDarkTheme() { return fDarkTheme; } bool getIgnoreThemeAutoDetection() { return fIgnoreThemeAutoDetection; }
bool getDarkThemeIconsMenuFlag() { return fDarkThemeIconsMenu; }
bool getDarkThemeIconsToolbarFlag() { return fDarkThemeIconsToolbar; }
void setTheme(bool theme) { fDarkTheme = theme; } void setIgnoreThemeAutoDetection(const bool theme) { fIgnoreThemeAutoDetection = theme; }
void setMarker(int marker, double size); void setThemeIconsMenu(const bool theme) { fDarkThemeIconsMenu = theme; }
void setColor(int r, int g, int b, QString name=""); void setThemeIconsToolbar(const bool theme) { fDarkThemeIconsToolbar = theme; }
void setMarker(const int marker, const double size);
void setColor(const int r, const int g, const int b, QString name="");
private: private:
friend class PmuppAdminXMLParser; friend class PmuppAdminXMLParser;
QVector<QString> fRecentFile; ///< keep vector of recent path-file names QVector<QString> fRecentFile; ///< keep vector of recent path-file names
bool fDarkTheme; bool fIgnoreThemeAutoDetection{false};
bool fDarkThemeIconsMenu{false};
bool fDarkThemeIconsToolbar{false};
QVector<PmuppMarker> fMarker; QVector<PmuppMarker> fMarker;
QVector<PmuppColor> fColor; QVector<PmuppColor> fColor;

View File

@ -270,7 +270,7 @@ PmuppGui::PmuppGui(QStringList fln)
getTheme(); getTheme();
QString iconName(""); QString iconName("");
if (fDarkTheme) if (fDarkThemeIconsMenu)
iconName = QString(":/icons/mupp-dark.svg"); iconName = QString(":/icons/mupp-dark.svg");
else else
iconName = QString(":/icons/mupp-plain.svg"); iconName = QString(":/icons/mupp-plain.svg");
@ -514,7 +514,7 @@ void PmuppGui::setupFileActions()
QAction *a; QAction *a;
QString iconName(""); QString iconName("");
if (fDarkTheme) if (fDarkThemeIconsMenu)
iconName = QString(":/icons/document-open-dark.svg"); iconName = QString(":/icons/document-open-dark.svg");
else else
iconName = QString(":/icons/document-open-plain.svg"); iconName = QString(":/icons/document-open-plain.svg");
@ -523,7 +523,7 @@ void PmuppGui::setupFileActions()
a->setStatusTip( tr("Open a musrfit parameter file.") ); a->setStatusTip( tr("Open a musrfit parameter file.") );
connect( a, SIGNAL( triggered() ), this, SLOT( fileOpen() ) ); connect( a, SIGNAL( triggered() ), this, SLOT( fileOpen() ) );
menu->addAction(a); menu->addAction(a);
if (!fDarkToolBarIcon) { // tool bar icon is not dark, even though the theme is (ubuntu) if (!fDarkThemeIconsToolbar) { // tool bar icon is not dark, even though the theme is (ubuntu)
iconName = QString(":/icons/document-open-plain.svg"); iconName = QString(":/icons/document-open-plain.svg");
a = new QAction( QIcon( QPixmap(iconName) ), tr( "&New..." ), this ); a = new QAction( QIcon( QPixmap(iconName) ), tr( "&New..." ), this );
connect( a, SIGNAL( triggered() ), this, SLOT( fileOpen() ) ); connect( a, SIGNAL( triggered() ), this, SLOT( fileOpen() ) );
@ -848,26 +848,32 @@ bool PmuppGui::eventFilter(QObject *o, QEvent *e)
*/ */
void PmuppGui::getTheme() void PmuppGui::getTheme()
{ {
fDarkTheme = false; // true if theme is dark if (fIgnoreThemeAutoDetection)
fDarkToolBarIcon = false; // needed for ubuntu dark since there the menu icons return;
// are dark, however the toolbar icons are plain!
fDarkThemeIconsMenu = false; // true if theme is dark
fDarkThemeIconsToolbar = false; // needed for ubuntu dark since there the menu icons
// are dark, however the toolbar icons are plain!
QString str = QIcon::themeName(); QString str = QIcon::themeName();
if (str.isEmpty()) { if (str.isEmpty()) {
if (fAdmin->isDarkTheme()) { if (fAdmin->getDarkThemeIconsMenuFlag()) {
fDarkTheme = true; fDarkThemeIconsMenu = true;
fDarkToolBarIcon = true; }
} if (fAdmin->getDarkThemeIconsToolbarFlag()) {
fDarkThemeIconsToolbar = true;
}
return; return;
} }
if (str.contains("dark", Qt::CaseInsensitive)) { if (str.contains("dark", Qt::CaseInsensitive)) {
fDarkTheme = true; fDarkThemeIconsMenu = true;
if (str.contains("ubuntu", Qt::CaseInsensitive)) { if (str.contains("ubuntu", Qt::CaseInsensitive) ||
fDarkToolBarIcon = false; str.contains("xfce", Qt::CaseInsensitive)) {
fDarkThemeIconsToolbar = false;
} else { } else {
fDarkToolBarIcon = true; fDarkThemeIconsToolbar = true;
} }
} }
} }
@ -1316,7 +1322,7 @@ void PmuppGui::addVar()
// call variable dialog // call variable dialog
fVarDlg.reset(); fVarDlg.reset();
fVarDlg = std::make_unique<PVarDialog>(collection_list, fDarkTheme); fVarDlg = std::make_unique<PVarDialog>(collection_list, fDarkThemeIconsMenu);
connect(fVarDlg.get(), SIGNAL(check_request(QString,QVector<int>)), this, SLOT(check(QString,QVector<int>))); connect(fVarDlg.get(), SIGNAL(check_request(QString,QVector<int>)), this, SLOT(check(QString,QVector<int>)));
connect(fVarDlg.get(), SIGNAL(add_request(QString,QVector<int>)), this, SLOT(add(QString,QVector<int>))); connect(fVarDlg.get(), SIGNAL(add_request(QString,QVector<int>)), this, SLOT(add(QString,QVector<int>)));
fVarDlg->show(); fVarDlg->show();

View File

@ -159,11 +159,12 @@ private:
enum EAxis {kXaxis, kYaxis}; enum EAxis {kXaxis, kYaxis};
PmuppAdmin *fAdmin; PmuppAdmin *fAdmin;
bool fDarkTheme; bool fIgnoreThemeAutoDetection{false};
bool fDarkToolBarIcon; bool fDarkThemeIconsMenu{false};
bool fNormalize; bool fDarkThemeIconsToolbar{false};
bool fNormalize{false};
uint fDatime; qint64 fDatime;
uint fMuppInstance; uint fMuppInstance;
PParamDataHandler *fParamDataHandler; PParamDataHandler *fParamDataHandler;
@ -179,11 +180,11 @@ private:
QAction *fRecentFilesAction[MAX_RECENT_FILES]; ///< array of the recent file actions QAction *fRecentFilesAction[MAX_RECENT_FILES]; ///< array of the recent file actions
std::unique_ptr<QAction> fNormalizeAction; std::unique_ptr<QAction> fNormalizeAction;
std::unique_ptr<QBoxLayout> fBoxLayout_Main; // top->bottom (0) std::unique_ptr<QBoxLayout> fBoxLayout_Main; // top->bottom (0)
std::unique_ptr<QBoxLayout> fBoxLayout_Top; // left->right (1) std::unique_ptr<QBoxLayout> fBoxLayout_Top; // left->right (1)
std::unique_ptr<QGridLayout> fGridLayout_Left; // 2 columns, 3 rows std::unique_ptr<QGridLayout> fGridLayout_Left; // 2 columns, 3 rows
std::unique_ptr<QGridLayout> fGridLayout_Right; // 2 columns, 6 rows std::unique_ptr<QGridLayout> fGridLayout_Right; // 2 columns, 6 rows
std::unique_ptr<QBoxLayout> fBoxLayout_Cmd; // left->right (1) std::unique_ptr<QBoxLayout> fBoxLayout_Cmd; // left->right (1)
std::unique_ptr<QLabel> fColLabel; std::unique_ptr<QLabel> fColLabel;
std::unique_ptr<QSplitter> fColParamSplitter; std::unique_ptr<QSplitter> fColParamSplitter;

View File

@ -5,7 +5,9 @@
</comment> </comment>
<recent_files> <recent_files>
</recent_files> </recent_files>
<dark_theme>no</dark_theme> <ignore_theme_auto_detection>n</ignore_theme_auto_detection>
<dark_theme_icon_menu>n</dark_theme_icon_menu>
<dark_theme_icon_toolbar>n</dark_theme_icon_toolbar>
<root_settings> <root_settings>
<marker_list> <marker_list>
<!-- Root marker numbers --> <!-- Root marker numbers -->

View File

@ -212,13 +212,13 @@ bool PmuppAdminXMLParser::characters()
fAdmin->setIgnoreThemeAutoDetection(false); fAdmin->setIgnoreThemeAutoDetection(false);
break; break;
case eDarkThemeIconsMenu: case eDarkThemeIconsMenu:
if ((str == "yes") || (str == "1") || (str == "true")) if ((str == "yes") || (str == "y") || (str == "1") || (str == "true"))
fAdmin->setThemeIconsMenu(true); fAdmin->setThemeIconsMenu(true);
else else
fAdmin->setThemeIconsMenu(false); fAdmin->setThemeIconsMenu(false);
break; break;
case eDarkThemeIconsToolbar: case eDarkThemeIconsToolbar:
if ((str == "yes") || (str == "1") || (str == "true")) if ((str == "yes") || (str == "y") || (str == "1") || (str == "true"))
fAdmin->setThemeIconsToolbar(true); fAdmin->setThemeIconsToolbar(true);
else else
fAdmin->setThemeIconsToolbar(false); fAdmin->setThemeIconsToolbar(false);