1
2/*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28
29#ifndef KP_VIEW_SCROLLABLE_CONTAINER_H
30#define KP_VIEW_SCROLLABLE_CONTAINER_H
31
32
33#include <qlabel.h>
34#include <qpoint.h>
35#include <QScrollArea>
36#include <qsize.h>
37
38
39class QCursor;
40class QDragMoveEvent;
41class QEvent;
42class QKeyEvent;
43class QMouseEvent;
44class QPaintEvent;
45class QRect;
46class QResizeEvent;
47class QTimer;
48
49class kpView;
50class kpOverlay;
51
52
53//---------------------------------------------------------------------
54
55// REFACTOR: refactor by sharing iface's with kpTool
56class kpGrip : public QWidget
57{
58Q_OBJECT
59
60public:
61 enum GripType
62 {
63 Right = 1, Bottom = 2,
64 BottomRight = Right | Bottom
65 };
66
67 kpGrip (GripType type, QWidget *parent);
68
69 GripType type () const;
70
71 static QCursor cursorForType (GripType type);
72
73 bool containsCursor();
74
75 bool isDrawing () const;
76
77 static const int Size;
78
79signals:
80 void beganDraw ();
81 void continuedDraw (int viewDX, int viewDY, bool dueToDragScroll);
82 void cancelledDraw ();
83 void endedDraw (int viewDX, int viewDY);
84
85 void statusMessageChanged (const QString &string);
86
87 void releasedAllButtons ();
88
89public:
90 QString haventBegunDrawUserMessage () const;
91
92 QString userMessage () const;
93 void setUserMessage (const QString &message);
94
95protected:
96 void cancel ();
97
98protected:
99 virtual void keyReleaseEvent (QKeyEvent *e);
100 virtual void mousePressEvent (QMouseEvent *e);
101public:
102 QPoint viewDeltaPoint () const;
103 void mouseMovedTo (const QPoint &point, bool dueToDragScroll);
104protected:
105 virtual void mouseMoveEvent (QMouseEvent *e);
106 virtual void mouseReleaseEvent (QMouseEvent *e);
107
108 virtual void enterEvent (QEvent *e);
109 virtual void leaveEvent (QEvent *e);
110
111protected:
112 GripType m_type;
113 QPoint m_startPoint, m_currentPoint;
114 QString m_userMessage;
115 bool m_shouldReleaseMouseButtons;
116};
117
118//---------------------------------------------------------------------
119
120class kpViewScrollableContainer : public QScrollArea
121{
122Q_OBJECT
123
124public:
125 kpViewScrollableContainer(QWidget *parent);
126
127 QSize newDocSize () const;
128 bool haveMovedFromOriginalDocSize () const;
129 QString statusMessage () const;
130 void clearStatusMessage ();
131
132 kpView *view () const;
133 void setView (kpView *view);
134
135 void drawResizeLines(); // public only for kpOverlay
136
137signals:
138 void contentsMoved();
139
140 void beganDocResize ();
141 void continuedDocResize (const QSize &size);
142 void cancelledDocResize ();
143 void endedDocResize (const QSize &size);
144
145 // (string.isEmpty() if kpViewScrollableContainer has nothing to say)
146 void statusMessageChanged (const QString &string);
147
148 void resized ();
149
150public slots:
151 void recalculateStatusMessage ();
152
153 void updateGrips ();
154
155 // TODO: Why the need for view's zoomLevel? We have the view() anyway.
156 bool beginDragScroll (int zoomLevel,
157 bool *didSomething);
158 bool beginDragScroll (int zoomLevel);
159 bool endDragScroll ();
160
161private:
162 void connectGripSignals (kpGrip *grip);
163
164 QSize newDocSize (int viewDX, int viewDY) const;
165
166 void calculateDocResizingGrip ();
167 kpGrip *docResizingGrip () const;
168
169 int bottomResizeLineWidth () const;
170 int rightResizeLineWidth () const;
171
172 QRect bottomResizeLineRect () const;
173 QRect rightResizeLineRect () const;
174 QRect bottomRightResizeLineRect () const;
175
176 QRect mapViewToViewport (const QRect &viewRect);
177
178 void updateResizeLines (int viewX, int viewY,
179 int viewDX, int viewDY);
180
181 void disconnectViewSignals ();
182 void connectViewSignals ();
183
184 QRect noDragScrollRect () const;
185
186 virtual void wheelEvent(QWheelEvent *e);
187 virtual void resizeEvent(QResizeEvent *e);
188
189private slots:
190 void slotGripBeganDraw ();
191 void slotGripContinuedDraw (int viewDX, int viewDY, bool dueToScrollView);
192 void slotGripCancelledDraw ();
193 void slotGripEndedDraw (int viewDX, int viewDY);
194
195 void slotGripStatusMessageChanged (const QString &string);
196
197 void slotContentsMoved ();
198 void slotViewDestroyed ();
199 bool slotDragScroll (bool *didSomething);
200 bool slotDragScroll ();
201
202private:
203 kpView *m_view;
204 kpOverlay *m_overlay;
205 kpGrip *m_bottomGrip, *m_rightGrip, *m_bottomRightGrip;
206 kpGrip *m_docResizingGrip;
207 QTimer *m_dragScrollTimer;
208 int m_zoomLevel;
209 bool m_scrollTimerRunOnce;
210 int m_resizeRoundedLastViewX, m_resizeRoundedLastViewY;
211 int m_resizeRoundedLastViewDX, m_resizeRoundedLastViewDY;
212 bool m_haveMovedFromOriginalDocSize;
213 QString m_gripStatusMessage;
214};
215
216#endif // KP_VIEW_SCROLLABLE_CONTAINER_H
217