1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets 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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QABSTRACTSCROLLAREA_H
41#define QABSTRACTSCROLLAREA_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtWidgets/qframe.h>
45
46QT_BEGIN_NAMESPACE
47
48
49#if QT_CONFIG(scrollarea)
50
51class QMargins;
52class QScrollBar;
53class QAbstractScrollAreaPrivate;
54
55class Q_WIDGETS_EXPORT QAbstractScrollArea : public QFrame
56{
57 Q_OBJECT
58
59 Q_PROPERTY(Qt::ScrollBarPolicy verticalScrollBarPolicy READ verticalScrollBarPolicy WRITE setVerticalScrollBarPolicy)
60 Q_PROPERTY(Qt::ScrollBarPolicy horizontalScrollBarPolicy READ horizontalScrollBarPolicy WRITE setHorizontalScrollBarPolicy)
61 Q_PROPERTY(SizeAdjustPolicy sizeAdjustPolicy READ sizeAdjustPolicy WRITE setSizeAdjustPolicy)
62
63public:
64 explicit QAbstractScrollArea(QWidget *parent = nullptr);
65 ~QAbstractScrollArea();
66
67 enum SizeAdjustPolicy {
68 AdjustIgnored,
69 AdjustToContentsOnFirstShow,
70 AdjustToContents
71 };
72 Q_ENUM(SizeAdjustPolicy)
73
74 Qt::ScrollBarPolicy verticalScrollBarPolicy() const;
75 void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy);
76 QScrollBar *verticalScrollBar() const;
77 void setVerticalScrollBar(QScrollBar *scrollbar);
78
79 Qt::ScrollBarPolicy horizontalScrollBarPolicy() const;
80 void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy);
81 QScrollBar *horizontalScrollBar() const;
82 void setHorizontalScrollBar(QScrollBar *scrollbar);
83
84 QWidget *cornerWidget() const;
85 void setCornerWidget(QWidget *widget);
86
87 void addScrollBarWidget(QWidget *widget, Qt::Alignment alignment);
88 QWidgetList scrollBarWidgets(Qt::Alignment alignment);
89
90 QWidget *viewport() const;
91 void setViewport(QWidget *widget);
92 QSize maximumViewportSize() const;
93
94 QSize minimumSizeHint() const override;
95
96 QSize sizeHint() const override;
97
98 virtual void setupViewport(QWidget *viewport);
99
100 SizeAdjustPolicy sizeAdjustPolicy() const;
101 void setSizeAdjustPolicy(SizeAdjustPolicy policy);
102
103protected:
104 QAbstractScrollArea(QAbstractScrollAreaPrivate &dd, QWidget *parent = nullptr);
105 void setViewportMargins(int left, int top, int right, int bottom);
106 void setViewportMargins(const QMargins &margins);
107 QMargins viewportMargins() const;
108
109 bool eventFilter(QObject *, QEvent *) override;
110 bool event(QEvent *) override;
111 virtual bool viewportEvent(QEvent *);
112
113 void resizeEvent(QResizeEvent *) override;
114 void paintEvent(QPaintEvent *) override;
115 void mousePressEvent(QMouseEvent *) override;
116 void mouseReleaseEvent(QMouseEvent *) override;
117 void mouseDoubleClickEvent(QMouseEvent *) override;
118 void mouseMoveEvent(QMouseEvent *) override;
119#if QT_CONFIG(wheelevent)
120 void wheelEvent(QWheelEvent *) override;
121#endif
122#ifndef QT_NO_CONTEXTMENU
123 void contextMenuEvent(QContextMenuEvent *) override;
124#endif
125#if QT_CONFIG(draganddrop)
126 void dragEnterEvent(QDragEnterEvent *) override;
127 void dragMoveEvent(QDragMoveEvent *) override;
128 void dragLeaveEvent(QDragLeaveEvent *) override;
129 void dropEvent(QDropEvent *) override;
130#endif
131
132 void keyPressEvent(QKeyEvent *) override;
133
134 virtual void scrollContentsBy(int dx, int dy);
135
136 virtual QSize viewportSizeHint() const;
137
138private:
139 Q_DECLARE_PRIVATE(QAbstractScrollArea)
140 Q_DISABLE_COPY(QAbstractScrollArea)
141 Q_PRIVATE_SLOT(d_func(), void _q_hslide(int))
142 Q_PRIVATE_SLOT(d_func(), void _q_vslide(int))
143 Q_PRIVATE_SLOT(d_func(), void _q_showOrHideScrollBars())
144
145 friend class QStyleSheetStyle;
146 friend class QWidgetPrivate;
147};
148
149#endif // QT_CONFIG(scrollarea)
150
151QT_END_NAMESPACE
152
153#endif // QABSTRACTSCROLLAREA_H
154

source code of qtbase/src/widgets/widgets/qabstractscrollarea.h