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
|
|
|
#include "Qt2BC.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-04-11 14:04:40 +00:00
|
|
|
#include "debug.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "ParagraphParameters.h"
|
|
|
|
#include "Spacing.h"
|
|
|
|
|
|
|
|
#include "controllers/ControlParagraph.h"
|
2007-04-25 17:53:54 +00:00
|
|
|
#include "controllers/frontend_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
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
|
|
|
|
2007-04-24 19:37:34 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
// GuiParagraphDialog
|
2007-04-24 19:37:34 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
#include <boost/current_function.hpp>
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
GuiParagraphDialog::GuiParagraphDialog(GuiParagraph * form)
|
2007-04-24 19:37:34 +00:00
|
|
|
: form_(form)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
|
|
|
|
connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
|
|
|
|
connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
|
|
|
|
connect(restorePB, SIGNAL(clicked()), form_, 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-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
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiParagraphDialog::change_adaptor()
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-06-22 22:34:16 +00:00
|
|
|
LyXAlignment const alignPossible = form_->controller().alignPossible();
|
2007-06-28 00:48:06 +00:00
|
|
|
|
2007-06-22 22:34:16 +00:00
|
|
|
QPRadioMap::iterator it = radioMap.begin();
|
|
|
|
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-06-28 00:48:06 +00:00
|
|
|
if (!form_->controller().haveMulitParSelection())
|
|
|
|
label += (" (" + labelMap[form_->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
|
|
|
{
|
|
|
|
QPRadioMap::const_iterator it = radioMap.begin();
|
|
|
|
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;
|
|
|
|
QPRadioMap::const_iterator it = radioMap.begin();
|
|
|
|
for (; it != radioMap.end(); ++it) {
|
|
|
|
if (it->second->isChecked()) {
|
|
|
|
alignment = it->first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return alignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
// GuiParagraph
|
2007-04-24 19:37:34 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
typedef QController<ControlParagraph, GuiView<GuiParagraphDialog> >
|
2007-04-24 19:37:34 +00:00
|
|
|
ParagraphBase;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
GuiParagraph::GuiParagraph(Dialog & parent)
|
2007-04-24 19:37:34 +00:00
|
|
|
: ParagraphBase(parent, _("Paragraph Settings"))
|
2006-03-05 17:24:44 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiParagraph::build_dialog()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
// the dialog
|
2007-08-31 05:53:55 +00:00
|
|
|
dialog_.reset(new GuiParagraphDialog(this));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// Manage the ok, apply, restore and cancel/close buttons
|
|
|
|
bcview().setOK(dialog_->okPB);
|
|
|
|
bcview().setApply(dialog_->applyPB);
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
bcview().setRestore(dialog_->restorePB);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiParagraph::apply()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
ParagraphParameters & params = controller().params();
|
|
|
|
|
2007-04-11 14:04:40 +00:00
|
|
|
params.align(dialog_->getAlignmentFromDialog());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// get spacing
|
|
|
|
Spacing::Space linespacing = Spacing::Default;
|
|
|
|
string other;
|
2006-08-17 08:58:01 +00:00
|
|
|
switch (dialog_->linespacing->currentIndex()) {
|
2006-03-05 17:24:44 +00:00
|
|
|
case 0:
|
|
|
|
linespacing = Spacing::Default;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
linespacing = Spacing::Single;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
linespacing = Spacing::Onehalf;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
linespacing = Spacing::Double;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
linespacing = Spacing::Other;
|
|
|
|
other = fromqstr(dialog_->linespacingValue->text());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Spacing const spacing(linespacing, other);
|
|
|
|
params.spacing(spacing);
|
|
|
|
|
|
|
|
// label width
|
2006-10-20 19:26:23 +00:00
|
|
|
params.labelWidthString(qstring_to_ucs4(dialog_->labelWidth->text()));
|
2006-03-05 17:24:44 +00:00
|
|
|
// indendation
|
|
|
|
params.noindent(!dialog_->indentCB->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiParagraph::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!")) {
|
2006-03-05 17:24:44 +00:00
|
|
|
dialog_->labelwidthGB->setEnabled(true);
|
2006-12-02 19:53:21 +00:00
|
|
|
dialog_->labelWidth->setText(toqstr(labelwidth));
|
2006-03-05 17:24:44 +00:00
|
|
|
} else {
|
|
|
|
dialog_->labelwidthGB->setEnabled(false);
|
|
|
|
dialog_->labelWidth->setText("");
|
|
|
|
}
|
|
|
|
|
|
|
|
// alignment
|
2007-04-11 14:04:40 +00:00
|
|
|
dialog_->checkAlignmentRadioButtons();
|
2007-06-22 22:34:16 +00:00
|
|
|
dialog_->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();
|
|
|
|
dialog_->indentCB->setEnabled(canindent);
|
|
|
|
dialog_->indentCB->setChecked(canindent && !params.noindent());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// linespacing
|
|
|
|
int linespacing;
|
|
|
|
Spacing const & space = params.spacing();
|
|
|
|
switch (space.getSpace()) {
|
|
|
|
case Spacing::Single:
|
|
|
|
linespacing = 1;
|
|
|
|
break;
|
|
|
|
case Spacing::Onehalf:
|
|
|
|
linespacing = 2;
|
|
|
|
break;
|
|
|
|
case Spacing::Double:
|
|
|
|
linespacing = 3;
|
|
|
|
break;
|
|
|
|
case Spacing::Other:
|
|
|
|
linespacing = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
linespacing = 0;
|
|
|
|
break;
|
|
|
|
}
|
2006-08-17 08:58:01 +00:00
|
|
|
dialog_->linespacing->setCurrentIndex(linespacing);
|
2006-03-05 17:24:44 +00:00
|
|
|
if (space.getSpace() == Spacing::Other) {
|
|
|
|
dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
|
|
|
|
dialog_->linespacingValue->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
dialog_->linespacingValue->setText("");
|
|
|
|
dialog_->linespacingValue->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 19:37:34 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiParagraph_moc.cpp"
|