make formatted spinbox work when suffix or prefix are set

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1129714
This commit is contained in:
Volker Lanz 2010-05-23 14:05:57 +00:00
parent 94f45fca5c
commit 91b6ce0a47
3 changed files with 37 additions and 1 deletions

View File

@ -21,6 +21,37 @@
#include <kglobal.h>
#include <klocale.h>
#include <kdebug.h>
// private method from Qt sources, qabstractspinbox.h:
QString FormattedSpinBox::stripped(const QString &t, int *pos) const
{
QString text = t;
if (specialValueText().size() == 0 || text != specialValueText()) {
int from = 0;
int size = text.size();
bool changed = false;
if (prefix().size() && text.startsWith(prefix())) {
from += prefix().size();
size -= from;
changed = true;
}
if (suffix().size() && text.endsWith(suffix())) {
size -= suffix().size();
changed = true;
}
if (changed)
text = text.mid(from, size);
}
const int s = text.size();
text = text.trimmed();
if (pos)
(*pos) -= (s - text.size());
return text;
}
QString FormattedSpinBox::textFromValue(double value) const
{
@ -29,5 +60,5 @@ QString FormattedSpinBox::textFromValue(double value) const
double FormattedSpinBox::valueFromText(const QString& text) const
{
return KGlobal::locale()->readNumber(text);
return KGlobal::locale()->readNumber(stripped(text));
}

View File

@ -31,6 +31,9 @@ class FormattedSpinBox : public QDoubleSpinBox
public:
virtual QString textFromValue(double value) const;
virtual double valueFromText(const QString& text) const;
private:
QString stripped(const QString &t, int *pos = 0) const;
};
#endif

View File

@ -156,6 +156,8 @@ void SizeDialogBase::onSpinFreeBeforeChanged(double newBefore)
success = dialogWidget().partResizerWidget().updateFirstSector(alignedFirstSector);
}
kDebug() << success;
if (success)
setDirty();
else