KIntNumInput::setTemplate(const QString &template)

Tom Albers tomalbers at kde.nl
Sun Sep 3 00:54:18 BST 2006


Op vrijdag 1 september 2006 10:26, schreef David Faure:
> On Sunday 27 August 2006 17:41, Sébastien Laoût wrote:
> > Currently, the class KIntNumInput has two methods:
> > - setPrefix(const QString &prefix)
> > - setSuffix(const QString &suffix)
> >
> > This generate two problems:
> > 1/ No plural for is allowed.
> >    Or to be more precise, all numbers are always presented in the plural
> > form. 2/ Currency translation is bad.
> >    In USA, the program should call setPreffix("$ ").
> >    In Europe, the program should call setSuffix(" €")
> >    (not sure if € should be postfixed or prefixed, but it's for the
> > example: other currencies are placed after the number).
> >
> > For KDE 4, I propose you remove those methods in profit of that one:
> > - KIntNumInput::setTemplate(const QString &template)
> >
> > The two examples will be transformed to:
> > - setTemplate(i18n("%n minute", "%n minutes));
>
> Doesn't work that way. The syntax is i18n("1 minute", "%n minutes",
> number_of_minutes). But in kde4 one can also use ki18np("1 minute", "%n
> minutes").subs(number_of_minutes).toString() so I think this could become
>
>   setTemplate( ki18np("1 minute", "%n minutes") )
>
> and KIntNumInput would take care of calling subs(number_of_minutes) when
> the number of minutes changes. And the api would be
>   setTemplate( const KLocalizedString& )
>
> But I'm not sure how the editing would work, when the number is somewhere
> in the middle of a string...

There is another difficulty. subs will return the complete string including 
the value itself, so calling setSuffix with the result of subs, will result 
in "1212 minutes" in case of value 12. There seems to be no way to set the 
complete text of the QSpinBox. 

I think QSpinBox needs to be subclassed for it, but then then the 
valueFromText will be pretty complicated: How to extract the number back from 
the complete text? Walk from min to max and compare strings seems not very 
efficient (even when I completly ignore the doubleInt variant). Any ideas?

Toma




More information about the kde-core-devel mailing list