Creating a Notification widget in the Main Window.

The main error message bar can be used to show exporting information and
other notification.

So a new Notification handler object is created in the main window
<NotificationWidget> that inherits <KMessageWidget> that shows different
type of notifications, ex. (Warning, Error and information)

Also this class contains a QFutureWatcher object that is set to handle
the QFuture variable returned from the exporting thread. this will allow
the UI to be updated when the thread finishes execution.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Gehad elrobey 2015-02-26 16:07:39 +02:00 committed by Dirk Hohndel
parent e6482bbdc8
commit 59ab849854
7 changed files with 88 additions and 12 deletions

View file

@ -9,6 +9,7 @@
#include "subsurfacewebservices.h"
#include "worldmap-save.h"
#include "save-html.h"
#include "mainwindow.h"
#define GET_UNIT(name, field, f, t) \
v = settings.value(QString(name)); \
@ -312,8 +313,11 @@ void DiveLogExportDialog::on_buttonBox_accepted()
settings.setValue("LastDir", fileInfo.dir().path());
settings.endGroup();
// the non XSLT exports are called directly above, the XSLT based ons are called here
if (!stylesheet.isEmpty())
if (!stylesheet.isEmpty()) {
future = QtConcurrent::run(export_dives_xslt, filename.toUtf8(), ui->exportSelected->isChecked(), ui->CSVUnits_2->currentIndex(), stylesheet.toUtf8());
MainWindow::instance()->getNotificationWidget()->showNotification("Exporting...", KMessageWidget::Information);
MainWindow::instance()->getNotificationWidget()->setFuture(future);
}
}
}

View file

@ -1308,12 +1308,12 @@ int MainWindow::file_save(void)
void MainWindow::showError(QString message)
{
if (message.isEmpty())
return;
ui.mainErrorMessage->setText(message);
ui.mainErrorMessage->setCloseButtonVisible(true);
ui.mainErrorMessage->setMessageType(KMessageWidget::Error);
ui.mainErrorMessage->animatedShow();
ui.mainErrorMessage->showNotification(message, KMessageWidget::Error);
}
NotificationWidget *MainWindow::getNotificationWidget()
{
return ui.mainErrorMessage;
}
void MainWindow::setTitle(enum MainWindowTitleFormat format)

View file

@ -13,6 +13,7 @@
#include <QUuid>
#include "ui_mainwindow.h"
#include "notificationwidget.h"
struct DiveList;
class QSortFilterProxyModel;
@ -92,6 +93,7 @@ public:
void setApplicationState(const QByteArray& state);
void showV2Dialog();
QUndoStack *undoStack;
NotificationWidget *getNotificationWidget();
private
slots:
/* file menu action */

View file

@ -40,7 +40,7 @@
</widget>
</item>
<item>
<widget class="KMessageWidget" name="mainErrorMessage" native="true"/>
<widget class="NotificationWidget" name="mainErrorMessage" native="true"/>
</item>
</layout>
</widget>
@ -699,9 +699,9 @@
</widget>
<customwidgets>
<customwidget>
<class>KMessageWidget</class>
<class>NotificationWidget</class>
<extends>QWidget</extends>
<header>kmessagewidget.h</header>
<header>notificationwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>

View file

@ -0,0 +1,37 @@
#include "notificationwidget.h"
NotificationWidget::NotificationWidget(QWidget *parent) : KMessageWidget(parent)
{
future_watcher = new QFutureWatcher<void>();
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::hideNotification()
{
animatedHide();
}
void NotificationWidget::setFuture(const QFuture<void> &future)
{
future_watcher->setFuture(future);
}
void NotificationWidget::finish()
{
hideNotification();
}
NotificationWidget::~NotificationWidget()
{
delete future_watcher;
}

View file

@ -0,0 +1,31 @@
#ifndef NOTIFICATIONWIDGET_H
#define NOTIFICATIONWIDGET_H
#include <QWidget>
#include <QFutureWatcher>
#include <kmessagewidget.h>
namespace Ui {
class NotificationWidget;
}
class NotificationWidget : public KMessageWidget {
Q_OBJECT
public:
explicit NotificationWidget(QWidget *parent = 0);
void setFuture(const QFuture<void> &future);
void showNotification(QString message, KMessageWidget::MessageType type);
void hideNotification();
~NotificationWidget();
private:
QFutureWatcher<void> *future_watcher;
private
slots:
void finish();
};
#endif // NOTIFICATIONWIDGET_H

View file

@ -111,7 +111,8 @@ HEADERS = \
qt-ui/statistics/yearstatistics.h \
qt-ui/diveshareexportdialog.h \
qt-ui/filtermodels.h \
qt-ui/undocommands.h
qt-ui/undocommands.h \
qt-ui/notificationwidget.h
android: HEADERS -= \
qt-ui/usermanual.h \
@ -209,7 +210,8 @@ SOURCES = \
qt-ui/statistics/monthstatistics.cpp \
qt-ui/diveshareexportdialog.cpp \
qt-ui/filtermodels.cpp \
qt-ui/undocommands.cpp
qt-ui/undocommands.cpp \
qt-ui/notificationwidget.cpp
android: SOURCES += android.cpp
else: win32: SOURCES += windows.c