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>
47 GuiParagraph::GuiParagraph(GuiView & lv)
48 : DialogView(lv, "paragraph", qt_("Paragraph Settings"))
52 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
53 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
54 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
55 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
56 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
57 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
58 connect(linespacingValue, SIGNAL(textChanged(QString)),
59 this, SLOT(changed()));
60 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
61 connect(labelWidth, SIGNAL(textChanged(QString)),
62 this, SLOT(changed()));
65 // On Mac it's common to have tool windows which are always in the
66 // foreground and are hidden when the main window is not focused.
67 setWindowFlags(Qt::Tool);
68 synchronizedViewCB->setChecked(true);
69 closePB->setText(qt_("&Cancel"));
71 synchronizedViewCB->setChecked(false);
74 on_synchronizedViewCB_toggled();
75 QDoubleValidator * val = new QDoubleValidator(linespacingValue);
76 val->setNotation(QDoubleValidator::StandardNotation);
77 linespacingValue->setValidator(val);
79 labelWidth->setWhatsThis(qt_(
80 "As described in the User Guide, the width of"
81 " this text determines the width of the label part"
82 " of each item in environments like List and"
85 " Normally, you won't need to set this,"
86 " since the largest label width of all the"
90 radioMap_[LYX_ALIGN_LAYOUT] = alignDefaultRB;
91 radioMap_[LYX_ALIGN_BLOCK] = alignJustRB;
92 radioMap_[LYX_ALIGN_LEFT] = alignLeftRB;
93 radioMap_[LYX_ALIGN_RIGHT] = alignRightRB;
94 radioMap_[LYX_ALIGN_CENTER] = alignCenterRB;
96 alignDefaultLabel_ = alignDefaultRB->text();
100 void GuiParagraph::on_linespacing_activated(int index)
102 linespacingValue->setEnabled(index == 4);
106 void GuiParagraph::checkAlignmentRadioButtons()
108 static std::map<LyXAlignment, QString> labelMap_;
109 if (labelMap_.empty()) {
110 labelMap_[LYX_ALIGN_BLOCK] = qt_("Justified");
111 labelMap_[LYX_ALIGN_LEFT] = qt_("Left");
112 labelMap_[LYX_ALIGN_RIGHT] = qt_("Right");
113 labelMap_[LYX_ALIGN_CENTER] = qt_("Center");
116 RadioMap::iterator it = radioMap_.begin();
117 for (; it != radioMap_.end(); ++it) {
118 LyXAlignment const align = it->first;
119 it->second->setEnabled(align & alignPossible());
121 if (haveMultiParSelection())
122 alignDefaultRB->setText(alignDefaultLabel_);
124 alignDefaultRB->setText(alignDefaultLabel_ + " ("
125 + labelMap_[alignDefault()] + ")");
129 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
131 RadioMap::const_iterator it = radioMap_.begin();
132 for (;it != radioMap_.end(); ++it) {
133 it->second->blockSignals(true);
134 it->second->setChecked(align == it->first);
135 it->second->blockSignals(false);
140 LyXAlignment GuiParagraph::getAlignmentFromDialog() const
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);
159 okPB->setEnabled(!in_sync);
161 closePB->setText(qt_("&Cancel"));
163 closePB->setText(qt_("&Close"));
167 void GuiParagraph::changed()
170 if (synchronizedViewCB->isChecked()
171 && !linespacingValue->text().endsWith(loc.decimalPoint())
172 && linespacingValue->hasAcceptableInput())
173 on_applyPB_clicked();
177 void GuiParagraph::on_applyPB_clicked()
183 void GuiParagraph::on_okPB_clicked()
190 void GuiParagraph::on_closePB_clicked()
196 void GuiParagraph::on_restorePB_clicked()
202 void GuiParagraph::applyView()
206 params_.align(getAlignmentFromDialog());
209 Spacing::Space ls = Spacing::Default;
211 switch (linespacing->currentIndex()) {
213 ls = Spacing::Default;
216 ls = Spacing::Single;
219 ls = Spacing::Onehalf;
222 ls = Spacing::Double;
226 other = widgetToDoubleStr(linespacingValue);
230 Spacing const spacing(ls, other);
231 params_.spacing(spacing);
234 params_.labelWidthString(qstring_to_ucs4(labelWidth->text()));
236 params_.noindent(!indentCB->isChecked());
242 void GuiParagraph::updateView()
244 on_synchronizedViewCB_toggled();
246 ParagraphParameters const & pp = params();
249 docstring const & labelwidth = pp.labelWidthString();
250 if (hasLabelwidth()) {
251 labelwidthGB->setEnabled(true);
252 labelWidth->setText(toqstr(labelwidth));
254 labelwidthGB->setEnabled(false);
255 labelWidth->setText(QString());
259 checkAlignmentRadioButtons();
260 alignmentToRadioButtons(pp.align());
263 bool const canindent = canIndent();
264 indentCB->setEnabled(canindent);
265 indentCB->setChecked(canindent && !pp.noindent());
269 Spacing const & space = pp.spacing();
270 switch (space.getSpace()) {
271 case Spacing::Single:
274 case Spacing::Onehalf:
277 case Spacing::Double:
287 linespacing->setCurrentIndex(ls);
288 if (space.getSpace() == Spacing::Other) {
289 doubleToWidget(linespacingValue, space.getValue());
290 linespacingValue->setEnabled(true);
292 linespacingValue->setText(QString());
293 linespacingValue->setEnabled(false);
298 void GuiParagraph::enableView(bool enable)
300 indentCB->setEnabled(enable);
301 linespacing->setEnabled(enable);
302 labelWidth->setEnabled(enable);
303 synchronizedViewCB->setEnabled(enable);
304 applyPB->setEnabled(enable);
305 restorePB->setEnabled(enable);
307 synchronizedViewCB->setChecked(true);
308 RadioMap::const_iterator it = radioMap_.begin();
309 for (; it != radioMap_.end(); ++it)
310 it->second->setEnabled(enable);
314 ParagraphParameters const & GuiParagraph::params() const
316 if (haveMultiParSelection()) {
317 // FIXME: in case of multi-paragraph selection, it would be nice to
318 // initialise the parameters that are common to all paragraphs.
319 static ParagraphParameters const empty;
322 return bufferview()->cursor().innerParagraph().params();
326 void GuiParagraph::dispatchParams()
330 FuncRequest const fr(getLfun(), data.str());
335 bool GuiParagraph::haveMultiParSelection() const
337 Cursor const & cur = bufferview()->cursor();
338 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
342 bool GuiParagraph::canIndent() const
344 Layout const lay = bufferview()->cursor().innerParagraph().layout();
345 if (buffer().params().paragraph_separation
346 == BufferParams::ParagraphIndentSeparation)
347 return (lay.toggle_indent != ITOGGLE_NEVER);
348 return (lay.toggle_indent == ITOGGLE_ALWAYS);
352 LyXAlignment GuiParagraph::alignPossible() const
354 return bufferview()->cursor().innerParagraph().layout().alignpossible;
358 LyXAlignment GuiParagraph::alignDefault() const
360 return bufferview()->cursor().innerParagraph().layout().align;
364 bool GuiParagraph::hasLabelwidth() const
366 Layout layout = bufferview()->cursor().innerParagraph().layout();
367 return (layout.margintype == MARGIN_MANUAL
368 || layout.latextype == LATEX_BIB_ENVIRONMENT);
372 void GuiParagraph::saveSession() const
374 Dialog::saveSession();
376 settings.setValue(sessionKey() + "/autoapply", synchronizedViewCB->isChecked());
380 void GuiParagraph::restoreSession()
382 Dialog::restoreSession();
384 synchronizedViewCB->setChecked(
385 settings.value(sessionKey() + "/autoapply").toBool());
389 Dialog * createGuiParagraph(GuiView & lv)
391 return new GuiParagraph(lv);
395 } // namespace frontend
398 #include "moc_GuiParagraph.cpp"