2 * \file GuiParagraph.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
15 #include "GuiParagraph.h"
16 #include "qt_helpers.h"
18 #include "ControlParagraph.h"
21 #include "frontend_helpers.h"
23 #include "ParagraphParameters.h"
27 #include <QCloseEvent>
29 #include <QPushButton>
31 #include <boost/current_function.hpp>
39 GuiParagraph::GuiParagraph(ControlParagraph & controller, QWidget * parent)
40 : QWidget(parent), controller_(controller)
43 setWindowTitle(qt_("Paragraph Settings"));
45 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
46 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
47 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
48 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
49 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
50 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
51 connect(linespacingValue, SIGNAL(textChanged(const QString &)),
52 this, SLOT(changed()));
53 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
54 connect(labelWidth, SIGNAL(textChanged(const QString &)),
55 this, SLOT(changed()));
58 synchronizedViewCB->setChecked(true);
59 on_synchronizedViewCB_toggled();
60 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
62 labelWidth->setWhatsThis( qt_(
63 "As described in the User Guide, the width of"
64 " this text determines the width of the label part"
65 " of each item in environments like List and"
68 " Normally, you won't need to set this,"
69 " since the largest label width of all the"
73 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
74 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
75 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
76 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
77 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
79 const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
83 void GuiParagraph::on_linespacing_activated(int index)
85 linespacingValue->setEnabled(index == 4);
89 void GuiParagraph::checkAlignmentRadioButtons() {
90 LyXAlignment const alignPossible = controller_.alignPossible();
92 RadioMap::iterator it = radioMap.begin();
93 for (; it != radioMap.end(); ++it) {
94 LyXAlignment const align = it->first;
95 it->second->setEnabled(align & alignPossible);
97 if (controller_.haveMulitParSelection())
98 alignDefaultRB->setText(alignDefaultLabel);
100 alignDefaultRB->setText(alignDefaultLabel + " ("
101 + radioMap[controller_.alignDefault()]->text() + ")");
105 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
107 RadioMap::const_iterator it = radioMap.begin();
108 for (;it != radioMap.end(); ++it) {
109 if (!it->second->isEnabled())
111 it->second->blockSignals(true);
112 it->second->setChecked(align == it->first);
113 it->second->blockSignals(false);
118 LyXAlignment GuiParagraph::getAlignmentFromDialog()
120 LyXAlignment alignment = LYX_ALIGN_NONE;
121 RadioMap::const_iterator it = radioMap.begin();
122 for (; it != radioMap.end(); ++it) {
123 if (it->second->isChecked()) {
124 alignment = it->first;
132 void GuiParagraph::on_synchronizedViewCB_toggled()
134 bool in_sync = synchronizedViewCB->isChecked();
135 restorePB->setEnabled(!in_sync);
136 applyPB->setEnabled(!in_sync);
140 void GuiParagraph::changed()
142 if (synchronizedViewCB->isChecked())
143 on_applyPB_clicked();
147 void GuiParagraph::on_applyPB_clicked()
149 ParagraphParameters & params = controller_.params();
151 params.align(getAlignmentFromDialog());
154 Spacing::Space ls = Spacing::Default;
156 switch (linespacing->currentIndex()) {
158 ls = Spacing::Default;
161 ls = Spacing::Single;
164 ls = Spacing::Onehalf;
167 ls = Spacing::Double;
171 other = fromqstr(linespacingValue->text());
175 Spacing const spacing(ls, other);
176 params.spacing(spacing);
179 params.labelWidthString(qstring_to_ucs4(labelWidth->text()));
181 params.noindent(!indentCB->isChecked());
183 controller_.dispatchParams();
187 void GuiParagraph::on_restorePB_clicked()
193 void GuiParagraph::updateView()
195 on_synchronizedViewCB_toggled();
197 ParagraphParameters const & params = controller_.params();
200 docstring const & labelwidth = params.labelWidthString();
201 // FIXME We should not compare translated strings
202 if (labelwidth != _("Senseless with this layout!")) {
203 labelwidthGB->setEnabled(true);
204 labelWidth->setText(toqstr(labelwidth));
206 labelwidthGB->setEnabled(false);
207 labelWidth->setText("");
211 checkAlignmentRadioButtons();
212 alignmentToRadioButtons(params.align());
215 bool const canindent = controller_.canIndent();
216 indentCB->setEnabled(canindent);
217 indentCB->setChecked(canindent && !params.noindent());
221 Spacing const & space = params.spacing();
222 switch (space.getSpace()) {
223 case Spacing::Single:
226 case Spacing::Onehalf:
229 case Spacing::Double:
239 linespacing->setCurrentIndex(ls);
240 if (space.getSpace() == Spacing::Other) {
241 linespacingValue->setText(toqstr(space.getValueAsString()));
242 linespacingValue->setEnabled(true);
244 linespacingValue->setText(QString());
245 linespacingValue->setEnabled(false);
249 } // namespace frontend
252 #include "GuiParagraph_moc.cpp"