Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | class QRadioButtonPrivate : public QAbstractButtonPrivate | - |
6 | { | - |
7 | inline QRadioButton* q_func() { return static_cast<QRadioButton *>(q_ptr); } inline const QRadioButton* q_func() const { return static_cast<const QRadioButton *>(q_ptr); } friend class QRadioButton; | - |
8 | | - |
9 | public: | - |
10 | QRadioButtonPrivate() : QAbstractButtonPrivate(QSizePolicy::RadioButton), hovering(true) {} | - |
11 | void init(); | - |
12 | uint hovering : 1; | - |
13 | }; | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | void QRadioButtonPrivate::init() | - |
19 | { | - |
20 | QRadioButton * const q = q_func(); | - |
21 | q->setCheckable(true); | - |
22 | q->setAutoExclusive(true); | - |
23 | q->setMouseTracking(true); | - |
24 | q->setForegroundRole(QPalette::WindowText); | - |
25 | setLayoutItemMargins(QStyle::SE_RadioButtonLayoutItem); | - |
26 | } | - |
27 | QRadioButton::QRadioButton(QWidget *parent) | - |
28 | : QAbstractButton(*new QRadioButtonPrivate, parent) | - |
29 | { | - |
30 | QRadioButtonPrivate * const d = d_func(); | - |
31 | d->init(); | - |
32 | } | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | QRadioButton::~QRadioButton() | - |
38 | { | - |
39 | } | - |
40 | | - |
41 | | - |
42 | | - |
43 | | - |
44 | | - |
45 | | - |
46 | | - |
47 | QRadioButton::QRadioButton(const QString &text, QWidget *parent) | - |
48 | : QAbstractButton(*new QRadioButtonPrivate, parent) | - |
49 | { | - |
50 | QRadioButtonPrivate * const d = d_func(); | - |
51 | d->init(); | - |
52 | setText(text); | - |
53 | } | - |
54 | void QRadioButton::initStyleOption(QStyleOptionButton *option) const | - |
55 | { | - |
56 | if (!optionTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
57 | return; never executed: return; | 0 |
58 | const QRadioButtonPrivate * const d = d_func(); | - |
59 | option->initFrom(this); | - |
60 | option->text = d->text; | - |
61 | option->icon = d->icon; | - |
62 | option->iconSize = iconSize(); | - |
63 | if (d->downTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
64 | option->state |= QStyle::State_Sunken; never executed: option->state |= QStyle::State_Sunken; | 0 |
65 | option->state |= (TRUE | never evaluated | FALSE | never evaluated |
d->checked)TRUE | never evaluated | FALSE | never evaluated |
? QStyle::State_On : QStyle::State_Off; | 0 |
66 | if (testAttribute(Qt::WA_Hover)TRUE | never evaluated | FALSE | never evaluated |
&& underMouse()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
67 | if (d->hovering)option->state|=.setFlag(QStyle::State_MouseOver; | - |
| else | |
| option, d->state &= ~QStyle::State_MouseOver;hovering); | |
68 | } never executed: end of block | 0 |
69 | } never executed: end of block | 0 |
70 | | - |
71 | | - |
72 | | - |
73 | | - |
74 | QSize QRadioButton::sizeHint() const | - |
75 | { | - |
76 | const QRadioButtonPrivate * const d = d_func(); | - |
77 | if (d->sizeHint.isValid()) | - |
78 | return d->sizeHint; | - |
79 | ensurePolished(); | - |
80 | QStyleOptionButton opt; | - |
81 | initStyleOption(&opt); | - |
82 | QSize sz = style()->itemTextRect(fontMetrics(), QRect(), Qt::TextShowMnemonic, | - |
83 | false, text()).size(); | - |
84 | if (!opt.icon.isNull()) | - |
85 | sz = QSize(sz.width() + opt.iconSize.width() + 4, qMax(sz.height(), opt.iconSize.height())); | - |
86 | d->sizeHint = (style()->sizeFromContents(QStyle::CT_RadioButton, &opt, sz, this). | - |
87 | expandedTo(QApplication::globalStrut())); | - |
88 | return d->sizeHint; | - |
89 | } | - |
90 | | - |
91 | | - |
92 | | - |
93 | | - |
94 | QSize QRadioButton::minimumSizeHint() const | - |
95 | { | - |
96 | return sizeHint(); | - |
97 | } | - |
98 | | - |
99 | | - |
100 | | - |
101 | | - |
102 | bool QRadioButton::hitButton(const QPoint &pos) const | - |
103 | { | - |
104 | QStyleOptionButton opt; | - |
105 | initStyleOption(&opt); | - |
106 | return style()->subElementRect(QStyle::SE_RadioButtonClickRect, &opt, this).contains(pos); | - |
107 | } | - |
108 | | - |
109 | | - |
110 | | - |
111 | | - |
112 | void QRadioButton::mouseMoveEvent(QMouseEvent *e) | - |
113 | { | - |
114 | QRadioButtonPrivate * const d = d_func(); | - |
115 | if (testAttribute(Qt::WA_Hover)) { | - |
116 | bool hit = false; | - |
117 | if (underMouse()) | - |
118 | hit = hitButton(e->pos()); | - |
119 | | - |
120 | if (hit != d->hovering) { | - |
121 | update(); | - |
122 | d->hovering = hit; | - |
123 | } | - |
124 | } | - |
125 | | - |
126 | QAbstractButton::mouseMoveEvent(e); | - |
127 | } | - |
128 | | - |
129 | | - |
130 | | - |
131 | void QRadioButton::paintEvent(QPaintEvent *) | - |
132 | { | - |
133 | QStylePainter p(this); | - |
134 | QStyleOptionButton opt; | - |
135 | initStyleOption(&opt); | - |
136 | p.drawControl(QStyle::CE_RadioButton, opt); | - |
137 | } | - |
138 | | - |
139 | | - |
140 | bool QRadioButton::event(QEvent *e) | - |
141 | { | - |
142 | QRadioButtonPrivate * const d = d_func(); | - |
143 | if (e->type() == QEvent::StyleChange | - |
144 | | - |
145 | | - |
146 | | - |
147 | ) | - |
148 | d->setLayoutItemMargins(QStyle::SE_RadioButtonLayoutItem); | - |
149 | return QAbstractButton::event(e); | - |
150 | } | - |
151 | | - |
152 | | - |
153 | | - |
154 | | - |
| | |