]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.h
do what the FIXME suggested
[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, QString 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         void closeEvent(QCloseEvent * e);
63
64 public:
65         /** Check whether we may apply our data.
66          *
67          *  The buttons are disabled if not and (re-)enabled if yes.
68          */
69         void setButtonsValid(bool valid);
70
71         /** \name Dialog Components
72          *  Methods to access the various components making up a dialog.
73          */
74         //@{
75         ButtonController const & bc() const { return bc_; }
76         ButtonController & bc() { return bc_; }
77         //@}
78
79         /// the dialog has changed contents
80         virtual void changed();
81
82         virtual void enableView(bool enable);
83
84         /// default: do nothing
85         virtual void applyView() {}
86         /// default: do nothing
87         virtual void updateContents() {}
88
89 public:
90         /// is the dialog currently valid ?
91         virtual bool isValid() { return true; }
92
93 public:
94
95         /** When applying, it's useful to know whether the dialog is about
96          *  to close or not (no point refreshing the display for example).
97          */
98         bool isClosing() const { return is_closing_; }
99
100         /// Update the display of the dialog whilst it is still visible.
101         virtual void updateView();
102
103 private:
104         ButtonController bc_;
105         /// are we updating ?
106         bool updating_;
107
108         bool is_closing_;
109 };
110
111
112 class GuiCommand : public GuiDialog
113 {
114 public:
115         /// We need to know with what sort of inset we're associated.
116         // FIXME This should probably be an InsetCode
117         GuiCommand(GuiView &, QString const & name, QString const & title);
118         ///
119         bool initialiseParams(std::string const & data);
120         /// clean-up on hide.
121         void clearParams() { params_.clear(); }
122         /// clean-up on hide.
123         void dispatchParams();
124         ///
125         bool isBufferDependent() const { return true; }
126
127 protected:
128         ///
129         InsetCommandParams params_;
130         //FIXME It should be possible to eliminate lfun_name_
131         //now and recover that information from params().insetType().
132         //But let's not do that quite yet.
133         /// Flags what action is taken by Kernel::dispatch()
134         std::string const lfun_name_;
135 };
136
137 } // namespace frontend
138 } // namespace lyx
139
140 #endif // GUIDIALOG_H