subsurface/desktop-widgets/notificationwidget.cpp
Berthold Stoeger a25f54e3c2 Use queued connection to thread-safe MainWindow error handling
Up to now, errors produced by threads were not directly shown in
the MainWindow. Code running in the GUI thread had to manually
show the errors.

This can be simplified by using Qt's queued connection as message
passing facility.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-31 14:47:26 +01:00

42 lines
853 B
C++

// SPDX-License-Identifier: GPL-2.0
#include "notificationwidget.h"
NotificationWidget::NotificationWidget(QWidget *parent) : KMessageWidget(parent)
{
connect(&future_watcher, SIGNAL(finished()), this, SLOT(finish()));
}
void NotificationWidget::showNotification(QString message, KMessageWidget::MessageType type)
{
if (message.isEmpty())
return;
setText(message);
setCloseButtonVisible(true);
setMessageType(type);
animatedShow();
}
void NotificationWidget::showError(QString message)
{
showNotification(message, KMessageWidget::Error);
}
void NotificationWidget::hideNotification()
{
animatedHide();
}
QString NotificationWidget::getNotificationText()
{
return text();
}
void NotificationWidget::setFuture(const QFuture<void> &future)
{
future_watcher.setFuture(future);
}
void NotificationWidget::finish()
{
hideNotification();
}