mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 02:14:50 +00:00
Add support for number localization in the GUI (using Qt's locale facilities).
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30511 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
14be173d42
commit
52d9b45b0c
@ -1877,7 +1877,7 @@ void GuiDocument::applyView()
|
||||
break;
|
||||
case 3:
|
||||
bp_.spacing().set(Spacing::Other,
|
||||
fromqstr(textLayoutModule->lspacingLE->text()));
|
||||
widgetToDoubleStr(textLayoutModule->lspacingLE));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2201,8 +2201,8 @@ void GuiDocument::paramsToDialog()
|
||||
|
||||
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);
|
||||
|
||||
|
@ -213,23 +213,25 @@ bool GuiExternal::activateAspectratio() const
|
||||
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;
|
||||
@ -353,7 +355,7 @@ static void setRotation(QLineEdit & angleED, QComboBox & originCO,
|
||||
external::RotationData const & data)
|
||||
{
|
||||
originCO.setCurrentIndex(int(data.origin()));
|
||||
angleED.setText(toqstr(data.angle));
|
||||
doubleToWidget(&angleED, data.angle);
|
||||
}
|
||||
|
||||
|
||||
@ -363,7 +365,7 @@ static void getRotation(external::RotationData & data,
|
||||
typedef external::RotationData::OriginType OriginType;
|
||||
|
||||
data.origin(static_cast<OriginType>(originCO.currentIndex()));
|
||||
data.angle = fromqstr(angleED.text());
|
||||
data.angle = widgetToDoubleStr(&angleED);
|
||||
}
|
||||
|
||||
|
||||
@ -381,7 +383,7 @@ static void setSize(QLineEdit & widthED, LengthCombo & widthUnitCO,
|
||||
}
|
||||
|
||||
if (using_scale) {
|
||||
widthED.setText(toqstr(scale));
|
||||
doubleToWidget(&widthED, scale);
|
||||
widthUnitCO.setCurrentItem("scale");
|
||||
} else
|
||||
lengthToWidgets(&widthED, &widthUnitCO,
|
||||
@ -408,11 +410,9 @@ static void getSize(external::ResizeData & data,
|
||||
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));
|
||||
|
@ -109,49 +109,6 @@ static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
|
||||
}
|
||||
|
||||
|
||||
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"))
|
||||
{
|
||||
@ -524,21 +481,25 @@ static int itemNumber(const vector<string> & v, string const & s)
|
||||
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();
|
||||
|
||||
@ -551,10 +512,10 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
|
||||
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);
|
||||
@ -568,30 +529,30 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
|
||||
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));
|
||||
}
|
||||
@ -607,7 +568,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
|
||||
|
||||
// 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);
|
||||
@ -665,7 +626,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
|
||||
|
||||
setAutoText();
|
||||
|
||||
angle->setText(toqstr(igp.rotateAngle));
|
||||
doubleToWidget(angle, igp.rotateAngle);
|
||||
rotateOrderCB->setChecked(igp.scaleBeforeRotation);
|
||||
|
||||
rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
|
||||
@ -673,16 +634,13 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
|
||||
|
||||
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);
|
||||
|
||||
@ -701,10 +659,10 @@ void GuiGraphics::applyView()
|
||||
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);
|
||||
@ -735,7 +693,7 @@ void GuiGraphics::applyView()
|
||||
|
||||
//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;
|
||||
@ -756,9 +714,9 @@ void GuiGraphics::applyView()
|
||||
|
||||
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);
|
||||
@ -766,7 +724,8 @@ void GuiGraphics::applyView()
|
||||
|
||||
// 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
|
||||
@ -787,10 +746,10 @@ void GuiGraphics::getBB()
|
||||
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);
|
||||
|
@ -218,7 +218,7 @@ void GuiParagraph::applyView()
|
||||
break;
|
||||
case 4:
|
||||
ls = Spacing::Other;
|
||||
other = fromqstr(linespacingValue->text());
|
||||
other = widgetToDoubleStr(linespacingValue);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -281,7 +281,7 @@ void GuiParagraph::updateView()
|
||||
}
|
||||
linespacing->setCurrentIndex(ls);
|
||||
if (space.getSpace() == Spacing::Other) {
|
||||
linespacingValue->setText(toqstr(space.getValueAsString()));
|
||||
doubleToWidget(linespacingValue, space.getValue());
|
||||
linespacingValue->setEnabled(true);
|
||||
} else {
|
||||
linespacingValue->setText(QString());
|
||||
|
@ -868,16 +868,16 @@ void PrefScreenFonts::apply(LyXRC & rc) const
|
||||
|
||||
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
|
||||
@ -910,16 +910,16 @@ void PrefScreenFonts::update(LyXRC const & rc)
|
||||
|
||||
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)
|
||||
@ -1325,7 +1325,7 @@ PrefConverters::PrefConverters(GuiPreferences * form)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -1333,8 +1333,7 @@ void PrefConverters::update(LyXRC const & rc)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QLocale>
|
||||
#include <QWidget>
|
||||
|
||||
using namespace std;
|
||||
@ -39,10 +40,13 @@ LengthValidator::LengthValidator(QWidget * parent)
|
||||
|
||||
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)) ?
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "Length.h"
|
||||
#include "TextClass.h"
|
||||
|
||||
#include "support/convert.h"
|
||||
#include "support/debug.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/foreach.h"
|
||||
@ -39,6 +40,7 @@
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QLineEdit>
|
||||
#include <QLocale>
|
||||
#include <QPalette>
|
||||
#include <QSet>
|
||||
|
||||
@ -78,7 +80,7 @@ string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
|
||||
|
||||
Length::UNIT const unit = combo->currentLengthItem();
|
||||
|
||||
return Length(length.toDouble(), unit).asString();
|
||||
return Length(length.trimmed().toDouble(), unit).asString();
|
||||
}
|
||||
|
||||
|
||||
@ -101,7 +103,7 @@ Length widgetsToLength(QLineEdit const * input, QComboBox const * combo)
|
||||
}
|
||||
}
|
||||
|
||||
return Length(length.toDouble(), unit);
|
||||
return Length(length.trimmed().toDouble(), unit);
|
||||
}
|
||||
|
||||
|
||||
@ -109,7 +111,8 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
@ -137,6 +140,39 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
|
@ -52,6 +52,17 @@ std::string const & len, Length::UNIT default_unit);
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user