Commit 57cc30ae authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add contextmenu

parent cbe25955
Pipeline #51284 failed with stage
in 8 minutes and 57 seconds
......@@ -33,6 +33,7 @@ void CustomDebugSettingsPageTest::shouldHaveDefaultValue()
QVERIFY(listWidget);
QCOMPARE(listWidget->selectionMode(), QAbstractItemView::MultiSelection);
QCOMPARE(listWidget->count(), 0);
QCOMPARE(listWidget->contextMenuPolicy(), Qt::CustomContextMenu);
auto searchLine = page.findChild<KListWidgetSearchLine *>(QStringLiteral("searchline"));
QVERIFY(searchLine);
......
......@@ -14,6 +14,7 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QListWidget>
#include <QMenu>
#include <QPointer>
#include <QPushButton>
#include <QVBoxLayout>
......@@ -40,8 +41,10 @@ CustomDebugSettingsPage::CustomDebugSettingsPage(QWidget *parent)
mListWidget->setObjectName(QStringLiteral("custom_listwidget"));
mListWidget->setSelectionMode(QAbstractItemView::MultiSelection);
mListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mListWidget, &QListWidget::itemSelectionChanged, this, &CustomDebugSettingsPage::updateButtons);
connect(mListWidget, &QListWidget::itemDoubleClicked, this, &CustomDebugSettingsPage::slotEditRule);
connect(mListWidget, &QListWidget::customContextMenuRequested, this, &CustomDebugSettingsPage::slotCustomContextMenu);
auto searchLine = new KListWidgetSearchLine(this, mListWidget);
searchLine->setObjectName(QStringLiteral("searchline"));
searchLine->setPlaceholderText(i18n("Search..."));
......@@ -70,6 +73,21 @@ CustomDebugSettingsPage::~CustomDebugSettingsPage()
{
}
void CustomDebugSettingsPage::slotCustomContextMenu(const QPoint &pos)
{
QMenu menu(this);
const int selectedItemCount{mListWidget->selectedItems().count()};
menu.addAction(i18n("Add Rule..."), this, &CustomDebugSettingsPage::slotAddRule);
if (selectedItemCount == 1) {
menu.addAction(QIcon::fromTheme(QStringLiteral("edit")), i18n("Edit Rule"), this, &CustomDebugSettingsPage::slotEditRule);
}
if (selectedItemCount > 0) {
menu.addSeparator();
menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("Remove Rule"), this, &CustomDebugSettingsPage::slotRemoveRules);
}
menu.exec(mListWidget->viewport()->mapToGlobal(pos));
}
void CustomDebugSettingsPage::updateButtons()
{
mEditRule->setEnabled(mListWidget->selectedItems().count() == 1);
......
......@@ -28,6 +28,7 @@ private:
void slotAddRule();
void slotEditRule();
void updateButtons();
void slotCustomContextMenu(const QPoint &pos);
QListWidget *const mListWidget;
QPushButton *const mAddRule;
......
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