summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gehad elrobey <gehadelrobey@gmail.com>2015-02-26 16:07:39 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-27 06:31:06 +0100
commit59ab849854bec7f61a527c4b6e5a1f063c57abb8 (patch)
tree9edc9025f935ab46d55c9eb72f0b38a47ac119fa
parente6482bbdc8a1359d51c70aaf847d3aac7895b960 (diff)
downloadsubsurface-59ab849854bec7f61a527c4b6e5a1f063c57abb8.tar.gz
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>
-rw-r--r--qt-ui/divelogexportdialog.cpp6
-rw-r--r--qt-ui/mainwindow.cpp12
-rw-r--r--qt-ui/mainwindow.h2
-rw-r--r--qt-ui/mainwindow.ui6
-rw-r--r--qt-ui/notificationwidget.cpp37
-rw-r--r--qt-ui/notificationwidget.h31
-rw-r--r--subsurface.pro6
7 files changed, 88 insertions, 12 deletions
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 <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 */
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 @@
</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>
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<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;
+}
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 <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
diff --git a/subsurface.pro b/subsurface.pro
index a9afae426..639fff647 100644
--- a/subsurface.pro
+++ b/subsurface.pro
@@ -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