aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/url/libkviurl.cpp
diff options
context:
space:
mode:
authorGravatar Vladimir Panteleev2019-04-17 21:01:35 +0000
committerGravatar Benjamin Staneck2019-05-02 02:12:05 +0200
commit1a47fd00af1f831dfaec3cfe413e2e5dc3a125ca (patch)
tree0640200a887676ce55a214a6d493a47803b7eeca /src/modules/url/libkviurl.cpp
parentlibkviurl: Fix showing configuration dialog after closing it with Esc (diff)
downloadKVIrc-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/modules/url/libkviurl.cpp')
-rw-r--r--src/modules/url/libkviurl.cpp55
1 files changed, 22 insertions, 33 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)