1 /*
2     KmPlot - a math. function plotter for the KDE-Desktop
3 
4     SPDX-FileCopyrightText: 1998, 1999, 2000, 2002 Klaus-Dieter Möller <kd.moeller@t-online.de>
5     SPDX-FileCopyrightText: 2006 David Saxton <david@bluehaze.org>
6 
7     This file is part of the KDE Project.
8     KmPlot is part of the KDE-EDU Project.
9 
10     SPDX-License-Identifier: GPL-2.0-or-later
11 */
12 
13 /** @file maindlg.h
14  * @brief Contains the main window class MainDlg. */
15 
16 #ifndef MainDlg_included
17 #define MainDlg_included
18 
19 // Qt includes
20 #include <QDomDocument>
21 #include <QMenu>
22 #include <QPrinter>
23 #include <QStack>
24 #include <QStandardPaths>
25 
26 // KDE includes
27 #include <KSharedConfig>
28 #include <KParts/BrowserExtension>
29 #include <KParts/Part>
30 #include <KParts/ReadWritePart>
31 #include <KPluginFactory>
32 
33 #undef  GrayScale
34 
35 // local includes
36 #include "coordsconfigdialog.h"
37 #include "view.h"
38 #include "kmplotio.h"
39 #include "kprinterdlg.h"
40 
41 class BrowserExtension;
42 class Calculator;
43 class FunctionEditor;
44 class FunctionTools;
45 class KConfigDialog;
46 class KConstantEditor;
47 class QAction;
48 class KRecentFilesAction;
49 class QTimer;
50 
51 
52 class SettingsPageColor;
53 class SettingsPageFonts;
54 class SettingsPageGeneral;
55 class SettingsPageDiagram;
56 
57 /**
58  * @short This is the main window of KmPlot.
59  */
60 class MainDlg : public KParts::ReadWritePart
61 {
62 	Q_OBJECT
63 
64 	public:
65 		/** Constructor.
66 		 * @param parentWidget parent widget for this part
67 		 * @param parent parent object
68 		 */
69 		MainDlg(QWidget *parentWidget, QObject *parent, const QVariantList& = QVariantList() );
70 
71 		/// Initialized as a pointer to this MainDlg object on creation
self()72 		static MainDlg * self() { return m_self; }
73 
74 	/// Cleaning up a bit.
75 	virtual ~MainDlg();
76 
77 	/// Is set to true if a file from an old file format was loaded
78 	static bool oldfileversion;
79 
80 	/// The function editor
functionEditor()81 	FunctionEditor * functionEditor() const { return m_functionEditor; }
82 
83 	/// The coords config dialog
84 	CoordsConfigDialog* coordsDialog();
85 
86 	/// Returns true if any changes are done
isModified()87 	bool isModified(){return m_modified;}
88 
89 	bool queryClose() Q_DECL_OVERRIDE;
90 
91 	/// For inserting the title in the function popup menu
92 	QAction * m_firstFunctionAction;
93 
94 	/// Show the constants editor modal to a parent dialog
95 	void editConstantsModal(QWidget *parent);
96 
97 	/// Check whether the url links to an existing file
98 	static bool fileExists(const QUrl &url);
99 
100 
101 public Q_SLOTS:
102     // DBus interface
103     /// Asks the user and returns true if modified data shall be discarded.
104     Q_SCRIPTABLE bool checkModified();
105 
106 
107 public slots:
108 	/// Implement the coordinate system edit dialog
109 	void editAxes();
110 	/// Show the constants editor
111 	void editConstants();
112 	/// Toggle whether the sliders window is shown
113 	void toggleShowSliders();
114 	/// Revert to the previous document state (in m_undoStack).
115 	void undo();
116 	/// Revert to the next document state (in m_redoStack).
117 	void redo();
118 	/// Pushes the previous document state to the undo stack and records the current one
119 	void requestSaveCurrentState();
120 
121 	///Save a plot i.e. save the function name and all the settings for the plot
122 	void slotSave();
123 	///Save a plot and choose a name for it
124 	void slotSaveas();
125 	///Print the current plot
126 	void slotPrint();
127 	/// For calling print preview functionality
128 	void slotPrintPreview();
129 	///Export the current plot as a png, svg or bmp picture
130 	void slotExport();
131 	///Implement the Configure KmPlot dialog
132 	void slotSettings();
133 	/// Calls the common function names dialog.
134 	void slotNames();
135 	/// Resets the view
136 	void slotResetView();
137 	/// Tools menu
138 	void calculator();
139 	void findMinimumValue();
140 	void findMaximumValue();
141 	void graphArea();
142 
143 private:
144 	/// Settings the standard and non standard actions of the application.
145 	void setupActions();
146 	/// Sets the printer options and draw the plot with the current options.
147 	void setupPrinter(KPrinterDlg *printDialog, QPrinter *printer);
148 	/// Called when a file is opened. The filename is m_url
149 	bool openFile() Q_DECL_OVERRIDE;
150 
151 	/// Called when a file is saved. The filename is m_url
152 	bool saveFile() Q_DECL_OVERRIDE;
153 
154 	///The Recent Files action
155 	KRecentFilesAction * m_recentFiles;
156 	/// true == modifications not saved
157 	bool m_modified;
158 	///An instance of the application config file
159 	KSharedConfigPtr m_config;
160 	///A Configure KmPlot dialog instance
161 	KConfigDialog* m_settingsDialog;
162 	///The General page for the Configure KmPlot dialog
163 	SettingsPageGeneral * m_generalSettings;
164 	///The Colors page for the Configure KmPlot constants
165 	SettingsPageColor * m_colorSettings;
166 	///The Fonts page for the Configure KmPlot constants
167 	SettingsPageFonts * m_fontsSettings;
168 	/// The diagram config page
169 	SettingsPageDiagram* m_diagramSettings;
170 
171 	/// A dialog used by many tools-menu-items
172 	FunctionTools *m_functionTools;
173 	/// The calculator dialog
174 	Calculator *m_calculator;
175 	/// the popup menu shown when cling with the right mouse button on a graph in the graph widget
176 	QMenu *m_popupmenu;
177 	/// the popup that shows when clicking on the new plot button in the function editor
178 	QMenu * m_newPlotMenu;
179 	/// Loads and saves the user's file.
180 	KmPlotIO *kmplotio;
181 	/// Set to true if the application is readonly
182 	bool m_readonly;
183 	/// MainDlg's parent widget
184 	QWidget *m_parent;
185 	/// Current file
186 	QUrl m_currentfile;
187 	/// The axes config dialogs
188 	CoordsConfigDialog* m_coordsDialog;
189 	/// The constants editor
190 	QPointer<KConstantEditor> m_constantEditor;
191 	/// The function editor
192 	FunctionEditor * m_functionEditor;
193 	/// The undo stack
194 	QStack<QDomDocument> m_undoStack;
195 	/// The reod stack
196 	QStack<QDomDocument> m_redoStack;
197 	/**
198 	 * The current document state - this is pushed to the undo stack when a new
199 	 * document state is created.
200 	 */
201 	QDomDocument m_currentState;
202 	/// Timer to ensure saveCurrentState() is called only once for a set of simultaneous changes
203 	QTimer * m_saveCurrentStateTimer;
204 	/// The undo action
205 	QAction * m_undoAction;
206 	/// The redo action
207 	QAction * m_redoAction;
208 
209 	/// A pointer to ourselves
210 	static MainDlg * m_self;
211 
212 	/// Root value for copying into clipboard
213 	double m_rootValue;
214 
215 protected slots:
216 	/**
217 	* When you click on a File->Open Recent file, it'll open
218 	* @param url name of the url to open
219 	*/
220 	void slotOpenRecent( const QUrl &url );
221 	/// @see requestSaveCurrentState
222 	void saveCurrentState();
223 	/// Used when opening a new file
224 	void resetUndoRedo();
225 
226 	void setReadOnlyStatusBarText(const QString &);
227 };
228 
229 class BrowserExtension : public KParts::BrowserExtension
230 {
231 	Q_OBJECT
232 public:
233 	explicit BrowserExtension(MainDlg*);
234 
235 public slots:
236 	// Automatically detected by the host.
237 	void print();
238 };
239 
240 #endif // MainDlg_included
241