3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
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
35 #include <q3scrollview.h>
54 // REFACTOR: refactor by sharing iface's with kpTool
55 class kpGrip
: public QLabel
62 Right
= 1, Bottom
= 2,
63 BottomRight
= Right
| Bottom
66 static const int Size
;
68 kpGrip (GripType type
, QWidget
*parent
);
71 GripType
type () const;
73 static QCursor
cursorForType (GripType type
);
75 QRect
hotRect (bool toGlobal
= false) const;
77 bool isDrawing () const;
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 ();
90 QString
haventBegunDrawUserMessage () const;
92 QString
userMessage () const;
93 void setUserMessage (const QString
&message
);
100 virtual void keyReleaseEvent (QKeyEvent
*e
);
101 virtual void mousePressEvent (QMouseEvent
*e
);
103 QPoint
viewDeltaPoint () const;
104 void mouseMovedTo (const QPoint
&point
, bool dueToDragScroll
);
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
);
117 QPoint m_startPoint
, m_currentPoint
;
118 QString m_userMessage
;
119 bool m_shouldReleaseMouseButtons
;
123 class kpViewScrollableContainer
: public Q3ScrollView
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 ();
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
);
154 QSize
newDocSize () const;
155 bool haveMovedFromOriginalDocSize () const;
156 QString
statusMessage () const;
157 void clearStatusMessage ();
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
);
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
);
199 void recalculateStatusMessage ();
202 void slotContentsMoving (int x
, int y
);
203 void slotContentsMoved ();
206 void disconnectViewSignals ();
207 void connectViewSignals ();
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
);
219 void slotViewDestroyed ();
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
&,
227 bool beginDragScroll (const QPoint
&, const QPoint
&,
229 bool endDragScroll ();
232 bool slotDragScroll (bool *didSomething
);
233 bool slotDragScroll ();
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
);
248 kpMainWindow
*m_mainWindow
;
249 int m_contentsXSoon
, m_contentsYSoon
;
251 kpGrip
*m_bottomGrip
, *m_rightGrip
, *m_bottomRightGrip
;
252 kpGrip
*m_docResizingGrip
;
253 QTimer
*m_dragScrollTimer
;
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