2014-05-30 08:53:19 +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.
|
2014-05-30 08:53:19 +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
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
2018-12-05 08:07:17 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_boxes.h"
|
2015-09-23 17:43:08 +00:00
|
|
|
|
2021-10-18 22:28:08 +00:00
|
|
|
namespace Ui {
|
2020-03-26 08:10:35 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
TextParseOptions kInformBoxTextOptions = {
|
|
|
|
(TextParseLinks
|
|
|
|
| TextParseMultiline
|
2022-01-07 03:50:06 +00:00
|
|
|
| TextParseMarkdown), // flags
|
2014-12-05 13:44:27 +00:00
|
|
|
0, // maxw
|
|
|
|
0, // maxh
|
|
|
|
Qt::LayoutDirectionAuto, // dir
|
|
|
|
};
|
|
|
|
|
2020-03-26 08:10:35 +00:00
|
|
|
TextParseOptions kMarkedTextBoxOptions = {
|
|
|
|
(TextParseLinks
|
|
|
|
| TextParseMultiline
|
|
|
|
| TextParseMarkdown
|
|
|
|
| TextParseMentions
|
|
|
|
| TextParseHashtags), // flags
|
|
|
|
0, // maxw
|
|
|
|
0, // maxh
|
|
|
|
Qt::LayoutDirectionAuto, // dir
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
2020-09-23 16:06:09 +00:00
|
|
|
ConfirmBox::ConfirmedCallback confirmedCallback,
|
2019-01-14 17:43:06 +00:00
|
|
|
FnMut<void()> cancelledCallback)
|
2019-06-19 15:09:03 +00:00
|
|
|
: _confirmText(tr::lng_box_ok(tr::now))
|
|
|
|
, _cancelText(tr::lng_cancel(tr::now))
|
2016-12-13 17:07:56 +00:00
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2021-10-18 21:36:55 +00:00
|
|
|
, _text(st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::defaultBox.buttonPadding.right())
|
2017-02-21 13:45:56 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
const QString &confirmText,
|
2020-09-23 16:06:09 +00:00
|
|
|
ConfirmBox::ConfirmedCallback confirmedCallback,
|
2019-01-14 17:43:06 +00:00
|
|
|
FnMut<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
2019-06-19 15:09:03 +00:00
|
|
|
, _cancelText(tr::lng_cancel(tr::now))
|
2016-12-13 17:07:56 +00:00
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2021-10-18 21:36:55 +00:00
|
|
|
, _text(st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::defaultBox.buttonPadding.right())
|
2017-02-21 13:45:56 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const TextWithEntities &text,
|
|
|
|
const QString &confirmText,
|
2020-09-23 16:06:09 +00:00
|
|
|
ConfirmBox::ConfirmedCallback confirmedCallback,
|
2019-01-14 17:43:06 +00:00
|
|
|
FnMut<void()> cancelledCallback)
|
2018-04-18 15:42:02 +00:00
|
|
|
: _confirmText(confirmText)
|
2019-06-19 15:09:03 +00:00
|
|
|
, _cancelText(tr::lng_cancel(tr::now))
|
2018-04-18 15:42:02 +00:00
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2021-10-18 21:36:55 +00:00
|
|
|
, _text(st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::defaultBox.buttonPadding.right())
|
2018-04-18 15:42:02 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
const QString &confirmText,
|
|
|
|
const style::RoundButton &confirmStyle,
|
2020-09-23 16:06:09 +00:00
|
|
|
ConfirmBox::ConfirmedCallback confirmedCallback,
|
2019-01-14 17:43:06 +00:00
|
|
|
FnMut<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
2019-06-19 15:09:03 +00:00
|
|
|
, _cancelText(tr::lng_cancel(tr::now))
|
2016-12-13 17:07:56 +00:00
|
|
|
, _confirmStyle(confirmStyle)
|
2021-10-18 21:36:55 +00:00
|
|
|
, _text(st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::defaultBox.buttonPadding.right())
|
2017-02-21 13:45:56 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
const QString &confirmText,
|
|
|
|
const QString &cancelText,
|
2020-09-23 16:06:09 +00:00
|
|
|
ConfirmBox::ConfirmedCallback confirmedCallback,
|
2019-01-14 17:43:06 +00:00
|
|
|
FnMut<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
|
|
|
, _cancelText(cancelText)
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2021-10-18 21:36:55 +00:00
|
|
|
, _text(st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::defaultBox.buttonPadding.right())
|
2017-02-21 13:45:56 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
2014-12-05 13:44:27 +00:00
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
const QString &confirmText,
|
|
|
|
const style::RoundButton &confirmStyle,
|
|
|
|
const QString &cancelText,
|
2020-09-23 16:06:09 +00:00
|
|
|
ConfirmBox::ConfirmedCallback confirmedCallback,
|
2019-01-14 17:43:06 +00:00
|
|
|
FnMut<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
|
|
|
, _cancelText(cancelText)
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2021-10-18 21:36:55 +00:00
|
|
|
, _text(st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::defaultBox.buttonPadding.right())
|
2017-02-21 13:45:56 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
const InformBoxTag &,
|
|
|
|
const QString &text,
|
|
|
|
const QString &doneText,
|
|
|
|
Fn<void()> closedCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(doneText)
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2016-03-04 22:04:15 +00:00
|
|
|
, _informative(true)
|
2021-10-18 21:36:55 +00:00
|
|
|
, _text(st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::defaultBox.buttonPadding.right())
|
2016-12-20 13:03:51 +00:00
|
|
|
, _confirmedCallback(generateInformCallback(closedCallback))
|
|
|
|
, _cancelledCallback(generateInformCallback(closedCallback)) {
|
2014-12-05 13:44:27 +00:00
|
|
|
init(text);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
const InformBoxTag &,
|
|
|
|
const TextWithEntities &text,
|
|
|
|
const QString &doneText,
|
|
|
|
Fn<void()> closedCallback)
|
2018-04-18 15:42:02 +00:00
|
|
|
: _confirmText(doneText)
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
|
|
|
, _informative(true)
|
2021-10-18 21:36:55 +00:00
|
|
|
, _text(st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::defaultBox.buttonPadding.right())
|
2018-04-18 15:42:02 +00:00
|
|
|
, _confirmedCallback(generateInformCallback(closedCallback))
|
|
|
|
, _cancelledCallback(generateInformCallback(closedCallback)) {
|
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
FnMut<void()> ConfirmBox::generateInformCallback(
|
|
|
|
Fn<void()> closedCallback) {
|
|
|
|
return crl::guard(this, [=] {
|
2016-12-20 13:03:51 +00:00
|
|
|
closeBox();
|
2017-03-17 18:44:55 +00:00
|
|
|
if (closedCallback) {
|
|
|
|
closedCallback();
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-12-05 13:44:27 +00:00
|
|
|
void ConfirmBox::init(const QString &text) {
|
2019-01-14 17:43:06 +00:00
|
|
|
_text.setText(
|
|
|
|
st::boxLabelStyle,
|
|
|
|
text,
|
2020-03-26 08:10:35 +00:00
|
|
|
_informative ? kInformBoxTextOptions : _textPlainOptions);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 15:42:02 +00:00
|
|
|
void ConfirmBox::init(const TextWithEntities &text) {
|
2020-03-26 08:10:35 +00:00
|
|
|
_text.setMarkedText(st::boxLabelStyle, text, kMarkedTextBoxOptions);
|
2018-04-18 15:42:02 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmBox::prepare() {
|
2019-01-14 17:43:06 +00:00
|
|
|
addButton(
|
2019-06-18 16:53:27 +00:00
|
|
|
rpl::single(_confirmText),
|
2019-01-14 17:43:06 +00:00
|
|
|
[=] { confirmed(); },
|
|
|
|
_confirmStyle);
|
2016-12-13 17:07:56 +00:00
|
|
|
if (!_informative) {
|
2019-01-14 17:43:06 +00:00
|
|
|
addButton(
|
2019-06-18 16:53:27 +00:00
|
|
|
rpl::single(_cancelText),
|
2019-01-14 17:43:06 +00:00
|
|
|
[=] { _cancelled = true; closeBox(); });
|
2016-08-12 15:22:11 +00:00
|
|
|
}
|
2018-03-29 19:49:31 +00:00
|
|
|
|
|
|
|
boxClosing() | rpl::start_with_next([=] {
|
2018-11-26 11:00:31 +00:00
|
|
|
if (!_confirmed && (!_strictCancel || _cancelled)) {
|
|
|
|
if (auto callback = std::move(_cancelledCallback)) {
|
|
|
|
callback();
|
|
|
|
}
|
2017-08-13 16:09:14 +00:00
|
|
|
}
|
2018-03-29 19:49:31 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
textUpdated();
|
2016-08-12 15:22:11 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 15:08:12 +00:00
|
|
|
void ConfirmBox::setMaxLineCount(int count) {
|
|
|
|
if (_maxLineCount != count) {
|
|
|
|
_maxLineCount = count;
|
|
|
|
textUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmBox::textUpdated() {
|
2021-10-18 21:36:55 +00:00
|
|
|
_textWidth = st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::defaultBox.buttonPadding.right();
|
2018-05-30 15:08:12 +00:00
|
|
|
_textHeight = _text.countHeight(_textWidth);
|
|
|
|
if (_maxLineCount > 0) {
|
2021-10-18 21:36:55 +00:00
|
|
|
accumulate_min(
|
|
|
|
_textHeight,
|
|
|
|
_maxLineCount * st::boxLabelStyle.lineHeight);
|
2018-05-30 15:08:12 +00:00
|
|
|
}
|
2021-10-18 21:36:55 +00:00
|
|
|
setDimensions(
|
|
|
|
st::boxWidth,
|
|
|
|
st::boxPadding.top() + _textHeight + st::boxPadding.bottom());
|
2016-08-12 15:22:11 +00:00
|
|
|
|
|
|
|
setMouseTracking(_text.hasLinks());
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmBox::confirmed() {
|
|
|
|
if (!_confirmed) {
|
|
|
|
_confirmed = true;
|
2020-09-23 16:06:09 +00:00
|
|
|
|
|
|
|
const auto confirmed = &_confirmedCallback;
|
|
|
|
if (const auto callbackPtr = std::get_if<1>(confirmed)) {
|
|
|
|
if (auto callback = base::take(*callbackPtr)) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
} else if (const auto callbackPtr = std::get_if<2>(confirmed)) {
|
|
|
|
if (auto callback = base::take(*callbackPtr)) {
|
2021-08-23 10:54:49 +00:00
|
|
|
const auto weak = Ui::MakeWeak(this);
|
|
|
|
callback(crl::guard(weak, [=] { closeBox(); }));
|
2020-09-23 16:06:09 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-12 18:01:32 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 13:44:27 +00:00
|
|
|
void ConfirmBox::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
updateHover();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::mousePressEvent(QMouseEvent *e) {
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
updateHover();
|
2016-03-29 17:17:00 +00:00
|
|
|
ClickHandler::pressed();
|
2016-12-13 17:07:56 +00:00
|
|
|
return BoxContent::mousePressEvent(e);
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
updateHover();
|
2018-11-26 11:00:31 +00:00
|
|
|
if (const auto activated = ClickHandler::unpressed()) {
|
2021-04-13 15:02:17 +00:00
|
|
|
ActivateClickHandler(window(), activated, e->button());
|
|
|
|
crl::on_main(this, [=] {
|
|
|
|
closeBox();
|
|
|
|
});
|
2018-11-26 11:00:31 +00:00
|
|
|
return;
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
2018-11-26 11:00:31 +00:00
|
|
|
BoxContent::mouseReleaseEvent(e);
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void ConfirmBox::leaveEventHook(QEvent *e) {
|
2016-03-29 17:17:00 +00:00
|
|
|
ClickHandler::clearActive(this);
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:36:55 +00:00
|
|
|
void ConfirmBox::clickHandlerActiveChanged(
|
|
|
|
const ClickHandlerPtr &p,
|
|
|
|
bool active) {
|
2016-03-29 17:17:00 +00:00
|
|
|
setCursor(active ? style::cur_pointer : style::cur_default);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:36:55 +00:00
|
|
|
void ConfirmBox::clickHandlerPressedChanged(
|
|
|
|
const ClickHandlerPtr &p,
|
|
|
|
bool pressed) {
|
2016-03-29 17:17:00 +00:00
|
|
|
update();
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::updateLink() {
|
|
|
|
_lastMousePos = QCursor::pos();
|
|
|
|
updateHover();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::updateHover() {
|
2021-10-18 21:36:55 +00:00
|
|
|
const auto m = mapFromGlobal(_lastMousePos);
|
|
|
|
const auto state = _text.getStateLeft(
|
|
|
|
m - QPoint(st::boxPadding.left(), st::boxPadding.top()),
|
|
|
|
_textWidth,
|
|
|
|
width());
|
2016-03-29 17:17:00 +00:00
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
ClickHandler::setActive(state.link, this);
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void ConfirmBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
2016-12-13 17:07:56 +00:00
|
|
|
confirmed();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::keyPressEvent(e);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-11-19 14:47:28 +00:00
|
|
|
|
|
|
|
Painter p(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
// draw box title / text
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
2018-05-30 15:08:12 +00:00
|
|
|
if (_maxLineCount > 0) {
|
2021-10-18 21:36:55 +00:00
|
|
|
_text.drawLeftElided(
|
|
|
|
p,
|
|
|
|
st::boxPadding.left(),
|
|
|
|
st::boxPadding.top(),
|
|
|
|
_textWidth,
|
|
|
|
width(),
|
|
|
|
_maxLineCount,
|
|
|
|
style::al_left);
|
2018-05-30 15:08:12 +00:00
|
|
|
} else {
|
2021-10-18 21:36:55 +00:00
|
|
|
_text.drawLeft(
|
|
|
|
p,
|
|
|
|
st::boxPadding.left(),
|
|
|
|
st::boxPadding.top(),
|
|
|
|
_textWidth,
|
|
|
|
width(),
|
|
|
|
style::al_left);
|
2018-05-30 15:08:12 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 21:36:55 +00:00
|
|
|
InformBox::InformBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text, Fn<void()> closedCallback)
|
|
|
|
: ConfirmBox(
|
|
|
|
ConfirmBox::InformBoxTag(),
|
|
|
|
text,
|
|
|
|
tr::lng_box_ok(tr::now),
|
|
|
|
std::move(closedCallback)) {
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 21:36:55 +00:00
|
|
|
InformBox::InformBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
const QString &doneText,
|
|
|
|
Fn<void()> closedCallback)
|
|
|
|
: ConfirmBox(
|
|
|
|
ConfirmBox::InformBoxTag(),
|
|
|
|
text,
|
|
|
|
doneText,
|
|
|
|
std::move(closedCallback)) {
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 21:36:55 +00:00
|
|
|
InformBox::InformBox(
|
|
|
|
QWidget*,
|
|
|
|
const TextWithEntities &text,
|
|
|
|
Fn<void()> closedCallback)
|
|
|
|
: ConfirmBox(
|
|
|
|
ConfirmBox::InformBoxTag(),
|
|
|
|
text,
|
|
|
|
tr::lng_box_ok(tr::now),
|
|
|
|
std::move(closedCallback)) {
|
2018-04-18 15:42:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 21:36:55 +00:00
|
|
|
InformBox::InformBox(
|
|
|
|
QWidget*,
|
|
|
|
const TextWithEntities &text,
|
|
|
|
const QString &doneText,
|
|
|
|
Fn<void()> closedCallback)
|
|
|
|
: ConfirmBox(
|
|
|
|
ConfirmBox::InformBoxTag(),
|
|
|
|
text,
|
|
|
|
doneText,
|
|
|
|
std::move(closedCallback)) {
|
2018-06-04 18:18:52 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 08:07:17 +00:00
|
|
|
ConfirmDontWarnBox::ConfirmDontWarnBox(
|
|
|
|
QWidget*,
|
2019-06-12 20:11:41 +00:00
|
|
|
rpl::producer<TextWithEntities> text,
|
2018-12-05 08:07:17 +00:00
|
|
|
const QString &checkbox,
|
2019-06-18 16:53:27 +00:00
|
|
|
rpl::producer<QString> confirm,
|
2018-12-05 08:07:17 +00:00
|
|
|
FnMut<void(bool)> callback)
|
2019-06-18 16:53:27 +00:00
|
|
|
: _confirm(std::move(confirm))
|
2019-06-12 20:11:41 +00:00
|
|
|
, _content(setupContent(std::move(text), checkbox, std::move(callback))) {
|
2018-12-05 08:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmDontWarnBox::prepare() {
|
|
|
|
setDimensionsToContent(st::boxWidth, _content);
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(std::move(_confirm), [=] { _callback(); });
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2018-12-05 08:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Ui::RpWidget*> ConfirmDontWarnBox::setupContent(
|
2019-06-12 20:11:41 +00:00
|
|
|
rpl::producer<TextWithEntities> text,
|
2018-12-05 08:07:17 +00:00
|
|
|
const QString &checkbox,
|
|
|
|
FnMut<void(bool)> callback) {
|
|
|
|
const auto result = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
result->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
result,
|
2019-06-12 20:11:41 +00:00
|
|
|
std::move(text),
|
2018-12-05 08:07:17 +00:00
|
|
|
st::boxLabel),
|
|
|
|
st::boxPadding);
|
|
|
|
const auto control = result->add(
|
|
|
|
object_ptr<Ui::Checkbox>(
|
|
|
|
result,
|
|
|
|
checkbox,
|
|
|
|
false,
|
|
|
|
st::defaultBoxCheckbox),
|
|
|
|
style::margins(
|
|
|
|
st::boxPadding.left(),
|
|
|
|
st::boxPadding.bottom(),
|
|
|
|
st::boxPadding.right(),
|
|
|
|
st::boxPadding.bottom()));
|
|
|
|
_callback = [=, callback = std::move(callback)]() mutable {
|
|
|
|
const auto checked = control->checked();
|
|
|
|
auto local = std::move(callback);
|
|
|
|
closeBox();
|
|
|
|
local(checked);
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
}
|
2021-10-18 22:28:08 +00:00
|
|
|
|
|
|
|
} // namespace Ui
|