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) {}-
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}-
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)option->state|=.setFlag(QStyle::State_MouseOver;-
else
option, d->state &= ~QStyle::State_MouseOver;hovering);
42 }
never executed: end of block
0
43 option->text = d->text;-
44 option->icon = d->icon;-
45 option->iconSize = iconSize();-
46}
never executed: end of block
0
47-
48-
49-
50-
51-
52-
53-
54QCheckBox::QCheckBox(QWidget *parent)-
55 : QAbstractButton (*new QCheckBoxPrivate, parent)-
56{-
57 QCheckBoxPrivate * const d = d_func();-
58 d->init();-
59}-
60-
61-
62-
63-
64-
65-
66-
67QCheckBox::QCheckBox(const QString &text, QWidget *parent)-
68 : QAbstractButton (*new QCheckBoxPrivate, parent)-
69{-
70 QCheckBoxPrivate * const d = d_func();-
71 d->init();-
72 setText(text);-
73}-
74-
75-
76-
77-
78QCheckBox::~QCheckBox()-
79{-
80}-
81-
82void QCheckBox::setTristate(bool y)-
83{-
84 QCheckBoxPrivate * const d = d_func();-
85 d->tristate = y;-
86}-
87-
88bool QCheckBox::isTristate() const-
89{-
90 const QCheckBoxPrivate * const d = d_func();-
91 return d->tristate;-
92}-
93Qt::CheckState QCheckBox::checkState() const-
94{-
95 const QCheckBoxPrivate * const d = d_func();-
96 if (d->tristate && d->noChange)-
97 return Qt::PartiallyChecked;-
98 return d->checked ? Qt::Checked : Qt::Unchecked;-
99}-
100void QCheckBox::setCheckState(Qt::CheckState state)-
101{-
102 QCheckBoxPrivate * const d = d_func();-
103 if (state == Qt::PartiallyChecked) {-
104 d->tristate = true;-
105 d->noChange = true;-
106 } else {-
107 d->noChange = false;-
108 }-
109 d->blockRefresh = true;-
110 setChecked(state != Qt::Unchecked);-
111 d->blockRefresh = false;-
112 d->refresh();-
113 if ((uint)state != d->publishedState) {-
114 d->publishedState = state;-
115 stateChanged(state);-
116 }-
117}-
118-
119-
120-
121-
122-
123QSize QCheckBox::sizeHint() const-
124{-
125 const QCheckBoxPrivate * const d = d_func();-
126 if (d->sizeHint.isValid())-
127 return d->sizeHint;-
128 ensurePolished();-
129 QFontMetrics fm = fontMetrics();-
130 QStyleOptionButton opt;-
131 initStyleOption(&opt);-
132 QSize sz = style()->itemTextRect(fm, QRect(), Qt::TextShowMnemonic, false,-
133 text()).size();-
134 if (!opt.icon.isNull())-
135 sz = QSize(sz.width() + opt.iconSize.width() + 4, qMax(sz.height(), opt.iconSize.height()));-
136 d->sizeHint = (style()->sizeFromContents(QStyle::CT_CheckBox, &opt, sz, this)-
137 .expandedTo(QApplication::globalStrut()));-
138 return d->sizeHint;-
139}-
140-
141-
142-
143-
144-
145QSize QCheckBox::minimumSizeHint() const-
146{-
147 return sizeHint();-
148}-
149-
150-
151-
152-
153void QCheckBox::paintEvent(QPaintEvent *)-
154{-
155 QStylePainter p(this);-
156 QStyleOptionButton opt;-
157 initStyleOption(&opt);-
158 p.drawControl(QStyle::CE_CheckBox, opt);-
159}-
160-
161-
162-
163-
164void QCheckBox::mouseMoveEvent(QMouseEvent *e)-
165{-
166 QCheckBoxPrivate * const d = d_func();-
167 if (testAttribute(Qt::WA_Hover)) {-
168 bool hit = false;-
169 if (underMouse())-
170 hit = hitButton(e->pos());-
171-
172 if (hit != d->hovering) {-
173 update(rect());-
174 d->hovering = hit;-
175 }-
176 }-
177-
178 QAbstractButton::mouseMoveEvent(e);-
179}-
180-
181-
182-
183-
184-
185bool QCheckBox::hitButton(const QPoint &pos) const-
186{-
187 QStyleOptionButton opt;-
188 initStyleOption(&opt);-
189 return style()->subElementRect(QStyle::SE_CheckBoxClickRect, &opt, this).contains(pos);-
190}-
191-
192-
193-
194-
195void QCheckBox::checkStateSet()-
196{-
197 QCheckBoxPrivate * const d = d_func();-
198 d->noChange = false;-
199 Qt::CheckState state = checkState();-
200 if ((uint)state != d->publishedState) {-
201 d->publishedState = state;-
202 stateChanged(state);-
203 }-
204}-
205-
206-
207-
208-
209void QCheckBox::nextCheckState()-
210{-
211 QCheckBoxPrivate * const d = d_func();-
212 if (d->tristate)-
213 setCheckState((Qt::CheckState)((checkState() + 1) % 3));-
214 else {-
215 QAbstractButton::nextCheckState();-
216 QCheckBox::checkStateSet();-
217 }-
218}-
219-
220-
221-
222-
223bool QCheckBox::event(QEvent *e)-
224{-
225 QCheckBoxPrivate * const d = d_func();-
226 if (e->type() == QEvent::StyleChange-
227-
228-
229-
230 )-
231 d->setLayoutItemMargins(QStyle::SE_CheckBoxLayoutItem);-
232 return QAbstractButton::event(e);-
233}-
234-
235-
236-
237-
238-
Switch to Source codePreprocessed file

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