mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added float preview of color for chats filter to settings.
This commit is contained in:
parent
cfc40ee966
commit
4a19f193ce
1 changed files with 79 additions and 7 deletions
|
@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_common.h"
|
||||||
|
#include "ui/effects/animation_value_f.h"
|
||||||
#include "ui/effects/animations.h"
|
#include "ui/effects/animations.h"
|
||||||
#include "ui/effects/panel_animation.h"
|
#include "ui/effects/panel_animation.h"
|
||||||
#include "ui/empty_userpic.h"
|
#include "ui/empty_userpic.h"
|
||||||
|
@ -44,6 +45,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "styles/style_settings.h"
|
#include "styles/style_settings.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
|
#include "styles/style_dialogs.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_window.h"
|
#include "styles/style_window.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
|
@ -339,6 +341,7 @@ void EditFilterBox(
|
||||||
Fn<void(Data::ChatFilter)> next)> saveAnd) {
|
Fn<void(Data::ChatFilter)> next)> saveAnd) {
|
||||||
using namespace rpl::mappers;
|
using namespace rpl::mappers;
|
||||||
constexpr auto kColorsCount = 8;
|
constexpr auto kColorsCount = 8;
|
||||||
|
constexpr auto kNoTag = kColorsCount - 1;
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
rpl::variable<Data::ChatFilter> rules;
|
rpl::variable<Data::ChatFilter> rules;
|
||||||
|
@ -354,7 +357,7 @@ void EditFilterBox(
|
||||||
.chatlist = filter.chatlist(),
|
.chatlist = filter.chatlist(),
|
||||||
.creating = filter.title().isEmpty(),
|
.creating = filter.title().isEmpty(),
|
||||||
});
|
});
|
||||||
state->colorIndex = filter.colorIndex().value_or(kColorsCount - 1);
|
state->colorIndex = filter.colorIndex().value_or(kNoTag);
|
||||||
state->links = owner->chatsFilters().chatlistLinks(filter.id()),
|
state->links = owner->chatsFilters().chatlistLinks(filter.id()),
|
||||||
state->hasLinks = state->links.value() | rpl::map([=](const auto &v) {
|
state->hasLinks = state->links.value() | rpl::map([=](const auto &v) {
|
||||||
return !v.empty();
|
return !v.empty();
|
||||||
|
@ -528,7 +531,59 @@ void EditFilterBox(
|
||||||
anim::type::instant);
|
anim::type::instant);
|
||||||
|
|
||||||
const auto isPremium = session->premium();
|
const auto isPremium = session->premium();
|
||||||
Ui::AddSubsectionTitle(colors, tr::lng_filters_tag_color_subtitle());
|
const auto title = Ui::AddSubsectionTitle(
|
||||||
|
colors,
|
||||||
|
tr::lng_filters_tag_color_subtitle());
|
||||||
|
const auto preview = Ui::CreateChild<Ui::RpWidget>(colors);
|
||||||
|
title->geometryValue(
|
||||||
|
) | rpl::start_with_next([=](const QRect &r) {
|
||||||
|
const auto h = st::normalFont->height;
|
||||||
|
preview->setGeometry(
|
||||||
|
colors->x(),
|
||||||
|
r.y() + (r.height() - h) / 2 + st::lineWidth,
|
||||||
|
colors->width(),
|
||||||
|
h);
|
||||||
|
}, preview->lifetime());
|
||||||
|
const auto previewColor = preview->lifetime().make_state<QColor>();
|
||||||
|
const auto previewAlpha = preview->lifetime().make_state<float64>(1);
|
||||||
|
preview->paintRequest() | rpl::start_with_next([=] {
|
||||||
|
auto p = QPainter(preview);
|
||||||
|
p.fillRect(preview->rect(), Qt::transparent);
|
||||||
|
const auto &font = st::dialogRowFilterTagFont;
|
||||||
|
const auto text = name->getLastText().toUpper();
|
||||||
|
p.setFont(font);
|
||||||
|
p.setOpacity(*previewAlpha);
|
||||||
|
const auto roundedWidth = font->width(text) + font->spacew * 3;
|
||||||
|
const auto rect = QRect(
|
||||||
|
preview->width() - roundedWidth - st::boxRowPadding.right(),
|
||||||
|
(st::normalFont->height - font->height) / 2,
|
||||||
|
roundedWidth,
|
||||||
|
font->height);
|
||||||
|
const auto pen = QPen(*previewColor);
|
||||||
|
p.setPen(Qt::NoPen);
|
||||||
|
p.setBrush(anim::with_alpha(pen.color(), .15));
|
||||||
|
{
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
const auto radius = font->height / 3.;
|
||||||
|
p.drawRoundedRect(rect, radius, radius);
|
||||||
|
}
|
||||||
|
p.setPen(pen);
|
||||||
|
p.drawText(rect, text, style::al_center);
|
||||||
|
if (p.opacity() < 1) {
|
||||||
|
p.setOpacity(1. - p.opacity());
|
||||||
|
p.setFont(st::normalFont);
|
||||||
|
p.setPen(st::windowSubTextFg);
|
||||||
|
p.drawText(
|
||||||
|
preview->rect() - st::boxRowPadding,
|
||||||
|
tr::lng_filters_tag_color_no(tr::now),
|
||||||
|
style::al_right);
|
||||||
|
}
|
||||||
|
}, preview->lifetime());
|
||||||
|
|
||||||
|
name->changes() | rpl::start_with_next([=] {
|
||||||
|
preview->update();
|
||||||
|
}, preview->lifetime());
|
||||||
|
|
||||||
const auto side = st::userpicBuilderEmojiAccentColorSize;
|
const auto side = st::userpicBuilderEmojiAccentColorSize;
|
||||||
const auto line = colors->add(
|
const auto line = colors->add(
|
||||||
Ui::CreateSkipWidget(colors, side),
|
Ui::CreateSkipWidget(colors, side),
|
||||||
|
@ -536,15 +591,25 @@ void EditFilterBox(
|
||||||
auto buttons = std::vector<not_null<UserpicBuilder::CircleButton*>>();
|
auto buttons = std::vector<not_null<UserpicBuilder::CircleButton*>>();
|
||||||
const auto animation
|
const auto animation
|
||||||
= line->lifetime().make_state<Ui::Animations::Simple>();
|
= line->lifetime().make_state<Ui::Animations::Simple>();
|
||||||
|
const auto palette = [](int i) {
|
||||||
|
return Ui::EmptyUserpic::UserpicColor(i).color2;
|
||||||
|
};
|
||||||
for (auto i = 0; i < kColorsCount; ++i) {
|
for (auto i = 0; i < kColorsCount; ++i) {
|
||||||
const auto button = Ui::CreateChild<UserpicBuilder::CircleButton>(
|
const auto button = Ui::CreateChild<UserpicBuilder::CircleButton>(
|
||||||
line);
|
line);
|
||||||
button->resize(side, side);
|
button->resize(side, side);
|
||||||
button->setIndex(i);
|
const auto progress = isPremium
|
||||||
button->setSelectedProgress(isPremium
|
|
||||||
? (state->colorIndex.current() == i)
|
? (state->colorIndex.current() == i)
|
||||||
: (i == (kColorsCount - 1)));
|
: (i == kNoTag);
|
||||||
button->setBrush(Ui::EmptyUserpic::UserpicColor(i).color2);
|
button->setSelectedProgress(progress);
|
||||||
|
const auto color = palette(i);
|
||||||
|
button->setBrush(color);
|
||||||
|
if (progress == 1) {
|
||||||
|
*previewColor = color->c;
|
||||||
|
if (i == kNoTag) {
|
||||||
|
*previewAlpha = 0.;
|
||||||
|
}
|
||||||
|
}
|
||||||
buttons.push_back(button);
|
buttons.push_back(button);
|
||||||
}
|
}
|
||||||
for (auto i = 0; i < kColorsCount; ++i) {
|
for (auto i = 0; i < kColorsCount; ++i) {
|
||||||
|
@ -553,12 +618,19 @@ void EditFilterBox(
|
||||||
const auto was = state->colorIndex.current();
|
const auto was = state->colorIndex.current();
|
||||||
const auto now = i;
|
const auto now = i;
|
||||||
if (was != now) {
|
if (was != now) {
|
||||||
|
const auto c1 = palette(was);
|
||||||
|
const auto c2 = palette(now);
|
||||||
|
const auto a1 = (was == kNoTag) ? 0. : 1.;
|
||||||
|
const auto a2 = (now == kNoTag) ? 0. : 1.;
|
||||||
animation->stop();
|
animation->stop();
|
||||||
animation->start([=](float64 progress) {
|
animation->start([=](float64 progress) {
|
||||||
if (was >= 0) {
|
if (was >= 0) {
|
||||||
buttons[was]->setSelectedProgress(1. - progress);
|
buttons[was]->setSelectedProgress(1. - progress);
|
||||||
}
|
}
|
||||||
buttons[now]->setSelectedProgress(progress);
|
buttons[now]->setSelectedProgress(progress);
|
||||||
|
*previewColor = anim::color(c1, c2, progress);
|
||||||
|
*previewAlpha = anim::interpolateF(a1, a2, progress);
|
||||||
|
preview->update();
|
||||||
}, 0., 1., st::universalDuration);
|
}, 0., 1., st::universalDuration);
|
||||||
}
|
}
|
||||||
state->colorIndex = now;
|
state->colorIndex = now;
|
||||||
|
@ -619,7 +691,7 @@ void EditFilterBox(
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const auto rawColorIndex = state->colorIndex.current();
|
const auto rawColorIndex = state->colorIndex.current();
|
||||||
const auto colorIndex = (rawColorIndex >= (kColorsCount - 1)
|
const auto colorIndex = (rawColorIndex >= kNoTag
|
||||||
? std::nullopt
|
? std::nullopt
|
||||||
: std::make_optional(rawColorIndex));
|
: std::make_optional(rawColorIndex));
|
||||||
return rules.withTitle(title).withColorIndex(colorIndex);
|
return rules.withTitle(title).withColorIndex(colorIndex);
|
||||||
|
|
Loading…
Add table
Reference in a new issue