make formatted spinbox work when suffix or prefix are set
svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1129714
This commit is contained in:
parent
94f45fca5c
commit
91b6ce0a47
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -156,6 +156,8 @@ void SizeDialogBase::onSpinFreeBeforeChanged(double newBefore)
|
|||
success = dialogWidget().partResizerWidget().updateFirstSector(alignedFirstSector);
|
||||
}
|
||||
|
||||
kDebug() << success;
|
||||
|
||||
if (success)
|
||||
setDirty();
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue