summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvia Pripoae <[email protected]>2015-05-25 14:29:03 +0200
committerDennis Nienhüser <[email protected]>2015-05-25 14:31:34 +0200
commit826a99d6bb2fc748c6e6152aba82c3ec4eb0cf0c (patch)
tree3756de086222a67e05782dd96819b0485415d2ff
parent75860402f0d4429a0b613524f1489164ad396ef0 (diff)
MessageBox asking to save tour when closing
Before this patch, when closing Marble, any unsaved tours were discarded. Now, a message box asking whether to save the tour is displayed. REVIEW: 123343
-rw-r--r--src/apps/marble-kde/KdeMainWindow.cpp14
-rw-r--r--src/apps/marble-kde/KdeMainWindow.h3
-rw-r--r--src/apps/marble-qt/QtMainWindow.cpp12
-rw-r--r--src/apps/marble-qt/QtMainWindow.h2
-rw-r--r--src/apps/marble-ui/ControlView.cpp13
-rw-r--r--src/apps/marble-ui/ControlView.h3
-rw-r--r--src/lib/marble/TourWidget.cpp31
-rw-r--r--src/lib/marble/TourWidget.h7
8 files changed, 77 insertions, 8 deletions
diff --git a/src/apps/marble-kde/KdeMainWindow.cpp b/src/apps/marble-kde/KdeMainWindow.cpp
index bebb8a1..0d414c4 100644
--- a/src/apps/marble-kde/KdeMainWindow.cpp
+++ b/src/apps/marble-kde/KdeMainWindow.cpp
@@ -17,6 +17,8 @@
#include <QToolBar>
#include <QAction>
#include <QActionGroup>
+#include <QCoreApplication>
+#include <QCloseEvent>
// KDE
#include <kaction.h>
@@ -186,5 +188,17 @@ void MainWindow::changeViewSize( QAction* action )
mDebug()<<size();
}
+void MainWindow::closeEvent( QCloseEvent *event )
+{
+ QCloseEvent newEvent;
+ QCoreApplication::sendEvent( this->marbleControl(), &newEvent );
+
+ if ( newEvent.isAccepted() ) {
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+
}
#include "KdeMainWindow.moc"
diff --git a/src/apps/marble-kde/KdeMainWindow.h b/src/apps/marble-kde/KdeMainWindow.h
index 7a94119..df1385f 100644
--- a/src/apps/marble-kde/KdeMainWindow.h
+++ b/src/apps/marble-kde/KdeMainWindow.h
@@ -42,6 +42,9 @@ class MainWindow : public KXmlGuiWindow
void setMapTitle();
void changeViewSize( QAction* );
+ protected:
+ void closeEvent( QCloseEvent *event );
+
private:
QSize m_savedSize;
MarblePart *m_part;
diff --git a/src/apps/marble-qt/QtMainWindow.cpp b/src/apps/marble-qt/QtMainWindow.cpp
index c4280c6..94d30d1 100644
--- a/src/apps/marble-qt/QtMainWindow.cpp
+++ b/src/apps/marble-qt/QtMainWindow.cpp
@@ -1128,10 +1128,18 @@ void MainWindow::removeProgressItem(){
m_downloadProgressBar->setUpdatesEnabled( true );
}
-void MainWindow::closeEvent(QCloseEvent *event)
+void MainWindow::closeEvent( QCloseEvent *event )
{
writeSettings();
- event->accept();
+
+ QCloseEvent newEvent;
+ QCoreApplication::sendEvent( m_controlView, &newEvent );
+
+ if ( newEvent.isAccepted() ) {
+ event->accept();
+ } else {
+ event->ignore();
+ }
}
QString MainWindow::readMarbleDataPath()
diff --git a/src/apps/marble-qt/QtMainWindow.h b/src/apps/marble-qt/QtMainWindow.h
index 595ffd2..81f23d4 100644
--- a/src/apps/marble-qt/QtMainWindow.h
+++ b/src/apps/marble-qt/QtMainWindow.h
@@ -59,7 +59,7 @@ public:
void addGeoDataFile( const QString &fileName );
protected:
- void closeEvent(QCloseEvent *event);
+ void closeEvent( QCloseEvent *event );
private:
void createActions();
diff --git a/src/apps/marble-ui/ControlView.cpp b/src/apps/marble-ui/ControlView.cpp
index b2d0b84..e2ca010 100644
--- a/src/apps/marble-ui/ControlView.cpp
+++ b/src/apps/marble-ui/ControlView.cpp
@@ -12,6 +12,7 @@
#include "ControlView.h"
+#include <QCloseEvent>
#include <QLayout>
#include <QSplitter>
#include <QStringListModel>
@@ -833,6 +834,18 @@ void ControlView::openTour( const QString &filename )
}
}
+void ControlView::closeEvent( QCloseEvent *event )
+{
+ QCloseEvent newEvent;
+ QCoreApplication::sendEvent( m_tourWidget, &newEvent );
+
+ if ( newEvent.isAccepted() ) {
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+
}
#include "ControlView.moc"
diff --git a/src/apps/marble-ui/ControlView.h b/src/apps/marble-ui/ControlView.h
index 21d58cf..418705a 100644
--- a/src/apps/marble-ui/ControlView.h
+++ b/src/apps/marble-ui/ControlView.h
@@ -128,6 +128,9 @@ signals:
void showUploadDialog();
void mapThemeDeleted();
+protected:
+ void closeEvent( QCloseEvent *event );
+
private Q_SLOTS:
void showSearch();
// Bookmark sync slots
diff --git a/src/lib/marble/TourWidget.cpp b/src/lib/marble/TourWidget.cpp
index b9fab0e..90b8c2b 100644
--- a/src/lib/marble/TourWidget.cpp
+++ b/src/lib/marble/TourWidget.cpp
@@ -102,7 +102,6 @@ private:
bool openDocument( GeoDataDocument *document );
bool saveTourAs( const QString &filename );
bool overrideModifications();
- bool m_isChanged;
public:
TourWidget *q;
@@ -111,6 +110,7 @@ public:
TourCaptureDialog *m_tourCaptureDialog;
TourPlayback m_playback;
TourItemDelegate *m_delegate;
+ bool m_isChanged;
bool m_playState;
bool m_isLoopingStopped;
GeoDataDocument* m_document;
@@ -125,11 +125,11 @@ public:
};
TourWidgetPrivate::TourWidgetPrivate( TourWidget *parent )
- : m_isChanged( false ),
- q( parent ),
+ : q( parent ),
m_widget( 0 ),
m_playback( 0 ),
m_delegate( 0 ),
+ m_isChanged( false ),
m_playState( false ),
m_document( 0 ),
m_addPrimitiveButton( new QToolButton )
@@ -330,6 +330,31 @@ void TourWidget::stopLooping()
d->m_isLoopingStopped = true;
}
+void TourWidget::closeEvent( QCloseEvent *event )
+{
+ if ( !d->m_document || !d->m_isChanged ) {
+ event->accept();
+ return;
+ }
+
+ const int result = QMessageBox::question( d->m_widget,
+ QObject::tr( "Save tour" ),
+ QObject::tr( "There are unsaved Tours. Do you want to save your changes?" ),
+ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
+
+ switch ( result ) {
+ case QMessageBox::Save:
+ d->saveTour();
+ event->accept();
+ break;
+ case QMessageBox::Discard:
+ event->accept();
+ break;
+ case QMessageBox::Cancel:
+ event->ignore();
+ }
+}
+
void TourWidget::handleSliderMove( int value )
{
removeHighlight();
diff --git a/src/lib/marble/TourWidget.h b/src/lib/marble/TourWidget.h
index a6cb8ca..a404eb4 100644
--- a/src/lib/marble/TourWidget.h
+++ b/src/lib/marble/TourWidget.h
@@ -48,7 +48,7 @@ class MARBLE_EXPORT TourWidget : public QWidget
{
Q_OBJECT
- public:
+public:
explicit TourWidget( QWidget *parent = 0, Qt::WindowFlags f = 0 );
~TourWidget();
@@ -88,7 +88,10 @@ private Q_SLOTS:
void finishAddingItem();
void stopLooping();
- private:
+protected:
+ void closeEvent( QCloseEvent *event );
+
+private:
Q_PRIVATE_SLOT( d, void openFile() )
Q_PRIVATE_SLOT( d, void createTour() )
Q_PRIVATE_SLOT( d, void saveTour() )