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 "ControlParagraph.h"
19 #include "frontend_helpers.h"
20 #include "ParagraphParameters.h"
21 #include "qt_helpers.h"
25 #include <QCloseEvent>
27 #include <QPushButton>
29 #include <boost/current_function.hpp>
37 GuiParagraphDialog::GuiParagraphDialog(LyXView & lv)
38 : GuiDialog(lv, "paragraph")
41 setViewTitle(_("Paragraph Settings"));
42 setController(new ControlParagraph(*this));
44 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
45 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
46 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
47 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
48 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
49 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
50 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
51 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
52 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
53 connect(linespacing, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
54 connect(linespacing, SIGNAL(activated(int)),
55 this, SLOT(enableLinespacingValue(int)));
56 connect(linespacingValue, SIGNAL(textChanged(const QString &)),
57 this, SLOT(change_adaptor()));
58 connect(indentCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
59 connect(labelWidth, SIGNAL(textChanged(const QString &)),
60 this, SLOT(change_adaptor()));
62 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
64 labelWidth->setWhatsThis( qt_(
65 "As described in the User Guide, the width of"
66 " this text determines the width of the label part"
67 " of each item in environments like List and"
70 " Normally, you won't need to set this,"
71 " since the largest label width of all the"
75 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
76 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
77 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
78 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
79 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
81 labelMap[LYX_ALIGN_LAYOUT] = _("Use Paragraph's Default Alignment");
82 labelMap[LYX_ALIGN_BLOCK] = _("Justified");
83 labelMap[LYX_ALIGN_LEFT] = _("Left");
84 labelMap[LYX_ALIGN_RIGHT] = _("Right");
85 labelMap[LYX_ALIGN_CENTER] = _("Center");
87 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
89 bc().setApply(applyPB);
90 bc().setCancel(closePB);
91 bc().setRestore(restorePB);
95 ControlParagraph & GuiParagraphDialog::controller()
97 return static_cast<ControlParagraph &>(GuiDialog::controller());
101 void GuiParagraphDialog::closeEvent(QCloseEvent * e)
108 void GuiParagraphDialog::change_adaptor()
114 void GuiParagraphDialog::enableLinespacingValue(int)
116 bool const enable = linespacing->currentIndex() == 4;
117 linespacingValue->setEnabled(enable);
121 void GuiParagraphDialog::checkAlignmentRadioButtons() {
122 LyXAlignment const alignPossible = controller().alignPossible();
124 RadioMap::iterator it = radioMap.begin();
125 for (; it != radioMap.end(); ++it) {
126 LyXAlignment const align = it->first;
127 it->second->setEnabled(align & alignPossible);
129 docstring label = labelMap[LYX_ALIGN_LAYOUT];
130 if (!controller().haveMulitParSelection())
131 label += (" (" + labelMap[controller().alignDefault()] + ")");
132 alignDefaultRB->setText(toqstr(label));
136 void GuiParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
138 RadioMap::const_iterator it = radioMap.begin();
139 for (;it != radioMap.end(); ++it) {
140 if (align == it->first) {
141 it->second->blockSignals(true);
142 it->second->setChecked(true);
143 it->second->blockSignals(false);
148 lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment "
149 << align << std::endl;
153 LyXAlignment GuiParagraphDialog::getAlignmentFromDialog()
155 LyXAlignment alignment = LYX_ALIGN_NONE;
156 RadioMap::const_iterator it = radioMap.begin();
157 for (; it != radioMap.end(); ++it) {
158 if (it->second->isChecked()) {
159 alignment = it->first;
167 void GuiParagraphDialog::applyView()
169 ParagraphParameters & params = controller().params();
171 params.align(getAlignmentFromDialog());
174 Spacing::Space ls = Spacing::Default;
176 switch (linespacing->currentIndex()) {
178 ls = Spacing::Default;
181 ls = Spacing::Single;
184 ls = Spacing::Onehalf;
187 ls = Spacing::Double;
191 other = fromqstr(linespacingValue->text());
195 Spacing const spacing(ls, other);
196 params.spacing(spacing);
199 params.labelWidthString(qstring_to_ucs4(labelWidth->text()));
201 params.noindent(!indentCB->isChecked());
205 void GuiParagraphDialog::updateContents()
207 ParagraphParameters const & params = controller().params();
210 docstring const & labelwidth = params.labelWidthString();
211 // FIXME We should not compare translated strings
212 if (labelwidth != _("Senseless with this layout!")) {
213 labelwidthGB->setEnabled(true);
214 labelWidth->setText(toqstr(labelwidth));
216 labelwidthGB->setEnabled(false);
217 labelWidth->setText("");
221 checkAlignmentRadioButtons();
222 alignmentToRadioButtons(params.align());
225 bool const canindent = controller().canIndent();
226 indentCB->setEnabled(canindent);
227 indentCB->setChecked(canindent && !params.noindent());
231 Spacing const & space = params.spacing();
232 switch (space.getSpace()) {
233 case Spacing::Single:
236 case Spacing::Onehalf:
239 case Spacing::Double:
249 linespacing->setCurrentIndex(ls);
250 if (space.getSpace() == Spacing::Other) {
251 linespacingValue->setText(toqstr(space.getValueAsString()));
252 linespacingValue->setEnabled(true);
254 linespacingValue->setText(QString());
255 linespacingValue->setEnabled(false);
259 } // namespace frontend
262 #include "GuiParagraph_moc.cpp"