Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | class 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 | | - |
8 | public: | - |
9 | QCommandLinkButtonPrivate() | - |
10 | : QPushButtonPrivate(){} executed: } Execution Count:12 | 12 |
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 10; } executed: return 10; Execution Count:170 | 170 |
28 | int leftMargin() const { return 7; } executed: return 7; Execution Count:164 | 164 |
29 | int rightMargin() const { return 4; } executed: return 4; Execution Count:123 | 123 |
30 | int bottomMargin() const { return 10; } executed: return 10; Execution Count:83 | 83 |
31 | | - |
32 | QString description; | - |
33 | QColor currentColor; | - |
34 | }; | - |
35 | | - |
36 | | - |
37 | QColor QCommandLinkButtonPrivate::mergedColors(const QColor &a, const QColor &b, int value = 50) const | - |
38 | { | - |
39 | qt_noop(); | - |
40 | 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 tmp; never executed: return tmp; | 0 |
46 | } | - |
47 | | - |
48 | QFont QCommandLinkButtonPrivate::titleFont() const | - |
49 | { | - |
50 | const QCommandLinkButton * const q = q_func(); | - |
51 | QFont font = q->font(); | - |
52 | if (usingVistaStyle()) { partially evaluated: usingVistaStyle() no Evaluation Count:0 | yes Evaluation Count:128 |
| 0-128 |
53 | font.setPointSizeF(12.0); | - |
54 | } else { | 0 |
55 | font.setBold(true); | - |
56 | font.setPointSizeF(9.0); | - |
57 | } executed: } Execution Count:128 | 128 |
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 modifiedFont; executed: return modifiedFont; Execution Count:128 | 128 |
66 | } | - |
67 | | - |
68 | QFont 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 modifiedFont; executed: return modifiedFont; Execution Count:51 | 51 |
81 | } | - |
82 | | - |
83 | QRect 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()) partially evaluated: description.isEmpty() no Evaluation Count:0 | yes Evaluation Count:41 |
| 0-41 |
88 | { | - |
89 | QFontMetrics fm(titleFont()); | - |
90 | r.setTop(r.top() + qMax(0, (q->icon().actualSize(q->iconSize()).height() | - |
91 | - fm.height()) / 2)); | - |
92 | } | 0 |
93 | | - |
94 | return r; executed: return r; Execution Count:41 | 41 |
95 | } | - |
96 | | - |
97 | QRect QCommandLinkButtonPrivate::descriptionRect() const | - |
98 | { | - |
99 | const QCommandLinkButton * const q = q_func(); | - |
100 | return q->rect().adjusted(textOffset(), descriptionOffset(), | 41 |
101 | -rightMargin(), -bottomMargin()); executed: return q->rect().adjusted(textOffset(), descriptionOffset(), -rightMargin(), -bottomMargin()); Execution Count:41 | 41 |
102 | } | - |
103 | | - |
104 | int QCommandLinkButtonPrivate::textOffset() const | - |
105 | { | - |
106 | const QCommandLinkButton * const q = q_func(); | - |
107 | return q->icon().actualSize(q->iconSize()).width() + leftMargin() + 6; executed: return q->icon().actualSize(q->iconSize()).width() + leftMargin() + 6; Execution Count:123 | 123 |
108 | } | - |
109 | | - |
110 | int QCommandLinkButtonPrivate::descriptionOffset() const | - |
111 | { | - |
112 | QFontMetrics fm(titleFont()); | - |
113 | return topMargin() + fm.height(); executed: return topMargin() + fm.height(); Execution Count:72 | 72 |
114 | } | - |
115 | | - |
116 | bool QCommandLinkButtonPrivate::usingVistaStyle() const | - |
117 | { | - |
118 | const QCommandLinkButton * const q = q_func(); | - |
119 | | - |
120 | | - |
121 | return q->style()->inherits("QWindowsVistaStyle") | 169 |
122 | && !q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal); executed: return q->style()->inherits("QWindowsVistaStyle") && !q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal); Execution Count:169 | 169 |
123 | } | - |
124 | | - |
125 | void 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 | } executed: } Execution Count:12 | 12 |
140 | | - |
141 | | - |
142 | int QCommandLinkButtonPrivate::descriptionHeight(int widgetWidth) const | - |
143 | { | - |
144 | | - |
145 | int lineWidth = widgetWidth - textOffset() - rightMargin(); | - |
146 | | - |
147 | qreal descriptionheight = 0; | - |
148 | if (!description.isEmpty()) { evaluated: !description.isEmpty() yes Evaluation Count:10 | yes Evaluation Count:16 |
| 10-16 |
149 | QTextLayout layout(description); | - |
150 | layout.setFont(descriptionFont()); | - |
151 | layout.beginLayout(); | - |
152 | while (true) { partially evaluated: true yes Evaluation Count:44 | no Evaluation Count:0 |
| 0-44 |
153 | QTextLine line = layout.createLine(); | - |
154 | if (!line.isValid()) evaluated: !line.isValid() yes Evaluation Count:10 | yes Evaluation Count:34 |
| 10-34 |
155 | break; executed: break; Execution Count:10 | 10 |
156 | line.setLineWidth(lineWidth); | - |
157 | line.setPosition(QPointF(0, descriptionheight)); | - |
158 | descriptionheight += line.height(); | - |
159 | } executed: } Execution Count:34 | 34 |
160 | layout.endLayout(); | - |
161 | } executed: } Execution Count:10 | 10 |
162 | return qCeil(descriptionheight); executed: return qCeil(descriptionheight); Execution Count:26 | 26 |
163 | } | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | QSize 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 size; executed: return size; Execution Count:5 | 5 |
176 | } | - |
177 | | - |
178 | | - |
179 | | - |
180 | | - |
181 | | - |
182 | QCommandLinkButton::QCommandLinkButton(QWidget *parent) | - |
183 | : QPushButton(*new QCommandLinkButtonPrivate, parent) | - |
184 | { | - |
185 | QCommandLinkButtonPrivate * const d = d_func(); | - |
186 | d->init(); | - |
187 | } executed: } Execution Count:9 | 9 |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | | - |
193 | | - |
194 | QCommandLinkButton::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 | } executed: } Execution Count:1 | 1 |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | QCommandLinkButton::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 | } executed: } Execution Count:2 | 2 |
213 | | - |
214 | | - |
215 | | - |
216 | | - |
217 | QCommandLinkButton::~QCommandLinkButton() | - |
218 | { | - |
219 | } | - |
220 | | - |
221 | | - |
222 | bool QCommandLinkButton::event(QEvent *e) | - |
223 | { | - |
224 | return QPushButton::event(e); executed: return QPushButton::event(e); Execution Count:268 | 268 |
225 | } | - |
226 | | - |
227 | | - |
228 | QSize 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 size; executed: return size; Execution Count:15 | 15 |
245 | } | - |
246 | | - |
247 | | - |
248 | int QCommandLinkButton::heightForWidth(int width) const | - |
249 | { | - |
250 | const QCommandLinkButtonPrivate * const d = d_func(); | - |
251 | int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin(); | - |
252 | | - |
253 | return qMax(heightWithoutDescription + d->descriptionHeight(width), | 11 |
254 | icon().actualSize(iconSize()).height() + d->topMargin() + | 11 |
255 | d->bottomMargin()); executed: return qMax(heightWithoutDescription + d->descriptionHeight(width), icon().actualSize(iconSize()).height() + d->topMargin() + d->bottomMargin()); Execution Count:11 | 11 |
256 | } | - |
257 | | - |
258 | | - |
259 | void 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() ? style()->pixelMetric(QStyle::PM_ButtonShiftVertical) : 0; evaluated: isDown() yes Evaluation Count:17 | yes Evaluation Count:24 |
| 17-24 |
275 | int hOffset = isDown() ? style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal) : 0; evaluated: isDown() yes Evaluation Count:17 | yes Evaluation Count:24 |
| 17-24 |
276 | | - |
277 | | - |
278 | p.drawControl(QStyle::CE_PushButton, option); | - |
279 | if (!icon().isNull()) partially evaluated: !icon().isNull() yes Evaluation Count:41 | no Evaluation Count:0 |
| 0-41 |
280 | p.drawPixmap(d->leftMargin() + hOffset, d->topMargin() + vOffset, | 41 |
281 | icon().pixmap(pixmapSize, isEnabled() ? QIcon::Normal : QIcon::Disabled, | 41 |
282 | isChecked() ? QIcon::On : QIcon::Off)); executed: p.drawPixmap(d->leftMargin() + hOffset, d->topMargin() + vOffset, icon().pixmap(pixmapSize, isEnabled() ? QIcon::Normal : QIcon::Disabled, isChecked() ? QIcon::On : QIcon::Off)); Execution Count:41 | 41 |
283 | | - |
284 | | - |
285 | QColor textColor = palette().buttonText().color(); | - |
286 | if (isEnabled() && d->usingVistaStyle()) { partially evaluated: isEnabled() yes Evaluation Count:41 | no Evaluation Count:0 |
partially evaluated: d->usingVistaStyle() no Evaluation Count:0 | yes Evaluation Count:41 |
| 0-41 |
287 | textColor = QColor(21, 28, 85); | - |
288 | if (underMouse() && !isDown()) never evaluated: underMouse() never evaluated: !isDown() | 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 | } | 0 |
294 | | - |
295 | int textflags = Qt::TextShowMnemonic; | - |
296 | if (!style()->styleHint(QStyle::SH_UnderlineShortcut, &option, this)) partially evaluated: !style()->styleHint(QStyle::SH_UnderlineShortcut, &option, this) no Evaluation Count:0 | yes Evaluation Count:41 |
| 0-41 |
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 | } executed: } Execution Count:41 | 41 |
310 | | - |
311 | void QCommandLinkButton::setDescription(const QString &description) | - |
312 | { | - |
313 | QCommandLinkButtonPrivate * const d = d_func(); | - |
314 | d->description = description; | - |
315 | updateGeometry(); | - |
316 | update(); | - |
317 | } executed: } Execution Count:17 | 17 |
318 | | - |
319 | QString QCommandLinkButton::description() const | - |
320 | { | - |
321 | const QCommandLinkButtonPrivate * const d = d_func(); | - |
322 | return d->description; executed: return d->description; Execution Count:43 | 43 |
323 | } | - |
324 | | - |
325 | | - |
326 | | - |
| | |