break;
case 3:
bp_.spacing().set(Spacing::Other,
- fromqstr(textLayoutModule->lspacingLE->text()));
+ widgetToDoubleStr(textLayoutModule->lspacingLE));
break;
}
textLayoutModule->lspacingCO->setCurrentIndex(nitem);
if (bp_.spacing().getSpace() == Spacing::Other) {
- textLayoutModule->lspacingLE->setText(
- toqstr(bp_.spacing().getValueAsString()));
+ doubleToWidget(textLayoutModule->lspacingLE,
+ bp_.spacing().getValueAsString());
}
setLSpacing(nitem);
if (usingScale())
return false;
- string const wstr = fromqstr(widthED->text());
- if (wstr.empty())
+ QString const wstr = widthED->text();
+ if (wstr.isEmpty())
return false;
- bool const wIsDbl = isStrDbl(wstr);
- if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
+ bool wIsDbl;
+ double val = wstr.trimmed().toDouble(&wIsDbl);
+ if (wIsDbl && float_equal(val, 0.0, 0.05))
return false;
Length l;
- if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
+ if (!wIsDbl && (!isValidLength(fromqstr(wstr), &l) || l.zero()))
return false;
- string const hstr = fromqstr(heightED->text());
- if (hstr.empty())
+ QString const hstr = heightED->text();
+ if (hstr.isEmpty())
return false;
- bool const hIsDbl = isStrDbl(hstr);
- if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
+ bool hIsDbl;
+ val = hstr.trimmed().toDouble(&hIsDbl);
+ if (hIsDbl && float_equal(val, 0.0, 0.05))
return false;
- if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
+ if (!hIsDbl && (!isValidLength(fromqstr(hstr), &l) || l.zero()))
return false;
return true;
external::RotationData const & data)
{
originCO.setCurrentIndex(int(data.origin()));
- angleED.setText(toqstr(data.angle));
+ doubleToWidget(&angleED, data.angle);
}
typedef external::RotationData::OriginType OriginType;
data.origin(static_cast<OriginType>(originCO.currentIndex()));
- data.angle = fromqstr(angleED.text());
+ data.angle = widgetToDoubleStr(&angleED);
}
}
if (using_scale) {
- widthED.setText(toqstr(scale));
+ doubleToWidget(&widthED, scale);
widthUnitCO.setCurrentItem("scale");
} else
lengthToWidgets(&widthED, &widthUnitCO,
QLineEdit const & heightED, LengthCombo const & heightUnitCO,
QCheckBox const & aspectratioCB, bool const scaling)
{
- string const width = fromqstr(widthED.text());
-
if (scaling) {
// scaling instead of a width
- data.scale = width;
+ data.scale = widgetToDoubleStr(&widthED);
data.width = Length();
} else {
data.width = Length(widgetsToLength(&widthED, &widthUnitCO));
}
-template<class Pair>
-vector<typename Pair::first_type> getFirst(vector<Pair> const & pr)
-{
- size_t const n = pr.size();
- vector<typename Pair::first_type> tmp(n);
- for (size_t i = 0; i != n; ++i)
- tmp[i] = pr[i].first;
- return tmp;
-}
-
-
-///
-template<class Pair>
-vector<typename Pair::second_type> getSecond(vector<Pair> const & pr)
-{
- size_t const n = pr.size();
- vector<typename Pair::second_type> tmp(n);
- for (size_t i = 0; i != n; ++i)
- tmp[i] = pr[i].second;
- return tmp;
-}
-
-
-/// The (tranlated) GUI string and it's LaTeX equivalent.
-typedef pair<docstring, string> RotationOriginPair;
-///
-vector<RotationOriginPair> getRotationOriginData()
-{
- static vector<RotationOriginPair> data;
- if (!data.empty())
- return data;
-
- data.resize(rorigin_size);
- for (size_type i = 0; i < rorigin_size; ++i) {
- data[i] = make_pair(_(rorigin_gui_strs[i]),
- rorigin_lyx_strs[i]);
- }
-
- return data;
-}
-
-
-
GuiGraphics::GuiGraphics(GuiView & lv)
: GuiDialog(lv, "graphics", qt_("Graphics"))
{
void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
{
static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
+ static char const * const bb_units_gui[] = { N_("bp"), N_("cm"), N_("mm"), N_("in") };
size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
- vector<string> const units = vector<string>(bb_units, bb_units + bb_size);
lbXunit->clear();
lbYunit->clear();
rtXunit->clear();
rtYunit->clear();
- for (vector<string>::const_iterator it = units.begin();
- it != units.end(); ++it) {
- lbXunit->addItem(toqstr(*it));
- lbYunit->addItem(toqstr(*it));
- rtXunit->addItem(toqstr(*it));
- rtYunit->addItem(toqstr(*it));
+
+ for (int i = 0; i < bb_size; i++) {
+ lbXunit->addItem(qt_(bb_units_gui[i]),
+ toqstr(bb_units[i]));
+ lbYunit->addItem(qt_(bb_units_gui[i]),
+ toqstr(bb_units[i]));
+ rtXunit->addItem(qt_(bb_units_gui[i]),
+ toqstr(bb_units[i]));
+ rtYunit->addItem(qt_(bb_units_gui[i]),
+ toqstr(bb_units[i]));
}
-
+
// set the right default unit
Length::UNIT const defaultUnit = Length::defaultUnit();
if (igp.bb.empty()) {
string const bb = readBoundingBox(igp.filename.absFilename());
// the values from the file always have the bigpoint-unit bp
- lbX->setText(toqstr(token(bb, ' ', 0)));
- lbY->setText(toqstr(token(bb, ' ', 1)));
- rtX->setText(toqstr(token(bb, ' ', 2)));
- rtY->setText(toqstr(token(bb, ' ', 3)));
+ doubleToWidget(lbX, token(bb, ' ', 0));
+ doubleToWidget(lbY, token(bb, ' ', 1));
+ doubleToWidget(rtX, token(bb, ' ', 2));
+ doubleToWidget(rtY, token(bb, ' ', 3));
lbXunit->setCurrentIndex(0);
lbYunit->setCurrentIndex(0);
rtXunit->setCurrentIndex(0);
string const xr = token(igp.bb, ' ', 2);
string const yr = token(igp.bb, ' ', 3);
if (isValidLength(xl, &anyLength)) {
- lbX->setText(toqstr(convert<string>(anyLength.value())));
+ doubleToWidget(lbX, anyLength.value());
string const unit = unit_name[anyLength.unit()];
- lbXunit->setCurrentIndex(itemNumber(units, unit));
+ lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit)));
} else {
lbX->setText(toqstr(xl));
}
if (isValidLength(yl, &anyLength)) {
- lbY->setText(toqstr(convert<string>(anyLength.value())));
+ doubleToWidget(lbY, anyLength.value());
string const unit = unit_name[anyLength.unit()];
- lbYunit->setCurrentIndex(itemNumber(units, unit));
+ lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit)));
} else {
lbY->setText(toqstr(xl));
}
if (isValidLength(xr, &anyLength)) {
- rtX->setText(toqstr(convert<string>(anyLength.value())));
+ doubleToWidget(rtX, anyLength.value());
string const unit = unit_name[anyLength.unit()];
- rtXunit->setCurrentIndex(itemNumber(units, unit));
+ rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit)));
} else {
rtX->setText(toqstr(xl));
}
if (isValidLength(yr, &anyLength)) {
- rtY->setText(toqstr(convert<string>(anyLength.value())));
+ doubleToWidget(rtY, anyLength.value());
string const unit = unit_name[anyLength.unit()];
- rtYunit->setCurrentIndex(itemNumber(units, unit));
+ rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit)));
} else {
rtY->setText(toqstr(xl));
}
// the output section (width/height)
- Scale->setText(toqstr(igp.scale));
+ doubleToWidget(Scale, igp.scale);
//igp.scale defaults to 100, so we treat it as empty
bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
scaleCB->blockSignals(true);
setAutoText();
- angle->setText(toqstr(igp.rotateAngle));
+ doubleToWidget(angle, igp.rotateAngle);
rotateOrderCB->setChecked(igp.scaleBeforeRotation);
rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
origin->clear();
- vector<RotationOriginPair> origindata = getRotationOriginData();
- vector<docstring> const origin_lang = getFirst(origindata);
- origin_ltx = getSecond(origindata);
-
- for (vector<docstring>::const_iterator it = origin_lang.begin();
- it != origin_lang.end(); ++it)
- origin->addItem(toqstr(*it));
+ for (int i = 0; i < rorigin_size; i++) {
+ origin->addItem(qt_(rorigin_gui_strs[i]),
+ toqstr(rorigin_lyx_strs[i]));
+ }
if (!igp.rotateOrigin.empty())
- origin->setCurrentIndex(itemNumber(origin_ltx, igp.rotateOrigin));
+ origin->setCurrentIndex(origin->findData(toqstr(igp.rotateOrigin)));
else
origin->setCurrentIndex(0);
igp.bb.erase();
if (bbChanged) {
string bb;
- string lbXs = fromqstr(lbX->text());
- string lbYs = fromqstr(lbY->text());
- string rtXs = fromqstr(rtX->text());
- string rtYs = fromqstr(rtY->text());
+ string lbXs = widgetToDoubleStr(lbX);
+ string lbYs = widgetToDoubleStr(lbY);
+ string rtXs = widgetToDoubleStr(rtX);
+ string rtYs = widgetToDoubleStr(rtY);
int bb_sum =
convert<int>(lbXs) + convert<int>(lbYs) +
convert<int>(rtXs) + convert<int>(rtXs);
//the graphics section
if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
- igp.scale = fromqstr(Scale->text());
+ igp.scale = widgetToDoubleStr(Scale);
igp.width = Length("0pt");
igp.height = Length("0pt");
igp.keepAspectRatio = false;
igp.noUnzip = unzipCB->isChecked();
igp.lyxscale = displayscale->text().toInt();
- igp.rotateAngle = fromqstr(angle->text());
+ igp.rotateAngle = widgetToDoubleStr(angle);
- double rotAngle = convert<double>(igp.rotateAngle);
+ double rotAngle = widgetToDouble(angle);
if (abs(rotAngle) > 360.0) {
rotAngle -= 360.0 * floor(rotAngle / 360.0);
igp.rotateAngle = convert<string>(rotAngle);
// save the latex name for the origin. If it is the default
// then origin_ltx returns ""
- igp.rotateOrigin = origin_ltx[origin->currentIndex()];
+ igp.rotateOrigin =
+ fromqstr(origin->itemData(origin->currentIndex()).toString());
igp.scaleBeforeRotation = rotateOrderCB->isChecked();
// more latex options
bbChanged = false;
if (bb.empty())
return;
- lbX->setText(toqstr(token(bb, ' ', 0)));
- lbY->setText(toqstr(token(bb, ' ', 1)));
- rtX->setText(toqstr(token(bb, ' ', 2)));
- rtY->setText(toqstr(token(bb, ' ', 3)));
+ doubleToWidget(lbX, token(bb, ' ', 0));
+ doubleToWidget(lbY, token(bb, ' ', 1));
+ doubleToWidget(rtX, token(bb, ' ', 2));
+ doubleToWidget(rtY, token(bb, ' ', 3));
// the default units for the bb values when reading
// it from the file
lbXunit->setCurrentIndex(0);
break;
case 4:
ls = Spacing::Other;
- other = fromqstr(linespacingValue->text());
+ other = widgetToDoubleStr(linespacingValue);
break;
}
}
linespacing->setCurrentIndex(ls);
if (space.getSpace() == Spacing::Other) {
- linespacingValue->setText(toqstr(space.getValueAsString()));
+ doubleToWidget(linespacingValue, space.getValue());
linespacingValue->setEnabled(true);
} else {
linespacingValue->setText(QString());
rc.zoom = screenZoomSB->value();
rc.dpi = screenDpiSB->value();
- rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
- rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
- rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
- rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
- rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
- rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
- rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
- rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
- rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
- rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
+ rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
+ rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
+ rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
+ rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
+ rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
+ rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
+ rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
+ rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
+ rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
+ rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
rc.use_pixmap_cache = pixmapCacheCB->isChecked();
if (rc.font_sizes != oldrc.font_sizes
screenZoomSB->setValue(rc.zoom);
screenDpiSB->setValue(rc.dpi);
- screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
- screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
- screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
- screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
- screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
- screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
- screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
- screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
- screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
- screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
+ doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
+ doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
+ doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
+ doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
+ doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
+ doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
+ doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
+ doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
+ doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
+ doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
pixmapCacheCB->setChecked(rc.use_pixmap_cache);
#if defined(Q_WS_X11)
void PrefConverters::apply(LyXRC & rc) const
{
rc.use_converter_cache = cacheCB->isChecked();
- rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
+ rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
}
{
cacheCB->setChecked(rc.use_converter_cache);
QString max_age;
- max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
- maxAgeLE->setText(max_age);
+ doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
updateGui();
}
#include "support/lstrings.h"
#include <QLineEdit>
+#include <QLocale>
#include <QWidget>
using namespace std;
QValidator::State LengthValidator::validate(QString & qtext, int &) const
{
- string const text = fromqstr(qtext);
- if (text.empty() || support::isStrDbl(text))
+ bool ok;
+ double d = qtext.trimmed().toDouble(&ok);
+ if (qtext.isEmpty() || ok)
return QValidator::Acceptable;
+ string const text = fromqstr(qtext);
+
if (glue_length_) {
GlueLength gl;
return (isValidGlueLength(text, &gl)) ?
#include "Length.h"
#include "TextClass.h"
+#include "support/convert.h"
#include "support/debug.h"
#include "support/filetools.h"
#include "support/foreach.h"
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
+#include <QLocale>
#include <QPalette>
#include <QSet>
Length::UNIT const unit = combo->currentLengthItem();
- return Length(length.toDouble(), unit).asString();
+ return Length(length.trimmed().toDouble(), unit).asString();
}
}
}
- return Length(length.toDouble(), unit);
+ return Length(length.trimmed().toDouble(), unit);
}
Length const & len, Length::UNIT /*defaultUnit*/)
{
combo->setCurrentItem(len.unit());
- input->setText(QString::number(Length(len).value()));
+ QLocale loc;
+ input->setText(loc.toString(Length(len).value()));
}
}
+double widgetToDouble(QLineEdit const * input)
+{
+ QString const text = input->text();
+ if (text.isEmpty())
+ return 0.0;
+
+ return text.trimmed().toDouble();
+}
+
+
+string widgetToDoubleStr(QLineEdit const * input)
+{
+ QString const text = input->text();
+ if (text.isEmpty())
+ return string();
+
+ return convert<string>(text.trimmed().toDouble());
+}
+
+
+void doubleToWidget(QLineEdit * input, double const & value, char f, int prec)
+{
+ QLocale loc;
+ input->setText(loc.toString(value, f, prec));
+}
+
+
+void doubleToWidget(QLineEdit * input, string const & value, char f, int prec)
+{
+ doubleToWidget(input, convert<double>(value), f, prec);
+}
+
+
void setValid(QWidget * widget, bool valid)
{
if (valid) {
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
docstring const & len, Length::UNIT default_unit);
+/// method to get a double value from a localized widget (QLineEdit)
+double widgetToDouble(QLineEdit const * input);
+/// method to get a double value from a localized widget (QLineEdit)
+std::string widgetToDoubleStr(QLineEdit const * input);
+/// method to set a (localized) double value in a widget (QLineEdit)
+void doubleToWidget(QLineEdit * input, double const & value,
+ char f = 'g', int prec = 6);
+/// method to set a (localized) double value in a widget (QLineEdit)
+void doubleToWidget(QLineEdit * input, std::string const & value,
+ char f = 'g', int prec = 6);
+
/// colors a widget red if invalid
void setValid(QWidget * widget, bool valid);