Skip to content

Commit

Permalink
force Night Mapping theme on Mac Mojave with Dark Theme (#8309)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
3nids committed Oct 25, 2018
1 parent 20a205d commit 0959e9f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
20 changes: 17 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -2002,8 +2002,8 @@ int QgisApp::dockedToolbarIconSize( int standardToolbarIconSize ) const
void QgisApp::readSettings() void QgisApp::readSettings()
{ {
QgsSettings settings; QgsSettings settings;
QString themename = settings.value( QStringLiteral( "UI/UITheme" ), "default" ).toString(); QString themeName = settings.value( QStringLiteral( "UI/UITheme" ), "default" ).toString();
setTheme( themename ); setTheme( themeName );


// Read legacy settings // Read legacy settings
readRecentProjects(); readRecentProjects();
Expand Down Expand Up @@ -3208,7 +3208,21 @@ void QgisApp::setTheme( const QString &themeName )
for the user to choose from. for the user to choose from.
*/ */


QgsApplication::setUITheme( themeName ); QString theme = themeName;
#ifdef Q_OS_MAC
#if QT_VERSION < QT_VERSION_CHECK( 5, 12, 0 )
if ( theme == QStringLiteral( "default" ) &&
QgsGui::instance()->nativePlatformInterface()->hasDarkTheme() )
{
QString darkTheme = QStringLiteral( "Night Mapping" );
if ( QgsApplication::uiThemes().contains( darkTheme ) )
theme = darkTheme;
}
#endif
#endif

QgsApplication::setUITheme( theme );

//QgsDebugMsg("Setting theme to \n" + themeName); //QgsDebugMsg("Setting theme to \n" + themeName);
mActionNewProject->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileNew.svg" ) ) ); mActionNewProject->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileNew.svg" ) ) );
mActionOpenProject->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileOpen.svg" ) ) ); mActionOpenProject->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileOpen.svg" ) ) );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsoptions.cpp
Expand Up @@ -566,7 +566,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
QString name = mSettings->value( QStringLiteral( "/qgis/style" ) ).toString(); QString name = mSettings->value( QStringLiteral( "/qgis/style" ) ).toString();
cmbStyle->setCurrentIndex( cmbStyle->findText( name, Qt::MatchFixedString ) ); cmbStyle->setCurrentIndex( cmbStyle->findText( name, Qt::MatchFixedString ) );


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


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


QgsApplication::setUITheme( theme ); QgisApp::instance()->setTheme( theme );
} }


void QgsOptions::mProjectOnLaunchCmbBx_currentIndexChanged( int indx ) void QgsOptions::mProjectOnLaunchCmbBx_currentIndexChanged( int indx )
Expand Down
2 changes: 2 additions & 0 deletions src/native/mac/qgsmacnative.h
Expand Up @@ -38,6 +38,8 @@ class NATIVE_EXPORT QgsMacNative : public QgsNative
QgsNative::Capabilities capabilities() const override; QgsNative::Capabilities capabilities() const override;
QgsNative::NotificationResult showDesktopNotification( const QString &summary, const QString &body, const NotificationSettings &settings ) override; QgsNative::NotificationResult showDesktopNotification( const QString &summary, const QString &body, const NotificationSettings &settings ) override;


bool hasDarkTheme() override;

private: private:
class QgsUserNotificationCenter; class QgsUserNotificationCenter;
QgsUserNotificationCenter *mQgsUserNotificationCenter = nullptr; QgsUserNotificationCenter *mQgsUserNotificationCenter = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions src/native/mac/qgsmacnative.mm
Expand Up @@ -118,3 +118,8 @@ - ( BOOL )userNotificationCenter:( NSUserNotificationCenter * )center shouldPres
result.successful = true; result.successful = true;
return result; return result;
} }

bool QgsMacNative::hasDarkTheme()
{
return ( NSApp.effectiveAppearance.name != NSAppearanceNameAqua );
}
5 changes: 5 additions & 0 deletions src/native/qgsnative.h
Expand Up @@ -135,6 +135,11 @@ class NATIVE_EXPORT QgsNative : public QObject
*/ */
virtual void setApplicationBadgeCount( int count ); virtual void setApplicationBadgeCount( int count );


/**
* Returns true if the operating system is set to utilise a "dark" theme.
*/
virtual bool hasDarkTheme() {return false;}

/** /**
* Notification settings, for use with showDesktopNotification(). * Notification settings, for use with showDesktopNotification().
*/ */
Expand Down

1 comment on commit 0959e9f

@slarosa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.