init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
150
Telegram/SourceFiles/window/themes/window_theme_warning.cpp
Normal file
150
Telegram/SourceFiles/window/themes/window_theme_warning.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
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 "window/themes/window_theme_warning.h"
|
||||
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/shadow.h"
|
||||
#include "ui/painter.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "ui/cached_round_corners.h"
|
||||
#include "window/themes/window_theme.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
namespace Window {
|
||||
namespace Theme {
|
||||
namespace {
|
||||
|
||||
constexpr int kWaitBeforeRevertMs = 15999;
|
||||
|
||||
} // namespace
|
||||
|
||||
WarningWidget::WarningWidget(QWidget *parent)
|
||||
: RpWidget(parent)
|
||||
, _timer([=] { handleTimer(); })
|
||||
, _secondsLeft(kWaitBeforeRevertMs / 1000)
|
||||
, _keepChanges(this, tr::lng_theme_keep_changes(), st::defaultBoxButton)
|
||||
, _revert(this, tr::lng_theme_revert(), st::defaultBoxButton) {
|
||||
using TextTransform = Ui::RoundButton::TextTransform;
|
||||
_keepChanges->setTextTransform(TextTransform::NoTransform);
|
||||
_keepChanges->setClickedCallback([] { KeepApplied(); });
|
||||
_revert->setTextTransform(TextTransform::NoTransform);
|
||||
_revert->setClickedCallback([] { 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()) {
|
||||
if (!_animation.animating()) {
|
||||
if (isHidden()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
p.setOpacity(_animation.value(_hiding ? 0. : 1.));
|
||||
p.drawPixmap(_outer.topLeft(), _cache);
|
||||
if (!_animation.animating()) {
|
||||
_cache = QPixmap();
|
||||
showChildren();
|
||||
_started = crl::now();
|
||||
_timer.callOnce(100);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Ui::Shadow::paint(p, _inner, width(), st::boxRoundShadow);
|
||||
Ui::FillRoundRect(p, _inner, st::boxBg, Ui::BoxCorners);
|
||||
|
||||
p.setFont(st::boxTitleFont);
|
||||
p.setPen(st::boxTitleFg);
|
||||
p.drawTextLeft(_inner.x() + st::boxTitlePosition.x(), _inner.y() + st::boxTitlePosition.y(), width(), tr::lng_theme_sure_keep(tr::now));
|
||||
|
||||
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);
|
||||
_outer = _inner.marginsAdded(st::boxRoundShadow.extend);
|
||||
updateControlsGeometry();
|
||||
update();
|
||||
}
|
||||
|
||||
void WarningWidget::updateControlsGeometry() {
|
||||
auto left = _inner.x() + _inner.width() - st::defaultBox.buttonPadding.right() - _keepChanges->width();
|
||||
_keepChanges->moveToLeft(left, _inner.y() + _inner.height() - st::defaultBox.buttonPadding.bottom() - _keepChanges->height());
|
||||
_revert->moveToLeft(left - st::defaultBox.buttonPadding.left() - _revert->width(), _keepChanges->y());
|
||||
}
|
||||
|
||||
void WarningWidget::refreshLang() {
|
||||
InvokeQueued(this, [this] { updateControlsGeometry(); });
|
||||
}
|
||||
|
||||
void WarningWidget::handleTimer() {
|
||||
auto msPassed = crl::now() - _started;
|
||||
setSecondsLeft((kWaitBeforeRevertMs - msPassed) / 1000);
|
||||
}
|
||||
|
||||
void WarningWidget::setSecondsLeft(int secondsLeft) {
|
||||
if (secondsLeft <= 0) {
|
||||
Window::Theme::Revert();
|
||||
} else {
|
||||
if (_secondsLeft != secondsLeft) {
|
||||
_secondsLeft = secondsLeft;
|
||||
updateText();
|
||||
update();
|
||||
}
|
||||
_timer.callOnce(100);
|
||||
}
|
||||
}
|
||||
|
||||
void WarningWidget::updateText() {
|
||||
_text = tr::lng_theme_reverting(tr::now, lt_count, _secondsLeft);
|
||||
}
|
||||
|
||||
void WarningWidget::showAnimated() {
|
||||
startAnimation(false);
|
||||
show();
|
||||
setFocus();
|
||||
}
|
||||
|
||||
void WarningWidget::hideAnimated() {
|
||||
startAnimation(true);
|
||||
}
|
||||
|
||||
void WarningWidget::startAnimation(bool hiding) {
|
||||
_timer.cancel();
|
||||
_hiding = hiding;
|
||||
if (_cache.isNull()) {
|
||||
showChildren();
|
||||
Ui::SendPendingMoveResizeEvents(this);
|
||||
_cache = Ui::GrabWidget(this, _outer);
|
||||
}
|
||||
hideChildren();
|
||||
_animation.start([this] {
|
||||
update();
|
||||
if (_hiding) {
|
||||
hide();
|
||||
if (_hiddenCallback) {
|
||||
_hiddenCallback();
|
||||
}
|
||||
}
|
||||
}, _hiding ? 1. : 0., _hiding ? 0. : 1., st::boxDuration);
|
||||
}
|
||||
|
||||
} // namespace Theme
|
||||
} // namespace Window
|
||||
Reference in New Issue
Block a user