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