2003-12-05 02:49:22 +00:00
|
|
|
/**
|
|
|
|
* \file qt2/checkedwidgets.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "checkedwidgets.h"
|
|
|
|
|
|
|
|
#include <qlabel.h>
|
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qvalidator.h>
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
2003-12-05 02:49:22 +00:00
|
|
|
|
|
|
|
void addCheckedLineEdit(BCView & bcview,
|
|
|
|
QLineEdit * input, QLabel * label)
|
|
|
|
{
|
|
|
|
bcview.addCheckedWidget(new CheckedLineEdit(input, label));
|
|
|
|
}
|
2004-04-03 08:37:12 +00:00
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2003-12-09 10:33:55 +00:00
|
|
|
void setWarningColor(QWidget * widget)
|
2003-12-05 02:49:22 +00:00
|
|
|
{
|
2003-12-09 10:33:55 +00:00
|
|
|
// Qt 2.3 does not have
|
|
|
|
// widget->setPaletteForegroundColor(QColor(255, 0, 0));
|
|
|
|
// So copy the appropriate parts of the function here:
|
|
|
|
QPalette pal = widget->palette();
|
|
|
|
pal.setColor(QPalette::Active,
|
|
|
|
QColorGroup::Foreground,
|
|
|
|
QColor(255, 0, 0));
|
|
|
|
widget->setPalette(pal);
|
|
|
|
}
|
2003-12-05 02:49:22 +00:00
|
|
|
|
2004-04-03 08:37:12 +00:00
|
|
|
|
2003-12-09 10:33:55 +00:00
|
|
|
void setWidget(bool valid, QLineEdit * input, QLabel * label)
|
|
|
|
{
|
2003-12-05 02:49:22 +00:00
|
|
|
if (valid)
|
|
|
|
input->unsetPalette();
|
|
|
|
else
|
2003-12-09 10:33:55 +00:00
|
|
|
setWarningColor(input);
|
2004-04-03 08:37:12 +00:00
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
if (!label)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (valid)
|
|
|
|
label->unsetPalette();
|
|
|
|
else
|
2003-12-09 10:33:55 +00:00
|
|
|
setWarningColor(label);
|
2003-12-05 02:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QLabel * label)
|
|
|
|
: input_(input), label_(label)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
bool CheckedLineEdit::check() const
|
|
|
|
{
|
|
|
|
QValidator const * validator = input_->validator();
|
|
|
|
if (!validator)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
QString t = input_->text();
|
|
|
|
int p = 0;
|
|
|
|
bool const valid = validator->validate(t, p) == QValidator::Acceptable;
|
|
|
|
|
|
|
|
// Visual feedback.
|
|
|
|
setWidget(valid, input_, label_);
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|