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
10 * Full author contact details are available in file CREDITS.
15 #include "GuiParagraph.h"
16 #include "qt_helpers.h"
18 #include "ControlParagraph.h"
21 #include "frontend_helpers.h"
23 #include "ParagraphParameters.h"
26 #include "DialogView.h"
30 #include <QCloseEvent>
32 #include <QPushButton>
34 #include <boost/current_function.hpp>
42 GuiParagraph::GuiParagraph(ControlParagraph & controller, QWidget * parent)
43 : QWidget(parent), controller_(controller)
46 setWindowTitle(qt_("Paragraph Settings"));
48 connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
49 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
50 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
51 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
52 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
53 connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
54 connect(linespacingValue, SIGNAL(textChanged(const QString &)),
55 this, SLOT(changed()));
56 connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
57 connect(labelWidth, SIGNAL(textChanged(const QString &)),
58 this, SLOT(changed()));
61 synchronizedViewCB->setChecked(false);
62 on_synchronizedViewCB_toggled();
63 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
65 labelWidth->setWhatsThis( qt_(
66 "As described in the User Guide, the width of"
67 " this text determines the width of the label part"
68 " of each item in environments like List and"
71 " Normally, you won't need to set this,"
72 " since the largest label width of all the"
76 radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
77 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
78 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
79 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
80 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
82 const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
86 void GuiParagraph::on_linespacing_activated(int index)
88 linespacingValue->setEnabled(index == 4);
92 void GuiParagraph::checkAlignmentRadioButtons() {
93 LyXAlignment const alignPossible = controller_.alignPossible();
95 RadioMap::iterator it = radioMap.begin();
96 for (; it != radioMap.end(); ++it) {
97 LyXAlignment const align = it->first;
98 it->second->setEnabled(align & alignPossible);
100 if (controller_.haveMulitParSelection())
101 alignDefaultRB->setText(alignDefaultLabel);
103 alignDefaultRB->setText(alignDefaultLabel + " ("
104 + radioMap[controller_.alignDefault()]->text() + ")");
108 void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
110 RadioMap::const_iterator it = radioMap.begin();
111 for (;it != radioMap.end(); ++it) {
112 if (!it->second->isEnabled())
114 it->second->blockSignals(true);
115 it->second->setChecked(align == it->first);
116 it->second->blockSignals(false);
121 LyXAlignment GuiParagraph::getAlignmentFromDialog()
123 LyXAlignment alignment = LYX_ALIGN_NONE;
124 RadioMap::const_iterator it = radioMap.begin();
125 for (; it != radioMap.end(); ++it) {
126 if (it->second->isChecked()) {
127 alignment = it->first;
135 void GuiParagraph::on_synchronizedViewCB_toggled()
137 bool in_sync = synchronizedViewCB->isChecked();
138 restorePB->setEnabled(!in_sync);
139 applyPB->setEnabled(!in_sync);
143 void GuiParagraph::changed()
145 if (synchronizedViewCB->isChecked())
146 on_applyPB_clicked();
150 void GuiParagraph::on_applyPB_clicked()
152 ParagraphParameters & params = controller_.params();
154 params.align(getAlignmentFromDialog());
157 Spacing::Space ls = Spacing::Default;
159 switch (linespacing->currentIndex()) {
161 ls = Spacing::Default;
164 ls = Spacing::Single;
167 ls = Spacing::Onehalf;
170 ls = Spacing::Double;
174 other = fromqstr(linespacingValue->text());
178 Spacing const spacing(ls, other);
179 params.spacing(spacing);
182 params.labelWidthString(qstring_to_ucs4(labelWidth->text()));
184 params.noindent(!indentCB->isChecked());
186 controller_.dispatchParams();
190 void GuiParagraph::on_restorePB_clicked()
196 void GuiParagraph::updateView()
198 on_synchronizedViewCB_toggled();
200 ParagraphParameters const & params = controller_.params();
203 docstring const & labelwidth = params.labelWidthString();
204 // FIXME We should not compare translated strings
205 if (labelwidth != _("Senseless with this layout!")) {
206 labelwidthGB->setEnabled(true);
207 labelWidth->setText(toqstr(labelwidth));
209 labelwidthGB->setEnabled(false);
210 labelWidth->setText("");
214 checkAlignmentRadioButtons();
215 alignmentToRadioButtons(params.align());
218 bool const canindent = controller_.canIndent();
219 indentCB->setEnabled(canindent);
220 indentCB->setChecked(canindent && !params.noindent());
224 Spacing const & space = params.spacing();
225 switch (space.getSpace()) {
226 case Spacing::Single:
229 case Spacing::Onehalf:
232 case Spacing::Double:
242 linespacing->setCurrentIndex(ls);
243 if (space.getSpace() == Spacing::Other) {
244 linespacingValue->setText(toqstr(space.getValueAsString()));
245 linespacingValue->setEnabled(true);
247 linespacingValue->setText(QString());
248 linespacingValue->setEnabled(false);
253 Dialog * createGuiParagraph(LyXView & lv)
255 GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);
256 #ifdef USE_DOCK_WIDGET
257 return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
258 Qt::TopDockWidgetArea);
260 return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
265 } // namespace frontend
268 #include "GuiParagraph_moc.cpp"