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>
42 using std::istringstream;
43 using std::ostringstream;
50 GuiParagraph::GuiParagraph(GuiView & lv)
51 : Dialog(lv, "paragraph")
54 setWindowTitle(qt_("Paragraph Settings"));
57 QGridLayout * gridLayout = new QGridLayout(this);
58 gridLayout->setMargin(0);
59 gridLayout->addWidget(this);
61 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
62 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
63 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
64 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
65 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
66 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
67 connect(linespacingValue, SIGNAL(textChanged(QString)),
68 this, SLOT(changed()));
69 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
70 connect(labelWidth, SIGNAL(textChanged(QString)),
71 this, SLOT(changed()));
74 synchronizedViewCB->setChecked(false);
75 on_synchronizedViewCB_toggled();
76 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
78 labelWidth->setWhatsThis( qt_(
79 "As described in the User Guide, the width of"
80 " this text determines the width of the label part"
81 " of each item in environments like List and"
84 " Normally, you won't need to set this,"
85 " since the largest label width of all the"
89 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
90 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
91 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
92 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
93 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
95 labelMap[LYX_ALIGN_BLOCK] = _("Justified");
96 labelMap[LYX_ALIGN_LEFT] = _("Left");
97 labelMap[LYX_ALIGN_RIGHT] = _("Right");
98 labelMap[LYX_ALIGN_CENTER] = _("Center");
100 const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
104 void GuiParagraph::on_linespacing_activated(int index)
106 linespacingValue->setEnabled(index == 4);
110 void GuiParagraph::checkAlignmentRadioButtons()
112 RadioMap::iterator it = radioMap.begin();
113 for (; it != radioMap.end(); ++it) {
114 LyXAlignment const align = it->first;
115 it->second->setEnabled(align & alignPossible());
117 if (haveMulitParSelection())
118 alignDefaultRB->setText(alignDefaultLabel);
120 alignDefaultRB->setText(alignDefaultLabel + " ("
121 + toqstr(labelMap[alignDefault()]) + ")");
125 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
127 RadioMap::const_iterator it = radioMap.begin();
128 for (;it != radioMap.end(); ++it) {
129 if (!it->second->isEnabled())
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);
160 void GuiParagraph::changed()
162 if (synchronizedViewCB->isChecked())
163 on_applyPB_clicked();
167 void GuiParagraph::on_applyPB_clicked()
169 ParagraphParameters & pp = params();
171 pp.align(getAlignmentFromDialog());
174 Spacing::Space ls = Spacing::Default;
176 switch (linespacing->currentIndex()) {
178 ls = Spacing::Default;
181 ls = Spacing::Single;
184 ls = Spacing::Onehalf;
187 ls = Spacing::Double;
191 other = fromqstr(linespacingValue->text());
195 Spacing const spacing(ls, other);
199 pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
201 pp.noindent(!indentCB->isChecked());
207 void GuiParagraph::on_restorePB_clicked()
213 void GuiParagraph::updateView()
215 on_synchronizedViewCB_toggled();
217 ParagraphParameters const & pp = params();
220 docstring const & labelwidth = pp.labelWidthString();
221 // FIXME We should not compare translated strings
222 if (labelwidth != _("Senseless with this layout!")) {
223 labelwidthGB->setEnabled(true);
224 labelWidth->setText(toqstr(labelwidth));
226 labelwidthGB->setEnabled(false);
227 labelWidth->setText("");
231 checkAlignmentRadioButtons();
232 alignmentToRadioButtons(pp.align());
235 bool const canindent = canIndent();
236 indentCB->setEnabled(canindent);
237 indentCB->setChecked(canindent && !pp.noindent());
241 Spacing const & space = pp.spacing();
242 switch (space.getSpace()) {
243 case Spacing::Single:
246 case Spacing::Onehalf:
249 case Spacing::Double:
259 linespacing->setCurrentIndex(ls);
260 if (space.getSpace() == Spacing::Other) {
261 linespacingValue->setText(toqstr(space.getValueAsString()));
262 linespacingValue->setEnabled(true);
264 linespacingValue->setText(QString());
265 linespacingValue->setEnabled(false);
270 ParagraphParameters & GuiParagraph::params()
272 if (haveMulitParSelection()) {
273 multiparsel_ = ParagraphParameters();
274 // FIXME: It would be nice to initialise the parameters that
275 // are common to all paragraphs.
279 return bufferview()->cursor().innerParagraph().params();
283 ParagraphParameters const & GuiParagraph::params() const
285 return bufferview()->cursor().innerParagraph().params();
289 void GuiParagraph::dispatchParams()
291 if (haveMulitParSelection()) {
293 multiparsel_.write(data);
294 FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
299 bufferview()->updateMetrics();
300 bufferview()->buffer().changed();
304 bool GuiParagraph::haveMulitParSelection()
306 Cursor cur = bufferview()->cursor();
307 return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
311 bool GuiParagraph::canIndent() const
313 return buffer().params().paragraph_separation ==
314 BufferParams::PARSEP_INDENT;
318 LyXAlignment GuiParagraph::alignPossible() const
320 return bufferview()->cursor().innerParagraph().layout()->alignpossible;
324 LyXAlignment GuiParagraph::alignDefault() const
326 return bufferview()->cursor().innerParagraph().layout()->align;
330 Dialog * createGuiParagraph(GuiView & lv)
333 GuiView & guiview = static_cast<GuiView &>(lv);
334 #ifdef USE_DOCK_WIDGET
335 return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
336 Qt::TopDockWidgetArea);
338 return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
342 return new GuiParagraph(lv);
346 } // namespace frontend
349 #include "GuiParagraph_moc.cpp"