Commit 93675892 authored by Laurent Montel's avatar Laurent Montel 😁

Fix enable disable ok button

parent 09f84fc1
......@@ -22,6 +22,7 @@
#include <QTest>
#include <QLabel>
#include <QCheckBox>
#include <QPushButton>
#include <QDialogButtonBox>
#include <Libkdepim/AddresseeLineEdit>
......@@ -45,6 +46,7 @@ void DelegateSelectorTest::shouldHaveDefaultValue()
KPIM::AddresseeLineEdit *mDelegate = w.findChild<KPIM::AddresseeLineEdit *>(QStringLiteral("delegate"));
QVERIFY(mDelegate);
QVERIFY(mDelegate->text().isEmpty());
QCheckBox *mRsvp = w.findChild<QCheckBox *>(QStringLiteral("informcheckbox"));
QVERIFY(mRsvp);
......@@ -53,6 +55,31 @@ void DelegateSelectorTest::shouldHaveDefaultValue()
QDialogButtonBox *buttonBox = w.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox"));
QVERIFY(buttonBox);
QPushButton *mOkButton = buttonBox->button(QDialogButtonBox::Ok);
QVERIFY(mOkButton);
QVERIFY(!mOkButton->isEnabled());
}
void DelegateSelectorTest::shouldChangeOkButtonState()
{
DelegateSelector w;
KPIM::AddresseeLineEdit *mDelegate = w.findChild<KPIM::AddresseeLineEdit *>(QStringLiteral("delegate"));
mDelegate->setEnableAkonadiSearch(false);
mDelegate->setEnableBalooSearch(false);
QDialogButtonBox *buttonBox = w.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox"));
QPushButton *mOkButton = buttonBox->button(QDialogButtonBox::Ok);
QVERIFY(!mOkButton->isEnabled());
mDelegate->setText(QStringLiteral("foo"));
QVERIFY(mOkButton->isEnabled());
mDelegate->clear();
QVERIFY(!mOkButton->isEnabled());
mDelegate->setText(QStringLiteral(" "));
QVERIFY(!mOkButton->isEnabled());
}
QTEST_MAIN(DelegateSelectorTest)
......@@ -30,6 +30,7 @@ public:
~DelegateSelectorTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldChangeOkButtonState();
};
#endif // DELEGATESELECTORTEST_H
......@@ -57,6 +57,7 @@ DelegateSelector::DelegateSelector(QWidget *parent)
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
buttonBox->setObjectName(QStringLiteral("buttonbox"));
mOkButton = buttonBox->button(QDialogButtonBox::Ok);
mOkButton->setObjectName(QStringLiteral("okbutton"));
mOkButton->setDefault(true);
mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &DelegateSelector::accept);
......@@ -69,7 +70,7 @@ DelegateSelector::DelegateSelector(QWidget *parent)
void DelegateSelector::slotTextChanged(const QString &text)
{
mOkButton->setEnabled(!text.isEmpty());
mOkButton->setEnabled(!text.trimmed().isEmpty());
}
QString DelegateSelector::delegate() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment