]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.h
GuiWrap.cpp: disconnect the widgets that are by default disabled from readonly
[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         /** Check whether we may apply our data.
54          *
55          *  The buttons are disabled if not and (re-)enabled if yes.
56          */
57         void checkStatus();
58         void setButtonsValid(bool valid);
59
60         /** \name Dialog Components
61          *  Methods to access the various components making up a dialog.
62          */
63         //@{
64         ButtonController const & bc() const { return bc_; }
65         ButtonController & bc() { return bc_; }
66         //@}
67
68         void setViewTitle(docstring const & title);
69
70
71         /// the dialog has changed contents
72         virtual void changed();
73
74         /// default: do nothing
75         virtual void applyView() {}
76         /// default: do nothing
77         virtual void updateContents() {}
78
79 protected:
80         /// Hide the dialog.
81         virtual void hideView();
82         /// Create the dialog if necessary, update it and display it.
83         virtual void showView();
84         ///
85         virtual bool isVisibleView() const;
86         /// is the dialog currently valid ?
87         virtual bool isValid() { return true; }
88
89 public:
90         /** \name Container Access
91          *  These methods are publicly accessible because they are invoked
92          *  by the parent container acting on commands from the LyX kernel.
93          */
94         //@{
95         /// \param data is a string encoding of the data to be displayed.
96         /// It is passed to the Controller to be translated into a useable form.
97         void showData(std::string const & data);
98         void updateData(std::string const & data);
99
100         void hide();
101
102         /** This function is called, for example, if the GUI colours
103          *  have been changed.
104          */
105         void redraw() { redrawView(); }
106         //@}
107
108         /** When applying, it's useful to know whether the dialog is about
109          *  to close or not (no point refreshing the display for example).
110          */
111         bool isClosing() const { return is_closing_; }
112
113         /** \name Dialog Specialization
114          *  Methods to set the Controller and View and so specialise
115          *  to a particular dialog.
116          */
117         //@{
118         /// \param ptr is stored and destroyed by \c Dialog.
119         void setController(Controller * ptr);
120         //@}
121
122         /** \name Dialog Components
123          *  Methods to access the various components making up a dialog.
124          */
125         //@{
126         virtual Controller & controller() { return *controller_; }
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         Controller * controller_;
156         LyXView * lyxview_; // FIXME: replace by moving to constructor
157 };
158
159 } // namespace frontend
160 } // namespace lyx
161
162 #endif // GUIDIALOG_H