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"
21 #include "frontend_helpers.h"
24 #include <QCloseEvent>
26 #include <QPushButton>
31 /////////////////////////////////////////////////////////////////////
35 /////////////////////////////////////////////////////////////////////
38 #include <boost/current_function.hpp>
43 GuiParagraphDialog::GuiParagraphDialog(GuiParagraph * form)
48 connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
49 connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
50 connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
51 connect(restorePB, SIGNAL(clicked()), form_, SLOT(slotRestore()));
52 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
53 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
54 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
55 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
56 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
57 connect(linespacing, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
58 connect(linespacing, SIGNAL(activated(int)),
59 this, SLOT(enableLinespacingValue(int)));
60 connect(linespacingValue, SIGNAL(textChanged(const QString &)),
61 this, SLOT(change_adaptor()));
62 connect(indentCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
63 connect(labelWidth, SIGNAL(textChanged(const QString &)),
64 this, SLOT(change_adaptor()));
66 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
68 labelWidth->setWhatsThis( qt_(
69 "As described in the User Guide, the width of"
70 " this text determines the width of the label part"
71 " of each item in environments like List and"
74 " Normally, you won't need to set this,"
75 " since the largest label width of all the"
79 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
80 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
81 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
82 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
83 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
85 labelMap[LYX_ALIGN_LAYOUT] = _("Use Paragraph's Default Alignment");
86 labelMap[LYX_ALIGN_BLOCK] = _("Justified");
87 labelMap[LYX_ALIGN_LEFT] = _("Left");
88 labelMap[LYX_ALIGN_RIGHT] = _("Right");
89 labelMap[LYX_ALIGN_CENTER] = _("Center");
93 void GuiParagraphDialog::closeEvent(QCloseEvent * e)
100 void GuiParagraphDialog::change_adaptor()
106 void GuiParagraphDialog::enableLinespacingValue(int)
108 bool const enable = linespacing->currentIndex() == 4;
109 linespacingValue->setEnabled(enable);
113 void GuiParagraphDialog::checkAlignmentRadioButtons() {
114 LyXAlignment const alignPossible = form_->controller().alignPossible();
116 QPRadioMap::iterator it = radioMap.begin();
117 for (; it != radioMap.end(); ++it) {
118 LyXAlignment const align = it->first;
119 it->second->setEnabled(align & alignPossible);
121 docstring label = labelMap[LYX_ALIGN_LAYOUT];
122 if (!form_->controller().haveMulitParSelection())
123 label += (" (" + labelMap[form_->controller().alignDefault()] + ")");
124 alignDefaultRB->setText(toqstr(label));
128 void GuiParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
130 QPRadioMap::const_iterator it = radioMap.begin();
131 for (;it != radioMap.end(); ++it) {
132 if (align == it->first) {
133 it->second->blockSignals(true);
134 it->second->setChecked(true);
135 it->second->blockSignals(false);
140 lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment "
141 << align << std::endl;
145 LyXAlignment GuiParagraphDialog::getAlignmentFromDialog()
147 LyXAlignment alignment = LYX_ALIGN_NONE;
148 QPRadioMap::const_iterator it = radioMap.begin();
149 for (; it != radioMap.end(); ++it) {
150 if (it->second->isChecked()) {
151 alignment = it->first;
159 /////////////////////////////////////////////////////////////////////
163 /////////////////////////////////////////////////////////////////////
166 GuiParagraph::GuiParagraph(Dialog & parent)
167 : GuiView<GuiParagraphDialog>(parent, _("Paragraph Settings"))
171 void GuiParagraph::build_dialog()
174 dialog_.reset(new GuiParagraphDialog(this));
176 // Manage the ok, apply, restore and cancel/close buttons
177 bcview().setOK(dialog_->okPB);
178 bcview().setApply(dialog_->applyPB);
179 bcview().setCancel(dialog_->closePB);
180 bcview().setRestore(dialog_->restorePB);
184 void GuiParagraph::apply()
186 ParagraphParameters & params = controller().params();
188 params.align(dialog_->getAlignmentFromDialog());
191 Spacing::Space linespacing = Spacing::Default;
193 switch (dialog_->linespacing->currentIndex()) {
195 linespacing = Spacing::Default;
198 linespacing = Spacing::Single;
201 linespacing = Spacing::Onehalf;
204 linespacing = Spacing::Double;
207 linespacing = Spacing::Other;
208 other = fromqstr(dialog_->linespacingValue->text());
212 Spacing const spacing(linespacing, other);
213 params.spacing(spacing);
216 params.labelWidthString(qstring_to_ucs4(dialog_->labelWidth->text()));
218 params.noindent(!dialog_->indentCB->isChecked());
222 void GuiParagraph::update_contents()
224 ParagraphParameters const & params = controller().params();
227 docstring const & labelwidth = params.labelWidthString();
228 // FIXME We should not compare translated strings
229 if (labelwidth != _("Senseless with this layout!")) {
230 dialog_->labelwidthGB->setEnabled(true);
231 dialog_->labelWidth->setText(toqstr(labelwidth));
233 dialog_->labelwidthGB->setEnabled(false);
234 dialog_->labelWidth->setText("");
238 dialog_->checkAlignmentRadioButtons();
239 dialog_->alignmentToRadioButtons(params.align());
242 bool const canindent = controller().canIndent();
243 dialog_->indentCB->setEnabled(canindent);
244 dialog_->indentCB->setChecked(canindent && !params.noindent());
248 Spacing const & space = params.spacing();
249 switch (space.getSpace()) {
250 case Spacing::Single:
253 case Spacing::Onehalf:
256 case Spacing::Double:
266 dialog_->linespacing->setCurrentIndex(linespacing);
267 if (space.getSpace() == Spacing::Other) {
268 dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
269 dialog_->linespacingValue->setEnabled(true);
271 dialog_->linespacingValue->setText("");
272 dialog_->linespacingValue->setEnabled(false);
276 } // namespace frontend
279 #include "GuiParagraph_moc.cpp"