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 "DialogView.h"
23 //#include "DockView.h"
24 #include "FuncRequest.h"
27 #include "Paragraph.h"
28 #include "ParagraphParameters.h"
29 #include "qt_helpers.h"
32 #include "support/debug.h"
33 #include "support/gettext.h"
36 #include <QCloseEvent>
38 #include <QPushButton>
47 GuiParagraph::GuiParagraph(GuiView & lv)
48 : DialogView(lv, "paragraph")
51 setWindowTitle(qt_("Paragraph Settings"));
53 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
54 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
55 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
56 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
57 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
58 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
59 connect(linespacingValue, SIGNAL(textChanged(QString)),
60 this, SLOT(changed()));
61 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
62 connect(labelWidth, SIGNAL(textChanged(QString)),
63 this, SLOT(changed()));
66 // On Mac it's common to have tool windows which are always in the
67 // foreground and are hidden when the main window is not focused.
68 setWindowFlags(Qt::Tool);
69 synchronizedViewCB->setChecked(true);
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 labelMap[LYX_ALIGN_BLOCK] = _("Justified");
95 labelMap[LYX_ALIGN_LEFT] = _("Left");
96 labelMap[LYX_ALIGN_RIGHT] = _("Right");
97 labelMap[LYX_ALIGN_CENTER] = _("Center");
99 const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
103 void GuiParagraph::on_linespacing_activated(int index)
105 linespacingValue->setEnabled(index == 4);
109 void GuiParagraph::checkAlignmentRadioButtons()
111 RadioMap::iterator it = radioMap.begin();
112 for (; it != radioMap.end(); ++it) {
113 LyXAlignment const align = it->first;
114 it->second->setEnabled(align & alignPossible());
116 if (haveMulitParSelection())
117 alignDefaultRB->setText(alignDefaultLabel);
119 alignDefaultRB->setText(alignDefaultLabel + " ("
120 + toqstr(labelMap[alignDefault()]) + ")");
124 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
126 RadioMap::const_iterator it = radioMap.begin();
127 for (;it != radioMap.end(); ++it) {
128 if (!it->second->isEnabled())
130 it->second->blockSignals(true);
131 it->second->setChecked(align == it->first);
132 it->second->blockSignals(false);
137 LyXAlignment GuiParagraph::getAlignmentFromDialog()
139 LyXAlignment alignment = LYX_ALIGN_NONE;
140 RadioMap::const_iterator it = radioMap.begin();
141 for (; it != radioMap.end(); ++it) {
142 if (it->second->isChecked()) {
143 alignment = it->first;
151 void GuiParagraph::on_synchronizedViewCB_toggled()
153 bool in_sync = synchronizedViewCB->isChecked();
154 restorePB->setEnabled(!in_sync);
155 applyPB->setEnabled(!in_sync);
159 void GuiParagraph::changed()
161 if (synchronizedViewCB->isChecked())
162 on_applyPB_clicked();
166 void GuiParagraph::on_applyPB_clicked()
168 ParagraphParameters & pp = params();
170 pp.align(getAlignmentFromDialog());
173 Spacing::Space ls = Spacing::Default;
175 switch (linespacing->currentIndex()) {
177 ls = Spacing::Default;
180 ls = Spacing::Single;
183 ls = Spacing::Onehalf;
186 ls = Spacing::Double;
190 other = fromqstr(linespacingValue->text());
194 Spacing const spacing(ls, other);
198 pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
200 pp.noindent(!indentCB->isChecked());
206 void GuiParagraph::on_restorePB_clicked()
212 void GuiParagraph::enableView(bool enable)
217 void GuiParagraph::updateView()
219 on_synchronizedViewCB_toggled();
221 ParagraphParameters const & pp = params();
224 docstring const & labelwidth = pp.labelWidthString();
225 // FIXME We should not compare translated strings
226 if (labelwidth != _("Senseless with this layout!")) {
227 labelwidthGB->setEnabled(true);
228 labelWidth->setText(toqstr(labelwidth));
230 labelwidthGB->setEnabled(false);
231 labelWidth->setText("");
235 checkAlignmentRadioButtons();
236 alignmentToRadioButtons(pp.align());
239 bool const canindent = canIndent();
240 indentCB->setEnabled(canindent);
241 indentCB->setChecked(canindent && !pp.noindent());
245 Spacing const & space = pp.spacing();
246 switch (space.getSpace()) {
247 case Spacing::Single:
250 case Spacing::Onehalf:
253 case Spacing::Double:
263 linespacing->setCurrentIndex(ls);
264 if (space.getSpace() == Spacing::Other) {
265 linespacingValue->setText(toqstr(space.getValueAsString()));
266 linespacingValue->setEnabled(true);
268 linespacingValue->setText(QString());
269 linespacingValue->setEnabled(false);
274 ParagraphParameters & GuiParagraph::params()
276 if (haveMulitParSelection()) {
277 multiparsel_ = ParagraphParameters();
278 // FIXME: It would be nice to initialise the parameters that
279 // are common to all paragraphs.
283 return bufferview()->cursor().innerParagraph().params();
287 ParagraphParameters const & GuiParagraph::params() const
289 return bufferview()->cursor().innerParagraph().params();
293 void GuiParagraph::dispatchParams()
295 if (haveMulitParSelection()) {
297 multiparsel_.write(data);
298 FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
303 bufferview()->updateMetrics();
304 bufferview()->buffer().changed();
308 bool GuiParagraph::haveMulitParSelection()
310 Cursor cur = bufferview()->cursor();
311 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
315 bool GuiParagraph::canIndent() const
317 return buffer().params().paragraph_separation ==
318 BufferParams::PARSEP_INDENT;
322 LyXAlignment GuiParagraph::alignPossible() const
324 return bufferview()->cursor().innerParagraph().layout()->alignpossible;
328 LyXAlignment GuiParagraph::alignDefault() const
330 return bufferview()->cursor().innerParagraph().layout()->align;
334 Dialog * createGuiParagraph(GuiView & lv)
337 GuiView & guiview = static_cast<GuiView &>(lv);
338 #ifdef USE_DOCK_WIDGET
339 return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
340 Qt::TopDockWidgetArea);
342 return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
346 return new GuiParagraph(lv);
350 } // namespace frontend
353 #include "GuiParagraph_moc.cpp"