[Pkg-owncloud-commits] [owncloud-client] 40/120: More improvements for high contrast themes

Sandro Knauß hefee-guest at moszumanska.debian.org
Mon Aug 24 00:02:42 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 379beb268f53fc7b64196202d0dfa3b0d14f607f
Author: Daniel Molkentin <danimo at owncloud.com>
Date:   Tue Aug 11 17:56:02 2015 +0200

    More improvements for high contrast themes
    
    - Invert icon color depending on the darkness of the theme
    - Ensure icons and colors are changed when theme or colors
      get changed during application run
    
    Final patch for #3582
---
 src/gui/settingsdialog.cpp | 92 +++++++++++++++++++++++++++++++++++++---------
 src/gui/settingsdialog.h   |  4 ++
 2 files changed, 79 insertions(+), 17 deletions(-)

diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp
index 46d51b9..5ebaf31 100644
--- a/src/gui/settingsdialog.cpp
+++ b/src/gui/settingsdialog.cpp
@@ -35,6 +35,8 @@
 #include <QToolButton>
 #include <QLayout>
 #include <QVBoxLayout>
+#include <QPixmap>
+#include <QImage>
 
 namespace {
   const char TOOLBAR_CSS[] =
@@ -64,11 +66,6 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
     _ui->setupUi(this);
     _toolBar = new QToolBar;
-    QString highlightColor(palette().highlight().color().name());
-    QString altBase(palette().alternateBase().color().name());
-    QString dark(palette().dark().color().name());
-    QString background(palette().base().color().name());
-    _toolBar->setStyleSheet(QString::fromAscii(TOOLBAR_CSS).arg(background).arg(dark).arg(highlightColor).arg(altBase));
     _toolBar->setIconSize(QSize(32, 32));
     _toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
     layout()->setMenuBar(_toolBar);
@@ -92,23 +89,20 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
 
     // Note: all the actions have a '\n' because the account name is in two lines and
     // all buttons must have the same size in order to keep a good layout
-    QIcon protocolIcon(QLatin1String(":/client/resources/activity.png"));
-    _protocolAction = _actionGroup->addAction(protocolIcon, tr("Activity"));
-    _protocolAction->setCheckable(true);
+    _protocolAction = createColorAwareAction(QLatin1String(":/client/resources/activity.png"), tr("Activity"));
+    _actionGroup->addAction(_protocolAction);
     addActionToToolBar(_protocolAction, _toolBar);
     ProtocolWidget *protocolWidget = new ProtocolWidget;
     _ui->stack->addWidget(protocolWidget);
 
-    QIcon generalIcon(QLatin1String(":/client/resources/settings.png"));
-    QAction *generalAction = _actionGroup->addAction(generalIcon, tr("General"));
-    generalAction->setCheckable(true);
+    QAction *generalAction = createColorAwareAction(QLatin1String(":/client/resources/settings.png"), tr("General"));
+    _actionGroup->addAction(generalAction);
     addActionToToolBar(generalAction, _toolBar);
     GeneralSettings *generalSettings = new GeneralSettings;
     _ui->stack->addWidget(generalSettings);
 
-    QIcon networkIcon(QLatin1String(":/client/resources/network.png"));
-    QAction *networkAction = _actionGroup->addAction(networkIcon, tr("Network"));
-    networkAction->setCheckable(true);
+    QAction *networkAction = createColorAwareAction(QLatin1String(":/client/resources/network.png"), tr("Network"));
+    _actionGroup->addAction(networkAction);
     addActionToToolBar(networkAction, _toolBar);
     NetworkSettings *networkSettings = new NetworkSettings;
     _ui->stack->addWidget(networkSettings);
@@ -138,6 +132,8 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
     connect(showLogWindow, SIGNAL(triggered()), gui, SLOT(slotToggleLogBrowser()));
     addAction(showLogWindow);
 
+    customizeStyle();
+
     ConfigFile cfg;
     cfg.restoreGeometry(this);
 }
@@ -160,6 +156,23 @@ void SettingsDialog::accept() {
     QDialog::accept();
 }
 
+void SettingsDialog::changeEvent(QEvent *e)
+{
+    switch (e->type()) {
+    case QEvent::StyleChange:
+    case QEvent::PaletteChange:
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+    case QEvent::ThemeChange:
+#endif
+        customizeStyle();
+        break;
+    default:
+        break;
+    }
+
+    QDialog::changeEvent(e);
+}
+
 void SettingsDialog::slotSwitchPage(QAction *action)
 {
     _ui->stack->setCurrentWidget(_actionGroupWidgets.value(action));
@@ -174,10 +187,9 @@ void SettingsDialog::showActivityPage()
 
 void SettingsDialog::accountAdded(AccountState *s)
 {
-    QIcon accountIcon(QLatin1String(":/client/resources/account.png"));
-    auto accountAction = new QAction(accountIcon, s->shortDisplayNameForSettings(), this);
+    auto accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"),
+                                                    s->shortDisplayNameForSettings());
     accountAction->setToolTip(s->account()->displayName());
-    accountAction->setCheckable(true);
 
     QToolButton* accountButton = new QToolButton;
     accountButton->setDefaultAction(accountAction);
@@ -216,6 +228,52 @@ void SettingsDialog::accountRemoved(AccountState *s)
     }
 }
 
+void SettingsDialog::customizeStyle()
+{
+    QString highlightColor(palette().highlight().color().name());
+    QString altBase(palette().alternateBase().color().name());
+    QString dark(palette().dark().color().name());
+    QString background(palette().base().color().name());
+    _toolBar->setStyleSheet(QString::fromAscii(TOOLBAR_CSS).arg(background).arg(dark).arg(highlightColor).arg(altBase));
+
+    Q_FOREACH(QAction *a, _actionGroup->actions()) {
+        qDebug() << Q_FUNC_INFO << a->property("iconPath").toString();
+        QIcon icon = createColorAwareIcon(a->property("iconPath").toString());
+        a->setIcon(icon);
+        QToolButton *btn = qobject_cast<QToolButton*>(_toolBar->widgetForAction(a));
+        if (btn) {
+            qDebug() << "SETTING BUTTON!";
+            btn->setIcon(icon);
+        }
+    }
+
+}
+
+QIcon SettingsDialog::createColorAwareIcon(const QString &name)
+{
+    QColor  bg(palette().base().color());
+    qDebug() << Q_FUNC_INFO << bg << bg.name();
+    QImage img(name);
+    // account for different sensitivty of the human eye to certain colors
+    double treshold = 1.0 - ( 0.299 * bg.red() + 0.587 * bg.green() + 0.114 * bg.blue())/255.0;
+    qDebug() << Q_FUNC_INFO << bg.red() << bg.green() << bg.blue();
+    qDebug() << Q_FUNC_INFO << treshold;
+    if (treshold > 0.5) {
+        img.invertPixels(QImage::InvertRgb);
+    }
+
+    return QIcon(QPixmap::fromImage(img));
+}
+
+QAction *SettingsDialog::createColorAwareAction(const QString &iconPath, const QString &text)
+{
+    // all buttons must have the same size in order to keep a good layout
+    QIcon coloredIcon = createColorAwareIcon(iconPath);
+    QAction *action = new QAction(coloredIcon, text, this);
+    action->setCheckable(true);
+    action->setProperty("iconPath", iconPath);
+    return action;
+}
 
 
 } // namespace OCC
diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h
index 46d0b55..dbd4ff2 100644
--- a/src/gui/settingsdialog.h
+++ b/src/gui/settingsdialog.h
@@ -57,12 +57,16 @@ public slots:
 protected:
     void reject() Q_DECL_OVERRIDE;
     void accept() Q_DECL_OVERRIDE;
+    void changeEvent(QEvent *);
 
 private slots:
     void accountAdded(AccountState *);
     void accountRemoved(AccountState *);
 
 private:
+    void customizeStyle();
+    QIcon createColorAwareIcon(const QString &name);
+    QAction *createColorAwareAction(const QString &iconName, const QString &fileName);
     Ui::SettingsDialog * const _ui;
 
     QActionGroup* _actionGroup;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list