]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.h
Transfer some more dialog related code from core to frontend:
[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(GuiView & 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         //@}
112
113         /** When applying, it's useful to know whether the dialog is about
114          *  to close or not (no point refreshing the display for example).
115          */
116         bool isClosing() const { return is_closing_; }
117
118         ///
119         std::string name() const { return name_; }
120
121         void apply();
122
123         /// Update the display of the dialog whilst it is still visible.
124         virtual void updateView();
125
126 private:
127         ButtonController bc_;
128         /// are we updating ?
129         bool updating_;
130
131         bool is_closing_;
132         /** The Dialog's name is the means by which a dialog identifies
133          *  itself to the kernel.
134          */
135         std::string name_;
136 };
137
138
139 class GuiCommand : public GuiDialog
140 {
141 public:
142         /// We need to know with what sort of inset we're associated.
143         // FIXME This should probably be an InsetCode
144         GuiCommand(GuiView &, std::string const & name);
145         ///
146         bool initialiseParams(std::string const & data);
147         /// clean-up on hide.
148         void clearParams() { params_.clear(); }
149         /// clean-up on hide.
150         void dispatchParams();
151         ///
152         bool isBufferDependent() const { return true; }
153
154 protected:
155         ///
156         InsetCommandParams params_;
157         //FIXME It should be possible to eliminate lfun_name_
158         //now and recover that information from params().insetType().
159         //But let's not do that quite yet.
160         /// Flags what action is taken by Kernel::dispatch()
161         std::string const lfun_name_;
162 };
163
164 } // namespace frontend
165 } // namespace lyx
166
167 #endif // GUIDIALOG_H