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"
16 #include "qt_helpers.h"
19 #include "ParagraphParameters.h"
22 #include "controllers/ControlParagraph.h"
23 #include "controllers/frontend_helpers.h"
27 #include <QPushButton>
32 /////////////////////////////////////////////////////////////////////
36 /////////////////////////////////////////////////////////////////////
39 #include <boost/current_function.hpp>
44 GuiParagraphDialog::GuiParagraphDialog(GuiParagraph * form)
49 connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
50 connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
51 connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
52 connect(restorePB, SIGNAL(clicked()), form_, SLOT(slotRestore()));
53 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
54 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
55 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
56 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
57 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
58 connect(linespacing, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
59 connect(linespacing, SIGNAL(activated(int)),
60 this, SLOT(enableLinespacingValue(int)));
61 connect(linespacingValue, SIGNAL(textChanged(const QString &)),
62 this, SLOT(change_adaptor()));
63 connect(indentCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
64 connect(labelWidth, SIGNAL(textChanged(const QString &)),
65 this, SLOT(change_adaptor()));
67 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
69 labelWidth->setWhatsThis( qt_(
70 "As described in the User Guide, the width of"
71 " this text determines the width of the label part"
72 " of each item in environments like List and"
75 " Normally, you won't need to set this,"
76 " since the largest label width of all the"
80 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
81 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
82 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
83 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
84 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
86 labelMap[LYX_ALIGN_LAYOUT] = _("Use Paragraph's Default Alignment");
87 labelMap[LYX_ALIGN_BLOCK] = _("Justified");
88 labelMap[LYX_ALIGN_LEFT] = _("Left");
89 labelMap[LYX_ALIGN_RIGHT] = _("Right");
90 labelMap[LYX_ALIGN_CENTER] = _("Center");
94 void GuiParagraphDialog::closeEvent(QCloseEvent * e)
101 void GuiParagraphDialog::change_adaptor()
107 void GuiParagraphDialog::enableLinespacingValue(int)
109 bool const enable = linespacing->currentIndex() == 4;
110 linespacingValue->setEnabled(enable);
114 void GuiParagraphDialog::checkAlignmentRadioButtons() {
115 LyXAlignment const alignPossible = form_->controller().alignPossible();
117 QPRadioMap::iterator it = radioMap.begin();
118 for (; it != radioMap.end(); ++it) {
119 LyXAlignment const align = it->first;
120 it->second->setEnabled(align & alignPossible);
122 docstring label = labelMap[LYX_ALIGN_LAYOUT];
123 if (!form_->controller().haveMulitParSelection())
124 label += (" (" + labelMap[form_->controller().alignDefault()] + ")");
125 alignDefaultRB->setText(toqstr(label));
129 void GuiParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
131 QPRadioMap::const_iterator it = radioMap.begin();
132 for (;it != radioMap.end(); ++it) {
133 if (align == it->first) {
134 it->second->blockSignals(true);
135 it->second->setChecked(true);
136 it->second->blockSignals(false);
141 lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment "
142 << align << std::endl;
146 LyXAlignment GuiParagraphDialog::getAlignmentFromDialog()
148 LyXAlignment alignment = LYX_ALIGN_NONE;
149 QPRadioMap::const_iterator it = radioMap.begin();
150 for (; it != radioMap.end(); ++it) {
151 if (it->second->isChecked()) {
152 alignment = it->first;
160 /////////////////////////////////////////////////////////////////////
164 /////////////////////////////////////////////////////////////////////
166 typedef QController<ControlParagraph, GuiView<GuiParagraphDialog> >
170 GuiParagraph::GuiParagraph(Dialog & parent)
171 : ParagraphBase(parent, _("Paragraph Settings"))
175 void GuiParagraph::build_dialog()
178 dialog_.reset(new GuiParagraphDialog(this));
180 // Manage the ok, apply, restore and cancel/close buttons
181 bcview().setOK(dialog_->okPB);
182 bcview().setApply(dialog_->applyPB);
183 bcview().setCancel(dialog_->closePB);
184 bcview().setRestore(dialog_->restorePB);
188 void GuiParagraph::apply()
190 ParagraphParameters & params = controller().params();
192 params.align(dialog_->getAlignmentFromDialog());
195 Spacing::Space linespacing = Spacing::Default;
197 switch (dialog_->linespacing->currentIndex()) {
199 linespacing = Spacing::Default;
202 linespacing = Spacing::Single;
205 linespacing = Spacing::Onehalf;
208 linespacing = Spacing::Double;
211 linespacing = Spacing::Other;
212 other = fromqstr(dialog_->linespacingValue->text());
216 Spacing const spacing(linespacing, other);
217 params.spacing(spacing);
220 params.labelWidthString(qstring_to_ucs4(dialog_->labelWidth->text()));
222 params.noindent(!dialog_->indentCB->isChecked());
226 void GuiParagraph::update_contents()
228 ParagraphParameters const & params = controller().params();
231 docstring const & labelwidth = params.labelWidthString();
232 // FIXME We should not compare translated strings
233 if (labelwidth != _("Senseless with this layout!")) {
234 dialog_->labelwidthGB->setEnabled(true);
235 dialog_->labelWidth->setText(toqstr(labelwidth));
237 dialog_->labelwidthGB->setEnabled(false);
238 dialog_->labelWidth->setText("");
242 dialog_->checkAlignmentRadioButtons();
243 dialog_->alignmentToRadioButtons(params.align());
246 bool const canindent = controller().canIndent();
247 dialog_->indentCB->setEnabled(canindent);
248 dialog_->indentCB->setChecked(canindent && !params.noindent());
252 Spacing const & space = params.spacing();
253 switch (space.getSpace()) {
254 case Spacing::Single:
257 case Spacing::Onehalf:
260 case Spacing::Double:
270 dialog_->linespacing->setCurrentIndex(linespacing);
271 if (space.getSpace() == Spacing::Other) {
272 dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
273 dialog_->linespacingValue->setEnabled(true);
275 dialog_->linespacingValue->setText("");
276 dialog_->linespacingValue->setEnabled(false);
280 } // namespace frontend
283 #include "GuiParagraph_moc.cpp"