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"
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"));
60 QGridLayout * gridLayout = new QGridLayout(this);
61 gridLayout->setMargin(0);
62 gridLayout->addWidget(this);
64 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
65 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
66 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
67 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
68 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
69 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
70 connect(linespacingValue, SIGNAL(textChanged(const QString &)),
71 this, SLOT(changed()));
72 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
73 connect(labelWidth, SIGNAL(textChanged(const QString &)),
74 this, SLOT(changed()));
77 synchronizedViewCB->setChecked(false);
78 on_synchronizedViewCB_toggled();
79 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
81 labelWidth->setWhatsThis( qt_(
82 "As described in the User Guide, the width of"
83 " this text determines the width of the label part"
84 " of each item in environments like List and"
87 " Normally, you won't need to set this,"
88 " since the largest label width of all the"
92 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
93 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
94 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
95 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
96 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
98 const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
102 void GuiParagraph::on_linespacing_activated(int index)
104 linespacingValue->setEnabled(index == 4);
108 void GuiParagraph::checkAlignmentRadioButtons()
110 RadioMap::iterator it = radioMap.begin();
111 for (; it != radioMap.end(); ++it) {
112 LyXAlignment const align = it->first;
113 it->second->setEnabled(align & alignPossible());
115 if (haveMulitParSelection())
116 alignDefaultRB->setText(alignDefaultLabel);
118 alignDefaultRB->setText(alignDefaultLabel + " ("
119 + radioMap[alignDefault()]->text() + ")");
123 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
125 RadioMap::const_iterator it = radioMap.begin();
126 for (;it != radioMap.end(); ++it) {
127 if (!it->second->isEnabled())
129 it->second->blockSignals(true);
130 it->second->setChecked(align == it->first);
131 it->second->blockSignals(false);
136 LyXAlignment GuiParagraph::getAlignmentFromDialog()
138 LyXAlignment alignment = LYX_ALIGN_NONE;
139 RadioMap::const_iterator it = radioMap.begin();
140 for (; it != radioMap.end(); ++it) {
141 if (it->second->isChecked()) {
142 alignment = it->first;
150 void GuiParagraph::on_synchronizedViewCB_toggled()
152 bool in_sync = synchronizedViewCB->isChecked();
153 restorePB->setEnabled(!in_sync);
154 applyPB->setEnabled(!in_sync);
158 void GuiParagraph::changed()
160 if (synchronizedViewCB->isChecked())
161 on_applyPB_clicked();
165 void GuiParagraph::on_applyPB_clicked()
167 ParagraphParameters & pp = params();
169 pp.align(getAlignmentFromDialog());
172 Spacing::Space ls = Spacing::Default;
174 switch (linespacing->currentIndex()) {
176 ls = Spacing::Default;
179 ls = Spacing::Single;
182 ls = Spacing::Onehalf;
185 ls = Spacing::Double;
189 other = fromqstr(linespacingValue->text());
193 Spacing const spacing(ls, other);
197 pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
199 pp.noindent(!indentCB->isChecked());
205 void GuiParagraph::on_restorePB_clicked()
211 void GuiParagraph::updateView()
213 on_synchronizedViewCB_toggled();
215 ParagraphParameters const & pp = params();
218 docstring const & labelwidth = pp.labelWidthString();
219 // FIXME We should not compare translated strings
220 if (labelwidth != _("Senseless with this layout!")) {
221 labelwidthGB->setEnabled(true);
222 labelWidth->setText(toqstr(labelwidth));
224 labelwidthGB->setEnabled(false);
225 labelWidth->setText("");
229 checkAlignmentRadioButtons();
230 alignmentToRadioButtons(pp.align());
233 bool const canindent = canIndent();
234 indentCB->setEnabled(canindent);
235 indentCB->setChecked(canindent && !pp.noindent());
239 Spacing const & space = pp.spacing();
240 switch (space.getSpace()) {
241 case Spacing::Single:
244 case Spacing::Onehalf:
247 case Spacing::Double:
257 linespacing->setCurrentIndex(ls);
258 if (space.getSpace() == Spacing::Other) {
259 linespacingValue->setText(toqstr(space.getValueAsString()));
260 linespacingValue->setEnabled(true);
262 linespacingValue->setText(QString());
263 linespacingValue->setEnabled(false);
268 ParagraphParameters & GuiParagraph::params()
270 if (haveMulitParSelection()) {
271 multiparsel_ = ParagraphParameters();
272 // FIXME: It would be nice to initialise the parameters that
273 // are common to all paragraphs.
277 return bufferview()->cursor().innerParagraph().params();
281 ParagraphParameters const & GuiParagraph::params() const
283 return bufferview()->cursor().innerParagraph().params();
287 void GuiParagraph::dispatchParams()
289 if (haveMulitParSelection()) {
291 multiparsel_.write(data);
292 FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
297 bufferview()->updateMetrics(false);
298 bufferview()->buffer().changed();
302 bool GuiParagraph::haveMulitParSelection()
304 Cursor cur = bufferview()->cursor();
305 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
309 bool GuiParagraph::canIndent() const
311 return buffer().params().paragraph_separation ==
312 BufferParams::PARSEP_INDENT;
316 LyXAlignment GuiParagraph::alignPossible() const
318 return bufferview()->cursor().innerParagraph().layout()->alignpossible;
322 LyXAlignment GuiParagraph::alignDefault() const
324 return bufferview()->cursor().innerParagraph().layout()->align;
328 Dialog * createGuiParagraph(LyXView & lv)
331 GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);
332 #ifdef USE_DOCK_WIDGET
333 return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
334 Qt::TopDockWidgetArea);
336 return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
340 return new GuiParagraph(lv);
344 } // namespace frontend
347 #include "GuiParagraph_moc.cpp"