Skip to content

Commit

Permalink
Pass on the theme style data directly instead of a file:///...
Browse files Browse the repository at this point in the history
Benefit: remove requirement to have write permission for the
theme directory.
  • Loading branch information
nirvn committed Dec 14, 2018
1 parent e58abfd commit 36d3633
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
18 changes: 9 additions & 9 deletions resources/themes/Night Mapping/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ QAbstractSpinBox {
subcontrol-position: top right;

width: 16px;
image: url(icons/up_arrow.png) 1;
image: url(@theme_path/icons/up_arrow.png) 1;
}

QAbstractSpinBox::down-button {
subcontrol-origin: border;
subcontrol-position: bottom right;

width: 16px;
image: url(icons/down_arrow.png);
image: url(@theme_path/icons/down_arrow.png);
}


Expand Down Expand Up @@ -159,7 +159,7 @@ QToolButton::hover, QToolButton::menu-button::hover
}
QToolButton::menu-arrow
{
image: url(icons/down_arrow.png);
image: url(@theme_path/icons/down_arrow.png);
}
QToolBar QToolButton, QToolButton::menu-button
{
Expand Down Expand Up @@ -219,7 +219,7 @@ QComboBox::drop-down {

QComboBox::down-arrow
{
image: url(icons/down_arrow.png);
image: url(@theme_path/icons/down_arrow.png);
}


Expand Down Expand Up @@ -298,7 +298,7 @@ QHeaderView::section
}
QDockWidget
{
titlebar-close-icon: url(icons/cross.svg);
titlebar-close-icon: url(@theme_path/icons/cross.svg);
}

QDockWidget::separator
Expand Down Expand Up @@ -566,13 +566,13 @@ QTreeView::item:selected, QTreeView::branch:selected {
QTreeView::branch:has-children:!has-siblings:closed,
QTreeView::branch:closed:has-children:has-siblings {
border-image: none;
image: url(icons/caret-right_ffffff_14.png);
image: url(@theme_path/icons/caret-right_ffffff_14.png);
}

QTreeView::branch:open:has-children:!has-siblings,
QTreeView::branch:open:has-children:has-siblings {
border-image: none;
image: url(icons/caret-down_ffffff_14.png);
image: url(@theme_path/icons/caret-down_ffffff_14.png);
}

QgsLayerTreeView
Expand All @@ -594,15 +594,15 @@ QTreeView#viewGraduated::indicator:unchecked,
QTreeView#viewCategories::indicator:unchecked,
QTreeView#viewRules::indicator:unchecked
{
image: url(icons/eye-blocked.svg);
image: url(@theme_path/icons/eye-blocked.svg);
}

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

/* ==================================================================================== */
Expand Down
26 changes: 10 additions & 16 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,22 +728,22 @@ void QgsApplication::setUITheme( const QString &themeName )

QString path = themes.value( 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 ) || ( variableInfo.exists() && !variablesfile.open( QIODevice::ReadOnly ) ) )
{
if ( !file.open( QIODevice::ReadOnly ) || !fileout.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
{
return;
}
return;
}

QString styledata = file.readAll();
styledata.replace( QStringLiteral( "@theme_path" ), path );

QString styledata = file.readAll();
if ( variableInfo.exists() )
{
QTextStream in( &variablesfile );
while ( !in.atEnd() )
{
Expand All @@ -758,16 +758,10 @@ void QgsApplication::setUITheme( const QString &themeName )
}
}
variablesfile.close();
QTextStream out( &fileout );
out << styledata;
fileout.close();
file.close();
stylesheetname = autostylesheet;
}
file.close();

QString styleSheet = QStringLiteral( "file:///" );
styleSheet.append( stylesheetname );
qApp->setStyleSheet( styleSheet );
qApp->setStyleSheet( styledata );
setThemeName( themeName );
}

Expand Down

0 comments on commit 36d3633

Please sign in to comment.