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);
67 closePB->setText(qt_("&Cancel"));
69 synchronizedViewCB->setChecked(false);
72 on_synchronizedViewCB_toggled();
73 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
75 labelWidth->setWhatsThis(qt_(
76 "As described in the User Guide, the width of"
77 " this text determines the width of the label part"
78 " of each item in environments like List and"
81 " Normally, you won't need to set this,"
82 " since the largest label width of all the"
86 radioMap_[LYX_ALIGN_LAYOUT] = alignDefaultRB;
87 radioMap_[LYX_ALIGN_BLOCK] = alignJustRB;
88 radioMap_[LYX_ALIGN_LEFT] = alignLeftRB;
89 radioMap_[LYX_ALIGN_RIGHT] = alignRightRB;
90 radioMap_[LYX_ALIGN_CENTER] = alignCenterRB;
92 alignDefaultLabel_ = alignDefaultRB->text();
96 void GuiParagraph::on_linespacing_activated(int index)
98 linespacingValue->setEnabled(index == 4);
102 void GuiParagraph::checkAlignmentRadioButtons()
104 static std::map<LyXAlignment, QString> labelMap_;
105 if (labelMap_.empty()) {
106 labelMap_[LYX_ALIGN_BLOCK] = qt_("Justified");
107 labelMap_[LYX_ALIGN_LEFT] = qt_("Left");
108 labelMap_[LYX_ALIGN_RIGHT] = qt_("Right");
109 labelMap_[LYX_ALIGN_CENTER] = qt_("Center");
112 RadioMap::iterator it = radioMap_.begin();
113 for (; it != radioMap_.end(); ++it) {
114 LyXAlignment const align = it->first;
115 it->second->setEnabled(align & alignPossible());
117 if (haveMultiParSelection())
118 alignDefaultRB->setText(alignDefaultLabel_);
120 alignDefaultRB->setText(alignDefaultLabel_ + " ("
121 + labelMap_[alignDefault()] + ")");
125 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
127 RadioMap::const_iterator it = radioMap_.begin();
128 for (;it != radioMap_.end(); ++it) {
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);
155 okPB->setEnabled(!in_sync);
157 closePB->setText(qt_("&Cancel"));
159 closePB->setText(qt_("&Close"));
163 void GuiParagraph::changed()
165 if (synchronizedViewCB->isChecked())
166 on_applyPB_clicked();
170 void GuiParagraph::on_applyPB_clicked()
176 void GuiParagraph::on_okPB_clicked()
183 void GuiParagraph::on_closePB_clicked()
189 void GuiParagraph::on_restorePB_clicked()
195 void GuiParagraph::applyView()
197 ParagraphParameters & pp = params();
199 pp.align(getAlignmentFromDialog());
202 Spacing::Space ls = Spacing::Default;
204 switch (linespacing->currentIndex()) {
206 ls = Spacing::Default;
209 ls = Spacing::Single;
212 ls = Spacing::Onehalf;
215 ls = Spacing::Double;
219 other = fromqstr(linespacingValue->text());
223 Spacing const spacing(ls, other);
227 pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
229 pp.noindent(!indentCB->isChecked());
235 void GuiParagraph::updateView()
237 on_synchronizedViewCB_toggled();
239 ParagraphParameters const & pp = params();
242 docstring const & labelwidth = pp.labelWidthString();
243 // FIXME We should not compare translated strings
244 if (labelwidth != _("Senseless with this layout!")) {
245 labelwidthGB->setEnabled(true);
246 labelWidth->setText(toqstr(labelwidth));
248 labelwidthGB->setEnabled(false);
249 labelWidth->setText(QString());
253 checkAlignmentRadioButtons();
254 alignmentToRadioButtons(pp.align());
257 bool const canindent = canIndent();
258 indentCB->setEnabled(canindent);
259 indentCB->setChecked(canindent && !pp.noindent());
263 Spacing const & space = pp.spacing();
264 switch (space.getSpace()) {
265 case Spacing::Single:
268 case Spacing::Onehalf:
271 case Spacing::Double:
281 linespacing->setCurrentIndex(ls);
282 if (space.getSpace() == Spacing::Other) {
283 linespacingValue->setText(toqstr(space.getValueAsString()));
284 linespacingValue->setEnabled(true);
286 linespacingValue->setText(QString());
287 linespacingValue->setEnabled(false);
292 void GuiParagraph::enableView(bool enable)
294 indentCB->setEnabled(enable);
295 linespacing->setEnabled(enable);
296 labelWidth->setEnabled(enable);
297 synchronizedViewCB->setEnabled(enable);
298 applyPB->setEnabled(enable);
299 restorePB->setEnabled(enable);
301 synchronizedViewCB->setChecked(true);
302 RadioMap::const_iterator it = radioMap_.begin();
303 for (; it != radioMap_.end(); ++it)
304 it->second->setEnabled(enable);
308 ParagraphParameters & GuiParagraph::params()
310 if (haveMultiParSelection()) {
311 multiparsel_ = ParagraphParameters();
312 // FIXME: It would be nice to initialise the parameters that
313 // are common to all paragraphs.
317 return bufferview()->cursor().innerParagraph().params();
321 ParagraphParameters const & GuiParagraph::params() const
323 return bufferview()->cursor().innerParagraph().params();
327 void GuiParagraph::dispatchParams()
329 if (haveMultiParSelection()) {
331 multiparsel_.write(data);
332 FuncRequest const fr(getLfun(), data.str());
337 bufferview()->updateMetrics();
338 bufferview()->buffer().changed();
342 bool GuiParagraph::haveMultiParSelection()
344 Cursor cur = bufferview()->cursor();
345 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
349 bool GuiParagraph::canIndent() const
351 return buffer().params().paragraph_separation
352 == BufferParams::ParagraphIndentSeparation;
356 LyXAlignment GuiParagraph::alignPossible() const
358 return bufferview()->cursor().innerParagraph().layout().alignpossible;
362 LyXAlignment GuiParagraph::alignDefault() const
364 return bufferview()->cursor().innerParagraph().layout().align;
368 Dialog * createGuiParagraph(GuiView & lv)
370 return new GuiParagraph(lv);
374 } // namespace frontend
377 #include "GuiParagraph_moc.cpp"