diff options
author | Grace Karanja <gracie.karanja89@gmail.com> | 2015-02-09 09:24:32 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-02-09 21:02:13 -0800 |
commit | c5138b2090e50cf76a51af1c561a31b5e01485db (patch) | |
tree | 1b1673e4b9b9cddc95d693776c89e49a84ca0b03 | |
parent | 853dfa66735db874cc16688e6fd9ad9320474e37 (diff) | |
download | subsurface-c5138b2090e50cf76a51af1c561a31b5e01485db.tar.gz |
Add menu entries for undo/redo
Add an edit menu with undo and redo submenus, and connect them to
the UndoBuffer class. The submenus are only enabled when needed.
Signed-off-by: Grace Karanja <gracie.karanja89@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/mainwindow.cpp | 19 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 5 | ||||
-rw-r--r-- | qt-ui/mainwindow.ui | 26 |
3 files changed, 49 insertions, 1 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 3142f5a82..57af5e091 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -31,6 +31,7 @@ #include "usermanual.h" #endif #include <QNetworkProxy> +#include "undobuffer.h" MainWindow *MainWindow::m_Instance = NULL; @@ -77,6 +78,7 @@ MainWindow::MainWindow() : QMainWindow(), connect(DivePlannerPointsModel::instance(), SIGNAL(planCreated()), this, SLOT(planCreated())); connect(DivePlannerPointsModel::instance(), SIGNAL(planCanceled()), this, SLOT(planCanceled())); connect(ui.printPlan, SIGNAL(pressed()), ui.divePlannerWidget, SLOT(printDecoPlan())); + connect(ui.menu_Edit, SIGNAL(aboutToShow()), this, SLOT(checkForUndoAndRedo())); #ifdef NO_PRINTING ui.printPlan->hide(); #endif @@ -152,6 +154,7 @@ MainWindow::MainWindow() : QMainWindow(), toolBar->setContentsMargins(zeroMargins); updateManager = new UpdateManager(this); + undoBuffer = new UndoBuffer(this); } MainWindow::~MainWindow() @@ -1466,3 +1469,19 @@ void MainWindow::on_actionFilterTags_triggered() else ui.multiFilter->setVisible(true); } + +void MainWindow::on_action_Undo_triggered() +{ + undoBuffer->undo(); +} + +void MainWindow::on_action_Redo_triggered() +{ + undoBuffer->redo(); +} + +void MainWindow::checkForUndoAndRedo() +{ + ui.action_Undo->setEnabled(undoBuffer->canUndo()); + ui.action_Redo->setEnabled(undoBuffer->canRedo()); +} diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 2364caadc..641c9ec9b 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -30,6 +30,7 @@ class QWebView; class QSettings; class UpdateManager; class UserManual; +class UndoBuffer; enum MainWindowTitleFormat { MWTF_DEFAULT, @@ -82,6 +83,7 @@ public: void setPlanNotes(const char *notes); void printPlan(); void checkSurvey(QSettings *s); + UndoBuffer *undoBuffer; private slots: /* file menu action */ @@ -151,6 +153,9 @@ slots: void on_paste_triggered(); void on_actionFilterTags_triggered(); void on_actionConfigure_Dive_Computer_triggered(); + void on_action_Undo_triggered(); + void on_action_Redo_triggered(); + void checkForUndoAndRedo(); protected: void closeEvent(QCloseEvent *); diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index 8ffb8bbd8..9507b5fc8 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -195,7 +195,7 @@ p, li { white-space: pre-wrap; } <x>0</x> <y>0</y> <width>1682</width> - <height>27</height> + <height>25</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -271,7 +271,15 @@ p, li { white-space: pre-wrap; } <addaction name="actionDownloadWeb"/> <addaction name="actionDivelogs_de"/> </widget> + <widget class="QMenu" name="menu_Edit"> + <property name="title"> + <string>&Edit</string> + </property> + <addaction name="action_Undo"/> + <addaction name="action_Redo"/> + </widget> <addaction name="menuFile"/> + <addaction name="menu_Edit"/> <addaction name="menuImport"/> <addaction name="menuLog"/> <addaction name="menuView"/> @@ -813,6 +821,22 @@ p, li { white-space: pre-wrap; } <string>User &survey</string> </property> </action> + <action name="action_Undo"> + <property name="text"> + <string>&Undo</string> + </property> + <property name="shortcut"> + <string>Ctrl+Z</string> + </property> + </action> + <action name="action_Redo"> + <property name="text"> + <string>&Redo</string> + </property> + <property name="shortcut"> + <string>Ctrl+Shift+Z</string> + </property> + </action> </widget> <customwidgets> <customwidget> |