| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | #include "qcheckbox.h" | - |
| 41 | #include "qapplication.h" | - |
| 42 | #include "qbitmap.h" | - |
| 43 | #include "qicon.h" | - |
| 44 | #include "qstylepainter.h" | - |
| 45 | #include "qstyle.h" | - |
| 46 | #include "qstyleoption.h" | - |
| 47 | #include "qevent.h" | - |
| 48 | | - |
| 49 | #include "private/qabstractbutton_p.h" | - |
| 50 | | - |
| 51 | QT_BEGIN_NAMESPACE | - |
| 52 | | - |
| 53 | class QCheckBoxPrivate : public QAbstractButtonPrivate | - |
| 54 | { | - |
| 55 | Q_DECLARE_PUBLIC(QCheckBox) | - |
| 56 | public: | - |
| 57 | QCheckBoxPrivate() | - |
| 58 | : QAbstractButtonPrivate(QSizePolicy::CheckBox), tristate(false), noChange(false), | - |
| 59 | hovering(true), publishedState(Qt::Unchecked) {} | - |
| 60 | | - |
| 61 | uint tristate : 1; | - |
| 62 | uint noChange : 1; | - |
| 63 | uint hovering : 1; | - |
| 64 | uint publishedState : 2; | - |
| 65 | | - |
| 66 | void init(); | - |
| 67 | }; | - |
| 68 | | - |
| 69 | | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | | - |
| 75 | | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | | - |
| 80 | | - |
| 81 | | - |
| 82 | | - |
| 83 | | - |
| 84 | | - |
| 85 | | - |
| 86 | | - |
| 87 | | - |
| 88 | | - |
| 89 | | - |
| 90 | | - |
| 91 | | - |
| 92 | | - |
| 93 | | - |
| 94 | | - |
| 95 | | - |
| 96 | | - |
| 97 | | - |
| 98 | | - |
| 99 | | - |
| 100 | | - |
| 101 | | - |
| 102 | | - |
| 103 | | - |
| 104 | | - |
| 105 | | - |
| 106 | | - |
| 107 | | - |
| 108 | | - |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | | - |
| 115 | | - |
| 116 | | - |
| 117 | | - |
| 118 | | - |
| 119 | | - |
| 120 | | - |
| 121 | | - |
| 122 | | - |
| 123 | | - |
| 124 | | - |
| 125 | | - |
| 126 | | - |
| 127 | | - |
| 128 | | - |
| 129 | | - |
| 130 | | - |
| 131 | | - |
| 132 | | - |
| 133 | | - |
| 134 | | - |
| 135 | | - |
| 136 | | - |
| 137 | | - |
| 138 | | - |
| 139 | | - |
| 140 | | - |
| 141 | | - |
| 142 | | - |
| 143 | | - |
| 144 | | - |
| 145 | | - |
| 146 | | - |
| 147 | | - |
| 148 | | - |
| 149 | | - |
| 150 | | - |
| 151 | void QCheckBoxPrivate::init() | - |
| 152 | { | - |
| 153 | Q_Q(QCheckBox); | - |
| 154 | q->setCheckable(true); | - |
| 155 | q->setMouseTracking(true); | - |
| 156 | q->setForegroundRole(QPalette::WindowText); | - |
| 157 | setLayoutItemMargins(QStyle::SE_CheckBoxLayoutItem); | - |
| 158 | } | - |
| 159 | | - |
| 160 | | - |
| 161 | | - |
| 162 | | - |
| 163 | | - |
| 164 | | - |
| 165 | | - |
| 166 | | - |
| 167 | void QCheckBox::initStyleOption(QStyleOptionButton *option) const | - |
| 168 | { | - |
| 169 | if (!option)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 170 | return; never executed: return; | 0 |
| 171 | Q_D(const QCheckBox); | - |
| 172 | option->initFrom(this); | - |
| 173 | if (d->down)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 174 | option->state |= QStyle::State_Sunken; never executed: option->state |= QStyle::State_Sunken; | 0 |
| 175 | if (d->tristate && d->noChange)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 176 | option->state |= QStyle::State_NoChange; never executed: option->state |= QStyle::State_NoChange; | 0 |
| 177 | else | - |
| 178 | option->state |= d->checked ? QStyle::State_On : QStyle::State_Off; never executed: option->state |= d->checked ? QStyle::State_On : QStyle::State_Off; | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 179 | if (testAttribute(Qt::WA_Hover) && underMouse()) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 180 | if (d->hovering)option->state|=.setFlag(QStyle::State_MouseOver; | - |
| else | |
| option, d->state &= ~QStyle::State_MouseOver;hovering); | |
| 181 | } never executed: end of block | 0 |
| 182 | option->text = d->text; | - |
| 183 | option->icon = d->icon; | - |
| 184 | option->iconSize = iconSize(); | - |
| 185 | } never executed: end of block | 0 |
| 186 | | - |
| 187 | | - |
| 188 | | - |
| 189 | | - |
| 190 | | - |
| 191 | | - |
| 192 | | - |
| 193 | QCheckBox::QCheckBox(QWidget *parent) | - |
| 194 | : QAbstractButton (*new QCheckBoxPrivate, parent) | - |
| 195 | { | - |
| 196 | Q_D(QCheckBox); | - |
| 197 | d->init(); | - |
| 198 | } | - |
| 199 | | - |
| 200 | | - |
| 201 | | - |
| 202 | | - |
| 203 | | - |
| 204 | | - |
| 205 | | - |
| 206 | QCheckBox::QCheckBox(const QString &text, QWidget *parent) | - |
| 207 | : QAbstractButton (*new QCheckBoxPrivate, parent) | - |
| 208 | { | - |
| 209 | Q_D(QCheckBox); | - |
| 210 | d->init(); | - |
| 211 | setText(text); | - |
| 212 | } | - |
| 213 | | - |
| 214 | | - |
| 215 | | - |
| 216 | | - |
| 217 | QCheckBox::~QCheckBox() | - |
| 218 | { | - |
| 219 | } | - |
| 220 | | - |
| 221 | void QCheckBox::setTristate(bool y) | - |
| 222 | { | - |
| 223 | Q_D(QCheckBox); | - |
| 224 | d->tristate = y; | - |
| 225 | } | - |
| 226 | | - |
| 227 | bool QCheckBox::isTristate() const | - |
| 228 | { | - |
| 229 | Q_D(const QCheckBox); | - |
| 230 | return d->tristate; | - |
| 231 | } | - |
| 232 | | - |
| 233 | | - |
| 234 | | - |
| 235 | | - |
| 236 | | - |
| 237 | | - |
| 238 | | - |
| 239 | | - |
| 240 | Qt::CheckState QCheckBox::checkState() const | - |
| 241 | { | - |
| 242 | Q_D(const QCheckBox); | - |
| 243 | if (d->tristate && d->noChange) | - |
| 244 | return Qt::PartiallyChecked; | - |
| 245 | return d->checked ? Qt::Checked : Qt::Unchecked; | - |
| 246 | } | - |
| 247 | | - |
| 248 | | - |
| 249 | | - |
| 250 | | - |
| 251 | | - |
| 252 | | - |
| 253 | | - |
| 254 | | - |
| 255 | void QCheckBox::setCheckState(Qt::CheckState state) | - |
| 256 | { | - |
| 257 | Q_D(QCheckBox); | - |
| 258 | if (state == Qt::PartiallyChecked) { | - |
| 259 | d->tristate = true; | - |
| 260 | d->noChange = true; | - |
| 261 | } else { | - |
| 262 | d->noChange = false; | - |
| 263 | } | - |
| 264 | d->blockRefresh = true; | - |
| 265 | setChecked(state != Qt::Unchecked); | - |
| 266 | d->blockRefresh = false; | - |
| 267 | d->refresh(); | - |
| 268 | if ((uint)state != d->publishedState) { | - |
| 269 | d->publishedState = state; | - |
| 270 | emit stateChanged(state); | - |
| 271 | } | - |
| 272 | } | - |
| 273 | | - |
| 274 | | - |
| 275 | | - |
| 276 | | - |
| 277 | | - |
| 278 | QSize QCheckBox::sizeHint() const | - |
| 279 | { | - |
| 280 | Q_D(const QCheckBox); | - |
| 281 | if (d->sizeHint.isValid()) | - |
| 282 | return d->sizeHint; | - |
| 283 | ensurePolished(); | - |
| 284 | QFontMetrics fm = fontMetrics(); | - |
| 285 | QStyleOptionButton opt; | - |
| 286 | initStyleOption(&opt); | - |
| 287 | QSize sz = style()->itemTextRect(fm, QRect(), Qt::TextShowMnemonic, false, | - |
| 288 | text()).size(); | - |
| 289 | if (!opt.icon.isNull()) | - |
| 290 | sz = QSize(sz.width() + opt.iconSize.width() + 4, qMax(sz.height(), opt.iconSize.height())); | - |
| 291 | d->sizeHint = (style()->sizeFromContents(QStyle::CT_CheckBox, &opt, sz, this) | - |
| 292 | .expandedTo(QApplication::globalStrut())); | - |
| 293 | return d->sizeHint; | - |
| 294 | } | - |
| 295 | | - |
| 296 | | - |
| 297 | | - |
| 298 | | - |
| 299 | | - |
| 300 | QSize QCheckBox::minimumSizeHint() const | - |
| 301 | { | - |
| 302 | return sizeHint(); | - |
| 303 | } | - |
| 304 | | - |
| 305 | | - |
| 306 | | - |
| 307 | | - |
| 308 | void QCheckBox::paintEvent(QPaintEvent *) | - |
| 309 | { | - |
| 310 | QStylePainter p(this); | - |
| 311 | QStyleOptionButton opt; | - |
| 312 | initStyleOption(&opt); | - |
| 313 | p.drawControl(QStyle::CE_CheckBox, opt); | - |
| 314 | } | - |
| 315 | | - |
| 316 | | - |
| 317 | | - |
| 318 | | - |
| 319 | void QCheckBox::mouseMoveEvent(QMouseEvent *e) | - |
| 320 | { | - |
| 321 | Q_D(QCheckBox); | - |
| 322 | if (testAttribute(Qt::WA_Hover)) { | - |
| 323 | bool hit = false; | - |
| 324 | if (underMouse()) | - |
| 325 | hit = hitButton(e->pos()); | - |
| 326 | | - |
| 327 | if (hit != d->hovering) { | - |
| 328 | update(rect()); | - |
| 329 | d->hovering = hit; | - |
| 330 | } | - |
| 331 | } | - |
| 332 | | - |
| 333 | QAbstractButton::mouseMoveEvent(e); | - |
| 334 | } | - |
| 335 | | - |
| 336 | | - |
| 337 | | - |
| 338 | | - |
| 339 | | - |
| 340 | bool QCheckBox::hitButton(const QPoint &pos) const | - |
| 341 | { | - |
| 342 | QStyleOptionButton opt; | - |
| 343 | initStyleOption(&opt); | - |
| 344 | return style()->subElementRect(QStyle::SE_CheckBoxClickRect, &opt, this).contains(pos); | - |
| 345 | } | - |
| 346 | | - |
| 347 | | - |
| 348 | | - |
| 349 | | - |
| 350 | void QCheckBox::checkStateSet() | - |
| 351 | { | - |
| 352 | Q_D(QCheckBox); | - |
| 353 | d->noChange = false; | - |
| 354 | Qt::CheckState state = checkState(); | - |
| 355 | if ((uint)state != d->publishedState) { | - |
| 356 | d->publishedState = state; | - |
| 357 | emit stateChanged(state); | - |
| 358 | } | - |
| 359 | } | - |
| 360 | | - |
| 361 | | - |
| 362 | | - |
| 363 | | - |
| 364 | void QCheckBox::nextCheckState() | - |
| 365 | { | - |
| 366 | Q_D(QCheckBox); | - |
| 367 | if (d->tristate) | - |
| 368 | setCheckState((Qt::CheckState)((checkState() + 1) % 3)); | - |
| 369 | else { | - |
| 370 | QAbstractButton::nextCheckState(); | - |
| 371 | QCheckBox::checkStateSet(); | - |
| 372 | } | - |
| 373 | } | - |
| 374 | | - |
| 375 | | - |
| 376 | | - |
| 377 | | - |
| 378 | bool QCheckBox::event(QEvent *e) | - |
| 379 | { | - |
| 380 | Q_D(QCheckBox); | - |
| 381 | if (e->type() == QEvent::StyleChange | - |
| 382 | #ifdef Q_OS_MAC | - |
| 383 | || e->type() == QEvent::MacSizeChange | - |
| 384 | #endif | - |
| 385 | ) | - |
| 386 | d->setLayoutItemMargins(QStyle::SE_CheckBoxLayoutItem); | - |
| 387 | return QAbstractButton::event(e); | - |
| 388 | } | - |
| 389 | | - |
| 390 | | - |
| 391 | | - |
| 392 | QT_END_NAMESPACE | - |
| 393 | | - |
| 394 | #include "moc_qcheckbox.cpp" | - |
| | |