*
* \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 "ControlParagraph.h"
+#include "qt_helpers.h"
-#include "debug.h"
-#include "frontend_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 "qt_helpers.h"
#include "Spacing.h"
+#include "support/debug.h"
+#include "support/gettext.h"
+
#include <QCheckBox>
-#include <QCloseEvent>
#include <QLineEdit>
#include <QPushButton>
+#include <QSettings>
+#include <QVariant>
-#include <boost/current_function.hpp>
+#include <sstream>
-using std::string;
-using std::endl;
+using namespace std;
namespace lyx {
namespace frontend {
-GuiParagraphDialog::GuiParagraphDialog(LyXView & lv)
- : GuiDialog(lv, "paragraph")
+GuiParagraph::GuiParagraph(GuiView & lv)
+ : DialogView(lv, "paragraph", qt_("Paragraph Settings"))
{
setupUi(this);
- setViewTitle(_("Paragraph Settings"));
- setController(new ControlParagraph(*this));
-
- connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
- connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
- connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
- connect(restorePB, SIGNAL(clicked()), this, 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);
+ closePB->setText(qt_("&Cancel"));
+#else
+ synchronizedViewCB->setChecked(false);
+#endif
+
+ on_synchronizedViewCB_toggled();
linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
- labelWidth->setWhatsThis( qt_(
+ labelWidth->setWhatsThis(qt_(
"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"
" items is used."
));
- 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;
-
- 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");
-
- bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
- bc().setOK(okPB);
- bc().setApply(applyPB);
- bc().setCancel(closePB);
- bc().setRestore(restorePB);
+ 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;
+
+ alignDefaultLabel_ = alignDefaultRB->text();
}
-ControlParagraph & GuiParagraphDialog::controller()
+void GuiParagraph::on_linespacing_activated(int index)
{
- return static_cast<ControlParagraph &>(GuiDialog::controller());
+ linespacingValue->setEnabled(index == 4);
}
-void GuiParagraphDialog::closeEvent(QCloseEvent * e)
+void GuiParagraph::checkAlignmentRadioButtons()
{
- slotClose();
- e->accept();
+ 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) {
+ LyXAlignment const align = it->first;
+ it->second->setEnabled(align & alignPossible());
+ }
+ if (haveMultiParSelection())
+ alignDefaultRB->setText(alignDefaultLabel_);
+ else
+ alignDefaultRB->setText(alignDefaultLabel_ + " ("
+ + labelMap_[alignDefault()] + ")");
}
-void GuiParagraphDialog::change_adaptor()
+void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
{
- changed();
+ RadioMap::const_iterator it = radioMap_.begin();
+ for (;it != radioMap_.end(); ++it) {
+ it->second->blockSignals(true);
+ it->second->setChecked(align == it->first);
+ it->second->blockSignals(false);
+ }
}
-void GuiParagraphDialog::enableLinespacingValue(int)
+LyXAlignment GuiParagraph::getAlignmentFromDialog() const
{
- bool const enable = linespacing->currentIndex() == 4;
- linespacingValue->setEnabled(enable);
+ LyXAlignment alignment = LYX_ALIGN_NONE;
+ RadioMap::const_iterator it = radioMap_.begin();
+ for (; it != radioMap_.end(); ++it) {
+ if (it->second->isChecked()) {
+ alignment = it->first;
+ break;
+ }
+ }
+ return alignment;
}
-void GuiParagraphDialog::checkAlignmentRadioButtons() {
- LyXAlignment const alignPossible = controller().alignPossible();
+void GuiParagraph::on_synchronizedViewCB_toggled()
+{
+ bool in_sync = synchronizedViewCB->isChecked();
+ restorePB->setEnabled(!in_sync);
+ applyPB->setEnabled(!in_sync);
+ okPB->setEnabled(!in_sync);
+ if (!in_sync)
+ closePB->setText(qt_("&Cancel"));
+ else
+ closePB->setText(qt_("&Close"));
+}
- RadioMap::iterator it = radioMap.begin();
- for (; it != radioMap.end(); ++it) {
- LyXAlignment const align = it->first;
- it->second->setEnabled(align & alignPossible);
- }
- docstring label = labelMap[LYX_ALIGN_LAYOUT];
- if (!controller().haveMulitParSelection())
- label += (" (" + labelMap[controller().alignDefault()] + ")");
- alignDefaultRB->setText(toqstr(label));
+
+void GuiParagraph::changed()
+{
+ if (synchronizedViewCB->isChecked())
+ on_applyPB_clicked();
}
-void GuiParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
+void GuiParagraph::on_applyPB_clicked()
{
- 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;
- }
- }
+ applyView();
+}
+
- lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment "
- << align << std::endl;
+void GuiParagraph::on_okPB_clicked()
+{
+ applyView();
+ hide();
}
-LyXAlignment GuiParagraphDialog::getAlignmentFromDialog()
+void GuiParagraph::on_closePB_clicked()
{
- LyXAlignment alignment = LYX_ALIGN_NONE;
- RadioMap::const_iterator it = radioMap.begin();
- for (; it != radioMap.end(); ++it) {
- if (it->second->isChecked()) {
- alignment = it->first;
- break;
- }
- }
- return alignment;
+ hide();
+}
+
+
+void GuiParagraph::on_restorePB_clicked()
+{
+ updateView();
}
-void GuiParagraphDialog::applyView()
+void GuiParagraph::applyView()
{
- ParagraphParameters & params = controller().params();
+ params_ = params();
- params.align(getAlignmentFromDialog());
+ params_.align(getAlignmentFromDialog());
// get spacing
Spacing::Space ls = Spacing::Default;
break;
case 4:
ls = Spacing::Other;
- other = fromqstr(linespacingValue->text());
+ other = widgetToDoubleStr(linespacingValue);
break;
}
Spacing const spacing(ls, other);
- params.spacing(spacing);
+ params_.spacing(spacing);
// label width
- params.labelWidthString(qstring_to_ucs4(labelWidth->text()));
- // indendation
- params.noindent(!indentCB->isChecked());
+ params_.labelWidthString(qstring_to_ucs4(labelWidth->text()));
+ // indentation
+ params_.noindent(!indentCB->isChecked());
+
+ dispatchParams();
}
-void GuiParagraphDialog::updateContents()
+void GuiParagraph::updateView()
{
- ParagraphParameters const & params = controller().params();
+ on_synchronizedViewCB_toggled();
+
+ ParagraphParameters const & pp = params();
// label width
- docstring const & labelwidth = params.labelWidthString();
- // FIXME We should not compare translated strings
- if (labelwidth != _("Senseless with this layout!")) {
+ docstring const & labelwidth = pp.labelWidthString();
+ if (hasLabelwidth()) {
labelwidthGB->setEnabled(true);
labelWidth->setText(toqstr(labelwidth));
} else {
labelwidthGB->setEnabled(false);
- labelWidth->setText("");
+ labelWidth->setText(QString());
}
// alignment
checkAlignmentRadioButtons();
- alignmentToRadioButtons(params.align());
+ alignmentToRadioButtons(pp.align());
//indentation
- bool const canindent = controller().canIndent();
+ bool const canindent = canIndent();
indentCB->setEnabled(canindent);
- indentCB->setChecked(canindent && !params.noindent());
+ indentCB->setChecked(canindent && !pp.noindent());
// linespacing
int ls;
- Spacing const & space = params.spacing();
+ Spacing const & space = pp.spacing();
switch (space.getSpace()) {
case Spacing::Single:
ls = 1;
}
linespacing->setCurrentIndex(ls);
if (space.getSpace() == Spacing::Other) {
- linespacingValue->setText(toqstr(space.getValueAsString()));
+ doubleToWidget(linespacingValue, space.getValue());
linespacingValue->setEnabled(true);
} else {
linespacingValue->setText(QString());
}
}
+
+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 const & GuiParagraph::params() const
+{
+ if (haveMultiParSelection()) {
+ // FIXME: in case of multi-paragraph selection, it would be nice to
+ // initialise the parameters that are common to all paragraphs.
+ static ParagraphParameters const empty;
+ return empty;
+ }
+ return bufferview()->cursor().innerParagraph().params();
+}
+
+
+void GuiParagraph::dispatchParams()
+{
+ ostringstream data;
+ params_.write(data);
+ FuncRequest const fr(getLfun(), data.str());
+ dispatch(fr);
+}
+
+
+bool GuiParagraph::haveMultiParSelection() const
+{
+ Cursor const & cur = bufferview()->cursor();
+ return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
+}
+
+
+bool GuiParagraph::canIndent() const
+{
+ Layout const lay = bufferview()->cursor().innerParagraph().layout();
+ if (buffer().params().paragraph_separation
+ == BufferParams::ParagraphIndentSeparation)
+ return (lay.toggle_indent != ITOGGLE_NEVER);
+ return (lay.toggle_indent == ITOGGLE_ALWAYS);
+}
+
+
+LyXAlignment GuiParagraph::alignPossible() const
+{
+ return bufferview()->cursor().innerParagraph().layout().alignpossible;
+}
+
+
+LyXAlignment GuiParagraph::alignDefault() const
+{
+ return bufferview()->cursor().innerParagraph().layout().align;
+}
+
+
+bool GuiParagraph::hasLabelwidth() const
+{
+ Layout layout = bufferview()->cursor().innerParagraph().layout();
+ return (layout.margintype == MARGIN_MANUAL
+ || layout.latextype == LATEX_BIB_ENVIRONMENT);
+}
+
+
+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());
+}
+
+
+Dialog * createGuiParagraph(GuiView & lv)
+{
+ return new GuiParagraph(lv);
+}
+
+
} // namespace frontend
} // namespace lyx
-#include "GuiParagraph_moc.cpp"
+#include "moc_GuiParagraph.cpp"