diff options
Diffstat (limited to 'src/widgets/widgets/qstatusbar.cpp')
-rw-r--r-- | src/widgets/widgets/qstatusbar.cpp | 85 |
1 files changed, 19 insertions, 66 deletions
diff --git a/src/widgets/widgets/qstatusbar.cpp b/src/widgets/widgets/qstatusbar.cpp index d368f6668b..e398f52ac4 100644 --- a/src/widgets/widgets/qstatusbar.cpp +++ b/src/widgets/widgets/qstatusbar.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qstatusbar.h" @@ -54,7 +18,7 @@ #include "qmainwindow.h" #endif -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) #include "qaccessible.h" #endif @@ -187,12 +151,12 @@ QRect QStatusBarPrivate::messageRect() const Use the showMessage() slot to display a \e temporary message: - \snippet mainwindows/dockwidgets/mainwindow.cpp 8 + \snippet code/src_gui_widgets_qstatusbar.cpp 1 To remove a temporary message, use the clearMessage() slot, or set a time limit when calling showMessage(). For example: - \snippet mainwindows/dockwidgets/mainwindow.cpp 3 + \snippet code/src_gui_widgets_qstatusbar.cpp 2 Use the currentMessage() function to retrieve the temporary message currently shown. The QStatusBar class also provide the @@ -215,8 +179,7 @@ QRect QStatusBarPrivate::messageRect() const \image fusion-statusbar-sizegrip.png A status bar shown in the Fusion widget style - \sa QMainWindow, QStatusTipEvent, {fowler}{GUI Design Handbook: - Status Bar}, {Qt Widgets - Application Example} + \sa QMainWindow, QStatusTipEvent */ @@ -308,7 +271,7 @@ int QStatusBar::insertWidget(int index, QWidget *widget, int stretch) widget->hide(); reformat(); - if (!widget->isHidden() || !widget->testAttribute(Qt::WA_WState_ExplicitShowHide)) + if (!QWidgetPrivate::get(widget)->isExplicitlyHidden()) widget->show(); return index; @@ -323,7 +286,7 @@ int QStatusBar::insertWidget(int index, QWidget *widget, int stretch) minimum of space. Permanently means that the widget may not be obscured by temporary - messages. It is is located at the far right of the status bar. + messages. It is located at the far right of the status bar. \sa insertPermanentWidget(), removeWidget(), addWidget() */ @@ -335,7 +298,6 @@ void QStatusBar::addPermanentWidget(QWidget * widget, int stretch) insertPermanentWidget(d_func()->items.size(), widget, stretch); } - /*! \since 4.2 @@ -350,7 +312,7 @@ void QStatusBar::addPermanentWidget(QWidget * widget, int stretch) minimum of space. Permanently means that the widget may not be obscured by temporary - messages. It is is located at the far right of the status bar. + messages. It is located at the far right of the status bar. \sa addPermanentWidget(), removeWidget(), addWidget() */ @@ -370,7 +332,7 @@ int QStatusBar::insertPermanentWidget(int index, QWidget *widget, int stretch) d->items.insert(index, item); reformat(); - if (!widget->isHidden() || !widget->testAttribute(Qt::WA_WState_ExplicitShowHide)) + if (!QWidgetPrivate::get(widget)->isExplicitlyHidden()) widget->show(); return index; @@ -392,19 +354,10 @@ void QStatusBar::removeWidget(QWidget *widget) return; Q_D(QStatusBar); - bool found = false; - for (int i = 0; i < d->items.size(); ++i) { - const auto &item = d->items.at(i); - if (item.widget == widget) { - d->items.removeAt(i); - item.widget->hide(); - found = true; - break; - } - } - - if (found) + if (d->items.removeIf([widget](const auto &item) { return item.widget == widget; })) { + widget->hide(); reformat(); + } #if defined(QT_DEBUG) else qDebug("QStatusBar::removeWidget(): Widget not found."); @@ -541,7 +494,7 @@ void QStatusBar::showMessage(const QString &message, int timeout) if (timeout > 0) { if (!d->timer) { d->timer = new QTimer(this); - connect(d->timer, SIGNAL(timeout()), this, SLOT(clearMessage())); + connect(d->timer, &QTimer::timeout, this, &QStatusBar::clearMessage); } d->timer->start(timeout); } else if (d->timer) { @@ -567,7 +520,7 @@ void QStatusBar::clearMessage() if (d->tempItem.isEmpty()) return; if (d->timer) { - qDeleteInEventHandler(d->timer); + delete d->timer; d->timer = nullptr; } d->tempItem.clear(); @@ -607,7 +560,7 @@ void QStatusBar::hideOrShow() Q_D(QStatusBar); bool haveMessage = !d->tempItem.isEmpty(); - for (const auto &item : qAsConst(d->items)) { + for (const auto &item : std::as_const(d->items)) { if (item.isPermanent()) break; if (haveMessage && item.widget->isVisible()) { @@ -620,7 +573,7 @@ void QStatusBar::hideOrShow() emit messageChanged(d->tempItem); -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) if (QAccessible::isActive()) { QAccessibleEvent event(this, QAccessible::NameChanged); QAccessible::updateAccessibility(&event); @@ -659,7 +612,7 @@ void QStatusBar::paintEvent(QPaintEvent *event) opt.initFrom(this); style()->drawPrimitive(QStyle::PE_PanelStatusBar, &opt, &p, this); - for (const auto &item : qAsConst(d->items)) { + for (const auto &item : std::as_const(d->items)) { if (item.widget->isVisible() && (!haveMessage || item.isPermanent())) { QRect ir = item.widget->geometry().adjusted(-2, -1, 2, 1); if (event->rect().intersects(ir)) { @@ -698,7 +651,7 @@ bool QStatusBar::event(QEvent *e) // Calculate new strut height and call reformat() if it has changed int maxH = fontMetrics().height(); - for (const auto &item : qAsConst(d->items)) { + for (const auto &item : std::as_const(d->items)) { const int itemH = qMin(qSmartMinSize(item.widget).height(), item.widget->maximumHeight()); maxH = qMax(maxH, itemH); } |