mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-10 16:59:55 +00:00
Ensure theme list radiobutton contrast.
This commit is contained in:
parent
9fd32fc85b
commit
1d4fbc64e2
@ -165,7 +165,7 @@ QImage createCircleMask(int size, QColor bg, QColor fg) {
|
||||
return (distance > kMinContrastDistance);
|
||||
}
|
||||
|
||||
void EnsureContrast(ColorData &over, const ColorData &under) {
|
||||
QColor EnsureContrast(const QColor &over, const QColor &under) {
|
||||
auto overH = 0;
|
||||
auto overS = 0;
|
||||
auto overL = 0;
|
||||
@ -173,11 +173,11 @@ void EnsureContrast(ColorData &over, const ColorData &under) {
|
||||
auto underH = 0;
|
||||
auto underS = 0;
|
||||
auto underL = 0;
|
||||
over.c.getHsl(&overH, &overS, &overL, &overA);
|
||||
under.c.getHsl(&underH, &underS, &underL);
|
||||
const auto good = GoodForContrast(over.c, under.c);
|
||||
over.getHsl(&overH, &overS, &overL, &overA);
|
||||
under.getHsl(&underH, &underS, &underL);
|
||||
const auto good = GoodForContrast(over, under);
|
||||
if (overA >= kMinContrastAlpha && good) {
|
||||
return;
|
||||
return over;
|
||||
}
|
||||
const auto newA = std::max(overA, kMinContrastAlpha);
|
||||
const auto newL = (overL > underL && overL + kContrastDeltaL <= 255)
|
||||
@ -187,9 +187,16 @@ void EnsureContrast(ColorData &over, const ColorData &under) {
|
||||
: (underL > 128)
|
||||
? (underL - kContrastDeltaL)
|
||||
: (underL + kContrastDeltaL);
|
||||
over.c = QColor::fromHsl(overH, overS, newL, newA).toRgb();
|
||||
over.p = QPen(over.c);
|
||||
over.b = QBrush(over.c);
|
||||
return QColor::fromHsl(overH, overS, newL, newA).toRgb();
|
||||
}
|
||||
|
||||
void EnsureContrast(ColorData &over, const ColorData &under) {
|
||||
const auto good = EnsureContrast(over.c, under.c);
|
||||
if (over.c != good) {
|
||||
over.c = good;
|
||||
over.p = QPen(good);
|
||||
over.b = QBrush(good);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
@ -54,6 +54,7 @@ void unregisterModule(ModuleBase *module);
|
||||
// This method is implemented in palette.cpp (codegen).
|
||||
bool setPaletteColor(QLatin1String name, uchar r, uchar g, uchar b, uchar a);
|
||||
|
||||
[[nodiscard]] QColor EnsureContrast(const QColor &over, const QColor &under);
|
||||
void EnsureContrast(ColorData &over, const ColorData &under);
|
||||
|
||||
} // namespace internal
|
||||
|
@ -154,8 +154,7 @@ CloudListCheck::CloudListCheck(bool checked)
|
||||
|
||||
void CloudListCheck::setColors(const Colors &colors) {
|
||||
_colors = colors;
|
||||
_radio.setToggledOverride(_colors->radiobuttonActive);
|
||||
_radio.setUntoggledOverride(_colors->radiobuttonInactive);
|
||||
if (!_colors->background.isNull()) {
|
||||
const auto size = st::settingsThemePreviewSize * cIntRetinaFactor();
|
||||
_backgroundFull = (_colors->background.size() == size)
|
||||
? _colors->background
|
||||
@ -164,9 +163,36 @@ void CloudListCheck::setColors(const Colors &colors) {
|
||||
Qt::IgnoreAspectRatio,
|
||||
Qt::SmoothTransformation);
|
||||
_backgroundCacheWidth = -1;
|
||||
|
||||
ensureContrast();
|
||||
_radio.setToggledOverride(_colors->radiobuttonActive);
|
||||
_radio.setUntoggledOverride(_colors->radiobuttonInactive);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void CloudListCheck::ensureContrast() {
|
||||
const auto radio = _radio.getSize();
|
||||
const auto x = (getSize().width() - radio.width()) / 2;
|
||||
const auto y = getSize().height()
|
||||
- radio.height()
|
||||
- st::settingsThemeRadioBottom;
|
||||
const auto under = QRect(
|
||||
QPoint(x, y) * cIntRetinaFactor(),
|
||||
radio * cIntRetinaFactor());
|
||||
const auto image = _backgroundFull.copy(under).convertToFormat(
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
const auto active = style::internal::EnsureContrast(
|
||||
_colors->radiobuttonActive,
|
||||
CountAverageColor(image));
|
||||
_colors->radiobuttonInactive = _colors->radiobuttonActive = QColor(
|
||||
active.red(),
|
||||
active.green(),
|
||||
active.blue(),
|
||||
255);
|
||||
_colors->radiobuttonInactive.setAlpha(192);
|
||||
}
|
||||
|
||||
QSize CloudListCheck::getSize() const {
|
||||
return st::settingsThemePreviewSize;
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ private:
|
||||
void paintWithColors(Painter &p, int left, int top, int outerWidth);
|
||||
void checkedChangedHook(anim::type animated) override;
|
||||
void validateBackgroundCache(int width);
|
||||
void ensureContrast();
|
||||
|
||||
std::optional<Colors> _colors;
|
||||
Ui::RadioView _radio;
|
||||
|
Loading…
Reference in New Issue
Block a user