]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.h
42e6b47d22bc68f95cc1b2004f47217630355217
[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 <QDialog>
19 #include <QObject>
20
21 namespace lyx {
22 namespace frontend {
23
24 /** \c Dialog collects the different parts of a Model-Controller-View
25  *  split of a generic dialog together.
26  */
27 class GuiDialog : public QDialog, public Dialog
28 {
29         Q_OBJECT
30
31 public:
32         /// \param lv is the access point for the dialog to the LyX kernel.
33         /// \param name is the identifier given to the dialog by its parent
34         /// container.
35         explicit GuiDialog(LyXView & lv, std::string const & name);
36         ~GuiDialog();
37
38 public Q_SLOTS:
39         // dialog closed from WM
40         void slotWMHide();
41         // Restore button clicked
42         void slotRestore();
43         // OK button clicked
44         void slotOK();
45         // Apply button clicked
46         void slotApply();
47         // Close button clicked
48         void slotClose();
49
50 public:
51         /** \name Buttons
52          *  These methods are publicly accessible because they are invoked
53          *  by the View when the user presses... guess what ;-)
54          */
55         //@{
56         void ApplyButton();
57         void OKButton();
58         void CancelButton();
59         void RestoreButton();
60         //@}
61
62         /** Check whether we may apply our data.
63          *
64          *  The buttons are disabled if not and (re-)enabled if yes.
65          */
66         void checkStatus();
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         void setViewTitle(docstring const & title);
78
79         ///
80         bool readOnly() const;
81
82         /// the dialog has changed contents
83         virtual void changed();
84
85         /// default: do nothing
86         virtual void applyView() {}
87         /// default: do nothing
88         virtual void update_contents() {}
89
90 protected:
91         /// Hide the dialog.
92         virtual void hideView();
93         /// Create the dialog if necessary, update it and display it.
94         virtual void showView();
95         ///
96         virtual bool isVisibleView() const;
97         /// is the dialog currently valid ?
98         virtual bool isValid() { return true; }
99
100 public:
101         /** \name Container Access
102          *  These methods are publicly accessible because they are invoked
103          *  by the parent container acting on commands from the LyX kernel.
104          */
105         //@{
106         /// \param data is a string encoding of the data to be displayed.
107         /// It is passed to the Controller to be translated into a useable form.
108         void showData(std::string const & data);
109         void updateData(std::string const & data);
110
111         void hide();
112
113         /** This function is called, for example, if the GUI colours
114          *  have been changed.
115          */
116         void redraw() { redrawView(); }
117         //@}
118
119         /** When applying, it's useful to know whether the dialog is about
120          *  to close or not (no point refreshing the display for example).
121          */
122         bool isClosing() const { return is_closing_; }
123
124         /** \name Dialog Specialization
125          *  Methods to set the Controller and View and so specialise
126          *  to a particular dialog.
127          */
128         //@{
129         /// \param ptr is stored and destroyed by \c Dialog.
130         void setController(Controller * ptr);
131         //@}
132
133         /** \name Dialog Components
134          *  Methods to access the various components making up a dialog.
135          */
136         //@{
137         virtual Controller & controller() const { return *controller_; }
138         //@}
139
140         /** Defaults to nothing. Can be used by the Controller, however, to
141          *  indicate to the View that something has changed and that the
142          *  dialog therefore needs updating.
143          *  \param id identifies what should be updated.
144          */
145         virtual void partialUpdateView(int /*id*/) {}
146
147         ///
148         std::string name() const { return name_; }
149
150         void apply();
151         void redrawView() {}
152
153 private:
154         /// Update the display of the dialog whilst it is still visible.
155         virtual void updateView();
156
157         ButtonController bc_;
158         /// are we updating ?
159         bool updating_;
160
161         bool is_closing_;
162         /** The Dialog's name is the means by which a dialog identifies
163          *  itself to the kernel.
164          */
165         std::string name_;
166         Controller * controller_;
167         LyXView * lyxview_; // FIXME: replace by moving to constructor
168 };
169
170 } // namespace frontend
171 } // namespace lyx
172
173 #endif // GUIDIALOG_H