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