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