From 86c1cce260b82eaa32b1b7ee7e010b83ac17a8f3 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 10 Apr 2021 21:52:18 +0300 Subject: [PATCH] Replaced QTimer with base::Timer in FlatLabel. --- ui/widgets/labels.cpp | 18 +++++++----------- ui/widgets/labels.h | 7 +++---- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/ui/widgets/labels.cpp b/ui/widgets/labels.cpp index ace7162..5fa7eed 100644 --- a/ui/widgets/labels.cpp +++ b/ui/widgets/labels.cpp @@ -230,7 +230,8 @@ FlatLabel::FlatLabel( const style::FlatLabel &st) : RpWidget(parent) , _text(st.minWidth ? st.minWidth : QFIXED_MAX) -, _st(st) { +, _st(st) +, _touchSelectTimer([=] { onTouchSelect(); }) { textUpdated(); std::move( text @@ -242,11 +243,6 @@ FlatLabel::FlatLabel( void FlatLabel::init() { _contextCopyText = Integration::Instance().phraseContextCopyText(); - - _trippleClickTimer.setSingleShot(true); - - _touchSelectTimer.setSingleShot(true); - connect(&_touchSelectTimer, SIGNAL(timeout()), this, SLOT(onTouchSelect())); } void FlatLabel::textUpdated() { @@ -406,7 +402,7 @@ Text::StateResult FlatLabel::dragActionStart(const QPoint &p, Qt::MouseButton bu _dragAction = Selecting; _selectionType = TextSelectType::Paragraphs; updateHover(state); - _trippleClickTimer.start(QApplication::doubleClickInterval()); + _trippleClickTimer.callOnce(QApplication::doubleClickInterval()); update(); } } @@ -486,7 +482,7 @@ void FlatLabel::mouseDoubleClickEvent(QMouseEvent *e) { mouseMoveEvent(e); _trippleClickPoint = e->globalPos(); - _trippleClickTimer.start(QApplication::doubleClickInterval()); + _trippleClickTimer.callOnce(QApplication::doubleClickInterval()); } } } @@ -559,7 +555,7 @@ void FlatLabel::touchEvent(QTouchEvent *e) { if (e->type() == QEvent::TouchCancel) { // cancel if (!_touchInProgress) return; _touchInProgress = false; - _touchSelectTimer.stop(); + _touchSelectTimer.cancel(); _touchSelect = false; _dragAction = NoDrag; return; @@ -580,7 +576,7 @@ void FlatLabel::touchEvent(QTouchEvent *e) { if (e->touchPoints().isEmpty()) return; _touchInProgress = true; - _touchSelectTimer.start(QApplication::startDragTime()); + _touchSelectTimer.callOnce(QApplication::startDragTime()); _touchSelect = false; _touchStart = _touchPrevPos = _touchPos; } break; @@ -606,7 +602,7 @@ void FlatLabel::touchEvent(QTouchEvent *e) { dragActionFinish(_touchPos, Qt::LeftButton); } if (weak) { - _touchSelectTimer.stop(); + _touchSelectTimer.cancel(); _touchSelect = false; } } break; diff --git a/ui/widgets/labels.h b/ui/widgets/labels.h index 076a39e..0dbe992 100644 --- a/ui/widgets/labels.h +++ b/ui/widgets/labels.h @@ -6,6 +6,7 @@ // #pragma once +#include "base/timer.h" #include "base/unique_qptr.h" #include "ui/rp_widget.h" #include "ui/wrap/padding_wrap.h" @@ -14,8 +15,6 @@ #include "ui/widgets/box_content_divider.h" #include "styles/style_widgets.h" -#include - class QTouchEvent; namespace Ui { @@ -227,7 +226,7 @@ private: QPoint _lastMousePos; QPoint _trippleClickPoint; - QTimer _trippleClickTimer; + base::Timer _trippleClickTimer; base::unique_qptr _contextMenu; QString _contextCopyText; @@ -238,7 +237,7 @@ private: bool _touchSelect = false; bool _touchInProgress = false; QPoint _touchStart, _touchPrevPos, _touchPos; - QTimer _touchSelectTimer; + base::Timer _touchSelectTimer; };