Commit 1422b0d0 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add button for add/remove/modify rule

parent b1444a2c
Pipeline #175552 failed with stage
in 12 minutes and 29 seconds
......@@ -7,6 +7,7 @@
#include "openurlwithconfigurewidgettest.h"
#include "openurlwithconfigurewidget.h"
#include <QListWidget>
#include <QPushButton>
#include <QTest>
#include <QVBoxLayout>
QTEST_MAIN(OpenUrlWithConfigureWidgetTest)
......@@ -29,4 +30,16 @@ void OpenUrlWithConfigureWidgetTest::shouldHaveDefaultValues()
QVERIFY(mListWidget->isSortingEnabled());
QCOMPARE(mListWidget->contextMenuPolicy(), Qt::CustomContextMenu);
QCOMPARE(mListWidget->selectionMode(), QAbstractItemView::ExtendedSelection);
auto mAddRule = w.findChild<QPushButton *>(QStringLiteral("mAddRule"));
QVERIFY(mAddRule);
QVERIFY(!mAddRule->text().isEmpty());
auto mRemoveRule = w.findChild<QPushButton *>(QStringLiteral("mRemoveRule"));
QVERIFY(mRemoveRule);
QVERIFY(!mRemoveRule->text().isEmpty());
auto mModifyRule = w.findChild<QPushButton *>(QStringLiteral("mModifyRule"));
QVERIFY(mModifyRule);
QVERIFY(!mModifyRule->text().isEmpty());
}
......@@ -14,6 +14,7 @@
#include <QListWidget>
#include <QMenu>
#include <QPointer>
#include <QPushButton>
#include <QTreeWidget>
#include <QVBoxLayout>
......@@ -53,23 +54,57 @@ MessageViewer::OpenWithUrlInfo OpenUrlWithConfigureItem::info() const
OpenUrlWithConfigureWidget::OpenUrlWithConfigureWidget(QWidget *parent)
: QWidget{parent}
, mListWidget(new QListWidget(this))
, mAddRule(new QPushButton(i18n("Add Rule..."), this))
, mRemoveRule(new QPushButton(i18n("Remove Rule"), this))
, mModifyRule(new QPushButton(i18n("Modify Rule..."), this))
{
auto mainLayout = new QVBoxLayout(this);
mainLayout->setObjectName(QStringLiteral("mainLayout"));
mainLayout->setContentsMargins(QMargins());
auto listLayout = new QHBoxLayout;
mainLayout->addLayout(listLayout);
mListWidget->setObjectName(QStringLiteral("mListWidget"));
mainLayout->addWidget(mListWidget);
listLayout->addWidget(mListWidget);
mListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
mListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
mListWidget->setAlternatingRowColors(true);
mListWidget->setSortingEnabled(true);
connect(mListWidget, &QListWidget::customContextMenuRequested, this, &OpenUrlWithConfigureWidget::slotCustomContextMenuRequested);
connect(mListWidget, &QListWidget::itemDoubleClicked, this, &OpenUrlWithConfigureWidget::slotEditRule);
connect(mListWidget, &QListWidget::itemSelectionChanged, this, &OpenUrlWithConfigureWidget::updateButtons);
auto buttonLayout = new QVBoxLayout;
listLayout->addLayout(buttonLayout);
connect(mAddRule, &QPushButton::clicked, this, &OpenUrlWithConfigureWidget::slotAddRule);
mAddRule->setObjectName(QStringLiteral("mAddRule"));
buttonLayout->addWidget(mAddRule);
connect(mModifyRule, &QPushButton::clicked, this, &OpenUrlWithConfigureWidget::slotEditRule);
mModifyRule->setObjectName(QStringLiteral("mModifyRule"));
buttonLayout->addWidget(mModifyRule);
connect(mRemoveRule, &QPushButton::clicked, this, &OpenUrlWithConfigureWidget::slotRemoveRule);
mRemoveRule->setObjectName(QStringLiteral("mRemoveRule"));
buttonLayout->addWidget(mRemoveRule);
buttonLayout->addStretch(1);
updateButtons();
}
OpenUrlWithConfigureWidget::~OpenUrlWithConfigureWidget()
OpenUrlWithConfigureWidget::~OpenUrlWithConfigureWidget() = default;
void OpenUrlWithConfigureWidget::updateButtons()
{
QListWidgetItem *item = mListWidget->currentItem();
if (item) {
mRemoveRule->setEnabled(true);
mModifyRule->setEnabled(true);
} else {
mRemoveRule->setEnabled(false);
mModifyRule->setEnabled(false);
}
}
void OpenUrlWithConfigureWidget::displayText(const MessageViewer::OpenWithUrlInfo &r, OpenUrlWithConfigureItem *item)
......
......@@ -9,6 +9,7 @@
#include "openurlwith_private_export.h"
#include <QWidget>
class QListWidget;
class QPushButton;
class OpenUrlWithConfigureItem;
namespace MessageViewer
{
......@@ -29,5 +30,9 @@ private:
void slotEditRule();
void slotRemoveRule();
void displayText(const MessageViewer::OpenWithUrlInfo &r, OpenUrlWithConfigureItem *item);
void updateButtons();
QListWidget *const mListWidget;
QPushButton *const mAddRule;
QPushButton *const mRemoveRule;
QPushButton *const mModifyRule;
};
Supports Markdown
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