1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the Qt3Support module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef KTL_Q3SCROLLVIEW_H
43 #define KTL_Q3SCROLLVIEW_H
44 
45 #include <ktlqt3support/ktlq3frame.h>
46 #include <QScrollBar>
47 
48 // QT_BEGIN_HEADER
49 
50 //QT_BEGIN_NAMESPACE
51 
52 //QT_MODULE(Qt3SupportLight)
53 
54 class KtlQ3ScrollViewData;
55 
56 class KtlQ3ScrollView : public KtlQ3Frame
57 {
58     Q_OBJECT
59     Q_ENUMS( ResizePolicy ScrollBarMode )
60     Q_PROPERTY( ResizePolicy resizePolicy READ resizePolicy WRITE setResizePolicy )
61     Q_PROPERTY( ScrollBarMode vScrollBarMode READ vScrollBarMode WRITE setVScrollBarMode )
62     Q_PROPERTY( ScrollBarMode hScrollBarMode READ hScrollBarMode WRITE setHScrollBarMode )
63     Q_PROPERTY( int visibleWidth READ visibleWidth )
64     Q_PROPERTY( int visibleHeight READ visibleHeight )
65     Q_PROPERTY( int contentsWidth READ contentsWidth )
66     Q_PROPERTY( int contentsHeight READ contentsHeight )
67     Q_PROPERTY( int contentsX READ contentsX )
68     Q_PROPERTY( int contentsY READ contentsY )
69     Q_PROPERTY( bool dragAutoScroll READ dragAutoScroll WRITE setDragAutoScroll )
70 
71 public:
72     KtlQ3ScrollView(QWidget* parent = nullptr, const char* name = nullptr, Qt::WindowFlags f = {});
73     ~KtlQ3ScrollView() override;
74 
75     enum ResizePolicy { Default, Manual, AutoOne, AutoOneFit };
76     virtual void setResizePolicy( ResizePolicy );
77     ResizePolicy resizePolicy() const;
78 
79     void styleChange( QStyle & );
80     void removeChild(QWidget* child);
81     virtual void addChild( QWidget* child, int x=0, int y=0 );
82     virtual void moveChild( QWidget* child, int x, int y );
83     int childX(QWidget* child);
84     int childY(QWidget* child);
childIsVisible(QWidget * child)85     bool childIsVisible(QWidget* child) { return child->isVisible(); } // obsolete functions
86     void showChild(QWidget* child, bool yes=true) { child->setVisible(yes); }
87 
88     enum ScrollBarMode { Auto, AlwaysOff, AlwaysOn };
89 
90     ScrollBarMode vScrollBarMode() const;
91     virtual void  setVScrollBarMode( ScrollBarMode );
92 
93     ScrollBarMode hScrollBarMode() const;
94     virtual void  setHScrollBarMode( ScrollBarMode );
95 
96     QWidget*     cornerWidget() const;
97     virtual void setCornerWidget(QWidget*);
98 
99     // ### 4.0: Consider providing a factory function for scrollbars
100     //          (e.g. make the two following functions virtual)
101     QScrollBar*  horizontalScrollBar() const;
102     QScrollBar*  verticalScrollBar() const;
103     QWidget*	 viewport() const;
104     QWidget*	 clipper() const;
105 
106     int		visibleWidth() const;
107     int		visibleHeight() const;
108 
109     int		contentsWidth() const;
110     int		contentsHeight() const;
111     int		contentsX() const;
112     int		contentsY() const;
113 
114     void	resize( int w, int h );
115     void	resize( const QSize& );
116     void	setVisible(bool visible) override;
117 
118     void	updateContents( int x, int y, int w, int h );
119     void	updateContents( const QRect& r );
120     void 	updateContents();
121     void	repaintContents( int x, int y, int w, int h, bool erase=true );
122     void	repaintContents( const QRect& r, bool erase=true );
123     void 	repaintContents( bool erase=true );
124     void	contentsToViewport( int x, int y, int& vx, int& vy ) const;
125     void	viewportToContents( int vx, int vy, int& x, int& y ) const;
126     QPoint	contentsToViewport( const QPoint& ) const;
127     QPoint	viewportToContents( const QPoint& ) const;
128     void	enableClipper( bool y );
129 
130     void	setStaticBackground( bool y );
131     bool	hasStaticBackground() const;
132 
133     QSize	viewportSize( int, int ) const;
134     QSize	sizeHint() const override;
135     QSize	minimumSizeHint() const override;
136 
137     void	removeChild(QObject* child);
138 
139     bool	isHorizontalSliderPressed();
140     bool	isVerticalSliderPressed();
141 
142     virtual void setDragAutoScroll( bool b );
143     bool	 dragAutoScroll() const;
144 
145 Q_SIGNALS:
146     void	contentsMoving(int x, int y);
147     void	horizontalSliderPressed();
148     void	horizontalSliderReleased();
149     void	verticalSliderPressed();
150     void	verticalSliderReleased();
151 
152 public Q_SLOTS:
153     virtual void resizeContents( int w, int h );
154     void	scrollBy( int dx, int dy );
155     virtual void setContentsPos( int x, int y );
156     void	ensureVisible(int x, int y);
157     void	ensureVisible(int x, int y, int xmargin, int ymargin);
158     void	center(int x, int y);
159     void	center(int x, int y, float xmargin, float ymargin);
160 
161     void	updateScrollBars(); // ### virtual in 4.0
162     void	setEnabled( bool enable );
163 
164 protected:
165     virtual void drawContents(QPainter*, int cx, int cy, int cw, int ch);
166     virtual void drawContentsOffset(QPainter*, int ox, int oy,
167 		    int cx, int cy, int cw, int ch);
168 
169 
170     virtual void contentsMousePressEvent( QMouseEvent* );
171     virtual void contentsMouseReleaseEvent( QMouseEvent* );
172     virtual void contentsMouseDoubleClickEvent( QMouseEvent* );
173     virtual void contentsMouseMoveEvent( QMouseEvent* );
174     virtual void contentsDragEnterEvent( QDragEnterEvent * );
175     virtual void contentsDragMoveEvent( QDragMoveEvent * );
176     virtual void contentsDragLeaveEvent( QDragLeaveEvent * );
177     virtual void contentsDropEvent( QDropEvent * );
178     virtual void contentsWheelEvent( QWheelEvent * );
179     virtual void contentsContextMenuEvent( QContextMenuEvent * );
180 
181 
182     virtual void viewportPaintEvent( QPaintEvent* );
183     virtual void viewportResizeEvent( QResizeEvent* );
184     virtual void viewportMousePressEvent( QMouseEvent* );
185     virtual void viewportMouseReleaseEvent( QMouseEvent* );
186     virtual void viewportMouseDoubleClickEvent( QMouseEvent* );
187     virtual void viewportMouseMoveEvent( QMouseEvent* );
188     virtual void viewportDragEnterEvent( QDragEnterEvent * );
189     virtual void viewportDragMoveEvent( QDragMoveEvent * );
190     virtual void viewportDragLeaveEvent( QDragLeaveEvent * );
191     virtual void viewportDropEvent( QDropEvent * );
192     virtual void viewportWheelEvent( QWheelEvent * );
193     virtual void viewportContextMenuEvent( QContextMenuEvent * );
194 
195     void	frameChanged() override;
196 
197 public:
198     virtual void setMargins(int left, int top, int right, int bottom);
199     int leftMargin() const;
200     int topMargin() const;
201     int rightMargin() const;
202     int bottomMargin() const;
203 protected:
204 
205     bool focusNextPrevChild( bool next ) override;
206 
207     virtual void setHBarGeometry(QScrollBar& hbar, int x, int y, int w, int h);
208     virtual void setVBarGeometry(QScrollBar& vbar, int x, int y, int w, int h);
209 
210     void resizeEvent(QResizeEvent*) override;
211     void  mousePressEvent( QMouseEvent * ) override;
212     void  mouseReleaseEvent( QMouseEvent * ) override;
213     void  mouseDoubleClickEvent( QMouseEvent * ) override;
214     void  mouseMoveEvent( QMouseEvent * ) override;
215     void  wheelEvent( QWheelEvent * ) override;
216     void contextMenuEvent( QContextMenuEvent * ) override;
217     bool eventFilter( QObject *, QEvent *e ) override;
218 
219     void setCachedSizeHint( const QSize &sh ) const;
220     QSize cachedSizeHint() const;
221     void fontChange( const QFont & );
222 
223 private:
224     void drawContents( QPainter* ) override;
225     void moveContents(int x, int y);
226 
227     KtlQ3ScrollViewData* d;
228 
229 private Q_SLOTS:
230     void hslide(int);
231     void vslide(int);
232     void hbarIsPressed();
233     void hbarIsReleased();
234     void vbarIsPressed();
235     void vbarIsReleased();
236     void doDragAutoScroll();
237     void startDragAutoScroll();
238     void stopDragAutoScroll();
239 
240 private: // Disabled copy constructor and operator=
241     Q_DISABLE_COPY(KtlQ3ScrollView)
242     void changeFrameRect(const QRect&);
243 
244 public:
245     void disableSizeHintCaching();
246 
247 };
248 
249 
250 
251 class KtlQAbstractScrollAreaWidget : public QWidget
252 {
253     Q_OBJECT
254 
255 public:
256     KtlQAbstractScrollAreaWidget(KtlQ3ScrollView* parent = nullptr, const char* name = nullptr, Qt::WindowFlags f = {})
QWidget(parent,f)257         : QWidget(parent, f)
258     {
259         setObjectName(name);
260         setAutoFillBackground(true);
261     }
262 };
263 
264 class KtlQClipperWidget : public QWidget
265 {
266     Q_OBJECT
267 
268 public:
269     KtlQClipperWidget(QWidget * parent = nullptr, const char * name = nullptr, Qt::WindowFlags f = {})
QWidget(parent,f)270         : QWidget (parent,f) {
271             setObjectName(name);
272         }
273 };
274 
275 
276 //QT_END_NAMESPACE
277 
278 // QT_END_HEADER
279 
280 #endif // KTL_Q3SCROLLVIEW_H
281