File: KisAsynchronousStrokeUpdateHelper.h

package info (click to toggle)
krita 1%3A5.2.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 535,928 kB
  • sloc: cpp: 644,668; python: 15,986; ansic: 10,315; xml: 8,488; perl: 622; sh: 214; sql: 129; lisp: 110; makefile: 8
file content (96 lines) | stat: -rw-r--r-- 2,739 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 *  SPDX-FileCopyrightText: 2019 Dmitry Kazakov <dimula73@gmail.com>
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 */


#ifndef KISASYNCHRONOUSSTROKEUPDATEHELPER_H
#define KISASYNCHRONOUSSTROKEUPDATEHELPER_H

#include <QObject>
#include <QTimer>
#include "kis_types.h"
#include "kis_stroke_job_strategy.h"
#include "kritaui_export.h"

class KisStrokesFacade;


class KRITAUI_EXPORT KisAsynchronousStrokeUpdateHelper : public QObject
{
    Q_OBJECT
public:
    class UpdateData : public KisStrokeJobData {
    public:
        UpdateData(bool _forceUpdate,
                   Sequentiality sequentiality = SEQUENTIAL,
                   Exclusivity exclusivity = NORMAL)
            : KisStrokeJobData(sequentiality, exclusivity),
              forceUpdate(_forceUpdate)
        {}

        KisStrokeJobData* createLodClone(int levelOfDetail) override {
            return new UpdateData(*this, levelOfDetail);
        }


    protected:
        UpdateData(const UpdateData &rhs, int levelOfDetail)
            : KisStrokeJobData(rhs),
              forceUpdate(rhs.forceUpdate)
        {
            Q_UNUSED(levelOfDetail);
        }
    public:
        bool forceUpdate = false;
    };

    using UpdateDataFactory = std::function<KisStrokeJobData*(bool)>;

public:
    KisAsynchronousStrokeUpdateHelper();
    ~KisAsynchronousStrokeUpdateHelper();

    /**
     * Initialize the update helper and start the steam of the
     * update events. This is just a simple combination of
     * initUpdateStreamLowLevel() and startUpdateStreamLowLevel().
     */
    void startUpdateStream(KisStrokesFacade *strokesFacade, KisStrokeId strokeId);

    /**
     *  A low-level version of startUpdateStream(...), initializes
     *  the helper but doesn't start the stream of update events.
     *  That is needed for the tool to issue endUpdateStream()
     *  signals, when the action has been ended **before** the
     *  stroke actually managed to initialize itself.
     */
    void initUpdateStreamLowLevel(KisStrokesFacade *strokesFacade, KisStrokeId strokeId);

    /**
     * Start the stream of the update events on **already
     * initialized** helper. One should call
     * initUpdateStreamWithoutStart() before calling
     * startUpdateStream().
     */
    void startUpdateStreamLowLevel();

    void endUpdateStream();
    void cancelUpdateStream();

    bool isActive() const;

    void setCustomUpdateDataFactory(UpdateDataFactory factory);

private Q_SLOTS:
    void slotAsyncUpdateCame(bool forceUpdate = false);

private:
    KisStrokesFacade *m_strokesFacade;
    QTimer m_updateThresholdTimer;
    KisStrokeId m_strokeId;
    UpdateDataFactory m_customUpdateFactory;
};

#endif // KISASYNCHRONOUSSTROKEUPDATEHELPER_H