]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.cpp
* fix spelling in comments to please John.
[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
15 #include "GuiView.h"
16 #include "qt_helpers.h"
17 #include "FuncRequest.h"
18
19 #include "support/debug.h"
20
21 #include <QCloseEvent>
22
23 using namespace std;
24
25 namespace lyx {
26 namespace frontend {
27
28 GuiDialog::GuiDialog(GuiView & lv, QString const & name, QString const & title)
29         : QDialog(&lv), Dialog(lv, name, "LyX: " + title), updating_(false), 
30           is_closing_(false)
31 {}
32
33
34 void GuiDialog::closeEvent(QCloseEvent * ev)
35 {
36         slotClose();
37         ev->accept();
38 }
39
40
41 void GuiDialog::setButtonsValid(bool valid)
42 {
43         bc().setValid(valid);
44 }
45
46
47 void GuiDialog::slotApply()
48 {
49         apply();
50         bc().apply();
51 }
52
53
54 void GuiDialog::slotAutoApply()
55 {
56         apply();
57         bc().autoApply();
58 }
59
60
61 void GuiDialog::slotOK()
62 {
63         is_closing_ = true;
64         apply();
65         is_closing_ = false;
66         hideView();
67         bc().ok();
68 }
69
70
71 void GuiDialog::slotClose()
72 {
73         hideView();
74         bc().cancel();
75 }
76
77
78 void GuiDialog::slotRestore()
79 {
80         // Tell the controller that a request to refresh the dialog's contents
81         // has been received. It's up to the controller to supply the necessary
82         // info by calling GuiDialog::updateView().
83         updateDialog();
84         bc().restore();
85 }
86
87
88 void GuiDialog::changed()
89 {
90         if (updating_)
91                 return;
92         bc().setValid(isValid());
93 }
94
95
96 void GuiDialog::enableView(bool enable)
97 {
98         if (!enable) {
99                 bc().setReadOnly(true);
100                 bc().setValid(false);
101         }
102         Dialog::enableView(enable);
103 }
104
105
106 void GuiDialog::updateView()
107 {
108         setUpdatesEnabled(false);
109
110         bc().setReadOnly(isBufferReadonly());
111         // protect the BC from unwarranted state transitions
112         updating_ = true;
113         updateContents();
114         updating_ = false;
115         // The widgets may not be valid, so refresh the button controller
116         bc().refresh();
117
118         setUpdatesEnabled(true);
119 }
120
121 } // namespace frontend
122 } // namespace lyx
123
124 #include "moc_GuiDialog.cpp"