From e2c80b665e54d28df5dc65f6bfa819795f0e1f34 Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 13 Sep 2020 18:58:33 +0200 Subject: [PATCH] EntryPushButton: Begin menus for deletion/favourites --- entrypushbutton.cpp | 16 +++++++++++++++- entrypushbutton.h | 6 ++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/entrypushbutton.cpp b/entrypushbutton.cpp index dd6f5a0..7eb682e 100644 --- a/entrypushbutton.cpp +++ b/entrypushbutton.cpp @@ -39,6 +39,9 @@ EntryPushButton::EntryPushButton(const EntryConfig &config) : QPushButton() } this->config = config; connect(this, SIGNAL(clicked()), this, SLOT(emitOwnClicked())); + + systemEntryMenu.addAction("Add to favorites", [&] { emit addToFavourites(this->config); }); + userEntryMenu.addAction("Delete", [&] { emit deleteRequested(this->config); }); } void EntryPushButton::emitOwnClicked() @@ -72,12 +75,23 @@ void EntryPushButton::mousePressEvent(QMouseEvent *event) { dragStartPosition = event->pos(); } + if(event->button() == Qt::RightButton) + { + if(this->config.userEntry) + { + this->userEntryMenu.exec(QCursor::pos()); + } + else + { + this->systemEntryMenu.exec(QCursor::pos()); + } + } return QPushButton::mousePressEvent(event); } void EntryPushButton::mouseMoveEvent(QMouseEvent *event) { - if(! this->config.userEntry) + if(!this->config.userEntry) { return; } diff --git a/entrypushbutton.h b/entrypushbutton.h index 8c14852..edd40eb 100644 --- a/entrypushbutton.h +++ b/entrypushbutton.h @@ -19,6 +19,8 @@ #include #include #include +#include + #include "entryprovider.h" #define ENTRYBUTTON_MIME_TYPE_STR "application/x-qsrun-entrypushbutton" @@ -27,6 +29,8 @@ class EntryPushButton : public QPushButton { Q_OBJECT private: + QMenu systemEntryMenu; + QMenu userEntryMenu; EntryConfig config; QPoint dragStartPosition; @@ -35,6 +39,8 @@ class EntryPushButton : public QPushButton signals: void clicked(const EntryConfig &config); + void deleteRequested(const EntryConfig &config); + void addToFavourites(const EntryConfig &config); protected: void mousePressEvent(QMouseEvent *event);