mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
e6482bbdc8
commit
59ab849854
7 changed files with 88 additions and 12 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include "subsurfacewebservices.h"
|
#include "subsurfacewebservices.h"
|
||||||
#include "worldmap-save.h"
|
#include "worldmap-save.h"
|
||||||
#include "save-html.h"
|
#include "save-html.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#define GET_UNIT(name, field, f, t) \
|
#define GET_UNIT(name, field, f, t) \
|
||||||
v = settings.value(QString(name)); \
|
v = settings.value(QString(name)); \
|
||||||
|
@ -312,8 +313,11 @@ void DiveLogExportDialog::on_buttonBox_accepted()
|
||||||
settings.setValue("LastDir", fileInfo.dir().path());
|
settings.setValue("LastDir", fileInfo.dir().path());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
// the non XSLT exports are called directly above, the XSLT based ons are called here
|
// 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());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1308,12 +1308,12 @@ int MainWindow::file_save(void)
|
||||||
|
|
||||||
void MainWindow::showError(QString message)
|
void MainWindow::showError(QString message)
|
||||||
{
|
{
|
||||||
if (message.isEmpty())
|
ui.mainErrorMessage->showNotification(message, KMessageWidget::Error);
|
||||||
return;
|
}
|
||||||
ui.mainErrorMessage->setText(message);
|
|
||||||
ui.mainErrorMessage->setCloseButtonVisible(true);
|
NotificationWidget *MainWindow::getNotificationWidget()
|
||||||
ui.mainErrorMessage->setMessageType(KMessageWidget::Error);
|
{
|
||||||
ui.mainErrorMessage->animatedShow();
|
return ui.mainErrorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setTitle(enum MainWindowTitleFormat format)
|
void MainWindow::setTitle(enum MainWindowTitleFormat format)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
#include "notificationwidget.h"
|
||||||
|
|
||||||
struct DiveList;
|
struct DiveList;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
|
@ -92,6 +93,7 @@ public:
|
||||||
void setApplicationState(const QByteArray& state);
|
void setApplicationState(const QByteArray& state);
|
||||||
void showV2Dialog();
|
void showV2Dialog();
|
||||||
QUndoStack *undoStack;
|
QUndoStack *undoStack;
|
||||||
|
NotificationWidget *getNotificationWidget();
|
||||||
private
|
private
|
||||||
slots:
|
slots:
|
||||||
/* file menu action */
|
/* file menu action */
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="KMessageWidget" name="mainErrorMessage" native="true"/>
|
<widget class="NotificationWidget" name="mainErrorMessage" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -699,9 +699,9 @@
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>KMessageWidget</class>
|
<class>NotificationWidget</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>kmessagewidget.h</header>
|
<header>notificationwidget.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
37
qt-ui/notificationwidget.cpp
Normal file
37
qt-ui/notificationwidget.cpp
Normal 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;
|
||||||
|
}
|
31
qt-ui/notificationwidget.h
Normal file
31
qt-ui/notificationwidget.h
Normal 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
|
|
@ -111,7 +111,8 @@ HEADERS = \
|
||||||
qt-ui/statistics/yearstatistics.h \
|
qt-ui/statistics/yearstatistics.h \
|
||||||
qt-ui/diveshareexportdialog.h \
|
qt-ui/diveshareexportdialog.h \
|
||||||
qt-ui/filtermodels.h \
|
qt-ui/filtermodels.h \
|
||||||
qt-ui/undocommands.h
|
qt-ui/undocommands.h \
|
||||||
|
qt-ui/notificationwidget.h
|
||||||
|
|
||||||
android: HEADERS -= \
|
android: HEADERS -= \
|
||||||
qt-ui/usermanual.h \
|
qt-ui/usermanual.h \
|
||||||
|
@ -209,7 +210,8 @@ SOURCES = \
|
||||||
qt-ui/statistics/monthstatistics.cpp \
|
qt-ui/statistics/monthstatistics.cpp \
|
||||||
qt-ui/diveshareexportdialog.cpp \
|
qt-ui/diveshareexportdialog.cpp \
|
||||||
qt-ui/filtermodels.cpp \
|
qt-ui/filtermodels.cpp \
|
||||||
qt-ui/undocommands.cpp
|
qt-ui/undocommands.cpp \
|
||||||
|
qt-ui/notificationwidget.cpp
|
||||||
|
|
||||||
android: SOURCES += android.cpp
|
android: SOURCES += android.cpp
|
||||||
else: win32: SOURCES += windows.c
|
else: win32: SOURCES += windows.c
|
||||||
|
|
Loading…
Add table
Reference in a new issue