]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.cpp
Start using QDialogButtonGroup rather than manual OK etc. buttons
[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
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, "LyX: " + title), updating_(false),
30           is_closing_(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         apply();
56         bc().apply();
57 }
58
59
60 void GuiDialog::slotAutoApply()
61 {
62         apply();
63         bc().autoApply();
64 }
65
66
67 void GuiDialog::slotOK()
68 {
69         is_closing_ = true;
70         apply();
71         is_closing_ = false;
72         hideView();
73         bc().ok();
74 }
75
76
77 void GuiDialog::slotClose()
78 {
79         hideView();
80         bc().cancel();
81 }
82
83
84 void GuiDialog::slotRestore()
85 {
86         // Tell the controller that a request to refresh the dialog's contents
87         // has been received. It's up to the controller to supply the necessary
88         // info by calling GuiDialog::updateView().
89         updateDialog();
90         bc().restore();
91 }
92
93
94 void GuiDialog::slotButtonBox(QAbstractButton * button)
95 {
96         QDialogButtonBox * bbox = qobject_cast<QDialogButtonBox*>(sender());
97         switch (bbox->standardButton(button)) {
98         case QDialogButtonBox::Ok:
99                 slotOK();
100                 break;
101         case QDialogButtonBox::Apply:
102                 slotApply();
103                 break;
104         case QDialogButtonBox::Cancel:
105                 slotClose();
106                 break;
107         case QDialogButtonBox::Reset:
108         case QDialogButtonBox::RestoreDefaults:
109                 slotRestore();
110                 break;
111         default:
112                 break;
113         }
114 }
115
116
117 void GuiDialog::changed()
118 {
119         if (updating_)
120                 return;
121         bc().setValid(isValid());
122 }
123
124
125 void GuiDialog::enableView(bool enable)
126 {
127         if (!enable) {
128                 bc().setReadOnly(true);
129                 bc().setValid(false);
130         }
131         Dialog::enableView(enable);
132 }
133
134
135 void GuiDialog::updateView()
136 {
137         setUpdatesEnabled(false);
138
139         bc().setReadOnly(isBufferReadonly());
140         // protect the BC from unwarranted state transitions
141         updating_ = true;
142         updateContents();
143         updating_ = false;
144         // The widgets may not be valid, so refresh the button controller
145         bc().refresh();
146
147         setUpdatesEnabled(true);
148 }
149
150 } // namespace frontend
151 } // namespace lyx
152
153 #include "moc_GuiDialog.cpp"