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
|
2007-09-26 13:13:01 +00:00
|
|
|
* \author Abdelrazak Younes
|
2007-10-07 20:00:46 +00:00
|
|
|
* \author Angus Leeming
|
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"
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-10-07 20:00:46 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "Cursor.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "GuiView.h"
|
|
|
|
#include "Lexer.h"
|
|
|
|
#include "Paragraph.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "ParagraphParameters.h"
|
|
|
|
#include "Spacing.h"
|
|
|
|
|
2007-11-29 21:10:35 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
2008-05-14 14:08:58 +00:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QVariant>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-07 20:00:46 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiParagraph::GuiParagraph(GuiView & lv)
|
2008-02-05 12:43:19 +00:00
|
|
|
: DialogView(lv, "paragraph", qt_("Paragraph Settings"))
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-26 13:13:01 +00:00
|
|
|
|
|
|
|
connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
|
|
|
|
connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
|
|
|
|
connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
|
|
|
|
connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
|
|
|
|
connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
|
|
|
|
connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(linespacingValue, SIGNAL(textChanged(QString)),
|
2007-09-26 13:13:01 +00:00
|
|
|
this, SLOT(changed()));
|
|
|
|
connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(labelWidth, SIGNAL(textChanged(QString)),
|
2007-09-26 13:13:01 +00:00
|
|
|
this, SLOT(changed()));
|
2007-04-24 19:37:34 +00:00
|
|
|
|
2008-01-25 22:31:33 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
// On Mac it's common to have tool windows which are always in the
|
|
|
|
// foreground and are hidden when the main window is not focused.
|
|
|
|
setWindowFlags(Qt::Tool);
|
|
|
|
synchronizedViewCB->setChecked(true);
|
2008-04-19 16:56:40 +00:00
|
|
|
closePB->setText(qt_("&Cancel"));
|
2008-01-25 22:31:33 +00:00
|
|
|
#else
|
2007-09-28 23:30:19 +00:00
|
|
|
synchronizedViewCB->setChecked(false);
|
2008-01-25 22:31:33 +00:00
|
|
|
#endif
|
|
|
|
|
2007-09-26 13:13:01 +00:00
|
|
|
on_synchronizedViewCB_toggled();
|
2007-04-24 19:37:34 +00:00
|
|
|
linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
|
|
|
|
|
2008-04-18 20:45:21 +00:00
|
|
|
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
|
|
|
));
|
|
|
|
|
2008-04-18 20:45:21 +00:00
|
|
|
radioMap_[LYX_ALIGN_LAYOUT] = alignDefaultRB;
|
|
|
|
radioMap_[LYX_ALIGN_BLOCK] = alignJustRB;
|
|
|
|
radioMap_[LYX_ALIGN_LEFT] = alignLeftRB;
|
|
|
|
radioMap_[LYX_ALIGN_RIGHT] = alignRightRB;
|
|
|
|
radioMap_[LYX_ALIGN_CENTER] = alignCenterRB;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2008-04-18 20:45:21 +00:00
|
|
|
alignDefaultLabel_ = alignDefaultRB->text();
|
2007-04-24 19:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-26 13:13:01 +00:00
|
|
|
void GuiParagraph::on_linespacing_activated(int index)
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
2007-09-26 13:13:01 +00:00
|
|
|
linespacingValue->setEnabled(index == 4);
|
2007-04-24 19:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 20:00:46 +00:00
|
|
|
void GuiParagraph::checkAlignmentRadioButtons()
|
|
|
|
{
|
2008-04-18 20:45:21 +00:00
|
|
|
static std::map<LyXAlignment, QString> labelMap_;
|
|
|
|
if (labelMap_.empty()) {
|
|
|
|
labelMap_[LYX_ALIGN_BLOCK] = qt_("Justified");
|
|
|
|
labelMap_[LYX_ALIGN_LEFT] = qt_("Left");
|
|
|
|
labelMap_[LYX_ALIGN_RIGHT] = qt_("Right");
|
|
|
|
labelMap_[LYX_ALIGN_CENTER] = qt_("Center");
|
|
|
|
}
|
|
|
|
|
|
|
|
RadioMap::iterator it = radioMap_.begin();
|
|
|
|
for (; it != radioMap_.end(); ++it) {
|
2007-06-22 22:34:16 +00:00
|
|
|
LyXAlignment const align = it->first;
|
2007-10-07 20:00:46 +00:00
|
|
|
it->second->setEnabled(align & alignPossible());
|
2007-04-24 19:37:34 +00:00
|
|
|
}
|
2008-02-08 16:14:24 +00:00
|
|
|
if (haveMultiParSelection())
|
2008-04-18 20:45:21 +00:00
|
|
|
alignDefaultRB->setText(alignDefaultLabel_);
|
2007-09-26 13:13:01 +00:00
|
|
|
else
|
2008-04-18 20:45:21 +00:00
|
|
|
alignDefaultRB->setText(alignDefaultLabel_ + " ("
|
|
|
|
+ labelMap_[alignDefault()] + ")");
|
2007-04-24 19:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-26 13:13:01 +00:00
|
|
|
void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
2008-04-18 20:45:21 +00:00
|
|
|
RadioMap::const_iterator it = radioMap_.begin();
|
|
|
|
for (;it != radioMap_.end(); ++it) {
|
2007-09-26 13:13:01 +00:00
|
|
|
it->second->blockSignals(true);
|
|
|
|
it->second->setChecked(align == it->first);
|
|
|
|
it->second->blockSignals(false);
|
2007-04-24 19:37:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-26 13:13:01 +00:00
|
|
|
LyXAlignment GuiParagraph::getAlignmentFromDialog()
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
|
|
|
LyXAlignment alignment = LYX_ALIGN_NONE;
|
2008-04-18 20:45:21 +00:00
|
|
|
RadioMap::const_iterator it = radioMap_.begin();
|
|
|
|
for (; it != radioMap_.end(); ++it) {
|
2007-04-24 19:37:34 +00:00
|
|
|
if (it->second->isChecked()) {
|
|
|
|
alignment = it->first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return alignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-26 13:13:01 +00:00
|
|
|
void GuiParagraph::on_synchronizedViewCB_toggled()
|
|
|
|
{
|
|
|
|
bool in_sync = synchronizedViewCB->isChecked();
|
|
|
|
restorePB->setEnabled(!in_sync);
|
|
|
|
applyPB->setEnabled(!in_sync);
|
2008-04-19 16:56:40 +00:00
|
|
|
okPB->setEnabled(!in_sync);
|
|
|
|
if (!in_sync)
|
|
|
|
closePB->setText(qt_("&Cancel"));
|
|
|
|
else
|
|
|
|
closePB->setText(qt_("&Close"));
|
2007-09-26 13:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiParagraph::changed()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-26 13:13:01 +00:00
|
|
|
if (synchronizedViewCB->isChecked())
|
|
|
|
on_applyPB_clicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiParagraph::on_applyPB_clicked()
|
2008-04-19 16:56:40 +00:00
|
|
|
{
|
|
|
|
applyView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiParagraph::on_okPB_clicked()
|
|
|
|
{
|
|
|
|
applyView();
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiParagraph::on_closePB_clicked()
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiParagraph::on_restorePB_clicked()
|
|
|
|
{
|
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiParagraph::applyView()
|
2007-09-26 13:13:01 +00:00
|
|
|
{
|
2007-10-07 20:00:46 +00:00
|
|
|
ParagraphParameters & pp = params();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-07 20:00:46 +00:00
|
|
|
pp.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);
|
2007-10-07 20:00:46 +00:00
|
|
|
pp.spacing(spacing);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// label width
|
2007-10-07 20:00:46 +00:00
|
|
|
pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
|
2006-03-05 17:24:44 +00:00
|
|
|
// indendation
|
2007-10-07 20:00:46 +00:00
|
|
|
pp.noindent(!indentCB->isChecked());
|
2007-09-26 13:13:01 +00:00
|
|
|
|
2007-10-07 20:00:46 +00:00
|
|
|
dispatchParams();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-26 13:13:01 +00:00
|
|
|
void GuiParagraph::updateView()
|
|
|
|
{
|
|
|
|
on_synchronizedViewCB_toggled();
|
|
|
|
|
2007-10-07 20:00:46 +00:00
|
|
|
ParagraphParameters const & pp = params();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// label width
|
2007-10-07 20:00:46 +00:00
|
|
|
docstring const & labelwidth = pp.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);
|
2008-03-15 00:22:54 +00:00
|
|
|
labelWidth->setText(QString());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// alignment
|
2007-09-05 20:33:29 +00:00
|
|
|
checkAlignmentRadioButtons();
|
2007-10-07 20:00:46 +00:00
|
|
|
alignmentToRadioButtons(pp.align());
|
2007-04-11 14:04:40 +00:00
|
|
|
|
|
|
|
//indentation
|
2007-10-07 20:00:46 +00:00
|
|
|
bool const canindent = canIndent();
|
2007-09-05 20:33:29 +00:00
|
|
|
indentCB->setEnabled(canindent);
|
2007-10-07 20:00:46 +00:00
|
|
|
indentCB->setChecked(canindent && !pp.noindent());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// linespacing
|
2007-09-05 20:33:29 +00:00
|
|
|
int ls;
|
2007-10-07 20:00:46 +00:00
|
|
|
Spacing const & space = pp.spacing();
|
2006-03-05 17:24:44 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-07 10:10:41 +00:00
|
|
|
|
2008-02-08 16:08:45 +00:00
|
|
|
void GuiParagraph::enableView(bool enable)
|
|
|
|
{
|
|
|
|
indentCB->setEnabled(enable);
|
|
|
|
linespacing->setEnabled(enable);
|
|
|
|
labelWidth->setEnabled(enable);
|
|
|
|
synchronizedViewCB->setEnabled(enable);
|
|
|
|
applyPB->setEnabled(enable);
|
|
|
|
restorePB->setEnabled(enable);
|
|
|
|
if (!enable)
|
|
|
|
synchronizedViewCB->setChecked(true);
|
2008-04-18 20:45:21 +00:00
|
|
|
RadioMap::const_iterator it = radioMap_.begin();
|
|
|
|
for (; it != radioMap_.end(); ++it)
|
2008-02-08 16:08:45 +00:00
|
|
|
it->second->setEnabled(enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 20:00:46 +00:00
|
|
|
ParagraphParameters & GuiParagraph::params()
|
|
|
|
{
|
2008-02-08 16:14:24 +00:00
|
|
|
if (haveMultiParSelection()) {
|
2007-10-07 20:00:46 +00:00
|
|
|
multiparsel_ = ParagraphParameters();
|
|
|
|
// FIXME: It would be nice to initialise the parameters that
|
|
|
|
// are common to all paragraphs.
|
|
|
|
return multiparsel_;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bufferview()->cursor().innerParagraph().params();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphParameters const & GuiParagraph::params() const
|
|
|
|
{
|
|
|
|
return bufferview()->cursor().innerParagraph().params();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiParagraph::dispatchParams()
|
|
|
|
{
|
2008-02-08 16:14:24 +00:00
|
|
|
if (haveMultiParSelection()) {
|
2007-10-07 20:00:46 +00:00
|
|
|
ostringstream data;
|
|
|
|
multiparsel_.write(data);
|
2008-02-08 16:08:45 +00:00
|
|
|
FuncRequest const fr(getLfun(), data.str());
|
2007-10-07 20:00:46 +00:00
|
|
|
dispatch(fr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-06 08:32:25 +00:00
|
|
|
bufferview()->updateMetrics();
|
2007-10-07 20:00:46 +00:00
|
|
|
bufferview()->buffer().changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-08 16:14:24 +00:00
|
|
|
bool GuiParagraph::haveMultiParSelection()
|
2007-10-07 20:00:46 +00:00
|
|
|
{
|
|
|
|
Cursor cur = bufferview()->cursor();
|
|
|
|
return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiParagraph::canIndent() const
|
|
|
|
{
|
2008-03-15 00:22:54 +00:00
|
|
|
return buffer().params().paragraph_separation
|
|
|
|
== BufferParams::ParagraphIndentSeparation;
|
2007-10-07 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXAlignment GuiParagraph::alignPossible() const
|
|
|
|
{
|
2008-03-06 21:31:27 +00:00
|
|
|
return bufferview()->cursor().innerParagraph().layout().alignpossible;
|
2007-10-07 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXAlignment GuiParagraph::alignDefault() const
|
|
|
|
{
|
2008-03-06 21:31:27 +00:00
|
|
|
return bufferview()->cursor().innerParagraph().layout().align;
|
2007-10-07 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-14 14:08:58 +00:00
|
|
|
void GuiParagraph::saveSession() const
|
|
|
|
{
|
|
|
|
Dialog::saveSession();
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue(sessionKey() + "/autoapply", synchronizedViewCB->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiParagraph::restoreSession()
|
|
|
|
{
|
|
|
|
Dialog::restoreSession();
|
|
|
|
QSettings settings;
|
|
|
|
synchronizedViewCB->setChecked(
|
|
|
|
settings.value(sessionKey() + "/autoapply").toBool());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiParagraph(GuiView & lv)
|
2007-10-07 10:10:41 +00:00
|
|
|
{
|
2007-10-07 20:00:46 +00:00
|
|
|
return new GuiParagraph(lv);
|
2007-10-07 10:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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"
|