mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Moved out graphic of button for expandable moderate list to view.
This commit is contained in:
parent
91b9266a91
commit
b364c4f23a
4 changed files with 166 additions and 78 deletions
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "base/event_filter.h"
|
#include "base/event_filter.h"
|
||||||
#include "base/timer.h"
|
#include "base/timer.h"
|
||||||
|
#include "ui/widgets/participants_check_view.h"
|
||||||
#include "boxes/delete_messages_box.h"
|
#include "boxes/delete_messages_box.h"
|
||||||
#include "boxes/peers/edit_peer_permissions_box.h"
|
#include "boxes/peers/edit_peer_permissions_box.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
|
@ -114,101 +115,44 @@ class Button final : public Ui::RippleButton {
|
||||||
public:
|
public:
|
||||||
Button(not_null<QWidget*> parent, int count);
|
Button(not_null<QWidget*> parent, int count);
|
||||||
|
|
||||||
void setChecked(bool checked);
|
[[nodiscard]] not_null<Ui::AbstractCheckView*> checkView() const;
|
||||||
[[nodiscard]] bool checked() const;
|
|
||||||
|
|
||||||
[[nodiscard]] static QSize ComputeSize(int);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
QImage prepareRippleMask() const override;
|
QImage prepareRippleMask() const override;
|
||||||
QPoint prepareRippleStartPosition() const override;
|
QPoint prepareRippleStartPosition() const override;
|
||||||
|
|
||||||
const int _count;
|
std::unique_ptr<Ui::AbstractCheckView> _view;
|
||||||
const QString _text;
|
|
||||||
bool _checked = false;
|
|
||||||
|
|
||||||
Ui::Animations::Simple _animation;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Button::Button(not_null<QWidget*> parent, int count)
|
Button::Button(not_null<QWidget*> parent, int count)
|
||||||
: RippleButton(parent, st::defaultRippleAnimation)
|
: Ui::RippleButton(parent, st::defaultRippleAnimation)
|
||||||
, _count(count)
|
, _view(std::make_unique<Ui::ParticipantsCheckView>(
|
||||||
, _text(QString::number(std::abs(_count))) {
|
count,
|
||||||
|
st::slideWrapDuration,
|
||||||
|
false,
|
||||||
|
[=] { update(); })) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize Button::ComputeSize(int count) {
|
not_null<Ui::AbstractCheckView*> Button::checkView() const {
|
||||||
return QSize(
|
return _view.get();
|
||||||
st::moderateBoxExpandHeight
|
|
||||||
+ st::moderateBoxExpand.width()
|
|
||||||
+ st::moderateBoxExpandInnerSkip * 4
|
|
||||||
+ st::moderateBoxExpandFont->width(
|
|
||||||
QString::number(std::abs(count)))
|
|
||||||
+ st::moderateBoxExpandToggleSize,
|
|
||||||
st::moderateBoxExpandHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::setChecked(bool checked) {
|
|
||||||
if (_checked == checked) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_checked = checked;
|
|
||||||
_animation.stop();
|
|
||||||
_animation.start(
|
|
||||||
[=] { update(); },
|
|
||||||
checked ? 0 : 1,
|
|
||||||
checked ? 1 : 0,
|
|
||||||
st::slideWrapDuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Button::checked() const {
|
|
||||||
return _checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::paintEvent(QPaintEvent *event) {
|
|
||||||
auto p = Painter(this);
|
|
||||||
auto hq = PainterHighQualityEnabler(p);
|
|
||||||
Ui::RippleButton::paintRipple(p, QPoint());
|
|
||||||
const auto radius = height() / 2;
|
|
||||||
p.setPen(Qt::NoPen);
|
|
||||||
st::moderateBoxExpand.paint(
|
|
||||||
p,
|
|
||||||
radius,
|
|
||||||
(height() - st::moderateBoxExpand.height()) / 2,
|
|
||||||
width());
|
|
||||||
|
|
||||||
const auto innerSkip = st::moderateBoxExpandInnerSkip;
|
|
||||||
|
|
||||||
p.setBrush(Qt::NoBrush);
|
|
||||||
p.setPen(st::boxTextFg);
|
|
||||||
p.setFont(st::moderateBoxExpandFont);
|
|
||||||
p.drawText(
|
|
||||||
QRect(
|
|
||||||
innerSkip + radius + st::moderateBoxExpand.width(),
|
|
||||||
0,
|
|
||||||
width(),
|
|
||||||
height()),
|
|
||||||
_text,
|
|
||||||
style::al_left);
|
|
||||||
|
|
||||||
const auto path = Ui::ToggleUpDownArrowPath(
|
|
||||||
width() - st::moderateBoxExpandToggleSize - radius,
|
|
||||||
height() / 2,
|
|
||||||
st::moderateBoxExpandToggleSize,
|
|
||||||
st::moderateBoxExpandToggleFourStrokes,
|
|
||||||
_animation.value(_checked ? 1. : 0.));
|
|
||||||
p.fillPath(path, st::boxTextFg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage Button::prepareRippleMask() const {
|
QImage Button::prepareRippleMask() const {
|
||||||
return Ui::RippleAnimation::RoundRectMask(size(), size().height() / 2);
|
return _view->prepareRippleMask();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPoint Button::prepareRippleStartPosition() const {
|
QPoint Button::prepareRippleStartPosition() const {
|
||||||
return mapFromGlobal(QCursor::pos());
|
return mapFromGlobal(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Button::paintEvent(QPaintEvent *event) {
|
||||||
|
auto p = QPainter(this);
|
||||||
|
Ui::RippleButton::paintRipple(p, QPoint());
|
||||||
|
_view->paint(p, 0, 0, width());
|
||||||
|
}
|
||||||
|
|
||||||
void CreateParticipantsList(
|
void CreateParticipantsList(
|
||||||
not_null<Controller*> controller,
|
not_null<Controller*> controller,
|
||||||
not_null<Ui::VerticalLayout*> inner,
|
not_null<Ui::VerticalLayout*> inner,
|
||||||
|
@ -313,7 +257,7 @@ void AppendList(
|
||||||
}
|
}
|
||||||
const auto count = int(participants.size());
|
const auto count = int(participants.size());
|
||||||
const auto button = Ui::CreateChild<Button>(inner, count);
|
const auto button = Ui::CreateChild<Button>(inner, count);
|
||||||
button->resize(Button::ComputeSize(count));
|
button->resize(Ui::ParticipantsCheckView::ComputeSize(count));
|
||||||
|
|
||||||
const auto overlay = Ui::CreateChild<Ui::AbstractButton>(inner);
|
const auto overlay = Ui::CreateChild<Ui::AbstractButton>(inner);
|
||||||
|
|
||||||
|
@ -334,8 +278,11 @@ void AppendList(
|
||||||
checkbox->setChecked(toggled);
|
checkbox->setChecked(toggled);
|
||||||
}, checkbox->lifetime());
|
}, checkbox->lifetime());
|
||||||
button->setClickedCallback([=] {
|
button->setClickedCallback([=] {
|
||||||
button->setChecked(!button->checked());
|
button->checkView()->setChecked(
|
||||||
controller->toggleRequestsFromTop.fire_copy(button->checked());
|
!button->checkView()->checked(),
|
||||||
|
anim::type::normal);
|
||||||
|
controller->toggleRequestsFromTop.fire_copy(
|
||||||
|
button->checkView()->checked());
|
||||||
});
|
});
|
||||||
overlay->setClickedCallback([=] {
|
overlay->setClickedCallback([=] {
|
||||||
checkbox->setChecked(!checkbox->checked());
|
checkbox->setChecked(!checkbox->checked());
|
||||||
|
@ -361,7 +308,12 @@ void CreateModerateMessagesBox(
|
||||||
const auto isSingle = participants.size() == 1;
|
const auto isSingle = participants.size() == 1;
|
||||||
const auto buttonPadding = isSingle
|
const auto buttonPadding = isSingle
|
||||||
? QMargins()
|
? QMargins()
|
||||||
: QMargins(0, 0, Button::ComputeSize(participants.size()).width(), 0);
|
: QMargins(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
Ui::ParticipantsCheckView::ComputeSize(
|
||||||
|
participants.size()).width(),
|
||||||
|
0);
|
||||||
|
|
||||||
const auto session = &items.front()->history()->session();
|
const auto session = &items.front()->history()->session();
|
||||||
const auto historyPeerId = items.front()->history()->peer->id;
|
const auto historyPeerId = items.front()->history()->peer->id;
|
||||||
|
|
95
Telegram/SourceFiles/ui/widgets/participants_check_view.cpp
Normal file
95
Telegram/SourceFiles/ui/widgets/participants_check_view.cpp
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
This file is part of Telegram Desktop,
|
||||||
|
the official desktop application for the Telegram messaging service.
|
||||||
|
|
||||||
|
For license and copyright information please follow this link:
|
||||||
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
*/
|
||||||
|
#include "ui/widgets/participants_check_view.h"
|
||||||
|
|
||||||
|
#include "ui/effects/ripple_animation.h"
|
||||||
|
#include "ui/effects/toggle_arrow.h"
|
||||||
|
#include "ui/painter.h"
|
||||||
|
#include "ui/rect.h"
|
||||||
|
#include "styles/style_boxes.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
|
||||||
|
ParticipantsCheckView::ParticipantsCheckView(
|
||||||
|
int count,
|
||||||
|
int duration,
|
||||||
|
bool checked,
|
||||||
|
Fn<void()> updateCallback)
|
||||||
|
: Ui::AbstractCheckView(duration, checked, std::move(updateCallback))
|
||||||
|
, _text(QString::number(std::abs(count)))
|
||||||
|
, _count(count) {
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize ParticipantsCheckView::ComputeSize(int count) {
|
||||||
|
return QSize(
|
||||||
|
st::moderateBoxExpandHeight
|
||||||
|
+ st::moderateBoxExpand.width()
|
||||||
|
+ st::moderateBoxExpandInnerSkip * 4
|
||||||
|
+ st::moderateBoxExpandFont->width(
|
||||||
|
QString::number(std::abs(count)))
|
||||||
|
+ st::moderateBoxExpandToggleSize,
|
||||||
|
st::moderateBoxExpandHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize ParticipantsCheckView::getSize() const {
|
||||||
|
return ComputeSize(_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticipantsCheckView::paint(
|
||||||
|
QPainter &p,
|
||||||
|
int left,
|
||||||
|
int top,
|
||||||
|
int outerWidth) {
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
const auto size = getSize();
|
||||||
|
const auto radius = size.height() / 2;
|
||||||
|
p.setPen(Qt::NoPen);
|
||||||
|
st::moderateBoxExpand.paint(
|
||||||
|
p,
|
||||||
|
radius,
|
||||||
|
left + (size.height() - st::moderateBoxExpand.height()) / 2,
|
||||||
|
top + size.width());
|
||||||
|
|
||||||
|
const auto innerSkip = st::moderateBoxExpandInnerSkip;
|
||||||
|
|
||||||
|
p.setBrush(Qt::NoBrush);
|
||||||
|
p.setPen(st::boxTextFg);
|
||||||
|
p.setFont(st::moderateBoxExpandFont);
|
||||||
|
p.drawText(
|
||||||
|
QRect(
|
||||||
|
left + innerSkip + radius + st::moderateBoxExpand.width(),
|
||||||
|
top,
|
||||||
|
size.width(),
|
||||||
|
size.height()),
|
||||||
|
_text,
|
||||||
|
style::al_left);
|
||||||
|
|
||||||
|
const auto path = Ui::ToggleUpDownArrowPath(
|
||||||
|
left + size.width() - st::moderateBoxExpandToggleSize - radius,
|
||||||
|
top + size.height() / 2,
|
||||||
|
st::moderateBoxExpandToggleSize,
|
||||||
|
st::moderateBoxExpandToggleFourStrokes,
|
||||||
|
Ui::AbstractCheckView::currentAnimationValue());
|
||||||
|
p.fillPath(path, st::boxTextFg);
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage ParticipantsCheckView::prepareRippleMask() const {
|
||||||
|
const auto size = getSize();
|
||||||
|
return Ui::RippleAnimation::RoundRectMask(size, size.height() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParticipantsCheckView::checkRippleStartPosition(QPoint position) const {
|
||||||
|
return Rect(getSize()).contains(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticipantsCheckView::checkedChangedHook(anim::type animated) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ParticipantsCheckView::~ParticipantsCheckView() = default;
|
||||||
|
|
||||||
|
} // namespace Ui
|
39
Telegram/SourceFiles/ui/widgets/participants_check_view.h
Normal file
39
Telegram/SourceFiles/ui/widgets/participants_check_view.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
This file is part of Telegram Desktop,
|
||||||
|
the official desktop application for the Telegram messaging service.
|
||||||
|
|
||||||
|
For license and copyright information please follow this link:
|
||||||
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ui/widgets/checkbox.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
|
||||||
|
class ParticipantsCheckView : public Ui::AbstractCheckView {
|
||||||
|
public:
|
||||||
|
ParticipantsCheckView(
|
||||||
|
int count,
|
||||||
|
int duration,
|
||||||
|
bool checked,
|
||||||
|
Fn<void()> updateCallback);
|
||||||
|
|
||||||
|
[[nodiscard]] static QSize ComputeSize(int count);
|
||||||
|
|
||||||
|
QSize getSize() const override;
|
||||||
|
|
||||||
|
void paint(QPainter &p, int left, int top, int outerWidth) override;
|
||||||
|
QImage prepareRippleMask() const override;
|
||||||
|
bool checkRippleStartPosition(QPoint position) const override;
|
||||||
|
|
||||||
|
~ParticipantsCheckView();
|
||||||
|
|
||||||
|
private:
|
||||||
|
const QString _text;
|
||||||
|
const int _count;
|
||||||
|
void checkedChangedHook(anim::type animated) override;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Ui
|
|
@ -428,6 +428,8 @@ PRIVATE
|
||||||
ui/widgets/multi_select.h
|
ui/widgets/multi_select.h
|
||||||
ui/widgets/sent_code_field.cpp
|
ui/widgets/sent_code_field.cpp
|
||||||
ui/widgets/sent_code_field.h
|
ui/widgets/sent_code_field.h
|
||||||
|
ui/widgets/participants_check_view.cpp
|
||||||
|
ui/widgets/participants_check_view.h
|
||||||
ui/widgets/slider_natural_width.h
|
ui/widgets/slider_natural_width.h
|
||||||
ui/widgets/vertical_drum_picker.cpp
|
ui/widgets/vertical_drum_picker.cpp
|
||||||
ui/widgets/vertical_drum_picker.h
|
ui/widgets/vertical_drum_picker.h
|
||||||
|
|
Loading…
Add table
Reference in a new issue