]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Improve macOS SysTray/StatusBar monochrome icon (#5227)
authorTommy Sparber <tsparber@users.noreply.github.com>
Thu, 6 Oct 2016 15:18:51 +0000 (17:18 +0200)
committerMarkus Goetz <markus@woboq.com>
Thu, 6 Oct 2016 15:18:51 +0000 (17:18 +0200)
- Use a white icon if the context menu is visible.
- Enable `QIcon::setIsMask` if compiled on Qt >= 5.6 to allow automatic
  macOS color handling.
- No changes if the colored icons are used.

src/gui/owncloudgui.cpp
src/libsync/theme.cpp
src/libsync/theme.h

index 1f5226944dd7231beb9db67b079c6aff1c7d5525..ae5eb0170397f5c5e8c14e7433649009582e35be 100644 (file)
@@ -67,7 +67,7 @@ ownCloudGui::ownCloudGui(Application *parent) :
     _tray->setParent(this);
 
     // for the beginning, set the offline icon until the account was verified
-    _tray->setIcon( Theme::instance()->folderOfflineIcon(true));
+    _tray->setIcon( Theme::instance()->folderOfflineIcon(true, contextMenuVisible()));
 
     connect(_tray.data(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
             SLOT(slotTrayClicked(QSystemTrayIcon::ActivationReason)));
@@ -262,7 +262,7 @@ void ownCloudGui::slotComputeOverallSyncStatus()
     }
 
     if (!problemAccounts.empty()) {
-        _tray->setIcon(Theme::instance()->folderOfflineIcon(true));
+        _tray->setIcon(Theme::instance()->folderOfflineIcon(true, contextMenuVisible()));
 #ifdef Q_OS_WIN
         // Windows has a 128-char tray tooltip length limit.
         QStringList accountNames;
@@ -289,11 +289,11 @@ void ownCloudGui::slotComputeOverallSyncStatus()
     }
 
     if (allSignedOut) {
-        _tray->setIcon(Theme::instance()->folderOfflineIcon(true));
+        _tray->setIcon(Theme::instance()->folderOfflineIcon(true, contextMenuVisible()));
         _tray->setToolTip(tr("Please sign in"));
         return;
     } else if (allPaused) {
-        _tray->setIcon(Theme::instance()->syncStateIcon(SyncResult::Paused, true));
+        _tray->setIcon(Theme::instance()->syncStateIcon(SyncResult::Paused, true, contextMenuVisible()));
         _tray->setToolTip(tr("Account synchronization is disabled"));
         return;
     }
@@ -323,12 +323,12 @@ void ownCloudGui::slotComputeOverallSyncStatus()
             trayMessage = tr("No sync folders configured.");
         }
 
-        QIcon statusIcon = Theme::instance()->syncStateIcon( overallResult.status(), true);
+        QIcon statusIcon = Theme::instance()->syncStateIcon( overallResult.status(), true, contextMenuVisible());
         _tray->setIcon( statusIcon );
         _tray->setToolTip(trayMessage);
     } else {
         // undefined because there are no folders.
-        QIcon icon = Theme::instance()->syncStateIcon(SyncResult::Problem, true);
+        QIcon icon = Theme::instance()->syncStateIcon(SyncResult::Problem, true, contextMenuVisible());
         _tray->setIcon( icon );
         _tray->setToolTip(tr("There are no sync folders configured."));
     }
@@ -405,6 +405,9 @@ void ownCloudGui::slotContextMenuAboutToShow()
     // For some reason on OS X _contextMenu->isVisible returns always false
     qDebug() << "";
     _contextMenuVisibleOsx = true;
+
+    // Update icon in sys tray, as it might change depending on the context menu state
+    slotComputeOverallSyncStatus();
 }
 
 void ownCloudGui::slotContextMenuAboutToHide()
@@ -412,6 +415,9 @@ void ownCloudGui::slotContextMenuAboutToHide()
     // For some reason on OS X _contextMenu->isVisible returns always false
     qDebug() << "";
     _contextMenuVisibleOsx = false;
+
+    // Update icon in sys tray, as it might change depending on the context menu state
+    slotComputeOverallSyncStatus();
 }
 
 bool ownCloudGui::contextMenuVisible() const
index 5dfecc94ba502fa4dedd3d6f7c22c180b17ec5af..474124275c8761f9142f4c0466a2d215ecbef9ce 100644 (file)
@@ -115,11 +115,11 @@ QIcon Theme::trayFolderIcon( const QString& backend ) const
  * helper to load a icon from either the icon theme the desktop provides or from
  * the apps Qt resources.
  */
-QIcon Theme::themeIcon( const QString& name, bool sysTray ) const
+QIcon Theme::themeIcon( const QString& name, bool sysTray, bool sysTrayMenuVisible ) const
 {
     QString flavor;
     if (sysTray) {
-        flavor = systrayIconFlavor(_mono);
+        flavor = systrayIconFlavor(_mono, sysTrayMenuVisible);
     } else {
         flavor = QLatin1String("colored");
     }
@@ -158,6 +158,14 @@ QIcon Theme::themeIcon( const QString& name, bool sysTray ) const
         }
     }
 
+    #ifdef Q_OS_MAC
+    #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
+    // This defines the icon as a template and enables automatic macOS color handling
+    // See https://bugreports.qt.io/browse/QTBUG-42109
+    cached.setIsMask(_mono && sysTray && !sysTrayMenuVisible);
+    #endif
+    #endif
+
     return cached;
 }
 
@@ -227,11 +235,17 @@ QString Theme::defaultClientFolder() const
     return appName();
 }
 
-QString Theme::systrayIconFlavor(bool mono) const
+QString Theme::systrayIconFlavor(bool mono, bool sysTrayMenuVisible ) const
 {
     QString flavor;
     if (mono) {
         flavor = Utility::hasDarkSystray() ? QLatin1String("white") : QLatin1String("black");
+
+        #ifdef Q_OS_MAC
+        if (sysTrayMenuVisible) {
+            flavor = QLatin1String("white");
+        }
+        #endif
     } else {
         flavor = QLatin1String("colored");
     }
@@ -331,7 +345,7 @@ QVariant Theme::customMedia( CustomMediaType type )
     return re;
 }
 
-QIcon Theme::syncStateIcon( SyncResult::Status status, bool sysTray ) const
+QIcon Theme::syncStateIcon( SyncResult::Status status, bool sysTray, bool sysTrayMenuVisible ) const
 {
     // FIXME: Mind the size!
     QString statusIcon;
@@ -363,7 +377,7 @@ QIcon Theme::syncStateIcon( SyncResult::Status status, bool sysTray ) const
         statusIcon = QLatin1String("state-error");
     }
 
-    return themeIcon( statusIcon, sysTray );
+    return themeIcon( statusIcon, sysTray, sysTrayMenuVisible );
 }
 
 QIcon Theme::folderDisabledIcon( ) const
@@ -371,9 +385,9 @@ QIcon Theme::folderDisabledIcon( ) const
     return themeIcon( QLatin1String("state-pause") );
 }
 
-QIcon Theme::folderOfflineIcon(bool systray) const
+QIcon Theme::folderOfflineIcon(bool sysTray, bool sysTrayMenuVisible ) const
 {
-    return themeIcon( QLatin1String("state-offline"), systray );
+    return themeIcon( QLatin1String("state-offline"), sysTray, sysTrayMenuVisible );
 }
 
 QColor Theme::wizardHeaderTitleColor() const
index 84416fc782d7cd741ff324b150f0bc2323258a25..63c86b4aa1f1e9076c8148fd94f17e99c88b3f76 100644 (file)
@@ -97,10 +97,10 @@ public:
     /**
       * get an sync state icon
       */
-    virtual QIcon   syncStateIcon( SyncResult::Status, bool sysTray = false ) const;
+    virtual QIcon   syncStateIcon( SyncResult::Status, bool sysTray = false, bool sysTrayMenuVisible = false) const;
 
     virtual QIcon   folderDisabledIcon() const;
-    virtual QIcon   folderOfflineIcon(bool systray = false) const;
+    virtual QIcon   folderOfflineIcon(bool sysTray = false, bool sysTrayMenuVisible = false) const;
     virtual QIcon   applicationIcon() const = 0;
 #endif
 
@@ -152,7 +152,7 @@ public:
     virtual QString enforcedLocale() const { return QString::null; }
 
     /** colored, white or black */
-    QString systrayIconFlavor(bool mono) const;
+    QString systrayIconFlavor(bool mono, bool sysTrayMenuVisible = false) const;
 
 #ifndef TOKEN_AUTH_ONLY
     /**
@@ -304,7 +304,7 @@ public:
 
 protected:
 #ifndef TOKEN_AUTH_ONLY
-    QIcon themeIcon(const QString& name, bool sysTray = false) const;
+    QIcon themeIcon(const QString& name, bool sysTray = false, bool sysTrayMenuVisible = false) const;
 #endif
     Theme();