]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.h
QDialogButtonBox for the remaining dialogs.
[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 <QAbstractButton>
19 #include <QDialog>
20
21
22 namespace lyx {
23 namespace frontend {
24
25 /// Base class for historical LyX dialogs.
26 /**
27   * \warning New dialogs should use the leaner classes \c DialogView or
28   * \c DockView depending on the intent. Eventually, old dialogs should be
29   * converted to \c DialogView too.
30   */
31 class GuiDialog : public QDialog, public Dialog
32 {
33         Q_OBJECT
34
35 public:
36         /// \param lv is the access point for the dialog to the LyX kernel.
37         /// \param name is the identifier given to the dialog by its parent
38         /// container.
39         /// \param title is the window title used for decoration.
40         GuiDialog(GuiView & lv, QString const & name, QString const & title);
41
42         virtual QWidget * asQWidget() { return this; }
43         virtual QWidget const * asQWidget() const { return this; }
44
45 public Q_SLOTS:
46         /** \name Buttons
47          *  These methods are publicly accessible because they are invoked
48          *  by the View when the user presses... guess what ;-)
49          */
50         // Restore button clicked
51         void slotRestore();
52         // OK button clicked
53         void slotOK();
54         // Apply button clicked
55         void slotApply();
56         // AutoApply checkbox clicked
57         void slotAutoApply();
58         // Close button clicked or closed from WindowManager
59         void slotClose();
60         // A collectiong slot for QDialogButtonBox
61         void slotButtonBox(QAbstractButton *);
62         ///
63         void closeEvent(QCloseEvent * e);
64
65 protected Q_SLOTS:
66         void onBufferViewChanged() {};//override
67
68 public:
69         /** Check whether we may apply our data.
70          *
71          *  The buttons are disabled if not and (re-)enabled if yes.
72          */
73         void setButtonsValid(bool valid);
74
75         /** \name Dialog Components
76          *  Methods to access the various components making up a dialog.
77          */
78         //@{
79         ButtonController const & bc() const { return bc_; }
80         ButtonController & bc() { return bc_; }
81         //@}
82
83         /// the dialog has changed contents
84         virtual void changed();
85
86         virtual void enableView(bool enable);
87
88         /// default: do nothing
89         virtual void applyView() {}
90         /// default: do nothing
91         virtual void updateContents() {}
92
93 public:
94         /// is the dialog currently valid ?
95         virtual bool isValid() { return true; }
96
97 public:
98
99         /** When applying, it's useful to know whether the dialog is about
100          *  to close or not (no point refreshing the display for example).
101          */
102         bool isClosing() const { return is_closing_; }
103
104         ///
105         bool needBufferOpen() const { return isBufferDependent(); }
106
107         /// Update the display of the dialog whilst it is still visible.
108         virtual void updateView();
109
110 private:
111         ButtonController bc_;
112         /// are we updating ?
113         bool updating_;
114
115         bool is_closing_;
116 };
117
118
119 } // namespace frontend
120 } // namespace lyx
121
122 #endif // GUIDIALOG_H