Skip to content

Commit

Permalink
Add Qt styles flags to QgsAppStyleSheet and update styled group boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
dakcarto committed Jan 25, 2013
1 parent 3e33cf8 commit fbe6c6a
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 91 deletions.
129 changes: 77 additions & 52 deletions src/app/qgisappstylesheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <QFont>
#include <QSettings>
#include <QStyle>

/** @class QgisAppStyleSheet
* @brief Adjustable stylesheet for the Qgis application
Expand All @@ -30,51 +31,7 @@
QgisAppStyleSheet::QgisAppStyleSheet( QObject *parent )
: QObject( parent )
{
// platforms, specific
#ifdef Q_OS_LINUX
mLinuxOS = true;
#else
mLinuxOS = false;
#endif
#ifdef Q_OS_WIN32
mWinOS = true;
#else
mWinOS = false;
#endif
#ifdef Q_OS_MAC
mMacOS = true;
#else
mMacOS = false;
#endif
#ifdef ANDROID
mAndroidOS = true;
#else
mAndroidOS = false;
#endif

// platforms, general
#ifdef Q_OS_UNIX
mUnix = true;
#else
mUnix = false;
#endif

// window servers
#ifdef Q_WS_X11
mX11WS = true;
#else
mX11WS = false;
#endif
#ifdef Q_WS_WIN
mWinWS = true;
#else
mWinWS = false;
#endif
#ifdef Q_WS_MAC
mMacWS = true;
#else
mMacWS = false;
#endif
setActiveValues();
}

QgisAppStyleSheet::~QgisAppStyleSheet()
Expand All @@ -84,7 +41,6 @@ QgisAppStyleSheet::~QgisAppStyleSheet()
QMap<QString, QVariant> QgisAppStyleSheet::defaultOptions()
{
QMap<QString, QVariant> opts;
mDefaultFont = qApp->font(); // save before it is changed in any way

// the following default values, before insertion in opts, can be
// configured using the platforms and window servers defined in the
Expand Down Expand Up @@ -158,7 +114,6 @@ void QgisAppStyleSheet::buildStyleSheet( const QMap<QString, QVariant>& opts )
ss += QString( "* { font: %1pt \"%2\"} " ).arg( fontSize ).arg( fontFamily );

// QGroupBox and QgsCollapsibleGroupBox, mostly for Ubuntu and Mac
// TODO: test on/adjust for Windows
bool gbxCustom = opts.value( "groupBoxCustom" ).toBool();
QgsDebugMsg( QString( "groupBoxCustom: %1" ).arg( gbxCustom ) );
bool gbxBoldTitle = opts.value( "groupBoxBoldTitle" ).toBool();
Expand All @@ -169,16 +124,17 @@ void QgisAppStyleSheet::buildStyleSheet( const QMap<QString, QVariant>& opts )
if ( gbxBoldTitle )
{
// doesn't work for QGroupBox::title
ss += QString( "color: rgb(%1,%1,%1);" ).arg( mMacWS ? 25 : 60 );
ss += QString( "color: rgb(%1,%1,%1);" ).arg( mMacStyle ? 25 : 60 );
ss += "font-weight: bold;";
}
if ( gbxCustom )
{
ss += QString( "background-color: rgba(%1,%1,%1,90%);" ).arg( mMacWS ? 225 : 235 );
ss += "border: 1px solid #c0c0c0;";
ss += QString( "background-color: rgba(0,0,0,%1%);" )
.arg( mWinOS && mStyle.startsWith( "windows" ) ? 0 : 3 );
ss += "border: 1px solid rgba(0,0,0,20%);";
ss += "border-radius: 5px;";
ss += "margin-top: 2.5ex;";
ss += QString( "margin-bottom: %1ex;" ).arg( mMacWS ? 1.5 : 1 );
ss += QString( "margin-bottom: %1ex;" ).arg( mMacStyle ? 1.5 : 1 );
}
ss += "} ";
if ( gbxCustom )
Expand All @@ -192,7 +148,10 @@ void QgisAppStyleSheet::buildStyleSheet( const QMap<QString, QVariant>& opts )
ss += "subcontrol-origin: margin;";
ss += "subcontrol-position: top left;";
ss += "margin-left: 6px;";
ss += "background-color: rgba(0,0,0,0);";
if ( !( mWinOS && mStyle.startsWith( "windows" ) ) && !mOxyStyle )
{
ss += "background-color: rgba(0,0,0,0);";
}
ss += "} ";
}
}
Expand All @@ -215,3 +174,69 @@ void QgisAppStyleSheet::saveToSettings( const QMap<QString, QVariant>& opts )
}
settings.endGroup(); // "qgis/stylesheet"
}

void QgisAppStyleSheet::setActiveValues()
{
mStyle = qApp->style()->objectName(); // active style name (lowercase)
QgsDebugMsg( QString( "Style name: %1" ).arg( mStyle ) );

mMotifStyle = mStyle.contains( "motif" ) ? true : false; // motif
mCdeStyle = mStyle.contains( "cde" ) ? true : false; // cde
mPlastqStyle = mStyle.contains( "plastique" ) ? true : false; // plastique
mCleanLkStyle = mStyle.contains( "cleanlooks" ) ? true : false; // cleanlooks
mGtkStyle = mStyle.contains( "gtk" ) ? true : false; // gtk+
mWinStyle = mStyle.contains( "windows" ) ? true : false; // windows
mWinXpStyle = mStyle.contains( "windowsxp" ) ? true : false; // windowsxp
mWinVistaStyle = mStyle.contains( "windowsvista" ) ? true : false; // windowsvista
mMacStyle = mStyle.contains( "macintosh" ) ? true : false; // macintosh (aqua)
mOxyStyle = mStyle.contains( "oxygen" ) ? true : false; // oxygen

mDefaultFont = qApp->font(); // save before it is changed in any way

// platforms, specific
#ifdef Q_OS_LINUX
mLinuxOS = true;
#else
mLinuxOS = false;
#endif
#ifdef Q_OS_WIN32
mWinOS = true;
#else
mWinOS = false;
#endif
#ifdef Q_OS_MAC
mMacOS = true;
#else
mMacOS = false;
#endif
#ifdef ANDROID
mAndroidOS = true;
#else
mAndroidOS = false;
#endif

// platforms, general
#ifdef Q_OS_UNIX
mUnix = true;
#else
mUnix = false;
#endif

// window servers
#ifdef Q_WS_X11
mX11WS = true;
#else
mX11WS = false;
#endif
#ifdef Q_WS_WIN
mWinWS = true;
#else
mWinWS = false;
#endif
#ifdef Q_WS_MAC
mMacWS = true;
#else
mMacWS = false;
#endif

}
22 changes: 19 additions & 3 deletions src/app/qgisappstylesheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ class QgisAppStyleSheet: public QObject
void appStyleSheetChanged( const QString& appStyleSheet );

private:
/** Set active configuration values */
void setActiveValues();

// qt styles
QString mStyle; // active style name (lowercase)
bool mMotifStyle; // motif
bool mCdeStyle; // cde
bool mPlastqStyle; // plastique
bool mCleanLkStyle; // cleanlooks
bool mGtkStyle; // gtk+
bool mWinStyle; // windows
bool mWinXpStyle; // windowsxp
bool mWinVistaStyle; // windowsvista
bool mMacStyle; // macintosh (aqua)
bool mOxyStyle; // oxygen

// default font saved for reference
QFont mDefaultFont;

// platforms, specific
bool mLinuxOS;
bool mWinOS;
Expand All @@ -68,9 +87,6 @@ class QgisAppStyleSheet: public QObject
bool mX11WS;
bool mWinWS;
bool mMacWS;

// default font saved for reference
QFont mDefaultFont;
};

#endif //QGISAPPSTYLESHEET_H
Loading

0 comments on commit fbe6c6a

Please sign in to comment.