compile
[kdegraphics.git] / kolourpaint / kpViewScrollableContainer.h
blob78e3303a5e3e0e63db4bbc194525ffea8ed0677b
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
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.
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.
29 #ifndef KP_VIEW_SCROLLABLE_CONTAINER_H
30 #define KP_VIEW_SCROLLABLE_CONTAINER_H
33 #include <qlabel.h>
34 #include <qpoint.h>
35 #include <q3scrollview.h>
36 #include <qsize.h>
39 class QCursor;
40 class QDragMoveEvent;
41 class QEvent;
42 class QKeyEvent;
43 class QMouseEvent;
44 class QPaintEvent;
45 class QRect;
46 class QResizeEvent;
47 class QTimer;
49 class kpGrip;
50 class kpView;
51 class kpMainWindow;
54 // REFACTOR: refactor by sharing iface's with kpTool
55 class kpGrip : public QLabel
57 Q_OBJECT
59 public:
60 enum GripType
62 Right = 1, Bottom = 2,
63 BottomRight = Right | Bottom
66 static const int Size;
68 kpGrip (GripType type, QWidget *parent);
69 virtual ~kpGrip ();
71 GripType type () const;
73 static QCursor cursorForType (GripType type);
75 QRect hotRect (bool toGlobal = false) const;
77 bool isDrawing () const;
79 signals:
80 void beganDraw ();
81 void continuedDraw (int viewDX, int viewDY, bool dueToDragScroll);
82 void cancelledDraw ();
83 void endedDraw (int viewDX, int viewDY);
85 void statusMessageChanged (const QString &string);
87 void releasedAllButtons ();
89 public:
90 QString haventBegunDrawUserMessage () const;
92 QString userMessage () const;
93 void setUserMessage (const QString &message);
95 protected:
96 void updatePixmap ();
97 void cancel ();
99 protected:
100 virtual void keyReleaseEvent (QKeyEvent *e);
101 virtual void mousePressEvent (QMouseEvent *e);
102 public:
103 QPoint viewDeltaPoint () const;
104 void mouseMovedTo (const QPoint &point, bool dueToDragScroll);
105 protected:
106 virtual void mouseMoveEvent (QMouseEvent *e);
107 virtual void mouseReleaseEvent (QMouseEvent *e);
108 virtual void resizeEvent (QResizeEvent *e);
110 virtual void enterEvent (QEvent *e);
111 virtual void leaveEvent (QEvent *e);
113 virtual void paintEvent (QPaintEvent *e);
115 protected:
116 GripType m_type;
117 QPoint m_startPoint, m_currentPoint;
118 QString m_userMessage;
119 bool m_shouldReleaseMouseButtons;
123 class kpViewScrollableContainer : public Q3ScrollView
125 Q_OBJECT
127 public:
128 kpViewScrollableContainer (kpMainWindow *parent);
129 virtual ~kpViewScrollableContainer ();
131 // Same as contentsX() and contentsY() except that after
132 // contentsMovingSoon() is emitted and before the scrollview actually
133 // scrolls, they return the would be values of contentsX() and
134 // contentsY() after scrolling.
135 int contentsXSoon ();
136 int contentsYSoon ();
138 signals:
139 // connect to this instead of contentsMoving(int,int) so that
140 // contentsXSoon() and contentsYSoon() work
141 void contentsMovingSoon (int contentsX, int contentsY);
143 void beganDocResize ();
144 void continuedDocResize (const QSize &size);
145 void cancelledDocResize ();
146 void endedDocResize (const QSize &size);
148 // (string.isEmpty() if kpViewScrollableContainer has nothing to say)
149 void statusMessageChanged (const QString &string);
151 void resized ();
153 public:
154 QSize newDocSize () const;
155 bool haveMovedFromOriginalDocSize () const;
156 QString statusMessage () const;
157 void clearStatusMessage ();
159 protected:
160 void connectGripSignals (kpGrip *grip);
162 QSize newDocSize (int viewDX, int viewDY) const;
164 void calculateDocResizingGrip ();
165 kpGrip *docResizingGrip () const;
167 int bottomResizeLineWidth () const;
168 int rightResizeLineWidth () const;
170 QRect bottomResizeLineRect () const;
171 QRect rightResizeLineRect () const;
172 QRect bottomRightResizeLineRect () const;
174 QPoint mapViewToViewport (const QPoint &viewPoint);
175 QRect mapViewToViewport (const QRect &viewRect);
177 QRect mapViewportToGlobal (const QRect &viewportRect);
178 QRect mapViewToGlobal (const QRect &viewRect);
180 void repaintWidgetAtResizeLineViewRect (QWidget *widget,
181 const QRect &resizeLineViewRect);
182 void repaintWidgetAtResizeLines (QWidget *widget);
183 void eraseResizeLines ();
185 void drawResizeLines ();
187 void updateResizeLines (int viewX, int viewY,
188 int viewDX, int viewDY);
190 protected slots:
191 void slotGripBeganDraw ();
192 void slotGripContinuedDraw (int viewDX, int viewDY, bool dueToScrollView);
193 void slotGripCancelledDraw ();
194 void slotGripEndedDraw (int viewDX, int viewDY);
196 void slotGripStatusMessageChanged (const QString &string);
198 public slots:
199 void recalculateStatusMessage ();
201 protected slots:
202 void slotContentsMoving (int x, int y);
203 void slotContentsMoved ();
205 protected:
206 void disconnectViewSignals ();
207 void connectViewSignals ();
209 public:
210 // Calls setView(<widget>) after adding <widget> if it's a kpView.
211 virtual void addChild (QWidget *widget, int x = 0, int y = 0);
213 kpView *view () const;
214 void setView (kpView *view);
216 public slots:
217 void updateGrips ();
218 protected slots:
219 void slotViewDestroyed ();
221 public slots:
222 // TODO: Why the QPoint's?
223 // Why the need for view's zoomLevel? We have the view() anyway.
224 bool beginDragScroll (const QPoint &, const QPoint &,
225 int zoomLevel,
226 bool *didSomething);
227 bool beginDragScroll (const QPoint &, const QPoint &,
228 int zoomLevel);
229 bool endDragScroll ();
231 protected slots:
232 bool slotDragScroll (bool *didSomething);
233 bool slotDragScroll ();
235 protected:
236 QRect noDragScrollRect () const;
238 virtual void contentsDragMoveEvent (QDragMoveEvent *e);
239 virtual void contentsMouseMoveEvent (QMouseEvent *e);
240 virtual void contentsWheelEvent (QWheelEvent *e);
241 virtual void mouseMoveEvent (QMouseEvent *e);
242 virtual bool eventFilter (QObject *watchedObject, QEvent *e);
243 virtual void viewportPaintEvent (QPaintEvent *e);
244 virtual void paintEvent (QPaintEvent *e);
245 virtual void resizeEvent (QResizeEvent *e);
247 protected:
248 kpMainWindow *m_mainWindow;
249 int m_contentsXSoon, m_contentsYSoon;
250 kpView *m_view;
251 kpGrip *m_bottomGrip, *m_rightGrip, *m_bottomRightGrip;
252 kpGrip *m_docResizingGrip;
253 QTimer *m_dragScrollTimer;
254 int m_zoomLevel;
255 bool m_scrollTimerRunOnce;
256 int m_resizeRoundedLastViewX, m_resizeRoundedLastViewY;
257 int m_resizeRoundedLastViewDX, m_resizeRoundedLastViewDY;
258 bool m_haveMovedFromOriginalDocSize;
259 QString m_gripStatusMessage;
263 #endif // KP_VIEW_SCROLLABLE_CONTAINER_H