*
* \author Edwin Leuven
* \author Richard Heck
+ * \author Abdelrazak Younes
+ * \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
#include "GuiParagraph.h"
-#include "debug.h"
-#include "frontend_helpers.h"
-#include "ParagraphParameters.h"
#include "qt_helpers.h"
+
+#include "Buffer.h"
+#include "BufferParams.h"
+#include "BufferView.h"
+#include "Cursor.h"
+#include "FuncRequest.h"
+#include "GuiView.h"
+#include "Lexer.h"
+#include "Paragraph.h"
+#include "ParagraphParameters.h"
#include "Spacing.h"
+#include "support/debug.h"
+#include "support/gettext.h"
+
#include <QCheckBox>
-#include <QCloseEvent>
#include <QLineEdit>
#include <QPushButton>
-using std::string;
-using std::endl;
-
-/////////////////////////////////////////////////////////////////////
-//
-// GuiParagraphDialog
-//
-/////////////////////////////////////////////////////////////////////
+#include <sstream>
-
-#include <boost/current_function.hpp>
+using namespace std;
namespace lyx {
namespace frontend {
-GuiParagraphDialog::GuiParagraphDialog(GuiParagraph * form)
- : form_(form)
+GuiParagraph::GuiParagraph(GuiView & lv)
+ : DialogView(lv, "paragraph", qt_("Paragraph Settings"))
{
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(alignDefaultRB, 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()));
-
+ 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()));
+ connect(linespacingValue, SIGNAL(textChanged(QString)),
+ this, SLOT(changed()));
+ connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
+ connect(labelWidth, SIGNAL(textChanged(QString)),
+ this, SLOT(changed()));
+
+#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);
+#else
+ synchronizedViewCB->setChecked(false);
+#endif
+
+ on_synchronizedViewCB_toggled();
linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
labelWidth->setWhatsThis( qt_(
radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
-
- 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");
-}
-
-void GuiParagraphDialog::closeEvent(QCloseEvent * e)
-{
- form_->slotWMHide();
- e->accept();
+ const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
}
-void GuiParagraphDialog::change_adaptor()
+void GuiParagraph::on_linespacing_activated(int index)
{
- form_->changed();
+ linespacingValue->setEnabled(index == 4);
}
-void GuiParagraphDialog::enableLinespacingValue(int)
+void GuiParagraph::checkAlignmentRadioButtons()
{
- bool const enable = linespacing->currentIndex() == 4;
- linespacingValue->setEnabled(enable);
-}
-
-
-void GuiParagraphDialog::checkAlignmentRadioButtons() {
- LyXAlignment const alignPossible = form_->controller().alignPossible();
-
- QPRadioMap::iterator it = radioMap.begin();
+ RadioMap::iterator it = radioMap.begin();
for (; it != radioMap.end(); ++it) {
LyXAlignment const align = it->first;
- it->second->setEnabled(align & alignPossible);
+ it->second->setEnabled(align & alignPossible());
}
- docstring label = labelMap[LYX_ALIGN_LAYOUT];
- if (!form_->controller().haveMulitParSelection())
- label += (" (" + labelMap[form_->controller().alignDefault()] + ")");
- alignDefaultRB->setText(toqstr(label));
+ if (haveMultiParSelection())
+ alignDefaultRB->setText(alignDefaultLabel);
+ else
+ alignDefaultRB->setText(alignDefaultLabel + " ("
+ + toqstr(labelMap[alignDefault()]) + ")");
}
-void GuiParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
+void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
{
- QPRadioMap::const_iterator it = radioMap.begin();
+ RadioMap::const_iterator it = radioMap.begin();
for (;it != radioMap.end(); ++it) {
- if (align == it->first) {
- it->second->blockSignals(true);
- it->second->setChecked(true);
- it->second->blockSignals(false);
- return;
- }
+ it->second->blockSignals(true);
+ it->second->setChecked(align == it->first);
+ it->second->blockSignals(false);
}
-
- lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment "
- << align << std::endl;
}
-LyXAlignment GuiParagraphDialog::getAlignmentFromDialog()
+LyXAlignment GuiParagraph::getAlignmentFromDialog()
{
LyXAlignment alignment = LYX_ALIGN_NONE;
- QPRadioMap::const_iterator it = radioMap.begin();
+ RadioMap::const_iterator it = radioMap.begin();
for (; it != radioMap.end(); ++it) {
if (it->second->isChecked()) {
alignment = it->first;
}
-/////////////////////////////////////////////////////////////////////
-//
-// GuiParagraph
-//
-/////////////////////////////////////////////////////////////////////
-
-
-GuiParagraph::GuiParagraph(GuiDialog & parent)
- : GuiView<GuiParagraphDialog>(parent, _("Paragraph Settings"))
-{}
+void GuiParagraph::on_synchronizedViewCB_toggled()
+{
+ bool in_sync = synchronizedViewCB->isChecked();
+ restorePB->setEnabled(!in_sync);
+ applyPB->setEnabled(!in_sync);
+}
-void GuiParagraph::build_dialog()
+void GuiParagraph::changed()
{
- // the dialog
- dialog_.reset(new GuiParagraphDialog(this));
-
- // Manage the ok, apply, restore and cancel/close buttons
- bc().setOK(dialog_->okPB);
- bc().setApply(dialog_->applyPB);
- bc().setCancel(dialog_->closePB);
- bc().setRestore(dialog_->restorePB);
+ if (synchronizedViewCB->isChecked())
+ on_applyPB_clicked();
}
-void GuiParagraph::apply()
+void GuiParagraph::on_applyPB_clicked()
{
- ParagraphParameters & params = controller().params();
+ ParagraphParameters & pp = params();
- params.align(dialog_->getAlignmentFromDialog());
+ pp.align(getAlignmentFromDialog());
// get spacing
- Spacing::Space linespacing = Spacing::Default;
+ Spacing::Space ls = Spacing::Default;
string other;
- switch (dialog_->linespacing->currentIndex()) {
+ switch (linespacing->currentIndex()) {
case 0:
- linespacing = Spacing::Default;
+ ls = Spacing::Default;
break;
case 1:
- linespacing = Spacing::Single;
+ ls = Spacing::Single;
break;
case 2:
- linespacing = Spacing::Onehalf;
+ ls = Spacing::Onehalf;
break;
case 3:
- linespacing = Spacing::Double;
+ ls = Spacing::Double;
break;
case 4:
- linespacing = Spacing::Other;
- other = fromqstr(dialog_->linespacingValue->text());
+ ls = Spacing::Other;
+ other = fromqstr(linespacingValue->text());
break;
}
- Spacing const spacing(linespacing, other);
- params.spacing(spacing);
+ Spacing const spacing(ls, other);
+ pp.spacing(spacing);
// label width
- params.labelWidthString(qstring_to_ucs4(dialog_->labelWidth->text()));
+ pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
// indendation
- params.noindent(!dialog_->indentCB->isChecked());
+ pp.noindent(!indentCB->isChecked());
+
+ dispatchParams();
+}
+
+
+void GuiParagraph::on_restorePB_clicked()
+{
+ updateView();
}
-void GuiParagraph::update_contents()
+void GuiParagraph::updateView()
{
- ParagraphParameters const & params = controller().params();
+ on_synchronizedViewCB_toggled();
+
+ ParagraphParameters const & pp = params();
// label width
- docstring const & labelwidth = params.labelWidthString();
+ docstring const & labelwidth = pp.labelWidthString();
// FIXME We should not compare translated strings
if (labelwidth != _("Senseless with this layout!")) {
- dialog_->labelwidthGB->setEnabled(true);
- dialog_->labelWidth->setText(toqstr(labelwidth));
+ labelwidthGB->setEnabled(true);
+ labelWidth->setText(toqstr(labelwidth));
} else {
- dialog_->labelwidthGB->setEnabled(false);
- dialog_->labelWidth->setText("");
+ labelwidthGB->setEnabled(false);
+ labelWidth->setText("");
}
// alignment
- dialog_->checkAlignmentRadioButtons();
- dialog_->alignmentToRadioButtons(params.align());
+ checkAlignmentRadioButtons();
+ alignmentToRadioButtons(pp.align());
//indentation
- bool const canindent = controller().canIndent();
- dialog_->indentCB->setEnabled(canindent);
- dialog_->indentCB->setChecked(canindent && !params.noindent());
+ bool const canindent = canIndent();
+ indentCB->setEnabled(canindent);
+ indentCB->setChecked(canindent && !pp.noindent());
// linespacing
- int linespacing;
- Spacing const & space = params.spacing();
+ int ls;
+ Spacing const & space = pp.spacing();
switch (space.getSpace()) {
case Spacing::Single:
- linespacing = 1;
+ ls = 1;
break;
case Spacing::Onehalf:
- linespacing = 2;
+ ls = 2;
break;
case Spacing::Double:
- linespacing = 3;
+ ls = 3;
break;
case Spacing::Other:
- linespacing = 4;
+ ls = 4;
break;
default:
- linespacing = 0;
+ ls = 0;
break;
}
- dialog_->linespacing->setCurrentIndex(linespacing);
+ linespacing->setCurrentIndex(ls);
if (space.getSpace() == Spacing::Other) {
- dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
- dialog_->linespacingValue->setEnabled(true);
+ linespacingValue->setText(toqstr(space.getValueAsString()));
+ linespacingValue->setEnabled(true);
} else {
- dialog_->linespacingValue->setText("");
- dialog_->linespacingValue->setEnabled(false);
+ linespacingValue->setText(QString());
+ linespacingValue->setEnabled(false);
}
}
+
+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);
+ RadioMap::const_iterator it = radioMap.begin();
+ for (; it != radioMap.end(); ++it)
+ it->second->setEnabled(enable);
+}
+
+
+ParagraphParameters & GuiParagraph::params()
+{
+ if (haveMultiParSelection()) {
+ 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 (haveMultiParSelection()) {
+ ostringstream data;
+ multiparsel_.write(data);
+ FuncRequest const fr(getLfun(), data.str());
+ dispatch(fr);
+ return;
+ }
+
+ bufferview()->updateMetrics();
+ bufferview()->buffer().changed();
+}
+
+
+bool GuiParagraph::haveMultiParSelection()
+{
+ 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;
+}
+
+
+Dialog * createGuiParagraph(GuiView & lv)
+{
+ return new GuiParagraph(lv);
+}
+
+
} // namespace frontend
} // namespace lyx