2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-03-16 13:49:28 +01:00
|
|
|
|
|
|
|
|
#include "statuslabel.h"
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTimer>
|
2011-03-16 13:49:28 +01:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class Utils::StatusLabel
|
|
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The StatusLabel class displays messages for a while with a timeout.
|
2011-03-16 13:49:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Utils {
|
|
|
|
|
|
2018-07-23 10:45:40 +02:00
|
|
|
StatusLabel::StatusLabel(QWidget *parent) : QLabel(parent)
|
2011-03-16 13:49:28 +01:00
|
|
|
{
|
|
|
|
|
// A manual size let's us shrink below minimum text width which is what
|
|
|
|
|
// we want in [fake] status bars.
|
|
|
|
|
setMinimumSize(QSize(30, 10));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatusLabel::stopTimer()
|
|
|
|
|
{
|
|
|
|
|
if (m_timer && m_timer->isActive())
|
|
|
|
|
m_timer->stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatusLabel::showStatusMessage(const QString &message, int timeoutMS)
|
|
|
|
|
{
|
|
|
|
|
setText(message);
|
|
|
|
|
if (timeoutMS > 0) {
|
|
|
|
|
if (!m_timer) {
|
|
|
|
|
m_timer = new QTimer(this);
|
|
|
|
|
m_timer->setSingleShot(true);
|
2015-03-05 22:00:05 +02:00
|
|
|
connect(m_timer, &QTimer::timeout, this, &StatusLabel::slotTimeout);
|
2011-03-16 13:49:28 +01:00
|
|
|
}
|
|
|
|
|
m_timer->start(timeoutMS);
|
|
|
|
|
} else {
|
|
|
|
|
m_lastPermanentStatusMessage = message;
|
|
|
|
|
stopTimer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatusLabel::slotTimeout()
|
|
|
|
|
{
|
|
|
|
|
setText(m_lastPermanentStatusMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StatusLabel::clearStatusMessage()
|
|
|
|
|
{
|
|
|
|
|
stopTimer();
|
|
|
|
|
m_lastPermanentStatusMessage.clear();
|
|
|
|
|
clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Utils
|