On Thursday 04 December 2003 11:30 pm, John Levon wrote:
> On Thu, Dec 04, 2003 at 07:44:56PM +0000, Angus Leeming wrote:
> > Patch and screen shot attached.
>
> A bit hard to see !

I didn't want to swamp the list with a huge screendump.

> What's the red in the dialog ? Baaddd...

;-) It's a bit of fun. The primary purpose of CheckedLineEdit is to ensure 
that the 'Apply' and 'Ok' buttons are disabled if you've input some nonsense 
in one of the QLineEdits. They will remain disabled even if you go elsewhere 
and play with another part of the dialog.

That said, I think it makes sense to provide the user with a visual clue that 
of where's he's going wrong.

So, 'hard coding 'Red' is 'Baaddd...', but the rest isn't.

namespace {

void setWidget(bool valid, QLineEdit * input, QLabel * label)
{
        QColor const red(255, 0, 0);

        if (valid)
                input->unsetPalette();
        else
                input->setPaletteForegroundColor(red);
        
        if (!label)
                return;

        if (valid)
                label->unsetPalette();
        else
                label->setPaletteForegroundColor(red);
}

} // namespace anon


CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QLabel * label)
        : input_(input), label_(label)
{}


bool CheckedLineEdit::check() const
{
        QString t = input_->text();
        int p = 0;
        QValidator const * validator = input_->validator();
        if (!validator)
                return true;

        bool const valid = validator->validate(t, p) == QValidator::Acceptable;

        // Visual feedback.
        setWidget(valid, input_, label_);

        return valid;
}

Reply via email to