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 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
77 labelWidth->setWhatsThis(qt_(
78 "As described in the User Guide, the width of"
79 " this text determines the width of the label part"
80 " of each item in environments like List and"
83 " Normally, you won't need to set this,"
84 " since the largest label width of all the"
88 radioMap_[LYX_ALIGN_LAYOUT] = alignDefaultRB;
89 radioMap_[LYX_ALIGN_BLOCK] = alignJustRB;
90 radioMap_[LYX_ALIGN_LEFT] = alignLeftRB;
91 radioMap_[LYX_ALIGN_RIGHT] = alignRightRB;
92 radioMap_[LYX_ALIGN_CENTER] = alignCenterRB;
94 alignDefaultLabel_ = alignDefaultRB->text();
98 void GuiParagraph::on_linespacing_activated(int index)
100 linespacingValue->setEnabled(index == 4);
104 void GuiParagraph::checkAlignmentRadioButtons()
106 static std::map<LyXAlignment, QString> labelMap_;
107 if (labelMap_.empty()) {
108 labelMap_[LYX_ALIGN_BLOCK] = qt_("Justified");
109 labelMap_[LYX_ALIGN_LEFT] = qt_("Left");
110 labelMap_[LYX_ALIGN_RIGHT] = qt_("Right");
111 labelMap_[LYX_ALIGN_CENTER] = qt_("Center");
114 RadioMap::iterator it = radioMap_.begin();
115 for (; it != radioMap_.end(); ++it) {
116 LyXAlignment const align = it->first;
117 it->second->setEnabled(align & alignPossible());
119 if (haveMultiParSelection())
120 alignDefaultRB->setText(alignDefaultLabel_);
122 alignDefaultRB->setText(alignDefaultLabel_ + " ("
123 + labelMap_[alignDefault()] + ")");
127 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
129 RadioMap::const_iterator it = radioMap_.begin();
130 for (;it != radioMap_.end(); ++it) {
131 it->second->blockSignals(true);
132 it->second->setChecked(align == it->first);
133 it->second->blockSignals(false);
138 LyXAlignment GuiParagraph::getAlignmentFromDialog() const
140 LyXAlignment alignment = LYX_ALIGN_NONE;
141 RadioMap::const_iterator it = radioMap_.begin();
142 for (; it != radioMap_.end(); ++it) {
143 if (it->second->isChecked()) {
144 alignment = it->first;
152 void GuiParagraph::on_synchronizedViewCB_toggled()
154 bool in_sync = synchronizedViewCB->isChecked();
155 restorePB->setEnabled(!in_sync);
156 applyPB->setEnabled(!in_sync);
157 okPB->setEnabled(!in_sync);
159 closePB->setText(qt_("&Cancel"));
161 closePB->setText(qt_("&Close"));
165 void GuiParagraph::changed()
167 if (synchronizedViewCB->isChecked())
168 on_applyPB_clicked();
172 void GuiParagraph::on_applyPB_clicked()
178 void GuiParagraph::on_okPB_clicked()
185 void GuiParagraph::on_closePB_clicked()
191 void GuiParagraph::on_restorePB_clicked()
197 void GuiParagraph::applyView()
201 params_.align(getAlignmentFromDialog());
204 Spacing::Space ls = Spacing::Default;
206 switch (linespacing->currentIndex()) {
208 ls = Spacing::Default;
211 ls = Spacing::Single;
214 ls = Spacing::Onehalf;
217 ls = Spacing::Double;
221 other = widgetToDoubleStr(linespacingValue);
225 Spacing const spacing(ls, other);
226 params_.spacing(spacing);
229 params_.labelWidthString(qstring_to_ucs4(labelWidth->text()));
231 params_.noindent(!indentCB->isChecked());
237 void GuiParagraph::updateView()
239 on_synchronizedViewCB_toggled();
241 ParagraphParameters const & pp = params();
244 docstring const & labelwidth = pp.labelWidthString();
245 if (hasLabelwidth()) {
246 labelwidthGB->setEnabled(true);
247 labelWidth->setText(toqstr(labelwidth));
249 labelwidthGB->setEnabled(false);
250 labelWidth->setText(QString());
254 checkAlignmentRadioButtons();
255 alignmentToRadioButtons(pp.align());
258 bool const canindent = canIndent();
259 indentCB->setEnabled(canindent);
260 indentCB->setChecked(canindent && !pp.noindent());
264 Spacing const & space = pp.spacing();
265 switch (space.getSpace()) {
266 case Spacing::Single:
269 case Spacing::Onehalf:
272 case Spacing::Double:
282 linespacing->setCurrentIndex(ls);
283 if (space.getSpace() == Spacing::Other) {
284 doubleToWidget(linespacingValue, space.getValue());
285 linespacingValue->setEnabled(true);
287 linespacingValue->setText(QString());
288 linespacingValue->setEnabled(false);
293 void GuiParagraph::enableView(bool enable)
295 indentCB->setEnabled(enable);
296 linespacing->setEnabled(enable);
297 labelWidth->setEnabled(enable);
298 synchronizedViewCB->setEnabled(enable);
299 applyPB->setEnabled(enable);
300 restorePB->setEnabled(enable);
302 synchronizedViewCB->setChecked(true);
303 RadioMap::const_iterator it = radioMap_.begin();
304 for (; it != radioMap_.end(); ++it)
305 it->second->setEnabled(enable);
309 ParagraphParameters const & GuiParagraph::params() const
311 if (haveMultiParSelection()) {
312 // FIXME: in case of multi-paragraph selection, it would be nice to
313 // initialise the parameters that are common to all paragraphs.
314 static ParagraphParameters empty;
317 return bufferview()->cursor().innerParagraph().params();
321 void GuiParagraph::dispatchParams()
325 FuncRequest const fr(getLfun(), data.str());
330 bool GuiParagraph::haveMultiParSelection() const
332 Cursor const & cur = bufferview()->cursor();
333 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
337 bool GuiParagraph::canIndent() const
339 return buffer().params().paragraph_separation
340 == BufferParams::ParagraphIndentSeparation;
344 LyXAlignment GuiParagraph::alignPossible() const
346 return bufferview()->cursor().innerParagraph().layout().alignpossible;
350 LyXAlignment GuiParagraph::alignDefault() const
352 return bufferview()->cursor().innerParagraph().layout().align;
356 bool GuiParagraph::hasLabelwidth() const
358 Layout layout = bufferview()->cursor().innerParagraph().layout();
359 return (layout.margintype == MARGIN_MANUAL
360 || layout.latextype == LATEX_BIB_ENVIRONMENT);
364 void GuiParagraph::saveSession() const
366 Dialog::saveSession();
368 settings.setValue(sessionKey() + "/autoapply", synchronizedViewCB->isChecked());
372 void GuiParagraph::restoreSession()
374 Dialog::restoreSession();
376 synchronizedViewCB->setChecked(
377 settings.value(sessionKey() + "/autoapply").toBool());
381 Dialog * createGuiParagraph(GuiView & lv)
383 return new GuiParagraph(lv);
387 } // namespace frontend
390 #include "moc_GuiParagraph.cpp"