2016-11-02 14:44:33 +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.
|
2016-11-02 14:44:33 +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
|
2016-11-02 14:44:33 +00:00
|
|
|
*/
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "window/themes/window_theme_warning.h"
|
2016-11-02 14:44:33 +00:00
|
|
|
|
|
|
|
#include "styles/style_boxes.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-11-02 14:44:33 +00:00
|
|
|
|
|
|
|
namespace Window {
|
|
|
|
namespace Theme {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr int kWaitBeforeRevertMs = 15999;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-01-18 11:26:43 +00:00
|
|
|
WarningWidget::WarningWidget(QWidget *parent)
|
|
|
|
: TWidget(parent)
|
|
|
|
, _timer([=] { handleTimer(); })
|
2016-11-02 14:44:33 +00:00
|
|
|
, _secondsLeft(kWaitBeforeRevertMs / 1000)
|
2017-05-30 15:21:05 +00:00
|
|
|
, _keepChanges(this, langFactory(lng_theme_keep_changes), st::defaultBoxButton)
|
|
|
|
, _revert(this, langFactory(lng_theme_revert), st::defaultBoxButton) {
|
2016-11-02 14:44:33 +00:00
|
|
|
_keepChanges->setClickedCallback([] { Window::Theme::KeepApplied(); });
|
|
|
|
_revert->setClickedCallback([] { Window::Theme::Revert(); });
|
|
|
|
updateText();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WarningWidget::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Escape) {
|
|
|
|
Window::Theme::Revert();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WarningWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
if (!_cache.isNull()) {
|
2019-04-02 09:13:30 +00:00
|
|
|
if (!_animation.animating()) {
|
2016-11-02 14:44:33 +00:00
|
|
|
if (isHidden()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-04-02 09:13:30 +00:00
|
|
|
p.setOpacity(_animation.value(_hiding ? 0. : 1.));
|
2016-11-02 14:44:33 +00:00
|
|
|
p.drawPixmap(_outer.topLeft(), _cache);
|
|
|
|
if (!_animation.animating()) {
|
|
|
|
_cache = QPixmap();
|
|
|
|
showChildren();
|
2019-02-19 06:57:53 +00:00
|
|
|
_started = crl::now();
|
2019-01-18 11:26:43 +00:00
|
|
|
_timer.callOnce(100);
|
2016-11-02 14:44:33 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::Shadow::paint(p, _inner, width(), st::boxRoundShadow);
|
|
|
|
App::roundRect(p, _inner, st::boxBg, BoxCorners);
|
2016-11-02 14:44:33 +00:00
|
|
|
|
|
|
|
p.setFont(st::boxTitleFont);
|
|
|
|
p.setPen(st::boxTitleFg);
|
|
|
|
p.drawTextLeft(_inner.x() + st::boxTitlePosition.x(), _inner.y() + st::boxTitlePosition.y(), width(), lang(lng_theme_sure_keep));
|
|
|
|
|
|
|
|
p.setFont(st::boxTextFont);
|
|
|
|
p.setPen(st::boxTextFg);
|
|
|
|
p.drawTextLeft(_inner.x() + st::boxTitlePosition.x(), _inner.y() + st::themeWarningTextTop, width(), _text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WarningWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
_inner = QRect((width() - st::themeWarningWidth) / 2, (height() - st::themeWarningHeight) / 2, st::themeWarningWidth, st::themeWarningHeight);
|
2016-12-13 17:07:56 +00:00
|
|
|
_outer = _inner.marginsAdded(st::boxRoundShadow.extend);
|
2017-05-30 15:21:05 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WarningWidget::updateControlsGeometry() {
|
2016-11-02 14:44:33 +00:00
|
|
|
auto left = _inner.x() + _inner.width() - st::boxButtonPadding.right() - _keepChanges->width();
|
|
|
|
_keepChanges->moveToLeft(left, _inner.y() + _inner.height() - st::boxButtonPadding.bottom() - _keepChanges->height());
|
|
|
|
_revert->moveToLeft(left - st::boxButtonPadding.left() - _revert->width(), _keepChanges->y());
|
2017-05-30 15:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WarningWidget::refreshLang() {
|
|
|
|
InvokeQueued(this, [this] { updateControlsGeometry(); });
|
2016-11-02 14:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WarningWidget::handleTimer() {
|
2019-02-19 06:57:53 +00:00
|
|
|
auto msPassed = crl::now() - _started;
|
2016-11-02 14:44:33 +00:00
|
|
|
setSecondsLeft((kWaitBeforeRevertMs - msPassed) / 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WarningWidget::setSecondsLeft(int secondsLeft) {
|
|
|
|
if (secondsLeft <= 0) {
|
|
|
|
Window::Theme::Revert();
|
|
|
|
} else {
|
|
|
|
if (_secondsLeft != secondsLeft) {
|
|
|
|
_secondsLeft = secondsLeft;
|
|
|
|
updateText();
|
|
|
|
update();
|
|
|
|
}
|
2019-01-18 11:26:43 +00:00
|
|
|
_timer.callOnce(100);
|
2016-11-02 14:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WarningWidget::updateText() {
|
|
|
|
_text = lng_theme_reverting(lt_count, _secondsLeft);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WarningWidget::showAnimated() {
|
|
|
|
startAnimation(false);
|
|
|
|
show();
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WarningWidget::hideAnimated() {
|
|
|
|
startAnimation(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WarningWidget::startAnimation(bool hiding) {
|
2019-01-18 11:26:43 +00:00
|
|
|
_timer.cancel();
|
2016-11-02 14:44:33 +00:00
|
|
|
_hiding = hiding;
|
|
|
|
if (_cache.isNull()) {
|
|
|
|
showChildren();
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
|
|
|
_cache = Ui::GrabWidget(this, _outer);
|
2016-11-02 14:44:33 +00:00
|
|
|
}
|
|
|
|
hideChildren();
|
|
|
|
_animation.start([this] {
|
|
|
|
update();
|
|
|
|
if (_hiding) {
|
|
|
|
hide();
|
|
|
|
if (_hiddenCallback) {
|
|
|
|
_hiddenCallback();
|
|
|
|
}
|
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
}, _hiding ? 1. : 0., _hiding ? 0. : 1., st::boxDuration);
|
2016-11-02 14:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Theme
|
|
|
|
} // namespace Window
|