File indexing completed on 2024-04-21 03:42:09

0001 /*
0002     KmPlot - a math. function plotter for the KDE-Desktop
0003 
0004     SPDX-FileCopyrightText: 1998, 1999, 2000, 2002 Klaus-Dieter Möller <kd.moeller@t-online.de>
0005     SPDX-FileCopyrightText: 2006 David Saxton <david@bluehaze.org>
0006 
0007     This file is part of the KDE Project.
0008     KmPlot is part of the KDE-EDU Project.
0009 
0010     SPDX-License-Identifier: GPL-2.0-or-later
0011 */
0012 
0013 /** @file maindlg.h
0014  * @brief Contains the main window class MainDlg. */
0015 
0016 #ifndef MainDlg_included
0017 #define MainDlg_included
0018 
0019 // Qt includes
0020 #include <QDomDocument>
0021 #include <QMenu>
0022 #include <QPrinter>
0023 #include <QStack>
0024 #include <QStandardPaths>
0025 
0026 // KDE includes
0027 #if QT_VERSION_MAJOR == 5
0028 #include <KParts/BrowserExtension>
0029 #else
0030 #include <KParts/NavigationExtension>
0031 #endif
0032 #include <KParts/Part>
0033 #include <KParts/ReadWritePart>
0034 #include <KPluginFactory>
0035 #include <KSharedConfig>
0036 
0037 #undef GrayScale
0038 
0039 // local includes
0040 #include "coordsconfigdialog.h"
0041 #include "kmplotio.h"
0042 #include "kprinterdlg.h"
0043 #include "view.h"
0044 
0045 class BrowserExtension;
0046 class Calculator;
0047 class FunctionEditor;
0048 class FunctionTools;
0049 class KConfigDialog;
0050 class KConstantEditor;
0051 class QAction;
0052 class KRecentFilesAction;
0053 class QTimer;
0054 
0055 class SettingsPageColor;
0056 class SettingsPageFonts;
0057 class SettingsPageGeneral;
0058 class SettingsPageDiagram;
0059 
0060 /**
0061  * @short This is the main window of KmPlot.
0062  */
0063 class MainDlg : public KParts::ReadWritePart
0064 {
0065     Q_OBJECT
0066 
0067 public:
0068     /** Constructor.
0069      * @param parentWidget parent widget for this part
0070      * @param parent parent object
0071      */
0072 #if QT_VERSION_MAJOR == 5
0073     MainDlg(QWidget *parentWidget, QObject *parent, const QVariantList & = QVariantList());
0074 #else
0075     MainDlg(QWidget *parentWidget, QObject *parent, const KPluginMetaData &data);
0076 #endif
0077 
0078     /// Initialized as a pointer to this MainDlg object on creation
0079     static MainDlg *self()
0080     {
0081         return m_self;
0082     }
0083 
0084     /// Cleaning up a bit.
0085     virtual ~MainDlg();
0086 
0087     /// Is set to true if a file from an old file format was loaded
0088     static bool oldfileversion;
0089 
0090     /// The function editor
0091     FunctionEditor *functionEditor() const
0092     {
0093         return m_functionEditor;
0094     }
0095 
0096     /// The coords config dialog
0097     CoordsConfigDialog *coordsDialog();
0098 
0099     /// Returns true if any changes are done
0100     bool isModified()
0101     {
0102         return m_modified;
0103     }
0104 
0105     bool queryClose() Q_DECL_OVERRIDE;
0106 
0107     /// For inserting the title in the function popup menu
0108     QAction *m_firstFunctionAction;
0109 
0110     /// Show the constants editor modal to a parent dialog
0111     void editConstantsModal(QWidget *parent);
0112 
0113     /// Check whether the url links to an existing file
0114     static bool fileExists(const QUrl &url);
0115 
0116 public Q_SLOTS:
0117     // DBus interface
0118     /// Asks the user and returns true if modified data shall be discarded.
0119     Q_SCRIPTABLE bool checkModified();
0120 
0121 public slots:
0122     /// Implement the coordinate system edit dialog
0123     void editAxes();
0124     /// Show the constants editor
0125     void editConstants();
0126     /// Toggle whether the sliders window is shown
0127     void toggleShowSliders();
0128     /// Revert to the previous document state (in m_undoStack).
0129     void undo();
0130     /// Revert to the next document state (in m_redoStack).
0131     void redo();
0132     /// Pushes the previous document state to the undo stack and records the current one
0133     void requestSaveCurrentState();
0134 
0135     /// Save a plot i.e. save the function name and all the settings for the plot
0136     void slotSave();
0137     /// Save a plot and choose a name for it
0138     void slotSaveas();
0139     /// Print the current plot
0140     void slotPrint();
0141     /// For calling print preview functionality
0142     void slotPrintPreview();
0143     /// Export the current plot as a png, svg or bmp picture
0144     void slotExport();
0145     /// Implement the Configure KmPlot dialog
0146     void slotSettings();
0147     /// Calls the common function names dialog.
0148     void slotNames();
0149     /// Resets the view
0150     void slotResetView();
0151     /// Tools menu
0152     void calculator();
0153     void findMinimumValue();
0154     void findMaximumValue();
0155     void graphArea();
0156 
0157 private:
0158     /// Settings the standard and non standard actions of the application.
0159     void setupActions();
0160     /// Sets the printer options and draw the plot with the current options.
0161     void setupPrinter(KPrinterDlg *printDialog, QPrinter *printer);
0162     /// Called when a file is opened. The filename is m_url
0163     bool openFile() Q_DECL_OVERRIDE;
0164 
0165     /// Called when a file is saved. The filename is m_url
0166     bool saveFile() Q_DECL_OVERRIDE;
0167 
0168     /// The Recent Files action
0169     KRecentFilesAction *m_recentFiles;
0170     /// true == modifications not saved
0171     bool m_modified;
0172     /// An instance of the application config file
0173     KSharedConfigPtr m_config;
0174     /// A Configure KmPlot dialog instance
0175     KConfigDialog *m_settingsDialog;
0176     /// The General page for the Configure KmPlot dialog
0177     SettingsPageGeneral *m_generalSettings;
0178     /// The Colors page for the Configure KmPlot constants
0179     SettingsPageColor *m_colorSettings;
0180     /// The Fonts page for the Configure KmPlot constants
0181     SettingsPageFonts *m_fontsSettings;
0182     /// The diagram config page
0183     SettingsPageDiagram *m_diagramSettings;
0184 
0185     /// A dialog used by many tools-menu-items
0186     FunctionTools *m_functionTools;
0187     /// The calculator dialog
0188     Calculator *m_calculator;
0189     /// the popup menu shown when cling with the right mouse button on a graph in the graph widget
0190     QMenu *m_popupmenu;
0191     /// the popup that shows when clicking on the new plot button in the function editor
0192     QMenu *m_newPlotMenu;
0193     /// Loads and saves the user's file.
0194     KmPlotIO *kmplotio;
0195     /// Set to true if the application is readonly
0196     bool m_readonly;
0197     /// MainDlg's parent widget
0198     QWidget *m_parent;
0199     /// Current file
0200     QUrl m_currentfile;
0201     /// The axes config dialogs
0202     CoordsConfigDialog *m_coordsDialog;
0203     /// The constants editor
0204     QPointer<KConstantEditor> m_constantEditor;
0205     /// The function editor
0206     FunctionEditor *m_functionEditor;
0207     /// The undo stack
0208     QStack<QDomDocument> m_undoStack;
0209     /// The reod stack
0210     QStack<QDomDocument> m_redoStack;
0211     /**
0212      * The current document state - this is pushed to the undo stack when a new
0213      * document state is created.
0214      */
0215     QDomDocument m_currentState;
0216     /// Timer to ensure saveCurrentState() is called only once for a set of simultaneous changes
0217     QTimer *m_saveCurrentStateTimer;
0218     /// The undo action
0219     QAction *m_undoAction;
0220     /// The redo action
0221     QAction *m_redoAction;
0222 
0223     /// A pointer to ourselves
0224     static MainDlg *m_self;
0225 
0226     /// Root value for copying into clipboard
0227     double m_rootValue;
0228 
0229 protected slots:
0230     /**
0231      * When you click on a File->Open Recent file, it'll open
0232      * @param url name of the url to open
0233      */
0234     void slotOpenRecent(const QUrl &url);
0235     /// @see requestSaveCurrentState
0236     void saveCurrentState();
0237     /// Used when opening a new file
0238     void resetUndoRedo();
0239 
0240     void setReadOnlyStatusBarText(const QString &);
0241 };
0242 
0243 #if QT_VERSION_MAJOR == 5
0244 class BrowserExtension : public KParts::BrowserExtension
0245 #else
0246 class BrowserExtension : public KParts::NavigationExtension
0247 #endif
0248 {
0249     Q_OBJECT
0250 public:
0251     explicit BrowserExtension(MainDlg *);
0252 
0253 public slots:
0254     // Automatically detected by the host.
0255     void print();
0256 };
0257 
0258 #endif // MainDlg_included