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/gettext.h"
35 #include <QPushButton>
46 GuiParagraph::GuiParagraph(GuiView & lv)
47 : DialogView(lv, "paragraph", qt_("Paragraph Settings"))
51 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
52 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
53 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
54 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
55 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
56 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
57 connect(linespacingValue, SIGNAL(textChanged(QString)),
58 this, SLOT(changed()));
59 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
60 connect(labelWidth, SIGNAL(textChanged(QString)),
61 this, SLOT(changed()));
64 // On Mac it's common to have tool windows which are always in the
65 // foreground and are hidden when the main window is not focused.
66 setWindowFlags(Qt::Tool);
67 synchronizedViewCB->setChecked(true);
68 closePB->setText(qt_("&Cancel"));
70 synchronizedViewCB->setChecked(false);
73 on_synchronizedViewCB_toggled();
74 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
76 labelWidth->setWhatsThis(qt_(
77 "As described in the User Guide, the width of"
78 " this text determines the width of the label part"
79 " of each item in environments like List and"
82 " Normally, you won't need to set this,"
83 " since the largest label width of all the"
87 radioMap_[LYX_ALIGN_LAYOUT] = alignDefaultRB;
88 radioMap_[LYX_ALIGN_BLOCK] = alignJustRB;
89 radioMap_[LYX_ALIGN_LEFT] = alignLeftRB;
90 radioMap_[LYX_ALIGN_RIGHT] = alignRightRB;
91 radioMap_[LYX_ALIGN_CENTER] = alignCenterRB;
93 alignDefaultLabel_ = alignDefaultRB->text();
97 void GuiParagraph::on_linespacing_activated(int index)
99 linespacingValue->setEnabled(index == 4);
103 void GuiParagraph::checkAlignmentRadioButtons()
105 static std::map<LyXAlignment, QString> labelMap_;
106 if (labelMap_.empty()) {
107 labelMap_[LYX_ALIGN_BLOCK] = qt_("Justified");
108 labelMap_[LYX_ALIGN_LEFT] = qt_("Left");
109 labelMap_[LYX_ALIGN_RIGHT] = qt_("Right");
110 labelMap_[LYX_ALIGN_CENTER] = qt_("Center");
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 (haveMultiParSelection())
119 alignDefaultRB->setText(alignDefaultLabel_);
121 alignDefaultRB->setText(alignDefaultLabel_ + " ("
122 + labelMap_[alignDefault()] + ")");
126 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
128 RadioMap::const_iterator it = radioMap_.begin();
129 for (;it != radioMap_.end(); ++it) {
130 it->second->blockSignals(true);
131 it->second->setChecked(align == it->first);
132 it->second->blockSignals(false);
137 LyXAlignment GuiParagraph::getAlignmentFromDialog() const
139 LyXAlignment alignment = LYX_ALIGN_NONE;
140 RadioMap::const_iterator it = radioMap_.begin();
141 for (; it != radioMap_.end(); ++it) {
142 if (it->second->isChecked()) {
143 alignment = it->first;
151 void GuiParagraph::on_synchronizedViewCB_toggled()
153 bool in_sync = synchronizedViewCB->isChecked();
154 restorePB->setEnabled(!in_sync);
155 applyPB->setEnabled(!in_sync);
156 okPB->setEnabled(!in_sync);
158 closePB->setText(qt_("&Cancel"));
160 closePB->setText(qt_("&Close"));
164 void GuiParagraph::changed()
166 if (synchronizedViewCB->isChecked())
167 on_applyPB_clicked();
171 void GuiParagraph::on_applyPB_clicked()
177 void GuiParagraph::on_okPB_clicked()
184 void GuiParagraph::on_closePB_clicked()
190 void GuiParagraph::on_restorePB_clicked()
196 void GuiParagraph::applyView()
200 params_.align(getAlignmentFromDialog());
203 Spacing::Space ls = Spacing::Default;
205 switch (linespacing->currentIndex()) {
207 ls = Spacing::Default;
210 ls = Spacing::Single;
213 ls = Spacing::Onehalf;
216 ls = Spacing::Double;
220 other = widgetToDoubleStr(linespacingValue);
224 Spacing const spacing(ls, other);
225 params_.spacing(spacing);
228 params_.labelWidthString(qstring_to_ucs4(labelWidth->text()));
230 params_.noindent(!indentCB->isChecked());
236 void GuiParagraph::updateView()
238 on_synchronizedViewCB_toggled();
240 ParagraphParameters const & pp = params();
243 docstring const & labelwidth = pp.labelWidthString();
244 if (hasLabelwidth()) {
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 doubleToWidget(linespacingValue, space.getValue());
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 const & GuiParagraph::params() const
310 if (haveMultiParSelection()) {
311 // FIXME: in case of multi-paragraph selection, it would be nice to
312 // initialise the parameters that are common to all paragraphs.
313 static ParagraphParameters empty;
316 return bufferview()->cursor().innerParagraph().params();
320 void GuiParagraph::dispatchParams()
324 FuncRequest const fr(getLfun(), data.str());
329 bool GuiParagraph::haveMultiParSelection() const
331 Cursor const & cur = bufferview()->cursor();
332 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
336 bool GuiParagraph::canIndent() const
338 return buffer().params().paragraph_separation
339 == BufferParams::ParagraphIndentSeparation;
343 LyXAlignment GuiParagraph::alignPossible() const
345 return bufferview()->cursor().innerParagraph().layout().alignpossible;
349 LyXAlignment GuiParagraph::alignDefault() const
351 return bufferview()->cursor().innerParagraph().layout().align;
355 bool GuiParagraph::hasLabelwidth() const
357 Layout layout = bufferview()->cursor().innerParagraph().layout();
358 return (layout.margintype == MARGIN_MANUAL
359 || layout.latextype == LATEX_BIB_ENVIRONMENT);
363 void GuiParagraph::saveSession() const
365 Dialog::saveSession();
367 settings.setValue(sessionKey() + "/autoapply", synchronizedViewCB->isChecked());
371 void GuiParagraph::restoreSession()
373 Dialog::restoreSession();
375 synchronizedViewCB->setChecked(
376 settings.value(sessionKey() + "/autoapply").toBool());
380 Dialog * createGuiParagraph(GuiView & lv)
382 return new GuiParagraph(lv);
386 } // namespace frontend
389 #include "moc_GuiParagraph.cpp"