Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
sheet_delegate.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
// Qt-Security score:significant reason:default
4
5
#
include
"sheet_delegate_p.h"
6
7
#
include
<
QtCore
/
qabstractitemmodel
.
h
>
8
#
include
<
QtWidgets
/
qtreeview
.
h
>
9
#
include
<
QtWidgets
/
qstyle
.
h
>
10
#
include
<
QtGui
/
qpainter
.
h
>
11
12
QT_BEGIN_NAMESPACE
13
14
namespace
qdesigner_internal
{
15
16
SheetDelegate
::
SheetDelegate
(
QTreeView
*
view
,
QWidget
*
parent
)
17
:
QStyledItemDelegate
(
parent
),
18
m_view
(
view
)
19
{
20
}
21
22
void
SheetDelegate
::
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
23
{
24
const
QAbstractItemModel
*
model
=
index
.
model
();
25
Q_ASSERT
(
model
);
26
27
if
(!
model
->
parent
(
index
).
isValid
()) {
28
// this is a top-level item.
29
QStyleOptionButton
buttonOption
;
30
31
buttonOption
.
state
=
option
.
state
;
32
#
ifdef
Q_OS_MACOS
33
buttonOption
.
state
|=
QStyle
::
State_Raised
;
34
#
endif
35
buttonOption
.
state
&= ~
QStyle
::
State_HasFocus
;
36
37
buttonOption
.
rect
=
option
.
rect
;
38
buttonOption
.
palette
=
option
.
palette
;
39
buttonOption
.
features
=
QStyleOptionButton
::
None
;
40
41
painter
->
save
();
42
QColor
buttonColor
(230, 230, 230);
43
QBrush
buttonBrush
=
option
.
palette
.
button
();
44
if
(!
buttonBrush
.
gradient
() &&
buttonBrush
.
texture
().
isNull
())
45
buttonColor
=
buttonBrush
.
color
();
46
QColor
outlineColor
=
buttonColor
.
darker
(150);
47
QColor
highlightColor
=
buttonColor
.
lighter
(130);
48
49
// Only draw topline if the previous item is expanded
50
QModelIndex
previousIndex
=
model
->
index
(
index
.
row
() - 1,
index
.
column
());
51
bool
drawTopline
= (
index
.
row
() > 0 &&
m_view
->
isExpanded
(
previousIndex
));
52
int
highlightOffset
=
drawTopline
? 1 : 0;
53
54
QLinearGradient
gradient
(
option
.
rect
.
topLeft
(),
option
.
rect
.
bottomLeft
());
55
gradient
.
setColorAt
(0,
buttonColor
.
lighter
(102));
56
gradient
.
setColorAt
(1,
buttonColor
.
darker
(106));
57
58
painter
->
setPen
(
Qt
::
NoPen
);
59
painter
->
setBrush
(
gradient
);
60
painter
->
drawRect
(
option
.
rect
);
61
painter
->
setPen
(
highlightColor
);
62
painter
->
drawLine
(
option
.
rect
.
topLeft
() +
QPoint
(0,
highlightOffset
),
63
option
.
rect
.
topRight
() +
QPoint
(0,
highlightOffset
));
64
painter
->
setPen
(
outlineColor
);
65
if
(
drawTopline
)
66
painter
->
drawLine
(
option
.
rect
.
topLeft
(),
option
.
rect
.
topRight
());
67
painter
->
drawLine
(
option
.
rect
.
bottomLeft
(),
option
.
rect
.
bottomRight
());
68
painter
->
restore
();
69
70
QStyleOption
branchOption
;
71
static
const
int
i
= 9;
// ### hardcoded in qcommonstyle.cpp
72
QRect
r
=
option
.
rect
;
73
branchOption
.
rect
=
QRect
(
r
.
left
() +
i
/2,
r
.
top
() + (
r
.
height
() -
i
)/2,
i
,
i
);
74
branchOption
.
palette
=
option
.
palette
;
75
branchOption
.
state
=
QStyle
::
State_Children
;
76
77
if
(
m_view
->
isExpanded
(
index
))
78
branchOption
.
state
|=
QStyle
::
State_Open
;
79
80
m_view
->
style
()->
drawPrimitive
(
QStyle
::
PE_IndicatorBranch
, &
branchOption
,
painter
,
m_view
);
81
82
// draw text
83
QRect
textrect
=
QRect
(
r
.
left
() +
i
*2,
r
.
top
(),
r
.
width
() - ((5*
i
)/2),
r
.
height
());
84
QString
text
=
option
.
fontMetrics
.
elidedText
(
model
->
data
(
index
,
Qt
::
DisplayRole
).
toString
(),
85
Qt
::
ElideMiddle
,
86
textrect
.
width
());
87
m_view
->
style
()->
drawItemText
(
painter
,
textrect
,
Qt
::
AlignCenter
,
88
option
.
palette
,
m_view
->
isEnabled
(),
text
);
89
90
}
else
{
91
QStyledItemDelegate
::
paint
(
painter
,
option
,
index
);
92
}
93
}
94
95
QSize
SheetDelegate
::
sizeHint
(
const
QStyleOptionViewItem
&
opt
,
const
QModelIndex
&
index
)
const
96
{
97
QSize
sz
=
QStyledItemDelegate
::
sizeHint
(
opt
,
index
) +
QSize
(2, 2);
98
return
sz
;
99
}
100
101
}
// namespace qdesigner_internal
102
103
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
qttools
src
designer
src
lib
shared
sheet_delegate.cpp
Generated on
for Qt by
1.16.1