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()
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()
199 if (haveMultiParSelection()) {
200 // FIXME: in case of multi-paragraph selection, it would be nice to
201 // initialise the parameters that are common to all paragraphs.
202 params_ = ParagraphParameters();
204 params_ = bufferview()->cursor().innerParagraph().params();
207 params_.align(getAlignmentFromDialog());
210 Spacing::Space ls = Spacing::Default;
212 switch (linespacing->currentIndex()) {
214 ls = Spacing::Default;
217 ls = Spacing::Single;
220 ls = Spacing::Onehalf;
223 ls = Spacing::Double;
227 other = fromqstr(linespacingValue->text());
231 Spacing const spacing(ls, other);
232 params_.spacing(spacing);
235 params_.labelWidthString(qstring_to_ucs4(labelWidth->text()));
237 params_.noindent(!indentCB->isChecked());
243 void GuiParagraph::updateView()
245 on_synchronizedViewCB_toggled();
247 ParagraphParameters const & pp = params();
250 docstring const & labelwidth = pp.labelWidthString();
251 // FIXME We should not compare translated strings
252 if (labelwidth != _("Senseless with this layout!")) {
253 labelwidthGB->setEnabled(true);
254 labelWidth->setText(toqstr(labelwidth));
256 labelwidthGB->setEnabled(false);
257 labelWidth->setText(QString());
261 checkAlignmentRadioButtons();
262 alignmentToRadioButtons(pp.align());
265 bool const canindent = canIndent();
266 indentCB->setEnabled(canindent);
267 indentCB->setChecked(canindent && !pp.noindent());
271 Spacing const & space = pp.spacing();
272 switch (space.getSpace()) {
273 case Spacing::Single:
276 case Spacing::Onehalf:
279 case Spacing::Double:
289 linespacing->setCurrentIndex(ls);
290 if (space.getSpace() == Spacing::Other) {
291 linespacingValue->setText(toqstr(space.getValueAsString()));
292 linespacingValue->setEnabled(true);
294 linespacingValue->setText(QString());
295 linespacingValue->setEnabled(false);
300 void GuiParagraph::enableView(bool enable)
302 indentCB->setEnabled(enable);
303 linespacing->setEnabled(enable);
304 labelWidth->setEnabled(enable);
305 synchronizedViewCB->setEnabled(enable);
306 applyPB->setEnabled(enable);
307 restorePB->setEnabled(enable);
309 synchronizedViewCB->setChecked(true);
310 RadioMap::const_iterator it = radioMap_.begin();
311 for (; it != radioMap_.end(); ++it)
312 it->second->setEnabled(enable);
316 ParagraphParameters const & GuiParagraph::params() const
318 if (haveMultiParSelection()) {
319 // FIXME: in case of multi-paragraph selection, it would be nice to
320 // initialise the parameters that are common to all paragraphs.
321 params_ = ParagraphParameters();
324 return bufferview()->cursor().innerParagraph().params();
328 void GuiParagraph::dispatchParams()
332 FuncRequest const fr(getLfun(), data.str());
337 bool GuiParagraph::haveMultiParSelection() const
339 Cursor const & cur = bufferview()->cursor();
340 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
344 bool GuiParagraph::canIndent() const
346 return buffer().params().paragraph_separation
347 == BufferParams::ParagraphIndentSeparation;
351 LyXAlignment GuiParagraph::alignPossible() const
353 return bufferview()->cursor().innerParagraph().layout().alignpossible;
357 LyXAlignment GuiParagraph::alignDefault() const
359 return bufferview()->cursor().innerParagraph().layout().align;
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 "GuiParagraph_moc.cpp"