forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/10.0' into qds/dev
bigger conflicts resolved at: src/plugins/qmldesigner/CMakeLists.txt src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp Change-Id: I08e2a109d8e37cbd77225129854e9e633725bfc7
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "stylehelper.h"
|
||||
|
||||
@@ -834,4 +834,29 @@ bool StyleHelper::isReadableOn(const QColor &background, const QColor &foregroun
|
||||
return contrastRatio(background, foreground) > 3;
|
||||
}
|
||||
|
||||
QColor StyleHelper::ensureReadableOn(const QColor &background, const QColor &desiredForeground)
|
||||
{
|
||||
if (isReadableOn(background, desiredForeground))
|
||||
return desiredForeground;
|
||||
|
||||
int h, s, v;
|
||||
QColor foreground = desiredForeground;
|
||||
foreground.getHsv(&h, &s, &v);
|
||||
// adjust the color value to ensure better readability
|
||||
if (luminance(background) < .5)
|
||||
v = v + 64;
|
||||
else if (v >= 64)
|
||||
v = v - 64;
|
||||
v %= 256;
|
||||
|
||||
foreground.setHsv(h, s, v);
|
||||
if (!isReadableOn(background, foreground)) {
|
||||
s = (s + 128) % 256; // adjust the saturation to ensure better readability
|
||||
foreground.setHsv(h, s, v);
|
||||
if (!isReadableOn(background, foreground)) // we failed to create some better foreground
|
||||
return desiredForeground;
|
||||
}
|
||||
return foreground;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
Reference in New Issue
Block a user