Skip to content
Permalink
Browse files

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
  • Loading branch information
3nids committed Oct 25, 2018
1 parent 20a205d commit 0959e9f4531fbb493b55990f4d1ecb0d9fd8efc6
Showing with 31 additions and 5 deletions.
  1. +17 −3 src/app/qgisapp.cpp
  2. +2 −2 src/app/qgsoptions.cpp
  3. +2 −0 src/native/mac/qgsmacnative.h
  4. +5 −0 src/native/mac/qgsmacnative.mm
  5. +5 −0 src/native/qgsnative.h
@@ -2002,8 +2002,8 @@ int QgisApp::dockedToolbarIconSize( int standardToolbarIconSize ) const
void QgisApp::readSettings()
{
QgsSettings settings;
QString themename = settings.value( QStringLiteral( "UI/UITheme" ), "default" ).toString();
setTheme( themename );
QString themeName = settings.value( QStringLiteral( "UI/UITheme" ), "default" ).toString();
setTheme( themeName );

// Read legacy settings
readRecentProjects();
@@ -3208,7 +3208,21 @@ void QgisApp::setTheme( const QString &themeName )
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);
mActionNewProject->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileNew.svg" ) ) );
mActionOpenProject->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileOpen.svg" ) ) );
@@ -566,7 +566,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
QString name = mSettings->value( QStringLiteral( "/qgis/style" ) ).toString();
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 ) );

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

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

void QgsOptions::mProjectOnLaunchCmbBx_currentIndexChanged( int indx )
@@ -38,6 +38,8 @@ class NATIVE_EXPORT QgsMacNative : public QgsNative
QgsNative::Capabilities capabilities() const override;
QgsNative::NotificationResult showDesktopNotification( const QString &summary, const QString &body, const NotificationSettings &settings ) override;

bool hasDarkTheme() override;

private:
class QgsUserNotificationCenter;
QgsUserNotificationCenter *mQgsUserNotificationCenter = nullptr;
@@ -118,3 +118,8 @@ - ( BOOL )userNotificationCenter:( NSUserNotificationCenter * )center shouldPres
result.successful = true;
return result;
}

bool QgsMacNative::hasDarkTheme()
{
return ( NSApp.effectiveAppearance.name != NSAppearanceNameAqua );
}
@@ -135,6 +135,11 @@ class NATIVE_EXPORT QgsNative : public QObject
*/
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().
*/

1 comment on commit 0959e9f

@slarosa

This comment has been minimized.

Copy link
Member

@slarosa slarosa commented on 0959e9f Oct 26, 2018

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.
You can’t perform that action at this time.