]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.h
move Controller inheritance further up the tree
[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 #include <QObject>
22
23 class QCloseEvent;
24 class QShowEvent;
25
26 namespace lyx {
27 namespace frontend {
28
29 /** \c Dialog collects the different parts of a Model-Controller-View
30  *  split of a generic dialog together.
31  */
32 class GuiDialog : public QDialog, public Dialog, public Controller
33 {
34         Q_OBJECT
35
36 public:
37         /// \param lv is the access point for the dialog to the LyX kernel.
38         /// \param name is the identifier given to the dialog by its parent
39         /// container.
40         explicit GuiDialog(LyXView & lv, std::string const & name);
41         ~GuiDialog();
42
43 public Q_SLOTS:
44         /** \name Buttons
45          *  These methods are publicly accessible because they are invoked
46          *  by the View when the user presses... guess what ;-)
47          */
48         // Restore button clicked
49         void slotRestore();
50         // OK button clicked
51         void slotOK();
52         // Apply button clicked
53         void slotApply();
54         // Close button clicked or closed from WindowManager
55         void slotClose();
56
57 public:
58         /** Check whether we may apply our data.
59          *
60          *  The buttons are disabled if not and (re-)enabled if yes.
61          */
62         void checkStatus();
63         void setButtonsValid(bool valid);
64
65         /** \name Dialog Components
66          *  Methods to access the various components making up a dialog.
67          */
68         //@{
69         ButtonController const & bc() const { return bc_; }
70         ButtonController & bc() { return bc_; }
71         //@}
72
73         void setViewTitle(docstring const & title);
74
75
76         /// the dialog has changed contents
77         virtual void changed();
78
79         /// default: do nothing
80         virtual void applyView() {}
81         /// default: do nothing
82         virtual void updateContents() {}
83         ///
84         void closeEvent(QCloseEvent *);
85         ///
86         void showEvent(QShowEvent *);
87
88 protected:
89         /// Hide the dialog.
90         virtual void hideView();
91         /// Create the dialog if necessary, update it and display it.
92         virtual void showView();
93         ///
94         virtual bool isVisibleView() const;
95         /// is the dialog currently valid ?
96         virtual bool isValid() { return true; }
97
98 public:
99         /** \name Container Access
100          *  These methods are publicly accessible because they are invoked
101          *  by the parent container acting on commands from the LyX kernel.
102          */
103         //@{
104         /// \param data is a string encoding of the data to be displayed.
105         /// It is passed to the Controller to be translated into a useable form.
106         void showData(std::string const & data);
107         void updateData(std::string const & data);
108
109         void hide();
110
111         /** This function is called, for example, if the GUI colours
112          *  have been changed.
113          */
114         void redraw() { redrawView(); }
115         //@}
116
117         /** When applying, it's useful to know whether the dialog is about
118          *  to close or not (no point refreshing the display for example).
119          */
120         bool isClosing() const { return is_closing_; }
121
122         /** \name Dialog Components
123          *  Methods to access the various components making up a dialog.
124          */
125         //@{
126         virtual Controller & controller() { return *this; }
127         //@}
128
129         /** Defaults to nothing. Can be used by the Controller, however, to
130          *  indicate to the View that something has changed and that the
131          *  dialog therefore needs updating.
132          *  \param id identifies what should be updated.
133          */
134         virtual void partialUpdateView(int /*id*/) {}
135
136         ///
137         std::string name() const { return name_; }
138
139         void apply();
140         void redrawView() {}
141
142 private:
143         /// Update the display of the dialog whilst it is still visible.
144         virtual void updateView();
145
146         ButtonController bc_;
147         /// are we updating ?
148         bool updating_;
149
150         bool is_closing_;
151         /** The Dialog's name is the means by which a dialog identifies
152          *  itself to the kernel.
153          */
154         std::string name_;
155 };
156
157
158 class GuiCommand : public GuiDialog
159 {
160 public:
161         /// We need to know with what sort of inset we're associated.
162         GuiCommand(LyXView &, std::string const & name);
163         ///
164         bool initialiseParams(std::string const & data);
165         /// clean-up on hide.
166         void clearParams() { params_.clear(); }
167         /// clean-up on hide.
168         void dispatchParams();
169         ///
170         bool isBufferDependent() const { return true; }
171
172 protected:
173         ///
174         InsetCommandParams params_;
175         //FIXME It should be possible to eliminate lfun_name_
176         //now and recover that information from params().insetType().
177         //But let's not do that quite yet.
178         /// Flags what action is taken by Kernel::dispatch()
179         std::string const lfun_name_;
180 };
181
182 } // namespace frontend
183 } // namespace lyx
184
185 #endif // GUIDIALOG_H