2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiParagraph.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
2007-04-11 14:04:40 +00:00
|
|
|
* \author Richard Heck
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiParagraph.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
#include "ControlParagraph.h"
|
|
|
|
|
2007-04-11 14:04:40 +00:00
|
|
|
#include "debug.h"
|
2007-09-03 05:59:32 +00:00
|
|
|
#include "frontend_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2007-09-03 05:59:32 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "Spacing.h"
|
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
#include <QCheckBox>
|
2007-08-31 22:16:11 +00:00
|
|
|
#include <QCloseEvent>
|
2006-05-04 07:31:46 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
#include <boost/current_function.hpp>
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
using std::string;
|
2007-04-11 14:04:40 +00:00
|
|
|
using std::endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
GuiParagraphDialog::GuiParagraphDialog(LyXView & lv)
|
|
|
|
: GuiDialog(lv, "paragraph")
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
setViewTitle(_("Paragraph Settings"));
|
|
|
|
setController(new ControlParagraph(*this));
|
2007-04-24 19:37:34 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
|
|
|
|
connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
|
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
|
|
|
|
connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
|
2007-06-22 22:34:16 +00:00
|
|
|
connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
2007-04-24 19:37:34 +00:00
|
|
|
connect(alignJustRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
connect(alignRightRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
connect(linespacing, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
|
2007-05-28 22:27:45 +00:00
|
|
|
connect(linespacing, SIGNAL(activated(int)),
|
2007-04-24 19:37:34 +00:00
|
|
|
this, SLOT(enableLinespacingValue(int)));
|
2007-05-28 22:27:45 +00:00
|
|
|
connect(linespacingValue, SIGNAL(textChanged(const QString &)),
|
2007-04-24 19:37:34 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
connect(indentCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
2007-05-28 22:27:45 +00:00
|
|
|
connect(labelWidth, SIGNAL(textChanged(const QString &)),
|
2007-04-24 19:37:34 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
|
|
|
linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
|
|
|
|
|
|
|
|
labelWidth->setWhatsThis( qt_(
|
2007-05-01 10:07:29 +00:00
|
|
|
"As described in the User Guide, the width of"
|
|
|
|
" this text determines the width of the label part"
|
|
|
|
" of each item in environments like List and"
|
2007-04-24 19:37:34 +00:00
|
|
|
" Description.\n"
|
|
|
|
"\n"
|
2007-05-01 10:07:29 +00:00
|
|
|
" Normally, you won't need to set this,"
|
2007-04-24 19:37:34 +00:00
|
|
|
" since the largest label width of all the"
|
2007-05-01 10:07:29 +00:00
|
|
|
" items is used."
|
2007-04-24 19:37:34 +00:00
|
|
|
));
|
|
|
|
|
2007-06-22 22:34:16 +00:00
|
|
|
radioMap[LYX_ALIGN_LAYOUT] = alignDefaultRB;
|
|
|
|
radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
|
|
|
|
radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
|
|
|
|
radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
|
2007-04-24 19:37:34 +00:00
|
|
|
radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
|
2007-06-22 22:34:16 +00:00
|
|
|
|
2007-07-09 19:01:27 +00:00
|
|
|
labelMap[LYX_ALIGN_LAYOUT] = _("Use Paragraph's Default Alignment");
|
|
|
|
labelMap[LYX_ALIGN_BLOCK] = _("Justified");
|
|
|
|
labelMap[LYX_ALIGN_LEFT] = _("Left");
|
|
|
|
labelMap[LYX_ALIGN_RIGHT] = _("Right");
|
|
|
|
labelMap[LYX_ALIGN_CENTER] = _("Center");
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
|
|
|
|
bc().setOK(okPB);
|
|
|
|
bc().setApply(applyPB);
|
|
|
|
bc().setCancel(closePB);
|
|
|
|
bc().setRestore(restorePB);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ControlParagraph & GuiParagraphDialog::controller() const
|
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
return static_cast<ControlParagraph &>(GuiDialog::controller());
|
2007-04-24 19:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiParagraphDialog::closeEvent(QCloseEvent * e)
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
slotWMHide();
|
2007-04-24 19:37:34 +00:00
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiParagraphDialog::change_adaptor()
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-24 19:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiParagraphDialog::enableLinespacingValue(int)
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
|
|
|
bool const enable = linespacing->currentIndex() == 4;
|
|
|
|
linespacingValue->setEnabled(enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiParagraphDialog::checkAlignmentRadioButtons() {
|
2007-09-05 20:33:29 +00:00
|
|
|
LyXAlignment const alignPossible = controller().alignPossible();
|
2007-06-28 00:48:06 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
RadioMap::iterator it = radioMap.begin();
|
2007-06-22 22:34:16 +00:00
|
|
|
for (; it != radioMap.end(); ++it) {
|
|
|
|
LyXAlignment const align = it->first;
|
2007-08-06 05:04:38 +00:00
|
|
|
it->second->setEnabled(align & alignPossible);
|
2007-04-24 19:37:34 +00:00
|
|
|
}
|
2007-07-09 19:01:27 +00:00
|
|
|
docstring label = labelMap[LYX_ALIGN_LAYOUT];
|
2007-09-05 20:33:29 +00:00
|
|
|
if (!controller().haveMulitParSelection())
|
|
|
|
label += (" (" + labelMap[controller().alignDefault()] + ")");
|
2007-07-09 19:01:27 +00:00
|
|
|
alignDefaultRB->setText(toqstr(label));
|
2007-04-24 19:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
RadioMap::const_iterator it = radioMap.begin();
|
2007-04-24 19:37:34 +00:00
|
|
|
for (;it != radioMap.end(); ++it) {
|
|
|
|
if (align == it->first) {
|
2007-06-22 22:34:16 +00:00
|
|
|
it->second->blockSignals(true);
|
2007-04-24 19:37:34 +00:00
|
|
|
it->second->setChecked(true);
|
2007-06-22 22:34:16 +00:00
|
|
|
it->second->blockSignals(false);
|
2007-04-24 19:37:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment "
|
2007-04-24 19:37:34 +00:00
|
|
|
<< align << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
LyXAlignment GuiParagraphDialog::getAlignmentFromDialog()
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
|
|
|
LyXAlignment alignment = LYX_ALIGN_NONE;
|
2007-09-05 20:33:29 +00:00
|
|
|
RadioMap::const_iterator it = radioMap.begin();
|
2007-04-24 19:37:34 +00:00
|
|
|
for (; it != radioMap.end(); ++it) {
|
|
|
|
if (it->second->isChecked()) {
|
|
|
|
alignment = it->first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return alignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
void GuiParagraphDialog::applyView()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
ParagraphParameters & params = controller().params();
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
params.align(getAlignmentFromDialog());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// get spacing
|
2007-09-05 20:33:29 +00:00
|
|
|
Spacing::Space ls = Spacing::Default;
|
2006-03-05 17:24:44 +00:00
|
|
|
string other;
|
2007-09-05 20:33:29 +00:00
|
|
|
switch (linespacing->currentIndex()) {
|
2006-03-05 17:24:44 +00:00
|
|
|
case 0:
|
2007-09-05 20:33:29 +00:00
|
|
|
ls = Spacing::Default;
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2007-09-05 20:33:29 +00:00
|
|
|
ls = Spacing::Single;
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2007-09-05 20:33:29 +00:00
|
|
|
ls = Spacing::Onehalf;
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2007-09-05 20:33:29 +00:00
|
|
|
ls = Spacing::Double;
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2007-09-05 20:33:29 +00:00
|
|
|
ls = Spacing::Other;
|
|
|
|
other = fromqstr(linespacingValue->text());
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
Spacing const spacing(ls, other);
|
2006-03-05 17:24:44 +00:00
|
|
|
params.spacing(spacing);
|
|
|
|
|
|
|
|
// label width
|
2007-09-05 20:33:29 +00:00
|
|
|
params.labelWidthString(qstring_to_ucs4(labelWidth->text()));
|
2006-03-05 17:24:44 +00:00
|
|
|
// indendation
|
2007-09-05 20:33:29 +00:00
|
|
|
params.noindent(!indentCB->isChecked());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
void GuiParagraphDialog::update_contents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
ParagraphParameters const & params = controller().params();
|
|
|
|
|
|
|
|
// label width
|
2006-10-20 19:26:23 +00:00
|
|
|
docstring const & labelwidth = params.labelWidthString();
|
2006-12-22 10:06:40 +00:00
|
|
|
// FIXME We should not compare translated strings
|
2006-10-20 19:26:23 +00:00
|
|
|
if (labelwidth != _("Senseless with this layout!")) {
|
2007-09-05 20:33:29 +00:00
|
|
|
labelwidthGB->setEnabled(true);
|
|
|
|
labelWidth->setText(toqstr(labelwidth));
|
2006-03-05 17:24:44 +00:00
|
|
|
} else {
|
2007-09-05 20:33:29 +00:00
|
|
|
labelwidthGB->setEnabled(false);
|
|
|
|
labelWidth->setText("");
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// alignment
|
2007-09-05 20:33:29 +00:00
|
|
|
checkAlignmentRadioButtons();
|
|
|
|
alignmentToRadioButtons(params.align());
|
2007-04-11 14:04:40 +00:00
|
|
|
|
|
|
|
//indentation
|
2007-05-08 15:35:44 +00:00
|
|
|
bool const canindent = controller().canIndent();
|
2007-09-05 20:33:29 +00:00
|
|
|
indentCB->setEnabled(canindent);
|
|
|
|
indentCB->setChecked(canindent && !params.noindent());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// linespacing
|
2007-09-05 20:33:29 +00:00
|
|
|
int ls;
|
2006-03-05 17:24:44 +00:00
|
|
|
Spacing const & space = params.spacing();
|
|
|
|
switch (space.getSpace()) {
|
|
|
|
case Spacing::Single:
|
2007-09-05 20:33:29 +00:00
|
|
|
ls = 1;
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
case Spacing::Onehalf:
|
2007-09-05 20:33:29 +00:00
|
|
|
ls = 2;
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
case Spacing::Double:
|
2007-09-05 20:33:29 +00:00
|
|
|
ls = 3;
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
case Spacing::Other:
|
2007-09-05 20:33:29 +00:00
|
|
|
ls = 4;
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-09-05 20:33:29 +00:00
|
|
|
ls = 0;
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-09-05 20:33:29 +00:00
|
|
|
linespacing->setCurrentIndex(ls);
|
2006-03-05 17:24:44 +00:00
|
|
|
if (space.getSpace() == Spacing::Other) {
|
2007-09-05 20:33:29 +00:00
|
|
|
linespacingValue->setText(toqstr(space.getValueAsString()));
|
|
|
|
linespacingValue->setEnabled(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
} else {
|
2007-09-05 20:33:29 +00:00
|
|
|
linespacingValue->setText(QString());
|
|
|
|
linespacingValue->setEnabled(false);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 19:37:34 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiParagraph_moc.cpp"
|