| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qprogressbar.cpp | 
| Source code | Switch to Preprocessed file | 
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 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 The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include "qprogressbar.h" | - | ||||||||||||||||||
| 35 | #ifndef QT_NO_PROGRESSBAR | - | ||||||||||||||||||
| 36 | #include <qlocale.h> | - | ||||||||||||||||||
| 37 | #include <qevent.h> | - | ||||||||||||||||||
| 38 | #include <qpainter.h> | - | ||||||||||||||||||
| 39 | #include <qstylepainter.h> | - | ||||||||||||||||||
| 40 | #include <qstyleoption.h> | - | ||||||||||||||||||
| 41 | #include <private/qwidget_p.h> | - | ||||||||||||||||||
| 42 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
| 43 | #include <qaccessible.h> | - | ||||||||||||||||||
| 44 | #endif | - | ||||||||||||||||||
| 45 | #include <limits.h> | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | class QProgressBarPrivate : public QWidgetPrivate | - | ||||||||||||||||||
| 50 | { | - | ||||||||||||||||||
| 51 | Q_DECLARE_PUBLIC(QProgressBar) | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | public: | - | ||||||||||||||||||
| 54 | QProgressBarPrivate(); | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | void init(); | - | ||||||||||||||||||
| 57 | void initDefaultFormat(); | - | ||||||||||||||||||
| 58 | inline void resetLayoutItemMargins(); | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | int minimum; | - | ||||||||||||||||||
| 61 | int maximum; | - | ||||||||||||||||||
| 62 | int value; | - | ||||||||||||||||||
| 63 | Qt::Alignment alignment; | - | ||||||||||||||||||
| 64 | uint textVisible : 1; | - | ||||||||||||||||||
| 65 | uint defaultFormat: 1; | - | ||||||||||||||||||
| 66 | int lastPaintedValue; | - | ||||||||||||||||||
| 67 | Qt::Orientation orientation; | - | ||||||||||||||||||
| 68 | bool invertedAppearance; | - | ||||||||||||||||||
| 69 | QProgressBar::Direction textDirection; | - | ||||||||||||||||||
| 70 | QString format; | - | ||||||||||||||||||
| 71 |     inline int bound(int val) const { return qMax(minimum-1, qMin(maximum, val)); } never executed:  return qMax(minimum-1, qMin(maximum, val)); | 0 | ||||||||||||||||||
| 72 | bool repaintRequired() const; | - | ||||||||||||||||||
| 73 | }; | - | ||||||||||||||||||
| 74 | - | |||||||||||||||||||
| 75 | QProgressBarPrivate::QProgressBarPrivate() | - | ||||||||||||||||||
| 76 | : minimum(0), maximum(100), value(-1), alignment(Qt::AlignLeft), textVisible(true), | - | ||||||||||||||||||
| 77 | defaultFormat(true), lastPaintedValue(-1), orientation(Qt::Horizontal), invertedAppearance(false), | - | ||||||||||||||||||
| 78 | textDirection(QProgressBar::TopToBottom) | - | ||||||||||||||||||
| 79 | { | - | ||||||||||||||||||
| 80 | initDefaultFormat(); | - | ||||||||||||||||||
| 81 | } never executed:  end of block | 0 | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | void QProgressBarPrivate::initDefaultFormat() | - | ||||||||||||||||||
| 84 | { | - | ||||||||||||||||||
| 85 |     if (defaultFormat)
  | 0 | ||||||||||||||||||
| 86 |         format = QLatin1String("%p") + locale.percent(); never executed:  format = QLatin1String("%p") + locale.percent(); | 0 | ||||||||||||||||||
| 87 | } never executed:  end of block | 0 | ||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | void QProgressBarPrivate::init() | - | ||||||||||||||||||
| 90 | { | - | ||||||||||||||||||
| 91 | Q_Q(QProgressBar); | - | ||||||||||||||||||
| 92 | QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed); | - | ||||||||||||||||||
| 93 |     if (orientation == Qt::Vertical)
  | 0 | ||||||||||||||||||
| 94 |         sp.transpose(); never executed:  sp.transpose(); | 0 | ||||||||||||||||||
| 95 | q->setSizePolicy(sp); | - | ||||||||||||||||||
| 96 | q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); | - | ||||||||||||||||||
| 97 | resetLayoutItemMargins(); | - | ||||||||||||||||||
| 98 | } never executed:  end of block | 0 | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | void QProgressBarPrivate::resetLayoutItemMargins() | - | ||||||||||||||||||
| 101 | { | - | ||||||||||||||||||
| 102 | Q_Q(QProgressBar); | - | ||||||||||||||||||
| 103 | QStyleOptionProgressBar option; | - | ||||||||||||||||||
| 104 | q->initStyleOption(&option); | - | ||||||||||||||||||
| 105 | setLayoutItemMargins(QStyle::SE_ProgressBarLayoutItem, &option); | - | ||||||||||||||||||
| 106 | } never executed:  end of block | 0 | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | /*! | - | ||||||||||||||||||
| 109 | Initialize \a option with the values from this QProgressBar. This method is useful | - | ||||||||||||||||||
| 110 | for subclasses when they need a QStyleOptionProgressBar, | - | ||||||||||||||||||
| 111 | but don't want to fill in all the information themselves. | - | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | \sa QStyleOption::initFrom() | - | ||||||||||||||||||
| 114 | */ | - | ||||||||||||||||||
| 115 | void QProgressBar::initStyleOption(QStyleOptionProgressBar *option) const | - | ||||||||||||||||||
| 116 | { | - | ||||||||||||||||||
| 117 |     if (!option)
  | 0 | ||||||||||||||||||
| 118 |         return; never executed:  return; | 0 | ||||||||||||||||||
| 119 | Q_D(const QProgressBar); | - | ||||||||||||||||||
| 120 | option->initFrom(this); | - | ||||||||||||||||||
| 121 | - | |||||||||||||||||||
| 122 |     if (d->orientation == Qt::Horizontal)
  | 0 | ||||||||||||||||||
| 123 |         option->state |= QStyle::State_Horizontal; never executed:  option->state |= QStyle::State_Horizontal; | 0 | ||||||||||||||||||
| 124 | option->minimum = d->minimum; | - | ||||||||||||||||||
| 125 | option->maximum = d->maximum; | - | ||||||||||||||||||
| 126 | option->progress = d->value; | - | ||||||||||||||||||
| 127 | option->textAlignment = d->alignment; | - | ||||||||||||||||||
| 128 | option->textVisible = d->textVisible; | - | ||||||||||||||||||
| 129 | option->text = text(); | - | ||||||||||||||||||
| 130 | option->orientation = d->orientation; // ### Qt 6: remove this member from QStyleOptionProgressBar | - | ||||||||||||||||||
| 131 | option->invertedAppearance = d->invertedAppearance; | - | ||||||||||||||||||
| 132 | option->bottomToTop = d->textDirection == QProgressBar::BottomToTop; | - | ||||||||||||||||||
| 133 | } never executed:  end of block | 0 | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | bool QProgressBarPrivate::repaintRequired() const | - | ||||||||||||||||||
| 136 | { | - | ||||||||||||||||||
| 137 | Q_Q(const QProgressBar); | - | ||||||||||||||||||
| 138 |     if (value == lastPaintedValue)
  | 0 | ||||||||||||||||||
| 139 |         return false; never executed:  return false; | 0 | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | const qint64 valueDifference = qAbs(qint64(value) - lastPaintedValue); | - | ||||||||||||||||||
| 142 | // Check if the text needs to be repainted | - | ||||||||||||||||||
| 143 |     if (value == minimum || value == maximum)
 
  | 0 | ||||||||||||||||||
| 144 |         return true; never executed:  return true; | 0 | ||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | const qint64 totalSteps = qint64(maximum) - minimum; | - | ||||||||||||||||||
| 147 |     if (textVisible) {
  | 0 | ||||||||||||||||||
| 148 |         if ((format.contains(QLatin1String("%v"))))
  | 0 | ||||||||||||||||||
| 149 |             return true; never executed:  return true; | 0 | ||||||||||||||||||
| 150 |         if ((format.contains(QLatin1String("%p"))
  | 0 | ||||||||||||||||||
| 151 |              && valueDifference >= qAbs(totalSteps / 100)))
  | 0 | ||||||||||||||||||
| 152 |             return true; never executed:  return true; | 0 | ||||||||||||||||||
| 153 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | // Check if the bar needs to be repainted | - | ||||||||||||||||||
| 156 | QStyleOptionProgressBar opt; | - | ||||||||||||||||||
| 157 | q->initStyleOption(&opt); | - | ||||||||||||||||||
| 158 | int cw = q->style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, q); | - | ||||||||||||||||||
| 159 | QRect groove = q->style()->subElementRect(QStyle::SE_ProgressBarGroove, &opt, q); | - | ||||||||||||||||||
| 160 | // This expression is basically | - | ||||||||||||||||||
| 161 | // (valueDifference / (maximum - minimum) > cw / groove.width()) | - | ||||||||||||||||||
| 162 | // transformed to avoid integer division. | - | ||||||||||||||||||
| 163 |     int grooveBlock = (q->orientation() == Qt::Horizontal) ? groove.width() : groove.height();
  | 0 | ||||||||||||||||||
| 164 |     return valueDifference * grooveBlock > cw * totalSteps; never executed:  return valueDifference * grooveBlock > cw * totalSteps; | 0 | ||||||||||||||||||
| 165 | } | - | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | /*! | - | ||||||||||||||||||
| 168 | \class QProgressBar | - | ||||||||||||||||||
| 169 | \brief The QProgressBar widget provides a horizontal or vertical progress bar. | - | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | \ingroup basicwidgets | - | ||||||||||||||||||
| 172 | \inmodule QtWidgets | - | ||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | A progress bar is used to give the user an indication of the | - | ||||||||||||||||||
| 175 | progress of an operation and to reassure them that the application | - | ||||||||||||||||||
| 176 | is still running. | - | ||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | The progress bar uses the concept of \e steps. You set it up by | - | ||||||||||||||||||
| 179 | specifying the minimum and maximum possible step values, and it | - | ||||||||||||||||||
| 180 | will display the percentage of steps that have been completed | - | ||||||||||||||||||
| 181 | when you later give it the current step value. The percentage is | - | ||||||||||||||||||
| 182 | calculated by dividing the progress (value() - minimum()) divided | - | ||||||||||||||||||
| 183 | by maximum() - minimum(). | - | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | You can specify the minimum and maximum number of steps with | - | ||||||||||||||||||
| 186 | setMinimum() and setMaximum. The current number of steps is set | - | ||||||||||||||||||
| 187 | with setValue(). The progress bar can be rewound to the | - | ||||||||||||||||||
| 188 | beginning with reset(). | - | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | If minimum and maximum both are set to 0, the bar shows a busy | - | ||||||||||||||||||
| 191 | indicator instead of a percentage of steps. This is useful, for | - | ||||||||||||||||||
| 192 | example, when using QNetworkAccessManager to download items when | - | ||||||||||||||||||
| 193 | they are unable to determine the size of the item being downloaded. | - | ||||||||||||||||||
| 194 | - | |||||||||||||||||||
| 195 | \table | - | ||||||||||||||||||
| 196 | \row \li \inlineimage macintosh-progressbar.png Screenshot of a Macintosh style progress bar | - | ||||||||||||||||||
| 197 | \li A progress bar shown in the Macintosh widget style. | - | ||||||||||||||||||
| 198 | \row \li \inlineimage windowsvista-progressbar.png Screenshot of a Windows Vista style progress bar | - | ||||||||||||||||||
| 199 | \li A progress bar shown in the Windows Vista widget style. | - | ||||||||||||||||||
| 200 | \row \li \inlineimage fusion-progressbar.png Screenshot of a Fusion style progress bar | - | ||||||||||||||||||
| 201 | \li A progress bar shown in the Fusion widget style. | - | ||||||||||||||||||
| 202 | \endtable | - | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | \sa QProgressDialog, {fowler}{GUI Design Handbook: Progress Indicator} | - | ||||||||||||||||||
| 205 | */ | - | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | /*! | - | ||||||||||||||||||
| 208 | \since 4.1 | - | ||||||||||||||||||
| 209 | \enum QProgressBar::Direction | - | ||||||||||||||||||
| 210 | \brief Specifies the reading direction of the \l text for vertical progress bars. | - | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | \value TopToBottom The text is rotated 90 degrees clockwise. | - | ||||||||||||||||||
| 213 | \value BottomToTop The text is rotated 90 degrees counter-clockwise. | - | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | Note that whether or not the text is drawn is dependent on the style. | - | ||||||||||||||||||
| 216 | Currently CleanLooks and Plastique draw the text. Mac, Windows | - | ||||||||||||||||||
| 217 | and WindowsXP style do not. | - | ||||||||||||||||||
| 218 | - | |||||||||||||||||||
| 219 | \sa textDirection | - | ||||||||||||||||||
| 220 | */ | - | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | /*! | - | ||||||||||||||||||
| 223 | \fn void QProgressBar::valueChanged(int value) | - | ||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | This signal is emitted when the value shown in the progress bar changes. | - | ||||||||||||||||||
| 226 | \a value is the new value shown by the progress bar. | - | ||||||||||||||||||
| 227 | */ | - | ||||||||||||||||||
| 228 | - | |||||||||||||||||||
| 229 | /*! | - | ||||||||||||||||||
| 230 | Constructs a progress bar with the given \a parent. | - | ||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | By default, the minimum step value is set to 0, and the maximum to 100. | - | ||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | \sa setRange() | - | ||||||||||||||||||
| 235 | */ | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | QProgressBar::QProgressBar(QWidget *parent) | - | ||||||||||||||||||
| 238 | : QWidget(*(new QProgressBarPrivate), parent, 0) | - | ||||||||||||||||||
| 239 | { | - | ||||||||||||||||||
| 240 | d_func()->init(); | - | ||||||||||||||||||
| 241 | } never executed:  end of block | 0 | ||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | /*! | - | ||||||||||||||||||
| 244 | Destructor. | - | ||||||||||||||||||
| 245 | */ | - | ||||||||||||||||||
| 246 | QProgressBar::~QProgressBar() | - | ||||||||||||||||||
| 247 | { | - | ||||||||||||||||||
| 248 | } | - | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | /*! | - | ||||||||||||||||||
| 251 | Reset the progress bar. The progress bar "rewinds" and shows no | - | ||||||||||||||||||
| 252 | progress. | - | ||||||||||||||||||
| 253 | */ | - | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | void QProgressBar::reset() | - | ||||||||||||||||||
| 256 | { | - | ||||||||||||||||||
| 257 | Q_D(QProgressBar); | - | ||||||||||||||||||
| 258 |     if (d->minimum == INT_MIN)
  | 0 | ||||||||||||||||||
| 259 |         d->value = INT_MIN; never executed:  d->value = (-2147483647 - 1); | 0 | ||||||||||||||||||
| 260 | else | - | ||||||||||||||||||
| 261 |         d->value = d->minimum - 1; never executed:  d->value = d->minimum - 1; | 0 | ||||||||||||||||||
| 262 | repaint(); | - | ||||||||||||||||||
| 263 | } never executed:  end of block | 0 | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | /*! | - | ||||||||||||||||||
| 266 | \property QProgressBar::minimum | - | ||||||||||||||||||
| 267 | \brief the progress bar's minimum value | - | ||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | When setting this property, the \l maximum is adjusted if | - | ||||||||||||||||||
| 270 | necessary to ensure that the range remains valid. If the | - | ||||||||||||||||||
| 271 | current value falls outside the new range, the progress bar is reset | - | ||||||||||||||||||
| 272 | with reset(). | - | ||||||||||||||||||
| 273 | */ | - | ||||||||||||||||||
| 274 | void QProgressBar::setMinimum(int minimum) | - | ||||||||||||||||||
| 275 | { | - | ||||||||||||||||||
| 276 | setRange(minimum, qMax(d_func()->maximum, minimum)); | - | ||||||||||||||||||
| 277 | } never executed:  end of block | 0 | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | int QProgressBar::minimum() const | - | ||||||||||||||||||
| 280 | { | - | ||||||||||||||||||
| 281 |     return d_func()->minimum; never executed:  return d_func()->minimum; | 0 | ||||||||||||||||||
| 282 | } | - | ||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | - | |||||||||||||||||||
| 285 | /*! | - | ||||||||||||||||||
| 286 | \property QProgressBar::maximum | - | ||||||||||||||||||
| 287 | \brief the progress bar's maximum value | - | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | When setting this property, the \l minimum is adjusted if | - | ||||||||||||||||||
| 290 | necessary to ensure that the range remains valid. If the | - | ||||||||||||||||||
| 291 | current value falls outside the new range, the progress bar is reset | - | ||||||||||||||||||
| 292 | with reset(). | - | ||||||||||||||||||
| 293 | */ | - | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | void QProgressBar::setMaximum(int maximum) | - | ||||||||||||||||||
| 296 | { | - | ||||||||||||||||||
| 297 | setRange(qMin(d_func()->minimum, maximum), maximum); | - | ||||||||||||||||||
| 298 | } never executed:  end of block | 0 | ||||||||||||||||||
| 299 | - | |||||||||||||||||||
| 300 | int QProgressBar::maximum() const | - | ||||||||||||||||||
| 301 | { | - | ||||||||||||||||||
| 302 |     return d_func()->maximum; never executed:  return d_func()->maximum; | 0 | ||||||||||||||||||
| 303 | } | - | ||||||||||||||||||
| 304 | - | |||||||||||||||||||
| 305 | /*! | - | ||||||||||||||||||
| 306 | \property QProgressBar::value | - | ||||||||||||||||||
| 307 | \brief the progress bar's current value | - | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | Attempting to change the current value to one outside | - | ||||||||||||||||||
| 310 | the minimum-maximum range has no effect on the current value. | - | ||||||||||||||||||
| 311 | */ | - | ||||||||||||||||||
| 312 | void QProgressBar::setValue(int value) | - | ||||||||||||||||||
| 313 | { | - | ||||||||||||||||||
| 314 | Q_D(QProgressBar); | - | ||||||||||||||||||
| 315 |     if (d->value == value
  | 0 | ||||||||||||||||||
| 316 |             || ((value > d->maximum || value < d->minimum)
 
  | 0 | ||||||||||||||||||
| 317 |                 && (d->maximum != 0 || d->minimum != 0)))
 
  | 0 | ||||||||||||||||||
| 318 |         return; never executed:  return; | 0 | ||||||||||||||||||
| 319 | d->value = value; | - | ||||||||||||||||||
| 320 | emit valueChanged(value); | - | ||||||||||||||||||
| 321 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
| 322 |     if (isVisible()) {
  | 0 | ||||||||||||||||||
| 323 | QAccessibleValueChangeEvent event(this, value); | - | ||||||||||||||||||
| 324 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||
| 325 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 326 | #endif | - | ||||||||||||||||||
| 327 |     if (d->repaintRequired())
  | 0 | ||||||||||||||||||
| 328 |         repaint(); never executed:  repaint(); | 0 | ||||||||||||||||||
| 329 | } never executed:  end of block | 0 | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | int QProgressBar::value() const | - | ||||||||||||||||||
| 332 | { | - | ||||||||||||||||||
| 333 |     return d_func()->value; never executed:  return d_func()->value; | 0 | ||||||||||||||||||
| 334 | } | - | ||||||||||||||||||
| 335 | - | |||||||||||||||||||
| 336 | /*! | - | ||||||||||||||||||
| 337 | Sets the progress bar's minimum and maximum values to \a minimum and | - | ||||||||||||||||||
| 338 | \a maximum respectively. | - | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | If \a maximum is smaller than \a minimum, \a minimum becomes the only | - | ||||||||||||||||||
| 341 | legal value. | - | ||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | If the current value falls outside the new range, the progress bar is reset | - | ||||||||||||||||||
| 344 | with reset(). | - | ||||||||||||||||||
| 345 | - | |||||||||||||||||||
| 346 | The QProgressBar can be set to undetermined state by using setRange(0, 0). | - | ||||||||||||||||||
| 347 | - | |||||||||||||||||||
| 348 | \sa minimum, maximum | - | ||||||||||||||||||
| 349 | */ | - | ||||||||||||||||||
| 350 | void QProgressBar::setRange(int minimum, int maximum) | - | ||||||||||||||||||
| 351 | { | - | ||||||||||||||||||
| 352 | Q_D(QProgressBar); | - | ||||||||||||||||||
| 353 |     if (minimum != d->minimum || maximum != d->maximum) {
 
  | 0 | ||||||||||||||||||
| 354 | d->minimum = minimum; | - | ||||||||||||||||||
| 355 | d->maximum = qMax(minimum, maximum); | - | ||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 |         if (d->value < qint64(d->minimum) - 1 || d->value > d->maximum)
 
  | 0 | ||||||||||||||||||
| 358 |             reset(); never executed:  reset(); | 0 | ||||||||||||||||||
| 359 | else | - | ||||||||||||||||||
| 360 |             update(); never executed:  update(); | 0 | ||||||||||||||||||
| 361 | } | - | ||||||||||||||||||
| 362 | } never executed:  end of block | 0 | ||||||||||||||||||
| 363 | - | |||||||||||||||||||
| 364 | /*! | - | ||||||||||||||||||
| 365 | \property QProgressBar::textVisible | - | ||||||||||||||||||
| 366 | \brief whether the current completed percentage should be displayed | - | ||||||||||||||||||
| 367 | - | |||||||||||||||||||
| 368 | This property may be ignored by the style (e.g., QMacStyle never draws the text). | - | ||||||||||||||||||
| 369 | - | |||||||||||||||||||
| 370 | \sa textDirection | - | ||||||||||||||||||
| 371 | */ | - | ||||||||||||||||||
| 372 | void QProgressBar::setTextVisible(bool visible) | - | ||||||||||||||||||
| 373 | { | - | ||||||||||||||||||
| 374 | Q_D(QProgressBar); | - | ||||||||||||||||||
| 375 |     if (d->textVisible != visible) {
  | 0 | ||||||||||||||||||
| 376 | d->textVisible = visible; | - | ||||||||||||||||||
| 377 | repaint(); | - | ||||||||||||||||||
| 378 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 379 | } never executed:  end of block | 0 | ||||||||||||||||||
| 380 | - | |||||||||||||||||||
| 381 | bool QProgressBar::isTextVisible() const | - | ||||||||||||||||||
| 382 | { | - | ||||||||||||||||||
| 383 |     return d_func()->textVisible; never executed:  return d_func()->textVisible; | 0 | ||||||||||||||||||
| 384 | } | - | ||||||||||||||||||
| 385 | - | |||||||||||||||||||
| 386 | /*! | - | ||||||||||||||||||
| 387 | \property QProgressBar::alignment | - | ||||||||||||||||||
| 388 | \brief the alignment of the progress bar | - | ||||||||||||||||||
| 389 | */ | - | ||||||||||||||||||
| 390 | void QProgressBar::setAlignment(Qt::Alignment alignment) | - | ||||||||||||||||||
| 391 | { | - | ||||||||||||||||||
| 392 |     if (d_func()->alignment != alignment) {
  | 0 | ||||||||||||||||||
| 393 | d_func()->alignment = alignment; | - | ||||||||||||||||||
| 394 | repaint(); | - | ||||||||||||||||||
| 395 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 396 | } never executed:  end of block | 0 | ||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | Qt::Alignment QProgressBar::alignment() const | - | ||||||||||||||||||
| 399 | { | - | ||||||||||||||||||
| 400 |     return d_func()->alignment; never executed:  return d_func()->alignment; | 0 | ||||||||||||||||||
| 401 | } | - | ||||||||||||||||||
| 402 | - | |||||||||||||||||||
| 403 | /*! | - | ||||||||||||||||||
| 404 | \reimp | - | ||||||||||||||||||
| 405 | */ | - | ||||||||||||||||||
| 406 | void QProgressBar::paintEvent(QPaintEvent *) | - | ||||||||||||||||||
| 407 | { | - | ||||||||||||||||||
| 408 | QStylePainter paint(this); | - | ||||||||||||||||||
| 409 | QStyleOptionProgressBar opt; | - | ||||||||||||||||||
| 410 | initStyleOption(&opt); | - | ||||||||||||||||||
| 411 | paint.drawControl(QStyle::CE_ProgressBar, opt); | - | ||||||||||||||||||
| 412 | d_func()->lastPaintedValue = d_func()->value; | - | ||||||||||||||||||
| 413 | } never executed:  end of block | 0 | ||||||||||||||||||
| 414 | - | |||||||||||||||||||
| 415 | /*! | - | ||||||||||||||||||
| 416 | \reimp | - | ||||||||||||||||||
| 417 | */ | - | ||||||||||||||||||
| 418 | QSize QProgressBar::sizeHint() const | - | ||||||||||||||||||
| 419 | { | - | ||||||||||||||||||
| 420 | ensurePolished(); | - | ||||||||||||||||||
| 421 | QFontMetrics fm = fontMetrics(); | - | ||||||||||||||||||
| 422 | QStyleOptionProgressBar opt; | - | ||||||||||||||||||
| 423 | initStyleOption(&opt); | - | ||||||||||||||||||
| 424 | int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, this); | - | ||||||||||||||||||
| 425 | QSize size = QSize(qMax(9, cw) * 7 + fm.width(QLatin1Char('0')) * 4, fm.height() + 8); | - | ||||||||||||||||||
| 426 |     if (opt.orientation == Qt::Vertical)
  | 0 | ||||||||||||||||||
| 427 |         size = size.transposed(); never executed:  size = size.transposed(); | 0 | ||||||||||||||||||
| 428 |     return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this); never executed:  return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this); | 0 | ||||||||||||||||||
| 429 | } | - | ||||||||||||||||||
| 430 | - | |||||||||||||||||||
| 431 | /*! | - | ||||||||||||||||||
| 432 | \reimp | - | ||||||||||||||||||
| 433 | */ | - | ||||||||||||||||||
| 434 | QSize QProgressBar::minimumSizeHint() const | - | ||||||||||||||||||
| 435 | { | - | ||||||||||||||||||
| 436 | QSize size; | - | ||||||||||||||||||
| 437 |     if (orientation() == Qt::Horizontal)
  | 0 | ||||||||||||||||||
| 438 |         size = QSize(sizeHint().width(), fontMetrics().height() + 2); never executed:  size = QSize(sizeHint().width(), fontMetrics().height() + 2); | 0 | ||||||||||||||||||
| 439 | else | - | ||||||||||||||||||
| 440 |         size = QSize(fontMetrics().height() + 2, sizeHint().height()); never executed:  size = QSize(fontMetrics().height() + 2, sizeHint().height()); | 0 | ||||||||||||||||||
| 441 |     return size; never executed:  return size; | 0 | ||||||||||||||||||
| 442 | } | - | ||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | /*! | - | ||||||||||||||||||
| 445 | \property QProgressBar::text | - | ||||||||||||||||||
| 446 | \brief the descriptive text shown with the progress bar | - | ||||||||||||||||||
| 447 | - | |||||||||||||||||||
| 448 | The text returned is the same as the text displayed in the center | - | ||||||||||||||||||
| 449 | (or in some styles, to the left) of the progress bar. | - | ||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | The progress shown in the text may be smaller than the minimum value, | - | ||||||||||||||||||
| 452 | indicating that the progress bar is in the "reset" state before any | - | ||||||||||||||||||
| 453 | progress is set. | - | ||||||||||||||||||
| 454 | - | |||||||||||||||||||
| 455 | In the default implementation, the text either contains a percentage | - | ||||||||||||||||||
| 456 | value that indicates the progress so far, or it is blank because the | - | ||||||||||||||||||
| 457 | progress bar is in the reset state. | - | ||||||||||||||||||
| 458 | */ | - | ||||||||||||||||||
| 459 | QString QProgressBar::text() const | - | ||||||||||||||||||
| 460 | { | - | ||||||||||||||||||
| 461 | Q_D(const QProgressBar); | - | ||||||||||||||||||
| 462 |     if ((d->maximum == 0 && d->minimum == 0) || d->value < d->minimum
 
 
  | 0 | ||||||||||||||||||
| 463 |             || (d->value == INT_MIN && d->minimum == INT_MIN))
 
  | 0 | ||||||||||||||||||
| 464 |         return QString(); never executed:  return QString(); | 0 | ||||||||||||||||||
| 465 | - | |||||||||||||||||||
| 466 | qint64 totalSteps = qint64(d->maximum) - d->minimum; | - | ||||||||||||||||||
| 467 | - | |||||||||||||||||||
| 468 | QString result = d->format; | - | ||||||||||||||||||
| 469 | QLocale locale = d->locale; // Omit group separators for compatibility with previous versions that were non-localized. | - | ||||||||||||||||||
| 470 | locale.setNumberOptions(locale.numberOptions() | QLocale::OmitGroupSeparator); | - | ||||||||||||||||||
| 471 | result.replace(QLatin1String("%m"), locale.toString(totalSteps)); | - | ||||||||||||||||||
| 472 | result.replace(QLatin1String("%v"), locale.toString(d->value)); | - | ||||||||||||||||||
| 473 | - | |||||||||||||||||||
| 474 | // If max and min are equal and we get this far, it means that the | - | ||||||||||||||||||
| 475 | // progress bar has one step and that we are on that step. Return | - | ||||||||||||||||||
| 476 | // 100% here in order to avoid division by zero further down. | - | ||||||||||||||||||
| 477 |     if (totalSteps == 0) {
  | 0 | ||||||||||||||||||
| 478 | result.replace(QLatin1String("%p"), locale.toString(int(100))); | - | ||||||||||||||||||
| 479 |         return result; never executed:  return result; | 0 | ||||||||||||||||||
| 480 | } | - | ||||||||||||||||||
| 481 | - | |||||||||||||||||||
| 482 | int progress = (qreal(d->value) - d->minimum) * 100.0 / totalSteps; | - | ||||||||||||||||||
| 483 | result.replace(QLatin1String("%p"), locale.toString(progress)); | - | ||||||||||||||||||
| 484 |     return result; never executed:  return result; | 0 | ||||||||||||||||||
| 485 | } | - | ||||||||||||||||||
| 486 | - | |||||||||||||||||||
| 487 | /*! | - | ||||||||||||||||||
| 488 | \since 4.1 | - | ||||||||||||||||||
| 489 | \property QProgressBar::orientation | - | ||||||||||||||||||
| 490 | \brief the orientation of the progress bar | - | ||||||||||||||||||
| 491 | - | |||||||||||||||||||
| 492 | The orientation must be \l Qt::Horizontal (the default) or \l | - | ||||||||||||||||||
| 493 | Qt::Vertical. | - | ||||||||||||||||||
| 494 | - | |||||||||||||||||||
| 495 | \sa invertedAppearance, textDirection | - | ||||||||||||||||||
| 496 | */ | - | ||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | void QProgressBar::setOrientation(Qt::Orientation orientation) | - | ||||||||||||||||||
| 499 | { | - | ||||||||||||||||||
| 500 | Q_D(QProgressBar); | - | ||||||||||||||||||
| 501 |     if (d->orientation == orientation)
  | 0 | ||||||||||||||||||
| 502 |         return; never executed:  return; | 0 | ||||||||||||||||||
| 503 | d->orientation = orientation; | - | ||||||||||||||||||
| 504 |     if (!testAttribute(Qt::WA_WState_OwnSizePolicy)) {
  | 0 | ||||||||||||||||||
| 505 | QSizePolicy sp = sizePolicy(); | - | ||||||||||||||||||
| 506 | sp.transpose(); | - | ||||||||||||||||||
| 507 | setSizePolicy(sp); | - | ||||||||||||||||||
| 508 | setAttribute(Qt::WA_WState_OwnSizePolicy, false); | - | ||||||||||||||||||
| 509 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 510 | d->resetLayoutItemMargins(); | - | ||||||||||||||||||
| 511 | update(); | - | ||||||||||||||||||
| 512 | updateGeometry(); | - | ||||||||||||||||||
| 513 | } never executed:  end of block | 0 | ||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | Qt::Orientation QProgressBar::orientation() const | - | ||||||||||||||||||
| 516 | { | - | ||||||||||||||||||
| 517 | Q_D(const QProgressBar); | - | ||||||||||||||||||
| 518 |     return d->orientation; never executed:  return d->orientation; | 0 | ||||||||||||||||||
| 519 | } | - | ||||||||||||||||||
| 520 | - | |||||||||||||||||||
| 521 | /*! | - | ||||||||||||||||||
| 522 | \since 4.1 | - | ||||||||||||||||||
| 523 | \property QProgressBar::invertedAppearance | - | ||||||||||||||||||
| 524 | \brief whether or not a progress bar shows its progress inverted | - | ||||||||||||||||||
| 525 | - | |||||||||||||||||||
| 526 | If this property is \c true, the progress bar grows in the other | - | ||||||||||||||||||
| 527 | direction (e.g. from right to left). By default, the progress bar | - | ||||||||||||||||||
| 528 | is not inverted. | - | ||||||||||||||||||
| 529 | - | |||||||||||||||||||
| 530 | \sa orientation, layoutDirection | - | ||||||||||||||||||
| 531 | */ | - | ||||||||||||||||||
| 532 | - | |||||||||||||||||||
| 533 | void QProgressBar::setInvertedAppearance(bool invert) | - | ||||||||||||||||||
| 534 | { | - | ||||||||||||||||||
| 535 | Q_D(QProgressBar); | - | ||||||||||||||||||
| 536 | d->invertedAppearance = invert; | - | ||||||||||||||||||
| 537 | update(); | - | ||||||||||||||||||
| 538 | } never executed:  end of block | 0 | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | bool QProgressBar::invertedAppearance() const | - | ||||||||||||||||||
| 541 | { | - | ||||||||||||||||||
| 542 | Q_D(const QProgressBar); | - | ||||||||||||||||||
| 543 |     return d->invertedAppearance; never executed:  return d->invertedAppearance; | 0 | ||||||||||||||||||
| 544 | } | - | ||||||||||||||||||
| 545 | - | |||||||||||||||||||
| 546 | /*! | - | ||||||||||||||||||
| 547 | \since 4.1 | - | ||||||||||||||||||
| 548 | \property QProgressBar::textDirection | - | ||||||||||||||||||
| 549 | \brief the reading direction of the \l text for vertical progress bars | - | ||||||||||||||||||
| 550 | - | |||||||||||||||||||
| 551 | This property has no impact on horizontal progress bars. | - | ||||||||||||||||||
| 552 | By default, the reading direction is QProgressBar::TopToBottom. | - | ||||||||||||||||||
| 553 | - | |||||||||||||||||||
| 554 | \sa orientation, textVisible | - | ||||||||||||||||||
| 555 | */ | - | ||||||||||||||||||
| 556 | void QProgressBar::setTextDirection(QProgressBar::Direction textDirection) | - | ||||||||||||||||||
| 557 | { | - | ||||||||||||||||||
| 558 | Q_D(QProgressBar); | - | ||||||||||||||||||
| 559 | d->textDirection = textDirection; | - | ||||||||||||||||||
| 560 | update(); | - | ||||||||||||||||||
| 561 | } never executed:  end of block | 0 | ||||||||||||||||||
| 562 | - | |||||||||||||||||||
| 563 | QProgressBar::Direction QProgressBar::textDirection() const | - | ||||||||||||||||||
| 564 | { | - | ||||||||||||||||||
| 565 | Q_D(const QProgressBar); | - | ||||||||||||||||||
| 566 |     return d->textDirection; never executed:  return d->textDirection; | 0 | ||||||||||||||||||
| 567 | } | - | ||||||||||||||||||
| 568 | - | |||||||||||||||||||
| 569 | /*! \reimp */ | - | ||||||||||||||||||
| 570 | bool QProgressBar::event(QEvent *e) | - | ||||||||||||||||||
| 571 | { | - | ||||||||||||||||||
| 572 | Q_D(QProgressBar); | - | ||||||||||||||||||
| 573 | switch (e->type()) { | - | ||||||||||||||||||
| 574 |     case QEvent::StyleChange: never executed:  case QEvent::StyleChange: | 0 | ||||||||||||||||||
| 575 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
| 576 | case QEvent::MacSizeChange: | - | ||||||||||||||||||
| 577 | #endif | - | ||||||||||||||||||
| 578 | d->resetLayoutItemMargins(); | - | ||||||||||||||||||
| 579 |         break; never executed:  break; | 0 | ||||||||||||||||||
| 580 |     case QEvent::LocaleChange: never executed:  case QEvent::LocaleChange: | 0 | ||||||||||||||||||
| 581 | d->initDefaultFormat(); | - | ||||||||||||||||||
| 582 |         break; never executed:  break; | 0 | ||||||||||||||||||
| 583 |     default: never executed:  default: | 0 | ||||||||||||||||||
| 584 |         break; never executed:  break; | 0 | ||||||||||||||||||
| 585 | } | - | ||||||||||||||||||
| 586 |     return QWidget::event(e); never executed:  return QWidget::event(e); | 0 | ||||||||||||||||||
| 587 | } | - | ||||||||||||||||||
| 588 | - | |||||||||||||||||||
| 589 | /*! | - | ||||||||||||||||||
| 590 | \since 4.2 | - | ||||||||||||||||||
| 591 | \property QProgressBar::format | - | ||||||||||||||||||
| 592 | \brief the string used to generate the current text | - | ||||||||||||||||||
| 593 | - | |||||||||||||||||||
| 594 | %p - is replaced by the percentage completed. | - | ||||||||||||||||||
| 595 | %v - is replaced by the current value. | - | ||||||||||||||||||
| 596 | %m - is replaced by the total number of steps. | - | ||||||||||||||||||
| 597 | - | |||||||||||||||||||
| 598 | The default value is "%p%". | - | ||||||||||||||||||
| 599 | - | |||||||||||||||||||
| 600 | \sa text() | - | ||||||||||||||||||
| 601 | */ | - | ||||||||||||||||||
| 602 | void QProgressBar::setFormat(const QString &format) | - | ||||||||||||||||||
| 603 | { | - | ||||||||||||||||||
| 604 | Q_D(QProgressBar); | - | ||||||||||||||||||
| 605 |     if (d->format == format)
  | 0 | ||||||||||||||||||
| 606 |         return; never executed:  return; | 0 | ||||||||||||||||||
| 607 | d->format = format; | - | ||||||||||||||||||
| 608 | d->defaultFormat = false; | - | ||||||||||||||||||
| 609 | update(); | - | ||||||||||||||||||
| 610 | } never executed:  end of block | 0 | ||||||||||||||||||
| 611 | - | |||||||||||||||||||
| 612 | void QProgressBar::resetFormat() | - | ||||||||||||||||||
| 613 | { | - | ||||||||||||||||||
| 614 | Q_D(QProgressBar); | - | ||||||||||||||||||
| 615 | d->defaultFormat = true; | - | ||||||||||||||||||
| 616 | d->initDefaultFormat(); | - | ||||||||||||||||||
| 617 | update(); | - | ||||||||||||||||||
| 618 | } never executed:  end of block | 0 | ||||||||||||||||||
| 619 | - | |||||||||||||||||||
| 620 | QString QProgressBar::format() const | - | ||||||||||||||||||
| 621 | { | - | ||||||||||||||||||
| 622 | Q_D(const QProgressBar); | - | ||||||||||||||||||
| 623 |     return d->format; never executed:  return d->format; | 0 | ||||||||||||||||||
| 624 | } | - | ||||||||||||||||||
| 625 | - | |||||||||||||||||||
| 626 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 627 | - | |||||||||||||||||||
| 628 | #include "moc_qprogressbar.cpp" | - | ||||||||||||||||||
| 629 | - | |||||||||||||||||||
| 630 | #endif // QT_NO_PROGRESSBAR | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |