2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file Qt2BC.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Allan Rae
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "Qt2BC.h"
|
2007-09-01 20:44:14 +00:00
|
|
|
#include "BCView.h"
|
|
|
|
#include "ButtonPolicy.h"
|
|
|
|
#include "debug.h"
|
2007-09-01 21:05:31 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QLineEdit>
|
2007-09-02 08:19:43 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QValidator>
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-09-01 20:44:14 +00:00
|
|
|
|
2007-09-02 07:53:07 +00:00
|
|
|
Qt2BC::Qt2BC(ButtonController & parent)
|
2007-09-01 20:44:14 +00:00
|
|
|
: BCView(parent), okay_(0), apply_(0), cancel_(0), restore_(0)
|
2006-03-05 17:24:44 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-09-01 20:44:14 +00:00
|
|
|
void Qt2BC::refresh() const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-02 07:53:07 +00:00
|
|
|
LYXERR(Debug::GUI) << "Calling BC refresh()" << std::endl;
|
2007-09-01 20:44:14 +00:00
|
|
|
|
|
|
|
bool const all_valid = checkWidgets();
|
|
|
|
|
|
|
|
if (okay_) {
|
|
|
|
bool const enabled =
|
|
|
|
all_valid && bp().buttonStatus(ButtonPolicy::OKAY);
|
|
|
|
okay_->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
if (apply_) {
|
|
|
|
bool const enabled =
|
|
|
|
all_valid && bp().buttonStatus(ButtonPolicy::APPLY);
|
|
|
|
apply_->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
if (restore_) {
|
|
|
|
bool const enabled =
|
|
|
|
all_valid && bp().buttonStatus(ButtonPolicy::RESTORE);
|
|
|
|
restore_->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
if (cancel_) {
|
|
|
|
bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL);
|
|
|
|
if (enabled)
|
|
|
|
cancel_->setText(toqstr(_("Cancel")));
|
|
|
|
else
|
|
|
|
cancel_->setText(toqstr(_("Close")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Qt2BC::refreshReadOnly() const
|
|
|
|
{
|
2007-09-02 07:53:07 +00:00
|
|
|
if (read_only_.empty())
|
|
|
|
return;
|
2007-09-01 20:44:14 +00:00
|
|
|
|
|
|
|
bool const enable = !bp().isReadOnly();
|
|
|
|
|
|
|
|
Widgets::const_iterator end = read_only_.end();
|
|
|
|
Widgets::const_iterator iter = read_only_.begin();
|
2007-09-02 07:53:07 +00:00
|
|
|
for (; iter != end; ++iter)
|
2007-09-01 20:44:14 +00:00
|
|
|
setWidgetEnabled(*iter, enable);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled) const
|
|
|
|
{
|
2007-04-25 16:39:21 +00:00
|
|
|
if (QLineEdit * le = qobject_cast<QLineEdit*>(obj))
|
2006-03-05 17:24:44 +00:00
|
|
|
le->setReadOnly(!enabled);
|
2007-04-25 16:39:21 +00:00
|
|
|
else
|
2006-03-05 17:24:44 +00:00
|
|
|
obj->setEnabled(enabled);
|
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
obj->setFocusPolicy(enabled ? Qt::StrongFocus : Qt::NoFocus);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-09-02 07:53:07 +00:00
|
|
|
|
2007-09-02 08:19:43 +00:00
|
|
|
void Qt2BC::addCheckedLineEdit(QLineEdit * input, QWidget * label)
|
2007-09-02 07:53:07 +00:00
|
|
|
{
|
2007-09-02 08:19:43 +00:00
|
|
|
checked_widgets.push_back(CheckedLineEdit(input, label));
|
2007-09-02 07:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Qt2BC::checkWidgets() const
|
|
|
|
{
|
|
|
|
bool valid = true;
|
|
|
|
|
|
|
|
CheckedWidgetList::const_iterator it = checked_widgets.begin();
|
|
|
|
CheckedWidgetList::const_iterator end = checked_widgets.end();
|
|
|
|
|
|
|
|
for (; it != end; ++it)
|
2007-09-02 08:19:43 +00:00
|
|
|
valid &= it->check();
|
2007-09-02 07:53:07 +00:00
|
|
|
|
|
|
|
// return valid status after checking ALL widgets
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-02 08:19:43 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CheckedLineEdit
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void addCheckedLineEdit(BCView & bcview, QLineEdit * input, QWidget * label)
|
|
|
|
{
|
|
|
|
Qt2BC * bc = static_cast<Qt2BC *>(&bcview);
|
|
|
|
bc->addCheckedLineEdit(input, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void setWarningColor(QWidget * widget)
|
|
|
|
{
|
|
|
|
QPalette pal = widget->palette();
|
|
|
|
pal.setColor(QPalette::Active, QPalette::Foreground, QColor(255, 0, 0));
|
|
|
|
widget->setPalette(pal);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QWidget * 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.
|
|
|
|
if (valid)
|
|
|
|
input_->setPalette(QPalette());
|
|
|
|
else
|
|
|
|
setWarningColor(input_);
|
|
|
|
|
2007-09-02 19:54:01 +00:00
|
|
|
if (label_) {
|
2007-09-02 08:19:43 +00:00
|
|
|
if (valid)
|
|
|
|
label_->setPalette(QPalette());
|
|
|
|
else
|
|
|
|
setWarningColor(label_);
|
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|