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
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
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
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
This commit is contained in:
104
Telegram/SourceFiles/window/window_history_hider.cpp
Normal file
104
Telegram/SourceFiles/window/window_history_hider.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
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/window_history_hider.h"
|
||||
|
||||
#include "lang/lang_keys.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/shadow.h"
|
||||
#include "ui/cached_round_corners.h"
|
||||
#include "mainwidget.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_chat.h"
|
||||
|
||||
namespace Window {
|
||||
|
||||
HistoryHider::HistoryHider(QWidget *parent, const QString &text)
|
||||
: RpWidget(parent)
|
||||
, _text(text) {
|
||||
Lang::Updated(
|
||||
) | rpl::on_next([=] {
|
||||
refreshLang();
|
||||
}, lifetime());
|
||||
|
||||
_chooseWidth = st::historyForwardChooseFont->width(_text);
|
||||
|
||||
resizeEvent(0);
|
||||
_a_opacity.start([=] { update(); }, 0., 1., st::boxDuration);
|
||||
}
|
||||
|
||||
HistoryHider::~HistoryHider() = default;
|
||||
|
||||
void HistoryHider::refreshLang() {
|
||||
InvokeQueued(this, [this] { updateControlsGeometry(); });
|
||||
}
|
||||
|
||||
void HistoryHider::paintEvent(QPaintEvent *e) {
|
||||
auto p = QPainter(this);
|
||||
auto opacity = _a_opacity.value(_hiding ? 0. : 1.);
|
||||
if (opacity == 0.) {
|
||||
if (_hiding) {
|
||||
_hidden.fire({});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
p.setOpacity(opacity);
|
||||
p.fillRect(rect(), st::layerBg);
|
||||
p.setFont(st::historyForwardChooseFont);
|
||||
auto w = st::historyForwardChooseMargins.left() + _chooseWidth + st::historyForwardChooseMargins.right();
|
||||
auto h = st::historyForwardChooseMargins.top() + st::historyForwardChooseFont->height + st::historyForwardChooseMargins.bottom();
|
||||
Ui::FillRoundRect(p, (width() - w) / 2, (height() - h) / 2, w, h, st::historyForwardChooseBg, Ui::ForwardCorners);
|
||||
|
||||
p.setPen(st::historyForwardChooseFg);
|
||||
p.drawText(_box, _text, QTextOption(style::al_center));
|
||||
}
|
||||
|
||||
void HistoryHider::keyPressEvent(QKeyEvent *e) {
|
||||
if (e->key() == Qt::Key_Escape) {
|
||||
startHide();
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryHider::mousePressEvent(QMouseEvent *e) {
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
if (!_box.contains(e->pos())) {
|
||||
startHide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryHider::startHide() {
|
||||
if (_hiding) return;
|
||||
|
||||
_hiding = true;
|
||||
_a_opacity.start([=] { animationCallback(); }, 1., 0., st::boxDuration);
|
||||
}
|
||||
|
||||
void HistoryHider::animationCallback() {
|
||||
update();
|
||||
if (!_a_opacity.animating() && _hiding) {
|
||||
crl::on_main(this, [=] { _hidden.fire({}); });
|
||||
}
|
||||
}
|
||||
|
||||
rpl::producer<> HistoryHider::hidden() const {
|
||||
return _hidden.events();
|
||||
}
|
||||
|
||||
void HistoryHider::resizeEvent(QResizeEvent *e) {
|
||||
updateControlsGeometry();
|
||||
}
|
||||
|
||||
void HistoryHider::updateControlsGeometry() {
|
||||
auto w = st::boxWidth;
|
||||
auto h = st::boxPadding.top() + st::boxPadding.bottom();
|
||||
h += st::historyForwardChooseFont->height;
|
||||
_box = QRect((width() - w) / 2, (height() - h) / 2, w, h);
|
||||
}
|
||||
|
||||
} // namespace Window
|
||||
Reference in New Issue
Block a user