2017-07-04 13:31:18 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-07-04 13:31:18 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-07-04 13:31:18 +00:00
|
|
|
*/
|
2018-01-09 17:08:31 +00:00
|
|
|
#include "history/admin_log/history_admin_log_filter.h"
|
2017-07-04 13:31:18 +00:00
|
|
|
|
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/effects/ripple_animation.h"
|
|
|
|
#include "lang/lang_keys.h"
|
2017-12-17 08:13:26 +00:00
|
|
|
#include "data/data_peer_values.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_user.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2017-07-04 13:31:18 +00:00
|
|
|
|
|
|
|
namespace AdminLog {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class UserCheckbox : public Ui::RippleButton {
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
UserCheckbox(QWidget *parent, not_null<UserData*> user, bool checked);
|
2017-07-04 13:31:18 +00:00
|
|
|
|
|
|
|
bool checked() const {
|
2017-07-07 11:16:37 +00:00
|
|
|
return _check->checked();
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
2018-12-05 09:55:56 +00:00
|
|
|
rpl::producer<bool> checkedChanges() const;
|
|
|
|
rpl::producer<bool> checkedValue() const;
|
2017-07-07 11:16:37 +00:00
|
|
|
|
2017-07-04 13:31:18 +00:00
|
|
|
enum class NotifyAboutChange {
|
|
|
|
Notify,
|
|
|
|
DontNotify,
|
|
|
|
};
|
2018-12-05 09:55:56 +00:00
|
|
|
void setChecked(
|
|
|
|
bool checked,
|
|
|
|
NotifyAboutChange notify = NotifyAboutChange::Notify);
|
2017-07-04 13:31:18 +00:00
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
void finishAnimating();
|
2017-07-04 13:31:18 +00:00
|
|
|
|
|
|
|
QMargins getMargins() const override {
|
|
|
|
return _st.margin;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
|
|
|
QImage prepareRippleMask() const override;
|
|
|
|
QPoint prepareRippleStartPosition() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const style::Checkbox &_st;
|
2017-07-07 11:16:37 +00:00
|
|
|
std::unique_ptr<Ui::AbstractCheckView> _check;
|
2018-12-05 09:55:56 +00:00
|
|
|
rpl::event_stream<bool> _checkedChanges;
|
2017-07-04 13:31:18 +00:00
|
|
|
|
|
|
|
QRect _checkRect;
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<UserData*> _user;
|
2017-07-04 13:31:18 +00:00
|
|
|
QString _statusText;
|
|
|
|
bool _statusOnline = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
UserCheckbox::UserCheckbox(QWidget *parent, not_null<UserData*> user, bool checked) : Ui::RippleButton(parent, st::defaultBoxCheckbox.ripple)
|
2017-07-04 13:31:18 +00:00
|
|
|
, _st(st::adminLogFilterUserCheckbox)
|
2017-07-07 11:16:37 +00:00
|
|
|
, _check(std::make_unique<Ui::CheckView>(st::defaultCheck, checked, [this] { rtlupdate(_checkRect); }))
|
|
|
|
, _user(user) {
|
2017-07-04 13:31:18 +00:00
|
|
|
setCursor(style::cur_pointer);
|
|
|
|
setClickedCallback([this] {
|
|
|
|
if (isDisabled()) return;
|
|
|
|
setChecked(!this->checked());
|
|
|
|
});
|
2019-07-10 17:28:33 +00:00
|
|
|
auto now = base::unixtime::now();
|
2017-12-17 08:13:26 +00:00
|
|
|
_statusText = Data::OnlineText(_user, now);
|
|
|
|
_statusOnline = Data::OnlineTextActive(_user, now);
|
2017-07-07 11:16:37 +00:00
|
|
|
auto checkSize = _check->getSize();
|
|
|
|
_checkRect = { QPoint(_st.margin.left(), (st::contactsPhotoSize - checkSize.height()) / 2), checkSize };
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 09:55:56 +00:00
|
|
|
rpl::producer<bool> UserCheckbox::checkedChanges() const {
|
|
|
|
return _checkedChanges.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> UserCheckbox::checkedValue() const {
|
|
|
|
return _checkedChanges.events_starting_with(checked());
|
|
|
|
}
|
|
|
|
|
2017-07-04 13:31:18 +00:00
|
|
|
void UserCheckbox::setChecked(bool checked, NotifyAboutChange notify) {
|
2017-07-07 11:16:37 +00:00
|
|
|
if (_check->checked() != checked) {
|
2018-09-26 11:28:16 +00:00
|
|
|
_check->setChecked(checked, anim::type::normal);
|
2017-07-07 11:16:37 +00:00
|
|
|
if (notify == NotifyAboutChange::Notify) {
|
2018-12-05 09:55:56 +00:00
|
|
|
_checkedChanges.fire_copy(checked);
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserCheckbox::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
auto active = _check->currentAnimationValue();
|
2017-07-04 13:31:18 +00:00
|
|
|
auto color = anim::color(_st.rippleBg, _st.rippleBgActive, active);
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y() + (_checkRect.y() - st::defaultBoxCheckbox.margin.top()), &color);
|
2017-07-04 13:31:18 +00:00
|
|
|
|
2017-07-07 11:16:37 +00:00
|
|
|
auto realCheckRect = myrtlrect(_checkRect);
|
|
|
|
if (realCheckRect.intersects(e->rect())) {
|
|
|
|
_check->paint(p, _checkRect.left(), _checkRect.top(), width());
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
2017-07-07 11:16:37 +00:00
|
|
|
if (realCheckRect.contains(e->rect())) return;
|
2017-07-04 13:31:18 +00:00
|
|
|
|
|
|
|
auto userpicLeft = _checkRect.x() + _checkRect.width() + st::adminLogFilterUserpicLeft;
|
|
|
|
auto userpicTop = 0;
|
|
|
|
_user->paintUserpicLeft(p, userpicLeft, userpicTop, width(), st::contactsPhotoSize);
|
|
|
|
|
|
|
|
auto nameLeft = userpicLeft + st::contactsPhotoSize + st::contactsPadding.left();
|
|
|
|
auto nameTop = userpicTop + st::contactsNameTop;
|
|
|
|
auto nameWidth = width() - nameLeft - st::contactsPadding.right();
|
|
|
|
p.setPen(st::contactsNameFg);
|
2019-06-12 10:45:06 +00:00
|
|
|
_user->nameText().drawLeftElided(p, nameLeft, nameTop, nameWidth, width());
|
2017-07-04 13:31:18 +00:00
|
|
|
|
|
|
|
auto statusLeft = nameLeft;
|
|
|
|
auto statusTop = userpicTop + st::contactsStatusTop;
|
|
|
|
p.setFont(st::contactsStatusFont);
|
|
|
|
p.setPen(_statusOnline ? st::contactsStatusFgOnline : st::contactsStatusFg);
|
|
|
|
p.drawTextLeft(statusLeft, statusTop, width(), _statusText);
|
|
|
|
}
|
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
void UserCheckbox::finishAnimating() {
|
|
|
|
_check->finishAnimating();
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int UserCheckbox::resizeGetHeight(int newWidth) {
|
|
|
|
return st::contactsPhotoSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage UserCheckbox::prepareRippleMask() const {
|
2017-07-09 15:06:27 +00:00
|
|
|
return _check->prepareRippleMask();
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPoint UserCheckbox::prepareRippleStartPosition() const {
|
|
|
|
auto position = mapFromGlobal(QCursor::pos()) - _st.rippleAreaPosition - QPoint(0, _checkRect.y() - st::defaultBoxCheckbox.margin.top());
|
2017-07-09 15:06:27 +00:00
|
|
|
return _check->checkRippleStartPosition(position) ? position : DisabledRippleStartPosition();
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-12-05 09:55:56 +00:00
|
|
|
class FilterBox::Inner : public Ui::RpWidget {
|
2017-07-04 13:31:18 +00:00
|
|
|
public:
|
2018-12-05 09:55:56 +00:00
|
|
|
Inner(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
const std::vector<not_null<UserData*>> &admins,
|
|
|
|
const FilterValue &filter,
|
|
|
|
Fn<void()> changedCallback);
|
2017-07-04 13:31:18 +00:00
|
|
|
|
|
|
|
template <typename Widget>
|
|
|
|
QPointer<Widget> addRow(object_ptr<Widget> widget, int marginTop) {
|
|
|
|
widget->setParent(this);
|
|
|
|
widget->show();
|
|
|
|
auto row = Row();
|
|
|
|
row.widget = std::move(widget);
|
|
|
|
row.marginTop = marginTop;
|
|
|
|
_rows.push_back(std::move(row));
|
|
|
|
return static_cast<Widget*>(_rows.back().widget.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool canSave() const;
|
|
|
|
FilterValue filter() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2018-12-05 09:55:56 +00:00
|
|
|
void createControls(
|
|
|
|
const std::vector<not_null<UserData*>> &admins,
|
|
|
|
const FilterValue &filter);
|
2017-07-04 13:31:18 +00:00
|
|
|
void createAllActionsCheckbox(const FilterValue &filter);
|
|
|
|
void createActionsCheckboxes(const FilterValue &filter);
|
|
|
|
void createAllUsersCheckbox(const FilterValue &filter);
|
2018-12-05 09:55:56 +00:00
|
|
|
void createAdminsCheckboxes(
|
|
|
|
const std::vector<not_null<UserData*>> &admins,
|
|
|
|
const FilterValue &filter);
|
2017-07-04 13:31:18 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<ChannelData*> _channel;
|
2017-07-04 13:31:18 +00:00
|
|
|
|
|
|
|
QPointer<Ui::Checkbox> _allFlags;
|
|
|
|
QMap<MTPDchannelAdminLogEventsFilter::Flags, QPointer<Ui::Checkbox>> _filterFlags;
|
|
|
|
|
|
|
|
QPointer<Ui::Checkbox> _allUsers;
|
2017-08-17 08:31:24 +00:00
|
|
|
QMap<not_null<UserData*>, QPointer<UserCheckbox>> _admins;
|
2017-07-04 13:31:18 +00:00
|
|
|
bool _restoringInvariant = false;
|
|
|
|
|
|
|
|
struct Row {
|
|
|
|
object_ptr<TWidget> widget = { nullptr };
|
|
|
|
int marginTop = 0;
|
|
|
|
};
|
|
|
|
std::vector<Row> _rows;
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _changedCallback;
|
2017-07-04 13:31:18 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-12-05 09:55:56 +00:00
|
|
|
FilterBox::Inner::Inner(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
const std::vector<not_null<UserData*>> &admins,
|
|
|
|
const FilterValue &filter,
|
|
|
|
Fn<void()> changedCallback)
|
|
|
|
: RpWidget(parent)
|
2017-07-04 13:31:18 +00:00
|
|
|
, _channel(channel)
|
|
|
|
, _changedCallback(std::move(changedCallback)) {
|
|
|
|
createControls(admins, filter);
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void FilterBox::Inner::createControls(const std::vector<not_null<UserData*>> &admins, const FilterValue &filter) {
|
2017-07-04 13:31:18 +00:00
|
|
|
createAllActionsCheckbox(filter);
|
|
|
|
createActionsCheckboxes(filter);
|
|
|
|
createAllUsersCheckbox(filter);
|
|
|
|
createAdminsCheckboxes(admins, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilterBox::Inner::createAllActionsCheckbox(const FilterValue &filter) {
|
|
|
|
auto checked = (filter.flags == 0);
|
2019-06-19 15:09:03 +00:00
|
|
|
_allFlags = addRow(object_ptr<Ui::Checkbox>(this, tr::lng_admin_log_filter_all_actions(tr::now), checked, st::adminLogFilterCheckbox), st::adminLogFilterCheckbox.margin.top());
|
2018-12-05 09:55:56 +00:00
|
|
|
_allFlags->checkedChanges(
|
|
|
|
) | rpl::start_with_next([=](bool checked) {
|
2017-07-04 13:31:18 +00:00
|
|
|
if (!std::exchange(_restoringInvariant, true)) {
|
|
|
|
auto allChecked = _allFlags->checked();
|
|
|
|
for_const (auto &&checkbox, _filterFlags) {
|
|
|
|
checkbox->setChecked(allChecked);
|
|
|
|
}
|
|
|
|
_restoringInvariant = false;
|
|
|
|
if (_changedCallback) {
|
|
|
|
_changedCallback();
|
|
|
|
}
|
|
|
|
}
|
2018-12-05 09:55:56 +00:00
|
|
|
}, _allFlags->lifetime());
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FilterBox::Inner::createActionsCheckboxes(const FilterValue &filter) {
|
|
|
|
using Flag = MTPDchannelAdminLogEventsFilter::Flag;
|
|
|
|
using Flags = MTPDchannelAdminLogEventsFilter::Flags;
|
|
|
|
auto addFlag = [this, &filter](Flags flag, QString &&text) {
|
|
|
|
auto checked = (filter.flags == 0) || (filter.flags & flag);
|
|
|
|
auto checkbox = addRow(object_ptr<Ui::Checkbox>(this, std::move(text), checked, st::defaultBoxCheckbox), st::adminLogFilterLittleSkip);
|
|
|
|
_filterFlags.insert(flag, checkbox);
|
2018-12-05 09:55:56 +00:00
|
|
|
checkbox->checkedChanges(
|
|
|
|
) | rpl::start_with_next([=](bool checked) {
|
2017-07-04 13:31:18 +00:00
|
|
|
if (!std::exchange(_restoringInvariant, true)) {
|
|
|
|
auto allChecked = true;
|
|
|
|
for_const (auto &&checkbox, _filterFlags) {
|
|
|
|
if (!checkbox->checked()) {
|
|
|
|
allChecked = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_allFlags->setChecked(allChecked);
|
|
|
|
_restoringInvariant = false;
|
|
|
|
if (_changedCallback) {
|
|
|
|
_changedCallback();
|
|
|
|
}
|
|
|
|
}
|
2018-12-05 09:55:56 +00:00
|
|
|
}, checkbox->lifetime());
|
2017-07-04 13:31:18 +00:00
|
|
|
};
|
|
|
|
auto isGroup = _channel->isMegagroup();
|
|
|
|
if (isGroup) {
|
2019-06-19 15:09:03 +00:00
|
|
|
addFlag(Flag::f_ban | Flag::f_unban | Flag::f_kick | Flag::f_unkick, tr::lng_admin_log_filter_restrictions(tr::now));
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
addFlag(Flag::f_promote | Flag::f_demote, tr::lng_admin_log_filter_admins_new(tr::now));
|
|
|
|
addFlag(Flag::f_join | Flag::f_invite, tr::lng_admin_log_filter_members_new(tr::now));
|
|
|
|
addFlag(Flag::f_info | Flag::f_settings, _channel->isMegagroup() ? tr::lng_admin_log_filter_info_group(tr::now) : tr::lng_admin_log_filter_info_channel(tr::now));
|
|
|
|
addFlag(Flag::f_delete, tr::lng_admin_log_filter_messages_deleted(tr::now));
|
|
|
|
addFlag(Flag::f_edit, tr::lng_admin_log_filter_messages_edited(tr::now));
|
2017-07-04 13:31:18 +00:00
|
|
|
if (isGroup) {
|
2019-06-19 15:09:03 +00:00
|
|
|
addFlag(Flag::f_pinned, tr::lng_admin_log_filter_messages_pinned(tr::now));
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
addFlag(Flag::f_leave, tr::lng_admin_log_filter_members_removed(tr::now));
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FilterBox::Inner::createAllUsersCheckbox(const FilterValue &filter) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_allUsers = addRow(object_ptr<Ui::Checkbox>(this, tr::lng_admin_log_filter_all_admins(tr::now), filter.allUsers, st::adminLogFilterCheckbox), st::adminLogFilterSkip);
|
2018-12-05 09:55:56 +00:00
|
|
|
_allUsers->checkedChanges(
|
|
|
|
) | rpl::start_with_next([=](bool checked) {
|
2019-09-19 18:50:31 +00:00
|
|
|
if (!std::exchange(_restoringInvariant, true)) {
|
|
|
|
auto allChecked = _allUsers->checked();
|
2017-07-04 13:31:18 +00:00
|
|
|
for_const (auto &&checkbox, _admins) {
|
2019-09-19 18:50:31 +00:00
|
|
|
checkbox->setChecked(allChecked);
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
|
|
|
_restoringInvariant = false;
|
|
|
|
if (_changedCallback) {
|
|
|
|
_changedCallback();
|
|
|
|
}
|
|
|
|
}
|
2018-12-05 09:55:56 +00:00
|
|
|
}, _allUsers->lifetime());
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void FilterBox::Inner::createAdminsCheckboxes(const std::vector<not_null<UserData*>> &admins, const FilterValue &filter) {
|
2017-07-04 13:31:18 +00:00
|
|
|
for (auto user : admins) {
|
|
|
|
auto checked = filter.allUsers || base::contains(filter.admins, user);
|
2017-07-07 11:16:37 +00:00
|
|
|
auto checkbox = addRow(object_ptr<UserCheckbox>(this, user, checked), st::adminLogFilterLittleSkip);
|
2018-12-05 09:55:56 +00:00
|
|
|
checkbox->checkedChanges(
|
|
|
|
) | rpl::start_with_next([=](bool checked) {
|
2017-07-04 13:31:18 +00:00
|
|
|
if (!std::exchange(_restoringInvariant, true)) {
|
|
|
|
auto allChecked = true;
|
|
|
|
for_const (auto &&checkbox, _admins) {
|
|
|
|
if (!checkbox->checked()) {
|
|
|
|
allChecked = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!allChecked) {
|
|
|
|
_allUsers->setChecked(allChecked);
|
|
|
|
}
|
|
|
|
_restoringInvariant = false;
|
|
|
|
if (_changedCallback) {
|
|
|
|
_changedCallback();
|
|
|
|
}
|
|
|
|
}
|
2018-12-05 09:55:56 +00:00
|
|
|
}, checkbox->lifetime());
|
2017-07-04 13:31:18 +00:00
|
|
|
_admins.insert(user, checkbox);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FilterBox::Inner::canSave() const {
|
|
|
|
for (auto i = _filterFlags.cbegin(), e = _filterFlags.cend(); i != e; ++i) {
|
|
|
|
if (i.value()->checked()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterValue FilterBox::Inner::filter() const {
|
|
|
|
auto result = FilterValue();
|
|
|
|
auto allChecked = true;
|
|
|
|
for (auto i = _filterFlags.cbegin(), e = _filterFlags.cend(); i != e; ++i) {
|
|
|
|
if (i.value()->checked()) {
|
|
|
|
result.flags |= i.key();
|
|
|
|
} else {
|
|
|
|
allChecked = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (allChecked) {
|
|
|
|
result.flags = 0;
|
|
|
|
}
|
|
|
|
result.allUsers = _allUsers->checked();
|
|
|
|
if (!result.allUsers) {
|
|
|
|
result.admins.reserve(_admins.size());
|
|
|
|
for (auto i = _admins.cbegin(), e = _admins.cend(); i != e; ++i) {
|
|
|
|
if (i.value()->checked()) {
|
|
|
|
result.admins.push_back(i.key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FilterBox::Inner::resizeGetHeight(int newWidth) {
|
|
|
|
auto newHeight = 0;
|
|
|
|
auto rowWidth = newWidth - st::boxPadding.left() - st::boxPadding.right();
|
|
|
|
for (auto &&row : _rows) {
|
|
|
|
newHeight += row.marginTop;
|
|
|
|
row.widget->resizeToNaturalWidth(rowWidth);
|
|
|
|
newHeight += row.widget->heightNoMargins();
|
|
|
|
}
|
|
|
|
return newHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilterBox::Inner::resizeEvent(QResizeEvent *e) {
|
|
|
|
auto top = 0;
|
|
|
|
for (auto &&row : _rows) {
|
|
|
|
top += row.marginTop;
|
|
|
|
row.widget->moveToLeft(st::boxPadding.left(), top);
|
|
|
|
top += row.widget->heightNoMargins();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
FilterBox::FilterBox(QWidget*, not_null<ChannelData*> channel, const std::vector<not_null<UserData*>> &admins, const FilterValue &filter, Fn<void(FilterValue &&filter)> saveCallback) : BoxContent()
|
2017-07-04 13:31:18 +00:00
|
|
|
, _channel(channel)
|
|
|
|
, _admins(admins)
|
|
|
|
, _initialFilter(filter)
|
|
|
|
, _saveCallback(std::move(saveCallback)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilterBox::prepare() {
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(tr::lng_admin_log_filter_title());
|
2017-07-04 13:31:18 +00:00
|
|
|
|
|
|
|
_inner = setInnerWidget(object_ptr<Inner>(this, _channel, _admins, _initialFilter, [this] { refreshButtons(); }));
|
|
|
|
_inner->resizeToWidth(st::boxWideWidth);
|
|
|
|
|
|
|
|
refreshButtons();
|
2017-07-10 10:43:25 +00:00
|
|
|
setDimensions(st::boxWideWidth, qMin(_inner->height(), st::boxMaxListHeight));
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FilterBox::refreshButtons() {
|
|
|
|
clearButtons();
|
|
|
|
if (_inner->canSave()) {
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_settings_save(), [this] {
|
2017-07-04 13:31:18 +00:00
|
|
|
if (_saveCallback) {
|
|
|
|
_saveCallback(_inner->filter());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
2017-07-04 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FilterBox::resizeToContent() {
|
|
|
|
_inner->resizeToWidth(st::boxWideWidth);
|
|
|
|
setDimensions(_inner->width(), _inner->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace AdminLog
|