File: kpViewScrollableContainer.h

package info (click to toggle)
kolourpaint 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,984 kB
  • sloc: cpp: 34,045; xml: 489; sh: 10; makefile: 5
file content (188 lines) | stat: -rw-r--r-- 4,553 bytes parent folder | download
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

/*
   SPDX-FileCopyrightText: 2003-2007 Clarence Dang <dang@kde.org>

   SPDX-License-Identifier: BSD-2-Clause
*/

#ifndef KP_VIEW_SCROLLABLE_CONTAINER_H
#define KP_VIEW_SCROLLABLE_CONTAINER_H

#include <QPoint>
#include <QScrollArea>
#include <QSize>

class QCursor;
class QEvent;
class QKeyEvent;
class QMouseEvent;
class QRect;
class QResizeEvent;
class QTimer;

class kpView;
class kpOverlay;

//---------------------------------------------------------------------

// REFACTOR: refactor by sharing iface's with kpTool
class kpGrip : public QWidget
{
    Q_OBJECT

public:
    enum GripType {
        Right = 1,
        Bottom = 2,
        BottomRight = Right | Bottom
    };

    kpGrip(GripType type, QWidget *parent);

    GripType type() const;

    static QCursor cursorForType(GripType type);

    bool containsCursor();

    bool isDrawing() const;

    static const int Size;

Q_SIGNALS:
    void beganDraw();
    void continuedDraw(int viewDX, int viewDY, bool dueToDragScroll);
    void cancelledDraw();
    void endedDraw(int viewDX, int viewDY);

    void statusMessageChanged(const QString &string);

    void releasedAllButtons();

public:
    QString haventBegunDrawUserMessage() const;

    QString userMessage() const;
    void setUserMessage(const QString &message);

protected:
    void cancel();

protected:
    void keyReleaseEvent(QKeyEvent *e) override;
    void mousePressEvent(QMouseEvent *e) override;

public:
    QPoint viewDeltaPoint() const;
    void mouseMovedTo(const QPoint &point, bool dueToDragScroll);

protected:
    void mouseMoveEvent(QMouseEvent *e) override;
    void mouseReleaseEvent(QMouseEvent *e) override;

    void enterEvent(QEnterEvent *e) override;
    void leaveEvent(QEvent *e) override;

protected:
    GripType m_type;
    QPoint m_startPoint, m_currentPoint;
    QString m_userMessage;
    bool m_shouldReleaseMouseButtons;
};

//---------------------------------------------------------------------

class kpViewScrollableContainer : public QScrollArea
{
    Q_OBJECT

public:
    explicit kpViewScrollableContainer(QWidget *parent);

    QSize newDocSize() const;
    bool haveMovedFromOriginalDocSize() const;
    QString statusMessage() const;
    void clearStatusMessage();

    kpView *view() const;
    void setView(kpView *view);

    void drawResizeLines(); // public only for kpOverlay

Q_SIGNALS:
    void contentsMoved();

    void beganDocResize();
    void continuedDocResize(const QSize &size);
    void cancelledDocResize();
    void endedDocResize(const QSize &size);

    // (string.isEmpty() if kpViewScrollableContainer has nothing to say)
    void statusMessageChanged(const QString &string);

    void resized();

public Q_SLOTS:
    void recalculateStatusMessage();

    void updateGrips();

    // TODO: Why the need for view's zoomLevel?  We have the view() anyway.
    bool beginDragScroll(int zoomLevel, bool *didSomething);
    bool beginDragScroll(int zoomLevel);
    bool endDragScroll();

private:
    void connectGripSignals(kpGrip *grip);

    QSize newDocSize(int viewDX, int viewDY) const;

    void calculateDocResizingGrip();
    kpGrip *docResizingGrip() const;

    int bottomResizeLineWidth() const;
    int rightResizeLineWidth() const;

    QRect bottomResizeLineRect() const;
    QRect rightResizeLineRect() const;
    QRect bottomRightResizeLineRect() const;

    QRect mapViewToViewport(const QRect &viewRect);

    void updateResizeLines(int viewX, int viewY, int viewDX, int viewDY);

    void disconnectViewSignals();
    void connectViewSignals();

    QRect noDragScrollRect() const;

    void wheelEvent(QWheelEvent *e) override;
    void resizeEvent(QResizeEvent *e) override;

private Q_SLOTS:
    void slotGripBeganDraw();
    void slotGripContinuedDraw(int viewDX, int viewDY, bool dueToScrollView);
    void slotGripCancelledDraw();
    void slotGripEndedDraw(int viewDX, int viewDY);

    void slotGripStatusMessageChanged(const QString &string);

    void slotContentsMoved();
    void slotViewDestroyed();
    bool slotDragScroll(bool *didSomething = nullptr);

private:
    kpView *m_view;
    kpOverlay *m_overlay;
    kpGrip *m_bottomGrip, *m_rightGrip, *m_bottomRightGrip;
    kpGrip *m_docResizingGrip;
    QTimer *m_dragScrollTimer;
    int m_zoomLevel;
    bool m_scrollTimerRunOnce;
    int m_resizeRoundedLastViewX, m_resizeRoundedLastViewY;
    int m_resizeRoundedLastViewDX, m_resizeRoundedLastViewDY;
    bool m_haveMovedFromOriginalDocSize;
    QString m_gripStatusMessage;
};

#endif // KP_VIEW_SCROLLABLE_CONTAINER_H