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