| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtGui 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 Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include "qcommandlinkbutton.h" | - |
| 43 | #include "qstylepainter.h" | - |
| 44 | #include "qstyleoption.h" | - |
| 45 | #include "qtextdocument.h" | - |
| 46 | #include "qtextlayout.h" | - |
| 47 | #include "qcolor.h" | - |
| 48 | #include "qfont.h" | - |
| 49 | #include <qmath.h> | - |
| 50 | | - |
| 51 | #include "private/qpushbutton_p.h" | - |
| 52 | | - |
| 53 | QT_BEGIN_NAMESPACE | - |
| 54 | | - |
| 55 | /*! | - |
| 56 | \class QCommandLinkButton | - |
| 57 | \since 4.4 | - |
| 58 | \brief The QCommandLinkButton widget provides a Vista style command link button. | - |
| 59 | | - |
| 60 | \ingroup basicwidgets | - |
| 61 | \inmodule QtWidgets | - |
| 62 | | - |
| 63 | The command link is a new control that was introduced by Windows Vista. It's | - |
| 64 | intended use is similar to that of a radio button in that it is used to choose | - |
| 65 | between a set of mutually exclusive options. Command link buttons should not | - |
| 66 | be used by themselves but rather as an alternative to radio buttons in | - |
| 67 | Wizards and dialogs and makes pressing the "next" button redundant. | - |
| 68 | The appearance is generally similar to that of a flat pushbutton, but | - |
| 69 | it allows for a descriptive text in addition to the normal button text. | - |
| 70 | By default it will also carry an arrow icon, indicating that pressing the | - |
| 71 | control will open another window or page. | - |
| 72 | | - |
| 73 | \sa QPushButton, QRadioButton | - |
| 74 | */ | - |
| 75 | | - |
| 76 | /*! | - |
| 77 | \property QCommandLinkButton::description | - |
| 78 | \brief A descriptive label to complement the button text | - |
| 79 | | - |
| 80 | Setting this property will set a descriptive text on the | - |
| 81 | button, complementing the text label. This will usually | - |
| 82 | be displayed in a smaller font than the primary text. | - |
| 83 | */ | - |
| 84 | | - |
| 85 | /*! | - |
| 86 | \property QCommandLinkButton::flat | - |
| 87 | \brief This property determines whether the button is displayed as a flat | - |
| 88 | panel or with a border. | - |
| 89 | | - |
| 90 | By default, this property is set to false. | - |
| 91 | | - |
| 92 | \sa QPushButton::flat | - |
| 93 | */ | - |
| 94 | | - |
| 95 | class QCommandLinkButtonPrivate : public QPushButtonPrivate | - |
| 96 | { | - |
| 97 | Q_DECLARE_PUBLIC(QCommandLinkButton) | - |
| 98 | | - |
| 99 | public: | - |
| 100 | QCommandLinkButtonPrivate() | - |
| 101 | : QPushButtonPrivate(){} executed: }Execution Count:12 | 12 |
| 102 | | - |
| 103 | void init(); | - |
| 104 | qreal titleSize() const; | - |
| 105 | bool usingVistaStyle() const; | - |
| 106 | | - |
| 107 | QFont titleFont() const; | - |
| 108 | QFont descriptionFont() const; | - |
| 109 | | - |
| 110 | QRect titleRect() const; | - |
| 111 | QRect descriptionRect() const; | - |
| 112 | | - |
| 113 | int textOffset() const; | - |
| 114 | int descriptionOffset() const; | - |
| 115 | int descriptionHeight(int width) const; | - |
| 116 | QColor mergedColors(const QColor &a, const QColor &b, int value) const; | - |
| 117 | | - |
| 118 | int topMargin() const { return 10; } executed: return 10;Execution Count:170 | 170 |
| 119 | int leftMargin() const { return 7; } executed: return 7;Execution Count:164 | 164 |
| 120 | int rightMargin() const { return 4; } executed: return 4;Execution Count:123 | 123 |
| 121 | int bottomMargin() const { return 10; } executed: return 10;Execution Count:83 | 83 |
| 122 | | - |
| 123 | QString description; | - |
| 124 | QColor currentColor; | - |
| 125 | }; | - |
| 126 | | - |
| 127 | // Mix colors a and b with a ratio in the range [0-255] | - |
| 128 | QColor QCommandLinkButtonPrivate::mergedColors(const QColor &a, const QColor &b, int value = 50) const | - |
| 129 | { | - |
| 130 | Q_ASSERT(value >= 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 131 | Q_ASSERT(value <= 255); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 132 | QColor tmp = a; never executed (the execution status of this line is deduced): QColor tmp = a; | - |
| 133 | tmp.setRed((tmp.red() * value) / 255 + (b.red() * (255 - value)) / 255); never executed (the execution status of this line is deduced): tmp.setRed((tmp.red() * value) / 255 + (b.red() * (255 - value)) / 255); | - |
| 134 | tmp.setGreen((tmp.green() * value) / 255 + (b.green() * (255 - value)) / 255); never executed (the execution status of this line is deduced): tmp.setGreen((tmp.green() * value) / 255 + (b.green() * (255 - value)) / 255); | - |
| 135 | tmp.setBlue((tmp.blue() * value) / 255 + (b.blue() * (255 - value)) / 255); never executed (the execution status of this line is deduced): tmp.setBlue((tmp.blue() * value) / 255 + (b.blue() * (255 - value)) / 255); | - |
| 136 | return tmp; never executed: return tmp; | 0 |
| 137 | } | - |
| 138 | | - |
| 139 | QFont QCommandLinkButtonPrivate::titleFont() const | - |
| 140 | { | - |
| 141 | Q_Q(const QCommandLinkButton); executed (the execution status of this line is deduced): const QCommandLinkButton * const q = q_func(); | - |
| 142 | QFont font = q->font(); executed (the execution status of this line is deduced): QFont font = q->font(); | - |
| 143 | if (usingVistaStyle()) { partially evaluated: usingVistaStyle()| no Evaluation Count:0 | yes Evaluation Count:128 |
| 0-128 |
| 144 | font.setPointSizeF(12.0); never executed (the execution status of this line is deduced): font.setPointSizeF(12.0); | - |
| 145 | } else { | 0 |
| 146 | font.setBold(true); executed (the execution status of this line is deduced): font.setBold(true); | - |
| 147 | font.setPointSizeF(9.0); executed (the execution status of this line is deduced): font.setPointSizeF(9.0); | - |
| 148 | } executed: }Execution Count:128 | 128 |
| 149 | | - |
| 150 | // Note the font will be resolved against | - |
| 151 | // QPainters font, so we need to restore the mask | - |
| 152 | int resolve_mask = font.resolve_mask; executed (the execution status of this line is deduced): int resolve_mask = font.resolve_mask; | - |
| 153 | QFont modifiedFont = q->font().resolve(font); executed (the execution status of this line is deduced): QFont modifiedFont = q->font().resolve(font); | - |
| 154 | modifiedFont.detach(); executed (the execution status of this line is deduced): modifiedFont.detach(); | - |
| 155 | modifiedFont.resolve_mask = resolve_mask; executed (the execution status of this line is deduced): modifiedFont.resolve_mask = resolve_mask; | - |
| 156 | return modifiedFont; executed: return modifiedFont;Execution Count:128 | 128 |
| 157 | } | - |
| 158 | | - |
| 159 | QFont QCommandLinkButtonPrivate::descriptionFont() const | - |
| 160 | { | - |
| 161 | Q_Q(const QCommandLinkButton); executed (the execution status of this line is deduced): const QCommandLinkButton * const q = q_func(); | - |
| 162 | QFont font = q->font(); executed (the execution status of this line is deduced): QFont font = q->font(); | - |
| 163 | font.setPointSizeF(9.0); executed (the execution status of this line is deduced): font.setPointSizeF(9.0); | - |
| 164 | | - |
| 165 | // Note the font will be resolved against | - |
| 166 | // QPainters font, so we need to restore the mask | - |
| 167 | int resolve_mask = font.resolve_mask; executed (the execution status of this line is deduced): int resolve_mask = font.resolve_mask; | - |
| 168 | QFont modifiedFont = q->font().resolve(font); executed (the execution status of this line is deduced): QFont modifiedFont = q->font().resolve(font); | - |
| 169 | modifiedFont.detach(); executed (the execution status of this line is deduced): modifiedFont.detach(); | - |
| 170 | modifiedFont.resolve_mask = resolve_mask; executed (the execution status of this line is deduced): modifiedFont.resolve_mask = resolve_mask; | - |
| 171 | return modifiedFont; executed: return modifiedFont;Execution Count:51 | 51 |
| 172 | } | - |
| 173 | | - |
| 174 | QRect QCommandLinkButtonPrivate::titleRect() const | - |
| 175 | { | - |
| 176 | Q_Q(const QCommandLinkButton); executed (the execution status of this line is deduced): const QCommandLinkButton * const q = q_func(); | - |
| 177 | QRect r = q->rect().adjusted(textOffset(), topMargin(), -rightMargin(), 0); executed (the execution status of this line is deduced): QRect r = q->rect().adjusted(textOffset(), topMargin(), -rightMargin(), 0); | - |
| 178 | if (description.isEmpty()) partially evaluated: description.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:41 |
| 0-41 |
| 179 | { | - |
| 180 | QFontMetrics fm(titleFont()); never executed (the execution status of this line is deduced): QFontMetrics fm(titleFont()); | - |
| 181 | r.setTop(r.top() + qMax(0, (q->icon().actualSize(q->iconSize()).height() never executed (the execution status of this line is deduced): r.setTop(r.top() + qMax(0, (q->icon().actualSize(q->iconSize()).height() | - |
| 182 | - fm.height()) / 2)); never executed (the execution status of this line is deduced): - fm.height()) / 2)); | - |
| 183 | } | 0 |
| 184 | | - |
| 185 | return r; executed: return r;Execution Count:41 | 41 |
| 186 | } | - |
| 187 | | - |
| 188 | QRect QCommandLinkButtonPrivate::descriptionRect() const | - |
| 189 | { | - |
| 190 | Q_Q(const QCommandLinkButton); executed (the execution status of this line is deduced): const QCommandLinkButton * const q = q_func(); | - |
| 191 | return q->rect().adjusted(textOffset(), descriptionOffset(), executed: return q->rect().adjusted(textOffset(), descriptionOffset(), -rightMargin(), -bottomMargin());Execution Count:41 | 41 |
| 192 | -rightMargin(), -bottomMargin()); executed: return q->rect().adjusted(textOffset(), descriptionOffset(), -rightMargin(), -bottomMargin());Execution Count:41 | 41 |
| 193 | } | - |
| 194 | | - |
| 195 | int QCommandLinkButtonPrivate::textOffset() const | - |
| 196 | { | - |
| 197 | Q_Q(const QCommandLinkButton); executed (the execution status of this line is deduced): const QCommandLinkButton * const q = q_func(); | - |
| 198 | return q->icon().actualSize(q->iconSize()).width() + leftMargin() + 6; executed: return q->icon().actualSize(q->iconSize()).width() + leftMargin() + 6;Execution Count:123 | 123 |
| 199 | } | - |
| 200 | | - |
| 201 | int QCommandLinkButtonPrivate::descriptionOffset() const | - |
| 202 | { | - |
| 203 | QFontMetrics fm(titleFont()); executed (the execution status of this line is deduced): QFontMetrics fm(titleFont()); | - |
| 204 | return topMargin() + fm.height(); executed: return topMargin() + fm.height();Execution Count:72 | 72 |
| 205 | } | - |
| 206 | | - |
| 207 | bool QCommandLinkButtonPrivate::usingVistaStyle() const | - |
| 208 | { | - |
| 209 | Q_Q(const QCommandLinkButton); executed (the execution status of this line is deduced): const QCommandLinkButton * const q = q_func(); | - |
| 210 | //### This is a hack to detect if we are indeed running Vista style themed and not in classic | - |
| 211 | // When we add api to query for this, we should change this implementation to use it. | - |
| 212 | return q->style()->inherits("QWindowsVistaStyle") executed: return q->style()->inherits("QWindowsVistaStyle") && !q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal);Execution Count:169 | 169 |
| 213 | && !q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal); executed: return q->style()->inherits("QWindowsVistaStyle") && !q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal);Execution Count:169 | 169 |
| 214 | } | - |
| 215 | | - |
| 216 | void QCommandLinkButtonPrivate::init() | - |
| 217 | { | - |
| 218 | Q_Q(QCommandLinkButton); executed (the execution status of this line is deduced): QCommandLinkButton * const q = q_func(); | - |
| 219 | QPushButtonPrivate::init(); executed (the execution status of this line is deduced): QPushButtonPrivate::init(); | - |
| 220 | q->setAttribute(Qt::WA_Hover); executed (the execution status of this line is deduced): q->setAttribute(Qt::WA_Hover); | - |
| 221 | | - |
| 222 | QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::PushButton); executed (the execution status of this line is deduced): QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::PushButton); | - |
| 223 | policy.setHeightForWidth(true); executed (the execution status of this line is deduced): policy.setHeightForWidth(true); | - |
| 224 | q->setSizePolicy(policy); executed (the execution status of this line is deduced): q->setSizePolicy(policy); | - |
| 225 | | - |
| 226 | q->setIconSize(QSize(20, 20)); executed (the execution status of this line is deduced): q->setIconSize(QSize(20, 20)); | - |
| 227 | QStyleOptionButton opt; executed (the execution status of this line is deduced): QStyleOptionButton opt; | - |
| 228 | q->initStyleOption(&opt); executed (the execution status of this line is deduced): q->initStyleOption(&opt); | - |
| 229 | q->setIcon(q->style()->standardIcon(QStyle::SP_CommandLink, &opt)); executed (the execution status of this line is deduced): q->setIcon(q->style()->standardIcon(QStyle::SP_CommandLink, &opt)); | - |
| 230 | } executed: }Execution Count:12 | 12 |
| 231 | | - |
| 232 | // Calculates the height of the description text based on widget width | - |
| 233 | int QCommandLinkButtonPrivate::descriptionHeight(int widgetWidth) const | - |
| 234 | { | - |
| 235 | // Calc width of actual paragraph | - |
| 236 | int lineWidth = widgetWidth - textOffset() - rightMargin(); executed (the execution status of this line is deduced): int lineWidth = widgetWidth - textOffset() - rightMargin(); | - |
| 237 | | - |
| 238 | qreal descriptionheight = 0; executed (the execution status of this line is deduced): qreal descriptionheight = 0; | - |
| 239 | if (!description.isEmpty()) { evaluated: !description.isEmpty()| yes Evaluation Count:10 | yes Evaluation Count:16 |
| 10-16 |
| 240 | QTextLayout layout(description); executed (the execution status of this line is deduced): QTextLayout layout(description); | - |
| 241 | layout.setFont(descriptionFont()); executed (the execution status of this line is deduced): layout.setFont(descriptionFont()); | - |
| 242 | layout.beginLayout(); executed (the execution status of this line is deduced): layout.beginLayout(); | - |
| 243 | while (true) { partially evaluated: true| yes Evaluation Count:44 | no Evaluation Count:0 |
| 0-44 |
| 244 | QTextLine line = layout.createLine(); executed (the execution status of this line is deduced): QTextLine line = layout.createLine(); | - |
| 245 | if (!line.isValid()) evaluated: !line.isValid()| yes Evaluation Count:10 | yes Evaluation Count:34 |
| 10-34 |
| 246 | break; executed: break;Execution Count:10 | 10 |
| 247 | line.setLineWidth(lineWidth); executed (the execution status of this line is deduced): line.setLineWidth(lineWidth); | - |
| 248 | line.setPosition(QPointF(0, descriptionheight)); executed (the execution status of this line is deduced): line.setPosition(QPointF(0, descriptionheight)); | - |
| 249 | descriptionheight += line.height(); executed (the execution status of this line is deduced): descriptionheight += line.height(); | - |
| 250 | } executed: }Execution Count:34 | 34 |
| 251 | layout.endLayout(); executed (the execution status of this line is deduced): layout.endLayout(); | - |
| 252 | } executed: }Execution Count:10 | 10 |
| 253 | return qCeil(descriptionheight); executed: return qCeil(descriptionheight);Execution Count:26 | 26 |
| 254 | } | - |
| 255 | | - |
| 256 | /*! | - |
| 257 | \reimp | - |
| 258 | */ | - |
| 259 | QSize QCommandLinkButton::minimumSizeHint() const | - |
| 260 | { | - |
| 261 | Q_D(const QCommandLinkButton); executed (the execution status of this line is deduced): const QCommandLinkButtonPrivate * const d = d_func(); | - |
| 262 | QSize size = sizeHint(); executed (the execution status of this line is deduced): QSize size = sizeHint(); | - |
| 263 | int minimumHeight = qMax(d->descriptionOffset() + d->bottomMargin(), executed (the execution status of this line is deduced): int minimumHeight = qMax(d->descriptionOffset() + d->bottomMargin(), | - |
| 264 | icon().actualSize(iconSize()).height() + d->topMargin()); executed (the execution status of this line is deduced): icon().actualSize(iconSize()).height() + d->topMargin()); | - |
| 265 | size.setHeight(minimumHeight); executed (the execution status of this line is deduced): size.setHeight(minimumHeight); | - |
| 266 | return size; executed: return size;Execution Count:5 | 5 |
| 267 | } | - |
| 268 | | - |
| 269 | /*! | - |
| 270 | Constructs a command link with no text and a \a parent. | - |
| 271 | */ | - |
| 272 | | - |
| 273 | QCommandLinkButton::QCommandLinkButton(QWidget *parent) | - |
| 274 | : QPushButton(*new QCommandLinkButtonPrivate, parent) | - |
| 275 | { | - |
| 276 | Q_D(QCommandLinkButton); executed (the execution status of this line is deduced): QCommandLinkButtonPrivate * const d = d_func(); | - |
| 277 | d->init(); executed (the execution status of this line is deduced): d->init(); | - |
| 278 | } executed: }Execution Count:9 | 9 |
| 279 | | - |
| 280 | /*! | - |
| 281 | Constructs a command link with the parent \a parent and the text \a | - |
| 282 | text. | - |
| 283 | */ | - |
| 284 | | - |
| 285 | QCommandLinkButton::QCommandLinkButton(const QString &text, QWidget *parent) | - |
| 286 | : QPushButton(*new QCommandLinkButtonPrivate, parent) | - |
| 287 | { | - |
| 288 | Q_D(QCommandLinkButton); executed (the execution status of this line is deduced): QCommandLinkButtonPrivate * const d = d_func(); | - |
| 289 | setText(text); executed (the execution status of this line is deduced): setText(text); | - |
| 290 | d->init(); executed (the execution status of this line is deduced): d->init(); | - |
| 291 | } executed: }Execution Count:1 | 1 |
| 292 | | - |
| 293 | /*! | - |
| 294 | Constructs a command link with a \a text, a \a description, and a \a parent. | - |
| 295 | */ | - |
| 296 | QCommandLinkButton::QCommandLinkButton(const QString &text, const QString &description, QWidget *parent) | - |
| 297 | : QPushButton(*new QCommandLinkButtonPrivate, parent) | - |
| 298 | { | - |
| 299 | Q_D(QCommandLinkButton); executed (the execution status of this line is deduced): QCommandLinkButtonPrivate * const d = d_func(); | - |
| 300 | setText(text); executed (the execution status of this line is deduced): setText(text); | - |
| 301 | setDescription(description); executed (the execution status of this line is deduced): setDescription(description); | - |
| 302 | d->init(); executed (the execution status of this line is deduced): d->init(); | - |
| 303 | } executed: }Execution Count:2 | 2 |
| 304 | | - |
| 305 | /*! | - |
| 306 | Destructor. | - |
| 307 | */ | - |
| 308 | QCommandLinkButton::~QCommandLinkButton() | - |
| 309 | { | - |
| 310 | } | - |
| 311 | | - |
| 312 | /*! \reimp */ | - |
| 313 | bool QCommandLinkButton::event(QEvent *e) | - |
| 314 | { | - |
| 315 | return QPushButton::event(e); executed: return QPushButton::event(e);Execution Count:268 | 268 |
| 316 | } | - |
| 317 | | - |
| 318 | /*! \reimp */ | - |
| 319 | QSize QCommandLinkButton::sizeHint() const | - |
| 320 | { | - |
| 321 | // Standard size hints from UI specs | - |
| 322 | // Without note: 135, 41 | - |
| 323 | // With note: 135, 60 | - |
| 324 | Q_D(const QCommandLinkButton); executed (the execution status of this line is deduced): const QCommandLinkButtonPrivate * const d = d_func(); | - |
| 325 | | - |
| 326 | QSize size = QPushButton::sizeHint(); executed (the execution status of this line is deduced): QSize size = QPushButton::sizeHint(); | - |
| 327 | QFontMetrics fm(d->titleFont()); executed (the execution status of this line is deduced): QFontMetrics fm(d->titleFont()); | - |
| 328 | int textWidth = qMax(fm.width(text()), 135); executed (the execution status of this line is deduced): int textWidth = qMax(fm.width(text()), 135); | - |
| 329 | int buttonWidth = textWidth + d->textOffset() + d->rightMargin(); executed (the execution status of this line is deduced): int buttonWidth = textWidth + d->textOffset() + d->rightMargin(); | - |
| 330 | int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin(); executed (the execution status of this line is deduced): int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin(); | - |
| 331 | | - |
| 332 | size.setWidth(qMax(size.width(), buttonWidth)); executed (the execution status of this line is deduced): size.setWidth(qMax(size.width(), buttonWidth)); | - |
| 333 | size.setHeight(qMax(d->description.isEmpty() ? 41 : 60, executed (the execution status of this line is deduced): size.setHeight(qMax(d->description.isEmpty() ? 41 : 60, | - |
| 334 | heightWithoutDescription + d->descriptionHeight(buttonWidth))); executed (the execution status of this line is deduced): heightWithoutDescription + d->descriptionHeight(buttonWidth))); | - |
| 335 | return size; executed: return size;Execution Count:15 | 15 |
| 336 | } | - |
| 337 | | - |
| 338 | /*! \reimp */ | - |
| 339 | int QCommandLinkButton::heightForWidth(int width) const | - |
| 340 | { | - |
| 341 | Q_D(const QCommandLinkButton); executed (the execution status of this line is deduced): const QCommandLinkButtonPrivate * const d = d_func(); | - |
| 342 | int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin(); executed (the execution status of this line is deduced): int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin(); | - |
| 343 | // find the width available for the description area | - |
| 344 | return qMax(heightWithoutDescription + d->descriptionHeight(width), executed: return qMax(heightWithoutDescription + d->descriptionHeight(width), icon().actualSize(iconSize()).height() + d->topMargin() + d->bottomMargin());Execution Count:11 | 11 |
| 345 | icon().actualSize(iconSize()).height() + d->topMargin() + executed: return qMax(heightWithoutDescription + d->descriptionHeight(width), icon().actualSize(iconSize()).height() + d->topMargin() + d->bottomMargin());Execution Count:11 | 11 |
| 346 | d->bottomMargin()); executed: return qMax(heightWithoutDescription + d->descriptionHeight(width), icon().actualSize(iconSize()).height() + d->topMargin() + d->bottomMargin());Execution Count:11 | 11 |
| 347 | } | - |
| 348 | | - |
| 349 | /*! \reimp */ | - |
| 350 | void QCommandLinkButton::paintEvent(QPaintEvent *) | - |
| 351 | { | - |
| 352 | Q_D(QCommandLinkButton); executed (the execution status of this line is deduced): QCommandLinkButtonPrivate * const d = d_func(); | - |
| 353 | QStylePainter p(this); executed (the execution status of this line is deduced): QStylePainter p(this); | - |
| 354 | p.save(); executed (the execution status of this line is deduced): p.save(); | - |
| 355 | | - |
| 356 | QStyleOptionButton option; executed (the execution status of this line is deduced): QStyleOptionButton option; | - |
| 357 | initStyleOption(&option); executed (the execution status of this line is deduced): initStyleOption(&option); | - |
| 358 | | - |
| 359 | //Enable command link appearance on Vista | - |
| 360 | option.features |= QStyleOptionButton::CommandLinkButton; executed (the execution status of this line is deduced): option.features |= QStyleOptionButton::CommandLinkButton; | - |
| 361 | option.text = QString(); executed (the execution status of this line is deduced): option.text = QString(); | - |
| 362 | option.icon = QIcon(); //we draw this ourselves executed (the execution status of this line is deduced): option.icon = QIcon(); | - |
| 363 | QSize pixmapSize = icon().actualSize(iconSize()); executed (the execution status of this line is deduced): QSize pixmapSize = icon().actualSize(iconSize()); | - |
| 364 | | - |
| 365 | int vOffset = isDown() ? style()->pixelMetric(QStyle::PM_ButtonShiftVertical) : 0; evaluated: isDown()| yes Evaluation Count:17 | yes Evaluation Count:24 |
| 17-24 |
| 366 | int hOffset = isDown() ? style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal) : 0; evaluated: isDown()| yes Evaluation Count:17 | yes Evaluation Count:24 |
| 17-24 |
| 367 | | - |
| 368 | //Draw icon | - |
| 369 | p.drawControl(QStyle::CE_PushButton, option); executed (the execution status of this line is deduced): p.drawControl(QStyle::CE_PushButton, option); | - |
| 370 | if (!icon().isNull()) partially evaluated: !icon().isNull()| yes Evaluation Count:41 | no Evaluation Count:0 |
| 0-41 |
| 371 | p.drawPixmap(d->leftMargin() + hOffset, d->topMargin() + vOffset, 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 |
| 372 | icon().pixmap(pixmapSize, isEnabled() ? QIcon::Normal : QIcon::Disabled, 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 |
| 373 | 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 |
| 374 | | - |
| 375 | //Draw title | - |
| 376 | QColor textColor = palette().buttonText().color(); executed (the execution status of this line is deduced): QColor textColor = palette().buttonText().color(); | - |
| 377 | 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 |
| 378 | textColor = QColor(21, 28, 85); never executed (the execution status of this line is deduced): textColor = QColor(21, 28, 85); | - |
| 379 | if (underMouse() && !isDown()) never evaluated: underMouse() never evaluated: !isDown() | 0 |
| 380 | textColor = QColor(7, 64, 229); never executed: textColor = QColor(7, 64, 229); | 0 |
| 381 | //A simple text color transition | - |
| 382 | d->currentColor = d->mergedColors(textColor, d->currentColor, 60); never executed (the execution status of this line is deduced): d->currentColor = d->mergedColors(textColor, d->currentColor, 60); | - |
| 383 | option.palette.setColor(QPalette::ButtonText, d->currentColor); never executed (the execution status of this line is deduced): option.palette.setColor(QPalette::ButtonText, d->currentColor); | - |
| 384 | } | 0 |
| 385 | | - |
| 386 | int textflags = Qt::TextShowMnemonic; executed (the execution status of this line is deduced): int textflags = Qt::TextShowMnemonic; | - |
| 387 | 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 |
| 388 | textflags |= Qt::TextHideMnemonic; never executed: textflags |= Qt::TextHideMnemonic; | 0 |
| 389 | | - |
| 390 | p.setFont(d->titleFont()); executed (the execution status of this line is deduced): p.setFont(d->titleFont()); | - |
| 391 | p.drawItemText(d->titleRect().translated(hOffset, vOffset), executed (the execution status of this line is deduced): p.drawItemText(d->titleRect().translated(hOffset, vOffset), | - |
| 392 | textflags, option.palette, isEnabled(), text(), QPalette::ButtonText); executed (the execution status of this line is deduced): textflags, option.palette, isEnabled(), text(), QPalette::ButtonText); | - |
| 393 | | - |
| 394 | //Draw description | - |
| 395 | textflags |= Qt::TextWordWrap | Qt::ElideRight; executed (the execution status of this line is deduced): textflags |= Qt::TextWordWrap | Qt::ElideRight; | - |
| 396 | p.setFont(d->descriptionFont()); executed (the execution status of this line is deduced): p.setFont(d->descriptionFont()); | - |
| 397 | p.drawItemText(d->descriptionRect().translated(hOffset, vOffset), textflags, executed (the execution status of this line is deduced): p.drawItemText(d->descriptionRect().translated(hOffset, vOffset), textflags, | - |
| 398 | option.palette, isEnabled(), description(), QPalette::ButtonText); executed (the execution status of this line is deduced): option.palette, isEnabled(), description(), QPalette::ButtonText); | - |
| 399 | p.restore(); executed (the execution status of this line is deduced): p.restore(); | - |
| 400 | } executed: }Execution Count:41 | 41 |
| 401 | | - |
| 402 | void QCommandLinkButton::setDescription(const QString &description) | - |
| 403 | { | - |
| 404 | Q_D(QCommandLinkButton); executed (the execution status of this line is deduced): QCommandLinkButtonPrivate * const d = d_func(); | - |
| 405 | d->description = description; executed (the execution status of this line is deduced): d->description = description; | - |
| 406 | updateGeometry(); executed (the execution status of this line is deduced): updateGeometry(); | - |
| 407 | update(); executed (the execution status of this line is deduced): update(); | - |
| 408 | } executed: }Execution Count:17 | 17 |
| 409 | | - |
| 410 | QString QCommandLinkButton::description() const | - |
| 411 | { | - |
| 412 | Q_D(const QCommandLinkButton); executed (the execution status of this line is deduced): const QCommandLinkButtonPrivate * const d = d_func(); | - |
| 413 | return d->description; executed: return d->description;Execution Count:43 | 43 |
| 414 | } | - |
| 415 | | - |
| 416 | QT_END_NAMESPACE | - |
| 417 | | - |
| 418 | | - |
| | |