]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiDialog.cpp
Add accelerators
[lyx.git] / src / frontends / qt / 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
18 #include "support/debug.h"
19
20 #include <QCloseEvent>
21 #include <QDialogButtonBox>
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, title), updating_(false),
30       is_closing_(false), apply_stopped_(false)
31 {
32         connect(&lv, SIGNAL(bufferViewChanged()),
33                 this, SLOT(onBufferViewChanged()));
34
35         // remove question marks from Windows dialogs
36         setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
37 }
38
39
40 void GuiDialog::closeEvent(QCloseEvent * ev)
41 {
42         slotClose();
43         ev->accept();
44 }
45
46
47 void GuiDialog::setButtonsValid(bool valid)
48 {
49         bc().setValid(valid);
50 }
51
52
53 void GuiDialog::slotApply()
54 {
55         setApplyStopped(false);
56         apply();
57         if (applyStopped())
58                 return;
59         bc().apply();
60 }
61
62
63 void GuiDialog::slotAutoApply()
64 {
65         apply();
66         bc().autoApply();
67 }
68
69
70 void GuiDialog::slotOK()
71 {
72         is_closing_ = true;
73         setApplyStopped(false);
74         apply();
75         if (applyStopped())
76                 return;
77         is_closing_ = false;
78         hideView();
79         bc().ok();
80 }
81
82
83 void GuiDialog::slotClose()
84 {
85         hideView();
86         bc().cancel();
87 }
88
89
90 void GuiDialog::slotRestore()
91 {
92         // Tell the controller that a request to refresh the dialog's contents
93         // has been received. It's up to the controller to supply the necessary
94         // info by calling GuiDialog::updateView().
95         updateDialog();
96         bc().restore();
97 }
98
99
100 void GuiDialog::slotButtonBox(QAbstractButton * button)
101 {
102         QDialogButtonBox * bbox = qobject_cast<QDialogButtonBox*>(sender());
103         switch (bbox->standardButton(button)) {
104         case QDialogButtonBox::Ok:
105                 slotOK();
106                 break;
107         case QDialogButtonBox::Apply:
108                 slotApply();
109                 break;
110         case QDialogButtonBox::Cancel:
111         case QDialogButtonBox::Close:
112                 slotClose();
113                 break;
114         case QDialogButtonBox::Reset:
115                 slotRestore();
116                 break;
117         case QDialogButtonBox::RestoreDefaults:
118                 slotRestoreDefaults();
119                 break;
120         default:
121                 break;
122         }
123 }
124
125
126 void GuiDialog::changed()
127 {
128         if (updating_)
129                 return;
130         bc().setValid(isValid());
131 }
132
133
134 void GuiDialog::enableView(bool enable)
135 {
136         if (!enable) {
137                 bc().setReadOnly(true);
138                 bc().setValid(false);
139         }
140         Dialog::enableView(enable);
141 }
142
143
144 void GuiDialog::updateView()
145 {
146         setUpdatesEnabled(false);
147
148         bc().setReadOnly(isBufferReadonly());
149         // protect the BC from unwarranted state transitions
150         updating_ = true;
151         updateContents();
152         updating_ = false;
153         // The widgets may not be valid, so refresh the button controller
154         bc().refresh();
155
156         setUpdatesEnabled(true);
157 }
158
159 } // namespace frontend
160 } // namespace lyx
161
162 #include "moc_GuiDialog.cpp"