mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-23 00:38:01 +00:00
* qt_helpers.{cpp,h}:
- get rid of function lengthAutoToWidgets, which was only used by GuiGraphics - new variant of lengthToWidgets that takes a docstring * Validator.{cpp,h}: - the auto text in the Auto validators are customizable * GuiGraphics.cpp: - make the "auto" string translatable git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28165 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
5707a39041
commit
94442d8b30
@ -74,6 +74,8 @@ char const * const rorigin_gui_strs[] = {
|
|||||||
|
|
||||||
size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
|
size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
|
||||||
|
|
||||||
|
static string autostr = N_("automatically");
|
||||||
|
|
||||||
} // namespace anon
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
@ -99,8 +101,8 @@ static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
|
|||||||
{
|
{
|
||||||
if (!checkBox->isChecked())
|
if (!checkBox->isChecked())
|
||||||
lengthToWidgets(lineEdit, lengthCombo,
|
lengthToWidgets(lineEdit, lengthCombo,
|
||||||
"auto", lengthCombo->currentLengthItem());
|
_(autostr), lengthCombo->currentLengthItem());
|
||||||
else if (lineEdit->text() == "auto")
|
else if (lineEdit->text() == qt_(autostr))
|
||||||
lengthToWidgets(lineEdit, lengthCombo, string(),
|
lengthToWidgets(lineEdit, lengthCombo, string(),
|
||||||
lengthCombo->currentLengthItem());
|
lengthCombo->currentLengthItem());
|
||||||
}
|
}
|
||||||
@ -191,12 +193,13 @@ GuiGraphics::GuiGraphics(GuiView & lv)
|
|||||||
filename->setValidator(new PathValidator(true, filename));
|
filename->setValidator(new PathValidator(true, filename));
|
||||||
setFocusProxy(filename);
|
setFocusProxy(filename);
|
||||||
|
|
||||||
QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
|
QDoubleValidator * scaleValidator =
|
||||||
|
new DoubleAutoValidator(Scale, qt_(autostr));
|
||||||
scaleValidator->setBottom(0);
|
scaleValidator->setBottom(0);
|
||||||
scaleValidator->setDecimals(256); //I guess that will do
|
scaleValidator->setDecimals(256); //I guess that will do
|
||||||
Scale->setValidator(scaleValidator);
|
Scale->setValidator(scaleValidator);
|
||||||
Height->setValidator(unsignedLengthAutoValidator(Height));
|
Height->setValidator(unsignedLengthAutoValidator(Height, qt_(autostr)));
|
||||||
Width->setValidator(unsignedLengthAutoValidator(Width));
|
Width->setValidator(unsignedLengthAutoValidator(Width, qt_(autostr)));
|
||||||
angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
|
angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
|
||||||
|
|
||||||
//clipping pane
|
//clipping pane
|
||||||
@ -338,7 +341,7 @@ void GuiGraphics::setAutoText()
|
|||||||
if (scaleCB->isChecked())
|
if (scaleCB->isChecked())
|
||||||
return;
|
return;
|
||||||
if (!Scale->isEnabled() && Scale->text() != "100")
|
if (!Scale->isEnabled() && Scale->text() != "100")
|
||||||
Scale->setText(QString("auto"));
|
Scale->setText(qt_(autostr));
|
||||||
|
|
||||||
setAutoTextCB(WidthCB, Width, widthUnit);
|
setAutoTextCB(WidthCB, Width, widthUnit);
|
||||||
setAutoTextCB(HeightCB, Height, heightUnit);
|
setAutoTextCB(HeightCB, Height, heightUnit);
|
||||||
@ -565,20 +568,26 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
|
|||||||
groupId->setCurrentIndex(groupId->findText(toqstr(igp.groupId), Qt::MatchExactly));
|
groupId->setCurrentIndex(groupId->findText(toqstr(igp.groupId), Qt::MatchExactly));
|
||||||
groupId->blockSignals(false);
|
groupId->blockSignals(false);
|
||||||
|
|
||||||
lengthAutoToWidgets(Width, widthUnit, igp.width,
|
if (igp.width.value() == 0)
|
||||||
unitDefault);
|
lengthToWidgets(Width, widthUnit, _(autostr), unitDefault);
|
||||||
|
else
|
||||||
|
lengthToWidgets(Width, widthUnit, igp.width, unitDefault);
|
||||||
|
|
||||||
bool const widthChecked = !Width->text().isEmpty() &&
|
bool const widthChecked = !Width->text().isEmpty() &&
|
||||||
Width->text() != "auto";
|
Width->text() != qt_(autostr);
|
||||||
WidthCB->blockSignals(true);
|
WidthCB->blockSignals(true);
|
||||||
WidthCB->setChecked(widthChecked);
|
WidthCB->setChecked(widthChecked);
|
||||||
WidthCB->blockSignals(false);
|
WidthCB->blockSignals(false);
|
||||||
Width->setEnabled(widthChecked);
|
Width->setEnabled(widthChecked);
|
||||||
widthUnit->setEnabled(widthChecked);
|
widthUnit->setEnabled(widthChecked);
|
||||||
|
|
||||||
lengthAutoToWidgets(Height, heightUnit, igp.height,
|
if (igp.height.value() == 0)
|
||||||
unitDefault);
|
lengthToWidgets(Height, heightUnit, _(autostr), unitDefault);
|
||||||
|
else
|
||||||
|
lengthToWidgets(Height, heightUnit, igp.height, unitDefault);
|
||||||
|
|
||||||
bool const heightChecked = !Height->text().isEmpty()
|
bool const heightChecked = !Height->text().isEmpty()
|
||||||
&& Height->text() != "auto";
|
&& Height->text() != qt_(autostr);
|
||||||
HeightCB->blockSignals(true);
|
HeightCB->blockSignals(true);
|
||||||
HeightCB->setChecked(heightChecked);
|
HeightCB->setChecked(heightChecked);
|
||||||
HeightCB->blockSignals(false);
|
HeightCB->blockSignals(false);
|
||||||
|
@ -85,29 +85,31 @@ LengthValidator * unsignedLengthValidator(QLineEdit * ed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LengthAutoValidator::LengthAutoValidator(QWidget * parent)
|
LengthAutoValidator::LengthAutoValidator(QWidget * parent, QString const autotext)
|
||||||
: LengthValidator(parent)
|
: LengthValidator(parent),
|
||||||
|
autotext_(autotext)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
QValidator::State LengthAutoValidator::validate(QString & qtext, int & dummy) const
|
QValidator::State LengthAutoValidator::validate(QString & qtext, int & dummy) const
|
||||||
{
|
{
|
||||||
if (qtext == "auto")
|
if (qtext == autotext_)
|
||||||
return QValidator::Acceptable;
|
return QValidator::Acceptable;
|
||||||
return LengthValidator::validate(qtext, dummy);
|
return LengthValidator::validate(qtext, dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed)
|
LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed, QString const autotext)
|
||||||
{
|
{
|
||||||
LengthAutoValidator * v = new LengthAutoValidator(ed);
|
LengthAutoValidator * v = new LengthAutoValidator(ed, autotext);
|
||||||
v->setBottom(Length());
|
v->setBottom(Length());
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DoubleAutoValidator::DoubleAutoValidator(QWidget * parent)
|
DoubleAutoValidator::DoubleAutoValidator(QWidget * parent, QString const autotext)
|
||||||
: QDoubleValidator(parent)
|
: QDoubleValidator(parent),
|
||||||
|
autotext_(autotext)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -118,7 +120,7 @@ DoubleAutoValidator::DoubleAutoValidator(double bottom,
|
|||||||
|
|
||||||
|
|
||||||
QValidator::State DoubleAutoValidator::validate(QString & input, int & pos) const {
|
QValidator::State DoubleAutoValidator::validate(QString & input, int & pos) const {
|
||||||
if (input == "auto")
|
if (input == autotext_)
|
||||||
return QValidator::Acceptable;
|
return QValidator::Acceptable;
|
||||||
return QDoubleValidator::validate(input, pos);
|
return QDoubleValidator::validate(input, pos);
|
||||||
}
|
}
|
||||||
|
@ -75,44 +75,45 @@ private:
|
|||||||
/// @returns a new @c LengthValidator that does not accept negative lengths.
|
/// @returns a new @c LengthValidator that does not accept negative lengths.
|
||||||
LengthValidator * unsignedLengthValidator(QLineEdit *);
|
LengthValidator * unsignedLengthValidator(QLineEdit *);
|
||||||
|
|
||||||
//FIXME This should be generalized to take "text" as part of the
|
|
||||||
//constructor and so to set what text we check for, rather than
|
|
||||||
//hard-coding it as "auto". But see qt_helpers.h for reasons this
|
|
||||||
//is not so trivial and an idea about how to do it. (RGH)
|
|
||||||
/** A class to ascertain whether the data passed to the @c validate()
|
/** A class to ascertain whether the data passed to the @c validate()
|
||||||
* member function can be interpretted as a GlueLength or is "auto".
|
* member function can be interpretted as a GlueLength or is @param autotext.
|
||||||
*/
|
*/
|
||||||
class LengthAutoValidator : public LengthValidator
|
class LengthAutoValidator : public LengthValidator
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
/// Define a validator for widget @c parent.
|
/// Define a validator for widget @c parent.
|
||||||
LengthAutoValidator(QWidget * parent);
|
LengthAutoValidator(QWidget * parent, QString const autotext);
|
||||||
|
|
||||||
/** @returns QValidator::Acceptable if @c data is a GlueLength
|
/** @returns QValidator::Acceptable if @c data is a GlueLength
|
||||||
* or is "auto". If not, returns QValidator::Intermediate.
|
* or is "auto". If not, returns QValidator::Intermediate.
|
||||||
*/
|
*/
|
||||||
QValidator::State validate(QString & data, int &) const;
|
QValidator::State validate(QString & data, int &) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString autotext_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @returns a new @c LengthAutoValidator that does not accept negative lengths.
|
/// @returns a new @c LengthAutoValidator that does not accept negative lengths.
|
||||||
LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *);
|
LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *, QString const autotext);
|
||||||
|
|
||||||
|
|
||||||
//FIXME As above, this should really take a text argument.
|
|
||||||
/**
|
/**
|
||||||
* A class to determine whether the passed is a double
|
* A class to determine whether the passed is a double
|
||||||
* or is "auto".
|
* or is @param autotext.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DoubleAutoValidator : public QDoubleValidator
|
class DoubleAutoValidator : public QDoubleValidator
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DoubleAutoValidator(QWidget * parent);
|
DoubleAutoValidator(QWidget * parent, QString const autotext);
|
||||||
DoubleAutoValidator(double bottom, double top, int decimals,
|
DoubleAutoValidator(double bottom, double top, int decimals,
|
||||||
QObject * parent);
|
QObject * parent);
|
||||||
QValidator::State validate(QString & input, int & pos) const;
|
QValidator::State validate(QString & input, int & pos) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString autotext_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,13 +130,10 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
|
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||||
Length const & len, Length::UNIT defaultUnit)
|
docstring const & len, Length::UNIT defaultUnit)
|
||||||
{
|
{
|
||||||
if (len.value() == 0)
|
lengthToWidgets(input, combo, to_utf8(len), defaultUnit);
|
||||||
lengthToWidgets(input, combo, "auto", defaultUnit);
|
|
||||||
else
|
|
||||||
lengthToWidgets(input, combo, len, defaultUnit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,9 +48,9 @@ Length const & len, Length::UNIT default_unit);
|
|||||||
/// method to set widgets from a string
|
/// method to set widgets from a string
|
||||||
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||||
std::string const & len, Length::UNIT default_unit);
|
std::string const & len, Length::UNIT default_unit);
|
||||||
/// method to set widgets from a Length with optional "auto" if zero
|
/// method to set widgets from a docstring
|
||||||
void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
|
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||||
Length const & len, Length::UNIT defaultUnit);
|
docstring const & len, Length::UNIT default_unit);
|
||||||
|
|
||||||
/// colors a widget red if invalid
|
/// colors a widget red if invalid
|
||||||
void setValid(QWidget * widget, bool valid);
|
void setValid(QWidget * widget, bool valid);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user