From 59ab849854bec7f61a527c4b6e5a1f063c57abb8 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 26 Feb 2015 16:07:39 +0200 Subject: 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 that inherits 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 Signed-off-by: Dirk Hohndel --- qt-ui/divelogexportdialog.cpp | 6 +++++- qt-ui/mainwindow.cpp | 12 ++++++------ qt-ui/mainwindow.h | 2 ++ qt-ui/mainwindow.ui | 6 +++--- qt-ui/notificationwidget.cpp | 37 +++++++++++++++++++++++++++++++++++++ qt-ui/notificationwidget.h | 31 +++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 qt-ui/notificationwidget.cpp create mode 100644 qt-ui/notificationwidget.h (limited to 'qt-ui') diff --git a/qt-ui/divelogexportdialog.cpp b/qt-ui/divelogexportdialog.cpp index 43c41550f..ff8317062 100644 --- a/qt-ui/divelogexportdialog.cpp +++ b/qt-ui/divelogexportdialog.cpp @@ -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); + } } } diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 8dcb59c90..de98eb08f 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -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) diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 7514a0938..06b180a39 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -13,6 +13,7 @@ #include #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 */ diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index 41a85bf8a..82f7bcd7f 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -40,7 +40,7 @@ - + @@ -699,9 +699,9 @@ - KMessageWidget + NotificationWidget QWidget -
kmessagewidget.h
+
notificationwidget.h
1
diff --git a/qt-ui/notificationwidget.cpp b/qt-ui/notificationwidget.cpp new file mode 100644 index 000000000..44e2eed1b --- /dev/null +++ b/qt-ui/notificationwidget.cpp @@ -0,0 +1,37 @@ +#include "notificationwidget.h" + +NotificationWidget::NotificationWidget(QWidget *parent) : KMessageWidget(parent) +{ + future_watcher = new QFutureWatcher(); + 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 &future) +{ + future_watcher->setFuture(future); +} + +void NotificationWidget::finish() +{ + hideNotification(); +} + +NotificationWidget::~NotificationWidget() +{ + delete future_watcher; +} diff --git a/qt-ui/notificationwidget.h b/qt-ui/notificationwidget.h new file mode 100644 index 000000000..7a3f93b4d --- /dev/null +++ b/qt-ui/notificationwidget.h @@ -0,0 +1,31 @@ +#ifndef NOTIFICATIONWIDGET_H +#define NOTIFICATIONWIDGET_H + +#include +#include + +#include + +namespace Ui { + class NotificationWidget; +} + +class NotificationWidget : public KMessageWidget { + Q_OBJECT + +public: + explicit NotificationWidget(QWidget *parent = 0); + void setFuture(const QFuture &future); + void showNotification(QString message, KMessageWidget::MessageType type); + void hideNotification(); + ~NotificationWidget(); + +private: + QFutureWatcher *future_watcher; + +private +slots: + void finish(); +}; + +#endif // NOTIFICATIONWIDGET_H -- cgit v1.2.3-70-g09d2