Skip to content

Commit 0959e9f

Browse files
authoredOct 25, 2018
force Night Mapping theme on Mac Mojave with Dark Theme (#8309)
* force Night Mapping theme on Mac Mojave with Dark Theme otherwise QGIS is pretty unusable see #20195 * [themes] add automatic mode to base theme on OS theme only effective on Mac OS for now * Revert "add auto theme based on OS to choose default / dark theme" This reverts commit d012451cadb4653421eb49711ac99ed48e064622. * apply auto theme only for Qt < 5.12 * Update src/app/qgisapp.cpp * better doc
1 parent 20a205d commit 0959e9f

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,8 +2002,8 @@ int QgisApp::dockedToolbarIconSize( int standardToolbarIconSize ) const
20022002
void QgisApp::readSettings()
20032003
{
20042004
QgsSettings settings;
2005-
QString themename = settings.value( QStringLiteral( "UI/UITheme" ), "default" ).toString();
2006-
setTheme( themename );
2005+
QString themeName = settings.value( QStringLiteral( "UI/UITheme" ), "default" ).toString();
2006+
setTheme( themeName );
20072007

20082008
// Read legacy settings
20092009
readRecentProjects();
@@ -3208,7 +3208,21 @@ void QgisApp::setTheme( const QString &themeName )
32083208
for the user to choose from.
32093209
*/
32103210

3211-
QgsApplication::setUITheme( themeName );
3211+
QString theme = themeName;
3212+
#ifdef Q_OS_MAC
3213+
#if QT_VERSION < QT_VERSION_CHECK( 5, 12, 0 )
3214+
if ( theme == QStringLiteral( "default" ) &&
3215+
QgsGui::instance()->nativePlatformInterface()->hasDarkTheme() )
3216+
{
3217+
QString darkTheme = QStringLiteral( "Night Mapping" );
3218+
if ( QgsApplication::uiThemes().contains( darkTheme ) )
3219+
theme = darkTheme;
3220+
}
3221+
#endif
3222+
#endif
3223+
3224+
QgsApplication::setUITheme( theme );
3225+
32123226
//QgsDebugMsg("Setting theme to \n" + themeName);
32133227
mActionNewProject->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileNew.svg" ) ) );
32143228
mActionOpenProject->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileOpen.svg" ) ) );

‎src/app/qgsoptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
566566
QString name = mSettings->value( QStringLiteral( "/qgis/style" ) ).toString();
567567
cmbStyle->setCurrentIndex( cmbStyle->findText( name, Qt::MatchFixedString ) );
568568

569-
QString theme = QgsApplication::themeName();
569+
QString theme = mSettings->value( QStringLiteral( "UI/UITheme" ), QStringLiteral( "auto" ) ).toString();
570570
cmbUITheme->setCurrentIndex( cmbUITheme->findText( theme, Qt::MatchFixedString ) );
571571

572572
mNativeColorDialogsChkBx->setChecked( mSettings->value( QStringLiteral( "/qgis/native_color_dialogs" ), false ).toBool() );
@@ -1235,7 +1235,7 @@ void QgsOptions::uiThemeChanged( const QString &theme )
12351235
if ( theme == QgsApplication::themeName() )
12361236
return;
12371237

1238-
QgsApplication::setUITheme( theme );
1238+
QgisApp::instance()->setTheme( theme );
12391239
}
12401240

12411241
void QgsOptions::mProjectOnLaunchCmbBx_currentIndexChanged( int indx )

‎src/native/mac/qgsmacnative.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class NATIVE_EXPORT QgsMacNative : public QgsNative
3838
QgsNative::Capabilities capabilities() const override;
3939
QgsNative::NotificationResult showDesktopNotification( const QString &summary, const QString &body, const NotificationSettings &settings ) override;
4040

41+
bool hasDarkTheme() override;
42+
4143
private:
4244
class QgsUserNotificationCenter;
4345
QgsUserNotificationCenter *mQgsUserNotificationCenter = nullptr;

‎src/native/mac/qgsmacnative.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,8 @@ - ( BOOL )userNotificationCenter:( NSUserNotificationCenter * )center shouldPres
118118
result.successful = true;
119119
return result;
120120
}
121+
122+
bool QgsMacNative::hasDarkTheme()
123+
{
124+
return ( NSApp.effectiveAppearance.name != NSAppearanceNameAqua );
125+
}

‎src/native/qgsnative.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ class NATIVE_EXPORT QgsNative : public QObject
135135
*/
136136
virtual void setApplicationBadgeCount( int count );
137137

138+
/**
139+
* Returns true if the operating system is set to utilise a "dark" theme.
140+
*/
141+
virtual bool hasDarkTheme() {return false;}
142+
138143
/**
139144
* Notification settings, for use with showDesktopNotification().
140145
*/

1 commit comments

Comments
 (1)

slarosa commented on Oct 26, 2018

@slarosa
Member

I am getting the following build error:

[  0%] Building CXX object src/native/CMakeFiles/qgis_native.dir/mac/qgsmacnative.mm.o
/Users/slarosa/dev/qgis-src/QGIS/src/native/mac/qgsmacnative.mm:124:18: error: property 'effectiveAppearance' not found on object of type '__kindof NSApplication *'
  return ( NSApp.effectiveAppearance.name != NSAppearanceNameAqua );
                 ^
1 error generated.
make[2]: *** [src/native/CMakeFiles/qgis_native.dir/mac/qgsmacnative.mm.o] Error 1
make[1]: *** [src/native/CMakeFiles/qgis_native.dir/all] Error 2
make: *** [all] Error 2
Please sign in to comment.