2 * \file GuiParagraph.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "GuiParagraph.h"
17 #include "frontend_helpers.h"
18 #include "ParagraphParameters.h"
19 #include "qt_helpers.h"
23 #include <QCloseEvent>
25 #include <QPushButton>
30 /////////////////////////////////////////////////////////////////////
34 /////////////////////////////////////////////////////////////////////
37 #include <boost/current_function.hpp>
42 GuiParagraphDialog::GuiParagraphDialog(GuiParagraph * form)
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()));
65 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
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"
73 " Normally, you won't need to set this,"
74 " since the largest label width of all the"
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;
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");
92 void GuiParagraphDialog::closeEvent(QCloseEvent * e)
99 void GuiParagraphDialog::change_adaptor()
105 void GuiParagraphDialog::enableLinespacingValue(int)
107 bool const enable = linespacing->currentIndex() == 4;
108 linespacingValue->setEnabled(enable);
112 void GuiParagraphDialog::checkAlignmentRadioButtons() {
113 LyXAlignment const alignPossible = form_->controller().alignPossible();
115 QPRadioMap::iterator it = radioMap.begin();
116 for (; it != radioMap.end(); ++it) {
117 LyXAlignment const align = it->first;
118 it->second->setEnabled(align & alignPossible);
120 docstring label = labelMap[LYX_ALIGN_LAYOUT];
121 if (!form_->controller().haveMulitParSelection())
122 label += (" (" + labelMap[form_->controller().alignDefault()] + ")");
123 alignDefaultRB->setText(toqstr(label));
127 void GuiParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
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);
139 lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment "
140 << align << std::endl;
144 LyXAlignment GuiParagraphDialog::getAlignmentFromDialog()
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;
158 /////////////////////////////////////////////////////////////////////
162 /////////////////////////////////////////////////////////////////////
165 GuiParagraph::GuiParagraph(GuiDialog & parent)
166 : GuiView<GuiParagraphDialog>(parent, _("Paragraph Settings"))
170 void GuiParagraph::build_dialog()
173 dialog_.reset(new GuiParagraphDialog(this));
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);
183 void GuiParagraph::apply()
185 ParagraphParameters & params = controller().params();
187 params.align(dialog_->getAlignmentFromDialog());
190 Spacing::Space linespacing = Spacing::Default;
192 switch (dialog_->linespacing->currentIndex()) {
194 linespacing = Spacing::Default;
197 linespacing = Spacing::Single;
200 linespacing = Spacing::Onehalf;
203 linespacing = Spacing::Double;
206 linespacing = Spacing::Other;
207 other = fromqstr(dialog_->linespacingValue->text());
211 Spacing const spacing(linespacing, other);
212 params.spacing(spacing);
215 params.labelWidthString(qstring_to_ucs4(dialog_->labelWidth->text()));
217 params.noindent(!dialog_->indentCB->isChecked());
221 void GuiParagraph::update_contents()
223 ParagraphParameters const & params = controller().params();
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));
232 dialog_->labelwidthGB->setEnabled(false);
233 dialog_->labelWidth->setText("");
237 dialog_->checkAlignmentRadioButtons();
238 dialog_->alignmentToRadioButtons(params.align());
241 bool const canindent = controller().canIndent();
242 dialog_->indentCB->setEnabled(canindent);
243 dialog_->indentCB->setChecked(canindent && !params.noindent());
247 Spacing const & space = params.spacing();
248 switch (space.getSpace()) {
249 case Spacing::Single:
252 case Spacing::Onehalf:
255 case Spacing::Double:
265 dialog_->linespacing->setCurrentIndex(linespacing);
266 if (space.getSpace() == Spacing::Other) {
267 dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
268 dialog_->linespacingValue->setEnabled(true);
270 dialog_->linespacingValue->setText("");
271 dialog_->linespacingValue->setEnabled(false);
275 } // namespace frontend
278 #include "GuiParagraph_moc.cpp"