Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qcheckbox.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | class 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; | - | ||||||||||||
8 | public: | - | ||||||||||||
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 | }; | - | ||||||||||||
20 | void 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 | ||||||||||||
28 | void QCheckBox::initStyleOption(QStyleOptionButton *option) const | - | ||||||||||||
29 | { | - | ||||||||||||
30 | if (!option
| 0 | ||||||||||||
31 | return; never executed: return; | 0 | ||||||||||||
32 | const QCheckBoxPrivate * const d = d_func(); | - | ||||||||||||
33 | option->initFrom(this); | - | ||||||||||||
34 | if (d->down
| 0 | ||||||||||||
35 | option->state |= QStyle::State_Sunken; never executed: option->state |= QStyle::State_Sunken; | 0 | ||||||||||||
36 | if (d->tristate
| 0 | ||||||||||||
37 | option->state |= QStyle::State_NoChange; never executed: option->state |= QStyle::State_NoChange; | 0 | ||||||||||||
38 | else | - | ||||||||||||
39 | option->state |= d->checked
never executed: option->state |= d->checked ? QStyle::State_On : QStyle::State_Off; | 0 | ||||||||||||
40 | if (testAttribute(Qt::WA_Hover)
| 0 | ||||||||||||
41 | if (d->hovering
| 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 | - | |||||||||||||
57 | QCheckBox::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 | - | |||||||||||||
70 | QCheckBox::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 | - | |||||||||||||
81 | QCheckBox::~QCheckBox() | - | ||||||||||||
82 | { | - | ||||||||||||
83 | } | - | ||||||||||||
84 | - | |||||||||||||
85 | void QCheckBox::setTristate(bool y) | - | ||||||||||||
86 | { | - | ||||||||||||
87 | QCheckBoxPrivate * const d = d_func(); | - | ||||||||||||
88 | d->tristate = y; | - | ||||||||||||
89 | } never executed: end of block | 0 | ||||||||||||
90 | - | |||||||||||||
91 | bool QCheckBox::isTristate() const | - | ||||||||||||
92 | { | - | ||||||||||||
93 | const QCheckBoxPrivate * const d = d_func(); | - | ||||||||||||
94 | return never executed: d->tristate;return d->tristate; never executed: return d->tristate; | 0 | ||||||||||||
95 | } | - | ||||||||||||
96 | Qt::CheckState QCheckBox::checkState() const | - | ||||||||||||
97 | { | - | ||||||||||||
98 | const QCheckBoxPrivate * const d = d_func(); | - | ||||||||||||
99 | if (d->tristate
| 0 | ||||||||||||
100 | return never executed: Qt::PartiallyChecked;return Qt::PartiallyChecked; never executed: return Qt::PartiallyChecked; | 0 | ||||||||||||
101 | return never executed: d->checkedreturn d->checked ? Qt::Checked : Qt::Unchecked;
never executed: return d->checked ? Qt::Checked : Qt::Unchecked; | 0 | ||||||||||||
102 | } | - | ||||||||||||
103 | void QCheckBox::setCheckState(Qt::CheckState state) | - | ||||||||||||
104 | { | - | ||||||||||||
105 | QCheckBoxPrivate * const d = d_func(); | - | ||||||||||||
106 | if (state == Qt::PartiallyChecked
| 0 | ||||||||||||
107 | d->tristate = true; | - | ||||||||||||
108 | d->noChange = true; | - | ||||||||||||
109 | } never executed: else {end of block | 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 ((
| 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 | - | |||||||||||||
126 | QSize QCheckBox::sizeHint() const | - | ||||||||||||
127 | { | - | ||||||||||||
128 | const QCheckBoxPrivate * const d = d_func(); | - | ||||||||||||
129 | if (d->sizeHint.isValid()
| 0 | ||||||||||||
130 | return never executed: d->sizeHint;return 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()
| 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: d->sizeHint;return d->sizeHint; never executed: return d->sizeHint; | 0 | ||||||||||||
142 | } | - | ||||||||||||
143 | - | |||||||||||||
144 | - | |||||||||||||
145 | - | |||||||||||||
146 | - | |||||||||||||
147 | - | |||||||||||||
148 | QSize QCheckBox::minimumSizeHint() const | - | ||||||||||||
149 | { | - | ||||||||||||
150 | return never executed: sizeHint();return sizeHint(); never executed: return sizeHint(); | 0 | ||||||||||||
151 | } | - | ||||||||||||
152 | - | |||||||||||||
153 | - | |||||||||||||
154 | - | |||||||||||||
155 | - | |||||||||||||
156 | void 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 | - | |||||||||||||
167 | void QCheckBox::mouseMoveEvent(QMouseEvent *e) | - | ||||||||||||
168 | { | - | ||||||||||||
169 | QCheckBoxPrivate * const d = d_func(); | - | ||||||||||||
170 | if (testAttribute(Qt::WA_Hover)
| 0 | ||||||||||||
171 | bool hit = false; | - | ||||||||||||
172 | if (underMouse()
| 0 | ||||||||||||
173 | hit = hitButton(e->pos()); never executed: hit = hitButton(e->pos()); | 0 | ||||||||||||
174 | - | |||||||||||||
175 | if (hit != d->hovering
| 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 | - | |||||||||||||
188 | bool QCheckBox::hitButton(const QPoint &pos) const | - | ||||||||||||
189 | { | - | ||||||||||||
190 | QStyleOptionButton opt; | - | ||||||||||||
191 | initStyleOption(&opt); | - | ||||||||||||
192 | return never executed: style()->subElementRect(QStyle::SE_CheckBoxClickRect, &opt, this).contains(pos);return 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 | - | |||||||||||||
198 | void QCheckBox::checkStateSet() | - | ||||||||||||
199 | { | - | ||||||||||||
200 | QCheckBoxPrivate * const d = d_func(); | - | ||||||||||||
201 | d->noChange = false; | - | ||||||||||||
202 | Qt::CheckState state = checkState(); | - | ||||||||||||
203 | if ((
| 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 | - | |||||||||||||
212 | void QCheckBox::nextCheckState() | - | ||||||||||||
213 | { | - | ||||||||||||
214 | QCheckBoxPrivate * const d = d_func(); | - | ||||||||||||
215 | if (d->tristate
| 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 | - | |||||||||||||
226 | bool QCheckBox::event(QEvent *e) | - | ||||||||||||
227 | { | - | ||||||||||||
228 | QCheckBoxPrivate * const d = d_func(); | - | ||||||||||||
229 | if (e->type() == QEvent::StyleChange
| 0 | ||||||||||||
230 | - | |||||||||||||
231 | - | |||||||||||||
232 | - | |||||||||||||
233 | ) | - | ||||||||||||
234 | d->setLayoutItemMargins(QStyle::SE_CheckBoxLayoutItem); never executed: d->setLayoutItemMargins(QStyle::SE_CheckBoxLayoutItem); | 0 | ||||||||||||
235 | return never executed: QAbstractButton::event(e);return QAbstractButton::event(e); never executed: return QAbstractButton::event(e); | 0 | ||||||||||||
236 | } | - | ||||||||||||
237 | - | |||||||||||||
238 | - | |||||||||||||
239 | - | |||||||||||||
240 | - | |||||||||||||
241 | - | |||||||||||||
Switch to Source code | Preprocessed file |