Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
// Qt-Security score:significant reason:default
4
5
#
include
"qcolumnviewgrip_p.h"
6
#
include
<
qstyleoption
.
h
>
7
#
include
<
qpainter
.
h
>
8
#
include
<
qbrush
.
h
>
9
#
include
<
qevent
.
h
>
10
#
include
<
qdebug
.
h
>
11
12
QT_BEGIN_NAMESPACE
13
14
/*
15
\internal
16
\fn void QColumnViewGrip::gripMoved()
17
Signal that is emitted when the grip moves the parent widget.
18
*/
19
20
/*!
21
\class QColumnViewGrip
22
\inmodule QtWidgets
23
\internal
24
25
QColumnViewGrip is created to go inside QAbstractScrollArea's corner.
26
When the mouse is moved it will resize the scroll area and emit a signal.
27
28
Creates a new QColumnViewGrip with the given \a parent to view a model.
29
Use setModel() to set the model.
30
*/
31
QColumnViewGrip::QColumnViewGrip(QWidget *parent)
32
: QWidget(*
new
QColumnViewGripPrivate, parent, { })
33
{
34
#
ifndef
QT_NO_CURSOR
35
setCursor(Qt::SplitHCursor);
36
#
endif
37
}
38
39
/*!
40
\internal
41
*/
42
QColumnViewGrip::QColumnViewGrip(QColumnViewGripPrivate & dd, QWidget *parent, Qt::WindowFlags f)
43
: QWidget(dd, parent, f)
44
{
45
}
46
47
/*!
48
Destroys the view.
49
*/
50
QColumnViewGrip::~QColumnViewGrip()
51
{
52
}
53
54
/*!
55
Attempt to resize the parent object by \a offset
56
returns the amount of offset that it was actually able to resized
57
*/
58
int
QColumnViewGrip::moveGrip(
int
offset)
59
{
60
QWidget *parentWidget = (QWidget*)parent();
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);
70
parentWidget->resize(newWidth, parentWidget->height());
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
82
/*!
83
\reimp
84
*/
85
void
QColumnViewGrip::paintEvent(QPaintEvent *event)
86
{
87
QPainter painter(
this
);
88
QStyleOption opt;
89
opt.initFrom(
this
);
90
style()->drawControl(QStyle::CE_ColumnViewGrip, &opt, &painter,
this
);
91
event->accept();
92
}
93
94
/*!
95
\reimp
96
Resize the parent window to the sizeHint
97
*/
98
void
QColumnViewGrip::mouseDoubleClickEvent(QMouseEvent *event)
99
{
100
Q_UNUSED(event);
101
QWidget *parentWidget = (QWidget*)parent();
102
int
offset = parentWidget->sizeHint().width() - parentWidget->width();
103
if
(isRightToLeft())
104
offset *= -1;
105
moveGrip(offset);
106
event->accept();
107
}
108
109
/*!
110
\reimp
111
Begin watching for mouse movements
112
*/
113
void
QColumnViewGrip::mousePressEvent(QMouseEvent *event)
114
{
115
Q_D(QColumnViewGrip);
116
d->originalXLocation = event->globalPosition().toPoint().x();
117
event->accept();
118
}
119
120
/*!
121
\reimp
122
Calculate the movement of the grip and moveGrip() and emit gripMoved
123
*/
124
void
QColumnViewGrip::mouseMoveEvent(QMouseEvent *event)
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
132
/*!
133
\reimp
134
Stop watching for mouse movements
135
*/
136
void
QColumnViewGrip::mouseReleaseEvent(QMouseEvent *event)
137
{
138
Q_D(QColumnViewGrip);
139
d->originalXLocation = -1;
140
event->accept();
141
}
142
143
/*
144
* private object implementation
145
*/
146
QColumnViewGripPrivate
::QColumnViewGripPrivate()
147
: QWidgetPrivate(),
148
originalXLocation
(-1)
149
{
150
}
151
152
QT_END_NAMESPACE
153
154
#
include
"moc_qcolumnviewgrip_p.cpp"
QColumnViewGripPrivate
Definition
qcolumnviewgrip_p.h:54
QColumnViewGripPrivate::originalXLocation
int originalXLocation
Definition
qcolumnviewgrip_p.h:61
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
widgets
itemviews
qcolumnviewgrip.cpp
Generated on
for Qt by
1.18.0