]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.h
pimpl not needed here
[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
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         /** Defaults to nothing. Can be used by the Controller, however, to
123          *  indicate to the View that something has changed and that the
124          *  dialog therefore needs updating.
125          *  \param id identifies what should be updated.
126          */
127         virtual void partialUpdateView(int /*id*/) {}
128
129         ///
130         std::string name() const { return name_; }
131
132         void apply();
133         void redrawView() {}
134
135         /// Update the display of the dialog whilst it is still visible.
136         virtual void updateView();
137
138 private:
139         ButtonController bc_;
140         /// are we updating ?
141         bool updating_;
142
143         bool is_closing_;
144         /** The Dialog's name is the means by which a dialog identifies
145          *  itself to the kernel.
146          */
147         std::string name_;
148 };
149
150
151 class GuiCommand : public GuiDialog
152 {
153 public:
154         /// We need to know with what sort of inset we're associated.
155         // FIXME This should probably be an InsetCode
156         GuiCommand(LyXView &, std::string const & name);
157         ///
158         bool initialiseParams(std::string const & data);
159         /// clean-up on hide.
160         void clearParams() { params_.clear(); }
161         /// clean-up on hide.
162         void dispatchParams();
163         ///
164         bool isBufferDependent() const { return true; }
165
166 protected:
167         ///
168         InsetCommandParams params_;
169         //FIXME It should be possible to eliminate lfun_name_
170         //now and recover that information from params().insetType().
171         //But let's not do that quite yet.
172         /// Flags what action is taken by Kernel::dispatch()
173         std::string const lfun_name_;
174 };
175
176 } // namespace frontend
177 } // namespace lyx
178
179 #endif // GUIDIALOG_H