3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "QParagraph.h"
16 #include "qt_helpers.h"
19 #include "ParagraphParameters.h"
22 #include "controllers/ControlParagraph.h"
23 #include "controllers/frontend_helpers.h"
27 #include <QPushButton>
32 /////////////////////////////////////////////////////////////////////
36 /////////////////////////////////////////////////////////////////////
39 #include <boost/current_function.hpp>
44 QParagraphDialog::QParagraphDialog(QParagraph * form)
49 connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
50 connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
51 connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
52 connect(restorePB, SIGNAL(clicked()), form_, SLOT(slotRestore()));
53 connect(alignDefaultCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
54 connect(alignJustRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
55 connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
56 connect(alignRightRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
57 connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
58 connect(linespacing, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
59 connect(linespacing, SIGNAL(activated(int)),
60 this, SLOT(enableLinespacingValue(int)));
61 connect(linespacingValue, SIGNAL(textChanged(const QString &)),
62 this, SLOT(change_adaptor()));
63 connect(indentCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
64 connect(labelWidth, SIGNAL(textChanged(const QString &)),
65 this, SLOT(change_adaptor()));
67 linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
69 labelWidth->setWhatsThis( qt_(
70 "As described in the User Guide, the width of"
71 " this text determines the width of the label part"
72 " of each item in environments like List and"
75 " Normally, you won't need to set this,"
76 " since the largest label width of all the"
80 radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
81 radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
82 radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
83 radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
87 void QParagraphDialog::closeEvent(QCloseEvent * e)
94 void QParagraphDialog::change_adaptor()
100 void QParagraphDialog::enableLinespacingValue(int)
102 bool const enable = linespacing->currentIndex() == 4;
103 linespacingValue->setEnabled(enable);
107 void QParagraphDialog::checkAlignmentRadioButtons() {
108 if (alignDefaultCB->isChecked()) {
109 QPRadioMap::const_iterator it = radioMap.begin();
110 for (; it != radioMap.end(); ++it)
111 it->second->setDisabled(true);
113 LyXAlignment alignPossible = form_->controller().alignPossible();
114 QPRadioMap::const_iterator it = radioMap.begin();
115 for (; it != radioMap.end(); ++it)
116 it->second->setEnabled(it->first & alignPossible);
121 void QParagraphDialog::on_alignDefaultCB_toggled(bool)
123 checkAlignmentRadioButtons();
124 alignmentToRadioButtons();
128 void QParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
130 if (align == LYX_ALIGN_LAYOUT)
131 align = form_->controller().alignDefault();
133 QPRadioMap::const_iterator it = radioMap.begin();
134 for (;it != radioMap.end(); ++it) {
135 if (align == it->first) {
136 it->second->setChecked(true);
141 lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment "
142 << align << std::endl;
146 LyXAlignment QParagraphDialog::getAlignmentFromDialog()
148 if (alignDefaultCB->isChecked())
149 return LYX_ALIGN_LAYOUT;
150 LyXAlignment alignment = LYX_ALIGN_NONE;
151 QPRadioMap::const_iterator it = radioMap.begin();
152 for (; it != radioMap.end(); ++it) {
153 if (it->second->isChecked()) {
154 alignment = it->first;
158 if (alignment == form_->controller().alignDefault())
159 return LYX_ALIGN_LAYOUT;
164 /////////////////////////////////////////////////////////////////////
168 /////////////////////////////////////////////////////////////////////
170 typedef QController<ControlParagraph, QView<QParagraphDialog> >
174 QParagraph::QParagraph(Dialog & parent)
175 : ParagraphBase(parent, _("Paragraph Settings"))
179 void QParagraph::build_dialog()
182 dialog_.reset(new QParagraphDialog(this));
184 // Manage the ok, apply, restore and cancel/close buttons
185 bcview().setOK(dialog_->okPB);
186 bcview().setApply(dialog_->applyPB);
187 bcview().setCancel(dialog_->closePB);
188 bcview().setRestore(dialog_->restorePB);
192 void QParagraph::apply()
194 ParagraphParameters & params = controller().params();
196 params.align(dialog_->getAlignmentFromDialog());
199 Spacing::Space linespacing = Spacing::Default;
201 switch (dialog_->linespacing->currentIndex()) {
203 linespacing = Spacing::Default;
206 linespacing = Spacing::Single;
209 linespacing = Spacing::Onehalf;
212 linespacing = Spacing::Double;
215 linespacing = Spacing::Other;
216 other = fromqstr(dialog_->linespacingValue->text());
220 Spacing const spacing(linespacing, other);
221 params.spacing(spacing);
224 params.labelWidthString(qstring_to_ucs4(dialog_->labelWidth->text()));
226 params.noindent(!dialog_->indentCB->isChecked());
230 void QParagraph::update_contents()
232 ParagraphParameters const & params = controller().params();
235 docstring const & labelwidth = params.labelWidthString();
236 // FIXME We should not compare translated strings
237 if (labelwidth != _("Senseless with this layout!")) {
238 dialog_->labelwidthGB->setEnabled(true);
239 dialog_->labelWidth->setText(toqstr(labelwidth));
241 dialog_->labelwidthGB->setEnabled(false);
242 dialog_->labelWidth->setText("");
246 LyXAlignment newAlignment = params.align();
247 LyXAlignment defaultAlignment = controller().alignDefault();
248 bool alignmentIsDefault =
249 newAlignment == LYX_ALIGN_LAYOUT || newAlignment == defaultAlignment;
250 dialog_->alignDefaultCB->blockSignals(true);
251 dialog_->alignDefaultCB->setChecked(alignmentIsDefault);
252 dialog_->alignDefaultCB->blockSignals(false);
253 dialog_->checkAlignmentRadioButtons();
254 dialog_->alignmentToRadioButtons(newAlignment);
257 bool const canindent = controller().canIndent();
258 dialog_->indentCB->setEnabled(canindent);
259 dialog_->indentCB->setChecked(canindent && !params.noindent());
263 Spacing const & space = params.spacing();
264 switch (space.getSpace()) {
265 case Spacing::Single:
268 case Spacing::Onehalf:
271 case Spacing::Double:
281 dialog_->linespacing->setCurrentIndex(linespacing);
282 if (space.getSpace() == Spacing::Other) {
283 dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
284 dialog_->linespacingValue->setEnabled(true);
286 dialog_->linespacingValue->setText("");
287 dialog_->linespacingValue->setEnabled(false);
291 } // namespace frontend
294 #include "QParagraph_moc.cpp"