|
From: <cn...@us...> - 2023-03-15 18:25:14
|
Revision: 1348
http://sourceforge.net/p/seq/svn/1348
Author: cn187
Date: 2023-03-15 18:25:07 +0000 (Wed, 15 Mar 2023)
Log Message:
-----------
Enumerate available Qt styles
* Instead of hard-coding styles which may or may not be available,
enumerate available styles and an allow the user to choose from those.
* Code now relies on style name instead of arbitrary integer ID. Modified
preference loading/saving code to provide backwards-compatibile
transition.
* Do not force a default style. If no style is saved to preferences, use
whatever style Qt defaults to. This should help with look-and-feel on
systems that know how to style Qt apps to match their native themes.
* Remove miscellaneous palette and font overrides for various themes.
Most notibly, the CDE style will look more like the other styles,
rather than being green.
Modified Paths:
--------------
showeq/trunk/src/interface.cpp
showeq/trunk/src/interface.h
Modified: showeq/trunk/src/interface.cpp
===================================================================
--- showeq/trunk/src/interface.cpp 2023-03-15 18:24:57 UTC (rev 1347)
+++ showeq/trunk/src/interface.cpp 2023-03-15 18:25:07 UTC (rev 1348)
@@ -92,6 +92,7 @@
#include <QMenu>
#include <QWidgetAction>
#include <QDesktopWidget>
+#include <QStyleFactory>
// this define is used to diagnose the order with which zone packets are rcvd
#define ZONE_ORDER_DIAG
@@ -1444,41 +1445,44 @@
QMenu* pStyleMenu = new QMenu("&Style");
pInterfaceMenu->addMenu(pStyleMenu);
- tmpAction = pStyleMenu->addAction( "Plastique");
- tmpAction->setCheckable(true);
- tmpAction->setData(1);
- ActionList_StyleMenu.append(tmpAction);
+ QStringList availableStyles = QStyleFactory::keys();
- tmpAction = pStyleMenu->addAction( "Windows (Default)");
- tmpAction->setCheckable(true);
- tmpAction->setData(2);
- ActionList_StyleMenu.append(tmpAction);
+ availableStyles.sort(Qt::CaseInsensitive);
- tmpAction = pStyleMenu->addAction( "CDE");
- tmpAction->setCheckable(true);
- tmpAction->setData(3);
- ActionList_StyleMenu.append(tmpAction);
+ QString currentStyleName = qApp->style()->objectName();
- tmpAction = pStyleMenu->addAction( "CDE Polished");
- tmpAction->setCheckable(true);
- tmpAction->setData(4);
- ActionList_StyleMenu.append(tmpAction);
+ QStringList::Iterator styleItr = availableStyles.begin();
- tmpAction = pStyleMenu->addAction( "Motif");
- tmpAction->setCheckable(true);
- tmpAction->setData(5);
- ActionList_StyleMenu.append(tmpAction);
+ while (styleItr != availableStyles.end()) {
- tmpAction = pStyleMenu->addAction( "Cleanlooks");
- tmpAction->setCheckable(true);
- tmpAction->setData(6);
- ActionList_StyleMenu.append(tmpAction);
+ tmpAction = pStyleMenu->addAction(*styleItr);
+ tmpAction->setCheckable(true);
+ if (currentStyleName.toLower() == (*styleItr).toLower())
+ tmpAction->setChecked(true);
+
+ tmpAction->setData(*styleItr);
+ ActionList_StyleMenu.append(tmpAction);
+
+ ++styleItr;
+ }
+
connect (pStyleMenu, SIGNAL(triggered(QAction*)), this,
SLOT(selectTheme(QAction*)));
- setTheme(pSEQPrefs->getPrefInt("Theme", section, 2));
+ QString themeName = pSEQPrefs->getPrefString("ThemeName", section, "");
+ //Use the text name if there is one. If not, fall back to old numeric id. If no
+ //numeric id, then just use whatever Qt started with (no forced default)
+ if (!themeName.isEmpty())
+ {
+ setTheme(themeName);
+ } else {
+ int themeId = pSEQPrefs->getPrefInt("Theme", section, -1);
+ if (themeId >= 0)
+ setTheme(themeId);
+ }
+
// Interface -> Status Bar
QMenu* statusBarMenu = new QMenu("&Status Bar");
pInterfaceMenu->addMenu(statusBarMenu);
@@ -5659,19 +5663,28 @@
m_terminal->setUseColor(enable);
}
-int EQInterface::setTheme(int id)
+QString EQInterface::setTheme(QString name)
{
static QFont OrigFont = qApp->font();
static QPalette OrigPalette = qApp->palette();;
+ QString currentStyleName = qApp->style()->objectName();
+
+ QStringList availableStyles = QStyleFactory::keys();
+
+ if (!availableStyles.contains(name, Qt::CaseInsensitive))
+ return currentStyleName;
+
+ qApp->setStyle(QStyleFactory::create(name));
+
MenuActionList::Iterator iter;
- int theme = 2;
+
for ( iter = ActionList_StyleMenu.begin(); iter != ActionList_StyleMenu.end(); ++iter)
{
- if ((*iter)->data().value<int>() == id)
+ if ((*iter)->data().value<QString>().toLower() == name.toLower())
{
(*iter)->setChecked(true);
- theme = (*iter)->data().value<int>();
+ currentStyleName = (*iter)->data().value<QString>();
}
else
{
@@ -5679,86 +5692,61 @@
}
}
- switch ( theme )
+ return currentStyleName;
+}
+
+int EQInterface::setTheme(int id)
+{
+
+ int current_theme = 2;
+
+ MenuActionList::Iterator iter;
+
+ for ( iter = ActionList_StyleMenu.begin(); iter != ActionList_StyleMenu.end(); ++iter)
{
- case 1: // plastique
- {
- QPalette p( QColor( 239, 239, 239 ) );
- qApp->setStyle("plastique");
- qApp->setPalette(p);
+ if ((*iter)->isChecked())
+ current_theme = (*iter)->data().value<int>();
}
- break;
- case 2: // windows
+
+ QString new_theme;
+
+ switch ( id )
{
- qApp->setStyle("windows");
- qApp->setFont( OrigFont );
- qApp->setPalette(OrigPalette);
+ case 1: // plastique
+ new_theme = "plastique";
+ break;
+ case 2: // windows
+ new_theme = "windows";
+ break;
+ case 3: // cde
+ case 4: // cde polished
+ new_theme = "cde";
+ break;
+ case 5: // motif
+ new_theme = "motif";
+ break;
+ case 6: // cleanlooks
+ new_theme = "cleanlooks";
+ break;
+ default: // system default
+ return current_theme;
+ break;
}
- break;
- case 3: // cde
- case 4: // cde polished
- {
- QPalette p( QColor( 75, 123, 130 ) );
- qApp->setStyle("cde");
- p.setColor( QPalette::Active, QPalette::Base, QColor( 55, 77, 78 ) );
- p.setColor( QPalette::Inactive, QPalette::Base, QColor( 55, 77, 78 ) );
- p.setColor( QPalette::Disabled, QPalette::Base, QColor( 55, 77, 78 ) );
- p.setColor( QPalette::Active, QPalette::Highlight, Qt::white );
- p.setColor( QPalette::Active, QPalette::HighlightedText, QColor( 55, 77, 78 ) );
- p.setColor( QPalette::Inactive, QPalette::Highlight, Qt::white );
- p.setColor( QPalette::Inactive, QPalette::HighlightedText, QColor( 55, 77, 78 ) );
- p.setColor( QPalette::Disabled, QPalette::Highlight, Qt::white );
- p.setColor( QPalette::Disabled, QPalette::HighlightedText, QColor( 55, 77, 78 ) );
- p.setColor( QPalette::Active, QPalette::Foreground, Qt::white );
- p.setColor( QPalette::Active, QPalette::Text, Qt::white );
- p.setColor( QPalette::Active, QPalette::ButtonText, Qt::white );
- p.setColor( QPalette::Inactive, QPalette::Foreground, Qt::white );
- p.setColor( QPalette::Inactive, QPalette::Text, Qt::white );
- p.setColor( QPalette::Inactive, QPalette::ButtonText, Qt::white );
- p.setColor( QPalette::Disabled, QPalette::Foreground, Qt::lightGray );
- p.setColor( QPalette::Disabled, QPalette::Text, Qt::lightGray );
- p.setColor( QPalette::Disabled, QPalette::ButtonText, Qt::lightGray );
- qApp->setPalette(p);
- qApp->setFont( QFont( "times", OrigFont.pointSize() ) );
- }
- break;
- case 5: // motif
- {
- QPalette p( QColor( 192, 192, 192 ) );
- qApp->setStyle("motif");
- qApp->setPalette(p);
- qApp->setFont( OrigFont );
- }
- break;
- case 6: // cleanlooks
- {
- //QPalette p( QColor( 192, 192, 192 ) );
- qApp->setStyle("cleanlooks");
- qApp->setPalette(OrigPalette);
- qApp->setFont( OrigFont );
- }
- break;
- default: // system default
- {
- QPalette p( QColor( 192, 192, 192 ) );
- qApp->setStyle("motif");
- qApp->setPalette(p);
- qApp->setFont( OrigFont );
- theme = 2;
- }
- break;
- }
- // make sure the windows that override the application font, do so
+ QString set_theme = setTheme(new_theme);
+
emit restoreFonts();
- return theme;
+ if (new_theme.toLower() == set_theme.toLower())
+ return id;
+ else
+ return current_theme;
}
void EQInterface::selectTheme(QAction* selection)
{
- int theme = setTheme(selection->data().value<int>());
- pSEQPrefs->setPrefInt("Theme", "Interface", theme);
+ QString theme = setTheme(selection->data().value<QString>());
+ pSEQPrefs->setPrefString("ThemeName", "Interface", theme);
}
void EQInterface::showMap(int i)
Modified: showeq/trunk/src/interface.h
===================================================================
--- showeq/trunk/src/interface.h 2023-03-15 18:24:57 UTC (rev 1347)
+++ showeq/trunk/src/interface.h 2023-03-15 18:25:07 UTC (rev 1348)
@@ -317,6 +317,7 @@
protected:
bool getMonitorOpCodeList(const QString& title, QString& opcodeList);
+ QString setTheme(QString name);
int setTheme(int id);
void loadFormatStrings();
void showMap(int mapNum);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|