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
9 * \author Angus Leeming
11 * Full author contact details are available in file CREDITS.
16 #include "GuiParagraph.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
22 #include "FuncRequest.h"
25 #include "Paragraph.h"
26 #include "ParagraphParameters.h"
27 #include "qt_helpers.h"
30 #include "support/debug.h"
31 #include "support/gettext.h"
35 #include <QPushButton>
44 GuiParagraph::GuiParagraph(GuiView & lv)
45 : DialogView(lv, "paragraph", qt_("Paragraph Settings"))
49 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
50 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
51 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
52 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
53 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
54 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
55 connect(linespacingValue, SIGNAL(textChanged(QString)),
56 this, SLOT(changed()));
57 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
58 connect(labelWidth, SIGNAL(textChanged(QString)),
59 this, SLOT(changed()));
62 // On Mac it's common to have tool windows which are always in the
63 // foreground and are hidden when the main window is not focused.
64 setWindowFlags(Qt::Tool);
65 synchronizedViewCB->setChecked(true);
67 synchronizedViewCB->setChecked(false);
70 on_synchronizedViewCB_toggled();
71 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
73 labelWidth->setWhatsThis( qt_(
74 "As described in the User Guide, the width of"
75 " this text determines the width of the label part"
76 " of each item in environments like List and"
79 " Normally, you won't need to set this,"
80 " since the largest label width of all the"
84 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
85 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
86 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
87 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
88 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
90 labelMap[LYX_ALIGN_BLOCK] = _("Justified");
91 labelMap[LYX_ALIGN_LEFT] = _("Left");
92 labelMap[LYX_ALIGN_RIGHT] = _("Right");
93 labelMap[LYX_ALIGN_CENTER] = _("Center");
95 const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
99 void GuiParagraph::on_linespacing_activated(int index)
101 linespacingValue->setEnabled(index == 4);
105 void GuiParagraph::checkAlignmentRadioButtons()
107 RadioMap::iterator it = radioMap.begin();
108 for (; it != radioMap.end(); ++it) {
109 LyXAlignment const align = it->first;
110 it->second->setEnabled(align & alignPossible());
112 if (haveMultiParSelection())
113 alignDefaultRB->setText(alignDefaultLabel);
115 alignDefaultRB->setText(alignDefaultLabel + " ("
116 + toqstr(labelMap[alignDefault()]) + ")");
120 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
122 RadioMap::const_iterator it = radioMap.begin();
123 for (;it != radioMap.end(); ++it) {
124 it->second->blockSignals(true);
125 it->second->setChecked(align == it->first);
126 it->second->blockSignals(false);
131 LyXAlignment GuiParagraph::getAlignmentFromDialog()
133 LyXAlignment alignment = LYX_ALIGN_NONE;
134 RadioMap::const_iterator it = radioMap.begin();
135 for (; it != radioMap.end(); ++it) {
136 if (it->second->isChecked()) {
137 alignment = it->first;
145 void GuiParagraph::on_synchronizedViewCB_toggled()
147 bool in_sync = synchronizedViewCB->isChecked();
148 restorePB->setEnabled(!in_sync);
149 applyPB->setEnabled(!in_sync);
153 void GuiParagraph::changed()
155 if (synchronizedViewCB->isChecked())
156 on_applyPB_clicked();
160 void GuiParagraph::on_applyPB_clicked()
162 ParagraphParameters & pp = params();
164 pp.align(getAlignmentFromDialog());
167 Spacing::Space ls = Spacing::Default;
169 switch (linespacing->currentIndex()) {
171 ls = Spacing::Default;
174 ls = Spacing::Single;
177 ls = Spacing::Onehalf;
180 ls = Spacing::Double;
184 other = fromqstr(linespacingValue->text());
188 Spacing const spacing(ls, other);
192 pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
194 pp.noindent(!indentCB->isChecked());
200 void GuiParagraph::on_restorePB_clicked()
206 void GuiParagraph::updateView()
208 on_synchronizedViewCB_toggled();
210 ParagraphParameters const & pp = params();
213 docstring const & labelwidth = pp.labelWidthString();
214 // FIXME We should not compare translated strings
215 if (labelwidth != _("Senseless with this layout!")) {
216 labelwidthGB->setEnabled(true);
217 labelWidth->setText(toqstr(labelwidth));
219 labelwidthGB->setEnabled(false);
220 labelWidth->setText("");
224 checkAlignmentRadioButtons();
225 alignmentToRadioButtons(pp.align());
228 bool const canindent = canIndent();
229 indentCB->setEnabled(canindent);
230 indentCB->setChecked(canindent && !pp.noindent());
234 Spacing const & space = pp.spacing();
235 switch (space.getSpace()) {
236 case Spacing::Single:
239 case Spacing::Onehalf:
242 case Spacing::Double:
252 linespacing->setCurrentIndex(ls);
253 if (space.getSpace() == Spacing::Other) {
254 linespacingValue->setText(toqstr(space.getValueAsString()));
255 linespacingValue->setEnabled(true);
257 linespacingValue->setText(QString());
258 linespacingValue->setEnabled(false);
263 void GuiParagraph::enableView(bool enable)
265 indentCB->setEnabled(enable);
266 linespacing->setEnabled(enable);
267 labelWidth->setEnabled(enable);
268 synchronizedViewCB->setEnabled(enable);
269 applyPB->setEnabled(enable);
270 restorePB->setEnabled(enable);
272 synchronizedViewCB->setChecked(true);
273 RadioMap::const_iterator it = radioMap.begin();
274 for (; it != radioMap.end(); ++it)
275 it->second->setEnabled(enable);
279 ParagraphParameters & GuiParagraph::params()
281 if (haveMultiParSelection()) {
282 multiparsel_ = ParagraphParameters();
283 // FIXME: It would be nice to initialise the parameters that
284 // are common to all paragraphs.
288 return bufferview()->cursor().innerParagraph().params();
292 ParagraphParameters const & GuiParagraph::params() const
294 return bufferview()->cursor().innerParagraph().params();
298 void GuiParagraph::dispatchParams()
300 if (haveMultiParSelection()) {
302 multiparsel_.write(data);
303 FuncRequest const fr(getLfun(), data.str());
308 bufferview()->updateMetrics();
309 bufferview()->buffer().changed();
313 bool GuiParagraph::haveMultiParSelection()
315 Cursor cur = bufferview()->cursor();
316 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
320 bool GuiParagraph::canIndent() const
322 return buffer().params().paragraph_separation ==
323 BufferParams::PARSEP_INDENT;
327 LyXAlignment GuiParagraph::alignPossible() const
329 return bufferview()->cursor().innerParagraph().layout()->alignpossible;
333 LyXAlignment GuiParagraph::alignDefault() const
335 return bufferview()->cursor().innerParagraph().layout()->align;
339 Dialog * createGuiParagraph(GuiView & lv)
341 return new GuiParagraph(lv);
345 } // namespace frontend
348 #include "GuiParagraph_moc.cpp"