diff options
| author | 2019-04-17 21:01:35 +0000 | |
|---|---|---|
| committer | 2019-05-02 02:12:05 +0200 | |
| commit | 1a47fd00af1f831dfaec3cfe413e2e5dc3a125ca (patch) | |
| tree | 0640200a887676ce55a214a6d493a47803b7eeca /src | |
| parent | libkviurl: Fix showing configuration dialog after closing it with Esc (diff) | |
| download | KVIrc-1a47fd00af1f831dfaec3cfe413e2e5dc3a125ca.tar.gz KVIrc-1a47fd00af1f831dfaec3cfe413e2e5dc3a125ca.tar.bz2 KVIrc-1a47fd00af1f831dfaec3cfe413e2e5dc3a125ca.zip | |
libkviurl: Use Qt's native context menu events instead of emulation
Use Qt's customContextMenuRequested signal + setContextMenuPolicy, and
unify UrlDialog::popup with UrlDialog::contextMenu, to fix:
- Pressing the Menu key on the keyboard did not pop up a menu.
- The right-clicked item was not selected before the context menu was
displayed, thus, the selected action applied to the old
selection. The selection changed to the right-clicked item after the
context menu was closed.
- If there was no room left, it was not possible to summon the context
menu that held the "Configure" option.
Diffstat (limited to 'src')
| -rw-r--r-- | src/modules/url/libkviurl.cpp | 55 | ||||
| -rw-r--r-- | src/modules/url/libkviurl.h | 5 |
2 files changed, 22 insertions, 38 deletions
diff --git a/src/modules/url/libkviurl.cpp b/src/modules/url/libkviurl.cpp index 8e6bfb569..de1a4982b 100644 --- a/src/modules/url/libkviurl.cpp +++ b/src/modules/url/libkviurl.cpp @@ -84,19 +84,6 @@ UrlDialogTreeWidget::UrlDialogTreeWidget(QWidget * par) { } -void UrlDialogTreeWidget::mousePressEvent(QMouseEvent * e) -{ - if(e->button() == Qt::RightButton) - { - QTreeWidgetItem * i = itemAt(e->pos()); - if(i) - emit rightButtonPressed(i, QCursor::pos()); - else - emit contextMenuRequested(QCursor::pos()); - } - QTreeWidget::mousePressEvent(e); -} - void UrlDialogTreeWidget::paintEvent(QPaintEvent * event) { QPainter * p = new QPainter(viewport()); @@ -154,8 +141,8 @@ UrlDialog::UrlDialog(std::unordered_set<KviUrl *>) m_pUrlList->setHeaderLabels(labels); connect(m_pUrlList, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), SLOT(dblclk_url(QTreeWidgetItem *, int))); - connect(m_pUrlList, SIGNAL(rightButtonPressed(QTreeWidgetItem *, const QPoint &)), SLOT(popup(QTreeWidgetItem *, const QPoint &))); - connect(m_pUrlList, SIGNAL(contextMenuRequested(const QPoint &)), SLOT(contextMenu(const QPoint &))); + connect(m_pUrlList, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(contextMenu(const QPoint &))); + m_pUrlList->setContextMenuPolicy(Qt::CustomContextMenu); m_pUrlList->setFocusPolicy(Qt::StrongFocus); m_pUrlList->setFocus(); } @@ -229,32 +216,34 @@ void UrlDialog::dblclk_url(QTreeWidgetItem * item, int) KviKvsScript::run(cmd, this); } -void UrlDialog::popup(QTreeWidgetItem * item, const QPoint & point) +void UrlDialog::contextMenu(const QPoint & point) { - m_szUrl = item->text(0); - QMenu p("menu", nullptr); - p.addAction(__tr2qs("&Remove"), this, SLOT(remove())); - - p.addSeparator(); - m_pListPopup = new QMenu("list", nullptr); + QTreeWidgetItem * item = m_pUrlList->itemAt(point); - for(auto & w : g_pMainWindow->windowList()) + QMenu p("contextmenu", nullptr); + if (item) { - if((w->type() == KviWindow::Channel) || (w->type() == KviWindow::Query) || (w->type() == KviWindow::DccChat)) + m_szUrl = item->text(0); + p.addAction(__tr2qs("&Remove"), this, SLOT(remove())); + + p.addSeparator(); + m_pListPopup = new QMenu("list", nullptr); + + for(auto & w : g_pMainWindow->windowList()) { - m_pListPopup->addAction(w->plainTextCaption()); + if((w->type() == KviWindow::Channel) || (w->type() == KviWindow::Query) || (w->type() == KviWindow::DccChat)) + { + m_pListPopup->addAction(w->plainTextCaption()); + } } + p.addAction(__tr2qs("&Say to Window"))->setMenu(m_pListPopup); + connect(m_pListPopup, SIGNAL(triggered(QAction *)), this, SLOT(sayToWin(QAction *))); + + p.addSeparator(); } - p.addAction(__tr2qs("&Say to Window"))->setMenu(m_pListPopup); - connect(m_pListPopup, SIGNAL(triggered(QAction *)), this, SLOT(sayToWin(QAction *))); - p.exec(point); -} -void UrlDialog::contextMenu(const QPoint & point) -{ - QMenu p("contextmenu", nullptr); p.addAction(__tr2qs("Configure"), this, SLOT(config())); - p.exec(point); + p.exec(m_pUrlList->viewport()->mapToGlobal(point)); } void UrlDialog::sayToWin(QAction * act) diff --git a/src/modules/url/libkviurl.h b/src/modules/url/libkviurl.h index cb14edac7..81519cdd9 100644 --- a/src/modules/url/libkviurl.h +++ b/src/modules/url/libkviurl.h @@ -64,11 +64,7 @@ public: ~UrlDialogTreeWidget(){}; protected: - void mousePressEvent(QMouseEvent * e) override; void paintEvent(QPaintEvent * event) override; -signals: - void rightButtonPressed(QTreeWidgetItem *, QPoint); - void contextMenuRequested(QPoint); }; class UrlDialog : public KviWindow @@ -100,7 +96,6 @@ protected slots: void remove(); void findtext(); void dblclk_url(QTreeWidgetItem * item, int); - void popup(QTreeWidgetItem * item, const QPoint & p); void contextMenu(const QPoint & p); void sayToWin(QAction * act); }; |
