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 "frontend_helpers.h"
26 #include "FuncRequest.h"
30 #include "Paragraph.h"
31 #include "ParagraphParameters.h"
32 #include "qt_helpers.h"
36 #include <QCloseEvent>
38 #include <QPushButton>
40 #include <boost/current_function.hpp>
44 using std::istringstream;
45 using std::ostringstream;
52 GuiParagraph::GuiParagraph(LyXView & lv)
56 setWindowTitle(qt_("Paragraph Settings"));
59 QGridLayout * gridLayout = new QGridLayout(this);
60 gridLayout->setMargin(0);
61 gridLayout->addWidget(this);
63 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
64 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
65 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
66 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
67 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
68 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
69 connect(linespacingValue, SIGNAL(textChanged(QString)),
70 this, SLOT(changed()));
71 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
72 connect(labelWidth, SIGNAL(textChanged(QString)),
73 this, SLOT(changed()));
76 synchronizedViewCB->setChecked(false);
77 on_synchronizedViewCB_toggled();
78 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
80 labelWidth->setWhatsThis( qt_(
81 "As described in the User Guide, the width of"
82 " this text determines the width of the label part"
83 " of each item in environments like List and"
86 " Normally, you won't need to set this,"
87 " since the largest label width of all the"
91 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
92 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
93 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
94 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
95 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
97 labelMap[LYX_ALIGN_BLOCK] = _("Justified");
98 labelMap[LYX_ALIGN_LEFT] = _("Left");
99 labelMap[LYX_ALIGN_RIGHT] = _("Right");
100 labelMap[LYX_ALIGN_CENTER] = _("Center");
102 const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
106 void GuiParagraph::on_linespacing_activated(int index)
108 linespacingValue->setEnabled(index == 4);
112 void GuiParagraph::checkAlignmentRadioButtons()
114 RadioMap::iterator it = radioMap.begin();
115 for (; it != radioMap.end(); ++it) {
116 LyXAlignment const align = it->first;
117 it->second->setEnabled(align & alignPossible());
119 if (haveMulitParSelection())
120 alignDefaultRB->setText(alignDefaultLabel);
122 alignDefaultRB->setText(alignDefaultLabel + " ("
123 + toqstr(labelMap[alignDefault()]) + ")");
127 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
129 RadioMap::const_iterator it = radioMap.begin();
130 for (;it != radioMap.end(); ++it) {
131 if (!it->second->isEnabled())
133 it->second->blockSignals(true);
134 it->second->setChecked(align == it->first);
135 it->second->blockSignals(false);
140 LyXAlignment GuiParagraph::getAlignmentFromDialog()
142 LyXAlignment alignment = LYX_ALIGN_NONE;
143 RadioMap::const_iterator it = radioMap.begin();
144 for (; it != radioMap.end(); ++it) {
145 if (it->second->isChecked()) {
146 alignment = it->first;
154 void GuiParagraph::on_synchronizedViewCB_toggled()
156 bool in_sync = synchronizedViewCB->isChecked();
157 restorePB->setEnabled(!in_sync);
158 applyPB->setEnabled(!in_sync);
162 void GuiParagraph::changed()
164 if (synchronizedViewCB->isChecked())
165 on_applyPB_clicked();
169 void GuiParagraph::on_applyPB_clicked()
171 ParagraphParameters & pp = params();
173 pp.align(getAlignmentFromDialog());
176 Spacing::Space ls = Spacing::Default;
178 switch (linespacing->currentIndex()) {
180 ls = Spacing::Default;
183 ls = Spacing::Single;
186 ls = Spacing::Onehalf;
189 ls = Spacing::Double;
193 other = fromqstr(linespacingValue->text());
197 Spacing const spacing(ls, other);
201 pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
203 pp.noindent(!indentCB->isChecked());
209 void GuiParagraph::on_restorePB_clicked()
215 void GuiParagraph::updateView()
217 on_synchronizedViewCB_toggled();
219 ParagraphParameters const & pp = params();
222 docstring const & labelwidth = pp.labelWidthString();
223 // FIXME We should not compare translated strings
224 if (labelwidth != _("Senseless with this layout!")) {
225 labelwidthGB->setEnabled(true);
226 labelWidth->setText(toqstr(labelwidth));
228 labelwidthGB->setEnabled(false);
229 labelWidth->setText("");
233 checkAlignmentRadioButtons();
234 alignmentToRadioButtons(pp.align());
237 bool const canindent = canIndent();
238 indentCB->setEnabled(canindent);
239 indentCB->setChecked(canindent && !pp.noindent());
243 Spacing const & space = pp.spacing();
244 switch (space.getSpace()) {
245 case Spacing::Single:
248 case Spacing::Onehalf:
251 case Spacing::Double:
261 linespacing->setCurrentIndex(ls);
262 if (space.getSpace() == Spacing::Other) {
263 linespacingValue->setText(toqstr(space.getValueAsString()));
264 linespacingValue->setEnabled(true);
266 linespacingValue->setText(QString());
267 linespacingValue->setEnabled(false);
272 ParagraphParameters & GuiParagraph::params()
274 if (haveMulitParSelection()) {
275 multiparsel_ = ParagraphParameters();
276 // FIXME: It would be nice to initialise the parameters that
277 // are common to all paragraphs.
281 return bufferview()->cursor().innerParagraph().params();
285 ParagraphParameters const & GuiParagraph::params() const
287 return bufferview()->cursor().innerParagraph().params();
291 void GuiParagraph::dispatchParams()
293 if (haveMulitParSelection()) {
295 multiparsel_.write(data);
296 FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
301 bufferview()->updateMetrics(false);
302 bufferview()->buffer().changed();
306 bool GuiParagraph::haveMulitParSelection()
308 Cursor cur = bufferview()->cursor();
309 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
313 bool GuiParagraph::canIndent() const
315 return buffer().params().paragraph_separation ==
316 BufferParams::PARSEP_INDENT;
320 LyXAlignment GuiParagraph::alignPossible() const
322 return bufferview()->cursor().innerParagraph().layout()->alignpossible;
326 LyXAlignment GuiParagraph::alignDefault() const
328 return bufferview()->cursor().innerParagraph().layout()->align;
332 Dialog * createGuiParagraph(LyXView & lv)
335 GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);
336 #ifdef USE_DOCK_WIDGET
337 return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
338 Qt::TopDockWidgetArea);
340 return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
344 return new GuiParagraph(lv);
348 } // namespace frontend
351 #include "GuiParagraph_moc.cpp"