Replaced QTimer with base::Timer in OverlayWidget.

This commit is contained in:
23rd 2020-11-17 03:54:53 +03:00 committed by John Preston
parent eb42a77eb7
commit b6f17e1cea
2 changed files with 18 additions and 22 deletions

View file

@ -322,8 +322,7 @@ OverlayWidget::OverlayWidget()
, _radial([=](crl::time now) { return radialAnimationCallback(now); }) , _radial([=](crl::time now) { return radialAnimationCallback(now); })
, _lastAction(-st::mediaviewDeltaFromLastAction, -st::mediaviewDeltaFromLastAction) , _lastAction(-st::mediaviewDeltaFromLastAction, -st::mediaviewDeltaFromLastAction)
, _stateAnimation([=](crl::time now) { return stateAnimationCallback(now); }) , _stateAnimation([=](crl::time now) { return stateAnimationCallback(now); })
, _dropdown(this, st::mediaviewDropdownMenu) , _dropdown(this, st::mediaviewDropdownMenu) {
, _dropdownShowTimer(this) {
Lang::Updated( Lang::Updated(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
refreshLang(); refreshLang();
@ -410,23 +409,19 @@ OverlayWidget::OverlayWidget()
} }
}, lifetime()); }, lifetime());
_saveMsgUpdater.setSingleShot(true); _saveMsgUpdater.setCallback([=] { updateImage(); });
connect(&_saveMsgUpdater, SIGNAL(timeout()), this, SLOT(updateImage()));
setAttribute(Qt::WA_AcceptTouchEvents); setAttribute(Qt::WA_AcceptTouchEvents);
_touchTimer.setSingleShot(true); _touchTimer.setCallback([=] { onTouchTimer(); });
connect(&_touchTimer, SIGNAL(timeout()), this, SLOT(onTouchTimer()));
_controlsHideTimer.setSingleShot(true); _controlsHideTimer.setCallback([=] { onHideControls(); });
connect(&_controlsHideTimer, SIGNAL(timeout()), this, SLOT(onHideControls()));
_docDownload->addClickHandler([=] { onDownload(); }); _docDownload->addClickHandler([=] { onDownload(); });
_docSaveAs->addClickHandler([=] { onSaveAs(); }); _docSaveAs->addClickHandler([=] { onSaveAs(); });
_docCancel->addClickHandler([=] { onSaveCancel(); }); _docCancel->addClickHandler([=] { onSaveCancel(); });
_dropdown->setHiddenCallback([this] { dropdownHidden(); }); _dropdown->setHiddenCallback([this] { dropdownHidden(); });
_dropdownShowTimer->setSingleShot(true); _dropdownShowTimer.setCallback([=] { onDropdown(); });
connect(_dropdownShowTimer, SIGNAL(timeout()), this, SLOT(onDropdown()));
} }
void OverlayWidget::refreshLang() { void OverlayWidget::refreshLang() {
@ -1240,7 +1235,7 @@ void OverlayWidget::close() {
void OverlayWidget::activateControls() { void OverlayWidget::activateControls() {
if (!_menu && !_mousePressed) { if (!_menu && !_mousePressed) {
_controlsHideTimer.start(int(st::mediaviewWaitHide)); _controlsHideTimer.callOnce(st::mediaviewWaitHide);
} }
if (_fullScreenVideo) { if (_fullScreenVideo) {
if (_streamed) { if (_streamed) {
@ -3113,7 +3108,7 @@ void OverlayWidget::paintEvent(QPaintEvent *e) {
} }
if (!_blurred) { if (!_blurred) {
auto nextFrame = (dt < st::mediaviewSaveMsgShowing || hidingDt >= 0) ? int(AnimationTimerDelta) : (st::mediaviewSaveMsgShowing + st::mediaviewSaveMsgShown + 1 - dt); auto nextFrame = (dt < st::mediaviewSaveMsgShowing || hidingDt >= 0) ? int(AnimationTimerDelta) : (st::mediaviewSaveMsgShowing + st::mediaviewSaveMsgShown + 1 - dt);
_saveMsgUpdater.start(nextFrame); _saveMsgUpdater.callOnce(nextFrame);
} }
} else { } else {
_saveMsgStarted = 0; _saveMsgStarted = 0;
@ -3968,9 +3963,9 @@ bool OverlayWidget::updateOverState(OverState newState) {
bool result = true; bool result = true;
if (_over != newState) { if (_over != newState) {
if (newState == OverMore && !_ignoringDropdown) { if (newState == OverMore && !_ignoringDropdown) {
_dropdownShowTimer->start(0); _dropdownShowTimer.callOnce(0);
} else { } else {
_dropdownShowTimer->stop(); _dropdownShowTimer.cancel();
} }
updateOverRect(_over); updateOverRect(_over);
updateOverRect(newState); updateOverRect(newState);
@ -4163,7 +4158,7 @@ void OverlayWidget::touchEvent(QTouchEvent *e) {
switch (e->type()) { switch (e->type()) {
case QEvent::TouchBegin: { case QEvent::TouchBegin: {
if (_touchPress || e->touchPoints().isEmpty()) return; if (_touchPress || e->touchPoints().isEmpty()) return;
_touchTimer.start(QApplication::startDragTime()); _touchTimer.callOnce(QApplication::startDragTime());
_touchPress = true; _touchPress = true;
_touchMove = _touchRightButton = false; _touchMove = _touchRightButton = false;
_touchStart = e->touchPoints().cbegin()->screenPos().toPoint(); _touchStart = e->touchPoints().cbegin()->screenPos().toPoint();
@ -4203,14 +4198,14 @@ void OverlayWidget::touchEvent(QTouchEvent *e) {
} }
} }
if (weak) { if (weak) {
_touchTimer.stop(); _touchTimer.cancel();
_touchPress = _touchMove = _touchRightButton = false; _touchPress = _touchMove = _touchRightButton = false;
} }
} break; } break;
case QEvent::TouchCancel: { case QEvent::TouchCancel: {
_touchPress = false; _touchPress = false;
_touchTimer.stop(); _touchTimer.cancel();
} break; } break;
} }
} }
@ -4315,7 +4310,7 @@ void OverlayWidget::setVisibleHook(bool visible) {
_preloadPhotos.clear(); _preloadPhotos.clear();
_preloadDocuments.clear(); _preloadDocuments.clear();
if (_menu) _menu->hideMenu(true); if (_menu) _menu->hideMenu(true);
_controlsHideTimer.stop(); _controlsHideTimer.cancel();
_controlsState = ControlsShown; _controlsState = ControlsShown;
_controlsOpacity = anim::value(1, 1); _controlsOpacity = anim::value(1, 1);
_groupThumbs = nullptr; _groupThumbs = nullptr;

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "base/timer.h"
#include "ui/rp_widget.h" #include "ui/rp_widget.h"
#include "ui/widgets/dropdown_menu.h" #include "ui/widgets/dropdown_menu.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
@ -493,13 +494,13 @@ private:
}; };
ControlsState _controlsState = ControlsShown; ControlsState _controlsState = ControlsShown;
crl::time _controlsAnimStarted = 0; crl::time _controlsAnimStarted = 0;
QTimer _controlsHideTimer; base::Timer _controlsHideTimer;
anim::value _controlsOpacity; anim::value _controlsOpacity;
bool _mousePressed = false; bool _mousePressed = false;
Ui::PopupMenu *_menu = nullptr; Ui::PopupMenu *_menu = nullptr;
object_ptr<Ui::DropdownMenu> _dropdown; object_ptr<Ui::DropdownMenu> _dropdown;
object_ptr<QTimer> _dropdownShowTimer; base::Timer _dropdownShowTimer;
struct ActionData { struct ActionData {
QString text; QString text;
@ -512,7 +513,7 @@ private:
bool _touchPress = false; bool _touchPress = false;
bool _touchMove = false; bool _touchMove = false;
bool _touchRightButton = false; bool _touchRightButton = false;
QTimer _touchTimer; base::Timer _touchTimer;
QPoint _touchStart; QPoint _touchStart;
QPoint _accumScroll; QPoint _accumScroll;
@ -520,7 +521,7 @@ private:
crl::time _saveMsgStarted = 0; crl::time _saveMsgStarted = 0;
anim::value _saveMsgOpacity; anim::value _saveMsgOpacity;
QRect _saveMsg; QRect _saveMsg;
QTimer _saveMsgUpdater; base::Timer _saveMsgUpdater;
Ui::Text::String _saveMsgText; Ui::Text::String _saveMsgText;
SavePhotoVideo _savePhotoVideoWhenLoaded = SavePhotoVideo::None; SavePhotoVideo _savePhotoVideoWhenLoaded = SavePhotoVideo::None;