Skip to content

Commit

Permalink
Add variable support to themes
Browse files Browse the repository at this point in the history
- Variables loaded from variables.qss file
- @varname: value e.g @mycolor: red
- Copy base themes to users home
  • Loading branch information
NathanW2 committed Aug 29, 2015
1 parent 37fc244 commit 61e5286
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 30 deletions.
Binary file added resources/themes/Night Mapping/icons/up_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 44 additions & 26 deletions resources/themes/Night Mapping/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ QToolTip
{
border: 1px solid #222;
background-color: #333;
color: #aaa;
color: @text;
}

QWidget
{
color: #aaa;
background-color: #323232;
color: @text;
background-color: @background;
}


QWidget:item:hover
{
background-color: #507098;
color: #aaa;
color: @text;
}

QWidget:item:selected
Expand All @@ -24,7 +24,7 @@ QWidget:item:selected
}

QMenuBar {
background-color: #323232;
background-color: @background;
}

QMenuBar::item
Expand Down Expand Up @@ -87,7 +87,7 @@ QMenu
QMenu::item
{
background: transparent;
padding: 2px 20px 2px 20px;
padding: 5px 20px 5px 20px;
}

QMenu::item:disabled
Expand All @@ -101,13 +101,13 @@ QMenu::item:disabled
QMenu::item:selected
{
background-color: #507098;
color: #aaa;
color: @text;
}

QWidget:disabled
{
color: #404040;
background-color: #323232;
background-color: @background;
}

QLineEdit
Expand Down Expand Up @@ -171,7 +171,7 @@ QComboBox:on {
}

QComboBox:editable {
background: #323232;
background: @background;
}

QComboBox QAbstractItemView {
Expand Down Expand Up @@ -279,7 +279,7 @@ QDockWidget::title
{
text-align: center;
spacing: 3px; /* spacing between items in the tool bar */
background-color: #323232;
background-color: @background;
font-weight: bold;
}

Expand Down Expand Up @@ -319,8 +319,8 @@ QMainWindow::separator:hover
}

QToolBar {
background: #323232;
border: 1px solid #323232;
background: @background;
border: 1px solid @background;
font-weight: bold;
}

Expand Down Expand Up @@ -373,7 +373,7 @@ QTabBar::tab {
color: #b1b1b1;
border: 1px solid #444;
border-bottom-style: none;
background-color: #323232;
background-color: @background;
padding-left: 10px;
padding-right: 10px;
padding-top: 3px;
Expand All @@ -396,12 +396,13 @@ QTabBar::tab:first:!selected
margin-left: 0px; /* the last selected tab has nothing to overlap with on the right */
}

QTabBar::tab:bottom {
border-bottom: 1px solid rgb(190, 190, 190);
}

QTabBar::tab:!selected
{
color: #b1b1b1;
border-bottom-style: solid;
margin-top: 3px;
/*background-color: QLinearGradient(x1:0, y1:0, x2:0, y2:1, stop:1 #212121, stop:.4 #343434);*/
margin-top: 5px;
}

QTabBar::tab:selected
Expand All @@ -423,23 +424,32 @@ QTabBar::tab:!selected:hover
QGroupBox::indicator:unchecked,
QGroupBox::indicator:checked,
QCheckBox::indicator:checked,
QCheckBox::indicator:unchecked,
QCheckBox::indicator:unchecked
QRadioButton::indicator:checked,
QRadioButton::indicator:unchecked{
color: #b1b1b1;
background-color: #323232;
background-color: @background;
border: 1px solid #b1b1b1;
}

QGroupBox::indicator:checked,
QCheckBox::indicator:checked,
QCheckBox::indicator:checked
{
background-color: qradialgradient(
cx: 0.5, cy: 0.5,
fx: 0.5, fy: 0.5,
radius: 1.0,
stop: 0.25 #ffaa00,
stop: 0.3 @background
);
}
QRadioButton::indicator:checked {
background-color: qradialgradient(
cx: 0.5, cy: 0.5,
fx: 0.5, fy: 0.5,
radius: 1.0,
stop: 0.25 #ffaa00,
stop: 0.3 #323232
stop: 0.3 @background
);
}

Expand All @@ -461,7 +471,7 @@ QRadioButton::indicator:hover
QAbstractItemView
{
background-color: #222;
alternate-background-color: #323232;
alternate-background-color: @background;
color: silver;
border: none;
border-radius: 3px;
Expand Down Expand Up @@ -513,20 +523,28 @@ QgsLayerTreeView
}

QgsLayerTreeView::item,
QTreeView#viewCategories::item
QTreeView#viewGraduated::item,
QTreeView#viewCategories::item,
QTreeView#viewRules::item
{
border-top: 0.5px solid rgba(108,108,108,50);
border-bottom: 0.5px solid rgba(108,108,108,50);
padding: 3px;
}

QgsLayerTreeView::indicator:unchecked,
QTreeView#viewCategories::indicator:unchecked {
QTreeView#viewGraduated::indicator:unchecked,
QTreeView#viewCategories::indicator:unchecked,
QTreeView#viewRules::indicator:unchecked
{
image: url(icons/eye-blocked.svg);
}

QgsLayerTreeView::indicator:checked,
QTreeView#viewCategories::indicator:checked {
QTreeView#viewGraduated::indicator:checked,
QTreeView#viewCategories::indicator:checked,
QTreeView#viewRules::indicator:checked
{
image: url(icons/eye.svg);
}

Expand All @@ -539,7 +557,7 @@ QHeaderView {

QHeaderView::section {
background: transparent;
background-color: #323232;
background-color: @background;
color: #777;
border-right: 0px solid #777;
border-top: 0px solid #777;
Expand Down
2 changes: 2 additions & 0 deletions resources/themes/Night Mapping/variables.qss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@background: #323232
@text: #aaa;
3 changes: 3 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
QMessageBox::critical( this, tr( "Private qgis.db" ), dbError );
}

// Create the themes folder for the user
QgsApplication::createThemeFolder();

mSplash->showMessage( tr( "Reading settings" ), Qt::AlignHCenter | Qt::AlignBottom );
qApp->processEvents();

Expand Down
86 changes: 82 additions & 4 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,18 +437,55 @@ void QgsApplication::setUITheme( const QString &themeName )
// Loop all style sheets, find matching name, load it.
QHash<QString, QString> themes = QgsApplication::uiThemes();
QString path = themes[themeName];
QString stylesheetname = path + "/style.qss";
QString autostylesheet = stylesheetname + ".auto";

QFile file( stylesheetname );
QFile variablesfile( path + "/variables.qss" );
QFile fileout( autostylesheet );

QFileInfo variableInfo( variablesfile );

if ( variableInfo.exists() && variablesfile.open( QIODevice::ReadOnly ) )
{
if ( !file.open( QIODevice::ReadOnly ) || !fileout.open( QIODevice::WriteOnly | QIODevice::Text ) )
{
return;
}

QHash<QString, QString> variables;
QString styledata = file.readAll();
QTextStream in( &variablesfile );
while ( !in.atEnd() )
{
QString line = in.readLine();
// This is is a variable
if ( line.startsWith( "@" ) )
{
int index = line.indexOf( ":" );
QString name = line.mid( 0, index );
QString value = line.mid( index + 1, line.length() );
styledata.replace( name, value );
}
}
variablesfile.close();
QTextStream out( &fileout );
out << styledata;
fileout.close();
file.close();
stylesheetname = autostylesheet;
}

QString styleSheet = QLatin1String( "file:///" );
styleSheet.append( path + "/style.qss" );
styleSheet.append( stylesheetname );
qApp->setStyleSheet( styleSheet );
QSettings settings;
return settings.setValue( "UI/UITheme", themeName );
}

QHash<QString, QString> QgsApplication::uiThemes()
{
QString themepath = ABISYM( mPkgDataPath ) + QString( "/resources/themes" );
QString userthemes = qgisSettingsDirPath() + QString( "/themes" );
QStringList paths = QStringList() << themepath << userthemes;
QStringList paths = QStringList() << userThemesFolder();
QHash<QString, QString> mapping;
mapping.insert( "default", "" );
foreach ( const QString& path, paths )
Expand Down Expand Up @@ -643,11 +680,21 @@ QString QgsApplication::userStyleV2Path()
return qgisSettingsDirPath() + QString( "symbology-ng-style.db" );
}

QString QgsApplication::userThemesFolder()
{
return qgisSettingsDirPath() + QString( "/themes" );
}

QString QgsApplication::defaultStyleV2Path()
{
return ABISYM( mPkgDataPath ) + QString( "/resources/symbology-ng-style.db" );
}

QString QgsApplication::defaultThemesFolder()
{
return ABISYM( mPkgDataPath ) + QString( "/resources/themes" );
}

QString QgsApplication::libraryPath()
{
return ABISYM( mLibraryPath );
Expand Down Expand Up @@ -971,6 +1018,37 @@ void QgsApplication::applyGdalSkippedDrivers()
GDALAllRegister(); //to update driver list and skip missing ones
}

bool QgsApplication::createThemeFolder()
{
QString folder = userThemesFolder();
QDir myDir( folder );
if ( !myDir.exists() )
{
myDir.mkpath( folder );
}

copyPath( defaultThemesFolder(), userThemesFolder() );
}

void QgsApplication::copyPath( QString src, QString dst )
{
QDir dir( src );
if ( ! dir.exists() )
return;

foreach ( QString d, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
{
QString dst_path = dst + QDir::separator() + d;
dir.mkpath( dst_path );
copyPath( src + QDir::separator() + d, dst_path );
}

foreach ( QString f, dir.entryList( QDir::Files ) )
{
QFile::copy( src + QDir::separator() + f, dst + QDir::separator() + f );
}
}

bool QgsApplication::createDB( QString *errorMessage )
{
// set a working directory up for gdal to write .aux.xml files into
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,15 @@ class CORE_EXPORT QgsApplication : public QApplication
//! Returns the path to user's style.
static QString userStyleV2Path();

//! Returns the path to user's themes folder
static QString userThemesFolder();

//! Returns the path to default style (works as a starting point).
static QString defaultStyleV2Path();

//! Returns the path to default themes folder from install (works as a starting point).
static QString defaultThemesFolder();

//! Returns the path containing qgis_core, qgis_gui, qgispython (and other) libraries
static QString libraryPath();

Expand All @@ -213,6 +219,9 @@ class CORE_EXPORT QgsApplication : public QApplication
//! initialise qgis.db
static bool createDB( QString* errorMessage = 0 );

//! Create the users theme folder
static bool createThemeFolder( );

//! deletes provider registry and map layer registry
static void exitQgis();

Expand Down Expand Up @@ -320,6 +329,7 @@ class CORE_EXPORT QgsApplication : public QApplication
void preNotify( QObject * receiver, QEvent * event, bool * done );

private:
static void copyPath( QString src, QString dst );
static QObject* ABISYM( mFileOpenEventReceiver );
static QStringList ABISYM( mFileOpenEventList );

Expand Down

0 comments on commit 61e5286

Please sign in to comment.