6#if QT_CONFIG(scrollarea)
17#if QT_CONFIG(itemviews)
27#include <private/qapplication_p.h>
129QAbstractScrollAreaPrivate::QAbstractScrollAreaPrivate()
131 shownOnce(
false), inResize(
false), sizeAdjustPolicy(QAbstractScrollArea::AdjustIgnored),
137QAbstractScrollAreaPrivate::~QAbstractScrollAreaPrivate()
144 orientation(orientation)
166 const int insertIndex = (
position & LogicalLeft) ? 0 : scrollBarLayoutIndex() + 1;
177 const int scrollBarIndex = scrollBarLayoutIndex();
180 for (
int i = 0;
i < scrollBarIndex; ++
i)
182 }
else if (
position == LogicalRight) {
184 list.
reserve(layoutItemCount - (scrollBarIndex + 1));
185 for (
int i = scrollBarIndex + 1;
i < layoutItemCount; ++
i)
197int QAbstractScrollAreaScrollBarContainer::scrollBarLayoutIndex()
const
200 for (
int i = 0;
i < layoutItemCount; ++
i) {
212 Q_Q(QAbstractScrollArea);
214 QAbstractScrollAreaScrollBarContainer *container = scrollBarContainers[orientation];
216 QScrollBar *oldBar = horizontal ? hbar : vbar;
224 container->layout->insertWidget(0,
scrollBar);
232 scrollBar->d_func()->viewMayChangeSingleStep = oldBar->d_func()->viewMayChangeSingleStep;
242 q, horizontal ?
SLOT(_q_hslide(
int)) :
SLOT(_q_vslide(int)));
247void QAbstractScrollAreaPrivate::init()
249 Q_Q(QAbstractScrollArea);
251 viewport->setObjectName(
"qt_scrollarea_viewport"_L1);
253 viewport->setAutoFillBackground(
true);
255 scrollBarContainers[
Qt::Horizontal]->setObjectName(
"qt_scrollarea_hcontainer"_L1);
259 hbar->installEventFilter(
q);
263 scrollBarContainers[
Qt::Vertical]->setObjectName(
"qt_scrollarea_vcontainer"_L1);
267 vbar->installEventFilter(
q);
270 viewportFilter.reset(
new QAbstractScrollAreaFilter(
this));
271 viewport->installEventFilter(viewportFilter.data());
278# ifndef QT_NO_GESTURES
284void QAbstractScrollAreaPrivate::layoutChildren()
288 layoutChildren_helper(&needH, &needV);
292 layoutChildren_helper(&needH, &needV);
295void QAbstractScrollAreaPrivate::layoutChildren_helper(
bool *needHorizontalScrollbar,
bool *needVerticalScrollbar)
297 Q_Q(QAbstractScrollArea);
298 QStyleOptionSlider barOpt;
300 hbar->initStyleOption(&barOpt);
304 && hbar->minimum() < hbar->maximum() && !hbar->sizeHint().isEmpty())));
307 vbar->initStyleOption(&barOpt);
311 && vbar->minimum() < vbar->maximum() && !vbar->sizeHint().isEmpty())));
317 const int hsbExt = hbar->sizeHint().height();
318 const int vsbExt = vbar->sizeHint().width();
319 const QPoint extPoint(vsbExt, hsbExt);
320 const QSize extSize(vsbExt, hsbExt);
322 const QRect widgetRect =
q->rect();
324 const bool hasCornerWidget = (cornerWidget !=
nullptr);
326 QPoint cornerOffset((needv && vscrollOverlap == 0) ? vsbExt : 0, (needh && hscrollOverlap == 0) ? hsbExt : 0);
334 controlsRect = widgetRect;
336 const QPoint cornerExtra(needv ?
spacing + vscrollOverlap : 0, needh ?
spacing + hscrollOverlap : 0);
337 QRect frameRect = widgetRect;
338 frameRect.
adjust(0, 0, -cornerOffset.
x() - cornerExtra.
x(), -cornerOffset.
y() - cornerExtra.
y());
346 controlsRect =
q->contentsRect();
350 cornerOffset =
QPoint(needv ? vsbExt : 0, needh ? hsbExt : 0);
354 if (hasCornerWidget && ((needv && vscrollOverlap == 0) || (needh && hscrollOverlap == 0)))
355 cornerOffset = extPoint;
363 if (needv && needh && !hasCornerWidget && hscrollOverlap == 0 && vscrollOverlap == 0)
366 cornerPaintingRect =
QRect();
369 int vHeaderRight = 0;
370 int hHeaderBottom = 0;
371#if QT_CONFIG(itemviews)
372 if ((vscrollOverlap > 0 && needv) || (hscrollOverlap > 0 && needh)) {
374 if (headers.
size() <= 2) {
380 hHeaderBottom = geo.
bottom();
386 QRect horizontalScrollBarRect(
QPoint(controlsRect.
left() + vHeaderRight, cornerPoint.y()),
QPoint(cornerPoint.x() - 1, controlsRect.
bottom()));
388 if (!hasCornerWidget && htransient)
389 horizontalScrollBarRect.adjust(0, 0, cornerOffset.
x(), 0);
395 QRect verticalScrollBarRect (
QPoint(cornerPoint.x(), controlsRect.
top() + hHeaderBottom),
QPoint(controlsRect.
right(), cornerPoint.y() - 1));
396 if (!hasCornerWidget && vtransient)
397 verticalScrollBarRect.adjust(0, 0, 0, cornerOffset.
y());
410 if (
q->isRightToLeft())
416 viewport->setGeometry(viewportRect);
418 *needHorizontalScrollbar = needh;
419 *needVerticalScrollbar = needv;
440QAbstractScrollArea::QAbstractScrollArea(QAbstractScrollAreaPrivate &dd,
QWidget *
parent)
443 Q_D(QAbstractScrollArea);
447 d->viewportFilter.reset();
460 Q_D(QAbstractScrollArea);
464 d->viewportFilter.reset();
473QAbstractScrollArea::~QAbstractScrollArea()
475 Q_D(QAbstractScrollArea);
477 d->viewportFilter.reset();
493 Q_D(QAbstractScrollArea);
499 d->viewport->setParent(
this);
500 d->viewport->setFocusProxy(
this);
501 d->viewport->installEventFilter(
d->viewportFilter.data());
502#ifndef QT_NO_GESTURES
524QWidget *QAbstractScrollArea::viewport()
const
526 Q_D(
const QAbstractScrollArea);
535QSize QAbstractScrollArea::maximumViewportSize()
const
537 Q_D(
const QAbstractScrollArea);
538 int f = 2 *
d->frameWidth;
542 max.
rwidth() -=
d->vbar->sizeHint().width();
544 max.
rheight() -=
d->hbar->sizeHint().height();
559 Q_D(
const QAbstractScrollArea);
560 return d->vbarpolicy;
565 Q_D(QAbstractScrollArea);
570 if (oldPolicy !=
d->vbarpolicy)
580QScrollBar *QAbstractScrollArea::verticalScrollBar()
const
582 Q_D(
const QAbstractScrollArea);
600 Q_D(QAbstractScrollArea);
602 qWarning(
"QAbstractScrollArea::setVerticalScrollBar: Cannot set a null scroll bar");
620 Q_D(
const QAbstractScrollArea);
621 return d->hbarpolicy;
626 Q_D(QAbstractScrollArea);
631 if (oldPolicy !=
d->hbarpolicy)
640QScrollBar *QAbstractScrollArea::horizontalScrollBar()
const
642 Q_D(
const QAbstractScrollArea);
661 Q_D(QAbstractScrollArea);
663 qWarning(
"QAbstractScrollArea::setHorizontalScrollBar: Cannot set a null scroll bar");
677QWidget *QAbstractScrollArea::cornerWidget()
const
679 Q_D(
const QAbstractScrollArea);
680 return d->cornerWidget;
711 Q_D(QAbstractScrollArea);
712 QWidget* oldWidget =
d->cornerWidget;
713 if (oldWidget !=
widget) {
764 Q_D(QAbstractScrollArea);
771 const QAbstractScrollAreaScrollBarContainer::LogicalPosition
position
773 ? QAbstractScrollAreaScrollBarContainer::LogicalRight : QAbstractScrollAreaScrollBarContainer::LogicalLeft;
774 d->scrollBarContainers[scrollBarOrientation]->addWidget(
widget,
position);
776 if (isHidden() ==
false)
789 Q_D(QAbstractScrollArea);
794 list +=
d->scrollBarContainers[
Qt::Horizontal]->widgets(QAbstractScrollAreaScrollBarContainer::LogicalLeft);
796 list +=
d->scrollBarContainers[
Qt::Horizontal]->widgets(QAbstractScrollAreaScrollBarContainer::LogicalRight);
798 list +=
d->scrollBarContainers[
Qt::Vertical]->widgets(QAbstractScrollAreaScrollBarContainer::LogicalLeft);
800 list +=
d->scrollBarContainers[
Qt::Vertical]->widgets(QAbstractScrollAreaScrollBarContainer::LogicalRight);
821 Q_D(QAbstractScrollArea);
839void QAbstractScrollArea::setViewportMargins(
const QMargins &margins)
841 setViewportMargins(margins.
left(), margins.
top(),
852QMargins QAbstractScrollArea::viewportMargins()
const
854 Q_D(
const QAbstractScrollArea);
861 Q_D(QAbstractScrollArea);
886bool QAbstractScrollArea::event(
QEvent *
e)
888 Q_D(QAbstractScrollArea);
897 d->viewport->setAcceptDrops(acceptDrops());
900 d->viewport->setMouseTracking(hasMouseTracking());
910 if (!
d->shownOnce &&
d->sizeAdjustPolicy == QAbstractScrollArea::AdjustToContentsOnFirstShow) {
919 if (
d->cornerPaintingRect.isValid()) {
920 option.rect =
d->cornerPaintingRect;
927#ifndef QT_NO_CONTEXTMENU
939#if QT_CONFIG(draganddrop)
950#ifndef QT_NO_GESTURES
962 int newX = hBar->
value() - delta.
x();
963 int newY = vBar->
value() - delta.
y();
1008 d->layoutChildren();
1036bool QAbstractScrollArea::viewportEvent(
QEvent *
e)
1038 switch (
e->type()) {
1049#if QT_CONFIG(wheelevent)
1052#if QT_CONFIG(draganddrop)
1066#ifndef QT_NO_GESTURES
1121void QAbstractScrollArea::mousePressEvent(
QMouseEvent *
e)
1133void QAbstractScrollArea::mouseReleaseEvent(
QMouseEvent *
e)
1145void QAbstractScrollArea::mouseDoubleClickEvent(
QMouseEvent *
e)
1157void QAbstractScrollArea::mouseMoveEvent(
QMouseEvent *
e)
1169#if QT_CONFIG(wheelevent)
1170void QAbstractScrollArea::wheelEvent(QWheelEvent *
e)
1172 Q_D(QAbstractScrollArea);
1173 if (
qAbs(
e->angleDelta().x()) >
qAbs(
e->angleDelta().y()))
1180#ifndef QT_NO_CONTEXTMENU
1199void QAbstractScrollArea::keyPressEvent(
QKeyEvent *
e)
1201 Q_D(QAbstractScrollArea);
1203#ifndef QT_NO_SHORTCUT
1210#ifdef QT_KEYPAD_NAVIGATION
1211 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
1224#ifdef QT_KEYPAD_NAVIGATION
1225 if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()
1226 && (!
d->hbar->isVisible() ||
d->hbar->value() ==
d->hbar->minimum())) {
1232 d->hbar->triggerAction(
1237#ifdef QT_KEYPAD_NAVIGATION
1238 if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()
1239 && (!
d->hbar->isVisible() ||
d->hbar->value() ==
d->hbar->maximum())) {
1245 d->hbar->triggerAction(
1258#if QT_CONFIG(draganddrop)
1267void QAbstractScrollArea::dragEnterEvent(QDragEnterEvent *)
1279void QAbstractScrollArea::dragMoveEvent(QDragMoveEvent *)
1291void QAbstractScrollArea::dragLeaveEvent(QDragLeaveEvent *)
1303void QAbstractScrollArea::dropEvent(QDropEvent *)
1328void QAbstractScrollArea::scrollContentsBy(
int,
int)
1333bool QAbstractScrollAreaPrivate::canStartScrollingAt(
const QPoint &startPos)
const
1335 Q_Q(
const QAbstractScrollArea);
1338 if (qobject_cast<QAbstractSlider *>(
q->viewport()->childAt(startPos)))
1344void QAbstractScrollAreaPrivate::flashScrollBars()
1346 QStyleOptionSlider
opt;
1347 hbar->initStyleOption(&
opt);
1351 hbar->d_func()->flash();
1352 vbar->initStyleOption(&
opt);
1355 vbar->d_func()->flash();
1358void QAbstractScrollAreaPrivate::setScrollBarTransient(
QScrollBar *
scrollBar,
bool transient)
1360 scrollBar->d_func()->setTransient(transient);
1363void QAbstractScrollAreaPrivate::_q_hslide(
int x)
1365 Q_Q(QAbstractScrollArea);
1368 q->scrollContentsBy(dx, 0);
1372void QAbstractScrollAreaPrivate::_q_vslide(
int y)
1374 Q_Q(QAbstractScrollArea);
1377 q->scrollContentsBy(0, dy);
1381void QAbstractScrollAreaPrivate::_q_showOrHideScrollBars()
1386QPoint QAbstractScrollAreaPrivate::contentsOffset()
const
1388 Q_Q(
const QAbstractScrollArea);
1390 if (vbar->isVisible())
1391 offset.setY(vbar->value());
1392 if (hbar->isVisible()) {
1393 if (
q->isRightToLeft())
1394 offset.setX(hbar->maximum() - hbar->value());
1396 offset.setX(hbar->value());
1405QSize QAbstractScrollArea::minimumSizeHint()
const
1407 Q_D(
const QAbstractScrollArea);
1408 int hsbExt =
d->hbar->sizeHint().height();
1409 int vsbExt =
d->vbar->sizeHint().width();
1410 int extra = 2 *
d->frameWidth;
1418 d->scrollBarContainers[
Qt::Vertical]->sizeHint().height() + hsbExt + extra);
1426QSize QAbstractScrollArea::sizeHint()
const
1428 Q_D(
const QAbstractScrollArea);
1429 if (
d->sizeAdjustPolicy == QAbstractScrollArea::AdjustIgnored)
1430 return QSize(256, 192);
1432 if (!
d->sizeHint.isValid() ||
d->sizeAdjustPolicy == QAbstractScrollArea::AdjustToContents) {
1433 const int f = 2 *
d->frameWidth;
1437 const QSize scrollbars(vbarHidden ? 0 :
d->vbar->sizeHint().
width(),
1438 hbarHidden ? 0 :
d->hbar->sizeHint().
height());
1439 d->sizeHint =
frame + scrollbars + viewportSizeHint();
1450QSize QAbstractScrollArea::viewportSizeHint()
const
1452 Q_D(
const QAbstractScrollArea);
1454 const QSize sh =
d->viewport->sizeHint();
1473QAbstractScrollArea::SizeAdjustPolicy QAbstractScrollArea::sizeAdjustPolicy()
const
1475 Q_D(
const QAbstractScrollArea);
1476 return d->sizeAdjustPolicy;
1479void QAbstractScrollArea::setSizeAdjustPolicy(SizeAdjustPolicy
policy)
1481 Q_D(QAbstractScrollArea);
1482 if (
d->sizeAdjustPolicy ==
policy)
1505#include "moc_qabstractscrollarea.cpp"
1506#include "moc_qabstractscrollarea_p.cpp"
bool invertedControls
whether or not the slider inverts its wheel and key events.
void setInvertedControls(bool)
int value
the slider's current value
void setTracking(bool enable)
void setInvertedAppearance(bool)
bool isSliderDown() const
int pageStep
the page step.
void setOrientation(Qt::Orientation)
Qt::Orientation orientation
the orientation of the slider
int sliderPosition
the current slider position
int singleStep
the single step.
bool invertedAppearance
whether or not a slider shows its values inverted.
int minimum
the sliders's minimum value
void setRange(int min, int max)
Sets the slider's minimum to min and its maximum to max.
void setSliderPosition(int)
int maximum
the slider's maximum value
The QBoxLayout class lines up child widgets horizontally or vertically.
int count() const override
\reimp
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.
QLayoutItem * itemAt(int) const override
\reimp
void insertWidget(int index, QWidget *widget, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Inserts widget at position index, with stretch factor stretch and alignment alignment.
void setSpacing(int spacing) override
Reimplements QLayout::setSpacing().
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
@ ApplicationLayoutDirectionChange
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
The QFrame class is the base class of widgets that can have a frame.
bool event(QEvent *e) override
\reimp
void paintEvent(QPaintEvent *) override
\reimp
The QGestureEvent class provides the description of triggered gestures.
QGesture * gesture(Qt::GestureType type) const
Returns a gesture object by type.
static bool isRightToLeft()
Returns true if the application's layout direction is Qt::RightToLeft; otherwise returns false.
The QKeyEvent class describes a key event.
virtual QWidget * widget() const
If this item manages a QWidget, returns that widget.
void removeWidget(QWidget *w)
Removes the widget widget from the layout.
void setSizeConstraint(SizeConstraint)
void setContentsMargins(int left, int top, int right, int bottom)
qsizetype size() const noexcept
void reserve(qsizetype size)
void append(parameter_type t)
constexpr int bottom() const noexcept
Returns the bottom margin.
constexpr int left() const noexcept
Returns the left margin.
constexpr int right() const noexcept
Returns the right margin.
constexpr int top() const noexcept
Returns the top margin.
void installEventFilter(QObject *filterObj)
Installs an event filter filterObj on this object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
virtual bool eventFilter(QObject *watched, QEvent *event)
Filters events if this object has been installed as an event filter for the watched object.
void removeEventFilter(QObject *obj)
Removes an event filter object obj from this object.
The QPaintEvent class contains event parameters for paint events.
The QPainter class performs low-level painting on widgets and other paint devices.
The QPanGesture class describes a panning gesture made by the user.\inmodule QtWidgets.
\inmodule QtCore\reentrant
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
constexpr qreal & rx() noexcept
Returns a reference to the x coordinate of this point.
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
bool isNull() const noexcept
Returns true if both the x and y coordinates are set to 0.0 (ignoring the sign); otherwise returns fa...
\inmodule QtCore\reentrant
constexpr bool isNull() const noexcept
Returns true if both the x and y coordinates are set to 0, otherwise returns false.
constexpr int x() const noexcept
Returns the x coordinate of this point.
constexpr int y() const noexcept
Returns the y coordinate of this point.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr void translate(int dx, int dy) noexcept
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position.
constexpr QPoint bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
The QResizeEvent class contains event parameters for resize events.
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
constexpr void setHorizontalPolicy(Policy d) noexcept
Sets the horizontal component to the given policy.
constexpr void setVerticalPolicy(Policy d) noexcept
Sets the vertical component to the given policy.
constexpr int & rheight() noexcept
Returns a reference to the height.
constexpr int & rwidth() noexcept
Returns a reference to the width.
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
The QStyleOption class stores the parameters used by QStyle functions.
void initFrom(const QWidget *w)
Qt::LayoutDirection direction
@ SH_ScrollView_FrameOnlyAroundContents
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction.
@ PM_ScrollView_ScrollBarOverlap
@ PM_ScrollView_ScrollBarSpacing
@ PE_PanelScrollAreaCorner
Combined button and popup list for selecting options.
static QString header(const QString &name)
constexpr const T & qMax(const T &a, const T &b)
constexpr T qAbs(const T &t)
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLint GLint GLint yoffset
GLenum GLuint GLintptr offset
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
view viewport() -> scroll(dx, dy, deviceRect)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent