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
|
|
|
|
2007-10-07 20:00:46 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "Cursor.h"
|
2007-10-09 21:21:01 +00:00
|
|
|
//#include "DialogView.h"
|
|
|
|
//#include "DockView.h"
|
2007-10-07 20:00:46 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "GuiView.h"
|
|
|
|
#include "Lexer.h"
|
|
|
|
#include "Paragraph.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2007-10-07 20:00:46 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#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>
|
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-10-07 20:00:46 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
using std::istringstream;
|
|
|
|
using std::ostringstream;
|
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-11-23 09:44:02 +00:00
|
|
|
GuiParagraph::GuiParagraph(GuiView & lv)
|
2007-12-09 22:35:04 +00:00
|
|
|
: DialogView(lv, "paragraph")
|
2007-04-24 19:37:34 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-26 13:13:01 +00:00
|
|
|
setWindowTitle(qt_("Paragraph Settings"));
|
|
|
|
|
|
|
|
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
|
|
|
|
2007-09-26 13:13:01 +00:00
|
|
|
|
2007-09-28 23:30:19 +00:00
|
|
|
synchronizedViewCB->setChecked(false);
|
2007-09-26 13:13:01 +00:00
|
|
|
on_synchronizedViewCB_toggled();
|
2007-04-24 19:37:34 +00:00
|
|
|
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-09-05 20:33:29 +00:00
|
|
|
|
2007-10-23 08:10:55 +00:00
|
|
|
labelMap[LYX_ALIGN_BLOCK] = _("Justified");
|
|
|
|
labelMap[LYX_ALIGN_LEFT] = _("Left");
|
|
|
|
labelMap[LYX_ALIGN_RIGHT] = _("Right");
|
|
|
|
labelMap[LYX_ALIGN_CENTER] = _("Center");
|
|
|
|
|
2007-09-26 13:13:01 +00:00
|
|
|
const_cast<QString &>(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()
|
|
|
|
{
|
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-10-07 20:00:46 +00:00
|
|
|
it->second->setEnabled(align & alignPossible());
|
2007-04-24 19:37:34 +00:00
|
|
|
}
|
2007-10-07 20:00:46 +00:00
|
|
|
if (haveMulitParSelection())
|
2007-09-26 13:13:01 +00:00
|
|
|
alignDefaultRB->setText(alignDefaultLabel);
|
|
|
|
else
|
2007-10-23 08:10:55 +00:00
|
|
|
alignDefaultRB->setText(alignDefaultLabel + " ("
|
|
|
|
+ toqstr(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
|
|
|
{
|
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) {
|
2007-09-26 13:13:01 +00:00
|
|
|
if (!it->second->isEnabled())
|
|
|
|
continue;
|
|
|
|
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;
|
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-26 13:13:01 +00:00
|
|
|
void GuiParagraph::on_synchronizedViewCB_toggled()
|
|
|
|
{
|
|
|
|
bool in_sync = synchronizedViewCB->isChecked();
|
|
|
|
restorePB->setEnabled(!in_sync);
|
|
|
|
applyPB->setEnabled(!in_sync);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
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::on_restorePB_clicked()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-26 13:13:01 +00:00
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
void GuiParagraph::enableView(bool enable)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
labelWidth->setText("");
|
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
|
|
|
|
2007-10-07 20:00:46 +00:00
|
|
|
ParagraphParameters & GuiParagraph::params()
|
|
|
|
{
|
|
|
|
if (haveMulitParSelection()) {
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
if (haveMulitParSelection()) {
|
|
|
|
ostringstream data;
|
|
|
|
multiparsel_.write(data);
|
|
|
|
FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
|
|
|
|
dispatch(fr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-06 08:32:25 +00:00
|
|
|
bufferview()->updateMetrics();
|
2007-10-07 20:00:46 +00:00
|
|
|
bufferview()->buffer().changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiParagraph::haveMulitParSelection()
|
|
|
|
{
|
|
|
|
Cursor cur = bufferview()->cursor();
|
|
|
|
return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiParagraph::canIndent() const
|
|
|
|
{
|
|
|
|
return buffer().params().paragraph_separation ==
|
|
|
|
BufferParams::PARSEP_INDENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXAlignment GuiParagraph::alignPossible() const
|
|
|
|
{
|
|
|
|
return bufferview()->cursor().innerParagraph().layout()->alignpossible;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXAlignment GuiParagraph::alignDefault() const
|
|
|
|
{
|
|
|
|
return bufferview()->cursor().innerParagraph().layout()->align;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
#if 0
|
2007-11-05 13:52:37 +00:00
|
|
|
GuiView & guiview = static_cast<GuiView &>(lv);
|
2007-10-07 10:10:41 +00:00
|
|
|
#ifdef USE_DOCK_WIDGET
|
2007-10-07 10:31:37 +00:00
|
|
|
return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
|
2007-10-07 10:10:41 +00:00
|
|
|
Qt::TopDockWidgetArea);
|
|
|
|
#else
|
2007-10-07 10:31:37 +00:00
|
|
|
return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
|
2007-10-07 10:10:41 +00:00
|
|
|
#endif
|
2007-10-07 20:00:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
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"
|