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", qt_("Paragraph Settings"))
50 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
51 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
52 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
53 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
54 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
55 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
56 connect(linespacingValue, SIGNAL(textChanged(QString)),
57 this, SLOT(changed()));
58 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
59 connect(labelWidth, SIGNAL(textChanged(QString)),
60 this, SLOT(changed()));
63 // On Mac it's common to have tool windows which are always in the
64 // foreground and are hidden when the main window is not focused.
65 setWindowFlags(Qt::Tool);
66 synchronizedViewCB->setChecked(true);
68 synchronizedViewCB->setChecked(false);
71 on_synchronizedViewCB_toggled();
72 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
74 labelWidth->setWhatsThis( qt_(
75 "As described in the User Guide, the width of"
76 " this text determines the width of the label part"
77 " of each item in environments like List and"
80 " Normally, you won't need to set this,"
81 " since the largest label width of all the"
85 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
86 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
87 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
88 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
89 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
91 labelMap[LYX_ALIGN_BLOCK] = _("Justified");
92 labelMap[LYX_ALIGN_LEFT] = _("Left");
93 labelMap[LYX_ALIGN_RIGHT] = _("Right");
94 labelMap[LYX_ALIGN_CENTER] = _("Center");
96 const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
100 void GuiParagraph::on_linespacing_activated(int index)
102 linespacingValue->setEnabled(index == 4);
106 void GuiParagraph::checkAlignmentRadioButtons()
108 RadioMap::iterator it = radioMap.begin();
109 for (; it != radioMap.end(); ++it) {
110 LyXAlignment const align = it->first;
111 it->second->setEnabled(align & alignPossible());
113 if (haveMulitParSelection())
114 alignDefaultRB->setText(alignDefaultLabel);
116 alignDefaultRB->setText(alignDefaultLabel + " ("
117 + toqstr(labelMap[alignDefault()]) + ")");
121 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
123 RadioMap::const_iterator it = radioMap.begin();
124 for (;it != radioMap.end(); ++it) {
125 if (!it->second->isEnabled())
127 it->second->blockSignals(true);
128 it->second->setChecked(align == it->first);
129 it->second->blockSignals(false);
134 LyXAlignment GuiParagraph::getAlignmentFromDialog()
136 LyXAlignment alignment = LYX_ALIGN_NONE;
137 RadioMap::const_iterator it = radioMap.begin();
138 for (; it != radioMap.end(); ++it) {
139 if (it->second->isChecked()) {
140 alignment = it->first;
148 void GuiParagraph::on_synchronizedViewCB_toggled()
150 bool in_sync = synchronizedViewCB->isChecked();
151 restorePB->setEnabled(!in_sync);
152 applyPB->setEnabled(!in_sync);
156 void GuiParagraph::changed()
158 if (synchronizedViewCB->isChecked())
159 on_applyPB_clicked();
163 void GuiParagraph::on_applyPB_clicked()
165 ParagraphParameters & pp = params();
167 pp.align(getAlignmentFromDialog());
170 Spacing::Space ls = Spacing::Default;
172 switch (linespacing->currentIndex()) {
174 ls = Spacing::Default;
177 ls = Spacing::Single;
180 ls = Spacing::Onehalf;
183 ls = Spacing::Double;
187 other = fromqstr(linespacingValue->text());
191 Spacing const spacing(ls, other);
195 pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
197 pp.noindent(!indentCB->isChecked());
203 void GuiParagraph::on_restorePB_clicked()
209 void GuiParagraph::updateView()
211 on_synchronizedViewCB_toggled();
213 ParagraphParameters const & pp = params();
216 docstring const & labelwidth = pp.labelWidthString();
217 // FIXME We should not compare translated strings
218 if (labelwidth != _("Senseless with this layout!")) {
219 labelwidthGB->setEnabled(true);
220 labelWidth->setText(toqstr(labelwidth));
222 labelwidthGB->setEnabled(false);
223 labelWidth->setText("");
227 checkAlignmentRadioButtons();
228 alignmentToRadioButtons(pp.align());
231 bool const canindent = canIndent();
232 indentCB->setEnabled(canindent);
233 indentCB->setChecked(canindent && !pp.noindent());
237 Spacing const & space = pp.spacing();
238 switch (space.getSpace()) {
239 case Spacing::Single:
242 case Spacing::Onehalf:
245 case Spacing::Double:
255 linespacing->setCurrentIndex(ls);
256 if (space.getSpace() == Spacing::Other) {
257 linespacingValue->setText(toqstr(space.getValueAsString()));
258 linespacingValue->setEnabled(true);
260 linespacingValue->setText(QString());
261 linespacingValue->setEnabled(false);
266 void GuiParagraph::enableView(bool enable)
268 indentCB->setEnabled(enable);
269 linespacing->setEnabled(enable);
270 labelWidth->setEnabled(enable);
271 synchronizedViewCB->setEnabled(enable);
272 applyPB->setEnabled(enable);
273 restorePB->setEnabled(enable);
275 synchronizedViewCB->setChecked(true);
276 RadioMap::const_iterator it = radioMap.begin();
277 for (; it != radioMap.end(); ++it)
278 it->second->setEnabled(enable);
282 ParagraphParameters & GuiParagraph::params()
284 if (haveMulitParSelection()) {
285 multiparsel_ = ParagraphParameters();
286 // FIXME: It would be nice to initialise the parameters that
287 // are common to all paragraphs.
291 return bufferview()->cursor().innerParagraph().params();
295 ParagraphParameters const & GuiParagraph::params() const
297 return bufferview()->cursor().innerParagraph().params();
301 void GuiParagraph::dispatchParams()
303 if (haveMulitParSelection()) {
305 multiparsel_.write(data);
306 FuncRequest const fr(getLfun(), data.str());
311 bufferview()->updateMetrics();
312 bufferview()->buffer().changed();
316 bool GuiParagraph::haveMulitParSelection()
318 Cursor cur = bufferview()->cursor();
319 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
323 bool GuiParagraph::canIndent() const
325 return buffer().params().paragraph_separation ==
326 BufferParams::PARSEP_INDENT;
330 LyXAlignment GuiParagraph::alignPossible() const
332 return bufferview()->cursor().innerParagraph().layout()->alignpossible;
336 LyXAlignment GuiParagraph::alignDefault() const
338 return bufferview()->cursor().innerParagraph().layout()->align;
342 Dialog * createGuiParagraph(GuiView & lv)
345 GuiView & guiview = static_cast<GuiView &>(lv);
346 #ifdef USE_DOCK_WIDGET
347 return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
348 Qt::TopDockWidgetArea);
350 return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
354 return new GuiParagraph(lv);
358 } // namespace frontend
361 #include "GuiParagraph_moc.cpp"