qcommandlinkbutton.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qcommandlinkbutton.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4class QCommandLinkButtonPrivate : public QPushButtonPrivate-
5{-
6 inline QCommandLinkButton* q_func() { return static_cast<QCommandLinkButton *>(q_ptr); } inline const QCommandLinkButton* q_func() const { return static_cast<const QCommandLinkButton *>(q_ptr); } friend class QCommandLinkButton;-
7-
8public:-
9 QCommandLinkButtonPrivate()-
10 : QPushButtonPrivate(){}
never executed: end of block
0
11-
12 void init();-
13 qreal titleSize() const;-
14 bool usingVistaStyle() const;-
15-
16 QFont titleFont() const;-
17 QFont descriptionFont() const;-
18-
19 QRect titleRect() const;-
20 QRect descriptionRect() const;-
21-
22 int textOffset() const;-
23 int descriptionOffset() const;-
24 int descriptionHeight(int width) const;-
25 QColor mergedColors(const QColor &a, const QColor &b, int value) const;-
26-
27 int topMargin() const { return
never executed: return 10;
10;
never executed: return 10;
}
0
28 int leftMargin() const { return
never executed: return 7;
7;
never executed: return 7;
}
0
29 int rightMargin() const { return
never executed: return 4;
4;
never executed: return 4;
}
0
30 int bottomMargin() const { return
never executed: return 10;
10;
never executed: return 10;
}
0
31-
32 QString description;-
33 QColor currentColor;-
34};-
35-
36-
37QColor QCommandLinkButtonPrivate::mergedColors(const QColor &a, const QColor &b, int value = 50) const-
38{-
39 ((!(value >= 0)) ? qt_assert("value >= 0",__FILE__,128) : qt_noop());-
40 ((!(value <= 255)) ? qt_assert("value <= 255",__FILE__,129) : qt_noop());-
41 QColor tmp = a;-
42 tmp.setRed((tmp.red() * value) / 255 + (b.red() * (255 - value)) / 255);-
43 tmp.setGreen((tmp.green() * value) / 255 + (b.green() * (255 - value)) / 255);-
44 tmp.setBlue((tmp.blue() * value) / 255 + (b.blue() * (255 - value)) / 255);-
45 return
never executed: return tmp;
tmp;
never executed: return tmp;
0
46}-
47-
48QFont QCommandLinkButtonPrivate::titleFont() const-
49{-
50 const QCommandLinkButton * const q = q_func();-
51 QFont font = q->font();-
52 if (usingVistaStyle()
usingVistaStyle()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
53 font.setPointSizeF(12.0);-
54 }
never executed: end of block
else {
0
55 font.setBold(true);-
56 font.setPointSizeF(9.0);-
57 }
never executed: end of block
0
58-
59-
60-
61 int resolve_mask = font.resolve_mask;-
62 QFont modifiedFont = q->font().resolve(font);-
63 modifiedFont.detach();-
64 modifiedFont.resolve_mask = resolve_mask;-
65 return
never executed: return modifiedFont;
modifiedFont;
never executed: return modifiedFont;
0
66}-
67-
68QFont QCommandLinkButtonPrivate::descriptionFont() const-
69{-
70 const QCommandLinkButton * const q = q_func();-
71 QFont font = q->font();-
72 font.setPointSizeF(9.0);-
73-
74-
75-
76 int resolve_mask = font.resolve_mask;-
77 QFont modifiedFont = q->font().resolve(font);-
78 modifiedFont.detach();-
79 modifiedFont.resolve_mask = resolve_mask;-
80 return
never executed: return modifiedFont;
modifiedFont;
never executed: return modifiedFont;
0
81}-
82-
83QRect QCommandLinkButtonPrivate::titleRect() const-
84{-
85 const QCommandLinkButton * const q = q_func();-
86 QRect r = q->rect().adjusted(textOffset(), topMargin(), -rightMargin(), 0);-
87 if (description.isEmpty()
description.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
88 {-
89 QFontMetrics fm(titleFont());-
90 r.setTop(r.top() + qMax(0, (q->icon().actualSize(q->iconSize()).height()-
91 - fm.height()) / 2));-
92 }
never executed: end of block
0
93-
94 return
never executed: return r;
r;
never executed: return r;
0
95}-
96-
97QRect QCommandLinkButtonPrivate::descriptionRect() const-
98{-
99 const QCommandLinkButton * const q = q_func();-
100 return
never executed: return q->rect().adjusted(textOffset(), descriptionOffset(), -rightMargin(), -bottomMargin());
q->rect().adjusted(textOffset(), descriptionOffset(),
never executed: return q->rect().adjusted(textOffset(), descriptionOffset(), -rightMargin(), -bottomMargin());
0
101 -rightMargin(), -bottomMargin());
never executed: return q->rect().adjusted(textOffset(), descriptionOffset(), -rightMargin(), -bottomMargin());
0
102}-
103-
104int QCommandLinkButtonPrivate::textOffset() const-
105{-
106 const QCommandLinkButton * const q = q_func();-
107 return
never executed: return q->icon().actualSize(q->iconSize()).width() + leftMargin() + 6;
q->icon().actualSize(q->iconSize()).width() + leftMargin() + 6;
never executed: return q->icon().actualSize(q->iconSize()).width() + leftMargin() + 6;
0
108}-
109-
110int QCommandLinkButtonPrivate::descriptionOffset() const-
111{-
112 QFontMetrics fm(titleFont());-
113 return
never executed: return topMargin() + fm.height();
topMargin() + fm.height();
never executed: return topMargin() + fm.height();
0
114}-
115-
116bool QCommandLinkButtonPrivate::usingVistaStyle() const-
117{-
118 const QCommandLinkButton * const q = q_func();-
119-
120-
121 return
never executed: return q->style()->inherits("QWindowsVistaStyle") && !q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal);
q->style()->inherits("QWindowsVistaStyle")
never executed: return q->style()->inherits("QWindowsVistaStyle") && !q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal);
0
122 && !q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal);
never executed: return q->style()->inherits("QWindowsVistaStyle") && !q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal);
0
123}-
124-
125void QCommandLinkButtonPrivate::init()-
126{-
127 QCommandLinkButton * const q = q_func();-
128 QPushButtonPrivate::init();-
129 q->setAttribute(Qt::WA_Hover);-
130-
131 QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::PushButton);-
132 policy.setHeightForWidth(true);-
133 q->setSizePolicy(policy);-
134-
135 q->setIconSize(QSize(20, 20));-
136 QStyleOptionButton opt;-
137 q->initStyleOption(&opt);-
138 q->setIcon(q->style()->standardIcon(QStyle::SP_CommandLink, &opt));-
139}
never executed: end of block
0
140-
141-
142int QCommandLinkButtonPrivate::descriptionHeight(int widgetWidth) const-
143{-
144-
145 int lineWidth = widgetWidth - textOffset() - rightMargin();-
146-
147 qreal descriptionheight = 0;-
148 if (!description.isEmpty()
!description.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
149 QTextLayout layout(description);-
150 layout.setFont(descriptionFont());-
151 layout.beginLayout();-
152 while (true) {-
153 QTextLine line = layout.createLine();-
154 if (!line.isValid()
!line.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
155 break;
never executed: break;
0
156 line.setLineWidth(lineWidth);-
157 line.setPosition(QPointF(0, descriptionheight));-
158 descriptionheight += line.height();-
159 }
never executed: end of block
0
160 layout.endLayout();-
161 }
never executed: end of block
0
162 return
never executed: return qCeil(descriptionheight);
qCeil(descriptionheight);
never executed: return qCeil(descriptionheight);
0
163}-
164-
165-
166-
167-
168QSize QCommandLinkButton::minimumSizeHint() const-
169{-
170 const QCommandLinkButtonPrivate * const d = d_func();-
171 QSize size = sizeHint();-
172 int minimumHeight = qMax(d->descriptionOffset() + d->bottomMargin(),-
173 icon().actualSize(iconSize()).height() + d->topMargin());-
174 size.setHeight(minimumHeight);-
175 return
never executed: return size;
size;
never executed: return size;
0
176}-
177-
178-
179-
180-
181-
182QCommandLinkButton::QCommandLinkButton(QWidget *parent)-
183: QPushButton(*new QCommandLinkButtonPrivate, parent)-
184{-
185 QCommandLinkButtonPrivate * const d = d_func();-
186 d->init();-
187}
never executed: end of block
0
188-
189-
190-
191-
192-
193-
194QCommandLinkButton::QCommandLinkButton(const QString &text, QWidget *parent)-
195 : QPushButton(*new QCommandLinkButtonPrivate, parent)-
196{-
197 QCommandLinkButtonPrivate * const d = d_func();-
198 setText(text);-
199 d->init();-
200}
never executed: end of block
0
201-
202-
203-
204-
205QCommandLinkButton::QCommandLinkButton(const QString &text, const QString &description, QWidget *parent)-
206 : QPushButton(*new QCommandLinkButtonPrivate, parent)-
207{-
208 QCommandLinkButtonPrivate * const d = d_func();-
209 setText(text);-
210 setDescription(description);-
211 d->init();-
212}
never executed: end of block
0
213-
214-
215-
216-
217QCommandLinkButton::~QCommandLinkButton()-
218{-
219}-
220-
221-
222bool QCommandLinkButton::event(QEvent *e)-
223{-
224 return
never executed: return QPushButton::event(e);
QPushButton::event(e);
never executed: return QPushButton::event(e);
0
225}-
226-
227-
228QSize QCommandLinkButton::sizeHint() const-
229{-
230-
231-
232-
233 const QCommandLinkButtonPrivate * const d = d_func();-
234-
235 QSize size = QPushButton::sizeHint();-
236 QFontMetrics fm(d->titleFont());-
237 int textWidth = qMax(fm.width(text()), 135);-
238 int buttonWidth = textWidth + d->textOffset() + d->rightMargin();-
239 int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin();-
240-
241 size.setWidth(qMax(size.width(), buttonWidth));-
242 size.setHeight(qMax(d->description.isEmpty() ? 41 : 60,-
243 heightWithoutDescription + d->descriptionHeight(buttonWidth)));-
244 return
never executed: return size;
size;
never executed: return size;
0
245}-
246-
247-
248int QCommandLinkButton::heightForWidth(int width) const-
249{-
250 const QCommandLinkButtonPrivate * const d = d_func();-
251 int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin();-
252-
253 return
never executed: return qMax(heightWithoutDescription + d->descriptionHeight(width), icon().actualSize(iconSize()).height() + d->topMargin() + d->bottomMargin());
qMax(heightWithoutDescription + d->descriptionHeight(width),
never executed: return qMax(heightWithoutDescription + d->descriptionHeight(width), icon().actualSize(iconSize()).height() + d->topMargin() + d->bottomMargin());
0
254 icon().actualSize(iconSize()).height() + d->topMargin() +
never executed: return qMax(heightWithoutDescription + d->descriptionHeight(width), icon().actualSize(iconSize()).height() + d->topMargin() + d->bottomMargin());
0
255 d->bottomMargin());
never executed: return qMax(heightWithoutDescription + d->descriptionHeight(width), icon().actualSize(iconSize()).height() + d->topMargin() + d->bottomMargin());
0
256}-
257-
258-
259void QCommandLinkButton::paintEvent(QPaintEvent *)-
260{-
261 QCommandLinkButtonPrivate * const d = d_func();-
262 QStylePainter p(this);-
263 p.save();-
264-
265 QStyleOptionButton option;-
266 initStyleOption(&option);-
267-
268-
269 option.features |= QStyleOptionButton::CommandLinkButton;-
270 option.text = QString();-
271 option.icon = QIcon();-
272 QSize pixmapSize = icon().actualSize(iconSize());-
273-
274 int vOffset = isDown()
isDown()Description
TRUEnever evaluated
FALSEnever evaluated
? style()->pixelMetric(QStyle::PM_ButtonShiftVertical) : 0;
0
275 int hOffset = isDown()
isDown()Description
TRUEnever evaluated
FALSEnever evaluated
? style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal) : 0;
0
276-
277-
278 p.drawControl(QStyle::CE_PushButton, option);-
279 if (!icon().isNull()
!icon().isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
280 p.drawPixmap(d->leftMargin() + hOffset, d->topMargin() + vOffset,
never executed: p.drawPixmap(d->leftMargin() + hOffset, d->topMargin() + vOffset, icon().pixmap(pixmapSize, isEnabled() ? QIcon::Normal : QIcon::Disabled, isChecked() ? QIcon::On : QIcon::Off));
0
281 icon().pixmap(pixmapSize, isEnabled() ? QIcon::Normal : QIcon::Disabled,
never executed: p.drawPixmap(d->leftMargin() + hOffset, d->topMargin() + vOffset, icon().pixmap(pixmapSize, isEnabled() ? QIcon::Normal : QIcon::Disabled, isChecked() ? QIcon::On : QIcon::Off));
0
282 isChecked() ? QIcon::On : QIcon::Off));
never executed: p.drawPixmap(d->leftMargin() + hOffset, d->topMargin() + vOffset, icon().pixmap(pixmapSize, isEnabled() ? QIcon::Normal : QIcon::Disabled, isChecked() ? QIcon::On : QIcon::Off));
0
283-
284-
285 QColor textColor = palette().buttonText().color();-
286 if (isEnabled()
isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
&& d->usingVistaStyle()
d->usingVistaStyle()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
287 textColor = QColor(21, 28, 85);-
288 if (underMouse()
underMouse()Description
TRUEnever evaluated
FALSEnever evaluated
&& !isDown()
!isDown()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
289 textColor = QColor(7, 64, 229);
never executed: textColor = QColor(7, 64, 229);
0
290-
291 d->currentColor = d->mergedColors(textColor, d->currentColor, 60);-
292 option.palette.setColor(QPalette::ButtonText, d->currentColor);-
293 }
never executed: end of block
0
294-
295 int textflags = Qt::TextShowMnemonic;-
296 if (!style()->styleHint(QStyle::SH_UnderlineShortcut, &option, this)
!style()->styl...&option, this)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
297 textflags |= Qt::TextHideMnemonic;
never executed: textflags |= Qt::TextHideMnemonic;
0
298-
299 p.setFont(d->titleFont());-
300 p.drawItemText(d->titleRect().translated(hOffset, vOffset),-
301 textflags, option.palette, isEnabled(), text(), QPalette::ButtonText);-
302-
303-
304 textflags |= Qt::TextWordWrap | Qt::ElideRight;-
305 p.setFont(d->descriptionFont());-
306 p.drawItemText(d->descriptionRect().translated(hOffset, vOffset), textflags,-
307 option.palette, isEnabled(), description(), QPalette::ButtonText);-
308 p.restore();-
309}
never executed: end of block
0
310-
311void QCommandLinkButton::setDescription(const QString &description)-
312{-
313 QCommandLinkButtonPrivate * const d = d_func();-
314 d->description = description;-
315 updateGeometry();-
316 update();-
317}
never executed: end of block
0
318-
319QString QCommandLinkButton::description() const-
320{-
321 const QCommandLinkButtonPrivate * const d = d_func();-
322 return
never executed: return d->description;
d->description;
never executed: return d->description;
0
323}-
324-
325-
326-
Switch to Source codePreprocessed file

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