Commit 1ae374aa authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to define icon

parent 7023bd22
......@@ -3,7 +3,7 @@ macro(add_messagelist_widget_unittest _source)
ecm_add_test(${_source}
TEST_NAME ${_name}
NAME_PREFIX "messagelist-"
LINK_LIBRARIES Qt::Test KF5::MessageCore KF5::MessageList KF5::PimCommon
LINK_LIBRARIES Qt::Test KF5::MessageCore KF5::MessageList KF5::PimCommon KF5::IconThemes
)
endmacro ()
......
......@@ -6,6 +6,9 @@
#include "filternamewidgettest.h"
#include "core/widgets/filternamewidget.h"
#include <KIconButton>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QTest>
QTEST_MAIN(FilterNameWidgetTest)
FilterNameWidgetTest::FilterNameWidgetTest(QObject *parent)
......@@ -16,5 +19,14 @@ FilterNameWidgetTest::FilterNameWidgetTest(QObject *parent)
void FilterNameWidgetTest::shouldHaveDefaultValues()
{
MessageList::Core::FilterNameWidget w;
// TODO
auto mainLayout = w.findChild<QHBoxLayout *>(QStringLiteral("mainLayout"));
QVERIFY(mainLayout);
QCOMPARE(mainLayout->contentsMargins(), {});
auto mName = w.findChild<QLineEdit *>(QStringLiteral("mName"));
QVERIFY(mName);
QVERIFY(mName->text().isEmpty());
auto mIconButton = w.findChild<KIconButton *>(QStringLiteral("mIconButton"));
QVERIFY(mIconButton);
}
......@@ -5,7 +5,9 @@
*/
#include "filternamewidget.h"
#include <KIconButton>
#include <KLocalizedString>
#include <QDebug>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
......@@ -14,18 +16,21 @@ using namespace MessageList::Core;
FilterNameWidget::FilterNameWidget(QWidget *parent)
: QWidget(parent)
, mName(new QLineEdit(this))
, mIconButton(new KIconButton(this))
{
auto mainLayout = new QHBoxLayout(this);
mainLayout->setObjectName(QStringLiteral("mainLayout"));
mainLayout->setContentsMargins({});
mName->setObjectName(QStringLiteral("mName"));
mIconButton->setObjectName(QStringLiteral("mIconButton"));
auto label = new QLabel(i18n("Name:"), this);
label->setObjectName(QStringLiteral("label"));
mainLayout->addWidget(label);
mainLayout->addWidget(mName);
mainLayout->addWidget(mIconButton);
connect(mName, &QLineEdit::textChanged, this, [this](const QString &str) {
const QString trimmedStr = str.trimmed();
Q_EMIT updateOkButton(!trimmedStr.isEmpty() && !mFilterListNames.contains(trimmedStr));
......@@ -41,6 +46,11 @@ QString FilterNameWidget::filterName() const
return mName->text();
}
QString FilterNameWidget::iconName() const
{
return mIconButton->icon();
}
void FilterNameWidget::setExistingFilterNames(const QStringList &lst)
{
mFilterListNames = lst;
......
......@@ -9,6 +9,7 @@
#include "messagelist_private_export.h"
#include <QWidget>
class QLineEdit;
class KIconButton;
namespace MessageList
{
namespace Core
......@@ -23,12 +24,14 @@ public:
Q_REQUIRED_RESULT QString filterName() const;
void setExistingFilterNames(const QStringList &lst);
Q_REQUIRED_RESULT QString iconName() const;
Q_SIGNALS:
void updateOkButton(bool enabled);
private:
QStringList mFilterListNames;
QLineEdit *const mName;
KIconButton *const mIconButton;
};
}
}
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