[Gui] Apply createColorAwareIcon on more icons

This commit is contained in:
Hannah von Reth 2020-03-03 11:12:55 +01:00 committed by Hannah von Reth
parent 7b75fe2c93
commit 90cdbe442b
14 changed files with 50 additions and 32 deletions

View File

@ -0,0 +1,6 @@
Bugfix: Fix serveral wrong colored icons in dark mode
We fixed multiple issues where monocrome icons where not converted to match the
current theme.
https://github.com/owncloud/client/issues/7043

View File

@ -25,6 +25,7 @@
#include "folderman.h"
#include "accessmanager.h"
#include "activityitemdelegate.h"
#include "guiutility.h"
#include "activitydata.h"
#include "activitylistmodel.h"
@ -68,7 +69,7 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
return QVariant(); // FIXME once the action can be quantified, display on Icon
break;
case ActivityItemDelegate::UserIconRole:
return QIcon(QLatin1String(":/client/resources/account.png"));
return Utility::createColorAwareIcon(QLatin1String(":/client/resources/account.png"));
break;
case Qt::ToolTipRole:
return tr("%1 %2 on %3").arg(a._subject, Utility::timeAgoInWords(a._dateTime), a._accName);

View File

@ -21,6 +21,8 @@
#include <QMessageBox>
#include <QUrlQuery>
#include "theme.h"
#include "common/asserts.h"
using namespace OCC;
@ -95,3 +97,17 @@ QString Utility::vfsFreeSpaceActionText()
{
return QCoreApplication::translate("utility", "Free up local space");
}
QPixmap Utility::createColorAwareIcon(const QString &name, const QPalette &palette)
{
const QColor bg(palette.base().color());
QImage img(Theme::hidpiFileName(name));
if (img.isGrayscale()) {
// account for different sensitivity 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;
if (treshold > 0.5) {
img.invertPixels(QImage::InvertRgb);
}
}
return QPixmap::fromImage(img);
}

View File

@ -49,6 +49,9 @@ namespace Utility {
/** Translated text for "free up local space" (and unpinning the item) */
QString vfsFreeSpaceActionText();
/** Create bw icon with matching contrast for the current theme */
QPixmap createColorAwareIcon(const QString &name, const QPalette &palette = QPalette());
} // namespace Utility
} // namespace OCC

View File

@ -16,6 +16,7 @@
#include "QProgressIndicator.h"
#include "common/utility.h"
#include "common/asserts.h"
#include "guiutility.h"
#include <QPushButton>
@ -56,9 +57,9 @@ void NotificationWidget::setActivity(const Activity &activity)
_ui._messageLabel->setText(activity._message);
_ui._notifIcon->setPixmap(QPixmap(":/client/resources/bell.png"));
_ui._notifIcon->setMinimumWidth(64);
_ui._notifIcon->setMinimumHeight(64);
const auto icon = Utility::createColorAwareIcon(":/client/resources/bell.png").scaled(64, 64, Qt::KeepAspectRatio);
_ui._notifIcon->setPixmap(icon);
_ui._notifIcon->setFixedSize(icon.size());
_ui._notifIcon->show();
QString tText = tr("Created at %1").arg(Utility::timeAgoInWords(activity._dateTime));

View File

@ -18,6 +18,7 @@
#include "folderman.h"
#include "theme.h"
#include "generalsettings.h"
#include "guiutility.h"
#include "networksettings.h"
#include "accountsettings.h"
#include "configfile.h"
@ -349,7 +350,7 @@ void SettingsDialog::customizeStyle()
_toolBar->setStyleSheet(TOOLBAR_CSS().arg(background, dark, highlightColor, highlightTextColor));
Q_FOREACH (QAction *a, _actionGroup->actions()) {
QIcon icon = createColorAwareIcon(a->property("iconPath").toString());
QIcon icon = Utility::createColorAwareIcon(a->property("iconPath").toString(), palette());
a->setIcon(icon);
QToolButton *btn = qobject_cast<QToolButton *>(_toolBar->widgetForAction(a));
if (btn) {
@ -358,19 +359,6 @@ void SettingsDialog::customizeStyle()
}
}
QIcon SettingsDialog::createColorAwareIcon(const QString &name)
{
QColor bg(palette().base().color());
QImage img(name);
// account for different sensitivity 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;
if (treshold > 0.5) {
img.invertPixels(QImage::InvertRgb);
}
return QIcon(QPixmap::fromImage(img));
}
class ToolButtonAction : public QWidgetAction
{
public:
@ -413,7 +401,7 @@ QAction *SettingsDialog::createActionWithIcon(const QIcon &icon, const QString &
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);
QIcon coloredIcon = Utility::createColorAwareIcon(iconPath, palette());
return createActionWithIcon(coloredIcon, text, iconPath);
}

View File

@ -75,7 +75,6 @@ private slots:
private:
void customizeStyle();
QIcon createColorAwareIcon(const QString &name);
QAction *createColorAwareAction(const QString &iconName, const QString &fileName);
QAction *createActionWithIcon(const QIcon &icon, const QString &text, const QString &iconPath = QString());

View File

@ -228,7 +228,7 @@ void ShareLinkWidget::slotSharesFetched(const QList<QSharedPointer<Share>> &shar
connect(table, &QTableWidget::itemSelectionChanged, this, &ShareLinkWidget::slotShareSelectionChanged);
auto deleteIcon = QIcon::fromTheme(QLatin1String("user-trash"),
QIcon(QLatin1String(":/client/resources/delete.png")));
Utility::createColorAwareIcon(QLatin1String(":/client/resources/delete.png")));
foreach (auto share, shares) {
if (share->getShareType() != Share::TypeLink) {

View File

@ -381,7 +381,7 @@ ShareUserLine::ShareUserLine(QSharedPointer<Share> share,
_ui->permissionToolButton->setMenu(menu);
_ui->permissionToolButton->setPopupMode(QToolButton::InstantPopup);
QIcon icon(QLatin1String(":/client/resources/more.svg"));
QIcon icon = Utility::createColorAwareIcon(QLatin1String(":/client/resources/more.svg"));
_ui->permissionToolButton->setIcon(icon);
// If there's only a single entry in the detailed permission menu, hide it
@ -417,7 +417,7 @@ ShareUserLine::ShareUserLine(QSharedPointer<Share> share,
connect(share.data(), &Share::shareDeleted, this, &ShareUserLine::slotShareDeleted);
_ui->deleteShareButton->setIcon(QIcon::fromTheme(QLatin1String("user-trash"),
QIcon(QLatin1String(":/client/resources/delete.png"))));
Utility::createColorAwareIcon(QLatin1String(":/client/resources/delete.png"))));
if (!share->account()->capabilities().shareResharing()) {
_ui->permissionShare->hide();

View File

@ -94,8 +94,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>377</width>
<height>169</height>
<width>371</width>
<height>148</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3"/>
@ -105,7 +105,7 @@
<item>
<widget class="QLabel" name="privateLinkText">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;You can direct people to this shared file or folder &lt;a href=&quot;private link menu&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;by giving them a private link&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;You can direct people to this shared file or folder &lt;a href=&quot;private link menu&quot;&gt;&lt;span style=&quot; text-decoration: underline&quot;&gt;by giving them a private link&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -16,6 +16,7 @@
#include "account.h"
#include "accountstate.h"
#include "theme.h"
#include "guiutility.h"
#include <QMenu>
#include <QUrl>
@ -169,11 +170,11 @@ void SslButton::updateAccountState(AccountState *accountState)
AccountPtr account = _accountState->account();
if (account->url().scheme() == QLatin1String("https")) {
setIcon(QIcon(QLatin1String(":/client/resources/lock-https.png")));
setIcon(Utility::createColorAwareIcon(QLatin1String(":/client/resources/lock-https.png")));
QSslCipher cipher = account->_sessionCipher;
setToolTip(tr("This connection is encrypted using %1 bit %2.\n").arg(cipher.usedBits()).arg(cipher.name()));
} else {
setIcon(QIcon(QLatin1String(":/client/resources/lock-http.png")));
setIcon(Utility::createColorAwareIcon(QLatin1String(":/client/resources/lock-http.png")));
setToolTip(tr("This connection is NOT secure as it is not encrypted.\n"));
}
}

View File

@ -31,6 +31,7 @@
#include <folderman.h>
#include "creds/abstractcredentials.h"
#include "networkjobs.h"
#include "guiutility.h"
namespace OCC {
@ -68,7 +69,7 @@ OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage()
_ui.lServerIcon->setText(QString());
_ui.lServerIcon->setPixmap(appIcon.pixmap(48));
_ui.lLocalIcon->setText(QString());
_ui.lLocalIcon->setPixmap(QPixmap(Theme::hidpiFileName(":/client/resources/folder-sync.png")));
_ui.lLocalIcon->setPixmap(Utility::createColorAwareIcon(":/client/resources/folder-sync.png"));
if (theme->wizardHideExternalStorageConfirmationCheckbox()) {
_ui.confCheckBoxExternal->hide();

View File

@ -26,6 +26,7 @@
#include "QProgressIndicator.h"
#include "guiutility.h"
#include "wizard/owncloudwizardcommon.h"
#include "wizard/owncloudsetuppage.h"
#include "wizard/owncloudconnectionmethoddialog.h"
@ -127,11 +128,11 @@ void OwncloudSetupPage::slotUrlChanged(const QString &url)
}
if (!url.startsWith(QLatin1String("https://"))) {
_ui.urlLabel->setPixmap(QPixmap(Theme::hidpiFileName(":/client/resources/lock-http.png")));
_ui.urlLabel->setPixmap(Utility::createColorAwareIcon(":/client/resources/lock-http.png"));
_ui.urlLabel->setToolTip(tr("This url is NOT secure as it is not encrypted.\n"
"It is not advisable to use it."));
} else {
_ui.urlLabel->setPixmap(QPixmap(Theme::hidpiFileName(":/client/resources/lock-https.png")));
_ui.urlLabel->setPixmap(Utility::createColorAwareIcon(":/client/resources/lock-https.png"));
_ui.urlLabel->setToolTip(tr("This url is secure. You can use it."));
}
}

View File

@ -17,6 +17,7 @@
#include <QDir>
#include <QUrl>
#include "guiutility.h"
#include "wizard/owncloudwizardresultpage.h"
#include "wizard/owncloudwizardcommon.h"
#include "theme.h"
@ -38,7 +39,7 @@ OwncloudWizardResultPage::OwncloudWizardResultPage()
setSubTitle(QLatin1String(" "));
_ui.pbOpenLocal->setText(tr("Open Local Folder"));
_ui.pbOpenLocal->setIcon(QIcon(QLatin1String(":/client/resources/folder-sync.png")));
_ui.pbOpenLocal->setIcon(Utility::createColorAwareIcon(QLatin1String(":/client/resources/folder-sync.png")));
_ui.pbOpenLocal->setIconSize(QSize(48, 48));
_ui.pbOpenLocal->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
connect(_ui.pbOpenLocal, &QAbstractButton::clicked, this, &OwncloudWizardResultPage::slotOpenLocal);