]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.cpp
0e2dbaaf5cab96ca9c68e9b75c8ecf7b7421d506
[lyx.git] / src / frontends / qt4 / GuiDialog.cpp
1 /**
2  * \file Dialog.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiDialog.h"
14 #include "debug.h"
15 #include "qt_helpers.h"
16
17 namespace lyx {
18 namespace frontend {
19
20 GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
21         : Dialog(lv, name)
22 {}
23
24
25 void GuiDialog::setViewTitle(docstring const & title)
26 {
27         setWindowTitle("LyX: " + toqstr(title));
28 }
29
30
31 void GuiDialog::setButtonsValid(bool valid)
32 {
33         bc().setValid(valid);
34 }
35
36
37 void GuiDialog::ApplyButton()
38 {
39         apply();
40         bc().apply();
41 }
42
43
44 void GuiDialog::OKButton()
45 {
46         is_closing_ = true;
47         apply();
48         is_closing_ = false;
49         QDialog::hide();
50         bc().ok();
51 }
52
53
54 void GuiDialog::CancelButton()
55 {
56         QDialog::hide();
57         bc().cancel();
58 }
59
60
61 void GuiDialog::RestoreButton()
62 {
63         // Tell the kernel that a request to refresh the dialog's contents
64         // has been received. It's up to the kernel to supply the necessary
65         // info by calling GuiDialog::updateView().
66         kernel().updateDialog(name_);
67         bc().restore();
68 }
69
70
71 void GuiDialog::preShow()
72 {
73         bc().setReadOnly(kernel().isBufferReadonly());
74 }
75
76
77 void GuiDialog::postShow()
78 {
79         // The widgets may not be valid, so refresh the button controller
80         bc().refresh();
81 }
82
83
84 void GuiDialog::preUpdate()
85 {
86         bc().setReadOnly(kernel().isBufferReadonly());
87 }
88
89
90 void GuiDialog::postUpdate()
91 {
92         // The widgets may not be valid, so refresh the button controller
93         bc().refresh();
94 }
95
96
97 void GuiDialog::checkStatus()
98 {
99         // buffer independant dialogs are always active.
100         // This check allows us leave canApply unimplemented for some dialogs.
101         if (!controller().isBufferDependent())
102                 return;
103
104         // deactivate the dialog if we have no buffer
105         if (!kernel().isBufferAvailable()) {
106                 bc().setReadOnly(true);
107                 return;
108         }
109
110         // check whether this dialog may be active
111         if (controller().canApply()) {
112                 bool const readonly = kernel().isBufferReadonly();
113                 bc().setReadOnly(readonly);
114                 // refreshReadOnly() is too generous in _enabling_ widgets
115                 // update dialog to disable disabled widgets again
116 /*
117  *      FIXME:
118                 if (!readonly || controller().canApplyToReadOnly())
119                         update();
120 */
121         } else {
122                 bc().setReadOnly(true);
123         }       
124 }
125
126
127 bool GuiDialog::isVisibleView() const
128 {
129         return QDialog::isVisible();
130 }
131
132
133 bool GuiDialog::readOnly() const
134 {
135         return kernel().isBufferReadonly();
136 }
137
138
139 void GuiDialog::showView()
140 {
141         QSize const hint = sizeHint();
142         if (hint.height() >= 0 && hint.width() >= 0)
143                 setMinimumSize(hint);
144
145         updateView();  // make sure its up-to-date
146         if (controller().exitEarly())
147                 return;
148
149         if (QWidget::isVisible()) {
150                 raise();
151                 activateWindow();
152         } else {
153                 QWidget::show();
154         }
155         setFocus();
156 }
157
158
159 void GuiDialog::hideView()
160 {
161         QDialog::hide();
162 }
163
164
165 bool GuiDialog::isValid()
166 {
167         return true;
168 }
169
170
171 void GuiDialog::changed()
172 {
173         if (updating_)
174                 return;
175         bc().setValid(isValid());
176 }
177
178
179 void GuiDialog::slotWMHide()
180 {
181         CancelButton();
182 }
183
184
185 void GuiDialog::slotApply()
186 {
187         ApplyButton();
188 }
189
190
191 void GuiDialog::slotOK()
192 {
193         OKButton();
194 }
195
196
197 void GuiDialog::slotClose()
198 {
199         CancelButton();
200 }
201
202
203 void GuiDialog::slotRestore()
204 {
205         RestoreButton();
206 }
207
208 void GuiDialog::updateView()
209 {
210         setUpdatesEnabled(false);
211
212         // protect the BC from unwarranted state transitions
213         updating_ = true;
214         update_contents();
215         updating_ = false;
216
217         setUpdatesEnabled(true);
218         QDialog::update();
219 }
220
221 } // namespace frontend
222 } // namespace lyx
223
224 #include "GuiDialog_moc.cpp"