]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiParagraph.cpp
renaming of some methods that hurt the eyes + removal of:
[lyx.git] / src / frontends / qt4 / GuiParagraph.cpp
1 /**
2  * \file GuiParagraph.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author Richard Heck
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiParagraph.h"
15
16 #include "debug.h"
17 #include "frontend_helpers.h"
18 #include "ParagraphParameters.h"
19 #include "qt_helpers.h"
20 #include "Spacing.h"
21
22 #include <QCheckBox>
23 #include <QCloseEvent>
24 #include <QLineEdit>
25 #include <QPushButton>
26
27 using std::string;
28 using std::endl;
29
30 /////////////////////////////////////////////////////////////////////
31 //
32 // GuiParagraphDialog
33 //
34 /////////////////////////////////////////////////////////////////////
35
36
37 #include <boost/current_function.hpp>
38
39 namespace lyx {
40 namespace frontend {
41
42 GuiParagraphDialog::GuiParagraphDialog(GuiParagraph * form)
43         : form_(form)
44 {
45         setupUi(this);
46
47         connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
48         connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
49         connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
50         connect(restorePB, SIGNAL(clicked()), form_, SLOT(slotRestore()));
51         connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
52         connect(alignJustRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
53         connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
54         connect(alignRightRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
55         connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
56         connect(linespacing, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
57         connect(linespacing, SIGNAL(activated(int)),
58                 this, SLOT(enableLinespacingValue(int)));
59         connect(linespacingValue, SIGNAL(textChanged(const QString &)),
60                 this, SLOT(change_adaptor()));
61         connect(indentCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
62         connect(labelWidth, SIGNAL(textChanged(const QString &)),
63                 this, SLOT(change_adaptor()));
64
65         linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
66
67         labelWidth->setWhatsThis( qt_(
68                 "As described in the User Guide, the width of"
69                 " this text determines the width of the label part"
70                 " of each item in environments like List and"
71                 " Description.\n"
72                 "\n"
73                 " Normally, you won't need to set this,"
74                 " since the largest label width of all the"
75                 " items is used."
76         ));
77
78         radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
79         radioMap[LYX_ALIGN_BLOCK]  = alignJustRB;
80         radioMap[LYX_ALIGN_LEFT]   = alignLeftRB;
81         radioMap[LYX_ALIGN_RIGHT]  = alignRightRB;
82         radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
83         
84         labelMap[LYX_ALIGN_LAYOUT] = _("Use Paragraph's Default Alignment");
85         labelMap[LYX_ALIGN_BLOCK]  = _("Justified");
86         labelMap[LYX_ALIGN_LEFT]   = _("Left");
87         labelMap[LYX_ALIGN_RIGHT]  = _("Right");
88         labelMap[LYX_ALIGN_CENTER] = _("Center");
89 }
90
91
92 void GuiParagraphDialog::closeEvent(QCloseEvent * e)
93 {
94         form_->slotWMHide();
95         e->accept();
96 }
97
98
99 void GuiParagraphDialog::change_adaptor()
100 {
101         form_->changed();
102 }
103
104
105 void GuiParagraphDialog::enableLinespacingValue(int)
106 {
107         bool const enable = linespacing->currentIndex() == 4;
108         linespacingValue->setEnabled(enable);
109 }
110
111
112 void GuiParagraphDialog::checkAlignmentRadioButtons() {
113         LyXAlignment const alignPossible = form_->controller().alignPossible();
114
115         QPRadioMap::iterator it = radioMap.begin();
116         for (; it != radioMap.end(); ++it) {
117                 LyXAlignment const align = it->first;
118                 it->second->setEnabled(align & alignPossible);
119         }
120         docstring label = labelMap[LYX_ALIGN_LAYOUT];
121         if (!form_->controller().haveMulitParSelection())
122                 label += (" (" + labelMap[form_->controller().alignDefault()] + ")");
123         alignDefaultRB->setText(toqstr(label));
124 }
125
126
127 void GuiParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
128 {
129         QPRadioMap::const_iterator it = radioMap.begin();
130         for (;it != radioMap.end(); ++it) {
131                 if (align == it->first) {
132                         it->second->blockSignals(true);
133                         it->second->setChecked(true);
134                         it->second->blockSignals(false);
135                         return;
136                 }
137         }
138
139         lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment "
140                 << align << std::endl;
141 }
142
143
144 LyXAlignment GuiParagraphDialog::getAlignmentFromDialog()
145 {
146         LyXAlignment alignment = LYX_ALIGN_NONE;
147         QPRadioMap::const_iterator it = radioMap.begin();
148         for (; it != radioMap.end(); ++it) {
149                 if (it->second->isChecked()) {
150                         alignment = it->first;
151                         break;
152                 }
153         }
154         return alignment;
155 }
156
157
158 /////////////////////////////////////////////////////////////////////
159 //
160 // GuiParagraph
161 //
162 /////////////////////////////////////////////////////////////////////
163
164
165 GuiParagraph::GuiParagraph(GuiDialog & parent)
166         : GuiView<GuiParagraphDialog>(parent, _("Paragraph Settings"))
167 {}
168
169
170 void GuiParagraph::build_dialog()
171 {
172         // the dialog
173         dialog_.reset(new GuiParagraphDialog(this));
174
175         // Manage the ok, apply, restore and cancel/close buttons
176         bc().setOK(dialog_->okPB);
177         bc().setApply(dialog_->applyPB);
178         bc().setCancel(dialog_->closePB);
179         bc().setRestore(dialog_->restorePB);
180 }
181
182
183 void GuiParagraph::applyView()
184 {
185         ParagraphParameters & params = controller().params();
186
187         params.align(dialog_->getAlignmentFromDialog());
188
189         // get spacing
190         Spacing::Space linespacing = Spacing::Default;
191         string other;
192         switch (dialog_->linespacing->currentIndex()) {
193         case 0:
194                 linespacing = Spacing::Default;
195                 break;
196         case 1:
197                 linespacing = Spacing::Single;
198                 break;
199         case 2:
200                 linespacing = Spacing::Onehalf;
201                 break;
202         case 3:
203                 linespacing = Spacing::Double;
204                 break;
205         case 4:
206                 linespacing = Spacing::Other;
207                 other = fromqstr(dialog_->linespacingValue->text());
208                 break;
209         }
210
211         Spacing const spacing(linespacing, other);
212         params.spacing(spacing);
213
214         // label width
215         params.labelWidthString(qstring_to_ucs4(dialog_->labelWidth->text()));
216         // indendation
217         params.noindent(!dialog_->indentCB->isChecked());
218 }
219
220
221 void GuiParagraph::update_contents()
222 {
223         ParagraphParameters const & params = controller().params();
224
225         // label width
226         docstring const & labelwidth = params.labelWidthString();
227         // FIXME We should not compare translated strings
228         if (labelwidth != _("Senseless with this layout!")) {
229                 dialog_->labelwidthGB->setEnabled(true);
230                 dialog_->labelWidth->setText(toqstr(labelwidth));
231         } else {
232                 dialog_->labelwidthGB->setEnabled(false);
233                 dialog_->labelWidth->setText("");
234         }
235
236         // alignment
237         dialog_->checkAlignmentRadioButtons();
238         dialog_->alignmentToRadioButtons(params.align());
239
240         //indentation
241         bool const canindent = controller().canIndent();
242         dialog_->indentCB->setEnabled(canindent);
243         dialog_->indentCB->setChecked(canindent && !params.noindent());
244
245         // linespacing
246         int linespacing;
247         Spacing const & space = params.spacing();
248         switch (space.getSpace()) {
249         case Spacing::Single:
250                 linespacing = 1;
251                 break;
252         case Spacing::Onehalf:
253                 linespacing = 2;
254                 break;
255         case Spacing::Double:
256                 linespacing = 3;
257                 break;
258         case Spacing::Other:
259                 linespacing = 4;
260                 break;
261         default:
262                 linespacing = 0;
263                 break;
264         }
265         dialog_->linespacing->setCurrentIndex(linespacing);
266         if (space.getSpace() == Spacing::Other) {
267                 dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
268                 dialog_->linespacingValue->setEnabled(true);
269         } else {
270                 dialog_->linespacingValue->setText("");
271                 dialog_->linespacingValue->setEnabled(false);
272         }
273 }
274
275 } // namespace frontend
276 } // namespace lyx
277
278 #include "GuiParagraph_moc.cpp"