* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author Jürgen Spitzmüller
+ * \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include "qt_helpers.h"
#include "Validator.h"
-#include "LyXRC.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)
- : GuiDialog(lv, "space", qt_("Horizontal Space Settings"))
+GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
+ : InsetParamsWidget(parent), math_mode_(math_mode)
{
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"), toqstr("normal"));
+ spacingCO->addItem(qt_("Thin Space"), toqstr("thinspace"));
+ spacingCO->addItem(qt_("Medium Space"), toqstr("medspace"));
+ spacingCO->addItem(qt_("Thick Space"), toqstr("thickspace"));
+ spacingCO->addItem(qt_("Negative Thin Space"), toqstr("negthinspace"));
+ spacingCO->addItem(qt_("Negative Medium Space"), toqstr("negmedspace"));
+ spacingCO->addItem(qt_("Negative Thick Space"), toqstr("negthickspace"));
+ spacingCO->addItem(qt_("Half Quad (0.5 em)"), toqstr("halfquad"));
+ spacingCO->addItem(qt_("Quad (1 em)"), toqstr("quad"));
+ spacingCO->addItem(qt_("Double Quad (2 em)"), toqstr("qquad"));
+ spacingCO->addItem(qt_("Horizontal Fill"), toqstr("hfill"));
+ spacingCO->addItem(qt_("Custom"), toqstr("custom"));
+ } else {
+ spacingCO->addItem(qt_("Interword Space"), toqstr("normal"));
+ spacingCO->addItem(qt_("Thin Space"), toqstr("thinspace"));
+ spacingCO->addItem(qt_("Negative Thin Space"), toqstr("negthinspace"));
+ spacingCO->addItem(qt_("Negative Medium Space"), toqstr("negmedspace"));
+ spacingCO->addItem(qt_("Negative Thick Space"), toqstr("negthickspace"));
+ spacingCO->addItem(qt_("Half Quad (0.5 em)"), toqstr("halfquad"));
+ spacingCO->addItem(qt_("Quad (1 em)"), toqstr("quad"));
+ spacingCO->addItem(qt_("Double Quad (2 em)"), toqstr("qquad"));
+ spacingCO->addItem(qt_("Horizontal Fill"), toqstr("hfill"));
+ spacingCO->addItem(qt_("Custom"), toqstr("custom"));
+ spacingCO->addItem(qt_("Visible Space"), toqstr("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()));
-
- valueLE->setValidator(unsignedLengthValidator(valueLE));
-
- // Manage the ok, apply, restore and cancel/close buttons
- bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
- bc().setOK(okPB);
- bc().setApply(applyPB);
- bc().setCancel(closePB);
+ this, SLOT(changedSlot()));
- // disable for read-only documents
- bc().addReadOnly(spacingCO);
- bc().addReadOnly(valueLE);
- bc().addReadOnly(unitCO);
- bc().addReadOnly(keepCB);
- bc().addReadOnly(fillPatternCO);
+ if (math_mode_)
+ valueLE->setValidator(unsignedLengthValidator(valueLE));
+ else
+ valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
// initialize the length validator
- bc().addCheckedLineEdit(valueLE, valueL);
-
- // remove the %-items from the unit choice
- unitCO->noPercents();
+ addCheckedWidget(valueLE, valueL);
+ enableWidgets();
}
-void GuiHSpace::change_adaptor()
+void GuiHSpace::changedSlot()
{
+ enableWidgets();
changed();
}
-void GuiHSpace::enableWidgets(int selection)
+void GuiHSpace::enableWidgets()
{
- valueLE->setEnabled(selection == 7);
- unitCO->setEnabled(selection == 7);
- fillPatternCO->setEnabled(selection == 6);
- int pattern = fillPatternCO->currentIndex();
+ QString const selection = spacingCO->itemData(spacingCO->currentIndex()).toString();
+ bool const custom = selection == "custom";
+ valueLE->setEnabled(custom);
+ unitCO->setEnabled(custom);
+ fillPatternCO->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();
}
-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)
-{
- 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;
+ item = "normal";
+ protect = true;
+ break;
+ case InsetSpaceParams::VISIBLE:
+ item = "visible";
protect = true;
break;
case InsetSpaceParams::THIN:
- item = 1;
+ item = "thinspace";
+ break;
+ case InsetSpaceParams::MEDIUM:
+ item = "medspace";
+ break;
+ case InsetSpaceParams::THICK:
+ item = "thickspace";
break;
case InsetSpaceParams::NEGTHIN:
- item = 2;
+ item = "negthinspace";
+ break;
+ case InsetSpaceParams::NEGMEDIUM:
+ item = "negmedspace";
+ break;
+ case InsetSpaceParams::NEGTHICK:
+ item = "negthickspace";
break;
case InsetSpaceParams::ENSKIP:
- item = 3;
+ item = "halfquad";
break;
case InsetSpaceParams::ENSPACE:
- item = 3;
+ item = "halfquad";
protect = true;
break;
case InsetSpaceParams::QUAD:
- item = 4;
+ item = "quad";
break;
case InsetSpaceParams::QQUAD:
- item = 5;
+ item = "qquad";
break;
case InsetSpaceParams::HFILL:
- item = 6;
+ item = "hfill";
break;
case InsetSpaceParams::HFILL_PROTECTED:
- item = 6;
+ item = "hfill";
protect = true;
break;
case InsetSpaceParams::DOTFILL:
- item = 6;
+ item = "hfill";
pattern = 1;
break;
case InsetSpaceParams::HRULEFILL:
- item = 6;
+ item = "hfill";
pattern = 2;
break;
case InsetSpaceParams::LEFTARROWFILL:
- item = 6;
+ item = "hfill";
pattern = 3;
break;
case InsetSpaceParams::RIGHTARROWFILL:
- item = 6;
+ item = "hfill";
pattern = 4;
break;
case InsetSpaceParams::UPBRACEFILL:
- item = 6;
+ item = "hfill";
pattern = 5;
break;
case InsetSpaceParams::DOWNBRACEFILL:
- item = 6;
+ item = "hfill";
pattern = 6;
break;
case InsetSpaceParams::CUSTOM:
- item = 7;
+ item = "custom";
break;
case InsetSpaceParams::CUSTOM_PROTECTED:
- item = 7;
+ item = "custom";
protect = true;
break;
}
- spacing->setCurrentIndex(item);
- fillPattern->setCurrentIndex(pattern);
- keep->setChecked(protect);
-
- Length::UNIT default_unit =
- (lyxrc.default_papersize > 3) ? Length::CM : Length::IN;
- if (item == 7)
- lengthToWidgets(value, unit, params.length, default_unit);
- else
- lengthToWidgets(value, unit, "", default_unit);
+ 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 == "custom") {
+ string length = params.length.asString();
+ lengthToWidgets(valueLE, unitCO, length, default_unit);
+ } else
+ lengthToWidgets(valueLE, unitCO, "", default_unit);
+
+ enableWidgets();
}
-static InsetSpaceParams setHSpaceFromWidgets(int spacing,
- QLineEdit * value, LengthCombo * unit, bool keep, int fill)
+docstring GuiHSpace::dialogToParams() const
{
- InsetSpaceParams 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 = Length(widgetsToLength(value, unit));
- break;
- }
- return params;
-}
-
-
-void GuiHSpace::applyView()
-{
- params_ = setHSpaceFromWidgets(spacingCO->currentIndex(),
- valueLE, unitCO, keepCB->isChecked(),
- fillPatternCO->currentIndex());
-}
-
-
-void GuiHSpace::updateContents()
-{
- setWidgetsFromHSpace(params_, spacingCO, valueLE, unitCO, keepCB,
- fillPatternCO);
- enableWidgets(spacingCO->currentIndex());
+ }
+ } 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));
}
-bool GuiHSpace::initialiseParams(string const & data)
+bool GuiHSpace::checkWidgets() const
{
- InsetSpace::string2params(data, params_);
- setButtonsValid(true);
- return true;
+ if (!InsetParamsWidget::checkWidgets())
+ return false;
+ return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"
+ || !valueLE->text().isEmpty();
}
-
-void GuiHSpace::clearParams()
-{
- params_ = InsetSpaceParams();
-}
-
-
-void GuiHSpace::dispatchParams()
-{
- dispatch(FuncRequest(getLfun(), InsetSpace::params2string(params_)));
-}
-
-
-bool GuiHSpace::isValid()
-{
- return spacingCO->currentIndex() != 7 || !valueLE->text().isEmpty();
-}
-
-
-Dialog * createGuiHSpace(GuiView & lv) { return new GuiHSpace(lv); }
-
-
} // namespace frontend
} // namespace lyx