qpushbutton.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qpushbutton.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11QPushButton::QPushButton(QWidget *parent)-
12 : QAbstractButton(*new QPushButtonPrivate, parent)-
13{-
14 QPushButtonPrivate * const d = d_func();-
15 d->init();-
16}
never executed: end of block
0
17-
18-
19-
20-
21-
22-
23QPushButton::QPushButton(const QString &text, QWidget *parent)-
24 : QAbstractButton(*new QPushButtonPrivate, parent)-
25{-
26 QPushButtonPrivate * const d = d_func();-
27 setText(text);-
28 d->init();-
29}
never executed: end of block
0
30QPushButton::QPushButton(const QIcon& icon, const QString &text, QWidget *parent)-
31 : QAbstractButton(*new QPushButtonPrivate, parent)-
32{-
33 QPushButtonPrivate * const d = d_func();-
34 setText(text);-
35 setIcon(icon);-
36 d->init();-
37}
never executed: end of block
0
38-
39-
40-
41QPushButton::QPushButton(QPushButtonPrivate &dd, QWidget *parent)-
42 : QAbstractButton(dd, parent)-
43{-
44 QPushButtonPrivate * const d = d_func();-
45 d->init();-
46}
never executed: end of block
0
47-
48-
49-
50-
51QPushButton::~QPushButton()-
52{-
53}-
54-
55QDialog *QPushButtonPrivate::dialogParent() const-
56{-
57 const QPushButton * const q = q_func();-
58 const QWidget *p = q;-
59 while (p
pDescription
TRUEnever evaluated
FALSEnever evaluated
&& !p->isWindow()
!p->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
60 p = p->parentWidget();-
61 if (const
const QDialog ... QDialog *>(p)Description
TRUEnever evaluated
FALSEnever evaluated
QDialog *dialog = qobject_cast<const QDialog *>(p)
const QDialog ... QDialog *>(p)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
62 return
never executed: return const_cast<QDialog *>(dialog);
const_cast<QDialog *>(dialog);
never executed: return const_cast<QDialog *>(dialog);
0
63 }
never executed: end of block
0
64 return
never executed: return 0;
0;
never executed: return 0;
0
65}-
66void QPushButton::initStyleOption(QStyleOptionButton *option) const-
67{-
68 if (!option
!optionDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
69 return;
never executed: return;
0
70-
71 const QPushButtonPrivate * const d = d_func();-
72 option->initFrom(this);-
73 option->features = QStyleOptionButton::None;-
74 if (d->flat
d->flatDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
75 option->features |= QStyleOptionButton::Flat;
never executed: option->features |= QStyleOptionButton::Flat;
0
76-
77 if (d->menu
d->menuDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
78 option->features |= QStyleOptionButton::HasMenu;
never executed: option->features |= QStyleOptionButton::HasMenu;
0
79-
80 if (autoDefault()
autoDefault()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
81 option->features |= QStyleOptionButton::AutoDefaultButton;
never executed: option->features |= QStyleOptionButton::AutoDefaultButton;
0
82 if (d->defaultButton
d->defaultButtonDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
83 option->features |= QStyleOptionButton::DefaultButton;
never executed: option->features |= QStyleOptionButton::DefaultButton;
0
84 if (d->down
d->downDescription
TRUEnever evaluated
FALSEnever evaluated
|| d->menuOpen
d->menuOpenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
85 option->state |= QStyle::State_Sunken;
never executed: option->state |= QStyle::State_Sunken;
0
86 if (d->checked
d->checkedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
87 option->state |= QStyle::State_On;
never executed: option->state |= QStyle::State_On;
0
88 if (!d->flat
!d->flatDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->down
!d->downDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
89 option->state |= QStyle::State_Raised;
never executed: option->state |= QStyle::State_Raised;
0
90 option->text = d->text;-
91 option->icon = d->icon;-
92 option->iconSize = iconSize();-
93}
never executed: end of block
0
94-
95void QPushButton::setAutoDefault(bool enable)-
96{-
97 QPushButtonPrivate * const d = d_func();-
98 uint state = enable
enableDescription
TRUEnever evaluated
FALSEnever evaluated
? QPushButtonPrivate::On : QPushButtonPrivate::Off;
0
99 if (d->autoDefault != QPushButtonPrivate::Auto
d->autoDefault...nPrivate::AutoDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->autoDefault == state
d->autoDefault == stateDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
100 return;
never executed: return;
0
101 d->autoDefault = state;-
102 d->sizeHint = QSize();-
103 update();-
104 updateGeometry();-
105}
never executed: end of block
0
106-
107bool QPushButton::autoDefault() const-
108{-
109 const QPushButtonPrivate * const d = d_func();-
110 if(d->autoDefault == QPushButtonPrivate::Auto
d->autoDefault...nPrivate::AutoDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
111 return
never executed: return ( d->dialogParent() != 0 );
( d->dialogParent() != 0 );
never executed: return ( d->dialogParent() != 0 );
0
112 return
never executed: return d->autoDefault;
d->autoDefault;
never executed: return d->autoDefault;
0
113}-
114-
115void QPushButton::setDefault(bool enable)-
116{-
117 QPushButtonPrivate * const d = d_func();-
118 if (d->defaultButton == enable
d->defaultButton == enableDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
119 return;
never executed: return;
0
120 d->defaultButton = enable;-
121 if (d->defaultButton
d->defaultButtonDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
122 if (QDialog *dlg = d->dialogParent()
QDialog *dlg =...dialogParent()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
123 dlg->d_func()->setMainDefault(this);
never executed: dlg->d_func()->setMainDefault(this);
0
124 }
never executed: end of block
0
125 update();-
126-
127 QAccessible::State s;-
128 s.defaultButton = true;-
129 QAccessibleStateChangeEvent event(this, s);-
130 QAccessible::updateAccessibility(&event);-
131-
132}
never executed: end of block
0
133-
134bool QPushButton::isDefault() const-
135{-
136 const QPushButtonPrivate * const d = d_func();-
137 return
never executed: return d->defaultButton;
d->defaultButton;
never executed: return d->defaultButton;
0
138}-
139-
140-
141-
142-
143QSize QPushButton::sizeHint() const-
144{-
145 const QPushButtonPrivate * const d = d_func();-
146 if (d->sizeHint.isValid()
d->sizeHint.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
&& d->lastAutoDefault == autoDefault()
d->lastAutoDef... autoDefault()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
147 return
never executed: return d->sizeHint;
d->sizeHint;
never executed: return d->sizeHint;
0
148 d->lastAutoDefault = autoDefault();-
149 ensurePolished();-
150-
151 int w = 0, h = 0;-
152-
153 QStyleOptionButton opt;-
154 initStyleOption(&opt);-
155-
156-
157-
158-
159 bool showButtonBoxIcons = qobject_cast<QDialogButtonBox*>(parentWidget())
qobject_cast<Q...arentWidget())Description
TRUEnever evaluated
FALSEnever evaluated
0
160 && style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons)
style()->style...tonsHaveIcons)Description
TRUEnever evaluated
FALSEnever evaluated
;
0
161-
162 if (!icon().isNull()
!icon().isNull()Description
TRUEnever evaluated
FALSEnever evaluated
|| showButtonBoxIcons
showButtonBoxIconsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
163 int ih = opt.iconSize.height();-
164 int iw = opt.iconSize.width() + 4;-
165 w += iw;-
166 h = qMax(h, ih);-
167 }
never executed: end of block
0
168-
169 QString s(text());-
170 bool empty = s.isEmpty();-
171 if (empty
emptyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
172 s = QString::fromLatin1("XXXX");
never executed: s = QString::fromLatin1("XXXX");
0
173 QFontMetrics fm = fontMetrics();-
174 QSize sz = fm.size(Qt::TextShowMnemonic, s);-
175 if(!empty
!emptyDescription
TRUEnever evaluated
FALSEnever evaluated
|| !w
!wDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
176 w += sz.width();
never executed: w += sz.width();
0
177 if(!empty
!emptyDescription
TRUEnever evaluated
FALSEnever evaluated
|| !h
!hDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
178 h = qMax(h, sz.height());
never executed: h = qMax(h, sz.height());
0
179 opt.rect.setSize(QSize(w, h));-
180-
181 if (menu()
menu()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
182 w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this);
never executed: w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this);
0
183-
184 d->sizeHint = (style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), this).-
185 expandedTo(QApplication::globalStrut()));-
186 return
never executed: return d->sizeHint;
d->sizeHint;
never executed: return d->sizeHint;
0
187}-
188-
189-
190-
191-
192QSize QPushButton::minimumSizeHint() const-
193{-
194 return
never executed: return sizeHint();
sizeHint();
never executed: return sizeHint();
0
195}-
196-
197-
198-
199-
200void QPushButton::paintEvent(QPaintEvent *)-
201{-
202 QStylePainter p(this);-
203 QStyleOptionButton option;-
204 initStyleOption(&option);-
205 p.drawControl(QStyle::CE_PushButton, option);-
206}
never executed: end of block
0
207-
208-
209-
210void QPushButton::keyPressEvent(QKeyEvent *e)-
211{-
212 QPushButtonPrivate * const d = d_func();-
213 switch (e->key()) {-
214 case
never executed: case Qt::Key_Enter:
Qt::Key_Enter:
never executed: case Qt::Key_Enter:
0
215 case
never executed: case Qt::Key_Return:
Qt::Key_Return:
never executed: case Qt::Key_Return:
0
216 if (autoDefault()
autoDefault()Description
TRUEnever evaluated
FALSEnever evaluated
|| d->defaultButton
d->defaultButtonDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
217 click();-
218 break;
never executed: break;
0
219 }-
220-
221 default
never executed: default:
:
never executed: default:
code before this statement never executed: default:
0
222 QAbstractButton::keyPressEvent(e);-
223 }
never executed: end of block
0
224}-
225-
226-
227-
228-
229void QPushButton::focusInEvent(QFocusEvent *e)-
230{-
231 QPushButtonPrivate * const d = d_func();-
232 if (e->reason() != Qt::PopupFocusReason
e->reason() !=...pupFocusReasonDescription
TRUEnever evaluated
FALSEnever evaluated
&& autoDefault()
autoDefault()Description
TRUEnever evaluated
FALSEnever evaluated
&& !d->defaultButton
!d->defaultButtonDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
233 d->defaultButton = true;-
234 QDialog *dlg = qobject_cast<QDialog*>(window());-
235 if (dlg
dlgDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
236 dlg->d_func()->setDefault(this);
never executed: dlg->d_func()->setDefault(this);
0
237 }
never executed: end of block
0
238 QAbstractButton::focusInEvent(e);-
239}
never executed: end of block
0
240-
241-
242-
243-
244void QPushButton::focusOutEvent(QFocusEvent *e)-
245{-
246 QPushButtonPrivate * const d = d_func();-
247 if (e->reason() != Qt::PopupFocusReason
e->reason() !=...pupFocusReasonDescription
TRUEnever evaluated
FALSEnever evaluated
&& autoDefault()
autoDefault()Description
TRUEnever evaluated
FALSEnever evaluated
&& d->defaultButton
d->defaultButtonDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
248 QDialog *dlg = qobject_cast<QDialog*>(window());-
249 if (dlg
dlgDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
250 dlg->d_func()->setDefault(0);
never executed: dlg->d_func()->setDefault(0);
0
251 else-
252 d->defaultButton = false;
never executed: d->defaultButton = false;
0
253 }-
254-
255 QAbstractButton::focusOutEvent(e);-
256-
257 if (d->menu
d->menuDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->menu->isVisible()
d->menu->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
258 setDown(true);
never executed: setDown(true);
0
259-
260}
never executed: end of block
0
261void QPushButton::setMenu(QMenu* menu)-
262{-
263 QPushButtonPrivate * const d = d_func();-
264 if (menu == d->menu
menu == d->menuDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
265 return;
never executed: return;
0
266-
267 if (menu
menuDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->menu
!d->menuDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
268 connect(this, qFlagLocation("2""pressed()" "\0" __FILE__ ":" "532"), this, qFlagLocation("1""_q_popupPressed()" "\0" __FILE__ ":" "532"), Qt::UniqueConnection);-
269 }
never executed: end of block
0
270 if (d->menu
d->menuDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
271 removeAction(d->menu->menuAction());
never executed: removeAction(d->menu->menuAction());
0
272 d->menu = menu;-
273 if (d->menu
d->menuDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
274 addAction(d->menu->menuAction());
never executed: addAction(d->menu->menuAction());
0
275-
276 d->resetLayoutItemMargins();-
277 d->sizeHint = QSize();-
278 update();-
279 updateGeometry();-
280}
never executed: end of block
0
281-
282-
283-
284-
285-
286-
287-
288QMenu* QPushButton::menu() const-
289{-
290 const QPushButtonPrivate * const d = d_func();-
291 return
never executed: return d->menu;
d->menu;
never executed: return d->menu;
0
292}-
293-
294-
295-
296-
297-
298-
299void QPushButton::showMenu()-
300{-
301 QPushButtonPrivate * const d = d_func();-
302 if (!d
!dDescription
TRUEnever evaluated
FALSEnever evaluated
|| !d->menu
!d->menuDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
303 return;
never executed: return;
0
304 setDown(true);-
305 d->_q_popupPressed();-
306}
never executed: end of block
0
307-
308void QPushButtonPrivate::_q_popupPressed()-
309{-
310 QPushButton * const q = q_func();-
311 if (!down
!downDescription
TRUEnever evaluated
FALSEnever evaluated
|| !menu
!menuDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
312 return;
never executed: return;
0
313-
314 menu->setNoReplayFor(q);-
315-
316 QPoint menuPos = adjustedMenuPosition();-
317-
318 QPointer<QPushButton> guard(q);-
319 QMenuPrivate::get(menu)->causedPopup.widget = guard;-
320-
321-
322-
323 menuOpen = true;-
324 menu->exec(menuPos);-
325 if (guard
guardDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
326 menuOpen = false;-
327 q->setDown(false);-
328 }
never executed: end of block
0
329}
never executed: end of block
0
330-
331QPoint QPushButtonPrivate::adjustedMenuPosition()-
332{-
333 QPushButton * const q = q_func();-
334-
335 bool horizontal = true;-
336-
337 QToolBar *tb = qobject_cast<QToolBar*>(parent);-
338 if (tb
tbDescription
TRUEnever evaluated
FALSEnever evaluated
&& tb->orientation() == Qt::Vertical
tb->orientatio...= Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
339 horizontal = false;
never executed: horizontal = false;
0
340-
341-
342 QWidgetItem item(q);-
343 QRect rect = item.geometry();-
344 rect.setRect(rect.x() - q->x(), rect.y() - q->y(), rect.width(), rect.height());-
345-
346 QSize menuSize = menu->sizeHint();-
347 QPoint globalPos = q->mapToGlobal(rect.topLeft());-
348 int x = globalPos.x();-
349 int y = globalPos.y();-
350 if (horizontal
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
351 if (globalPos.y() + rect.height() + menuSize.height() <= QApplication::desktop()->availableGeometry(q).height()
globalPos.y() ...ry(q).height()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
352 y += rect.height();-
353 }
never executed: end of block
else {
0
354 y -= menuSize.height();-
355 }
never executed: end of block
0
356 if (q->layoutDirection() == Qt::RightToLeft
q->layoutDirec...t::RightToLeftDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
357 x += rect.width() - menuSize.width();
never executed: x += rect.width() - menuSize.width();
0
358 }
never executed: end of block
else {
0
359 if (globalPos.x() + rect.width() + menu->sizeHint().width() <= QApplication::desktop()->availableGeometry(q).width()
globalPos.x() ...try(q).width()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
360 x += rect.width();
never executed: x += rect.width();
0
361 else-
362 x -= menuSize.width();
never executed: x -= menuSize.width();
0
363 }-
364-
365 return
never executed: return QPoint(x,y);
QPoint(x,y);
never executed: return QPoint(x,y);
0
366}-
367-
368-
369-
370void QPushButtonPrivate::resetLayoutItemMargins()-
371{-
372 QPushButton * const q = q_func();-
373 QStyleOptionButton opt;-
374 q->initStyleOption(&opt);-
375 setLayoutItemMargins(QStyle::SE_PushButtonLayoutItem, &opt);-
376}
never executed: end of block
0
377-
378void QPushButton::setFlat(bool flat)-
379{-
380 QPushButtonPrivate * const d = d_func();-
381 if (d->flat == flat
d->flat == flatDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
382 return;
never executed: return;
0
383 d->flat = flat;-
384 d->resetLayoutItemMargins();-
385 d->sizeHint = QSize();-
386 update();-
387 updateGeometry();-
388}
never executed: end of block
0
389-
390bool QPushButton::isFlat() const-
391{-
392 const QPushButtonPrivate * const d = d_func();-
393 return
never executed: return d->flat;
d->flat;
never executed: return d->flat;
0
394}-
395-
396-
397bool QPushButton::event(QEvent *e)-
398{-
399 QPushButtonPrivate * const d = d_func();-
400 if (e->type() == QEvent::ParentChange
e->type() == Q...::ParentChangeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
401 if (QDialog *dialog = d->dialogParent()
QDialog *dialo...dialogParent()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
402 if (d->defaultButton
d->defaultButtonDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
403 dialog->d_func()->setMainDefault(this);
never executed: dialog->d_func()->setMainDefault(this);
0
404 }
never executed: end of block
0
405 }
never executed: end of block
else if (e->type() == QEvent::StyleChange
e->type() == Q...t::StyleChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
406-
407-
408-
409 ) {-
410 d->resetLayoutItemMargins();-
411 updateGeometry();-
412 }
never executed: end of block
else if (e->type() == QEvent::PolishRequest
e->type() == Q...:PolishRequestDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
413 updateGeometry();-
414 }
never executed: end of block
0
415 return
never executed: return QAbstractButton::event(e);
QAbstractButton::event(e);
never executed: return QAbstractButton::event(e);
0
416}-
417-
418-
Switch to Source codePreprocessed file

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