Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcolumnviewgrip.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qcolumnviewgrip_p.h"
5#include <qstyleoption.h>
6#include <qpainter.h>
7#include <qbrush.h>
8#include <qevent.h>
9#include <qdebug.h>
10
12
13/*
14 \internal
15 class QColumnViewGrip
16
17 QColumnViewGrip is created to go inside QAbstractScrollArea's corner.
18 When the mouse it moved it will resize the scroll area and emit's a signal.
19 */
20
21/*
22 \internal
23 \fn void QColumnViewGrip::gripMoved()
24 Signal that is emitted when the grip moves the parent widget.
25 */
26
32 : QWidget(*new QColumnViewGripPrivate, parent, { })
33{
34#ifndef QT_NO_CURSOR
36#endif
37}
38
43: QWidget(dd, parent, f)
44{
45}
46
53
59{
61
62 // first resize the parent
63 int oldWidth = parentWidget->width();
64 int newWidth = oldWidth;
65 if (isRightToLeft())
66 newWidth -= offset;
67 else
68 newWidth += offset;
69 newWidth = qMax(parentWidget->minimumWidth(), newWidth);
71
72 // Then have the view move the widget
73 int realOffset = parentWidget->width() - oldWidth;
74 int oldX = parentWidget->x();
75 if (realOffset != 0)
76 emit gripMoved(realOffset);
77 if (isRightToLeft())
78 realOffset = -1 * (oldX - parentWidget->x());
79 return realOffset;
80}
81
93
99{
103 if (isRightToLeft())
104 offset *= -1;
106 event->accept();
107}
108
114{
115 Q_D(QColumnViewGrip);
116 d->originalXLocation = event->globalPosition().toPoint().x();
117 event->accept();
118}
119
125{
126 Q_D(QColumnViewGrip);
127 int offset = event->globalPosition().toPoint().x() - d->originalXLocation;
128 d->originalXLocation = moveGrip(offset) + d->originalXLocation;
129 event->accept();
130}
131
137{
138 Q_D(QColumnViewGrip);
139 d->originalXLocation = -1;
140 event->accept();
141}
142
143/*
144 * private object implementation
145 */
148originalXLocation(-1)
149{
150}
151
153
154#include "moc_qcolumnviewgrip_p.cpp"
void mouseDoubleClickEvent(QMouseEvent *event) override
\reimp Resize the parent window to the sizeHint
void mousePressEvent(QMouseEvent *event) override
\reimp Begin watching for mouse movements
~QColumnViewGrip()
Destroys the view.
int moveGrip(int offset)
Attempt to resize the parent object by offset returns the amount of offset that it was actually able ...
void mouseReleaseEvent(QMouseEvent *event) override
\reimp Stop watching for mouse movements
void gripMoved(int offset)
void paintEvent(QPaintEvent *event) override
\reimp
void mouseMoveEvent(QMouseEvent *event) override
\reimp Calculate the movement of the grip and moveGrip() and emit gripMoved
QColumnViewGrip(QWidget *parent=nullptr)
Creates a new QColumnViewGrip with the given parent to view a model.
\inmodule QtGui
Definition qevent.h:196
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
The QStyleOption class stores the parameters used by QStyle functions.
void initFrom(const QWidget *w)
@ CE_ColumnViewGrip
Definition qstyle.h:228
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0
Draws the given element with the provided painter with the style options specified by option.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
int minimumWidth
the widget's minimum width in pixels
Definition qwidget.h:123
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
int x
the x coordinate of the widget relative to its parent including any window frame
Definition qwidget.h:109
QSize sizeHint
the recommended size for the widget
Definition qwidget.h:148
bool isRightToLeft() const
Definition qwidget.h:419
QStyle * style() const
Definition qwidget.cpp:2600
void resize(int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:883
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
QStyleOptionButton opt
Combined button and popup list for selecting options.
@ SplitHCursor
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLfloat GLfloat f
GLenum GLuint GLintptr offset
struct _cl_event * event
#define emit
#define Q_UNUSED(x)
item setCursor(Qt::IBeamCursor)
[1]
QPainter painter(this)
[7]