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"
18 #include "qt_helpers.h"
21 #include "BufferParams.h"
22 #include "BufferView.h"
24 #include "FuncRequest.h"
27 #include "Paragraph.h"
28 #include "ParagraphParameters.h"
31 #include "support/debug.h"
32 #include "support/gettext.h"
36 #include <QPushButton>
45 GuiParagraph::GuiParagraph(GuiView & lv)
46 : DialogView(lv, "paragraph", qt_("Paragraph Settings"))
50 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
51 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
52 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
53 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
54 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
55 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
56 connect(linespacingValue, SIGNAL(textChanged(QString)),
57 this, SLOT(changed()));
58 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
59 connect(labelWidth, SIGNAL(textChanged(QString)),
60 this, SLOT(changed()));
63 // On Mac it's common to have tool windows which are always in the
64 // foreground and are hidden when the main window is not focused.
65 setWindowFlags(Qt::Tool);
66 synchronizedViewCB->setChecked(true);
68 synchronizedViewCB->setChecked(false);
71 on_synchronizedViewCB_toggled();
72 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
74 labelWidth->setWhatsThis( qt_(
75 "As described in the User Guide, the width of"
76 " this text determines the width of the label part"
77 " of each item in environments like List and"
80 " Normally, you won't need to set this,"
81 " since the largest label width of all the"
85 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
86 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
87 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
88 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
89 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
91 labelMap[LYX_ALIGN_BLOCK] = _("Justified");
92 labelMap[LYX_ALIGN_LEFT] = _("Left");
93 labelMap[LYX_ALIGN_RIGHT] = _("Right");
94 labelMap[LYX_ALIGN_CENTER] = _("Center");
96 const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
100 void GuiParagraph::on_linespacing_activated(int index)
102 linespacingValue->setEnabled(index == 4);
106 void GuiParagraph::checkAlignmentRadioButtons()
108 RadioMap::iterator it = radioMap.begin();
109 for (; it != radioMap.end(); ++it) {
110 LyXAlignment const align = it->first;
111 it->second->setEnabled(align & alignPossible());
113 if (haveMultiParSelection())
114 alignDefaultRB->setText(alignDefaultLabel);
116 alignDefaultRB->setText(alignDefaultLabel + " ("
117 + toqstr(labelMap[alignDefault()]) + ")");
121 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
123 RadioMap::const_iterator it = radioMap.begin();
124 for (;it != radioMap.end(); ++it) {
125 it->second->blockSignals(true);
126 it->second->setChecked(align == it->first);
127 it->second->blockSignals(false);
132 LyXAlignment GuiParagraph::getAlignmentFromDialog()
134 LyXAlignment alignment = LYX_ALIGN_NONE;
135 RadioMap::const_iterator it = radioMap.begin();
136 for (; it != radioMap.end(); ++it) {
137 if (it->second->isChecked()) {
138 alignment = it->first;
146 void GuiParagraph::on_synchronizedViewCB_toggled()
148 bool in_sync = synchronizedViewCB->isChecked();
149 restorePB->setEnabled(!in_sync);
150 applyPB->setEnabled(!in_sync);
154 void GuiParagraph::changed()
156 if (synchronizedViewCB->isChecked())
157 on_applyPB_clicked();
161 void GuiParagraph::on_applyPB_clicked()
163 ParagraphParameters & pp = params();
165 pp.align(getAlignmentFromDialog());
168 Spacing::Space ls = Spacing::Default;
170 switch (linespacing->currentIndex()) {
172 ls = Spacing::Default;
175 ls = Spacing::Single;
178 ls = Spacing::Onehalf;
181 ls = Spacing::Double;
185 other = fromqstr(linespacingValue->text());
189 Spacing const spacing(ls, other);
193 pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
195 pp.noindent(!indentCB->isChecked());
201 void GuiParagraph::on_restorePB_clicked()
207 void GuiParagraph::updateView()
209 on_synchronizedViewCB_toggled();
211 ParagraphParameters const & pp = params();
214 docstring const & labelwidth = pp.labelWidthString();
215 // FIXME We should not compare translated strings
216 if (labelwidth != _("Senseless with this layout!")) {
217 labelwidthGB->setEnabled(true);
218 labelWidth->setText(toqstr(labelwidth));
220 labelwidthGB->setEnabled(false);
221 labelWidth->setText("");
225 checkAlignmentRadioButtons();
226 alignmentToRadioButtons(pp.align());
229 bool const canindent = canIndent();
230 indentCB->setEnabled(canindent);
231 indentCB->setChecked(canindent && !pp.noindent());
235 Spacing const & space = pp.spacing();
236 switch (space.getSpace()) {
237 case Spacing::Single:
240 case Spacing::Onehalf:
243 case Spacing::Double:
253 linespacing->setCurrentIndex(ls);
254 if (space.getSpace() == Spacing::Other) {
255 linespacingValue->setText(toqstr(space.getValueAsString()));
256 linespacingValue->setEnabled(true);
258 linespacingValue->setText(QString());
259 linespacingValue->setEnabled(false);
264 void GuiParagraph::enableView(bool enable)
266 indentCB->setEnabled(enable);
267 linespacing->setEnabled(enable);
268 labelWidth->setEnabled(enable);
269 synchronizedViewCB->setEnabled(enable);
270 applyPB->setEnabled(enable);
271 restorePB->setEnabled(enable);
273 synchronizedViewCB->setChecked(true);
274 RadioMap::const_iterator it = radioMap.begin();
275 for (; it != radioMap.end(); ++it)
276 it->second->setEnabled(enable);
280 ParagraphParameters & GuiParagraph::params()
282 if (haveMultiParSelection()) {
283 multiparsel_ = ParagraphParameters();
284 // FIXME: It would be nice to initialise the parameters that
285 // are common to all paragraphs.
289 return bufferview()->cursor().innerParagraph().params();
293 ParagraphParameters const & GuiParagraph::params() const
295 return bufferview()->cursor().innerParagraph().params();
299 void GuiParagraph::dispatchParams()
301 if (haveMultiParSelection()) {
303 multiparsel_.write(data);
304 FuncRequest const fr(getLfun(), data.str());
309 bufferview()->updateMetrics();
310 bufferview()->buffer().changed();
314 bool GuiParagraph::haveMultiParSelection()
316 Cursor cur = bufferview()->cursor();
317 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
321 bool GuiParagraph::canIndent() const
323 return buffer().params().paragraph_separation ==
324 BufferParams::PARSEP_INDENT;
328 LyXAlignment GuiParagraph::alignPossible() const
330 return bufferview()->cursor().innerParagraph().layout()->alignpossible;
334 LyXAlignment GuiParagraph::alignDefault() const
336 return bufferview()->cursor().innerParagraph().layout()->align;
340 Dialog * createGuiParagraph(GuiView & lv)
342 return new GuiParagraph(lv);
346 } // namespace frontend
349 #include "GuiParagraph_moc.cpp"