File indexing completed on 2024-04-28 15:14:02

0001 /***************************************************************************
0002     File                 : MainWin.h
0003     Project              : LabPlot
0004     --------------------------------------------------------------------
0005     Copyright            : (C) 2011-2020 Alexander Semke (alexander.semke@web.de)
0006     Copyright            : (C) 2008-2018 by Stefan Gerlach (stefan.gerlach@uni.kn)
0007     Description          : Main window of the application
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *  This program is free software; you can redistribute it and/or modify   *
0013  *  it under the terms of the GNU General Public License as published by   *
0014  *  the Free Software Foundation; either version 2 of the License, or      *
0015  *  (at your option) any later version.                                    *
0016  *                                                                         *
0017  *  This program is distributed in the hope that it will be useful,        *
0018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0020  *  GNU General Public License for more details.                           *
0021  *                                                                         *
0022  *   You should have received a copy of the GNU General Public License     *
0023  *   along with this program; if not, write to the Free Software           *
0024  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0025  *   Boston, MA  02110-1301  USA                                           *
0026  *                                                                         *
0027  ***************************************************************************/
0028 #ifndef MAINWIN_H
0029 #define MAINWIN_H
0030 
0031 #include "backend/worksheet/plots/cartesian/CartesianPlot.h"
0032 
0033 #include <KXmlGuiWindow>
0034 #include <QTimer>
0035 
0036 class AbstractAspect;
0037 class AspectTreeModel;
0038 class Folder;
0039 class ProjectExplorer;
0040 class Project;
0041 class Worksheet;
0042 class Note;
0043 class Workbook;
0044 class Datapicker;
0045 class Spreadsheet;
0046 class Matrix;
0047 class GuiObserver;
0048 class AxisDock;
0049 class CursorDock;
0050 class NoteDock;
0051 class CartesianPlotDock;
0052 class HistogramDock;
0053 class BarChartPlotDock;
0054 class CartesianPlotLegendDock;
0055 class CustomPointDock;
0056 class ReferenceLineDock;
0057 class ColumnDock;
0058 class LiveDataDock;
0059 class MatrixDock;
0060 class ProjectDock;
0061 class SpreadsheetDock;
0062 class XYCurveDock;
0063 class XYEquationCurveDock;
0064 class XYDataReductionCurveDock;
0065 class XYDifferentiationCurveDock;
0066 class XYIntegrationCurveDock;
0067 class XYInterpolationCurveDock;
0068 class XYSmoothCurveDock;
0069 class XYFitCurveDock;
0070 class XYFourierFilterCurveDock;
0071 class XYFourierTransformCurveDock;
0072 class XYConvolutionCurveDock;
0073 class XYCorrelationCurveDock;
0074 class WorksheetDock;
0075 class ImageDock;
0076 class LabelWidget;
0077 class DatapickerImageWidget;
0078 class DatapickerCurveWidget;
0079 class MemoryWidget;
0080 class CartesianPlot;
0081 
0082 #ifdef HAVE_CANTOR_LIBS
0083 class CantorWorksheet;
0084 class CantorWorksheetDock;
0085 #endif
0086 
0087 class ImportDatasetWidget;
0088 class TreeModel;
0089 // class WelcomeScreenHelper;
0090 
0091 class QDockWidget;
0092 class QDragEnterEvent;
0093 class QDropEvent;
0094 class QMdiArea;
0095 class QMdiSubWindow;
0096 class QStackedWidget;
0097 class QToolButton;
0098 class QQuickWidget;
0099 
0100 class KColorSchemeManager;
0101 class KRecentFilesAction;
0102 class KToggleFullScreenAction;
0103 
0104 #ifdef HAVE_KUSERFEEDBACK
0105 #include <KUserFeedback/Provider>
0106 #endif
0107 
0108 #ifdef Q_OS_MAC
0109     class KDMacTouchBar;
0110 #endif
0111 
0112 class MainWin : public KXmlGuiWindow {
0113     Q_OBJECT
0114 
0115 public:
0116     explicit MainWin(QWidget* parent = nullptr, const QString& filename = nullptr);
0117     ~MainWin() override;
0118 
0119     void showPresenter();
0120     AspectTreeModel* model() const;
0121     Project* project() const;
0122     void addAspectToProject(AbstractAspect*);
0123 
0124     enum class LoadOnStart {Nothing, NewProject, NewProjectWorksheet, LastProject, WelcomeScreen};
0125     enum class TitleBarMode {ShowFilePath, ShowFileName, ShowProjectName};
0126 
0127 #ifdef HAVE_KUSERFEEDBACK
0128     KUserFeedback::Provider& userFeedbackProvider() {return m_userFeedbackProvider;}
0129 #endif
0130 
0131 private:
0132     QMdiArea* m_mdiArea{nullptr};
0133     KColorSchemeManager* m_schemeManager{nullptr};
0134     QMdiSubWindow* m_currentSubWindow{nullptr};
0135     Project* m_project{nullptr};
0136     AspectTreeModel* m_aspectTreeModel{nullptr};
0137     ProjectExplorer* m_projectExplorer{nullptr};
0138     QDockWidget* m_projectExplorerDock{nullptr};
0139     QDockWidget* m_propertiesDock{nullptr};
0140     AbstractAspect* m_currentAspect{nullptr};
0141     Folder* m_currentFolder{nullptr};
0142     QString m_currentFileName;
0143     QString m_undoViewEmptyLabel;
0144     bool m_suppressCurrentSubWindowChangedEvent{false};
0145     bool m_closing{false};
0146     bool m_projectClosing{false};
0147     bool m_autoSaveActive{false};
0148     QTimer m_autoSaveTimer;
0149     bool m_showWelcomeScreen{false};
0150     bool m_saveWelcomeScreen{true};
0151     MemoryWidget* m_memoryInfoWidget{nullptr};
0152     QMdiSubWindow* m_welcomeWindow{nullptr};
0153     QQuickWidget* m_welcomeWidget{nullptr};
0154 //  WelcomeScreenHelper* m_welcomeScreenHelper{nullptr};
0155     ImportDatasetWidget* m_importDatasetWidget{nullptr};
0156     QString m_lastOpenFileFilter;
0157     TitleBarMode m_titleBarMode{TitleBarMode::ShowFilePath};
0158 
0159 #ifdef HAVE_KUSERFEEDBACK
0160     KUserFeedback::Provider m_userFeedbackProvider;
0161 #endif
0162 
0163 #ifdef Q_OS_MAC
0164     KDMacTouchBar* m_touchBar;
0165     QAction* m_undoIconOnlyAction;
0166     QAction* m_redoIconOnlyAction;
0167 #endif
0168 
0169     KRecentFilesAction* m_recentProjectsAction;
0170     QAction* m_saveAction;
0171     QAction* m_saveAsAction;
0172     QAction* m_printAction;
0173     QAction* m_printPreviewAction;
0174     QAction* m_importFileAction;
0175     QAction* m_importSqlAction;
0176     QAction* m_importDatasetAction;
0177     QAction* m_importLabPlotAction;
0178     QAction* m_importOpjAction;
0179     QAction* m_exportAction;
0180     QAction* m_closeAction;
0181     QAction* m_newFolderAction;
0182     QAction* m_newWorkbookAction;
0183     QAction* m_newSpreadsheetAction;
0184     QAction* m_newMatrixAction;
0185     QAction* m_newWorksheetAction;
0186     QAction* m_newNotesAction;
0187     QAction* m_newLiveDataSourceAction;
0188     QAction* m_newSqlDataSourceAction;
0189     QAction* m_newScriptAction;
0190     QAction* m_newProjectAction;
0191     QAction* m_openProjectAction;
0192     QAction* m_historyAction;
0193     QAction* m_undoAction;
0194     QAction* m_redoAction;
0195     QAction* m_closeWindowAction;
0196     QAction* m_closeAllWindowsAction;
0197     QAction* m_tileWindowsAction;
0198     QAction* m_cascadeWindowsAction;
0199     QAction* m_nextWindowAction;
0200     QAction* m_prevWindowAction;
0201     QAction* m_newDatapickerAction;
0202     QAction* m_editFitsFileAction;
0203 
0204     //toggling doch widgets and the status bar
0205     QAction* m_toggleProjectExplorerDockAction;
0206     QAction* m_togglePropertiesDockAction;
0207     QAction* m_toggleStatusBarAction;
0208     QAction* m_toggleMemoryInfoAction;
0209     KToggleFullScreenAction* m_toggleFullScreenAction;
0210 
0211     //window visibility
0212     QAction* m_visibilityFolderAction;
0213     QAction* m_visibilitySubfolderAction;
0214     QAction* m_visibilityAllAction;
0215 
0216     //Menus
0217     QMenu* m_visibilityMenu{nullptr};
0218     QMenu* m_newMenu{nullptr};
0219     QMenu* m_importMenu;
0220     QMenu* m_editMenu{nullptr};
0221 
0222     //Docks
0223     QStackedWidget* stackedWidget{nullptr};
0224     AxisDock* axisDock{nullptr};
0225     QDockWidget* cursorDock{nullptr};
0226     CursorDock* cursorWidget{nullptr};
0227     NoteDock* notesDock{nullptr};
0228     CartesianPlotDock* cartesianPlotDock{nullptr};
0229     CartesianPlotLegendDock* cartesianPlotLegendDock{nullptr};
0230     ColumnDock* columnDock{nullptr};
0231     LiveDataDock* m_liveDataDock{nullptr};
0232     MatrixDock* matrixDock{nullptr};
0233     SpreadsheetDock* spreadsheetDock{nullptr};
0234     ProjectDock* projectDock{nullptr};
0235     XYCurveDock* xyCurveDock{nullptr};
0236     XYEquationCurveDock* xyEquationCurveDock{nullptr};
0237     XYDataReductionCurveDock* xyDataReductionCurveDock{nullptr};
0238     XYDifferentiationCurveDock* xyDifferentiationCurveDock{nullptr};
0239     XYIntegrationCurveDock* xyIntegrationCurveDock{nullptr};
0240     XYInterpolationCurveDock* xyInterpolationCurveDock{nullptr};
0241     XYSmoothCurveDock* xySmoothCurveDock{nullptr};
0242     XYFitCurveDock* xyFitCurveDock{nullptr};
0243     XYFourierFilterCurveDock* xyFourierFilterCurveDock{nullptr};
0244     XYFourierTransformCurveDock* xyFourierTransformCurveDock{nullptr};
0245     XYConvolutionCurveDock* xyConvolutionCurveDock{nullptr};
0246     XYCorrelationCurveDock* xyCorrelationCurveDock{nullptr};
0247     HistogramDock* histogramDock{nullptr};
0248     WorksheetDock* worksheetDock{nullptr};
0249     LabelWidget* textLabelDock{nullptr};
0250     ImageDock* imageDock{nullptr};
0251     CustomPointDock* customPointDock{nullptr};
0252     ReferenceLineDock* referenceLineDock{nullptr};
0253     DatapickerImageWidget* datapickerImageDock{nullptr};
0254     DatapickerCurveWidget* datapickerCurveDock{nullptr};
0255 
0256     void initActions();
0257     void initMenus();
0258     bool warnModified();
0259     void activateSubWindowForAspect(const AbstractAspect*) const;
0260     bool save(const QString&);
0261 //  void toggleShowWidget(QWidget* widget, bool showToRight);
0262 //  void toggleHideWidget(QWidget* widget, bool hideToLeft);
0263 
0264     Spreadsheet* activeSpreadsheet() const;
0265 
0266     //Cantor
0267 #ifdef HAVE_CANTOR_LIBS
0268     QMenu* m_newCantorWorksheetMenu;
0269     CantorWorksheetDock* cantorWorksheetDock{nullptr};
0270 #endif
0271 
0272     friend class GuiObserver;
0273     GuiObserver* m_guiObserver{nullptr};
0274 
0275 protected:
0276     void closeEvent(QCloseEvent*) override;
0277     void dragEnterEvent(QDragEnterEvent*) override;
0278     void dropEvent(QDropEvent*) override;
0279 
0280 private slots:
0281     void initGUI(const QString&);
0282 //  QQuickWidget* createWelcomeScreen();
0283 //  void resetWelcomeScreen();
0284     void createMdiArea();
0285     void updateGUI();
0286     void updateGUIOnProjectChanges();
0287     void undo();
0288     void redo();
0289 
0290     bool newProject();
0291     void openProject();
0292     void openProject(const QString&);
0293     void openRecentProject(const QUrl&);
0294     bool closeProject();
0295     bool saveProject();
0296     bool saveProjectAs();
0297     void autoSaveProject();
0298     void updateTitleBar();
0299 
0300     void print();
0301     void printPreview();
0302 
0303     void historyDialog();
0304     void importFileDialog(const QString& fileName = QString());
0305     void importSqlDialog();
0306     void importProjectDialog();
0307     void importDatasetDialog();
0308     void exportDialog();
0309     void editFitsFileDialog();
0310     void settingsDialog();
0311     void projectChanged();
0312     void colorSchemeChanged(QAction*);
0313     void openDatasetExample();
0314 
0315     //Cantor
0316 #ifdef HAVE_CANTOR_LIBS
0317     void newCantorWorksheet(QAction* action);
0318     void cantorSettingsDialog();
0319 #endif
0320 
0321     void newFolder();
0322     void newWorkbook();
0323     void newSpreadsheet();
0324     void newMatrix();
0325     void newWorksheet();
0326     void newNotes();
0327     void newDatapicker();
0328     //TODO: void newScript();
0329     void newLiveDataSourceActionTriggered();
0330 
0331     void createContextMenu(QMenu*) const;
0332     void createFolderContextMenu(const Folder*, QMenu*) const;
0333 
0334     void handleAspectAdded(const AbstractAspect*);
0335     void handleAspectAboutToBeRemoved(const AbstractAspect*);
0336     void handleAspectRemoved(const AbstractAspect*,const AbstractAspect*,const AbstractAspect*);
0337     void handleCurrentAspectChanged(AbstractAspect* );
0338     void handleCurrentSubWindowChanged(QMdiSubWindow*);
0339     void handleShowSubWindowRequested();
0340 
0341     void handleSettingsChanges();
0342 
0343     void setMdiWindowVisibility(QAction*);
0344     void updateMdiWindowVisibility() const;
0345     void toggleDockWidget(QAction*);
0346     void toggleStatusBar();
0347     void toggleMemoryInfo();
0348     void toggleFullScreen(bool);
0349     void projectExplorerDockVisibilityChanged(bool);
0350     void propertiesDockVisibilityChanged(bool);
0351     void cursorDockVisibilityChanged(bool);
0352     void propertiesExplorerRequested();
0353 
0354     void cartesianPlotMouseModeChanged(CartesianPlot::MouseMode);
0355 };
0356 
0357 #endif