]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.h
Fix a crash following the input of an invalid paragraph separation value in the docum...
[lyx.git] / src / frontends / qt4 / GuiDialog.h
1 // -*- C++ -*-
2 /**
3  * \file GuiDialog.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GUIDIALOG_H
13 #define GUIDIALOG_H
14
15 #include "Dialog.h"
16 #include "ButtonController.h"
17
18 #include "insets/InsetCommandParams.h"
19
20 #include <QDialog>
21
22 class QCloseEvent;
23 class QShowEvent;
24
25 namespace lyx {
26 namespace frontend {
27
28 /// Base class for historical LyX dialogs.
29 /** 
30   * \warning New dialogs should use the leaner classes \c DialogView or
31   * \c DockView depending on the intent. Eventally, old dialog should be
32   * converted to \c DialogView too.
33   */
34 class GuiDialog : public QDialog, public Dialog
35 {
36         Q_OBJECT
37
38 public:
39         /// \param lv is the access point for the dialog to the LyX kernel.
40         /// \param name is the identifier given to the dialog by its parent
41         /// container.
42         /// \param title is the window title used for decoration.
43         GuiDialog(GuiView & lv, std::string const & name, QString const & title);
44
45         virtual QWidget * asQWidget() { return this; }
46         virtual QWidget const * asQWidget() const { return this; }
47
48 public Q_SLOTS:
49         /** \name Buttons
50          *  These methods are publicly accessible because they are invoked
51          *  by the View when the user presses... guess what ;-)
52          */
53         // Restore button clicked
54         void slotRestore();
55         // OK button clicked
56         void slotOK();
57         // Apply button clicked
58         void slotApply();
59         // Close button clicked or closed from WindowManager
60         void slotClose();
61
62 public:
63         /** Check whether we may apply our data.
64          *
65          *  The buttons are disabled if not and (re-)enabled if yes.
66          */
67         void setButtonsValid(bool valid);
68
69         /** \name Dialog Components
70          *  Methods to access the various components making up a dialog.
71          */
72         //@{
73         ButtonController const & bc() const { return bc_; }
74         ButtonController & bc() { return bc_; }
75         //@}
76
77         /// the dialog has changed contents
78         virtual void changed();
79
80         virtual void enableView(bool enable);
81
82         /// default: do nothing
83         virtual void applyView() {}
84         /// default: do nothing
85         virtual void updateContents() {}
86
87 public:
88         /// is the dialog currently valid ?
89         virtual bool isValid() { return true; }
90
91 public:
92
93         /** When applying, it's useful to know whether the dialog is about
94          *  to close or not (no point refreshing the display for example).
95          */
96         bool isClosing() const { return is_closing_; }
97
98         /// Update the display of the dialog whilst it is still visible.
99         virtual void updateView();
100
101 private:
102         ButtonController bc_;
103         /// are we updating ?
104         bool updating_;
105
106         bool is_closing_;
107 };
108
109
110 class GuiCommand : public GuiDialog
111 {
112 public:
113         /// We need to know with what sort of inset we're associated.
114         // FIXME This should probably be an InsetCode
115         GuiCommand(GuiView &, std::string const & name, QString const & title);
116         ///
117         bool initialiseParams(std::string const & data);
118         /// clean-up on hide.
119         void clearParams() { params_.clear(); }
120         /// clean-up on hide.
121         void dispatchParams();
122         ///
123         bool isBufferDependent() const { return true; }
124
125 protected:
126         ///
127         InsetCommandParams params_;
128         //FIXME It should be possible to eliminate lfun_name_
129         //now and recover that information from params().insetType().
130         //But let's not do that quite yet.
131         /// Flags what action is taken by Kernel::dispatch()
132         std::string const lfun_name_;
133 };
134
135 } // namespace frontend
136 } // namespace lyx
137
138 #endif // GUIDIALOG_H