]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.cpp
* Dialog.cpp: whitespace
[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 "GuiView.h"
15 #include "qt_helpers.h"
16
17 #include "support/debug.h"
18
19 #include <QCloseEvent>
20 #include <QMainWindow>
21 #include <QSettings>
22 #include <QShowEvent>
23
24 using namespace std;
25
26 namespace lyx {
27 namespace frontend {
28
29 GuiDialog::GuiDialog(GuiView & lv, string const & name)
30         :  QDialog(&lv), Dialog(lv, name), is_closing_(false)
31 {}
32
33
34 void GuiDialog::setViewTitle(docstring const & title)
35 {
36         setWindowTitle("LyX: " + toqstr(title));
37 }
38
39
40 void GuiDialog::setButtonsValid(bool valid)
41 {
42         bc().setValid(valid);
43 }
44
45
46 void GuiDialog::slotApply()
47 {
48         apply();
49         bc().apply();
50 }
51
52
53 void GuiDialog::slotOK()
54 {
55         is_closing_ = true;
56         apply();
57         is_closing_ = false;
58         QDialog::hide();
59         bc().ok();
60 }
61
62
63 void GuiDialog::slotClose()
64 {
65         QDialog::hide();
66         bc().cancel();
67 }
68
69
70 void GuiDialog::slotRestore()
71 {
72         // Tell the controller that a request to refresh the dialog's contents
73         // has been received. It's up to the controller to supply the necessary
74         // info by calling GuiDialog::updateView().
75         updateDialog();
76         bc().restore();
77 }
78
79
80 void GuiDialog::changed()
81 {
82         if (updating_)
83                 return;
84         bc().setValid(isValid());
85 }
86
87
88 void GuiDialog::enableView(bool enable)
89 {
90         bc().setReadOnly(!enable);
91         bc().setValid(enable);
92         Dialog::enableView(enable);
93 }
94
95
96 void GuiDialog::updateView()
97 {
98         setUpdatesEnabled(false);
99
100         bc().setReadOnly(isBufferReadonly());
101         // protect the BC from unwarranted state transitions
102         updating_ = true;
103         updateContents();
104         updating_ = false;
105         // The widgets may not be valid, so refresh the button controller
106         bc().refresh();
107
108         setUpdatesEnabled(true);
109 }
110
111 } // namespace frontend
112 } // namespace lyx
113
114
115 /////////////////////////////////////////////////////////////////////
116 //
117 // Command based dialogs
118 //
119 /////////////////////////////////////////////////////////////////////
120
121 #include "FuncRequest.h"
122 #include "insets/InsetCommand.h"
123
124 using namespace std;
125
126 namespace lyx {
127 namespace frontend {
128
129 GuiCommand::GuiCommand(GuiView & lv, string const & name)
130         : GuiDialog(lv, name), params_(insetCode(name)), lfun_name_(name)
131 {
132 }
133
134
135 bool GuiCommand::initialiseParams(string const & data)
136 {
137         // The name passed with LFUN_INSET_APPLY is also the name
138         // used to identify the mailer.
139         InsetCommandMailer::string2params(lfun_name_, data, params_);
140         return true;
141 }
142
143
144 void GuiCommand::dispatchParams()
145 {
146         if (lfun_name_.empty())
147                 return;
148
149         string const lfun = 
150                 InsetCommandMailer::params2string(lfun_name_, params_);
151         dispatch(FuncRequest(getLfun(), lfun));
152 }
153
154 } // namespace frontend
155 } // namespace lyx
156
157 #include "GuiDialog_moc.cpp"