File indexing completed on 2024-05-12 15:58:45

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef __KIS_TIMED_SIGNAL_THRESHOLD_H
0008 #define __KIS_TIMED_SIGNAL_THRESHOLD_H
0009 
0010 #include "kritaimage_export.h"
0011 #include <QScopedPointer>
0012 #include <QObject>
0013 
0014 
0015 /**
0016  * Emits the timeout() signal if and only if the flow of start()
0017  * events has been coming for a consecutive \p delay of milliseconds.
0018  * If the events were not coming for \p cancelDelay of milliseconds the
0019  * counting is dropped and the new period is started.
0020  */
0021 class KRITAIMAGE_EXPORT KisTimedSignalThreshold : public QObject
0022 {
0023     Q_OBJECT
0024 public:
0025     KisTimedSignalThreshold(int delay, int cancelDelay = -1, QObject *parent = 0);
0026     ~KisTimedSignalThreshold() override;
0027 
0028 public Q_SLOTS:
0029     /**
0030      * Stops counting and emits the signal forcefully
0031      */
0032     void forceDone();
0033 
0034     /**
0035      * Start/continue counting and if the signal flow is stable enough
0036      * (longer than \p delay and shorter than \p cancelDelay), the
0037      * timeout signal in emitted.
0038      */
0039     void start();
0040 
0041     /**
0042      * Stops counting the signals flow
0043      */
0044     void stop();
0045 
0046     /**
0047      * Enable or disable emitting the signal
0048      */
0049     void setEnabled(bool value);
0050 
0051 
0052     /**
0053      * The peiod of time, after which the signal will be emitted
0054      */
0055     void setDelayThreshold(int delay, int cancelDelay = -1);
0056 
0057 Q_SIGNALS:
0058     void timeout();
0059 
0060 private:
0061     struct Private;
0062     const QScopedPointer<Private> m_d;
0063 };
0064 
0065 #endif /* __KIS_TIMED_SIGNAL_THRESHOLD_H */