mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Add variable support to themes
- Variables loaded from variables.qss file - @varname: value e.g @mycolor: red - Copy base themes to users home
This commit is contained in:
parent
37fc2444d4
commit
61e5286e39
BIN
resources/themes/Night Mapping/icons/up_arrow.png
Normal file
BIN
resources/themes/Night Mapping/icons/up_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 990 B |
@ -2,20 +2,20 @@ QToolTip
|
|||||||
{
|
{
|
||||||
border: 1px solid #222;
|
border: 1px solid #222;
|
||||||
background-color: #333;
|
background-color: #333;
|
||||||
color: #aaa;
|
color: @text;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget
|
QWidget
|
||||||
{
|
{
|
||||||
color: #aaa;
|
color: @text;
|
||||||
background-color: #323232;
|
background-color: @background;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QWidget:item:hover
|
QWidget:item:hover
|
||||||
{
|
{
|
||||||
background-color: #507098;
|
background-color: #507098;
|
||||||
color: #aaa;
|
color: @text;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget:item:selected
|
QWidget:item:selected
|
||||||
@ -24,7 +24,7 @@ QWidget:item:selected
|
|||||||
}
|
}
|
||||||
|
|
||||||
QMenuBar {
|
QMenuBar {
|
||||||
background-color: #323232;
|
background-color: @background;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMenuBar::item
|
QMenuBar::item
|
||||||
@ -87,7 +87,7 @@ QMenu
|
|||||||
QMenu::item
|
QMenu::item
|
||||||
{
|
{
|
||||||
background: transparent;
|
background: transparent;
|
||||||
padding: 2px 20px 2px 20px;
|
padding: 5px 20px 5px 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMenu::item:disabled
|
QMenu::item:disabled
|
||||||
@ -101,13 +101,13 @@ QMenu::item:disabled
|
|||||||
QMenu::item:selected
|
QMenu::item:selected
|
||||||
{
|
{
|
||||||
background-color: #507098;
|
background-color: #507098;
|
||||||
color: #aaa;
|
color: @text;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget:disabled
|
QWidget:disabled
|
||||||
{
|
{
|
||||||
color: #404040;
|
color: #404040;
|
||||||
background-color: #323232;
|
background-color: @background;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLineEdit
|
QLineEdit
|
||||||
@ -171,7 +171,7 @@ QComboBox:on {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QComboBox:editable {
|
QComboBox:editable {
|
||||||
background: #323232;
|
background: @background;
|
||||||
}
|
}
|
||||||
|
|
||||||
QComboBox QAbstractItemView {
|
QComboBox QAbstractItemView {
|
||||||
@ -279,7 +279,7 @@ QDockWidget::title
|
|||||||
{
|
{
|
||||||
text-align: center;
|
text-align: center;
|
||||||
spacing: 3px; /* spacing between items in the tool bar */
|
spacing: 3px; /* spacing between items in the tool bar */
|
||||||
background-color: #323232;
|
background-color: @background;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,8 +319,8 @@ QMainWindow::separator:hover
|
|||||||
}
|
}
|
||||||
|
|
||||||
QToolBar {
|
QToolBar {
|
||||||
background: #323232;
|
background: @background;
|
||||||
border: 1px solid #323232;
|
border: 1px solid @background;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,7 +373,7 @@ QTabBar::tab {
|
|||||||
color: #b1b1b1;
|
color: #b1b1b1;
|
||||||
border: 1px solid #444;
|
border: 1px solid #444;
|
||||||
border-bottom-style: none;
|
border-bottom-style: none;
|
||||||
background-color: #323232;
|
background-color: @background;
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
padding-right: 10px;
|
padding-right: 10px;
|
||||||
padding-top: 3px;
|
padding-top: 3px;
|
||||||
@ -396,12 +396,13 @@ QTabBar::tab:first:!selected
|
|||||||
margin-left: 0px; /* the last selected tab has nothing to overlap with on the right */
|
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
|
QTabBar::tab:!selected
|
||||||
{
|
{
|
||||||
color: #b1b1b1;
|
margin-top: 5px;
|
||||||
border-bottom-style: solid;
|
|
||||||
margin-top: 3px;
|
|
||||||
/*background-color: QLinearGradient(x1:0, y1:0, x2:0, y2:1, stop:1 #212121, stop:.4 #343434);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTabBar::tab:selected
|
QTabBar::tab:selected
|
||||||
@ -423,23 +424,32 @@ QTabBar::tab:!selected:hover
|
|||||||
QGroupBox::indicator:unchecked,
|
QGroupBox::indicator:unchecked,
|
||||||
QGroupBox::indicator:checked,
|
QGroupBox::indicator:checked,
|
||||||
QCheckBox::indicator:checked,
|
QCheckBox::indicator:checked,
|
||||||
QCheckBox::indicator:unchecked,
|
QCheckBox::indicator:unchecked
|
||||||
QRadioButton::indicator:checked,
|
QRadioButton::indicator:checked,
|
||||||
QRadioButton::indicator:unchecked{
|
QRadioButton::indicator:unchecked{
|
||||||
color: #b1b1b1;
|
color: #b1b1b1;
|
||||||
background-color: #323232;
|
background-color: @background;
|
||||||
border: 1px solid #b1b1b1;
|
border: 1px solid #b1b1b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QGroupBox::indicator:checked,
|
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 {
|
QRadioButton::indicator:checked {
|
||||||
background-color: qradialgradient(
|
background-color: qradialgradient(
|
||||||
cx: 0.5, cy: 0.5,
|
cx: 0.5, cy: 0.5,
|
||||||
fx: 0.5, fy: 0.5,
|
fx: 0.5, fy: 0.5,
|
||||||
radius: 1.0,
|
radius: 1.0,
|
||||||
stop: 0.25 #ffaa00,
|
stop: 0.25 #ffaa00,
|
||||||
stop: 0.3 #323232
|
stop: 0.3 @background
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,7 +471,7 @@ QRadioButton::indicator:hover
|
|||||||
QAbstractItemView
|
QAbstractItemView
|
||||||
{
|
{
|
||||||
background-color: #222;
|
background-color: #222;
|
||||||
alternate-background-color: #323232;
|
alternate-background-color: @background;
|
||||||
color: silver;
|
color: silver;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
@ -513,7 +523,9 @@ QgsLayerTreeView
|
|||||||
}
|
}
|
||||||
|
|
||||||
QgsLayerTreeView::item,
|
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-top: 0.5px solid rgba(108,108,108,50);
|
||||||
border-bottom: 0.5px solid rgba(108,108,108,50);
|
border-bottom: 0.5px solid rgba(108,108,108,50);
|
||||||
@ -521,12 +533,18 @@ QTreeView#viewCategories::item
|
|||||||
}
|
}
|
||||||
|
|
||||||
QgsLayerTreeView::indicator:unchecked,
|
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);
|
image: url(icons/eye-blocked.svg);
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsLayerTreeView::indicator:checked,
|
QgsLayerTreeView::indicator:checked,
|
||||||
QTreeView#viewCategories::indicator:checked {
|
QTreeView#viewGraduated::indicator:checked,
|
||||||
|
QTreeView#viewCategories::indicator:checked,
|
||||||
|
QTreeView#viewRules::indicator:checked
|
||||||
|
{
|
||||||
image: url(icons/eye.svg);
|
image: url(icons/eye.svg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,7 +557,7 @@ QHeaderView {
|
|||||||
|
|
||||||
QHeaderView::section {
|
QHeaderView::section {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
background-color: #323232;
|
background-color: @background;
|
||||||
color: #777;
|
color: #777;
|
||||||
border-right: 0px solid #777;
|
border-right: 0px solid #777;
|
||||||
border-top: 0px solid #777;
|
border-top: 0px solid #777;
|
||||||
|
2
resources/themes/Night Mapping/variables.qss
Normal file
2
resources/themes/Night Mapping/variables.qss
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
@background: #323232
|
||||||
|
@text: #aaa;
|
@ -552,6 +552,9 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
|
|||||||
QMessageBox::critical( this, tr( "Private qgis.db" ), dbError );
|
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 );
|
mSplash->showMessage( tr( "Reading settings" ), Qt::AlignHCenter | Qt::AlignBottom );
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
|
|
||||||
|
@ -437,8 +437,47 @@ void QgsApplication::setUITheme( const QString &themeName )
|
|||||||
// Loop all style sheets, find matching name, load it.
|
// Loop all style sheets, find matching name, load it.
|
||||||
QHash<QString, QString> themes = QgsApplication::uiThemes();
|
QHash<QString, QString> themes = QgsApplication::uiThemes();
|
||||||
QString path = themes[themeName];
|
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:///" );
|
QString styleSheet = QLatin1String( "file:///" );
|
||||||
styleSheet.append( path + "/style.qss" );
|
styleSheet.append( stylesheetname );
|
||||||
qApp->setStyleSheet( styleSheet );
|
qApp->setStyleSheet( styleSheet );
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
return settings.setValue( "UI/UITheme", themeName );
|
return settings.setValue( "UI/UITheme", themeName );
|
||||||
@ -446,9 +485,7 @@ void QgsApplication::setUITheme( const QString &themeName )
|
|||||||
|
|
||||||
QHash<QString, QString> QgsApplication::uiThemes()
|
QHash<QString, QString> QgsApplication::uiThemes()
|
||||||
{
|
{
|
||||||
QString themepath = ABISYM( mPkgDataPath ) + QString( "/resources/themes" );
|
QStringList paths = QStringList() << userThemesFolder();
|
||||||
QString userthemes = qgisSettingsDirPath() + QString( "/themes" );
|
|
||||||
QStringList paths = QStringList() << themepath << userthemes;
|
|
||||||
QHash<QString, QString> mapping;
|
QHash<QString, QString> mapping;
|
||||||
mapping.insert( "default", "" );
|
mapping.insert( "default", "" );
|
||||||
foreach ( const QString& path, paths )
|
foreach ( const QString& path, paths )
|
||||||
@ -643,11 +680,21 @@ QString QgsApplication::userStyleV2Path()
|
|||||||
return qgisSettingsDirPath() + QString( "symbology-ng-style.db" );
|
return qgisSettingsDirPath() + QString( "symbology-ng-style.db" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsApplication::userThemesFolder()
|
||||||
|
{
|
||||||
|
return qgisSettingsDirPath() + QString( "/themes" );
|
||||||
|
}
|
||||||
|
|
||||||
QString QgsApplication::defaultStyleV2Path()
|
QString QgsApplication::defaultStyleV2Path()
|
||||||
{
|
{
|
||||||
return ABISYM( mPkgDataPath ) + QString( "/resources/symbology-ng-style.db" );
|
return ABISYM( mPkgDataPath ) + QString( "/resources/symbology-ng-style.db" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsApplication::defaultThemesFolder()
|
||||||
|
{
|
||||||
|
return ABISYM( mPkgDataPath ) + QString( "/resources/themes" );
|
||||||
|
}
|
||||||
|
|
||||||
QString QgsApplication::libraryPath()
|
QString QgsApplication::libraryPath()
|
||||||
{
|
{
|
||||||
return ABISYM( mLibraryPath );
|
return ABISYM( mLibraryPath );
|
||||||
@ -971,6 +1018,37 @@ void QgsApplication::applyGdalSkippedDrivers()
|
|||||||
GDALAllRegister(); //to update driver list and skip missing ones
|
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 )
|
bool QgsApplication::createDB( QString *errorMessage )
|
||||||
{
|
{
|
||||||
// set a working directory up for gdal to write .aux.xml files into
|
// set a working directory up for gdal to write .aux.xml files into
|
||||||
|
@ -186,9 +186,15 @@ class CORE_EXPORT QgsApplication : public QApplication
|
|||||||
//! Returns the path to user's style.
|
//! Returns the path to user's style.
|
||||||
static QString userStyleV2Path();
|
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).
|
//! Returns the path to default style (works as a starting point).
|
||||||
static QString defaultStyleV2Path();
|
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
|
//! Returns the path containing qgis_core, qgis_gui, qgispython (and other) libraries
|
||||||
static QString libraryPath();
|
static QString libraryPath();
|
||||||
|
|
||||||
@ -213,6 +219,9 @@ class CORE_EXPORT QgsApplication : public QApplication
|
|||||||
//! initialise qgis.db
|
//! initialise qgis.db
|
||||||
static bool createDB( QString* errorMessage = 0 );
|
static bool createDB( QString* errorMessage = 0 );
|
||||||
|
|
||||||
|
//! Create the users theme folder
|
||||||
|
static bool createThemeFolder( );
|
||||||
|
|
||||||
//! deletes provider registry and map layer registry
|
//! deletes provider registry and map layer registry
|
||||||
static void exitQgis();
|
static void exitQgis();
|
||||||
|
|
||||||
@ -320,6 +329,7 @@ class CORE_EXPORT QgsApplication : public QApplication
|
|||||||
void preNotify( QObject * receiver, QEvent * event, bool * done );
|
void preNotify( QObject * receiver, QEvent * event, bool * done );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static void copyPath( QString src, QString dst );
|
||||||
static QObject* ABISYM( mFileOpenEventReceiver );
|
static QObject* ABISYM( mFileOpenEventReceiver );
|
||||||
static QStringList ABISYM( mFileOpenEventList );
|
static QStringList ABISYM( mFileOpenEventList );
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user