improved dark theme handling on mupp for qt6.

This commit is contained in:
suter_a 2025-03-29 20:17:28 +01:00
parent 3796925e93
commit f7e5c53879
5 changed files with 66 additions and 33 deletions

View File

@ -156,8 +156,12 @@ bool PmuppAdminXMLParser::startElement()
if (qName == "path_file_name") {
fKeyWord = eRecentFile;
} else if (qName == "dark_theme") {
fKeyWord = eDarkTheme;
} else if (qName == "ignore_theme_auto_detection") {
fKeyWord = eIgnoreThemeAutoDetection;
} else if (qName == "dark_theme_icons_menu") {
fKeyWord = eDarkThemeIconsMenu;
} else if (qName == "dark_theme_icons_toolbar") {
fKeyWord = eDarkThemeIconsToolbar;
} else if (qName == "marker") {
fKeyWord = eMarker;
} else if (qName == "color") {
@ -201,11 +205,23 @@ bool PmuppAdminXMLParser::characters()
case eRecentFile:
fAdmin->addRecentFile(QString(str.toLatin1()).trimmed());
break;
case eDarkTheme:
if ((str == "yes") || (str == "1") || (str == "true"))
fAdmin->setTheme(true);
case eIgnoreThemeAutoDetection:
if ((str == "yes") || (str == "y") || (str == "1") || (str == "true"))
fAdmin->setIgnoreThemeAutoDetection(true);
else
fAdmin->setTheme(false);
fAdmin->setIgnoreThemeAutoDetection(false);
break;
case eDarkThemeIconsMenu:
if ((str == "yes") || (str == "1") || (str == "true"))
fAdmin->setThemeIconsMenu(true);
else
fAdmin->setThemeIconsMenu(false);
break;
case eDarkThemeIconsToolbar:
if ((str == "yes") || (str == "1") || (str == "true"))
fAdmin->setThemeIconsToolbar(true);
else
fAdmin->setThemeIconsToolbar(false);
break;
case eMarker:
tok = str.split(",", Qt::SkipEmptyParts);
@ -272,7 +288,7 @@ bool PmuppAdminXMLParser::endDocument()
* <p>Initializes that PmuppAdmin object, and calls the XML parser which feeds
* the object variables.
*/
PmuppAdmin::PmuppAdmin() : QObject(), fDarkTheme(false)
PmuppAdmin::PmuppAdmin() : QObject()
{
// XML Parser part
// 1st: check local directory
@ -433,7 +449,7 @@ void PmuppAdmin::getColor(int idx, int &r, int &g, int &b)
* @param marker marker code
* @param size marker size
*/
void PmuppAdmin::setMarker(int marker, double size)
void PmuppAdmin::setMarker(const int marker, const double size)
{
PmuppMarker markerObj;
@ -456,7 +472,7 @@ void PmuppAdmin::setMarker(int marker, double size)
* @param b blue value (0..255)
* @param name color name
*/
void PmuppAdmin::setColor(int r, int g, int b, QString name)
void PmuppAdmin::setColor(const int r, const int g, const int b, QString name)
{
if (((r<0) || (r>255)) ||
((g<0) || (g>255)) ||

View File

@ -102,7 +102,9 @@ class PmuppAdminXMLParser
virtual bool isValid() { return fValid; }
private:
enum EAdminKeyWords {eEmpty, eRecentFile, eDarkTheme, eMarker, eColor};
enum EAdminKeyWords {eEmpty, eRecentFile,
eIgnoreThemeAutoDetection, eDarkThemeIconsMenu, eDarkThemeIconsToolbar,
eMarker, eColor};
bool parse(QIODevice *device);
bool startDocument();
@ -145,18 +147,24 @@ 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; }
bool getIgnoreThemeAutoDetection() { return fIgnoreThemeAutoDetection; }
bool getDarkThemeIconsMenuFlag() { return fDarkThemeIconsMenu; }
bool getDarkThemeIconsToolbarFlag() { return fDarkThemeIconsToolbar; }
void setTheme(bool theme) { fDarkTheme = theme; }
void setMarker(int marker, double size);
void setColor(int r, int g, int b, QString name="");
void setIgnoreThemeAutoDetection(const bool theme) { fIgnoreThemeAutoDetection = theme; }
void setThemeIconsMenu(const bool theme) { fDarkThemeIconsMenu = theme; }
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:
friend class PmuppAdminXMLParser;
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<PmuppColor> fColor;

View File

@ -270,7 +270,7 @@ PmuppGui::PmuppGui(QStringList fln)
getTheme();
QString iconName("");
if (fDarkTheme)
if (fDarkThemeIconsMenu)
iconName = QString(":/icons/mupp-dark.svg");
else
iconName = QString(":/icons/mupp-plain.svg");
@ -513,7 +513,7 @@ void PmuppGui::setupFileActions()
QAction *a;
QString iconName("");
if (fDarkTheme)
if (fDarkThemeIconsMenu)
iconName = QString(":/icons/document-open-dark.svg");
else
iconName = QString(":/icons/document-open-plain.svg");
@ -522,7 +522,7 @@ void PmuppGui::setupFileActions()
a->setStatusTip( tr("Open a musrfit parameter file.") );
connect( a, SIGNAL( triggered() ), this, SLOT( fileOpen() ) );
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, mx, xfce)
iconName = QString(":/icons/document-open-plain.svg");
a = new QAction( QIcon( QPixmap(iconName) ), tr( "&New..." ), this );
connect( a, SIGNAL( triggered() ), this, SLOT( fileOpen() ) );
@ -847,26 +847,32 @@ bool PmuppGui::eventFilter(QObject *o, QEvent *e)
*/
void PmuppGui::getTheme()
{
fDarkTheme = false; // true if theme is dark
fDarkToolBarIcon = false; // needed for ubuntu dark since there the menu icons
// are dark, however the toolbar icons are plain!
if (fIgnoreThemeAutoDetection)
return;
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();
if (str.isEmpty()) {
if (fAdmin->isDarkTheme()) {
fDarkTheme = true;
fDarkToolBarIcon = true;
if (fAdmin->getDarkThemeIconsMenuFlag()) {
fDarkThemeIconsMenu = true;
}
if (fAdmin->getDarkThemeIconsToolbarFlag()) {
fDarkThemeIconsToolbar = true;
}
return;
}
if (str.contains("dark", Qt::CaseInsensitive)) {
fDarkTheme = true;
if (str.contains("ubuntu", Qt::CaseInsensitive)) {
fDarkToolBarIcon = false;
fDarkThemeIconsMenu = true;
if (str.contains("ubuntu", Qt::CaseInsensitive) ||
str.contains("xfce", Qt::CaseInsensitive)) {
fDarkThemeIconsToolbar = false;
} else {
fDarkToolBarIcon = true;
fDarkThemeIconsToolbar = true;
}
}
}
@ -1304,7 +1310,7 @@ void PmuppGui::addVar()
// call variable dialog
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(add_request(QString,QVector<int>)), this, SLOT(add(QString,QVector<int>)));
fVarDlg->show();

View File

@ -159,9 +159,10 @@ private:
enum EAxis {kXaxis, kYaxis};
PmuppAdmin *fAdmin;
bool fDarkTheme;
bool fDarkToolBarIcon;
bool fNormalize;
bool fIgnoreThemeAutoDetection{false};
bool fDarkThemeIconsMenu{false};
bool fDarkThemeIconsToolbar{false};
bool fNormalize{false};
qint64 fDatime;
uint fMuppInstance;

View File

@ -5,7 +5,9 @@
</comment>
<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>
<marker_list>
<!-- Root marker numbers -->