refs #830, improved widget style detection

This commit is contained in:
Klaus Basan
2016-12-12 18:15:24 +01:00
parent eb3b2252a2
commit 3b2468632a
2 changed files with 22 additions and 3 deletions

View File

@@ -8,6 +8,7 @@
*/ */
#include "blackconfig/buildconfig.h" #include "blackconfig/buildconfig.h"
#include "blackcore/context/contextnetwork.h"
#include "blackcore/data/globalsetup.h" #include "blackcore/data/globalsetup.h"
#include "blackcore/data/updateinfo.h" #include "blackcore/data/updateinfo.h"
#include "blackgui/components/applicationclosedialog.h" #include "blackgui/components/applicationclosedialog.h"
@@ -482,6 +483,13 @@ namespace BlackGui
return this->m_styleSheetUtility; return this->m_styleSheetUtility;
} }
QString CGuiApplication::getWidgetStyle() const
{
QString currentWidgetStyle(QApplication::style()->metaObject()->className());
if (currentWidgetStyle.startsWith('Q')) { currentWidgetStyle.remove(0, 1); }
return currentWidgetStyle.replace("Style", "");
}
bool CGuiApplication::reloadStyleSheets() bool CGuiApplication::reloadStyleSheets()
{ {
return m_styleSheetUtility.read(); return m_styleSheetUtility.read();
@@ -554,13 +562,21 @@ namespace BlackGui
{ {
// changing widget style is slow, so I try to prevent setting it when nothing changed // changing widget style is slow, so I try to prevent setting it when nothing changed
const QString widgetStyle = m_guiSettings.get().getWidgetStyle(); const QString widgetStyle = m_guiSettings.get().getWidgetStyle();
const QString currentWidgetStyle(QApplication::style()->metaObject()->className()); const QString currentWidgetStyle(this->getWidgetStyle());
if (!currentWidgetStyle.contains(widgetStyle, Qt::CaseInsensitive)) if (!(currentWidgetStyle.length() == widgetStyle.length() && currentWidgetStyle.startsWith(widgetStyle, Qt::CaseInsensitive)))
{ {
const auto availableStyles = QStyleFactory::keys(); const auto availableStyles = QStyleFactory::keys();
if (availableStyles.contains(widgetStyle)) if (availableStyles.contains(widgetStyle))
{ {
QApplication::setStyle(QStyleFactory::create(widgetStyle)); // changing style freezes the application, so it must not be done in flight mode
if (this->getIContextNetwork() && this->getIContextNetwork()->isConnected())
{
CLogMessage(this).validationError("Cannot change style while connected to network");
}
else
{
QApplication::setStyle(QStyleFactory::create(widgetStyle));
}
} }
} }
} }

View File

@@ -135,6 +135,9 @@ namespace BlackGui
//! Style sheet handling //! Style sheet handling
const CStyleSheetUtility &getStyleSheetUtility() const; const CStyleSheetUtility &getStyleSheetUtility() const;
//! Current widget style
QString getWidgetStyle() const;
//! Reload style sheets //! Reload style sheets
bool reloadStyleSheets(); bool reloadStyleSheets();