| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qstatusbar.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtWidgets 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 The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | #include "qstatusbar.h" | - | ||||||||||||||||||||||||
| 41 | #ifndef QT_NO_STATUSBAR | - | ||||||||||||||||||||||||
| 42 | - | |||||||||||||||||||||||||
| 43 | #include "qlist.h" | - | ||||||||||||||||||||||||
| 44 | #include "qdebug.h" | - | ||||||||||||||||||||||||
| 45 | #include "qevent.h" | - | ||||||||||||||||||||||||
| 46 | #include "qlayout.h" | - | ||||||||||||||||||||||||
| 47 | #include "qpainter.h" | - | ||||||||||||||||||||||||
| 48 | #include "qtimer.h" | - | ||||||||||||||||||||||||
| 49 | #include "qstyle.h" | - | ||||||||||||||||||||||||
| 50 | #include "qstyleoption.h" | - | ||||||||||||||||||||||||
| 51 | #include "qsizegrip.h" | - | ||||||||||||||||||||||||
| 52 | #include "qmainwindow.h" | - | ||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||
| 54 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 55 | #include "qaccessible.h" | - | ||||||||||||||||||||||||
| 56 | #endif | - | ||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||
| 58 | #include <private/qlayoutengine_p.h> | - | ||||||||||||||||||||||||
| 59 | #include <private/qwidget_p.h> | - | ||||||||||||||||||||||||
| 60 | - | |||||||||||||||||||||||||
| 61 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 62 | - | |||||||||||||||||||||||||
| 63 | class QStatusBarPrivate : public QWidgetPrivate | - | ||||||||||||||||||||||||
| 64 | { | - | ||||||||||||||||||||||||
| 65 | Q_DECLARE_PUBLIC(QStatusBar) | - | ||||||||||||||||||||||||
| 66 | public: | - | ||||||||||||||||||||||||
| 67 | QStatusBarPrivate() {} | - | ||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||
| 69 | struct SBItem { | - | ||||||||||||||||||||||||
| 70 | SBItem(QWidget* widget, int stretch, bool permanent) | - | ||||||||||||||||||||||||
| 71 | : s(stretch), w(widget), p(permanent) {} never executed: end of block | 0 | ||||||||||||||||||||||||
| 72 | int s; | - | ||||||||||||||||||||||||
| 73 | QWidget * w; | - | ||||||||||||||||||||||||
| 74 | bool p; | - | ||||||||||||||||||||||||
| 75 | }; | - | ||||||||||||||||||||||||
| 76 | - | |||||||||||||||||||||||||
| 77 | QList<SBItem *> items; | - | ||||||||||||||||||||||||
| 78 | QString tempItem; | - | ||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||
| 80 | QBoxLayout * box; | - | ||||||||||||||||||||||||
| 81 | QTimer * timer; | - | ||||||||||||||||||||||||
| 82 | - | |||||||||||||||||||||||||
| 83 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
| 84 | QSizeGrip * resizer; | - | ||||||||||||||||||||||||
| 85 | bool showSizeGrip; | - | ||||||||||||||||||||||||
| 86 | #endif | - | ||||||||||||||||||||||||
| 87 | - | |||||||||||||||||||||||||
| 88 | int savedStrut; | - | ||||||||||||||||||||||||
| 89 | - | |||||||||||||||||||||||||
| 90 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||||||||
| 91 | QPoint dragStart; | - | ||||||||||||||||||||||||
| 92 | #endif | - | ||||||||||||||||||||||||
| 93 | - | |||||||||||||||||||||||||
| 94 | int indexToLastNonPermanentWidget() const | - | ||||||||||||||||||||||||
| 95 | { | - | ||||||||||||||||||||||||
| 96 | int i = items.size() - 1; | - | ||||||||||||||||||||||||
| 97 | for (; i >= 0; --i) {
| 0 | ||||||||||||||||||||||||
| 98 | SBItem *item = items.at(i); | - | ||||||||||||||||||||||||
| 99 | if (!(item && item->p))
| 0 | ||||||||||||||||||||||||
| 100 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 101 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 102 | return i; never executed: return i; | 0 | ||||||||||||||||||||||||
| 103 | } | - | ||||||||||||||||||||||||
| 104 | - | |||||||||||||||||||||||||
| 105 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
| 106 | void tryToShowSizeGrip() | - | ||||||||||||||||||||||||
| 107 | { | - | ||||||||||||||||||||||||
| 108 | if (!showSizeGrip)
| 0 | ||||||||||||||||||||||||
| 109 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 110 | showSizeGrip = false; | - | ||||||||||||||||||||||||
| 111 | if (!resizer || resizer->isVisible())
| 0 | ||||||||||||||||||||||||
| 112 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 113 | resizer->setAttribute(Qt::WA_WState_ExplicitShowHide, false); | - | ||||||||||||||||||||||||
| 114 | QMetaObject::invokeMethod(resizer, "_q_showIfNotHidden", Qt::DirectConnection); | - | ||||||||||||||||||||||||
| 115 | resizer->setAttribute(Qt::WA_WState_ExplicitShowHide, false); | - | ||||||||||||||||||||||||
| 116 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 117 | #endif | - | ||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||
| 119 | QRect messageRect() const; | - | ||||||||||||||||||||||||
| 120 | }; | - | ||||||||||||||||||||||||
| 121 | - | |||||||||||||||||||||||||
| 122 | - | |||||||||||||||||||||||||
| 123 | QRect QStatusBarPrivate::messageRect() const | - | ||||||||||||||||||||||||
| 124 | { | - | ||||||||||||||||||||||||
| 125 | Q_Q(const QStatusBar); | - | ||||||||||||||||||||||||
| 126 | bool rtl = q->layoutDirection() == Qt::RightToLeft; | - | ||||||||||||||||||||||||
| 127 | - | |||||||||||||||||||||||||
| 128 | int left = 6; | - | ||||||||||||||||||||||||
| 129 | int right = q->width() - 12; | - | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
| 132 | if (resizer && resizer->isVisible()) {
| 0 | ||||||||||||||||||||||||
| 133 | if (rtl)
| 0 | ||||||||||||||||||||||||
| 134 | left = resizer->x() + resizer->width(); never executed: left = resizer->x() + resizer->width(); | 0 | ||||||||||||||||||||||||
| 135 | else | - | ||||||||||||||||||||||||
| 136 | right = resizer->x(); never executed: right = resizer->x(); | 0 | ||||||||||||||||||||||||
| 137 | } | - | ||||||||||||||||||||||||
| 138 | #endif | - | ||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||
| 140 | for (int i=0; i<items.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 141 | QStatusBarPrivate::SBItem* item = items.at(i); | - | ||||||||||||||||||||||||
| 142 | if (!item)
| 0 | ||||||||||||||||||||||||
| 143 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 144 | if (item->p && item->w->isVisible()) {
| 0 | ||||||||||||||||||||||||
| 145 | if (item->p) {
| 0 | ||||||||||||||||||||||||
| 146 | if (rtl)
| 0 | ||||||||||||||||||||||||
| 147 | left = qMax(left, item->w->x() + item->w->width() + 2); never executed: left = qMax(left, item->w->x() + item->w->width() + 2); | 0 | ||||||||||||||||||||||||
| 148 | else | - | ||||||||||||||||||||||||
| 149 | right = qMin(right, item->w->x() - 2); never executed: right = qMin(right, item->w->x() - 2); | 0 | ||||||||||||||||||||||||
| 150 | } | - | ||||||||||||||||||||||||
| 151 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 152 | } | - | ||||||||||||||||||||||||
| 153 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 154 | return QRect(left, 0, right-left, q->height()); never executed: return QRect(left, 0, right-left, q->height()); | 0 | ||||||||||||||||||||||||
| 155 | } | - | ||||||||||||||||||||||||
| 156 | - | |||||||||||||||||||||||||
| 157 | - | |||||||||||||||||||||||||
| 158 | /*! | - | ||||||||||||||||||||||||
| 159 | \class QStatusBar | - | ||||||||||||||||||||||||
| 160 | \brief The QStatusBar class provides a horizontal bar suitable for | - | ||||||||||||||||||||||||
| 161 | presenting status information. | - | ||||||||||||||||||||||||
| 162 | - | |||||||||||||||||||||||||
| 163 | \ingroup mainwindow-classes | - | ||||||||||||||||||||||||
| 164 | \ingroup helpsystem | - | ||||||||||||||||||||||||
| 165 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
| 166 | - | |||||||||||||||||||||||||
| 167 | Each status indicator falls into one of three categories: | - | ||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||
| 169 | \list | - | ||||||||||||||||||||||||
| 170 | \li \e Temporary - briefly occupies most of the status bar. Used | - | ||||||||||||||||||||||||
| 171 | to explain tool tip texts or menu entries, for example. | - | ||||||||||||||||||||||||
| 172 | \li \e Normal - occupies part of the status bar and may be hidden | - | ||||||||||||||||||||||||
| 173 | by temporary messages. Used to display the page and line | - | ||||||||||||||||||||||||
| 174 | number in a word processor, for example. | - | ||||||||||||||||||||||||
| 175 | \li \e Permanent - is never hidden. Used for important mode | - | ||||||||||||||||||||||||
| 176 | indications, for example, some applications put a Caps Lock | - | ||||||||||||||||||||||||
| 177 | indicator in the status bar. | - | ||||||||||||||||||||||||
| 178 | \endlist | - | ||||||||||||||||||||||||
| 179 | - | |||||||||||||||||||||||||
| 180 | QStatusBar lets you display all three types of indicators. | - | ||||||||||||||||||||||||
| 181 | - | |||||||||||||||||||||||||
| 182 | Typically, a request for the status bar functionality occurs in | - | ||||||||||||||||||||||||
| 183 | relation to a QMainWindow object. QMainWindow provides a main | - | ||||||||||||||||||||||||
| 184 | application window, with a menu bar, tool bars, dock widgets \e | - | ||||||||||||||||||||||||
| 185 | and a status bar around a large central widget. The status bar can | - | ||||||||||||||||||||||||
| 186 | be retrieved using the QMainWindow::statusBar() function, and | - | ||||||||||||||||||||||||
| 187 | replaced using the QMainWindow::setStatusBar() function. | - | ||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||
| 189 | Use the showMessage() slot to display a \e temporary message: | - | ||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||
| 191 | \snippet mainwindows/dockwidgets/mainwindow.cpp 8 | - | ||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||
| 193 | To remove a temporary message, use the clearMessage() slot, or set | - | ||||||||||||||||||||||||
| 194 | a time limit when calling showMessage(). For example: | - | ||||||||||||||||||||||||
| 195 | - | |||||||||||||||||||||||||
| 196 | \snippet mainwindows/dockwidgets/mainwindow.cpp 3 | - | ||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||
| 198 | Use the currentMessage() function to retrieve the temporary | - | ||||||||||||||||||||||||
| 199 | message currently shown. The QStatusBar class also provide the | - | ||||||||||||||||||||||||
| 200 | messageChanged() signal which is emitted whenever the temporary | - | ||||||||||||||||||||||||
| 201 | status message changes. | - | ||||||||||||||||||||||||
| 202 | - | |||||||||||||||||||||||||
| 203 | \target permanent message | - | ||||||||||||||||||||||||
| 204 | \e Normal and \e Permanent messages are displayed by creating a | - | ||||||||||||||||||||||||
| 205 | small widget (QLabel, QProgressBar or even QToolButton) and then | - | ||||||||||||||||||||||||
| 206 | adding it to the status bar using the addWidget() or the | - | ||||||||||||||||||||||||
| 207 | addPermanentWidget() function. Use the removeWidget() function to | - | ||||||||||||||||||||||||
| 208 | remove such messages from the status bar. | - | ||||||||||||||||||||||||
| 209 | - | |||||||||||||||||||||||||
| 210 | \snippet code/src_gui_widgets_qstatusbar.cpp 0 | - | ||||||||||||||||||||||||
| 211 | - | |||||||||||||||||||||||||
| 212 | By default QStatusBar provides a QSizeGrip in the lower-right | - | ||||||||||||||||||||||||
| 213 | corner. You can disable it using the setSizeGripEnabled() | - | ||||||||||||||||||||||||
| 214 | function. Use the isSizeGripEnabled() function to determine the | - | ||||||||||||||||||||||||
| 215 | current status of the size grip. | - | ||||||||||||||||||||||||
| 216 | - | |||||||||||||||||||||||||
| 217 | \image fusion-statusbar-sizegrip.png A status bar shown in the Fusion widget style | - | ||||||||||||||||||||||||
| 218 | - | |||||||||||||||||||||||||
| 219 | \sa QMainWindow, QStatusTipEvent, {fowler}{GUI Design Handbook: | - | ||||||||||||||||||||||||
| 220 | Status Bar}, {Application Example} | - | ||||||||||||||||||||||||
| 221 | */ | - | ||||||||||||||||||||||||
| 222 | - | |||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||
| 224 | /*! | - | ||||||||||||||||||||||||
| 225 | Constructs a status bar with a size grip and the given \a parent. | - | ||||||||||||||||||||||||
| 226 | - | |||||||||||||||||||||||||
| 227 | \sa setSizeGripEnabled() | - | ||||||||||||||||||||||||
| 228 | */ | - | ||||||||||||||||||||||||
| 229 | QStatusBar::QStatusBar(QWidget * parent) | - | ||||||||||||||||||||||||
| 230 | : QWidget(*new QStatusBarPrivate, parent, 0) | - | ||||||||||||||||||||||||
| 231 | { | - | ||||||||||||||||||||||||
| 232 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 233 | d->box = 0; | - | ||||||||||||||||||||||||
| 234 | d->timer = 0; | - | ||||||||||||||||||||||||
| 235 | - | |||||||||||||||||||||||||
| 236 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
| 237 | d->resizer = 0; | - | ||||||||||||||||||||||||
| 238 | setSizeGripEnabled(true); // causes reformat() | - | ||||||||||||||||||||||||
| 239 | #else | - | ||||||||||||||||||||||||
| 240 | reformat(); | - | ||||||||||||||||||||||||
| 241 | #endif | - | ||||||||||||||||||||||||
| 242 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 243 | - | |||||||||||||||||||||||||
| 244 | /*! | - | ||||||||||||||||||||||||
| 245 | Destroys this status bar and frees any allocated resources and | - | ||||||||||||||||||||||||
| 246 | child widgets. | - | ||||||||||||||||||||||||
| 247 | */ | - | ||||||||||||||||||||||||
| 248 | QStatusBar::~QStatusBar() | - | ||||||||||||||||||||||||
| 249 | { | - | ||||||||||||||||||||||||
| 250 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 251 | while (!d->items.isEmpty())
| 0 | ||||||||||||||||||||||||
| 252 | delete d->items.takeFirst(); never executed: delete d->items.takeFirst(); | 0 | ||||||||||||||||||||||||
| 253 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 254 | - | |||||||||||||||||||||||||
| 255 | - | |||||||||||||||||||||||||
| 256 | /*! | - | ||||||||||||||||||||||||
| 257 | Adds the given \a widget to this status bar, reparenting the | - | ||||||||||||||||||||||||
| 258 | widget if it isn't already a child of this QStatusBar object. The | - | ||||||||||||||||||||||||
| 259 | \a stretch parameter is used to compute a suitable size for the | - | ||||||||||||||||||||||||
| 260 | given \a widget as the status bar grows and shrinks. The default | - | ||||||||||||||||||||||||
| 261 | stretch factor is 0, i.e giving the widget a minimum of space. | - | ||||||||||||||||||||||||
| 262 | - | |||||||||||||||||||||||||
| 263 | The widget is located to the far left of the first permanent | - | ||||||||||||||||||||||||
| 264 | widget (see addPermanentWidget()) and may be obscured by temporary | - | ||||||||||||||||||||||||
| 265 | messages. | - | ||||||||||||||||||||||||
| 266 | - | |||||||||||||||||||||||||
| 267 | \sa insertWidget(), removeWidget(), addPermanentWidget() | - | ||||||||||||||||||||||||
| 268 | */ | - | ||||||||||||||||||||||||
| 269 | - | |||||||||||||||||||||||||
| 270 | void QStatusBar::addWidget(QWidget * widget, int stretch) | - | ||||||||||||||||||||||||
| 271 | { | - | ||||||||||||||||||||||||
| 272 | if (!widget)
| 0 | ||||||||||||||||||||||||
| 273 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 274 | insertWidget(d_func()->indexToLastNonPermanentWidget() + 1, widget, stretch); | - | ||||||||||||||||||||||||
| 275 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 276 | - | |||||||||||||||||||||||||
| 277 | /*! | - | ||||||||||||||||||||||||
| 278 | \since 4.2 | - | ||||||||||||||||||||||||
| 279 | - | |||||||||||||||||||||||||
| 280 | Inserts the given \a widget at the given \a index to this status bar, | - | ||||||||||||||||||||||||
| 281 | reparenting the widget if it isn't already a child of this | - | ||||||||||||||||||||||||
| 282 | QStatusBar object. If \a index is out of range, the widget is appended | - | ||||||||||||||||||||||||
| 283 | (in which case it is the actual index of the widget that is returned). | - | ||||||||||||||||||||||||
| 284 | - | |||||||||||||||||||||||||
| 285 | The \a stretch parameter is used to compute a suitable size for | - | ||||||||||||||||||||||||
| 286 | the given \a widget as the status bar grows and shrinks. The | - | ||||||||||||||||||||||||
| 287 | default stretch factor is 0, i.e giving the widget a minimum of | - | ||||||||||||||||||||||||
| 288 | space. | - | ||||||||||||||||||||||||
| 289 | - | |||||||||||||||||||||||||
| 290 | The widget is located to the far left of the first permanent | - | ||||||||||||||||||||||||
| 291 | widget (see addPermanentWidget()) and may be obscured by temporary | - | ||||||||||||||||||||||||
| 292 | messages. | - | ||||||||||||||||||||||||
| 293 | - | |||||||||||||||||||||||||
| 294 | \sa addWidget(), removeWidget(), addPermanentWidget() | - | ||||||||||||||||||||||||
| 295 | */ | - | ||||||||||||||||||||||||
| 296 | int QStatusBar::insertWidget(int index, QWidget *widget, int stretch) | - | ||||||||||||||||||||||||
| 297 | { | - | ||||||||||||||||||||||||
| 298 | if (!widget)
| 0 | ||||||||||||||||||||||||
| 299 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
| 300 | - | |||||||||||||||||||||||||
| 301 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 302 | QStatusBarPrivate::SBItem* item = new QStatusBarPrivate::SBItem(widget, stretch, false); | - | ||||||||||||||||||||||||
| 303 | - | |||||||||||||||||||||||||
| 304 | int idx = d->indexToLastNonPermanentWidget(); | - | ||||||||||||||||||||||||
| 305 | if (Q_UNLIKELY(index < 0 || index > d->items.size() || (idx >= 0 && index > idx + 1))) {
| 0 | ||||||||||||||||||||||||
| 306 | qWarning("QStatusBar::insertWidget: Index out of range (%d), appending widget", index); | - | ||||||||||||||||||||||||
| 307 | index = idx + 1; | - | ||||||||||||||||||||||||
| 308 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 309 | d->items.insert(index, item); | - | ||||||||||||||||||||||||
| 310 | - | |||||||||||||||||||||||||
| 311 | if (!d->tempItem.isEmpty())
| 0 | ||||||||||||||||||||||||
| 312 | widget->hide(); never executed: widget->hide(); | 0 | ||||||||||||||||||||||||
| 313 | - | |||||||||||||||||||||||||
| 314 | reformat(); | - | ||||||||||||||||||||||||
| 315 | if (!widget->isHidden() || !widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
| 0 | ||||||||||||||||||||||||
| 316 | widget->show(); never executed: widget->show(); | 0 | ||||||||||||||||||||||||
| 317 | - | |||||||||||||||||||||||||
| 318 | return index; never executed: return index; | 0 | ||||||||||||||||||||||||
| 319 | } | - | ||||||||||||||||||||||||
| 320 | - | |||||||||||||||||||||||||
| 321 | /*! | - | ||||||||||||||||||||||||
| 322 | Adds the given \a widget permanently to this status bar, | - | ||||||||||||||||||||||||
| 323 | reparenting the widget if it isn't already a child of this | - | ||||||||||||||||||||||||
| 324 | QStatusBar object. The \a stretch parameter is used to compute a | - | ||||||||||||||||||||||||
| 325 | suitable size for the given \a widget as the status bar grows and | - | ||||||||||||||||||||||||
| 326 | shrinks. The default stretch factor is 0, i.e giving the widget a | - | ||||||||||||||||||||||||
| 327 | minimum of space. | - | ||||||||||||||||||||||||
| 328 | - | |||||||||||||||||||||||||
| 329 | Permanently means that the widget may not be obscured by temporary | - | ||||||||||||||||||||||||
| 330 | messages. It is is located at the far right of the status bar. | - | ||||||||||||||||||||||||
| 331 | - | |||||||||||||||||||||||||
| 332 | \sa insertPermanentWidget(), removeWidget(), addWidget() | - | ||||||||||||||||||||||||
| 333 | */ | - | ||||||||||||||||||||||||
| 334 | - | |||||||||||||||||||||||||
| 335 | void QStatusBar::addPermanentWidget(QWidget * widget, int stretch) | - | ||||||||||||||||||||||||
| 336 | { | - | ||||||||||||||||||||||||
| 337 | if (!widget)
| 0 | ||||||||||||||||||||||||
| 338 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 339 | insertPermanentWidget(d_func()->items.size(), widget, stretch); | - | ||||||||||||||||||||||||
| 340 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 341 | - | |||||||||||||||||||||||||
| 342 | - | |||||||||||||||||||||||||
| 343 | /*! | - | ||||||||||||||||||||||||
| 344 | \since 4.2 | - | ||||||||||||||||||||||||
| 345 | - | |||||||||||||||||||||||||
| 346 | Inserts the given \a widget at the given \a index permanently to this status bar, | - | ||||||||||||||||||||||||
| 347 | reparenting the widget if it isn't already a child of this | - | ||||||||||||||||||||||||
| 348 | QStatusBar object. If \a index is out of range, the widget is appended | - | ||||||||||||||||||||||||
| 349 | (in which case it is the actual index of the widget that is returned). | - | ||||||||||||||||||||||||
| 350 | - | |||||||||||||||||||||||||
| 351 | The \a stretch parameter is used to compute a | - | ||||||||||||||||||||||||
| 352 | suitable size for the given \a widget as the status bar grows and | - | ||||||||||||||||||||||||
| 353 | shrinks. The default stretch factor is 0, i.e giving the widget a | - | ||||||||||||||||||||||||
| 354 | minimum of space. | - | ||||||||||||||||||||||||
| 355 | - | |||||||||||||||||||||||||
| 356 | Permanently means that the widget may not be obscured by temporary | - | ||||||||||||||||||||||||
| 357 | messages. It is is located at the far right of the status bar. | - | ||||||||||||||||||||||||
| 358 | - | |||||||||||||||||||||||||
| 359 | \sa addPermanentWidget(), removeWidget(), addWidget() | - | ||||||||||||||||||||||||
| 360 | */ | - | ||||||||||||||||||||||||
| 361 | int QStatusBar::insertPermanentWidget(int index, QWidget *widget, int stretch) | - | ||||||||||||||||||||||||
| 362 | { | - | ||||||||||||||||||||||||
| 363 | if (!widget)
| 0 | ||||||||||||||||||||||||
| 364 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||
| 366 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 367 | QStatusBarPrivate::SBItem* item = new QStatusBarPrivate::SBItem(widget, stretch, true); | - | ||||||||||||||||||||||||
| 368 | - | |||||||||||||||||||||||||
| 369 | int idx = d->indexToLastNonPermanentWidget(); | - | ||||||||||||||||||||||||
| 370 | if (Q_UNLIKELY(index < 0 || index > d->items.size() || (idx >= 0 && index <= idx))) {
| 0 | ||||||||||||||||||||||||
| 371 | qWarning("QStatusBar::insertPermanentWidget: Index out of range (%d), appending widget", index); | - | ||||||||||||||||||||||||
| 372 | index = d->items.size(); | - | ||||||||||||||||||||||||
| 373 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 374 | d->items.insert(index, item); | - | ||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||
| 376 | reformat(); | - | ||||||||||||||||||||||||
| 377 | if (!widget->isHidden() || !widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
| 0 | ||||||||||||||||||||||||
| 378 | widget->show(); never executed: widget->show(); | 0 | ||||||||||||||||||||||||
| 379 | - | |||||||||||||||||||||||||
| 380 | return index; never executed: return index; | 0 | ||||||||||||||||||||||||
| 381 | } | - | ||||||||||||||||||||||||
| 382 | - | |||||||||||||||||||||||||
| 383 | /*! | - | ||||||||||||||||||||||||
| 384 | Removes the specified \a widget from the status bar. | - | ||||||||||||||||||||||||
| 385 | - | |||||||||||||||||||||||||
| 386 | \note This function does not delete the widget but \e hides it. | - | ||||||||||||||||||||||||
| 387 | To add the widget again, you must call both the addWidget() and | - | ||||||||||||||||||||||||
| 388 | show() functions. | - | ||||||||||||||||||||||||
| 389 | - | |||||||||||||||||||||||||
| 390 | \sa addWidget(), addPermanentWidget(), clearMessage() | - | ||||||||||||||||||||||||
| 391 | */ | - | ||||||||||||||||||||||||
| 392 | - | |||||||||||||||||||||||||
| 393 | void QStatusBar::removeWidget(QWidget *widget) | - | ||||||||||||||||||||||||
| 394 | { | - | ||||||||||||||||||||||||
| 395 | if (!widget)
| 0 | ||||||||||||||||||||||||
| 396 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 397 | - | |||||||||||||||||||||||||
| 398 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 399 | bool found = false; | - | ||||||||||||||||||||||||
| 400 | QStatusBarPrivate::SBItem* item; | - | ||||||||||||||||||||||||
| 401 | for (int i=0; i<d->items.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 402 | item = d->items.at(i); | - | ||||||||||||||||||||||||
| 403 | if (!item)
| 0 | ||||||||||||||||||||||||
| 404 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 405 | if (item->w == widget) {
| 0 | ||||||||||||||||||||||||
| 406 | d->items.removeAt(i); | - | ||||||||||||||||||||||||
| 407 | item->w->hide(); | - | ||||||||||||||||||||||||
| 408 | delete item; | - | ||||||||||||||||||||||||
| 409 | found = true; | - | ||||||||||||||||||||||||
| 410 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 411 | } | - | ||||||||||||||||||||||||
| 412 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 413 | - | |||||||||||||||||||||||||
| 414 | if (found)
| 0 | ||||||||||||||||||||||||
| 415 | reformat(); never executed: reformat(); | 0 | ||||||||||||||||||||||||
| 416 | #if defined(QT_DEBUG) | - | ||||||||||||||||||||||||
| 417 | else | - | ||||||||||||||||||||||||
| 418 | qDebug("QStatusBar::removeWidget(): Widget not found."); never executed: QMessageLogger(__FILE__, 418, __PRETTY_FUNCTION__).debug("QStatusBar::removeWidget(): Widget not found."); | 0 | ||||||||||||||||||||||||
| 419 | #endif | - | ||||||||||||||||||||||||
| 420 | } | - | ||||||||||||||||||||||||
| 421 | - | |||||||||||||||||||||||||
| 422 | /*! | - | ||||||||||||||||||||||||
| 423 | \property QStatusBar::sizeGripEnabled | - | ||||||||||||||||||||||||
| 424 | - | |||||||||||||||||||||||||
| 425 | \brief whether the QSizeGrip in the bottom-right corner of the | - | ||||||||||||||||||||||||
| 426 | status bar is enabled | - | ||||||||||||||||||||||||
| 427 | - | |||||||||||||||||||||||||
| 428 | The size grip is enabled by default. | - | ||||||||||||||||||||||||
| 429 | */ | - | ||||||||||||||||||||||||
| 430 | - | |||||||||||||||||||||||||
| 431 | bool QStatusBar::isSizeGripEnabled() const | - | ||||||||||||||||||||||||
| 432 | { | - | ||||||||||||||||||||||||
| 433 | #ifdef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
| 434 | return false; | - | ||||||||||||||||||||||||
| 435 | #else | - | ||||||||||||||||||||||||
| 436 | Q_D(const QStatusBar); | - | ||||||||||||||||||||||||
| 437 | return !!d->resizer; never executed: return !!d->resizer; | 0 | ||||||||||||||||||||||||
| 438 | #endif | - | ||||||||||||||||||||||||
| 439 | } | - | ||||||||||||||||||||||||
| 440 | - | |||||||||||||||||||||||||
| 441 | void QStatusBar::setSizeGripEnabled(bool enabled) | - | ||||||||||||||||||||||||
| 442 | { | - | ||||||||||||||||||||||||
| 443 | #ifdef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
| 444 | Q_UNUSED(enabled); | - | ||||||||||||||||||||||||
| 445 | #else | - | ||||||||||||||||||||||||
| 446 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 447 | if (!enabled != !d->resizer) {
| 0 | ||||||||||||||||||||||||
| 448 | if (enabled) {
| 0 | ||||||||||||||||||||||||
| 449 | d->resizer = new QSizeGrip(this); | - | ||||||||||||||||||||||||
| 450 | d->resizer->hide(); | - | ||||||||||||||||||||||||
| 451 | d->resizer->installEventFilter(this); | - | ||||||||||||||||||||||||
| 452 | d->showSizeGrip = true; | - | ||||||||||||||||||||||||
| 453 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 454 | delete d->resizer; | - | ||||||||||||||||||||||||
| 455 | d->resizer = 0; | - | ||||||||||||||||||||||||
| 456 | d->showSizeGrip = false; | - | ||||||||||||||||||||||||
| 457 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 458 | reformat(); | - | ||||||||||||||||||||||||
| 459 | if (d->resizer && isVisible())
| 0 | ||||||||||||||||||||||||
| 460 | d->tryToShowSizeGrip(); never executed: d->tryToShowSizeGrip(); | 0 | ||||||||||||||||||||||||
| 461 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 462 | #endif | - | ||||||||||||||||||||||||
| 463 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 464 | - | |||||||||||||||||||||||||
| 465 | - | |||||||||||||||||||||||||
| 466 | /*! | - | ||||||||||||||||||||||||
| 467 | Changes the status bar's appearance to account for item changes. | - | ||||||||||||||||||||||||
| 468 | - | |||||||||||||||||||||||||
| 469 | Special subclasses may need this function, but geometry management | - | ||||||||||||||||||||||||
| 470 | will usually take care of any necessary rearrangements. | - | ||||||||||||||||||||||||
| 471 | */ | - | ||||||||||||||||||||||||
| 472 | void QStatusBar::reformat() | - | ||||||||||||||||||||||||
| 473 | { | - | ||||||||||||||||||||||||
| 474 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 475 | if (d->box)
| 0 | ||||||||||||||||||||||||
| 476 | delete d->box; never executed: delete d->box; | 0 | ||||||||||||||||||||||||
| 477 | - | |||||||||||||||||||||||||
| 478 | QBoxLayout *vbox; | - | ||||||||||||||||||||||||
| 479 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
| 480 | if (d->resizer) {
| 0 | ||||||||||||||||||||||||
| 481 | d->box = new QHBoxLayout(this); | - | ||||||||||||||||||||||||
| 482 | d->box->setMargin(0); | - | ||||||||||||||||||||||||
| 483 | vbox = new QVBoxLayout; | - | ||||||||||||||||||||||||
| 484 | d->box->addLayout(vbox); | - | ||||||||||||||||||||||||
| 485 | } else never executed: end of block | 0 | ||||||||||||||||||||||||
| 486 | #endif | - | ||||||||||||||||||||||||
| 487 | { | - | ||||||||||||||||||||||||
| 488 | vbox = d->box = new QVBoxLayout(this); | - | ||||||||||||||||||||||||
| 489 | d->box->setMargin(0); | - | ||||||||||||||||||||||||
| 490 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 491 | vbox->addSpacing(3); | - | ||||||||||||||||||||||||
| 492 | QBoxLayout* l = new QHBoxLayout; | - | ||||||||||||||||||||||||
| 493 | vbox->addLayout(l); | - | ||||||||||||||||||||||||
| 494 | l->addSpacing(2); | - | ||||||||||||||||||||||||
| 495 | l->setSpacing(6); | - | ||||||||||||||||||||||||
| 496 | - | |||||||||||||||||||||||||
| 497 | int maxH = fontMetrics().height(); | - | ||||||||||||||||||||||||
| 498 | - | |||||||||||||||||||||||||
| 499 | int i; | - | ||||||||||||||||||||||||
| 500 | QStatusBarPrivate::SBItem* item; | - | ||||||||||||||||||||||||
| 501 | for (i=0,item=0; i<d->items.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 502 | item = d->items.at(i); | - | ||||||||||||||||||||||||
| 503 | if (!item || item->p)
| 0 | ||||||||||||||||||||||||
| 504 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 505 | l->addWidget(item->w, item->s); | - | ||||||||||||||||||||||||
| 506 | int itemH = qMin(qSmartMinSize(item->w).height(), item->w->maximumHeight()); | - | ||||||||||||||||||||||||
| 507 | maxH = qMax(maxH, itemH); | - | ||||||||||||||||||||||||
| 508 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 509 | - | |||||||||||||||||||||||||
| 510 | l->addStretch(0); | - | ||||||||||||||||||||||||
| 511 | - | |||||||||||||||||||||||||
| 512 | for (item=0; i<d->items.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 513 | item = d->items.at(i); | - | ||||||||||||||||||||||||
| 514 | if (!item)
| 0 | ||||||||||||||||||||||||
| 515 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 516 | l->addWidget(item->w, item->s); | - | ||||||||||||||||||||||||
| 517 | int itemH = qMin(qSmartMinSize(item->w).height(), item->w->maximumHeight()); | - | ||||||||||||||||||||||||
| 518 | maxH = qMax(maxH, itemH); | - | ||||||||||||||||||||||||
| 519 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 520 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
| 521 | if (d->resizer) {
| 0 | ||||||||||||||||||||||||
| 522 | maxH = qMax(maxH, d->resizer->sizeHint().height()); | - | ||||||||||||||||||||||||
| 523 | d->box->addSpacing(1); | - | ||||||||||||||||||||||||
| 524 | d->box->addWidget(d->resizer, 0, Qt::AlignBottom); | - | ||||||||||||||||||||||||
| 525 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 526 | #endif | - | ||||||||||||||||||||||||
| 527 | l->addStrut(maxH); | - | ||||||||||||||||||||||||
| 528 | d->savedStrut = maxH; | - | ||||||||||||||||||||||||
| 529 | vbox->addSpacing(2); | - | ||||||||||||||||||||||||
| 530 | d->box->activate(); | - | ||||||||||||||||||||||||
| 531 | update(); | - | ||||||||||||||||||||||||
| 532 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 533 | - | |||||||||||||||||||||||||
| 534 | /*! | - | ||||||||||||||||||||||||
| 535 | - | |||||||||||||||||||||||||
| 536 | Hides the normal status indications and displays the given \a | - | ||||||||||||||||||||||||
| 537 | message for the specified number of milli-seconds (\a{timeout}). If | - | ||||||||||||||||||||||||
| 538 | \a{timeout} is 0 (default), the \a {message} remains displayed until | - | ||||||||||||||||||||||||
| 539 | the clearMessage() slot is called or until the showMessage() slot is | - | ||||||||||||||||||||||||
| 540 | called again to change the message. | - | ||||||||||||||||||||||||
| 541 | - | |||||||||||||||||||||||||
| 542 | Note that showMessage() is called to show temporary explanations of | - | ||||||||||||||||||||||||
| 543 | tool tip texts, so passing a \a{timeout} of 0 is not sufficient to | - | ||||||||||||||||||||||||
| 544 | display a \l{permanent message}{permanent message}. | - | ||||||||||||||||||||||||
| 545 | - | |||||||||||||||||||||||||
| 546 | \sa messageChanged(), currentMessage(), clearMessage() | - | ||||||||||||||||||||||||
| 547 | */ | - | ||||||||||||||||||||||||
| 548 | void QStatusBar::showMessage(const QString &message, int timeout) | - | ||||||||||||||||||||||||
| 549 | { | - | ||||||||||||||||||||||||
| 550 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 551 | - | |||||||||||||||||||||||||
| 552 | if (timeout > 0) {
| 0 | ||||||||||||||||||||||||
| 553 | if (!d->timer) {
| 0 | ||||||||||||||||||||||||
| 554 | d->timer = new QTimer(this); | - | ||||||||||||||||||||||||
| 555 | connect(d->timer, SIGNAL(timeout()), this, SLOT(clearMessage())); | - | ||||||||||||||||||||||||
| 556 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 557 | d->timer->start(timeout); | - | ||||||||||||||||||||||||
| 558 | } else if (d->timer) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 559 | delete d->timer; | - | ||||||||||||||||||||||||
| 560 | d->timer = 0; | - | ||||||||||||||||||||||||
| 561 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 562 | if (d->tempItem == message)
| 0 | ||||||||||||||||||||||||
| 563 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 564 | d->tempItem = message; | - | ||||||||||||||||||||||||
| 565 | - | |||||||||||||||||||||||||
| 566 | hideOrShow(); | - | ||||||||||||||||||||||||
| 567 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 568 | - | |||||||||||||||||||||||||
| 569 | /*! | - | ||||||||||||||||||||||||
| 570 | Removes any temporary message being shown. | - | ||||||||||||||||||||||||
| 571 | - | |||||||||||||||||||||||||
| 572 | \sa currentMessage(), showMessage(), removeWidget() | - | ||||||||||||||||||||||||
| 573 | */ | - | ||||||||||||||||||||||||
| 574 | - | |||||||||||||||||||||||||
| 575 | void QStatusBar::clearMessage() | - | ||||||||||||||||||||||||
| 576 | { | - | ||||||||||||||||||||||||
| 577 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 578 | if (d->tempItem.isEmpty())
| 0 | ||||||||||||||||||||||||
| 579 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 580 | if (d->timer) {
| 0 | ||||||||||||||||||||||||
| 581 | qDeleteInEventHandler(d->timer); | - | ||||||||||||||||||||||||
| 582 | d->timer = 0; | - | ||||||||||||||||||||||||
| 583 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 584 | d->tempItem.clear(); | - | ||||||||||||||||||||||||
| 585 | hideOrShow(); | - | ||||||||||||||||||||||||
| 586 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 587 | - | |||||||||||||||||||||||||
| 588 | /*! | - | ||||||||||||||||||||||||
| 589 | Returns the temporary message currently shown, | - | ||||||||||||||||||||||||
| 590 | or an empty string if there is no such message. | - | ||||||||||||||||||||||||
| 591 | - | |||||||||||||||||||||||||
| 592 | \sa showMessage() | - | ||||||||||||||||||||||||
| 593 | */ | - | ||||||||||||||||||||||||
| 594 | QString QStatusBar::currentMessage() const | - | ||||||||||||||||||||||||
| 595 | { | - | ||||||||||||||||||||||||
| 596 | Q_D(const QStatusBar); | - | ||||||||||||||||||||||||
| 597 | return d->tempItem; never executed: return d->tempItem; | 0 | ||||||||||||||||||||||||
| 598 | } | - | ||||||||||||||||||||||||
| 599 | - | |||||||||||||||||||||||||
| 600 | /*! | - | ||||||||||||||||||||||||
| 601 | \fn QStatusBar::messageChanged(const QString &message) | - | ||||||||||||||||||||||||
| 602 | - | |||||||||||||||||||||||||
| 603 | This signal is emitted whenever the temporary status message | - | ||||||||||||||||||||||||
| 604 | changes. The new temporary message is passed in the \a message | - | ||||||||||||||||||||||||
| 605 | parameter which is a null-string when the message has been | - | ||||||||||||||||||||||||
| 606 | removed. | - | ||||||||||||||||||||||||
| 607 | - | |||||||||||||||||||||||||
| 608 | \sa showMessage(), clearMessage() | - | ||||||||||||||||||||||||
| 609 | */ | - | ||||||||||||||||||||||||
| 610 | - | |||||||||||||||||||||||||
| 611 | /*! | - | ||||||||||||||||||||||||
| 612 | Ensures that the right widgets are visible. | - | ||||||||||||||||||||||||
| 613 | - | |||||||||||||||||||||||||
| 614 | Used by the showMessage() and clearMessage() functions. | - | ||||||||||||||||||||||||
| 615 | */ | - | ||||||||||||||||||||||||
| 616 | void QStatusBar::hideOrShow() | - | ||||||||||||||||||||||||
| 617 | { | - | ||||||||||||||||||||||||
| 618 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 619 | bool haveMessage = !d->tempItem.isEmpty(); | - | ||||||||||||||||||||||||
| 620 | - | |||||||||||||||||||||||||
| 621 | QStatusBarPrivate::SBItem* item = 0; | - | ||||||||||||||||||||||||
| 622 | for (int i=0; i<d->items.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 623 | item = d->items.at(i); | - | ||||||||||||||||||||||||
| 624 | if (!item || item->p)
| 0 | ||||||||||||||||||||||||
| 625 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 626 | if (haveMessage && item->w->isVisible()) {
| 0 | ||||||||||||||||||||||||
| 627 | item->w->hide(); | - | ||||||||||||||||||||||||
| 628 | item->w->setAttribute(Qt::WA_WState_ExplicitShowHide, false); | - | ||||||||||||||||||||||||
| 629 | } else if (!haveMessage && !item->w->testAttribute(Qt::WA_WState_ExplicitShowHide)) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 630 | item->w->show(); | - | ||||||||||||||||||||||||
| 631 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 632 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 633 | - | |||||||||||||||||||||||||
| 634 | emit messageChanged(d->tempItem); | - | ||||||||||||||||||||||||
| 635 | - | |||||||||||||||||||||||||
| 636 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 637 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||
| 638 | QAccessibleEvent event(this, QAccessible::NameChanged); | - | ||||||||||||||||||||||||
| 639 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||
| 640 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 641 | #endif | - | ||||||||||||||||||||||||
| 642 | - | |||||||||||||||||||||||||
| 643 | repaint(d->messageRect()); | - | ||||||||||||||||||||||||
| 644 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 645 | - | |||||||||||||||||||||||||
| 646 | /*! | - | ||||||||||||||||||||||||
| 647 | \reimp | - | ||||||||||||||||||||||||
| 648 | */ | - | ||||||||||||||||||||||||
| 649 | void QStatusBar::showEvent(QShowEvent *) | - | ||||||||||||||||||||||||
| 650 | { | - | ||||||||||||||||||||||||
| 651 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
| 652 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 653 | if (d->resizer && d->showSizeGrip)
| 0 | ||||||||||||||||||||||||
| 654 | d->tryToShowSizeGrip(); never executed: d->tryToShowSizeGrip(); | 0 | ||||||||||||||||||||||||
| 655 | #endif | - | ||||||||||||||||||||||||
| 656 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 657 | - | |||||||||||||||||||||||||
| 658 | /*! | - | ||||||||||||||||||||||||
| 659 | \reimp | - | ||||||||||||||||||||||||
| 660 | \fn void QStatusBar::paintEvent(QPaintEvent *event) | - | ||||||||||||||||||||||||
| 661 | - | |||||||||||||||||||||||||
| 662 | Shows the temporary message, if appropriate, in response to the | - | ||||||||||||||||||||||||
| 663 | paint \a event. | - | ||||||||||||||||||||||||
| 664 | */ | - | ||||||||||||||||||||||||
| 665 | void QStatusBar::paintEvent(QPaintEvent *event) | - | ||||||||||||||||||||||||
| 666 | { | - | ||||||||||||||||||||||||
| 667 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 668 | bool haveMessage = !d->tempItem.isEmpty(); | - | ||||||||||||||||||||||||
| 669 | - | |||||||||||||||||||||||||
| 670 | QPainter p(this); | - | ||||||||||||||||||||||||
| 671 | QStyleOption opt; | - | ||||||||||||||||||||||||
| 672 | opt.initFrom(this); | - | ||||||||||||||||||||||||
| 673 | style()->drawPrimitive(QStyle::PE_PanelStatusBar, &opt, &p, this); | - | ||||||||||||||||||||||||
| 674 | - | |||||||||||||||||||||||||
| 675 | for (int i=0; i<d->items.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 676 | QStatusBarPrivate::SBItem* item = d->items.at(i); | - | ||||||||||||||||||||||||
| 677 | if (item && item->w->isVisible() && (!haveMessage || item->p)) {
| 0 | ||||||||||||||||||||||||
| 678 | QRect ir = item->w->geometry().adjusted(-2, -1, 2, 1); | - | ||||||||||||||||||||||||
| 679 | if (event->rect().intersects(ir)) {
| 0 | ||||||||||||||||||||||||
| 680 | QStyleOption opt(0); | - | ||||||||||||||||||||||||
| 681 | opt.rect = ir; | - | ||||||||||||||||||||||||
| 682 | opt.palette = palette(); | - | ||||||||||||||||||||||||
| 683 | opt.state = QStyle::State_None; | - | ||||||||||||||||||||||||
| 684 | style()->drawPrimitive(QStyle::PE_FrameStatusBarItem, &opt, &p, item->w); | - | ||||||||||||||||||||||||
| 685 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 686 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 687 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 688 | if (haveMessage) {
| 0 | ||||||||||||||||||||||||
| 689 | p.setPen(palette().foreground().color()); | - | ||||||||||||||||||||||||
| 690 | p.drawText(d->messageRect(), Qt::AlignLeading | Qt::AlignVCenter | Qt::TextSingleLine, d->tempItem); | - | ||||||||||||||||||||||||
| 691 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 692 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 693 | - | |||||||||||||||||||||||||
| 694 | /*! | - | ||||||||||||||||||||||||
| 695 | \reimp | - | ||||||||||||||||||||||||
| 696 | */ | - | ||||||||||||||||||||||||
| 697 | void QStatusBar::resizeEvent(QResizeEvent * e) | - | ||||||||||||||||||||||||
| 698 | { | - | ||||||||||||||||||||||||
| 699 | QWidget::resizeEvent(e); | - | ||||||||||||||||||||||||
| 700 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 701 | - | |||||||||||||||||||||||||
| 702 | /*! | - | ||||||||||||||||||||||||
| 703 | \reimp | - | ||||||||||||||||||||||||
| 704 | */ | - | ||||||||||||||||||||||||
| 705 | - | |||||||||||||||||||||||||
| 706 | bool QStatusBar::event(QEvent *e) | - | ||||||||||||||||||||||||
| 707 | { | - | ||||||||||||||||||||||||
| 708 | Q_D(QStatusBar); | - | ||||||||||||||||||||||||
| 709 | - | |||||||||||||||||||||||||
| 710 | if (e->type() == QEvent::LayoutRequest
| 0 | ||||||||||||||||||||||||
| 711 | ) { | - | ||||||||||||||||||||||||
| 712 | // Calculate new strut height and call reformat() if it has changed | - | ||||||||||||||||||||||||
| 713 | int maxH = fontMetrics().height(); | - | ||||||||||||||||||||||||
| 714 | - | |||||||||||||||||||||||||
| 715 | QStatusBarPrivate::SBItem* item = 0; | - | ||||||||||||||||||||||||
| 716 | for (int i=0; i<d->items.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 717 | item = d->items.at(i); | - | ||||||||||||||||||||||||
| 718 | if (!item)
| 0 | ||||||||||||||||||||||||
| 719 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 720 | int itemH = qMin(qSmartMinSize(item->w).height(), item->w->maximumHeight()); | - | ||||||||||||||||||||||||
| 721 | maxH = qMax(maxH, itemH); | - | ||||||||||||||||||||||||
| 722 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 723 | - | |||||||||||||||||||||||||
| 724 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
| 725 | if (d->resizer)
| 0 | ||||||||||||||||||||||||
| 726 | maxH = qMax(maxH, d->resizer->sizeHint().height()); never executed: maxH = qMax(maxH, d->resizer->sizeHint().height()); | 0 | ||||||||||||||||||||||||
| 727 | #endif | - | ||||||||||||||||||||||||
| 728 | - | |||||||||||||||||||||||||
| 729 | if (maxH != d->savedStrut)
| 0 | ||||||||||||||||||||||||
| 730 | reformat(); never executed: reformat(); | 0 | ||||||||||||||||||||||||
| 731 | else | - | ||||||||||||||||||||||||
| 732 | update(); never executed: update(); | 0 | ||||||||||||||||||||||||
| 733 | } | - | ||||||||||||||||||||||||
| 734 | if (e->type() == QEvent::ChildRemoved) {
| 0 | ||||||||||||||||||||||||
| 735 | QStatusBarPrivate::SBItem* item = 0; | - | ||||||||||||||||||||||||
| 736 | for (int i=0; i<d->items.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 737 | item = d->items.at(i); | - | ||||||||||||||||||||||||
| 738 | if (!item)
| 0 | ||||||||||||||||||||||||
| 739 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 740 | if (item->w == ((QChildEvent*)e)->child()) {
| 0 | ||||||||||||||||||||||||
| 741 | d->items.removeAt(i); | - | ||||||||||||||||||||||||
| 742 | delete item; | - | ||||||||||||||||||||||||
| 743 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 744 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 745 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 746 | - | |||||||||||||||||||||||||
| 747 | // On Mac OS X Leopard it is possible to drag the window by clicking | - | ||||||||||||||||||||||||
| 748 | // on the tool bar on most applications. | - | ||||||||||||||||||||||||
| 749 | #ifndef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||||||||
| 750 | return QWidget::event(e); never executed: return QWidget::event(e); | 0 | ||||||||||||||||||||||||
| 751 | #else | - | ||||||||||||||||||||||||
| 752 | if (QSysInfo::MacintoshVersion <= QSysInfo::MV_10_4) | - | ||||||||||||||||||||||||
| 753 | return QWidget::event(e); | - | ||||||||||||||||||||||||
| 754 | - | |||||||||||||||||||||||||
| 755 | // Enable drag-click only if the status bar is the status bar for a | - | ||||||||||||||||||||||||
| 756 | // QMainWindow with a unifed toolbar. | - | ||||||||||||||||||||||||
| 757 | if (parent() == 0 || qobject_cast<QMainWindow *>(parent()) == 0 || | - | ||||||||||||||||||||||||
| 758 | qobject_cast<QMainWindow *>(parent())->unifiedTitleAndToolBarOnMac() == false ) | - | ||||||||||||||||||||||||
| 759 | return QWidget::event(e); | - | ||||||||||||||||||||||||
| 760 | - | |||||||||||||||||||||||||
| 761 | // Check for mouse events. | - | ||||||||||||||||||||||||
| 762 | QMouseEvent *mouseEvent; | - | ||||||||||||||||||||||||
| 763 | if (e->type() == QEvent::MouseButtonPress || | - | ||||||||||||||||||||||||
| 764 | e->type() == QEvent::MouseMove || | - | ||||||||||||||||||||||||
| 765 | e->type() == QEvent::MouseButtonRelease) { | - | ||||||||||||||||||||||||
| 766 | mouseEvent = static_cast <QMouseEvent*>(e); | - | ||||||||||||||||||||||||
| 767 | } else { | - | ||||||||||||||||||||||||
| 768 | return QWidget::event(e); | - | ||||||||||||||||||||||||
| 769 | } | - | ||||||||||||||||||||||||
| 770 | - | |||||||||||||||||||||||||
| 771 | // The following is a standard mouse drag handler. | - | ||||||||||||||||||||||||
| 772 | if (e->type() == QEvent::MouseButtonPress && (mouseEvent->button() == Qt::LeftButton)) { | - | ||||||||||||||||||||||||
| 773 | d->dragStart = mouseEvent->pos(); | - | ||||||||||||||||||||||||
| 774 | } else if (e->type() == QEvent::MouseMove){ | - | ||||||||||||||||||||||||
| 775 | if (d->dragStart == QPoint()) | - | ||||||||||||||||||||||||
| 776 | return QWidget::event(e); | - | ||||||||||||||||||||||||
| 777 | QPoint pos = mouseEvent->pos(); | - | ||||||||||||||||||||||||
| 778 | QPoint delta = (pos - d->dragStart); | - | ||||||||||||||||||||||||
| 779 | window()->move(window()->pos() + delta); | - | ||||||||||||||||||||||||
| 780 | } else if (e->type() == QEvent::MouseButtonRelease && (mouseEvent->button() == Qt::LeftButton)){ | - | ||||||||||||||||||||||||
| 781 | d->dragStart = QPoint(); | - | ||||||||||||||||||||||||
| 782 | } else { | - | ||||||||||||||||||||||||
| 783 | return QWidget::event(e); | - | ||||||||||||||||||||||||
| 784 | } | - | ||||||||||||||||||||||||
| 785 | - | |||||||||||||||||||||||||
| 786 | return true; | - | ||||||||||||||||||||||||
| 787 | #endif | - | ||||||||||||||||||||||||
| 788 | } | - | ||||||||||||||||||||||||
| 789 | - | |||||||||||||||||||||||||
| 790 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 791 | - | |||||||||||||||||||||||||
| 792 | #include "moc_qstatusbar.cpp" | - | ||||||||||||||||||||||||
| 793 | - | |||||||||||||||||||||||||
| 794 | #endif | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |