#include "Validator.h"
#include "Spacing.h"
-#include "FuncRequest.h"
#include "insets/InsetSpace.h"
+#include "mathed/InsetMathSpace.h"
+
#include "support/gettext.h"
#include "support/lstrings.h"
namespace lyx {
namespace frontend {
-GuiHSpace::GuiHSpace(GuiView & lv, bool math)
- : GuiDialog(lv, math ? "mathspace" : "space", qt_("Horizontal Space Settings"))
+GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
+ : InsetParamsWidget(parent), math_mode_(math_mode)
{
- params_.math = math;
setupUi(this);
- connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
- connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
- connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
+ spacingCO->clear();
+ if (math_mode_) {
+ spacingCO->addItem(qt_("Interword Space"), "normal");
+ spacingCO->addItem(qt_("Thin Space"), "thinspace");
+ spacingCO->addItem(qt_("Medium Space"), "medspace");
+ spacingCO->addItem(qt_("Thick Space"), "thickspace");
+ spacingCO->addItem(qt_("Negative Thin Space"), "negthinspace");
+ spacingCO->addItem(qt_("Negative Medium Space"), "negmedspace");
+ spacingCO->addItem(qt_("Negative Thick Space"), "negthickspace");
+ spacingCO->addItem(qt_("Half Quad (0.5 em)"), "halfquad");
+ spacingCO->addItem(qt_("Quad (1 em)"), "quad");
+ spacingCO->addItem(qt_("Double Quad (2 em)"), "qquad");
+ spacingCO->addItem(qt_("Horizontal Fill"), "hfill");
+ spacingCO->addItem(qt_("Custom"), "custom");
+ } else {
+ spacingCO->addItem(qt_("Interword Space"), "normal");
+ spacingCO->addItem(qt_("Thin Space"), "thinspace");
+ spacingCO->addItem(qt_("Negative Thin Space"), "negthinspace");
+ spacingCO->addItem(qt_("Negative Medium Space"), "negmedspace");
+ spacingCO->addItem(qt_("Negative Thick Space"), "negthickspace");
+ spacingCO->addItem(qt_("Half Quad (0.5 em)"), "halfquad");
+ spacingCO->addItem(qt_("Quad (1 em)"), "quad");
+ spacingCO->addItem(qt_("Double Quad (2 em)"), "qquad");
+ spacingCO->addItem(qt_("Horizontal Fill"), "hfill");
+ spacingCO->addItem(qt_("Custom"), "custom");
+ spacingCO->addItem(qt_("Visible Space"), "visible");
+ }
connect(spacingCO, SIGNAL(highlighted(QString)),
- this, SLOT(change_adaptor()));
+ this, SLOT(changedSlot()));
connect(valueLE, SIGNAL(textChanged(QString)),
- this, SLOT(change_adaptor()));
+ this, SLOT(changedSlot()));
connect(spacingCO, SIGNAL(activated(int)),
- this, SLOT(enableWidgets(int)));
+ this, SLOT(changedSlot()));
connect(keepCB, SIGNAL(clicked()),
- this, SLOT(change_adaptor()));
+ this, SLOT(changedSlot()));
connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
- this, SLOT(change_adaptor()));
+ this, SLOT(changedSlot()));
connect(fillPatternCO, SIGNAL(activated(int)),
- this, SLOT(patternChanged()));
+ this, SLOT(changedSlot()));
- if (params_.math)
- valueLE->setValidator(unsignedLengthValidator(valueLE));
+ // Set up a signed (glue) length validator
+ LengthValidator * v = new LengthValidator(valueLE);
+ if (math_mode_)
+ v->setBottom(Length());
else
- valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
-
- // Manage the ok, apply, restore and cancel/close buttons
- bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
- bc().setOK(okPB);
- bc().setApply(applyPB);
- bc().setCancel(closePB);
-
- // disable for read-only documents
- bc().addReadOnly(spacingCO);
- bc().addReadOnly(valueLE);
- bc().addReadOnly(unitCO);
- bc().addReadOnly(keepCB);
- bc().addReadOnly(fillPatternCO);
+ v->setBottom(GlueLength());
+ valueLE->setValidator(v);
// initialize the length validator
- bc().addCheckedLineEdit(valueLE, valueL);
+ addCheckedWidget(valueLE, valueL);
+ enableWidgets();
}
-void GuiHSpace::change_adaptor()
+void GuiHSpace::changedSlot()
{
+ enableWidgets();
changed();
}
-void GuiHSpace::setMath(bool custom)
+void GuiHSpace::enableWidgets() const
{
+ QString const selection = spacingCO->itemData(spacingCO->currentIndex()).toString();
+ bool const custom = selection == "custom";
valueLE->setEnabled(custom);
+ if (custom)
+ valueLE->setFocus();
+ valueL->setEnabled(custom);
unitCO->setEnabled(custom);
- fillPatternCO->setEnabled(false);
- keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
- keepCB->setEnabled(false);
-}
-
-
-void GuiHSpace::enableWidgets(int selection)
-{
- if (params_.math) {
- setMath(selection == 9);
- changed();
- return;
- }
- valueLE->setEnabled(selection == 7);
- unitCO->setEnabled(selection == 7);
- fillPatternCO->setEnabled(selection == 6);
- int pattern = fillPatternCO->currentIndex();
+ fillPatternCO->setEnabled(!math_mode_ && selection == "hfill");
+ fillPatternL->setEnabled(!math_mode_ && selection == "hfill");
+ bool const no_pattern = fillPatternCO->currentIndex() == 0 || math_mode_;
bool const enable_keep =
- selection == 0 || selection == 3 ||
- (selection == 6 && pattern == 0) || selection == 7;
+ selection == "normal" || selection == "halfquad"
+ || (selection == "hfill" && no_pattern) || custom;
keepCB->setEnabled(enable_keep);
- if (selection == 3)
- keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
- "Note that a protected Half Quad will be turned into\n"
- "a vertical space if used at the beginning of a paragraph!"));
- else
- keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
- changed();
+ keepL->setEnabled(enable_keep);
}
-void GuiHSpace::patternChanged()
+void GuiHSpace::paramsToDialog(Inset const * inset)
{
- enableWidgets(spacingCO->currentIndex());
- changed();
-}
-
+ InsetSpaceParams const params = math_mode_
+ ? static_cast<InsetMathSpace const *>(inset)->params()
+ : static_cast<InsetSpace const *>(inset)->params();
-static void setWidgetsFromHSpace(InsetSpaceParams const & params,
- QComboBox * spacing,
- QLineEdit * value,
- LengthCombo * unit,
- QCheckBox * keep,
- QComboBox * fillPattern)
-{
- spacing->clear();
- if (params.math) {
- spacing->addItem(qt_("Thin space"));
- spacing->addItem(qt_("Medium space"));
- spacing->addItem(qt_("Thick space"));
- spacing->addItem(qt_("Negative thin space"));
- spacing->addItem(qt_("Negative medium space"));
- spacing->addItem(qt_("Negative thick space"));
- spacing->addItem(qt_("Half Quad (0.5 em)"));
- spacing->addItem(qt_("Quad (1 em)"));
- spacing->addItem(qt_("Double Quad (2 em)"));
- spacing->addItem(qt_("Custom"));
- keep->setEnabled(false);
- fillPattern->setEnabled(false);
- } else {
- spacing->addItem(qt_("Inter-word space"));
- spacing->addItem(qt_("Thin space"));
- spacing->addItem(qt_("Negative thin space"));
- spacing->addItem(qt_("Half Quad (0.5 em)"));
- spacing->addItem(qt_("Quad (1 em)"));
- spacing->addItem(qt_("Double Quad (2 em)"));
- spacing->addItem(qt_("Horizontal Fill"));
- spacing->addItem(qt_("Custom"));
- keep->setEnabled(true);
- fillPattern->setEnabled(true);
- }
-
- int item = 0;
+ QString item;
int pattern = 0;
bool protect = false;
switch (params.kind) {
case InsetSpaceParams::NORMAL:
- item = 0;
+ item = "normal";
break;
case InsetSpaceParams::PROTECTED:
- item = 0;
- protect = !params.math;
+ item = "normal";
+ protect = true;
+ break;
+ case InsetSpaceParams::VISIBLE:
+ item = "visible";
+ protect = true;
break;
case InsetSpaceParams::THIN:
- item = params.math ? 0 : 1;
+ item = "thinspace";
break;
case InsetSpaceParams::MEDIUM:
- item = 1;
+ item = "medspace";
break;
case InsetSpaceParams::THICK:
- item = params.math ? 2 : 1;
+ item = "thickspace";
break;
case InsetSpaceParams::NEGTHIN:
- item = params.math ? 3 : 2;
+ item = "negthinspace";
break;
case InsetSpaceParams::NEGMEDIUM:
- item = params.math ? 4 : 2;
+ item = "negmedspace";
break;
case InsetSpaceParams::NEGTHICK:
- item = params.math ? 5 : 2;
+ item = "negthickspace";
break;
case InsetSpaceParams::ENSKIP:
- item = params.math ? 6 : 3;
+ item = "halfquad";
break;
case InsetSpaceParams::ENSPACE:
- item = params.math ? 6 : 3;
- protect = !params.math;
+ item = "halfquad";
+ protect = true;
break;
case InsetSpaceParams::QUAD:
- item = params.math ? 7 : 4;
+ item = "quad";
break;
case InsetSpaceParams::QQUAD:
- item = params.math ? 8 : 5;
+ item = "qquad";
break;
case InsetSpaceParams::HFILL:
- item = params.math ? 3 : 6;
+ item = "hfill";
break;
case InsetSpaceParams::HFILL_PROTECTED:
- item = params.math ? 3 : 6;
- protect = !params.math;
+ item = "hfill";
+ protect = true;
break;
case InsetSpaceParams::DOTFILL:
- item = params.math ? 3 : 6;
+ item = "hfill";
pattern = 1;
break;
case InsetSpaceParams::HRULEFILL:
- item = params.math ? 3 : 6;
+ item = "hfill";
pattern = 2;
break;
case InsetSpaceParams::LEFTARROWFILL:
- item = params.math ? 3 : 6;
+ item = "hfill";
pattern = 3;
break;
case InsetSpaceParams::RIGHTARROWFILL:
- item = params.math ? 3 : 6;
+ item = "hfill";
pattern = 4;
break;
case InsetSpaceParams::UPBRACEFILL:
- item = params.math ? 3 : 6;
+ item = "hfill";
pattern = 5;
break;
case InsetSpaceParams::DOWNBRACEFILL:
- item = params.math ? 3 : 6;
+ item = "hfill";
pattern = 6;
break;
case InsetSpaceParams::CUSTOM:
- item = params.math ? 9 : 7;
+ item = "custom";
break;
case InsetSpaceParams::CUSTOM_PROTECTED:
- item = params.math ? 9 : 7;
- protect = !params.math;
+ item = "custom";
+ protect = true;
break;
}
- spacing->setCurrentIndex(item);
- fillPattern->setCurrentIndex(pattern);
- keep->setChecked(protect);
-
+ spacingCO->setCurrentIndex(spacingCO->findData(item));
+ fillPatternCO->setCurrentIndex(pattern);
+ keepCB->setChecked(protect);
+ if (item == "halfquad") {
+ keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
+ "Note that a protected Half Quad will be turned into\n"
+ "a vertical space if used at the beginning of a paragraph!"));
+ } else {
+ keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
+ }
Length::UNIT const default_unit = Length::defaultUnit();
- if (item == (params.math ? 9 : 7)) {
+ if (item == "custom") {
string length = params.length.asString();
- lengthToWidgets(value, unit, length, default_unit);
+ lengthToWidgets(valueLE, unitCO, length, default_unit);
} else
- lengthToWidgets(value, unit, "", default_unit);
+ lengthToWidgets(valueLE, unitCO, "", default_unit);
+
+ enableWidgets();
}
-static InsetSpaceParams setHSpaceFromWidgets(int spacing,
- QLineEdit * value, LengthCombo * unit, bool keep, int fill, bool math)
+docstring GuiHSpace::dialogToParams() const
{
- InsetSpaceParams params(math);
- if (math) {
- switch (spacing) {
- case 0: params.kind = InsetSpaceParams::THIN; break;
- case 1: params.kind = InsetSpaceParams::MEDIUM; break;
- case 2: params.kind = InsetSpaceParams::THICK; break;
- case 3: params.kind = InsetSpaceParams::NEGTHIN; break;
- case 4: params.kind = InsetSpaceParams::NEGMEDIUM; break;
- case 5: params.kind = InsetSpaceParams::NEGTHICK; break;
- case 6: params.kind = InsetSpaceParams::ENSKIP; break;
- case 7: params.kind = InsetSpaceParams::QUAD; break;
- case 8: params.kind = InsetSpaceParams::QQUAD; break;
- case 9:
- params.kind = InsetSpaceParams::CUSTOM;
- params.length = GlueLength(widgetsToLength(value, unit));
- break;
- }
- return params;
- }
-
- switch (spacing) {
- case 0:
- if (keep)
- params.kind = InsetSpaceParams::PROTECTED;
- else
- params.kind = InsetSpaceParams::NORMAL;
- break;
+ InsetSpaceParams params = math_mode_ ?
+ InsetSpaceParams(true) : InsetSpaceParams(false);
+
+ QString const item =
+ spacingCO->itemData(spacingCO->currentIndex()).toString();
+
+ if (item == "normal")
+ params.kind = keepCB->isChecked() ?
+ InsetSpaceParams::PROTECTED : InsetSpaceParams::NORMAL;
+ else if (item == "thinspace")
+ params.kind = InsetSpaceParams::THIN;
+ else if (item == "medspace")
+ params.kind = InsetSpaceParams::MEDIUM;
+ else if (item == "thickspace")
+ params.kind = InsetSpaceParams::THICK;
+ else if (item == "negthinspace")
+ params.kind = InsetSpaceParams::NEGTHIN;
+ else if (item == "negmedspace")
+ params.kind = InsetSpaceParams::NEGMEDIUM;
+ else if (item == "negthickspace")
+ params.kind = InsetSpaceParams::NEGTHICK;
+ else if (item == "halfquad")
+ params.kind = keepCB->isChecked() ?
+ InsetSpaceParams::ENSPACE : InsetSpaceParams::ENSKIP;
+ else if (item == "quad")
+ params.kind = InsetSpaceParams::QUAD;
+ else if (item == "qquad")
+ params.kind = InsetSpaceParams::QQUAD;
+ else if (item == "hfill") {
+ switch (fillPatternCO->currentIndex()) {
case 1:
- params.kind = InsetSpaceParams::THIN;
+ params.kind = InsetSpaceParams::DOTFILL;
break;
case 2:
- params.kind = InsetSpaceParams::NEGTHIN;
+ params.kind = InsetSpaceParams::HRULEFILL;
break;
case 3:
- if (keep)
- params.kind = InsetSpaceParams::ENSPACE;
- else
- params.kind = InsetSpaceParams::ENSKIP;
+ params.kind = InsetSpaceParams::LEFTARROWFILL;
break;
case 4:
- params.kind = InsetSpaceParams::QUAD;
+ params.kind = InsetSpaceParams::RIGHTARROWFILL;
break;
case 5:
- params.kind = InsetSpaceParams::QQUAD;
+ params.kind = InsetSpaceParams::UPBRACEFILL;
break;
case 6:
- if (fill == 1)
- params.kind = InsetSpaceParams::DOTFILL;
- else if (fill == 2)
- params.kind = InsetSpaceParams::HRULEFILL;
- else if (fill == 3)
- params.kind = InsetSpaceParams::LEFTARROWFILL;
- else if (fill == 4)
- params.kind = InsetSpaceParams::RIGHTARROWFILL;
- else if (fill == 5)
- params.kind = InsetSpaceParams::UPBRACEFILL;
- else if (fill == 6)
- params.kind = InsetSpaceParams::DOWNBRACEFILL;
- else if (keep)
+ params.kind = InsetSpaceParams::DOWNBRACEFILL;
+ break;
+ default:
+ if (keepCB->isChecked())
params.kind = InsetSpaceParams::HFILL_PROTECTED;
else
params.kind = InsetSpaceParams::HFILL;
break;
- case 7:
- if (keep)
- params.kind = InsetSpaceParams::CUSTOM_PROTECTED;
- else
- params.kind = InsetSpaceParams::CUSTOM;
- params.length = GlueLength(widgetsToLength(value, unit));
- break;
- }
- return params;
-}
-
-
-void GuiHSpace::applyView()
-{
- params_ = setHSpaceFromWidgets(spacingCO->currentIndex(),
- valueLE, unitCO, keepCB->isChecked(),
- fillPatternCO->currentIndex(), params_.math);
-}
-
-
-void GuiHSpace::updateContents()
-{
- setWidgetsFromHSpace(params_, spacingCO, valueLE, unitCO, keepCB,
- fillPatternCO);
- enableWidgets(spacingCO->currentIndex());
-}
-
-
-bool GuiHSpace::initialiseParams(string const & data)
-{
- bool const math = params_.math;
- InsetSpace::string2params(data, params_);
- params_.math = math;
- if (params_.math)
- setMath(params_.kind == InsetSpaceParams::CUSTOM);
- setButtonsValid(true);
- return true;
-}
-
-
-void GuiHSpace::clearParams()
-{
- params_ = InsetSpaceParams(params_.math);
+ }
+ } else if (item == "custom") {
+ params.kind = keepCB->isChecked() ?
+ InsetSpaceParams::CUSTOM_PROTECTED : InsetSpaceParams::CUSTOM;
+ params.length = GlueLength(widgetsToLength(valueLE, unitCO));
+ } else if (item == "visible")
+ params.kind = InsetSpaceParams::VISIBLE;
+
+ return from_ascii(InsetSpace::params2string(params));
}
-void GuiHSpace::dispatchParams()
+bool GuiHSpace::checkWidgets(bool readonly) const
{
- dispatch(FuncRequest(getLfun(), InsetSpace::params2string(params_)));
-}
-
+ valueLE->setReadOnly(readonly);
+
+ if (readonly) {
+ spacingCO->setEnabled(false);
+ unitCO->setEnabled(false);
+ fillPatternCO->setEnabled(false);
+ keepCB->setEnabled(false);
+ valueLE->setEnabled(false);
+ } else
+ enableWidgets();
-bool GuiHSpace::isValid()
-{
- return spacingCO->currentIndex() != (params_.math ? 9 : 7)
+ if (!InsetParamsWidget::checkWidgets())
+ return false;
+ return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"
|| !valueLE->text().isEmpty();
}
-
-Dialog * createGuiMathHSpace(GuiView & lv) { return new GuiHSpace(lv, true); }
-
-
-Dialog * createGuiTextHSpace(GuiView & lv) { return new GuiHSpace(lv, false); }
-
-
} // namespace frontend
} // namespace lyx