]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.cpp
QDialogButtonBox for the remaining dialogs.
[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         case QDialogButtonBox::Close:
106                 slotClose();
107                 break;
108         case QDialogButtonBox::Reset:
109         case QDialogButtonBox::RestoreDefaults:
110                 slotRestore();
111                 break;
112         default:
113                 break;
114         }
115 }
116
117
118 void GuiDialog::changed()
119 {
120         if (updating_)
121                 return;
122         bc().setValid(isValid());
123 }
124
125
126 void GuiDialog::enableView(bool enable)
127 {
128         if (!enable) {
129                 bc().setReadOnly(true);
130                 bc().setValid(false);
131         }
132         Dialog::enableView(enable);
133 }
134
135
136 void GuiDialog::updateView()
137 {
138         setUpdatesEnabled(false);
139
140         bc().setReadOnly(isBufferReadonly());
141         // protect the BC from unwarranted state transitions
142         updating_ = true;
143         updateContents();
144         updating_ = false;
145         // The widgets may not be valid, so refresh the button controller
146         bc().refresh();
147
148         setUpdatesEnabled(true);
149 }
150
151 } // namespace frontend
152 } // namespace lyx
153
154 #include "moc_GuiDialog.cpp"