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