3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
16 #include "ButtonPolicy.h"
18 #include "qt_helpers.h"
20 #include <QPushButton>
30 Qt2BC::Qt2BC(ButtonController & parent)
31 : BCView(parent), okay_(0), apply_(0), cancel_(0), restore_(0)
35 void Qt2BC::refresh() const
37 LYXERR(Debug::GUI) << "Calling BC refresh()" << std::endl;
39 bool const all_valid = checkWidgets();
43 all_valid && bp().buttonStatus(ButtonPolicy::OKAY);
44 okay_->setEnabled(enabled);
48 all_valid && bp().buttonStatus(ButtonPolicy::APPLY);
49 apply_->setEnabled(enabled);
53 all_valid && bp().buttonStatus(ButtonPolicy::RESTORE);
54 restore_->setEnabled(enabled);
57 bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL);
59 cancel_->setText(toqstr(_("Cancel")));
61 cancel_->setText(toqstr(_("Close")));
66 void Qt2BC::refreshReadOnly() const
68 if (read_only_.empty())
71 bool const enable = !bp().isReadOnly();
73 Widgets::const_iterator end = read_only_.end();
74 Widgets::const_iterator iter = read_only_.begin();
75 for (; iter != end; ++iter)
76 setWidgetEnabled(*iter, enable);
80 void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled) const
82 if (QLineEdit * le = qobject_cast<QLineEdit*>(obj))
83 le->setReadOnly(!enabled);
85 obj->setEnabled(enabled);
87 obj->setFocusPolicy(enabled ? Qt::StrongFocus : Qt::NoFocus);
91 void Qt2BC::addCheckedLineEdit(QLineEdit * input, QWidget * label)
93 checked_widgets.push_back(CheckedLineEdit(input, label));
97 bool Qt2BC::checkWidgets() const
101 CheckedWidgetList::const_iterator it = checked_widgets.begin();
102 CheckedWidgetList::const_iterator end = checked_widgets.end();
104 for (; it != end; ++it)
105 valid &= it->check();
107 // return valid status after checking ALL widgets
112 //////////////////////////////////////////////////////////////
116 //////////////////////////////////////////////////////////////
118 void addCheckedLineEdit(BCView & bcview, QLineEdit * input, QWidget * label)
120 Qt2BC * bc = static_cast<Qt2BC *>(&bcview);
121 bc->addCheckedLineEdit(input, label);
125 static void setWarningColor(QWidget * widget)
127 QPalette pal = widget->palette();
128 pal.setColor(QPalette::Active, QPalette::Foreground, QColor(255, 0, 0));
129 widget->setPalette(pal);
134 CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QWidget * label)
135 : input_(input), label_(label)
139 bool CheckedLineEdit::check() const
141 QValidator const * validator = input_->validator();
145 QString t = input_->text();
147 bool const valid = validator->validate(t, p) == QValidator::Acceptable;
151 input_->setPalette(QPalette());
153 setWarningColor(input_);
157 label_->setPalette(QPalette());
159 setWarningColor(label_);
165 } // namespace frontend