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 "DialogView.h"
23 //#include "DockView.h"
24 #include "FuncRequest.h"
27 #include "Paragraph.h"
28 #include "ParagraphParameters.h"
29 #include "qt_helpers.h"
32 #include "support/debug.h"
33 #include "support/gettext.h"
36 #include <QCloseEvent>
38 #include <QPushButton>
42 using std::istringstream;
43 using std::ostringstream;
50 GuiParagraph::GuiParagraph(GuiView & lv)
51 : DialogView(lv, "paragraph")
54 setWindowTitle(qt_("Paragraph Settings"));
56 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
57 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
58 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
59 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
60 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
61 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
62 connect(linespacingValue, SIGNAL(textChanged(QString)),
63 this, SLOT(changed()));
64 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
65 connect(labelWidth, SIGNAL(textChanged(QString)),
66 this, SLOT(changed()));
69 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 (haveMulitParSelection())
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 if (!it->second->isEnabled())
126 it->second->blockSignals(true);
127 it->second->setChecked(align == it->first);
128 it->second->blockSignals(false);
133 LyXAlignment GuiParagraph::getAlignmentFromDialog()
135 LyXAlignment alignment = LYX_ALIGN_NONE;
136 RadioMap::const_iterator it = radioMap.begin();
137 for (; it != radioMap.end(); ++it) {
138 if (it->second->isChecked()) {
139 alignment = it->first;
147 void GuiParagraph::on_synchronizedViewCB_toggled()
149 bool in_sync = synchronizedViewCB->isChecked();
150 restorePB->setEnabled(!in_sync);
151 applyPB->setEnabled(!in_sync);
155 void GuiParagraph::changed()
157 if (synchronizedViewCB->isChecked())
158 on_applyPB_clicked();
162 void GuiParagraph::on_applyPB_clicked()
164 ParagraphParameters & pp = params();
166 pp.align(getAlignmentFromDialog());
169 Spacing::Space ls = Spacing::Default;
171 switch (linespacing->currentIndex()) {
173 ls = Spacing::Default;
176 ls = Spacing::Single;
179 ls = Spacing::Onehalf;
182 ls = Spacing::Double;
186 other = fromqstr(linespacingValue->text());
190 Spacing const spacing(ls, other);
194 pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
196 pp.noindent(!indentCB->isChecked());
202 void GuiParagraph::on_restorePB_clicked()
208 void GuiParagraph::enableView(bool enable)
213 void GuiParagraph::updateView()
215 on_synchronizedViewCB_toggled();
217 ParagraphParameters const & pp = params();
220 docstring const & labelwidth = pp.labelWidthString();
221 // FIXME We should not compare translated strings
222 if (labelwidth != _("Senseless with this layout!")) {
223 labelwidthGB->setEnabled(true);
224 labelWidth->setText(toqstr(labelwidth));
226 labelwidthGB->setEnabled(false);
227 labelWidth->setText("");
231 checkAlignmentRadioButtons();
232 alignmentToRadioButtons(pp.align());
235 bool const canindent = canIndent();
236 indentCB->setEnabled(canindent);
237 indentCB->setChecked(canindent && !pp.noindent());
241 Spacing const & space = pp.spacing();
242 switch (space.getSpace()) {
243 case Spacing::Single:
246 case Spacing::Onehalf:
249 case Spacing::Double:
259 linespacing->setCurrentIndex(ls);
260 if (space.getSpace() == Spacing::Other) {
261 linespacingValue->setText(toqstr(space.getValueAsString()));
262 linespacingValue->setEnabled(true);
264 linespacingValue->setText(QString());
265 linespacingValue->setEnabled(false);
270 ParagraphParameters & GuiParagraph::params()
272 if (haveMulitParSelection()) {
273 multiparsel_ = ParagraphParameters();
274 // FIXME: It would be nice to initialise the parameters that
275 // are common to all paragraphs.
279 return bufferview()->cursor().innerParagraph().params();
283 ParagraphParameters const & GuiParagraph::params() const
285 return bufferview()->cursor().innerParagraph().params();
289 void GuiParagraph::dispatchParams()
291 if (haveMulitParSelection()) {
293 multiparsel_.write(data);
294 FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
299 bufferview()->updateMetrics();
300 bufferview()->buffer().changed();
304 bool GuiParagraph::haveMulitParSelection()
306 Cursor cur = bufferview()->cursor();
307 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
311 bool GuiParagraph::canIndent() const
313 return buffer().params().paragraph_separation ==
314 BufferParams::PARSEP_INDENT;
318 LyXAlignment GuiParagraph::alignPossible() const
320 return bufferview()->cursor().innerParagraph().layout()->alignpossible;
324 LyXAlignment GuiParagraph::alignDefault() const
326 return bufferview()->cursor().innerParagraph().layout()->align;
330 Dialog * createGuiParagraph(GuiView & lv)
333 GuiView & guiview = static_cast<GuiView &>(lv);
334 #ifdef USE_DOCK_WIDGET
335 return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
336 Qt::TopDockWidgetArea);
338 return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
342 return new GuiParagraph(lv);
346 } // namespace frontend
349 #include "GuiParagraph_moc.cpp"