qgroupbox.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qgroupbox.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qgroupbox.h"-
41#ifndef QT_NO_GROUPBOX-
42#include "qapplication.h"-
43#include "qbitmap.h"-
44#include "qdrawutil.h"-
45#include "qevent.h"-
46#include "qlayout.h"-
47#include "qradiobutton.h"-
48#include "qstyle.h"-
49#include "qstyleoption.h"-
50#include "qstylepainter.h"-
51#ifndef QT_NO_ACCESSIBILITY-
52#include "qaccessible.h"-
53#endif-
54#include <private/qwidget_p.h>-
55-
56#include "qdebug.h"-
57-
58QT_BEGIN_NAMESPACE-
59-
60class QGroupBoxPrivate : public QWidgetPrivate-
61{-
62 Q_DECLARE_PUBLIC(QGroupBox)-
63-
64public:-
65 void skip();-
66 void init();-
67 void calculateFrame();-
68 QString title;-
69 int align;-
70#ifndef QT_NO_SHORTCUT-
71 int shortcutId;-
72#endif-
73-
74 void _q_fixFocus(Qt::FocusReason reason);-
75 void _q_setChildrenEnabled(bool b);-
76 void click();-
77 bool flat;-
78 bool checkable;-
79 bool checked;-
80 bool hover;-
81 bool overCheckBox;-
82 QStyle::SubControl pressedControl;-
83};-
84-
85/*!-
86 Initialize \a option with the values from this QGroupBox. This method-
87 is useful for subclasses when they need a QStyleOptionGroupBox, but don't want-
88 to fill in all the information themselves.-
89-
90 \sa QStyleOption::initFrom()-
91*/-
92void QGroupBox::initStyleOption(QStyleOptionGroupBox *option) const-
93{-
94 if (!option)
!optionDescription
TRUEnever evaluated
FALSEnever evaluated
0
95 return;
never executed: return;
0
96-
97 Q_D(const QGroupBox);-
98 option->initFrom(this);-
99 option->text = d->title;-
100 option->lineWidth = 1;-
101 option->midLineWidth = 0;-
102 option->textAlignment = Qt::Alignment(d->align);-
103 option->activeSubControls |= d->pressedControl;-
104 option->subControls = QStyle::SC_GroupBoxFrame;-
105-
106 option->state.setFlag(QStyle::State_MouseOver, d->hover);-
107 if (d->flat)
d->flatDescription
TRUEnever evaluated
FALSEnever evaluated
0
108 option->features |= QStyleOptionFrame::Flat;
never executed: option->features |= QStyleOptionFrame::Flat;
0
109-
110 if (d->checkable) {
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
0
111 option->subControls |= QStyle::SC_GroupBoxCheckBox;-
112 option->state |= (d->checked ? QStyle::State_On : QStyle::State_Off);
d->checkedDescription
TRUEnever evaluated
FALSEnever evaluated
0
113 if ((d->pressedControl == QStyle::SC_GroupBoxCheckBox
d->pressedCont...oupBoxCheckBoxDescription
TRUEnever evaluated
FALSEnever evaluated
0
114 || d->pressedControl == QStyle::SC_GroupBoxLabel) && (d->hover || d->overCheckBox))
d->pressedCont..._GroupBoxLabelDescription
TRUEnever evaluated
FALSEnever evaluated
d->hoverDescription
TRUEnever evaluated
FALSEnever evaluated
d->overCheckBoxDescription
TRUEnever evaluated
FALSEnever evaluated
0
115 option->state |= QStyle::State_Sunken;
never executed: option->state |= QStyle::State_Sunken;
0
116 }
never executed: end of block
0
117-
118 if (!option->palette.isBrushSet(isEnabled() ? QPalette::Active :
!option->palet...e::WindowText)Description
TRUEnever evaluated
FALSEnever evaluated
0
119 QPalette::Disabled, QPalette::WindowText))
!option->palet...e::WindowText)Description
TRUEnever evaluated
FALSEnever evaluated
0
120 option->textColor = QColor(style()->styleHint(QStyle::SH_GroupBox_TextLabelColor,
never executed: option->textColor = QColor(style()->styleHint(QStyle::SH_GroupBox_TextLabelColor, option, this));
0
121 option, this));
never executed: option->textColor = QColor(style()->styleHint(QStyle::SH_GroupBox_TextLabelColor, option, this));
0
122-
123 if (!d->title.isEmpty())
!d->title.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
124 option->subControls |= QStyle::SC_GroupBoxLabel;
never executed: option->subControls |= QStyle::SC_GroupBoxLabel;
0
125}
never executed: end of block
0
126-
127void QGroupBoxPrivate::click()-
128{-
129 Q_Q(QGroupBox);-
130-
131 QPointer<QGroupBox> guard(q);-
132 q->setChecked(!checked);-
133 if (!guard)
!guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
134 return;
never executed: return;
0
135 emit q->clicked(checked);-
136}
never executed: end of block
0
137-
138/*!-
139 \class QGroupBox-
140 \brief The QGroupBox widget provides a group box frame with a title.-
141-
142 \ingroup organizers-
143 \ingroup geomanagement-
144 \inmodule QtWidgets-
145-
146 A group box provides a frame, a title on top, a keyboard shortcut, and-
147 displays various other widgets inside itself. The keyboard shortcut moves-
148 keyboard focus to one of the group box's child widgets.-
149-
150 QGroupBox also lets you set the \l title (normally set in the-
151 constructor) and the title's \l alignment. Group boxes can be-
152 \l checkable. Child widgets in checkable group boxes are enabled or-
153 disabled depending on whether or not the group box is \l checked.-
154-
155 You can minimize the space consumption of a group box by enabling-
156 the \l flat property. In most \l{QStyle}{styles}, enabling this-
157 property results in the removal of the left, right and bottom-
158 edges of the frame.-
159-
160 QGroupBox doesn't automatically lay out the child widgets (which-
161 are often \l{QCheckBox}es or \l{QRadioButton}s but can be any-
162 widgets). The following example shows how we can set up a-
163 QGroupBox with a layout:-
164-
165 \snippet widgets/groupbox/window.cpp 2-
166-
167 \table 100%-
168 \row \li \inlineimage windowsvista-groupbox.png Screenshot of a Windows Vista style group box-
169 \li \inlineimage macintosh-groupbox.png Screenshot of a Macintosh style group box-
170 \li \inlineimage fusion-groupbox.png Screenshot of a Fusion style group box-
171 \row \li A \l{Windows Vista Style Widget Gallery}{Windows Vista style} group box.-
172 \li A \l{Macintosh Style Widget Gallery}{Macintosh style} group box.-
173 \li A \l{Fusion Style Widget Gallery}{Fusion style} group box.-
174 \endtable-
175-
176 \sa QButtonGroup, {Group Box Example}-
177*/-
178-
179-
180-
181/*!-
182 Constructs a group box widget with the given \a parent but with no title.-
183*/-
184-
185QGroupBox::QGroupBox(QWidget *parent)-
186 : QWidget(*new QGroupBoxPrivate, parent, 0)-
187{-
188 Q_D(QGroupBox);-
189 d->init();-
190}
never executed: end of block
0
191-
192/*!-
193 Constructs a group box with the given \a title and \a parent.-
194*/-
195-
196QGroupBox::QGroupBox(const QString &title, QWidget *parent)-
197 : QWidget(*new QGroupBoxPrivate, parent, 0)-
198{-
199 Q_D(QGroupBox);-
200 d->init();-
201 setTitle(title);-
202}
never executed: end of block
0
203-
204-
205/*!-
206 Destroys the group box.-
207*/-
208QGroupBox::~QGroupBox()-
209{-
210}-
211-
212void QGroupBoxPrivate::init()-
213{-
214 Q_Q(QGroupBox);-
215 align = Qt::AlignLeft;-
216#ifndef QT_NO_SHORTCUT-
217 shortcutId = 0;-
218#endif-
219 flat = false;-
220 checkable = false;-
221 checked = true;-
222 hover = false;-
223 overCheckBox = false;-
224 pressedControl = QStyle::SC_None;-
225 calculateFrame();-
226 q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred,-
227 QSizePolicy::GroupBox));-
228}
never executed: end of block
0
229-
230void QGroupBox::setTitle(const QString &title)-
231{-
232 Q_D(QGroupBox);-
233 if (d->title == title) // no change
d->title == titleDescription
TRUEnever evaluated
FALSEnever evaluated
0
234 return;
never executed: return;
0
235 d->title = title;-
236#ifndef QT_NO_SHORTCUT-
237 releaseShortcut(d->shortcutId);-
238 d->shortcutId = grabShortcut(QKeySequence::mnemonic(title));-
239#endif-
240 d->calculateFrame();-
241-
242 update();-
243 updateGeometry();-
244#ifndef QT_NO_ACCESSIBILITY-
245 QAccessibleEvent event(this, QAccessible::NameChanged);-
246 QAccessible::updateAccessibility(&event);-
247#endif-
248}
never executed: end of block
0
249-
250/*!-
251 \property QGroupBox::title-
252 \brief the group box title text-
253-
254 The group box title text will have a keyboard shortcut if the title-
255 contains an ampersand ('&') followed by a letter.-
256-
257 \snippet code/src_gui_widgets_qgroupbox.cpp 0-
258-
259 In the example above, \uicontrol Alt+U moves the keyboard focus to the-
260 group box. See the \l {QShortcut#mnemonic}{QShortcut}-
261 documentation for details (to display an actual ampersand, use-
262 '&&').-
263-
264 There is no default title text.-
265-
266 \sa alignment-
267*/-
268-
269QString QGroupBox::title() const-
270{-
271 Q_D(const QGroupBox);-
272 return d->title;
never executed: return d->title;
0
273}-
274-
275/*!-
276 \property QGroupBox::alignment-
277 \brief the alignment of the group box title.-
278-
279 Most styles place the title at the top of the frame. The horizontal-
280 alignment of the title can be specified using single values from-
281 the following list:-
282-
283 \list-
284 \li Qt::AlignLeft aligns the title text with the left-hand side of the group box.-
285 \li Qt::AlignRight aligns the title text with the right-hand side of the group box.-
286 \li Qt::AlignHCenter aligns the title text with the horizontal center of the group box.-
287 \endlist-
288-
289 The default alignment is Qt::AlignLeft.-
290-
291 \sa Qt::Alignment-
292*/-
293Qt::Alignment QGroupBox::alignment() const-
294{-
295 Q_D(const QGroupBox);-
296 return QFlag(d->align);
never executed: return QFlag(d->align);
0
297}-
298-
299void QGroupBox::setAlignment(int alignment)-
300{-
301 Q_D(QGroupBox);-
302 d->align = alignment;-
303 updateGeometry();-
304 update();-
305}
never executed: end of block
0
306-
307/*! \reimp-
308*/-
309void QGroupBox::resizeEvent(QResizeEvent *e)-
310{-
311 QWidget::resizeEvent(e);-
312}
never executed: end of block
0
313-
314/*! \reimp-
315*/-
316-
317void QGroupBox::paintEvent(QPaintEvent *)-
318{-
319 QStylePainter paint(this);-
320 QStyleOptionGroupBox option;-
321 initStyleOption(&option);-
322 paint.drawComplexControl(QStyle::CC_GroupBox, option);-
323}
never executed: end of block
0
324-
325/*! \reimp */-
326bool QGroupBox::event(QEvent *e)-
327{-
328 Q_D(QGroupBox);-
329#ifndef QT_NO_SHORTCUT-
330 if (e->type() == QEvent::Shortcut) {
e->type() == QEvent::ShortcutDescription
TRUEnever evaluated
FALSEnever evaluated
0
331 QShortcutEvent *se = static_cast<QShortcutEvent *>(e);-
332 if (se->shortcutId() == d->shortcutId) {
se->shortcutId... d->shortcutIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
333 if (!isCheckable()) {
!isCheckable()Description
TRUEnever evaluated
FALSEnever evaluated
0
334 d->_q_fixFocus(Qt::ShortcutFocusReason);-
335 } else {
never executed: end of block
0
336 d->click();-
337 setFocus(Qt::ShortcutFocusReason);-
338 }
never executed: end of block
0
339 return true;
never executed: return true;
0
340 }-
341 }
never executed: end of block
0
342#endif-
343 QStyleOptionGroupBox box;-
344 initStyleOption(&box);-
345 switch (e->type()) {-
346 case QEvent::HoverEnter:
never executed: case QEvent::HoverEnter:
0
347 case QEvent::HoverMove: {
never executed: case QEvent::HoverMove:
0
348 QStyle::SubControl control = style()->hitTestComplexControl(QStyle::CC_GroupBox, &box,-
349 static_cast<QHoverEvent *>(e)->pos(),-
350 this);-
351 bool oldHover = d->hover;-
352 d->hover = d->checkable && (control == QStyle::SC_GroupBoxLabel || control == QStyle::SC_GroupBoxCheckBox);
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
control == QSt..._GroupBoxLabelDescription
TRUEnever evaluated
FALSEnever evaluated
control == QSt...oupBoxCheckBoxDescription
TRUEnever evaluated
FALSEnever evaluated
0
353 if (oldHover != d->hover) {
oldHover != d->hoverDescription
TRUEnever evaluated
FALSEnever evaluated
0
354 QRect rect = style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this)-
355 | style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxLabel, this);-
356 update(rect);-
357 }
never executed: end of block
0
358 return true;
never executed: return true;
0
359 }-
360 case QEvent::HoverLeave:
never executed: case QEvent::HoverLeave:
0
361 d->hover = false;-
362 if (d->checkable) {
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
0
363 QRect rect = style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this)-
364 | style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxLabel, this);-
365 update(rect);-
366 }
never executed: end of block
0
367 return true;
never executed: return true;
0
368 case QEvent::KeyPress: {
never executed: case QEvent::KeyPress:
0
369 QKeyEvent *k = static_cast<QKeyEvent*>(e);-
370 if (!k->isAutoRepeat() && (k->key() == Qt::Key_Select || k->key() == Qt::Key_Space)) {
!k->isAutoRepeat()Description
TRUEnever evaluated
FALSEnever evaluated
k->key() == Qt::Key_SelectDescription
TRUEnever evaluated
FALSEnever evaluated
k->key() == Qt::Key_SpaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
371 d->pressedControl = QStyle::SC_GroupBoxCheckBox;-
372 update(style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this));-
373 return true;
never executed: return true;
0
374 }-
375 break;
never executed: break;
0
376 }-
377 case QEvent::KeyRelease: {
never executed: case QEvent::KeyRelease:
0
378 QKeyEvent *k = static_cast<QKeyEvent*>(e);-
379 if (!k->isAutoRepeat() && (k->key() == Qt::Key_Select || k->key() == Qt::Key_Space)) {
!k->isAutoRepeat()Description
TRUEnever evaluated
FALSEnever evaluated
k->key() == Qt::Key_SelectDescription
TRUEnever evaluated
FALSEnever evaluated
k->key() == Qt::Key_SpaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
380 bool toggle = (d->pressedControl == QStyle::SC_GroupBoxLabel
d->pressedCont..._GroupBoxLabelDescription
TRUEnever evaluated
FALSEnever evaluated
0
381 || d->pressedControl == QStyle::SC_GroupBoxCheckBox);
d->pressedCont...oupBoxCheckBoxDescription
TRUEnever evaluated
FALSEnever evaluated
0
382 d->pressedControl = QStyle::SC_None;-
383 if (toggle)
toggleDescription
TRUEnever evaluated
FALSEnever evaluated
0
384 d->click();
never executed: d->click();
0
385 return true;
never executed: return true;
0
386 }-
387 break;
never executed: break;
0
388 }-
389 default:
never executed: default:
0
390 break;
never executed: break;
0
391 }-
392 return QWidget::event(e);
never executed: return QWidget::event(e);
0
393}-
394-
395/*!\reimp */-
396void QGroupBox::childEvent(QChildEvent *c)-
397{-
398 Q_D(QGroupBox);-
399 if (c->type() != QEvent::ChildAdded || !c->child()->isWidgetType())
c->type() != Q...nt::ChildAddedDescription
TRUEnever evaluated
FALSEnever evaluated
!c->child()->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
0
400 return;
never executed: return;
0
401 QWidget *w = (QWidget*)c->child();-
402 if (w->isWindow())
w->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
403 return;
never executed: return;
0
404 if (d->checkable) {
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
0
405 if (d->checked) {
d->checkedDescription
TRUEnever evaluated
FALSEnever evaluated
0
406 if (!w->testAttribute(Qt::WA_ForceDisabled))
!w->testAttrib...ForceDisabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
407 w->setEnabled(true);
never executed: w->setEnabled(true);
0
408 } else {
never executed: end of block
0
409 if (w->isEnabled()) {
w->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
410 w->setEnabled(false);-
411 w->setAttribute(Qt::WA_ForceDisabled, false);-
412 }
never executed: end of block
0
413 }
never executed: end of block
0
414 }-
415}
never executed: end of block
0
416-
417-
418/*!-
419 \internal-
420-
421 This private slot finds a widget in this group box that can accept-
422 focus, and gives the focus to that widget.-
423*/-
424-
425void QGroupBoxPrivate::_q_fixFocus(Qt::FocusReason reason)-
426{-
427 Q_Q(QGroupBox);-
428 QWidget *fw = q->focusWidget();-
429 if (!fw || fw == q) {
!fwDescription
TRUEnever evaluated
FALSEnever evaluated
fw == qDescription
TRUEnever evaluated
FALSEnever evaluated
0
430 QWidget * best = 0;-
431 QWidget * candidate = 0;-
432 QWidget * w = q;-
433 while ((w = w->nextInFocusChain()) != q) {
(w = w->nextIn...sChain()) != qDescription
TRUEnever evaluated
FALSEnever evaluated
0
434 if (q->isAncestorOf(w) && (w->focusPolicy() & Qt::TabFocus) == Qt::TabFocus && w->isVisibleTo(q)) {
q->isAncestorOf(w)Description
TRUEnever evaluated
FALSEnever evaluated
(w->focusPolic...= Qt::TabFocusDescription
TRUEnever evaluated
FALSEnever evaluated
w->isVisibleTo(q)Description
TRUEnever evaluated
FALSEnever evaluated
0
435 if (!best && qobject_cast<QRadioButton*>(w) && ((QRadioButton*)w)->isChecked())
!bestDescription
TRUEnever evaluated
FALSEnever evaluated
qobject_cast<QRadioButton*>(w)Description
TRUEnever evaluated
FALSEnever evaluated
((QRadioButton...)->isChecked()Description
TRUEnever evaluated
FALSEnever evaluated
0
436 // we prefer a checked radio button or a widget that-
437 // already has focus, if there is one-
438 best = w;
never executed: best = w;
0
439 else-
440 if (!candidate)
!candidateDescription
TRUEnever evaluated
FALSEnever evaluated
0
441 // but we'll accept anything that takes focus-
442 candidate = w;
never executed: candidate = w;
0
443 }
never executed: end of block
0
444 }
never executed: end of block
0
445 if (best)
bestDescription
TRUEnever evaluated
FALSEnever evaluated
0
446 fw = best;
never executed: fw = best;
0
447 else if (candidate)
candidateDescription
TRUEnever evaluated
FALSEnever evaluated
0
448 fw = candidate;
never executed: fw = candidate;
0
449 }
never executed: end of block
0
450 if (fw)
fwDescription
TRUEnever evaluated
FALSEnever evaluated
0
451 fw->setFocus(reason);
never executed: fw->setFocus(reason);
0
452}
never executed: end of block
0
453-
454/*-
455 Sets the right frame rect depending on the title.-
456*/-
457void QGroupBoxPrivate::calculateFrame()-
458{-
459 Q_Q(QGroupBox);-
460 QStyleOptionGroupBox box;-
461 q->initStyleOption(&box);-
462 QRect contentsRect = q->style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxContents, q);-
463 q->setContentsMargins(contentsRect.left() - box.rect.left(), contentsRect.top() - box.rect.top(),-
464 box.rect.right() - contentsRect.right(), box.rect.bottom() - contentsRect.bottom());-
465 setLayoutItemMargins(QStyle::SE_GroupBoxLayoutItem, &box);-
466}
never executed: end of block
0
467-
468/*! \reimp-
469 */-
470void QGroupBox::focusInEvent(QFocusEvent *fe)-
471{ // note no call to super-
472 Q_D(QGroupBox);-
473 if (focusPolicy() == Qt::NoFocus) {
focusPolicy() == Qt::NoFocusDescription
TRUEnever evaluated
FALSEnever evaluated
0
474 d->_q_fixFocus(fe->reason());-
475 } else {
never executed: end of block
0
476 QWidget::focusInEvent(fe);-
477 }
never executed: end of block
0
478}-
479-
480-
481/*!-
482 \reimp-
483*/-
484QSize QGroupBox::minimumSizeHint() const-
485{-
486 Q_D(const QGroupBox);-
487 QStyleOptionGroupBox option;-
488 initStyleOption(&option);-
489-
490 QFontMetrics metrics(fontMetrics());-
491-
492 int baseWidth = metrics.width(d->title) + metrics.width(QLatin1Char(' '));-
493 int baseHeight = metrics.height();-
494 if (d->checkable) {
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
0
495 baseWidth += style()->pixelMetric(QStyle::PM_IndicatorWidth);-
496 baseWidth += style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing);-
497 baseHeight = qMax(baseHeight, style()->pixelMetric(QStyle::PM_IndicatorHeight));-
498 }
never executed: end of block
0
499-
500 QSize size = style()->sizeFromContents(QStyle::CT_GroupBox, &option, QSize(baseWidth, baseHeight), this);-
501 return size.expandedTo(QWidget::minimumSizeHint());
never executed: return size.expandedTo(QWidget::minimumSizeHint());
0
502}-
503-
504/*!-
505 \property QGroupBox::flat-
506 \brief whether the group box is painted flat or has a frame-
507-
508 A group box usually consists of a surrounding frame with a title-
509 at the top. If this property is enabled, only the top part of the frame is-
510 drawn in most styles; otherwise, the whole frame is drawn.-
511-
512 By default, this property is disabled, i.e., group boxes are not flat unless-
513 explicitly specified.-
514-
515 \b{Note:} In some styles, flat and non-flat group boxes have similar-
516 representations and may not be as distinguishable as they are in other-
517 styles.-
518-
519 \sa title-
520*/-
521bool QGroupBox::isFlat() const-
522{-
523 Q_D(const QGroupBox);-
524 return d->flat;
never executed: return d->flat;
0
525}-
526-
527void QGroupBox::setFlat(bool b)-
528{-
529 Q_D(QGroupBox);-
530 if (d->flat == b)
d->flat == bDescription
TRUEnever evaluated
FALSEnever evaluated
0
531 return;
never executed: return;
0
532 d->flat = b;-
533 updateGeometry();-
534 update();-
535}
never executed: end of block
0
536-
537-
538/*!-
539 \property QGroupBox::checkable-
540 \brief whether the group box has a checkbox in its title-
541-
542 If this property is \c true, the group box displays its title using-
543 a checkbox in place of an ordinary label. If the checkbox is checked,-
544 the group box's children are enabled; otherwise, they are disabled and-
545 inaccessible.-
546-
547 By default, group boxes are not checkable.-
548-
549 If this property is enabled for a group box, it will also be initially-
550 checked to ensure that its contents are enabled.-
551-
552 \sa checked-
553*/-
554void QGroupBox::setCheckable(bool checkable)-
555{-
556 Q_D(QGroupBox);-
557-
558 bool wasCheckable = d->checkable;-
559 d->checkable = checkable;-
560-
561 if (checkable) {
checkableDescription
TRUEnever evaluated
FALSEnever evaluated
0
562 setChecked(true);-
563 if (!wasCheckable) {
!wasCheckableDescription
TRUEnever evaluated
FALSEnever evaluated
0
564 setFocusPolicy(Qt::StrongFocus);-
565 d->_q_setChildrenEnabled(true);-
566 updateGeometry();-
567 }
never executed: end of block
0
568 } else {
never executed: end of block
0
569 if (wasCheckable) {
wasCheckableDescription
TRUEnever evaluated
FALSEnever evaluated
0
570 setFocusPolicy(Qt::NoFocus);-
571 d->_q_setChildrenEnabled(true);-
572 updateGeometry();-
573 }
never executed: end of block
0
574 d->_q_setChildrenEnabled(true);-
575 }
never executed: end of block
0
576-
577 if (wasCheckable != checkable) {
wasCheckable != checkableDescription
TRUEnever evaluated
FALSEnever evaluated
0
578 d->calculateFrame();-
579 update();-
580 }
never executed: end of block
0
581}
never executed: end of block
0
582-
583bool QGroupBox::isCheckable() const-
584{-
585 Q_D(const QGroupBox);-
586 return d->checkable;
never executed: return d->checkable;
0
587}-
588-
589-
590bool QGroupBox::isChecked() const-
591{-
592 Q_D(const QGroupBox);-
593 return d->checkable && d->checked;
never executed: return d->checkable && d->checked;
0
594}-
595-
596-
597/*!-
598 \fn void QGroupBox::toggled(bool on)-
599-
600 If the group box is checkable, this signal is emitted when the check box-
601 is toggled. \a on is true if the check box is checked; otherwise, it is false.-
602-
603 \sa checkable-
604*/-
605-
606-
607/*!-
608 \fn void QGroupBox::clicked(bool checked)-
609 \since 4.2-
610-
611 This signal is emitted when the check box is activated (i.e., pressed down-
612 then released while the mouse cursor is inside the button), or when the-
613 shortcut key is typed. Notably, this signal is \e not emitted if you call-
614 setChecked().-
615-
616 If the check box is checked, \a checked is true; it is false if the check-
617 box is unchecked.-
618-
619 \sa checkable, toggled(), checked-
620*/-
621-
622/*!-
623 \property QGroupBox::checked-
624 \brief whether the group box is checked-
625-
626 If the group box is checkable, it is displayed with a check box.-
627 If the check box is checked, the group box's children are enabled;-
628 otherwise, the children are disabled and are inaccessible to the user.-
629-
630 By default, checkable group boxes are also checked.-
631-
632 \sa checkable-
633*/-
634void QGroupBox::setChecked(bool b)-
635{-
636 Q_D(QGroupBox);-
637 if (d->checkable && b != d->checked) {
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
b != d->checkedDescription
TRUEnever evaluated
FALSEnever evaluated
0
638 update();-
639 d->checked = b;-
640 d->_q_setChildrenEnabled(b);-
641#ifndef QT_NO_ACCESSIBILITY-
642 QAccessible::State st;-
643 st.checked = true;-
644 QAccessibleStateChangeEvent e(this, st);-
645 QAccessible::updateAccessibility(&e);-
646#endif-
647 emit toggled(b);-
648 }
never executed: end of block
0
649}
never executed: end of block
0
650-
651/*-
652 sets all children of the group box except the qt_groupbox_checkbox-
653 to either disabled/enabled-
654*/-
655void QGroupBoxPrivate::_q_setChildrenEnabled(bool b)-
656{-
657 Q_Q(QGroupBox);-
658 for (QObject *o : q->children()) {-
659 if (o->isWidgetType()) {
o->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
0
660 QWidget *w = static_cast<QWidget *>(o);-
661 if (b) {
bDescription
TRUEnever evaluated
FALSEnever evaluated
0
662 if (!w->testAttribute(Qt::WA_ForceDisabled))
!w->testAttrib...ForceDisabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
663 w->setEnabled(true);
never executed: w->setEnabled(true);
0
664 } else {
never executed: end of block
0
665 if (w->isEnabled()) {
w->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
666 w->setEnabled(false);-
667 w->setAttribute(Qt::WA_ForceDisabled, false);-
668 }
never executed: end of block
0
669 }
never executed: end of block
0
670 }-
671 }
never executed: end of block
0
672}
never executed: end of block
0
673-
674/*! \reimp */-
675void QGroupBox::changeEvent(QEvent *ev)-
676{-
677 Q_D(QGroupBox);-
678 if (ev->type() == QEvent::EnabledChange) {
ev->type() == ...:EnabledChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
679 if (d->checkable && isEnabled()) {
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
680 // we are being enabled - disable children-
681 if (!d->checked)
!d->checkedDescription
TRUEnever evaluated
FALSEnever evaluated
0
682 d->_q_setChildrenEnabled(false);
never executed: d->_q_setChildrenEnabled(false);
0
683 }
never executed: end of block
0
684 } else if (ev->type() == QEvent::FontChange
never executed: end of block
ev->type() == ...nt::FontChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
685#ifdef Q_OS_MAC-
686 || ev->type() == QEvent::MacSizeChange-
687#endif-
688 || ev->type() == QEvent::StyleChange) {
ev->type() == ...t::StyleChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
689 d->calculateFrame();-
690 }
never executed: end of block
0
691 QWidget::changeEvent(ev);-
692}
never executed: end of block
0
693-
694/*! \reimp */-
695void QGroupBox::mousePressEvent(QMouseEvent *event)-
696{-
697 if (event->button() != Qt::LeftButton) {
event->button(...Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
698 event->ignore();-
699 return;
never executed: return;
0
700 }-
701-
702 Q_D(QGroupBox);-
703 QStyleOptionGroupBox box;-
704 initStyleOption(&box);-
705 d->pressedControl = style()->hitTestComplexControl(QStyle::CC_GroupBox, &box,-
706 event->pos(), this);-
707 if (d->checkable && (d->pressedControl & (QStyle::SC_GroupBoxCheckBox | QStyle::SC_GroupBoxLabel))) {
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
(d->pressedCon...roupBoxLabel))Description
TRUEnever evaluated
FALSEnever evaluated
0
708 d->overCheckBox = true;-
709 update(style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this));-
710 } else {
never executed: end of block
0
711 event->ignore();-
712 }
never executed: end of block
0
713}-
714-
715/*! \reimp */-
716void QGroupBox::mouseMoveEvent(QMouseEvent *event)-
717{-
718 Q_D(QGroupBox);-
719 QStyleOptionGroupBox box;-
720 initStyleOption(&box);-
721 QStyle::SubControl pressed = style()->hitTestComplexControl(QStyle::CC_GroupBox, &box,-
722 event->pos(), this);-
723 bool oldOverCheckBox = d->overCheckBox;-
724 d->overCheckBox = (pressed == QStyle::SC_GroupBoxCheckBox || pressed == QStyle::SC_GroupBoxLabel);
pressed == QSt...oupBoxCheckBoxDescription
TRUEnever evaluated
FALSEnever evaluated
pressed == QSt..._GroupBoxLabelDescription
TRUEnever evaluated
FALSEnever evaluated
0
725 if (d->checkable && (d->pressedControl == QStyle::SC_GroupBoxCheckBox || d->pressedControl == QStyle::SC_GroupBoxLabel)
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
d->pressedCont...oupBoxCheckBoxDescription
TRUEnever evaluated
FALSEnever evaluated
d->pressedCont..._GroupBoxLabelDescription
TRUEnever evaluated
FALSEnever evaluated
0
726 && (d->overCheckBox != oldOverCheckBox))
(d->overCheckB...dOverCheckBox)Description
TRUEnever evaluated
FALSEnever evaluated
0
727 update(style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this));
never executed: update(style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this));
0
728-
729 event->ignore();-
730}
never executed: end of block
0
731-
732/*! \reimp */-
733void QGroupBox::mouseReleaseEvent(QMouseEvent *event)-
734{-
735 if (event->button() != Qt::LeftButton) {
event->button(...Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
736 event->ignore();-
737 return;
never executed: return;
0
738 }-
739-
740 Q_D(QGroupBox);-
741 if (!d->overCheckBox) {
!d->overCheckBoxDescription
TRUEnever evaluated
FALSEnever evaluated
0
742 event->ignore();-
743 return;
never executed: return;
0
744 }-
745 QStyleOptionGroupBox box;-
746 initStyleOption(&box);-
747 QStyle::SubControl released = style()->hitTestComplexControl(QStyle::CC_GroupBox, &box,-
748 event->pos(), this);-
749 bool toggle = d->checkable && (released == QStyle::SC_GroupBoxLabel
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
released == QS..._GroupBoxLabelDescription
TRUEnever evaluated
FALSEnever evaluated
0
750 || released == QStyle::SC_GroupBoxCheckBox);
released == QS...oupBoxCheckBoxDescription
TRUEnever evaluated
FALSEnever evaluated
0
751 d->pressedControl = QStyle::SC_None;-
752 d->overCheckBox = false;-
753 if (toggle)
toggleDescription
TRUEnever evaluated
FALSEnever evaluated
0
754 d->click();
never executed: d->click();
0
755 else if (d->checkable)
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
0
756 update(style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this));
never executed: update(style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this));
0
757}
never executed: end of block
0
758-
759-
760QT_END_NAMESPACE-
761-
762#include "moc_qgroupbox.cpp"-
763-
764#endif //QT_NO_GROUPBOX-
Source codeSwitch to Preprocessed file

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