File indexing completed on 2024-12-01 05:12:52
0001 /**************************************************************************** 0002 ** 0003 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 0004 ** Contact: http://www.qt-project.org/legal 0005 ** 0006 ** This file is part of the Qt3Support module of the Qt Toolkit. 0007 ** 0008 ** $QT_BEGIN_LICENSE:LGPL$ 0009 ** Commercial License Usage 0010 ** Licensees holding valid commercial Qt licenses may use this file in 0011 ** accordance with the commercial license agreement provided with the 0012 ** Software or, alternatively, in accordance with the terms contained in 0013 ** a written agreement between you and Digia. For licensing terms and 0014 ** conditions see http://qt.digia.com/licensing. For further information 0015 ** use the contact form at http://qt.digia.com/contact-us. 0016 ** 0017 ** GNU Lesser General Public License Usage 0018 ** Alternatively, this file may be used under the terms of the GNU Lesser 0019 ** General Public License version 2.1 as published by the Free Software 0020 ** Foundation and appearing in the file LICENSE.LGPL included in the 0021 ** packaging of this file. Please review the following information to 0022 ** ensure the GNU Lesser General Public License version 2.1 requirements 0023 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 0024 ** 0025 ** In addition, as a special exception, Digia gives you certain additional 0026 ** rights. These rights are described in the Digia Qt LGPL Exception 0027 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 0028 ** 0029 ** GNU General Public License Usage 0030 ** Alternatively, this file may be used under the terms of the GNU 0031 ** General Public License version 3.0 as published by the Free Software 0032 ** Foundation and appearing in the file LICENSE.GPL included in the 0033 ** packaging of this file. Please review the following information to 0034 ** ensure the GNU General Public License version 3.0 requirements will be 0035 ** met: http://www.gnu.org/copyleft/gpl.html. 0036 ** 0037 ** 0038 ** $QT_END_LICENSE$ 0039 ** 0040 ****************************************************************************/ 0041 0042 #ifndef KTL_Q3SCROLLVIEW_H 0043 #define KTL_Q3SCROLLVIEW_H 0044 0045 #include <QScrollBar> 0046 #include <ktlqt3support/ktlq3frame.h> 0047 0048 // QT_BEGIN_HEADER 0049 0050 // QT_BEGIN_NAMESPACE 0051 0052 // QT_MODULE(Qt3SupportLight) 0053 0054 class KtlQ3ScrollViewData; 0055 0056 class KtlQ3ScrollView : public KtlQ3Frame 0057 { 0058 Q_OBJECT 0059 Q_ENUMS(ResizePolicy ScrollBarMode) 0060 Q_PROPERTY(ResizePolicy resizePolicy READ resizePolicy WRITE setResizePolicy) 0061 Q_PROPERTY(ScrollBarMode vScrollBarMode READ vScrollBarMode WRITE setVScrollBarMode) 0062 Q_PROPERTY(ScrollBarMode hScrollBarMode READ hScrollBarMode WRITE setHScrollBarMode) 0063 Q_PROPERTY(int visibleWidth READ visibleWidth) 0064 Q_PROPERTY(int visibleHeight READ visibleHeight) 0065 Q_PROPERTY(int contentsWidth READ contentsWidth) 0066 Q_PROPERTY(int contentsHeight READ contentsHeight) 0067 Q_PROPERTY(int contentsX READ contentsX) 0068 Q_PROPERTY(int contentsY READ contentsY) 0069 Q_PROPERTY(bool dragAutoScroll READ dragAutoScroll WRITE setDragAutoScroll) 0070 0071 public: 0072 KtlQ3ScrollView(QWidget *parent = nullptr, const char *name = nullptr, Qt::WindowFlags f = {}); 0073 ~KtlQ3ScrollView() override; 0074 0075 enum ResizePolicy { Default, Manual, AutoOne, AutoOneFit }; 0076 virtual void setResizePolicy(ResizePolicy); 0077 ResizePolicy resizePolicy() const; 0078 0079 void styleChange(QStyle &); 0080 void removeChild(QWidget *child); 0081 virtual void addChild(QWidget *child, int x = 0, int y = 0); 0082 virtual void moveChild(QWidget *child, int x, int y); 0083 int childX(QWidget *child); 0084 int childY(QWidget *child); 0085 bool childIsVisible(QWidget *child) 0086 { 0087 return child->isVisible(); 0088 } // obsolete functions 0089 void showChild(QWidget *child, bool yes = true) 0090 { 0091 child->setVisible(yes); 0092 } 0093 0094 enum ScrollBarMode { Auto, AlwaysOff, AlwaysOn }; 0095 0096 ScrollBarMode vScrollBarMode() const; 0097 virtual void setVScrollBarMode(ScrollBarMode); 0098 0099 ScrollBarMode hScrollBarMode() const; 0100 virtual void setHScrollBarMode(ScrollBarMode); 0101 0102 QWidget *cornerWidget() const; 0103 virtual void setCornerWidget(QWidget *); 0104 0105 // ### 4.0: Consider providing a factory function for scrollbars 0106 // (e.g. make the two following functions virtual) 0107 QScrollBar *horizontalScrollBar() const; 0108 QScrollBar *verticalScrollBar() const; 0109 QWidget *viewport() const; 0110 QWidget *clipper() const; 0111 0112 int visibleWidth() const; 0113 int visibleHeight() const; 0114 0115 int contentsWidth() const; 0116 int contentsHeight() const; 0117 int contentsX() const; 0118 int contentsY() const; 0119 0120 void resize(int w, int h); 0121 void resize(const QSize &); 0122 void setVisible(bool visible) override; 0123 0124 void updateContents(int x, int y, int w, int h); 0125 void updateContents(const QRect &r); 0126 void updateContents(); 0127 void repaintContents(int x, int y, int w, int h, bool erase = true); 0128 void repaintContents(const QRect &r, bool erase = true); 0129 void repaintContents(bool erase = true); 0130 void contentsToViewport(int x, int y, int &vx, int &vy) const; 0131 void viewportToContents(int vx, int vy, int &x, int &y) const; 0132 QPoint contentsToViewport(const QPoint &) const; 0133 QPoint viewportToContents(const QPoint &) const; 0134 void enableClipper(bool y); 0135 0136 void setStaticBackground(bool y); 0137 bool hasStaticBackground() const; 0138 0139 QSize viewportSize(int, int) const; 0140 QSize sizeHint() const override; 0141 QSize minimumSizeHint() const override; 0142 0143 void removeChild(QObject *child); 0144 0145 bool isHorizontalSliderPressed(); 0146 bool isVerticalSliderPressed(); 0147 0148 virtual void setDragAutoScroll(bool b); 0149 bool dragAutoScroll() const; 0150 0151 Q_SIGNALS: 0152 void contentsMoving(int x, int y); 0153 void horizontalSliderPressed(); 0154 void horizontalSliderReleased(); 0155 void verticalSliderPressed(); 0156 void verticalSliderReleased(); 0157 0158 public Q_SLOTS: 0159 virtual void resizeContents(int w, int h); 0160 void scrollBy(int dx, int dy); 0161 virtual void setContentsPos(int x, int y); 0162 void ensureVisible(int x, int y); 0163 void ensureVisible(int x, int y, int xmargin, int ymargin); 0164 void center(int x, int y); 0165 void center(int x, int y, float xmargin, float ymargin); 0166 0167 void updateScrollBars(); // ### virtual in 4.0 0168 void setEnabled(bool enable); 0169 0170 protected: 0171 virtual void drawContents(QPainter *, int cx, int cy, int cw, int ch); 0172 virtual void drawContentsOffset(QPainter *, int ox, int oy, int cx, int cy, int cw, int ch); 0173 0174 virtual void contentsMousePressEvent(QMouseEvent *); 0175 virtual void contentsMouseReleaseEvent(QMouseEvent *); 0176 virtual void contentsMouseDoubleClickEvent(QMouseEvent *); 0177 virtual void contentsMouseMoveEvent(QMouseEvent *); 0178 virtual void contentsDragEnterEvent(QDragEnterEvent *); 0179 virtual void contentsDragMoveEvent(QDragMoveEvent *); 0180 virtual void contentsDragLeaveEvent(QDragLeaveEvent *); 0181 virtual void contentsDropEvent(QDropEvent *); 0182 virtual void contentsWheelEvent(QWheelEvent *); 0183 virtual void contentsContextMenuEvent(QContextMenuEvent *); 0184 0185 virtual void viewportPaintEvent(QPaintEvent *); 0186 virtual void viewportResizeEvent(QResizeEvent *); 0187 virtual void viewportMousePressEvent(QMouseEvent *); 0188 virtual void viewportMouseReleaseEvent(QMouseEvent *); 0189 virtual void viewportMouseDoubleClickEvent(QMouseEvent *); 0190 virtual void viewportMouseMoveEvent(QMouseEvent *); 0191 virtual void viewportDragEnterEvent(QDragEnterEvent *); 0192 virtual void viewportDragMoveEvent(QDragMoveEvent *); 0193 virtual void viewportDragLeaveEvent(QDragLeaveEvent *); 0194 virtual void viewportDropEvent(QDropEvent *); 0195 virtual void viewportWheelEvent(QWheelEvent *); 0196 virtual void viewportContextMenuEvent(QContextMenuEvent *); 0197 0198 void frameChanged() override; 0199 0200 public: 0201 virtual void setMargins(int left, int top, int right, int bottom); 0202 int leftMargin() const; 0203 int topMargin() const; 0204 int rightMargin() const; 0205 int bottomMargin() const; 0206 0207 protected: 0208 bool focusNextPrevChild(bool next) override; 0209 0210 virtual void setHBarGeometry(QScrollBar &hbar, int x, int y, int w, int h); 0211 virtual void setVBarGeometry(QScrollBar &vbar, int x, int y, int w, int h); 0212 0213 void resizeEvent(QResizeEvent *) override; 0214 void mousePressEvent(QMouseEvent *) override; 0215 void mouseReleaseEvent(QMouseEvent *) override; 0216 void mouseDoubleClickEvent(QMouseEvent *) override; 0217 void mouseMoveEvent(QMouseEvent *) override; 0218 void wheelEvent(QWheelEvent *) override; 0219 void contextMenuEvent(QContextMenuEvent *) override; 0220 bool eventFilter(QObject *, QEvent *e) override; 0221 0222 void setCachedSizeHint(const QSize &sh) const; 0223 QSize cachedSizeHint() const; 0224 void fontChange(const QFont &); 0225 0226 private: 0227 void drawContents(QPainter *) override; 0228 void moveContents(int x, int y); 0229 0230 KtlQ3ScrollViewData *d; 0231 0232 private Q_SLOTS: 0233 void hslide(int); 0234 void vslide(int); 0235 void hbarIsPressed(); 0236 void hbarIsReleased(); 0237 void vbarIsPressed(); 0238 void vbarIsReleased(); 0239 void doDragAutoScroll(); 0240 void startDragAutoScroll(); 0241 void stopDragAutoScroll(); 0242 0243 private: // Disabled copy constructor and operator= 0244 Q_DISABLE_COPY(KtlQ3ScrollView) 0245 void changeFrameRect(const QRect &); 0246 0247 public: 0248 void disableSizeHintCaching(); 0249 }; 0250 0251 class KtlQAbstractScrollAreaWidget : public QWidget 0252 { 0253 Q_OBJECT 0254 0255 public: 0256 KtlQAbstractScrollAreaWidget(KtlQ3ScrollView *parent = nullptr, const char *name = nullptr, Qt::WindowFlags f = {}) 0257 : QWidget(parent, f) 0258 { 0259 setObjectName(name); 0260 setAutoFillBackground(true); 0261 } 0262 }; 0263 0264 class KtlQClipperWidget : public QWidget 0265 { 0266 Q_OBJECT 0267 0268 public: 0269 KtlQClipperWidget(QWidget *parent = nullptr, const char *name = nullptr, Qt::WindowFlags f = {}) 0270 : QWidget(parent, f) 0271 { 0272 setObjectName(name); 0273 } 0274 }; 0275 0276 // QT_END_NAMESPACE 0277 0278 // QT_END_HEADER 0279 0280 #endif // KTL_Q3SCROLLVIEW_H