]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/Dialog.h
Update sk.po
[lyx.git] / src / frontends / qt / Dialog.h
1 // -*- C++ -*-
2 /**
3  * \file Dialog.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 DIALOG_H
13 #define DIALOG_H
14
15 #include "FuncCode.h"
16
17 #include "insets/InsetCode.h"
18
19 #include "support/strfwd.h"
20
21 #include <QString>
22
23 class QSettings;
24 class QWidget;
25
26 namespace lyx {
27
28 class Buffer;
29 class BufferView;
30 class FuncRequest;
31 class Inset;
32
33 namespace frontend {
34
35 class GuiView;
36
37 /** \enum KernelDocType used to flag the different kinds of buffer
38  *  without making the kernel header files available to the
39  *  dialog's Controller or View.
40  */
41 enum class KernelDocType : int
42 {
43         LaTeX,
44         Literate
45 };
46
47 /** \c Dialog collects the different parts of a Model-Controller-View
48  *  split of a generic dialog together.
49  */
50 class Dialog
51 {
52 public:
53         /// \param lv is the access point for the dialog to the LyX kernel.
54         /// \param name is the identifier given to the dialog by its parent
55         /// container.
56         /// \param title is the window title used for decoration.
57         Dialog(GuiView & lv, QString const & name, QString const & title);
58
59         virtual ~Dialog() {}
60
61         virtual QWidget * asQWidget() = 0;
62         virtual QWidget const * asQWidget() const = 0;
63
64         /// Session key.
65         /**
66          * This key must be used for any session setting.
67          **/
68         QString sessionKey() const;
69
70         /// Save session settings.
71         /**
72          * This default implementation saves the geometry state.
73          * Reimplement to save more settings.
74          **/
75         virtual void saveSession(QSettings & settings) const;
76
77         /// Restore session settings.
78         /**
79          * This default implementation restores the geometry state.
80          * Reimplement to restore more settings.
81          **/
82         virtual void restoreSession();
83
84         /** \name Container Access
85          *  These methods are publicly accessible because they are invoked
86          *  by the parent container acting on commands from the LyX kernel.
87          */
88         //@{
89         /// \param data is a string encoding of the data to be displayed.
90         /// It is passed to the Controller to be translated into a usable form.
91     virtual void showData(std::string const & data)
92     {
93         return showData(data, Qt::PopupFocusReason);
94     }
95
96     /// \param data is a string encoding of the data to be displayed.
97     /// It is passed to the Controller to be translated into a usable form.
98     /// \param reason provides the focus reason of the dialog.
99     /// E.g. dialog "findreplaceadv" requires special treatment after
100     /// obtaining focus in terms of the input method item transformation,
101     /// so should be marked as reason = Qt::OtherFocusReason.
102     virtual void showData(std::string const & data, Qt::FocusReason reason);
103         //@}
104
105         /// \return inset at current cursor location.
106         Inset const * inset(InsetCode code) const;
107
108         /** Check whether we may apply our data.
109          *
110          *  The buttons are disabled if not and (re-)enabled if yes.
111          */
112         virtual void checkStatus();
113
114         /** When applying, it's useful to know whether the dialog is about
115          *  to close or not (no point refreshing the display for example).
116          */
117         virtual bool isClosing() const { return false; }
118
119         /** \c View part
120          *  of a Model-Controller-View split of a generic dialog.
121          *  These few methods are all that a generic dialog needs of a
122          *  view.
123          */
124         //@{
125         /** A request to modify the data structures stored by the
126          *  accompanying Controller in preparation for their dispatch to
127          *  the LyX kernel.
128          */
129         virtual void applyView() = 0;
130
131         /// Hide the dialog from sight
132         void hideView();
133
134         /// Prepare dialog and display it.
135     void showView() { return showView(Qt::PopupFocusReason); }
136
137     /// Prepare dialog and display it.
138     /// \param reason provides the focus reason of the dialog.
139     /// E.g. dialog "findreplaceadv" requires special treatment after
140     /// obtaining focus in terms of the input method item transformation,
141     /// so should be marked as reason = Qt::OtherFocusReason.
142     void showView(Qt::FocusReason reason);
143
144         /// Prepare dialog before view.
145         void prepareView();
146
147         /// Decide whether the dialog should grab thekeyboard focus when shown.
148         /// This method defaults to true, override if a different behaviour
149         /// is wanted.
150         virtual bool wantInitialFocus() const { return true; }
151
152         /// Update the display of the dialog whilst it is still visible.
153         virtual void updateView() = 0;
154
155         // Default Implementation does nothing.
156         // Each dialog has to choose what control to enable or disable.
157         virtual void enableView(bool /*enable*/) {}
158
159         /// \return true if the dialog is visible.
160         virtual bool isVisibleView() const;
161         //@}
162
163         /// Dialog identifier.
164         QString name() const { return name_; }
165
166         //@{
167         /** Enable the controller to initialise its data structures.
168          *  \param data is a string encoding of the parameters to be displayed.
169          *  \return true if the translation was successful.
170          */
171         virtual bool initialiseParams(std::string const & data) = 0;
172
173         /// Enable the controller to clean up its data structures.
174         virtual void clearParams() = 0;
175
176         /// Enable the Controller to dispatch its data back to the LyX kernel.
177         virtual void dispatchParams() = 0;
178
179         /** \return true if the dialog should be updated when the
180          *  buffer has changed.
181          */
182         virtual bool isBufferDependent() const = 0;
183
184         /** \return true if the dialog should be shown only when
185          *  a buffer is open.
186          */
187         virtual bool needBufferOpen() const = 0;
188
189         /** \return true if the dialog can apply data also
190          *  for ReadOnly buffers.
191          *  This has to be distinguished from isBufferDependent()
192          */
193         virtual bool canApplyToReadOnly() const { return false; }
194
195         /** The lfun that is sent for applying the data.
196          *
197          * This method is used by the default implementation of canApply()
198          * for buffer dependent dialogs that send one lfun when applying the
199          * data.
200          * It should be used in dispatchParams(), too for consistency reasons.
201          *  \returns the lfun that is sent for applying the data.
202          */
203         virtual FuncCode getLfun() const { return LFUN_INSET_APPLY; }
204
205         /** Check whether we may apply our data.
206          *
207          * The default implementation works for all dialogs that send one
208          * lfun when applying the data. Dialogs that send none or more than
209          * one lfun need to reimplement it.
210          *  \returns whether the data can be applied or not.
211          */
212         virtual bool canApply() const;
213
214         /** \return true if the kernel should disconnect the dialog from
215          *  a particular inset after the data has been applied to it.
216          *  Clearly this makes sense only for dialogs modifying the contents
217          *  of an inset :-)
218          *  In practise, only a very few dialogs (e.g. the citation dialog)
219          *  return true.
220          */
221         virtual bool disconnectOnApply() const { return false; }
222
223         //@}
224
225         /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
226          * (Ie, it provides an interface to the Model part of the Model-Controller-
227          *  View split.
228          *  In an ideal world, it will shrink as more info is passed to the
229          *  Dialog::show() and Dialog::update() methods.
230          */
231
232
233         /** This method is the primary purpose of the class. It provides
234          *  the "gateway" by which the dialog can send a request (of a
235          *  change in the data, for more information) to the kernel.
236          *  \param fr is the encoding of the request.
237          */
238         void dispatch(FuncRequest const & fr) const;
239
240         /** The dialog has received a request from the user
241          *  (who pressed the "Restore" button) to update contents.
242          *  It must, therefore, ask the kernel to provide this information.
243          *  \param name is used to identify the dialog to the kernel.
244          */
245         void updateDialog() const;
246
247         /** A request from the Controller that future changes to the data
248          *  stored by the dialog are not applied to the inset currently
249          *  connected to the dialog. Instead, they will be used to generate
250          *  a new inset at the cursor position.
251          */
252         void disconnect() const;
253
254         /** \name Kernel Wrappers
255          *  Simple wrapper functions to Buffer methods.
256          */
257         //@{
258         bool isBufferAvailable() const;
259         bool isBufferReadonly() const;
260         QString bufferFilePath() const;
261         //@}
262
263         /// The type of the current buffer.
264         KernelDocType docType() const;
265
266         /** \name Kernel Nasties
267          *  Unpleasantly public internals of the LyX kernel.
268          *  We should aim to reduce/remove these from the interface.
269          */
270         //@{
271         GuiView const & lyxview() const { return lyxview_; }
272         /// Current buffer
273         Buffer const & buffer() const;
274         /// Main document buffer
275         Buffer const & documentBuffer() const;
276         /// Current BufferView
277         BufferView const * bufferview() const;
278         //@}
279
280 protected:
281         ///
282         void setTitle(QString const & title) { title_ = title; }
283         ///
284         virtual void apply();
285         /// To be called when the buffer view has changed
286         virtual void onBufferViewChanged() = 0;
287         ///
288         virtual void onClosing(int) = 0;
289         ///
290         void connectToNewInset();
291
292 private:
293         /** The Dialog's name is the means by which a dialog identifies
294          *  itself to the GuiView.
295          */
296         QString const name_;
297         ///
298         QString title_;
299         ///
300         GuiView & lyxview_;
301
302         /// intentionally unimplemented, therefore uncopiable
303         Dialog(Dialog const &);
304         void operator=(Dialog const &);
305 };
306
307
308 } // namespace frontend
309 } // namespace lyx
310
311 #endif // DIALOG_H