2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file QParagraph.C
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include "QParagraph.h"
|
|
|
|
#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"
|
2007-04-11 14:04:40 +00:00
|
|
|
#include "layout.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#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
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// QParagraphDialog
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
#include <boost/current_function.hpp>
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-04-24 19:37:34 +00:00
|
|
|
QParagraphDialog::QParagraphDialog(QParagraph * form)
|
|
|
|
: 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()));
|
|
|
|
connect(alignDefaultCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
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()));
|
|
|
|
connect(linespacing, SIGNAL(activated(int)),
|
|
|
|
this, SLOT(enableLinespacingValue(int)));
|
|
|
|
connect(linespacingValue, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
connect(indentCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
connect(labelWidth, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
|
|
|
linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
|
|
|
|
|
|
|
|
labelWidth->setWhatsThis( qt_(
|
|
|
|
"As described in the User Guide, the length of"
|
|
|
|
" this text will determine how wide the label part"
|
|
|
|
" of each item is in environments like List and"
|
|
|
|
" Description.\n"
|
|
|
|
"\n"
|
|
|
|
" Normally you won't need to set this,"
|
|
|
|
" since the largest label width of all the"
|
|
|
|
" items is used. But if you need to, you can"
|
|
|
|
" change it here."
|
|
|
|
));
|
|
|
|
|
|
|
|
radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
|
|
|
|
radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
|
|
|
|
radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
|
|
|
|
radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QParagraphDialog::closeEvent(QCloseEvent * e)
|
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QParagraphDialog::change_adaptor()
|
|
|
|
{
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QParagraphDialog::enableLinespacingValue(int)
|
|
|
|
{
|
|
|
|
bool const enable = linespacing->currentIndex() == 4;
|
|
|
|
linespacingValue->setEnabled(enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QParagraphDialog::checkAlignmentRadioButtons() {
|
|
|
|
if (alignDefaultCB->isChecked()) {
|
|
|
|
QPRadioMap::const_iterator it = radioMap.begin();
|
|
|
|
for (; it != radioMap.end(); ++it)
|
|
|
|
it->second->setDisabled(true);
|
|
|
|
} else {
|
|
|
|
LyXAlignment alignPossible = form_->controller().alignPossible();
|
|
|
|
QPRadioMap::const_iterator it = radioMap.begin();
|
|
|
|
for (; it != radioMap.end(); ++it)
|
|
|
|
it->second->setEnabled(it->first & alignPossible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QParagraphDialog::on_alignDefaultCB_toggled(bool)
|
|
|
|
{
|
|
|
|
checkAlignmentRadioButtons();
|
|
|
|
alignmentToRadioButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
|
|
|
|
{
|
|
|
|
if (align == LYX_ALIGN_LAYOUT)
|
|
|
|
align = form_->controller().alignDefault();
|
|
|
|
|
|
|
|
QPRadioMap::const_iterator it = radioMap.begin();
|
|
|
|
for (;it != radioMap.end(); ++it) {
|
|
|
|
if (align == it->first) {
|
|
|
|
it->second->setChecked(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment "
|
|
|
|
<< align << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXAlignment QParagraphDialog::getAlignmentFromDialog()
|
|
|
|
{
|
|
|
|
if (alignDefaultCB->isChecked())
|
|
|
|
return LYX_ALIGN_LAYOUT;
|
|
|
|
LyXAlignment alignment = LYX_ALIGN_NONE;
|
|
|
|
QPRadioMap::const_iterator it = radioMap.begin();
|
|
|
|
for (; it != radioMap.end(); ++it) {
|
|
|
|
if (it->second->isChecked()) {
|
|
|
|
alignment = it->first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (alignment == form_->controller().alignDefault())
|
|
|
|
return LYX_ALIGN_LAYOUT;
|
|
|
|
return alignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// QParagraph
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
typedef QController<ControlParagraph, QView<QParagraphDialog> >
|
|
|
|
ParagraphBase;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
QParagraph::QParagraph(Dialog & parent)
|
2007-04-24 19:37:34 +00:00
|
|
|
: ParagraphBase(parent, _("Paragraph Settings"))
|
2006-03-05 17:24:44 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void QParagraph::build_dialog()
|
|
|
|
{
|
|
|
|
// the dialog
|
|
|
|
dialog_.reset(new QParagraphDialog(this));
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QParagraph::apply()
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QParagraph::update_contents()
|
|
|
|
{
|
|
|
|
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
|
|
|
LyXAlignment newAlignment = params.align();
|
|
|
|
LyXAlignment defaultAlignment = controller().alignDefault();
|
|
|
|
bool alignmentIsDefault =
|
|
|
|
newAlignment == LYX_ALIGN_LAYOUT || newAlignment == defaultAlignment;
|
2007-04-13 02:09:50 +00:00
|
|
|
dialog_->alignDefaultCB->blockSignals(true);
|
2007-04-11 14:04:40 +00:00
|
|
|
dialog_->alignDefaultCB->setChecked(alignmentIsDefault);
|
2007-04-13 02:09:50 +00:00
|
|
|
dialog_->alignDefaultCB->blockSignals(false);
|
2007-04-11 14:04:40 +00:00
|
|
|
dialog_->checkAlignmentRadioButtons();
|
|
|
|
dialog_->alignmentToRadioButtons(newAlignment);
|
|
|
|
|
|
|
|
//indentation
|
2006-03-05 17:24:44 +00:00
|
|
|
dialog_->indentCB->setChecked(!params.noindent());
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
#include "QParagraph_moc.cpp"
|