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"
23 //#include "DialogView.h"
24 //#include "DockView.h"
25 #include "FuncRequest.h"
29 #include "Paragraph.h"
30 #include "ParagraphParameters.h"
31 #include "qt_helpers.h"
35 #include <QCloseEvent>
37 #include <QPushButton>
39 #include <boost/current_function.hpp>
43 using std::istringstream;
44 using std::ostringstream;
51 GuiParagraph::GuiParagraph(GuiView & lv)
55 setWindowTitle(qt_("Paragraph Settings"));
58 QGridLayout * gridLayout = new QGridLayout(this);
59 gridLayout->setMargin(0);
60 gridLayout->addWidget(this);
62 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
63 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
64 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
65 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
66 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
67 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
68 connect(linespacingValue, SIGNAL(textChanged(QString)),
69 this, SLOT(changed()));
70 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
71 connect(labelWidth, SIGNAL(textChanged(QString)),
72 this, SLOT(changed()));
75 synchronizedViewCB->setChecked(false);
76 on_synchronizedViewCB_toggled();
77 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
79 labelWidth->setWhatsThis( qt_(
80 "As described in the User Guide, the width of"
81 " this text determines the width of the label part"
82 " of each item in environments like List and"
85 " Normally, you won't need to set this,"
86 " since the largest label width of all the"
90 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
91 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
92 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
93 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
94 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
96 labelMap[LYX_ALIGN_BLOCK] = _("Justified");
97 labelMap[LYX_ALIGN_LEFT] = _("Left");
98 labelMap[LYX_ALIGN_RIGHT] = _("Right");
99 labelMap[LYX_ALIGN_CENTER] = _("Center");
101 const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
105 void GuiParagraph::on_linespacing_activated(int index)
107 linespacingValue->setEnabled(index == 4);
111 void GuiParagraph::checkAlignmentRadioButtons()
113 RadioMap::iterator it = radioMap.begin();
114 for (; it != radioMap.end(); ++it) {
115 LyXAlignment const align = it->first;
116 it->second->setEnabled(align & alignPossible());
118 if (haveMulitParSelection())
119 alignDefaultRB->setText(alignDefaultLabel);
121 alignDefaultRB->setText(alignDefaultLabel + " ("
122 + toqstr(labelMap[alignDefault()]) + ")");
126 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
128 RadioMap::const_iterator it = radioMap.begin();
129 for (;it != radioMap.end(); ++it) {
130 if (!it->second->isEnabled())
132 it->second->blockSignals(true);
133 it->second->setChecked(align == it->first);
134 it->second->blockSignals(false);
139 LyXAlignment GuiParagraph::getAlignmentFromDialog()
141 LyXAlignment alignment = LYX_ALIGN_NONE;
142 RadioMap::const_iterator it = radioMap.begin();
143 for (; it != radioMap.end(); ++it) {
144 if (it->second->isChecked()) {
145 alignment = it->first;
153 void GuiParagraph::on_synchronizedViewCB_toggled()
155 bool in_sync = synchronizedViewCB->isChecked();
156 restorePB->setEnabled(!in_sync);
157 applyPB->setEnabled(!in_sync);
161 void GuiParagraph::changed()
163 if (synchronizedViewCB->isChecked())
164 on_applyPB_clicked();
168 void GuiParagraph::on_applyPB_clicked()
170 ParagraphParameters & pp = params();
172 pp.align(getAlignmentFromDialog());
175 Spacing::Space ls = Spacing::Default;
177 switch (linespacing->currentIndex()) {
179 ls = Spacing::Default;
182 ls = Spacing::Single;
185 ls = Spacing::Onehalf;
188 ls = Spacing::Double;
192 other = fromqstr(linespacingValue->text());
196 Spacing const spacing(ls, other);
200 pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
202 pp.noindent(!indentCB->isChecked());
208 void GuiParagraph::on_restorePB_clicked()
214 void GuiParagraph::updateView()
216 on_synchronizedViewCB_toggled();
218 ParagraphParameters const & pp = params();
221 docstring const & labelwidth = pp.labelWidthString();
222 // FIXME We should not compare translated strings
223 if (labelwidth != _("Senseless with this layout!")) {
224 labelwidthGB->setEnabled(true);
225 labelWidth->setText(toqstr(labelwidth));
227 labelwidthGB->setEnabled(false);
228 labelWidth->setText("");
232 checkAlignmentRadioButtons();
233 alignmentToRadioButtons(pp.align());
236 bool const canindent = canIndent();
237 indentCB->setEnabled(canindent);
238 indentCB->setChecked(canindent && !pp.noindent());
242 Spacing const & space = pp.spacing();
243 switch (space.getSpace()) {
244 case Spacing::Single:
247 case Spacing::Onehalf:
250 case Spacing::Double:
260 linespacing->setCurrentIndex(ls);
261 if (space.getSpace() == Spacing::Other) {
262 linespacingValue->setText(toqstr(space.getValueAsString()));
263 linespacingValue->setEnabled(true);
265 linespacingValue->setText(QString());
266 linespacingValue->setEnabled(false);
271 ParagraphParameters & GuiParagraph::params()
273 if (haveMulitParSelection()) {
274 multiparsel_ = ParagraphParameters();
275 // FIXME: It would be nice to initialise the parameters that
276 // are common to all paragraphs.
280 return bufferview()->cursor().innerParagraph().params();
284 ParagraphParameters const & GuiParagraph::params() const
286 return bufferview()->cursor().innerParagraph().params();
290 void GuiParagraph::dispatchParams()
292 if (haveMulitParSelection()) {
294 multiparsel_.write(data);
295 FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
300 bufferview()->updateMetrics();
301 bufferview()->buffer().changed();
305 bool GuiParagraph::haveMulitParSelection()
307 Cursor cur = bufferview()->cursor();
308 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
312 bool GuiParagraph::canIndent() const
314 return buffer().params().paragraph_separation ==
315 BufferParams::PARSEP_INDENT;
319 LyXAlignment GuiParagraph::alignPossible() const
321 return bufferview()->cursor().innerParagraph().layout()->alignpossible;
325 LyXAlignment GuiParagraph::alignDefault() const
327 return bufferview()->cursor().innerParagraph().layout()->align;
331 Dialog * createGuiParagraph(GuiView & lv)
334 GuiView & guiview = static_cast<GuiView &>(lv);
335 #ifdef USE_DOCK_WIDGET
336 return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
337 Qt::TopDockWidgetArea);
339 return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
343 return new GuiParagraph(lv);
347 } // namespace frontend
350 #include "GuiParagraph_moc.cpp"