Fix forum rounding in folder editing box.

This commit is contained in:
John Preston 2022-12-06 12:12:07 +04:00
parent cb653df0f6
commit b775d577a4
12 changed files with 64 additions and 41 deletions

View File

@ -49,7 +49,8 @@ public:
QString generateName() override;
QString generateShortName() override;
PaintRoundImageCallback generatePaintUserpicCallback() override;
PaintRoundImageCallback generatePaintUserpicCallback(
bool forceRound) override;
private:
[[nodiscard]] Flag flag() const;
@ -62,7 +63,8 @@ public:
QString generateName() override;
QString generateShortName() override;
PaintRoundImageCallback generatePaintUserpicCallback() override;
PaintRoundImageCallback generatePaintUserpicCallback(
bool forceRound) override;
};
@ -124,7 +126,8 @@ QString TypeRow::generateShortName() {
return generateName();
}
PaintRoundImageCallback TypeRow::generatePaintUserpicCallback() {
PaintRoundImageCallback TypeRow::generatePaintUserpicCallback(
bool forceRound) {
const auto flag = this->flag();
return [=](QPainter &p, int x, int y, int outerWidth, int size) {
PaintFilterChatsTypeIcon(p, flag, x, y, outerWidth, size);
@ -153,11 +156,15 @@ QString ExceptionRow::generateShortName() {
return generateName();
}
PaintRoundImageCallback ExceptionRow::generatePaintUserpicCallback() {
PaintRoundImageCallback ExceptionRow::generatePaintUserpicCallback(
bool forceRound) {
const auto peer = this->peer();
const auto saved = peer->isSelf();
const auto replies = peer->isRepliesChat();
auto userpic = saved ? Ui::PeerUserpicView() : ensureUserpicView();
if (forceRound && peer->isForum()) {
return ForceRoundUserpicCallback(peer);
}
return [=](Painter &p, int x, int y, int outerWidth, int size) mutable {
if (saved) {
Ui::EmptyUserpic::PaintSavedMessages(p, x, y, outerWidth, size);

View File

@ -54,6 +54,25 @@ PaintRoundImageCallback PaintUserpicCallback(
};
}
PaintRoundImageCallback ForceRoundUserpicCallback(not_null<PeerData*> peer) {
auto userpic = Ui::PeerUserpicView();
auto cache = std::make_shared<QImage>();
return [=](Painter &p, int x, int y, int outerWidth, int size) mutable {
const auto ratio = style::DevicePixelRatio();
const auto cacheSize = QSize(size, size) * ratio;
if (cache->size() != cacheSize) {
*cache = QImage(cacheSize, QImage::Format_ARGB32_Premultiplied);
cache->setDevicePixelRatio(ratio);
}
auto q = Painter(cache.get());
peer->paintUserpicLeft(q, userpic, 0, 0, outerWidth, size);
q.end();
*cache = Images::Circle(std::move(*cache));
p.drawImage(x, y, *cache);
};
}
PeerListContentDelegateShow::PeerListContentDelegateShow(
std::shared_ptr<Ui::Show> show)
: _show(show) {
@ -412,7 +431,9 @@ void PeerListBox::addSelectItem(
addSelectItem(
peer->id.value,
text,
PaintUserpicCallback(peer, respect),
(peer->isForum()
? ForceRoundUserpicCallback(peer)
: PaintUserpicCallback(peer, respect)),
animated);
}
@ -422,7 +443,7 @@ void PeerListBox::addSelectItem(
addSelectItem(
row->id(),
row->generateShortName(),
row->generatePaintUserpicCallback(),
row->generatePaintUserpicCallback(true),
animated);
}
@ -642,11 +663,15 @@ Ui::PeerUserpicView &PeerListRow::ensureUserpicView() {
return _userpic;
}
PaintRoundImageCallback PeerListRow::generatePaintUserpicCallback() {
PaintRoundImageCallback PeerListRow::generatePaintUserpicCallback(
bool forceRound) {
const auto saved = _isSavedMessagesChat;
const auto replies = _isRepliesMessagesChat;
const auto peer = this->peer();
auto userpic = saved ? Ui::PeerUserpicView() : ensureUserpicView();
if (forceRound && peer->isForum()) {
return ForceRoundUserpicCallback(peer);
}
return [=](Painter &p, int x, int y, int outerWidth, int size) mutable {
if (saved) {
Ui::EmptyUserpic::PaintSavedMessages(p, x, y, outerWidth, size);
@ -769,7 +794,7 @@ void PeerListRow::paintUserpic(
paintDisabledCheckUserpic(p, st, x, y, outerWidth);
} else if (_checkbox) {
_checkbox->paint(p, x, y, outerWidth);
} else if (const auto callback = generatePaintUserpicCallback()) {
} else if (const auto callback = generatePaintUserpicCallback(false)) {
callback(p, x, y, outerWidth, st.photoSize);
}
}
@ -848,7 +873,7 @@ void PeerListRow::createCheckbox(
_checkbox = std::make_unique<Ui::RoundImageCheckbox>(
st,
std::move(updateCallback),
generatePaintUserpicCallback(),
generatePaintUserpicCallback(false),
generateRadius);
}

View File

@ -47,6 +47,8 @@ using PaintRoundImageCallback = Fn<void(
[[nodiscard]] PaintRoundImageCallback PaintUserpicCallback(
not_null<PeerData*> peer,
bool respectSavedMessagesChat);
[[nodiscard]] PaintRoundImageCallback ForceRoundUserpicCallback(
not_null<PeerData*> peer);
using PeerListRowId = uint64;
@ -89,8 +91,8 @@ public:
[[nodiscard]] virtual QString generateName();
[[nodiscard]] virtual QString generateShortName();
[[nodiscard]] virtual auto generatePaintUserpicCallback()
-> PaintRoundImageCallback;
[[nodiscard]] virtual auto generatePaintUserpicCallback(
bool forceRound) -> PaintRoundImageCallback;
[[nodiscard]] virtual auto generateNameFirstLetters() const
-> const base::flat_set<QChar> &;

View File

@ -624,7 +624,8 @@ QString ChooseTopicBoxController::Row::generateShortName() {
return _topic->title();
}
auto ChooseTopicBoxController::Row::generatePaintUserpicCallback()
auto ChooseTopicBoxController::Row::generatePaintUserpicCallback(
bool forceRound)
-> PaintRoundImageCallback {
return [=](
Painter &p,

View File

@ -235,7 +235,8 @@ private:
QString generateName() override;
QString generateShortName() override;
PaintRoundImageCallback generatePaintUserpicCallback() override;
PaintRoundImageCallback generatePaintUserpicCallback(
bool forceRound) override;
auto generateNameFirstLetters() const
-> const base::flat_set<QChar> & override;

View File

@ -402,7 +402,9 @@ void PeerListsBox::addSelectItem(
addSelectItem(
peer->id.value,
peer->shortName(),
PaintUserpicCallback(peer, false),
(peer->isForum()
? ForceRoundUserpicCallback(peer)
: PaintUserpicCallback(peer, false)),
animated);
}
@ -412,7 +414,7 @@ void PeerListsBox::addSelectItem(
addSelectItem(
row->id(),
row->generateShortName(),
row->generatePaintUserpicCallback(),
row->generatePaintUserpicCallback(true),
animated);
}

View File

@ -91,7 +91,8 @@ public:
QString generateName() override;
QString generateShortName() override;
PaintRoundImageCallback generatePaintUserpicCallback() override;
PaintRoundImageCallback generatePaintUserpicCallback(
bool forceRound) override;
QSize rightActionSize() const override;
QMargins rightActionMargins() const override;
@ -327,7 +328,7 @@ QString Row::generateShortName() {
return generateName();
}
PaintRoundImageCallback Row::generatePaintUserpicCallback() {
PaintRoundImageCallback Row::generatePaintUserpicCallback(bool forceRound) {
return [=](
QPainter &p,
int x,

View File

@ -77,7 +77,8 @@ public:
QString generateName() override;
QString generateShortName() override;
PaintRoundImageCallback generatePaintUserpicCallback() override;
PaintRoundImageCallback generatePaintUserpicCallback(
bool forceRound) override;
int elementsCount() const override;
QRect elementGeometry(int element, int outerWidth) const override;
@ -520,7 +521,7 @@ QString Row::generateShortName() {
return generateName();
}
PaintRoundImageCallback Row::generatePaintUserpicCallback() {
PaintRoundImageCallback Row::generatePaintUserpicCallback(bool forceRound) {
return [=](
QPainter &p,
int x,

View File

@ -535,25 +535,6 @@ void ShareBox::applyFilterUpdate(const QString &query) {
_inner->updateFilter(query);
}
PaintRoundImageCallback ForceRoundUserpicCallback(not_null<PeerData*> peer) {
auto userpic = Ui::PeerUserpicView();
auto cache = std::make_shared<QImage>();
return [=](Painter &p, int x, int y, int outerWidth, int size) mutable {
const auto ratio = style::DevicePixelRatio();
const auto cacheSize = QSize(size, size) * ratio;
if (cache->size() != cacheSize) {
*cache = QImage(cacheSize, QImage::Format_ARGB32_Premultiplied);
cache->setDevicePixelRatio(ratio);
}
auto q = Painter(cache.get());
peer->paintUserpicLeft(q, userpic, 0, 0, outerWidth, size);
q.end();
*cache = Images::Circle(std::move(*cache));
p.drawImage(x, y, *cache);
};
}
void ShareBox::addPeerToMultiSelect(not_null<Data::Thread*> thread) {
auto addItemWay = Ui::MultiSelect::AddItemWay::Default;
const auto peer = thread->peer();

View File

@ -448,7 +448,8 @@ void MembersRow::paintMuteIcon(
_delegate->rowPaintIcon(p, iconRect, computeIconState(style));
}
auto MembersRow::generatePaintUserpicCallback() -> PaintRoundImageCallback {
auto MembersRow::generatePaintUserpicCallback(bool forceRound)
-> PaintRoundImageCallback {
return [=](Painter &p, int x, int y, int outerWidth, int size) {
const auto outer = outerWidth;
paintComplexUserpic(p, x, y, outer, size, size, PanelMode::Default);

View File

@ -122,7 +122,8 @@ public:
bool selected,
bool actionSelected) override;
PaintRoundImageCallback generatePaintUserpicCallback() override;
PaintRoundImageCallback generatePaintUserpicCallback(
bool forceRound) override;
void paintComplexUserpic(
Painter &p,
int x,

View File

@ -390,7 +390,7 @@ void RoundImageCheckbox::paint(Painter &p, int x, int y, int outerWidth) const {
if (selectionLevel > 0) {
const auto radius = _roundingRadius
? _roundingRadius(_st.imageRadius)
? _roundingRadius(_st.imageRadius * 2)
: std::optional<int>();
PainterHighQualityEnabler hq(p);
p.setOpacity(std::clamp(selectionLevel, 0., 1.));