qcheckbox.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qcheckbox.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5class QCheckBoxPrivate : public QAbstractButtonPrivate-
6{-
7 inline QCheckBox* q_func() { return static_cast<QCheckBox *>(q_ptr); } inline const QCheckBox* q_func() const { return static_cast<const QCheckBox *>(q_ptr); } friend class QCheckBox;-
8public:-
9 QCheckBoxPrivate()-
10 : QAbstractButtonPrivate(QSizePolicy::CheckBox), tristate(false), noChange(false),-
11 hovering(true), publishedState(Qt::Unchecked) {}
never executed: end of block
0
12-
13 uint tristate : 1;-
14 uint noChange : 1;-
15 uint hovering : 1;-
16 uint publishedState : 2;-
17-
18 void init();-
19};-
20void QCheckBoxPrivate::init()-
21{-
22 QCheckBox * const q = q_func();-
23 q->setCheckable(true);-
24 q->setMouseTracking(true);-
25 q->setForegroundRole(QPalette::WindowText);-
26 setLayoutItemMargins(QStyle::SE_CheckBoxLayoutItem);-
27}
never executed: end of block
0
28void QCheckBox::initStyleOption(QStyleOptionButton *option) const-
29{-
30 if (!option
!optionDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
31 return;
never executed: return;
0
32 const QCheckBoxPrivate * const d = d_func();-
33 option->initFrom(this);-
34 if (d->down
d->downDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
35 option->state |= QStyle::State_Sunken;
never executed: option->state |= QStyle::State_Sunken;
0
36 if (d->tristate
d->tristateDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->noChange
d->noChangeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
37 option->state |= QStyle::State_NoChange;
never executed: option->state |= QStyle::State_NoChange;
0
38 else-
39 option->state |= d->checked
d->checkedDescription
TRUEnever evaluated
FALSEnever evaluated
? QStyle::State_On : QStyle::State_Off;
never executed: option->state |= d->checked ? QStyle::State_On : QStyle::State_Off;
0
40 if (testAttribute(Qt::WA_Hover)
testAttribute(Qt::WA_Hover)Description
TRUEnever evaluated
FALSEnever evaluated
&& underMouse()
underMouse()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
41 if (d->hovering
d->hoveringDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
42 option->state |= QStyle::State_MouseOver;
never executed: option->state |= QStyle::State_MouseOver;
0
43 else-
44 option->state &= ~QStyle::State_MouseOver;
never executed: option->state &= ~QStyle::State_MouseOver;
0
45 }-
46 option->text = d->text;-
47 option->icon = d->icon;-
48 option->iconSize = iconSize();-
49}
never executed: end of block
0
50-
51-
52-
53-
54-
55-
56-
57QCheckBox::QCheckBox(QWidget *parent)-
58 : QAbstractButton (*new QCheckBoxPrivate, parent)-
59{-
60 QCheckBoxPrivate * const d = d_func();-
61 d->init();-
62}
never executed: end of block
0
63-
64-
65-
66-
67-
68-
69-
70QCheckBox::QCheckBox(const QString &text, QWidget *parent)-
71 : QAbstractButton (*new QCheckBoxPrivate, parent)-
72{-
73 QCheckBoxPrivate * const d = d_func();-
74 d->init();-
75 setText(text);-
76}
never executed: end of block
0
77-
78-
79-
80-
81QCheckBox::~QCheckBox()-
82{-
83}-
84-
85void QCheckBox::setTristate(bool y)-
86{-
87 QCheckBoxPrivate * const d = d_func();-
88 d->tristate = y;-
89}
never executed: end of block
0
90-
91bool QCheckBox::isTristate() const-
92{-
93 const QCheckBoxPrivate * const d = d_func();-
94 return
never executed: return d->tristate;
d->tristate;
never executed: return d->tristate;
0
95}-
96Qt::CheckState QCheckBox::checkState() const-
97{-
98 const QCheckBoxPrivate * const d = d_func();-
99 if (d->tristate
d->tristateDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->noChange
d->noChangeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
100 return
never executed: return Qt::PartiallyChecked;
Qt::PartiallyChecked;
never executed: return Qt::PartiallyChecked;
0
101 return
never executed: return d->checked ? Qt::Checked : Qt::Unchecked;
d->checked
d->checkedDescription
TRUEnever evaluated
FALSEnever evaluated
? Qt::Checked : Qt::Unchecked;
never executed: return d->checked ? Qt::Checked : Qt::Unchecked;
0
102}-
103void QCheckBox::setCheckState(Qt::CheckState state)-
104{-
105 QCheckBoxPrivate * const d = d_func();-
106 if (state == Qt::PartiallyChecked
state == Qt::PartiallyCheckedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
107 d->tristate = true;-
108 d->noChange = true;-
109 }
never executed: end of block
else {
0
110 d->noChange = false;-
111 }
never executed: end of block
0
112 d->blockRefresh = true;-
113 setChecked(state != Qt::Unchecked);-
114 d->blockRefresh = false;-
115 d->refresh();-
116 if ((
(uint)state !=...publishedStateDescription
TRUEnever evaluated
FALSEnever evaluated
uint)state != d->publishedState
(uint)state !=...publishedStateDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
117 d->publishedState = state;-
118 stateChanged(state);-
119 }
never executed: end of block
0
120}
never executed: end of block
0
121-
122-
123-
124-
125-
126QSize QCheckBox::sizeHint() const-
127{-
128 const QCheckBoxPrivate * const d = d_func();-
129 if (d->sizeHint.isValid()
d->sizeHint.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
130 return
never executed: return d->sizeHint;
d->sizeHint;
never executed: return d->sizeHint;
0
131 ensurePolished();-
132 QFontMetrics fm = fontMetrics();-
133 QStyleOptionButton opt;-
134 initStyleOption(&opt);-
135 QSize sz = style()->itemTextRect(fm, QRect(), Qt::TextShowMnemonic, false,-
136 text()).size();-
137 if (!opt.icon.isNull()
!opt.icon.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
138 sz = QSize(sz.width() + opt.iconSize.width() + 4, qMax(sz.height(), opt.iconSize.height()));
never executed: sz = QSize(sz.width() + opt.iconSize.width() + 4, qMax(sz.height(), opt.iconSize.height()));
0
139 d->sizeHint = (style()->sizeFromContents(QStyle::CT_CheckBox, &opt, sz, this)-
140 .expandedTo(QApplication::globalStrut()));-
141 return
never executed: return d->sizeHint;
d->sizeHint;
never executed: return d->sizeHint;
0
142}-
143-
144-
145-
146-
147-
148QSize QCheckBox::minimumSizeHint() const-
149{-
150 return
never executed: return sizeHint();
sizeHint();
never executed: return sizeHint();
0
151}-
152-
153-
154-
155-
156void QCheckBox::paintEvent(QPaintEvent *)-
157{-
158 QStylePainter p(this);-
159 QStyleOptionButton opt;-
160 initStyleOption(&opt);-
161 p.drawControl(QStyle::CE_CheckBox, opt);-
162}
never executed: end of block
0
163-
164-
165-
166-
167void QCheckBox::mouseMoveEvent(QMouseEvent *e)-
168{-
169 QCheckBoxPrivate * const d = d_func();-
170 if (testAttribute(Qt::WA_Hover)
testAttribute(Qt::WA_Hover)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
171 bool hit = false;-
172 if (underMouse()
underMouse()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
173 hit = hitButton(e->pos());
never executed: hit = hitButton(e->pos());
0
174-
175 if (hit != d->hovering
hit != d->hoveringDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
176 update(rect());-
177 d->hovering = hit;-
178 }
never executed: end of block
0
179 }
never executed: end of block
0
180-
181 QAbstractButton::mouseMoveEvent(e);-
182}
never executed: end of block
0
183-
184-
185-
186-
187-
188bool QCheckBox::hitButton(const QPoint &pos) const-
189{-
190 QStyleOptionButton opt;-
191 initStyleOption(&opt);-
192 return
never executed: return style()->subElementRect(QStyle::SE_CheckBoxClickRect, &opt, this).contains(pos);
style()->subElementRect(QStyle::SE_CheckBoxClickRect, &opt, this).contains(pos);
never executed: return style()->subElementRect(QStyle::SE_CheckBoxClickRect, &opt, this).contains(pos);
0
193}-
194-
195-
196-
197-
198void QCheckBox::checkStateSet()-
199{-
200 QCheckBoxPrivate * const d = d_func();-
201 d->noChange = false;-
202 Qt::CheckState state = checkState();-
203 if ((
(uint)state !=...publishedStateDescription
TRUEnever evaluated
FALSEnever evaluated
uint)state != d->publishedState
(uint)state !=...publishedStateDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
204 d->publishedState = state;-
205 stateChanged(state);-
206 }
never executed: end of block
0
207}
never executed: end of block
0
208-
209-
210-
211-
212void QCheckBox::nextCheckState()-
213{-
214 QCheckBoxPrivate * const d = d_func();-
215 if (d->tristate
d->tristateDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
216 setCheckState((Qt::CheckState)((checkState() + 1) % 3));
never executed: setCheckState((Qt::CheckState)((checkState() + 1) % 3));
0
217 else {-
218 QAbstractButton::nextCheckState();-
219 QCheckBox::checkStateSet();-
220 }
never executed: end of block
0
221}-
222-
223-
224-
225-
226bool QCheckBox::event(QEvent *e)-
227{-
228 QCheckBoxPrivate * const d = d_func();-
229 if (e->type() == QEvent::StyleChange
e->type() == Q...t::StyleChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
230-
231-
232-
233 )-
234 d->setLayoutItemMargins(QStyle::SE_CheckBoxLayoutItem);
never executed: d->setLayoutItemMargins(QStyle::SE_CheckBoxLayoutItem);
0
235 return
never executed: return QAbstractButton::event(e);
QAbstractButton::event(e);
never executed: return QAbstractButton::event(e);
0
236}-
237-
238-
239-
240-
241-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9