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"
19 #include "BufferParams.h"
20 #include "BufferView.h"
22 #include "FuncRequest.h"
25 #include "Paragraph.h"
26 #include "ParagraphParameters.h"
27 #include "qt_helpers.h"
30 #include "support/debug.h"
31 #include "support/gettext.h"
34 #include <QCloseEvent>
36 #include <QPushButton>
45 GuiParagraph::GuiParagraph(GuiView & lv)
46 : DialogView(lv, "paragraph")
49 setWindowTitle(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);
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 labelMap[LYX_ALIGN_BLOCK] = _("Justified");
93 labelMap[LYX_ALIGN_LEFT] = _("Left");
94 labelMap[LYX_ALIGN_RIGHT] = _("Right");
95 labelMap[LYX_ALIGN_CENTER] = _("Center");
97 const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
101 void GuiParagraph::on_linespacing_activated(int index)
103 linespacingValue->setEnabled(index == 4);
107 void GuiParagraph::checkAlignmentRadioButtons()
109 RadioMap::iterator it = radioMap.begin();
110 for (; it != radioMap.end(); ++it) {
111 LyXAlignment const align = it->first;
112 it->second->setEnabled(align & alignPossible());
114 if (haveMulitParSelection())
115 alignDefaultRB->setText(alignDefaultLabel);
117 alignDefaultRB->setText(alignDefaultLabel + " ("
118 + toqstr(labelMap[alignDefault()]) + ")");
122 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
124 RadioMap::const_iterator it = radioMap.begin();
125 for (;it != radioMap.end(); ++it) {
126 if (!it->second->isEnabled())
128 it->second->blockSignals(true);
129 it->second->setChecked(align == it->first);
130 it->second->blockSignals(false);
135 LyXAlignment GuiParagraph::getAlignmentFromDialog()
137 LyXAlignment alignment = LYX_ALIGN_NONE;
138 RadioMap::const_iterator it = radioMap.begin();
139 for (; it != radioMap.end(); ++it) {
140 if (it->second->isChecked()) {
141 alignment = it->first;
149 void GuiParagraph::on_synchronizedViewCB_toggled()
151 bool in_sync = synchronizedViewCB->isChecked();
152 restorePB->setEnabled(!in_sync);
153 applyPB->setEnabled(!in_sync);
157 void GuiParagraph::changed()
159 if (synchronizedViewCB->isChecked())
160 on_applyPB_clicked();
164 void GuiParagraph::on_applyPB_clicked()
166 ParagraphParameters & pp = params();
168 pp.align(getAlignmentFromDialog());
171 Spacing::Space ls = Spacing::Default;
173 switch (linespacing->currentIndex()) {
175 ls = Spacing::Default;
178 ls = Spacing::Single;
181 ls = Spacing::Onehalf;
184 ls = Spacing::Double;
188 other = fromqstr(linespacingValue->text());
192 Spacing const spacing(ls, other);
196 pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
198 pp.noindent(!indentCB->isChecked());
204 void GuiParagraph::on_restorePB_clicked()
210 void GuiParagraph::updateView()
212 on_synchronizedViewCB_toggled();
214 ParagraphParameters const & pp = params();
217 docstring const & labelwidth = pp.labelWidthString();
218 // FIXME We should not compare translated strings
219 if (labelwidth != _("Senseless with this layout!")) {
220 labelwidthGB->setEnabled(true);
221 labelWidth->setText(toqstr(labelwidth));
223 labelwidthGB->setEnabled(false);
224 labelWidth->setText("");
228 checkAlignmentRadioButtons();
229 alignmentToRadioButtons(pp.align());
232 bool const canindent = canIndent();
233 indentCB->setEnabled(canindent);
234 indentCB->setChecked(canindent && !pp.noindent());
238 Spacing const & space = pp.spacing();
239 switch (space.getSpace()) {
240 case Spacing::Single:
243 case Spacing::Onehalf:
246 case Spacing::Double:
256 linespacing->setCurrentIndex(ls);
257 if (space.getSpace() == Spacing::Other) {
258 linespacingValue->setText(toqstr(space.getValueAsString()));
259 linespacingValue->setEnabled(true);
261 linespacingValue->setText(QString());
262 linespacingValue->setEnabled(false);
267 ParagraphParameters & GuiParagraph::params()
269 if (haveMulitParSelection()) {
270 multiparsel_ = ParagraphParameters();
271 // FIXME: It would be nice to initialise the parameters that
272 // are common to all paragraphs.
276 return bufferview()->cursor().innerParagraph().params();
280 ParagraphParameters const & GuiParagraph::params() const
282 return bufferview()->cursor().innerParagraph().params();
286 void GuiParagraph::dispatchParams()
288 if (haveMulitParSelection()) {
290 multiparsel_.write(data);
291 FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
296 bufferview()->updateMetrics();
297 bufferview()->buffer().changed();
301 bool GuiParagraph::haveMulitParSelection()
303 Cursor cur = bufferview()->cursor();
304 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
308 bool GuiParagraph::canIndent() const
310 return buffer().params().paragraph_separation ==
311 BufferParams::PARSEP_INDENT;
315 LyXAlignment GuiParagraph::alignPossible() const
317 return bufferview()->cursor().innerParagraph().layout()->alignpossible;
321 LyXAlignment GuiParagraph::alignDefault() const
323 return bufferview()->cursor().innerParagraph().layout()->align;
327 Dialog * createGuiParagraph(GuiView & lv)
330 GuiView & guiview = static_cast<GuiView &>(lv);
331 #ifdef USE_DOCK_WIDGET
332 return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
333 Qt::TopDockWidgetArea);
335 return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
339 return new GuiParagraph(lv);
343 } // namespace frontend
346 #include "GuiParagraph_moc.cpp"