2017-04-27 18:26:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-04-14 03:44:02 +00:00
|
|
|
/*
|
|
|
|
* mainwindow.h
|
|
|
|
*
|
|
|
|
* header file for the main window of Subsurface
|
|
|
|
*
|
|
|
|
*/
|
2013-04-07 22:20:43 +00:00
|
|
|
#ifndef MAINWINDOW_H
|
|
|
|
#define MAINWINDOW_H
|
|
|
|
|
|
|
|
#include <QMainWindow>
|
2013-05-12 13:54:34 +00:00
|
|
|
#include <QAction>
|
2013-12-05 12:02:25 +00:00
|
|
|
#include <QUrl>
|
2015-02-11 18:14:45 +00:00
|
|
|
#include <QUuid>
|
2015-09-09 20:02:39 +00:00
|
|
|
#include <QProgressDialog>
|
2019-04-13 08:54:06 +00:00
|
|
|
#include <memory>
|
2013-04-07 22:20:43 +00:00
|
|
|
|
2013-10-03 18:54:24 +00:00
|
|
|
#include "ui_mainwindow.h"
|
2017-11-27 16:36:21 +00:00
|
|
|
#include "ui_plannerDetails.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/notificationwidget.h"
|
2020-09-26 09:40:54 +00:00
|
|
|
#include "desktop-widgets/filterwidget.h"
|
2019-11-17 17:13:55 +00:00
|
|
|
#include "core/dive.h"
|
2020-02-18 01:16:11 +00:00
|
|
|
#include "core/subsurface-qt/divelistnotifier.h"
|
2013-10-03 18:54:24 +00:00
|
|
|
|
2017-11-30 10:52:42 +00:00
|
|
|
#define NUM_RECENT_FILES 4
|
|
|
|
|
2013-04-25 23:44:06 +00:00
|
|
|
class QSortFilterProxyModel;
|
2013-04-12 07:24:07 +00:00
|
|
|
class DiveTripModel;
|
2013-05-04 00:49:40 +00:00
|
|
|
class QItemSelection;
|
2013-05-19 03:09:36 +00:00
|
|
|
class DiveListView;
|
2022-09-18 11:49:29 +00:00
|
|
|
class DiveSiteListView;
|
2013-05-19 03:09:36 +00:00
|
|
|
class MainTab;
|
2020-12-18 11:01:36 +00:00
|
|
|
class MapWidget;
|
2013-08-22 19:20:47 +00:00
|
|
|
class QWebView;
|
2018-08-29 10:08:47 +00:00
|
|
|
class QSettings;
|
2014-04-02 19:41:39 +00:00
|
|
|
class UpdateManager;
|
2014-06-30 20:45:52 +00:00
|
|
|
class UserManual;
|
2020-11-25 06:31:19 +00:00
|
|
|
class PlannerWidgets;
|
2021-04-12 21:34:28 +00:00
|
|
|
class ProfileWidget;
|
2020-12-18 11:01:36 +00:00
|
|
|
class StatsWidget;
|
2015-05-17 19:13:41 +00:00
|
|
|
class LocationInformationWidget;
|
2013-04-07 22:20:43 +00:00
|
|
|
|
2019-09-27 23:26:54 +00:00
|
|
|
class MainWindow : public QMainWindow {
|
2014-02-28 04:09:57 +00:00
|
|
|
Q_OBJECT
|
2013-04-07 22:20:43 +00:00
|
|
|
public:
|
|
|
|
MainWindow();
|
2018-07-31 05:41:19 +00:00
|
|
|
~MainWindow();
|
2019-09-27 23:26:54 +00:00
|
|
|
static MainWindow *instance();
|
2017-11-30 10:52:42 +00:00
|
|
|
void loadRecentFiles();
|
|
|
|
void updateRecentFiles();
|
|
|
|
void updateRecentFilesMenu();
|
|
|
|
void addRecentFile(const QString &file, bool update);
|
2015-02-11 15:19:35 +00:00
|
|
|
LocationInformationWidget *locationInformationWidget();
|
2017-12-11 16:43:53 +00:00
|
|
|
void setTitle();
|
2013-04-09 08:35:44 +00:00
|
|
|
|
2021-02-14 19:59:02 +00:00
|
|
|
enum class ApplicationState {
|
|
|
|
Default,
|
|
|
|
PlanDive,
|
|
|
|
EditDiveSite,
|
|
|
|
FilterDive,
|
|
|
|
Statistics,
|
2022-09-18 11:49:29 +00:00
|
|
|
DiveSites,
|
2021-02-14 19:59:02 +00:00
|
|
|
MapMaximized,
|
|
|
|
ProfileMaximized,
|
|
|
|
ListMaximized,
|
|
|
|
InfoMaximized,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
2013-09-09 08:59:03 +00:00
|
|
|
void loadFiles(const QStringList files);
|
|
|
|
void importFiles(const QStringList importFiles);
|
2014-03-11 16:30:58 +00:00
|
|
|
void setToolButtonsEnabled(bool enabled);
|
2019-05-10 17:51:43 +00:00
|
|
|
void setApplicationState(ApplicationState state);
|
2022-09-18 13:25:41 +00:00
|
|
|
void enterPreviousState();
|
2015-02-26 14:07:39 +00:00
|
|
|
NotificationWidget *getNotificationWidget();
|
2015-06-14 22:42:28 +00:00
|
|
|
void enableDisableCloudActions();
|
2019-03-16 10:35:44 +00:00
|
|
|
void editDiveSite(dive_site *ds);
|
2021-04-12 21:34:28 +00:00
|
|
|
void setEnabledToolbar(bool arg1);
|
2015-11-19 02:52:44 +00:00
|
|
|
|
2019-04-13 08:54:06 +00:00
|
|
|
std::unique_ptr<MainTab> mainTab;
|
2020-11-25 06:31:19 +00:00
|
|
|
std::unique_ptr<PlannerWidgets> plannerWidgets;
|
2020-12-18 11:01:36 +00:00
|
|
|
std::unique_ptr<StatsWidget> statistics;
|
2022-09-18 11:49:29 +00:00
|
|
|
std::unique_ptr<DiveSiteListView> diveSites;
|
2020-12-18 11:01:36 +00:00
|
|
|
std::unique_ptr<DiveListView> diveList;
|
2021-04-12 21:34:28 +00:00
|
|
|
std::unique_ptr<ProfileWidget> profile;
|
2020-12-18 11:01:36 +00:00
|
|
|
std::unique_ptr<MapWidget> mapWidget;
|
2014-02-28 04:09:57 +00:00
|
|
|
private
|
|
|
|
slots:
|
2013-04-09 16:26:23 +00:00
|
|
|
/* file menu action */
|
2014-02-13 21:48:07 +00:00
|
|
|
void recentFileTriggered(bool checked);
|
2013-04-09 08:35:44 +00:00
|
|
|
void on_actionNew_triggered();
|
2013-04-09 16:26:23 +00:00
|
|
|
void on_actionOpen_triggered();
|
|
|
|
void on_actionSave_triggered();
|
|
|
|
void on_actionSaveAs_triggered();
|
|
|
|
void on_actionClose_triggered();
|
2015-06-01 05:11:27 +00:00
|
|
|
void on_actionCloudstorageopen_triggered();
|
|
|
|
void on_actionCloudstoragesave_triggered();
|
2018-01-03 10:46:21 +00:00
|
|
|
void on_actionCloudOnline_triggered();
|
2013-04-09 16:26:23 +00:00
|
|
|
void on_actionPrint_triggered();
|
|
|
|
void on_actionPreferences_triggered();
|
|
|
|
void on_actionQuit_triggered();
|
2015-02-26 13:44:27 +00:00
|
|
|
void on_actionHash_images_triggered();
|
2013-04-09 16:26:23 +00:00
|
|
|
|
|
|
|
/* log menu actions */
|
|
|
|
void on_actionDownloadDC_triggered();
|
2013-10-25 01:02:59 +00:00
|
|
|
void on_actionDivelogs_de_triggered();
|
2013-04-09 16:26:23 +00:00
|
|
|
void on_actionAddDive_triggered();
|
|
|
|
void on_actionRenumber_triggered();
|
|
|
|
void on_actionAutoGroup_triggered();
|
|
|
|
void on_actionYearlyStatistics_triggered();
|
|
|
|
|
|
|
|
/* view menu actions */
|
|
|
|
void on_actionViewList_triggered();
|
|
|
|
void on_actionViewProfile_triggered();
|
|
|
|
void on_actionViewInfo_triggered();
|
2017-07-14 22:48:53 +00:00
|
|
|
void on_actionViewMap_triggered();
|
2022-09-18 11:49:29 +00:00
|
|
|
void on_actionViewDiveSites_triggered();
|
2013-04-09 16:26:23 +00:00
|
|
|
void on_actionViewAll_triggered();
|
|
|
|
void on_actionPreviousDC_triggered();
|
|
|
|
void on_actionNextDC_triggered();
|
2014-01-14 17:36:07 +00:00
|
|
|
void on_actionFullScreen_triggered(bool checked);
|
2013-04-09 16:26:23 +00:00
|
|
|
|
|
|
|
/* other menu actions */
|
|
|
|
void on_actionAboutSubsurface_triggered();
|
|
|
|
void on_actionUserManual_triggered();
|
2013-06-20 21:48:21 +00:00
|
|
|
void on_actionDivePlanner_triggered();
|
2014-08-19 20:03:53 +00:00
|
|
|
void on_actionReplanDive_triggered();
|
2014-04-02 19:41:39 +00:00
|
|
|
void on_action_Check_for_Updates_triggered();
|
2013-04-09 08:35:44 +00:00
|
|
|
|
2022-09-03 20:45:08 +00:00
|
|
|
void divesSelected(const std::vector<dive *> &selection, dive *currentDive, int currentDC);
|
2013-06-04 12:40:09 +00:00
|
|
|
void initialUiSetup();
|
2013-05-14 11:18:26 +00:00
|
|
|
|
2013-12-29 16:11:20 +00:00
|
|
|
void on_actionImportDiveLog_triggered();
|
2019-05-05 03:46:42 +00:00
|
|
|
void on_actionImportDiveSites_triggered();
|
2013-10-16 19:05:19 +00:00
|
|
|
|
2014-02-06 13:38:28 +00:00
|
|
|
/* TODO: Move those slots below to it's own class */
|
2014-05-20 16:33:32 +00:00
|
|
|
void on_actionExport_triggered();
|
2014-08-16 15:32:23 +00:00
|
|
|
void on_copy_triggered();
|
|
|
|
void on_paste_triggered();
|
2014-09-17 17:50:41 +00:00
|
|
|
void on_actionFilterTags_triggered();
|
2020-10-28 11:23:41 +00:00
|
|
|
void on_actionStats_triggered();
|
2014-05-29 15:54:19 +00:00
|
|
|
void on_actionConfigure_Dive_Computer_triggered();
|
2015-02-11 15:58:23 +00:00
|
|
|
void setDefaultState();
|
2015-06-16 13:04:34 +00:00
|
|
|
void setAutomaticTitle();
|
2015-09-09 20:02:39 +00:00
|
|
|
void cancelCloudStorageOperation();
|
2014-05-29 15:54:19 +00:00
|
|
|
|
2013-04-27 09:09:57 +00:00
|
|
|
protected:
|
|
|
|
void closeEvent(QCloseEvent *);
|
|
|
|
|
2015-08-25 21:27:19 +00:00
|
|
|
signals:
|
2018-01-28 21:08:30 +00:00
|
|
|
void showError(QString message);
|
2015-08-25 21:27:19 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
public
|
|
|
|
slots:
|
2013-05-26 18:33:45 +00:00
|
|
|
void readSettings();
|
2014-05-28 18:43:32 +00:00
|
|
|
void planCanceled();
|
2014-05-28 18:54:04 +00:00
|
|
|
void planCreated();
|
2015-11-05 19:12:22 +00:00
|
|
|
// Some shortcuts like "change DC" or "copy/paste dive components"
|
|
|
|
// should only be enabled when the profile's visible.
|
2019-03-16 10:51:42 +00:00
|
|
|
void startDiveSiteEdit();
|
2017-01-02 06:23:39 +00:00
|
|
|
|
2013-04-07 22:20:43 +00:00
|
|
|
private:
|
2021-02-14 19:59:02 +00:00
|
|
|
ApplicationState appState;
|
2022-09-18 13:25:41 +00:00
|
|
|
std::vector<ApplicationState> state_stack;
|
2013-10-03 18:54:25 +00:00
|
|
|
Ui::MainWindow ui;
|
2020-09-26 09:40:54 +00:00
|
|
|
FilterWidget filterWidget;
|
2020-12-18 11:01:36 +00:00
|
|
|
std::unique_ptr<QSplitter> topSplitter;
|
|
|
|
std::unique_ptr<QSplitter> bottomSplitter;
|
2013-05-12 13:54:34 +00:00
|
|
|
QAction *actionNextDive;
|
|
|
|
QAction *actionPreviousDive;
|
2018-07-30 09:15:08 +00:00
|
|
|
QAction *undoAction;
|
|
|
|
QAction *redoAction;
|
2018-05-31 14:36:34 +00:00
|
|
|
#ifndef NO_USERMANUAL
|
2014-06-30 20:45:52 +00:00
|
|
|
UserManual *helpView;
|
2018-05-31 14:36:34 +00:00
|
|
|
#endif
|
2017-10-27 12:52:27 +00:00
|
|
|
QString filter_open();
|
|
|
|
QString filter_import();
|
2019-05-05 03:46:42 +00:00
|
|
|
QString filter_import_dive_sites();
|
2019-09-27 23:26:54 +00:00
|
|
|
static MainWindow *m_Instance;
|
2015-06-12 13:53:00 +00:00
|
|
|
QString displayedFilename(QString fullFilename);
|
2013-04-13 13:17:59 +00:00
|
|
|
bool askSaveChanges();
|
2014-06-09 02:46:43 +00:00
|
|
|
bool okToClose(QString message);
|
|
|
|
void closeCurrentFile();
|
2018-01-03 16:11:52 +00:00
|
|
|
void setCurrentFile(const char *f);
|
|
|
|
void updateCloudOnlineStatus();
|
2015-09-09 20:02:39 +00:00
|
|
|
void showProgressBar();
|
|
|
|
void hideProgressBar();
|
2013-04-27 09:09:57 +00:00
|
|
|
void writeSettings();
|
2022-03-02 20:08:19 +00:00
|
|
|
void refreshDisplay();
|
2022-11-12 08:14:00 +00:00
|
|
|
void updateAutogroup();
|
2022-03-02 20:08:19 +00:00
|
|
|
void showProfile();
|
2014-03-14 17:19:23 +00:00
|
|
|
int file_save();
|
|
|
|
int file_save_as();
|
2013-11-07 16:37:27 +00:00
|
|
|
void saveSplitterSizes();
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
void restoreSplitterSizes();
|
2014-02-28 04:09:57 +00:00
|
|
|
void updateLastUsedDir(const QString &s);
|
2014-03-11 21:54:28 +00:00
|
|
|
bool filesAsArguments;
|
2014-04-02 19:41:39 +00:00
|
|
|
UpdateManager *updateManager;
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
std::unique_ptr<LocationInformationWidget> diveSiteEdit;
|
2014-05-25 18:19:36 +00:00
|
|
|
|
2022-03-12 11:48:12 +00:00
|
|
|
bool inPlanner();
|
2014-05-25 18:19:36 +00:00
|
|
|
bool plannerStateClean();
|
2015-11-09 20:05:30 +00:00
|
|
|
void setupSocialNetworkMenu();
|
2018-06-10 14:40:23 +00:00
|
|
|
QDialog *findMovedImagesDialog;
|
2014-08-16 15:32:23 +00:00
|
|
|
struct dive copyPasteDive;
|
|
|
|
struct dive_components what;
|
2017-11-30 10:52:42 +00:00
|
|
|
QStringList recentFiles;
|
2017-11-30 16:44:32 +00:00
|
|
|
QAction *actionsRecent[NUM_RECENT_FILES];
|
2015-02-09 17:35:36 +00:00
|
|
|
|
2019-05-10 18:51:25 +00:00
|
|
|
enum {
|
|
|
|
FLAG_NONE = 0,
|
|
|
|
FLAG_DISABLED = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Quadrant {
|
|
|
|
QWidget *widget;
|
|
|
|
int flags;
|
2015-02-09 17:35:36 +00:00
|
|
|
};
|
2015-08-21 01:24:49 +00:00
|
|
|
|
2019-05-10 18:51:25 +00:00
|
|
|
struct Quadrants {
|
2020-12-17 22:13:06 +00:00
|
|
|
bool allowUserChange; // Allow the user to change away from this state
|
2019-05-10 18:51:25 +00:00
|
|
|
Quadrant topLeft;
|
|
|
|
Quadrant topRight;
|
|
|
|
Quadrant bottomLeft;
|
|
|
|
Quadrant bottomRight;
|
2015-08-21 01:24:49 +00:00
|
|
|
};
|
|
|
|
|
2019-05-10 18:51:25 +00:00
|
|
|
Quadrants applicationState[(size_t)ApplicationState::Count];
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
static void addWidgets(const Quadrant &);
|
2020-12-17 22:13:06 +00:00
|
|
|
bool userMayChangeAppState() const;
|
2021-01-27 21:06:41 +00:00
|
|
|
void setQuadrantWidget(QSplitter &splitter, const Quadrant &q, int pos);
|
|
|
|
void setQuadrantWidgets(QSplitter &splitter, const Quadrant &left, const Quadrant &right);
|
2019-05-10 18:51:25 +00:00
|
|
|
void registerApplicationState(ApplicationState state, Quadrants q);
|
profile: remove [disable|enable]Shortcuts() signals
When switching to the "plan" or "add" (which should rather be
called "edit", by the way) mode of the profile, the "shortcuts"
for copy&paste, undo&redo, etc. are disabled. When switching
to "profile" mode, they are reenabled.
This was done in a most convoluted way:
- The MainWindow calls the set*State() function of the profile.
- The Profile emits [disable|enable]Shortcuts() signals.
- The MainWindow catches these signals and does the enabling
or disabling.
Not only is this very hard to reason about, it is also in
contradiction to the profile being part of the display layer.
Moreover, in editCurrentDive() the MainWindow disabled the
shortcuts itself, so this was all redundant.
For the sake of sanity, let's just move this logic to the
MainWindow, unslotify the [disable|enable]Shortcuts() functions
and make them private.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-04-09 19:51:42 +00:00
|
|
|
void disableShortcuts(bool disablePaste = true);
|
|
|
|
void enableShortcuts();
|
2015-08-21 01:24:49 +00:00
|
|
|
|
2017-01-02 06:19:08 +00:00
|
|
|
QMenu *connections;
|
2017-04-16 09:41:29 +00:00
|
|
|
QAction *share_on_fb;
|
2020-02-18 01:16:11 +00:00
|
|
|
void divesChanged(const QVector<dive *> &dives, DiveField field);
|
2013-04-07 22:20:43 +00:00
|
|
|
};
|
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // MAINWINDOW_H
|