summaryrefslogtreecommitdiff
path: root/qmap/decode_click_coalescer.cpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-09-26 23:24:28 +0200
committerChristoph Berg <myon@debian.org>2026-09-26 23:24:28 +0200
commit69344560ea394c06ca94acac46a2e4c3e8b7b229 (patch)
treeebc98370a697a9bbd6b973a14fa5113c475c6db7 /qmap/decode_click_coalescer.cpp
parent3e9d10a67671d0bd5c7b8c3ca8088f1818322eff (diff)
parent059831534c7e884f0a607ed86b582fd00d821731 (diff)
Update upstream source from tag 'upstream/3.2.0_rc1+dfsg'
Update to upstream version '3.2.0~rc1+dfsg' with Debian dir dbff457fd2c3616d5c77b863c7bfb2186ed86047
Diffstat (limited to 'qmap/decode_click_coalescer.cpp')
-rw-r--r--qmap/decode_click_coalescer.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/qmap/decode_click_coalescer.cpp b/qmap/decode_click_coalescer.cpp
new file mode 100644
index 00000000..b1c2725e
--- /dev/null
+++ b/qmap/decode_click_coalescer.cpp
@@ -0,0 +1,50 @@
+#include "decode_click_coalescer.h"
+
+#include <utility>
+
+#include <QApplication>
+#include <QObject>
+
+DecodeClickCoalescer::DecodeClickCoalescer (QObject * context, Dispatch dispatch, int interval)
+ : dispatch_ {std::move (dispatch)}
+{
+ timer_.setSingleShot (true);
+ timer_.setTimerType (Qt::PreciseTimer);
+ timer_.setInterval (interval >= 0 ? interval : QApplication::doubleClickInterval ());
+ QObject::connect (&timer_, &QTimer::timeout, context, [this] { dispatchPending (); });
+}
+
+void DecodeClickCoalescer::press (QString const& identity, QByteArray const& decodeRow)
+{
+ // Qt reports the first press before deciding whether the gesture is a double-click.
+ if (timer_.isActive () && pendingIdentity_ != identity) {
+ timer_.stop ();
+ dispatchPending ();
+ }
+ dispatch_ (decodeRow, DecodeClickGesture::Press);
+ pendingIdentity_ = identity;
+ pending_ = decodeRow;
+ timer_.start ();
+}
+
+void DecodeClickCoalescer::doubleClick (QString const& identity, QByteArray const& decodeRow)
+{
+ if (timer_.isActive ()) {
+ timer_.stop ();
+ if (pendingIdentity_ != identity) dispatchPending ();
+ else {
+ pendingIdentity_.clear ();
+ pending_.clear ();
+ }
+ }
+ dispatch_ (decodeRow, DecodeClickGesture::DoubleClick);
+}
+
+void DecodeClickCoalescer::dispatchPending ()
+{
+ if (pending_.isEmpty ()) return;
+ auto const decodeRow = pending_;
+ pendingIdentity_.clear ();
+ pending_.clear ();
+ dispatch_ (decodeRow, DecodeClickGesture::SingleClick);
+}