1 /**************************************************************************** 2 ** $Id: qt/qscrollview.h 3.3.8 edited Jan 11 14:38 $ 3 ** 4 ** Definition of QScrollView class 5 ** 6 ** Created : 970523 7 ** 8 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 9 ** 10 ** This file is part of the widgets module of the Qt GUI Toolkit. 11 ** 12 ** This file may be distributed under the terms of the Q Public License 13 ** as defined by Trolltech ASA of Norway and appearing in the file 14 ** LICENSE.QPL included in the packaging of this file. 15 ** 16 ** This file may be distributed and/or modified under the terms of the 17 ** GNU General Public License version 2 as published by the Free Software 18 ** Foundation and appearing in the file LICENSE.GPL included in the 19 ** packaging of this file. 20 ** 21 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 22 ** licenses may use this file in accordance with the Qt Commercial License 23 ** Agreement provided with the Software. 24 ** 25 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 26 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 27 ** 28 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 29 ** information about Qt Commercial License Agreements. 30 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 31 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 32 ** 33 ** Contact info@trolltech.com if any conditions of this licensing are 34 ** not clear to you. 35 ** 36 **********************************************************************/ 37 #ifndef QSCROLLVIEW_H 38 #define QSCROLLVIEW_H 39 40 #ifndef QT_H 41 #include "qframe.h" 42 #include "qscrollbar.h" 43 #endif // QT_H 44 45 #ifndef QT_NO_SCROLLVIEW 46 47 class QScrollViewData; 48 49 class Q_EXPORT QScrollView : public QFrame 50 { 51 Q_OBJECT 52 Q_ENUMS( ResizePolicy ScrollBarMode ) 53 Q_PROPERTY( ResizePolicy resizePolicy READ resizePolicy WRITE setResizePolicy ) 54 Q_PROPERTY( ScrollBarMode vScrollBarMode READ vScrollBarMode WRITE setVScrollBarMode ) 55 Q_PROPERTY( ScrollBarMode hScrollBarMode READ hScrollBarMode WRITE setHScrollBarMode ) 56 Q_PROPERTY( int visibleWidth READ visibleWidth ) 57 Q_PROPERTY( int visibleHeight READ visibleHeight ) 58 Q_PROPERTY( int contentsWidth READ contentsWidth ) 59 Q_PROPERTY( int contentsHeight READ contentsHeight ) 60 Q_PROPERTY( int contentsX READ contentsX ) 61 Q_PROPERTY( int contentsY READ contentsY ) 62 #ifndef QT_NO_DRAGANDDROP 63 Q_PROPERTY( bool dragAutoScroll READ dragAutoScroll WRITE setDragAutoScroll ) 64 #endif 65 66 public: 67 QScrollView(QWidget* parent=0, const char* name=0, WFlags f=0); 68 ~QScrollView(); 69 70 enum ResizePolicy { Default, Manual, AutoOne, AutoOneFit }; 71 virtual void setResizePolicy( ResizePolicy ); 72 ResizePolicy resizePolicy() const; 73 74 void styleChange( QStyle & ); 75 void removeChild(QWidget* child); 76 virtual void addChild( QWidget* child, int x=0, int y=0 ); 77 virtual void moveChild( QWidget* child, int x, int y ); 78 int childX(QWidget* child); 79 int childY(QWidget* child); childIsVisible(QWidget * child)80 bool childIsVisible(QWidget* child) { return child->isVisible(); } // obsolete functions 81 void showChild(QWidget* child, bool yes=TRUE) { 82 if ( yes ) 83 child->show(); 84 else 85 child->hide(); 86 } 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 show(); 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; 135 QSize minimumSizeHint() const; 136 137 void removeChild(QObject* child); 138 139 bool isHorizontalSliderPressed(); 140 bool isVerticalSliderPressed(); 141 142 #ifndef QT_NO_DRAGANDDROP 143 virtual void setDragAutoScroll( bool b ); 144 bool dragAutoScroll() const; 145 #endif 146 147 signals: 148 void contentsMoving(int x, int y); 149 void horizontalSliderPressed(); 150 void horizontalSliderReleased(); 151 void verticalSliderPressed(); 152 void verticalSliderReleased(); 153 154 public slots: 155 virtual void resizeContents( int w, int h ); 156 void scrollBy( int dx, int dy ); 157 virtual void setContentsPos( int x, int y ); 158 void ensureVisible(int x, int y); 159 void ensureVisible(int x, int y, int xmargin, int ymargin); 160 void center(int x, int y); 161 void center(int x, int y, float xmargin, float ymargin); 162 163 void updateScrollBars(); // ### virtual in 4.0 164 void setEnabled( bool enable ); 165 166 protected: 167 virtual void drawContents(QPainter*, int cx, int cy, int cw, int ch); 168 virtual void drawContentsOffset(QPainter*, int ox, int oy, 169 int cx, int cy, int cw, int ch); 170 171 172 virtual void contentsMousePressEvent( QMouseEvent* ); 173 virtual void contentsMouseReleaseEvent( QMouseEvent* ); 174 virtual void contentsMouseDoubleClickEvent( QMouseEvent* ); 175 virtual void contentsMouseMoveEvent( QMouseEvent* ); 176 #ifndef QT_NO_DRAGANDDROP 177 virtual void contentsDragEnterEvent( QDragEnterEvent * ); 178 virtual void contentsDragMoveEvent( QDragMoveEvent * ); 179 virtual void contentsDragLeaveEvent( QDragLeaveEvent * ); 180 virtual void contentsDropEvent( QDropEvent * ); 181 #endif 182 #ifndef QT_NO_WHEELEVENT 183 virtual void contentsWheelEvent( QWheelEvent * ); 184 #endif 185 virtual void contentsContextMenuEvent( QContextMenuEvent * ); 186 187 188 virtual void viewportPaintEvent( QPaintEvent* ); 189 virtual void viewportResizeEvent( QResizeEvent* ); 190 virtual void viewportMousePressEvent( QMouseEvent* ); 191 virtual void viewportMouseReleaseEvent( QMouseEvent* ); 192 virtual void viewportMouseDoubleClickEvent( QMouseEvent* ); 193 virtual void viewportMouseMoveEvent( QMouseEvent* ); 194 #ifndef QT_NO_DRAGANDDROP 195 virtual void viewportDragEnterEvent( QDragEnterEvent * ); 196 virtual void viewportDragMoveEvent( QDragMoveEvent * ); 197 virtual void viewportDragLeaveEvent( QDragLeaveEvent * ); 198 virtual void viewportDropEvent( QDropEvent * ); 199 #endif 200 #ifndef QT_NO_WHEELEVENT 201 virtual void viewportWheelEvent( QWheelEvent * ); 202 #endif 203 virtual void viewportContextMenuEvent( QContextMenuEvent * ); 204 205 void frameChanged(); 206 207 virtual void setMargins(int left, int top, int right, int bottom); 208 int leftMargin() const; 209 int topMargin() const; 210 int rightMargin() const; 211 int bottomMargin() const; 212 213 bool focusNextPrevChild( bool next ); 214 215 virtual void setHBarGeometry(QScrollBar& hbar, int x, int y, int w, int h); 216 virtual void setVBarGeometry(QScrollBar& vbar, int x, int y, int w, int h); 217 218 void resizeEvent(QResizeEvent*); 219 void mousePressEvent( QMouseEvent * ); 220 void mouseReleaseEvent( QMouseEvent * ); 221 void mouseDoubleClickEvent( QMouseEvent * ); 222 void mouseMoveEvent( QMouseEvent * ); 223 #ifndef QT_NO_WHEELEVENT 224 void wheelEvent( QWheelEvent * ); 225 #endif 226 void contextMenuEvent( QContextMenuEvent * ); 227 bool eventFilter( QObject *, QEvent *e ); 228 229 void setCachedSizeHint( const QSize &sh ) const; 230 QSize cachedSizeHint() const; 231 void fontChange( const QFont & ); 232 233 private: 234 void drawContents( QPainter* ); 235 void moveContents(int x, int y); 236 237 QScrollViewData* d; 238 239 private slots: 240 void hslide(int); 241 void vslide(int); 242 void hbarIsPressed(); 243 void hbarIsReleased(); 244 void vbarIsPressed(); 245 void vbarIsReleased(); 246 #ifndef QT_NO_DRAGANDDROP 247 void doDragAutoScroll(); 248 void startDragAutoScroll(); 249 void stopDragAutoScroll(); 250 #endif 251 252 private: // Disabled copy constructor and operator= 253 #if defined(Q_DISABLE_COPY) 254 QScrollView( const QScrollView & ); 255 QScrollView &operator=( const QScrollView & ); 256 #endif 257 void changeFrameRect(const QRect&); 258 259 public: 260 void disableSizeHintCaching(); 261 262 }; 263 264 #endif // QT_NO_SCROLLVIEW 265 266 #endif // QSCROLLVIEW_H 267