#include "GuiParagraph.h"
+#include "qt_helpers.h"
+
#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "Cursor.h"
-//#include "DialogView.h"
-//#include "DockView.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 <sstream>
-using std::istringstream;
-using std::ostringstream;
-using std::string;
-using std::endl;
+using namespace std;
namespace lyx {
namespace frontend {
GuiParagraph::GuiParagraph(GuiView & lv)
- : DialogView(lv, "paragraph")
+ : DialogView(lv, "paragraph", qt_("Paragraph Settings"))
{
setupUi(this);
- setWindowTitle(qt_("Paragraph Settings"));
connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
connect(labelWidth, SIGNAL(textChanged(QString)),
this, SLOT(changed()));
-
+#ifdef Q_OS_MAC
+ // 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));
+ QDoubleValidator * val = new QDoubleValidator(linespacingValue);
+ val->setNotation(QDoubleValidator::StandardNotation);
+ linespacingValue->setValidator(val);
- 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_BLOCK] = _("Justified");
- labelMap[LYX_ALIGN_LEFT] = _("Left");
- labelMap[LYX_ALIGN_RIGHT] = _("Right");
- labelMap[LYX_ALIGN_CENTER] = _("Center");
+ 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;
- const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
+ alignDefaultLabel_ = alignDefaultRB->text();
}
void GuiParagraph::checkAlignmentRadioButtons()
{
- RadioMap::iterator it = radioMap.begin();
- for (; it != radioMap.end(); ++it) {
+ 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 (haveMulitParSelection())
- alignDefaultRB->setText(alignDefaultLabel);
+ if (haveMultiParSelection())
+ alignDefaultRB->setText(alignDefaultLabel_);
else
- alignDefaultRB->setText(alignDefaultLabel + " ("
- + toqstr(labelMap[alignDefault()]) + ")");
+ alignDefaultRB->setText(alignDefaultLabel_ + " ("
+ + labelMap_[alignDefault()] + ")");
}
void GuiParagraph::alignmentToRadioButtons(LyXAlignment align)
{
- RadioMap::const_iterator it = radioMap.begin();
- for (;it != radioMap.end(); ++it) {
- if (!it->second->isEnabled())
- continue;
+ 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);
}
-LyXAlignment GuiParagraph::getAlignmentFromDialog()
+LyXAlignment GuiParagraph::getAlignmentFromDialog() const
{
LyXAlignment alignment = LYX_ALIGN_NONE;
- RadioMap::const_iterator it = radioMap.begin();
- for (; it != radioMap.end(); ++it) {
+ RadioMap::const_iterator it = radioMap_.begin();
+ for (; it != radioMap_.end(); ++it) {
if (it->second->isChecked()) {
alignment = it->first;
break;
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"));
}
void GuiParagraph::changed()
{
- if (synchronizedViewCB->isChecked())
+ QLocale loc;
+ // We apply immediately, except if we have custom line spacing
+ // with an intermediate result (trailing decimal separator) or
+ // an invalid value (which might as well be intermediate)
+ if (synchronizedViewCB->isChecked()
+ && (linespacing->currentIndex() != 4
+ || (!linespacingValue->text().endsWith(loc.decimalPoint())
+ && linespacingValue->hasAcceptableInput())))
on_applyPB_clicked();
}
void GuiParagraph::on_applyPB_clicked()
{
- ParagraphParameters & pp = params();
+ applyView();
+}
+
+
+void GuiParagraph::on_okPB_clicked()
+{
+ applyView();
+ hide();
+}
+
+
+void GuiParagraph::on_closePB_clicked()
+{
+ hide();
+}
+
+
+void GuiParagraph::on_restorePB_clicked()
+{
+ updateView();
+}
+
+
+void GuiParagraph::applyView()
+{
+ params_ = params();
- pp.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);
- pp.spacing(spacing);
+ params_.spacing(spacing);
// label width
- pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
- // indendation
- pp.noindent(!indentCB->isChecked());
+ params_.labelWidthString(qstring_to_ucs4(labelWidth->text()));
+ // indentation
+ params_.noindent(!indentCB->isChecked());
dispatchParams();
}
-void GuiParagraph::on_restorePB_clicked()
-{
- updateView();
-}
-
-
-void GuiParagraph::enableView(bool enable)
-{
-}
-
-
void GuiParagraph::updateView()
{
on_synchronizedViewCB_toggled();
// label width
docstring const & labelwidth = pp.labelWidthString();
- // FIXME We should not compare translated strings
- if (labelwidth != _("Senseless with this layout!")) {
+ if (hasLabelwidth()) {
labelwidthGB->setEnabled(true);
labelWidth->setText(toqstr(labelwidth));
} else {
labelwidthGB->setEnabled(false);
- labelWidth->setText("");
+ labelWidth->setText(QString());
}
// alignment
// linespacing
int ls;
+ bool pending_input = false;
Spacing const & space = pp.spacing();
- switch (space.getSpace()) {
- case Spacing::Single:
- ls = 1;
- break;
- case Spacing::Onehalf:
- ls = 2;
- break;
- case Spacing::Double:
- ls = 3;
- break;
- case Spacing::Other:
+ if (synchronizedViewCB->isChecked() && linespacingValue->hasFocus()) {
+ // The user is about to enter custom spacing.
+ // We thus stay in Custom mode.
+ // This prevents the combo from e.g. immediately
+ // switching to single if a user enters "1" in the
+ // linespacingValue widget while aiming at e.g. "1.3"
ls = 4;
- break;
- default:
- ls = 0;
- break;
+ pending_input = true;
+ } else {
+ switch (space.getSpace()) {
+ case Spacing::Single:
+ ls = 1;
+ break;
+ case Spacing::Onehalf:
+ ls = 2;
+ break;
+ case Spacing::Double:
+ ls = 3;
+ break;
+ case Spacing::Other:
+ ls = 4;
+ break;
+ default:
+ ls = 0;
+ break;
+ }
}
linespacing->setCurrentIndex(ls);
- if (space.getSpace() == Spacing::Other) {
- linespacingValue->setText(toqstr(space.getValueAsString()));
+ if (space.getSpace() == Spacing::Other || pending_input) {
+ doubleToWidget(linespacingValue, space.getValue());
linespacingValue->setEnabled(true);
} else {
linespacingValue->setText(QString());
}
-ParagraphParameters & GuiParagraph::params()
+void GuiParagraph::enableView(bool enable)
{
- 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();
+ 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()
{
- if (haveMulitParSelection()) {
- ostringstream data;
- multiparsel_.write(data);
- FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
- dispatch(fr);
- return;
- }
-
- bufferview()->updateMetrics();
- bufferview()->buffer().changed();
+ ostringstream data;
+ params_.write(data);
+ FuncRequest const fr(getLfun(), data.str());
+ dispatch(fr);
}
-bool GuiParagraph::haveMulitParSelection()
+bool GuiParagraph::haveMultiParSelection() const
{
- Cursor cur = bufferview()->cursor();
+ Cursor const & cur = bufferview()->cursor();
return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
}
-
+
bool GuiParagraph::canIndent() const
{
- return buffer().params().paragraph_separation ==
- BufferParams::PARSEP_INDENT;
+ 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;
+ return bufferview()->cursor().innerParagraph().layout().alignpossible;
}
LyXAlignment GuiParagraph::alignDefault() const
{
- return bufferview()->cursor().innerParagraph().layout()->align;
+ return bufferview()->cursor().innerParagraph().layout().align;
}
-Dialog * createGuiParagraph(GuiView & lv)
+bool GuiParagraph::hasLabelwidth() const
{
-#if 0
- GuiView & guiview = static_cast<GuiView &>(lv);
-#ifdef USE_DOCK_WIDGET
- return new DockView<ControlParagraph, GuiParagraph>(guiview, "paragraph",
- Qt::TopDockWidgetArea);
-#else
- return new DialogView<ControlParagraph, GuiParagraph>(guiview, "paragraph");
-#endif
-#endif
+ Layout layout = bufferview()->cursor().innerParagraph().layout();
+ return (layout.margintype == MARGIN_MANUAL
+ || layout.latextype == LATEX_BIB_ENVIRONMENT);
+}
+
+void GuiParagraph::saveSession(QSettings & settings) const
+{
+ Dialog::saveSession(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"