Commit c75a2e52 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Make context menu on a bookmark menu action work again

Solves a todo from porting to kf5

Reviewed by Albert Astals
parent 7304d320
......@@ -44,6 +44,7 @@
#include <QSpinBox>
#include <QStandardPaths>
#include <QWidgetAction>
#include <QContextMenuEvent>
#include <KAboutApplicationDialog>
#include <KActionCollection>
......@@ -2156,15 +2157,8 @@ void Part::slotRenameCurrentViewportBookmark()
slotRenameBookmark( m_document->viewport() );
}
void Part::slotAboutToShowContextMenu(QMenu * /*menu*/, QAction *action, QMenu *contextMenu)
bool Part::aboutToShowContextMenu(QMenu * /*menu*/, QAction *action, QMenu *contextMenu)
{
const QList<QAction*> actions = contextMenu->findChildren<QAction*>(QStringLiteral("OkularPrivateRenameBookmarkActions"));
foreach(QAction *a, actions)
{
contextMenu->removeAction(a);
delete a;
}
KBookmarkAction *ba = dynamic_cast<KBookmarkAction*>(action);
if (ba != NULL)
{
......@@ -2174,6 +2168,7 @@ void Part::slotAboutToShowContextMenu(QMenu * /*menu*/, QAction *action, QMenu *
renameAction->setData(ba->property("htmlRef").toString());
renameAction->setObjectName(QStringLiteral("OkularPrivateRenameBookmarkActions"));
}
return ba;
}
void Part::slotPreviousBookmark()
......@@ -3009,12 +3004,10 @@ void Part::rebuildBookmarkMenu( bool unplugActions )
bool containerFound = false;
for (int i = 0; !containerFound && i < clients.size(); ++i)
{
QWidget *container = factory()->container(QStringLiteral("bookmarks"), clients[i]);
QMenu *container = dynamic_cast<QMenu*>(factory()->container(QStringLiteral("bookmarks"), clients[i]));
if (container && container->actions().contains(m_bookmarkActions.first()))
{
Q_ASSERT(dynamic_cast<QMenu*>(container));
disconnect(container, 0, this, 0);
connect(container, SIGNAL(aboutToShowContextMenu(QMenu*,QAction*,QMenu*)), this, SLOT(slotAboutToShowContextMenu(QMenu*,QAction*,QMenu*))); // kf5 FIXME
container->installEventFilter(this);
containerFound = true;
}
}
......@@ -3024,6 +3017,39 @@ void Part::rebuildBookmarkMenu( bool unplugActions )
m_nextBookmark->setEnabled( havebookmarks );
}
bool Part::eventFilter(QObject * watched, QEvent * event)
{
switch (event->type()) {
case QEvent::ContextMenu: {
QContextMenuEvent *e = static_cast<QContextMenuEvent *>(event);
QMenu *menu = static_cast<QMenu *>(watched);
QScopedPointer<QMenu> ctxMenu(new QMenu);
QPoint pos;
bool ret = false;
if (e->reason() == QContextMenuEvent::Mouse) {
pos = e->pos();
ret = aboutToShowContextMenu(menu, menu->actionAt(e->pos()), ctxMenu.data());
} else if (menu->activeAction()) {
pos = menu->actionGeometry(menu->activeAction()).center();
ret = aboutToShowContextMenu(menu, menu->activeAction(), ctxMenu.data());
}
ctxMenu->exec(menu->mapToGlobal(pos));
if (ret) {
event->accept();
}
return ret;
}
default:
break;
}
return false;
}
void Part::updateAboutBackendAction()
{
const KPluginMetaData data = m_document->generatorInfo();
......
......@@ -190,7 +190,6 @@ class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::Docu
void slotAddBookmark();
void slotRenameBookmarkFromMenu();
void slotRenameCurrentViewportBookmark();
void slotAboutToShowContextMenu(QMenu *menu, QAction *action, QMenu *contextMenu);
void slotPreviousBookmark();
void slotNextBookmark();
void slotFindNext();
......@@ -240,6 +239,8 @@ class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::Docu
void moveSplitter( const int sideWidgetSize );
private:
bool aboutToShowContextMenu(QMenu *menu, QAction *action, QMenu *contextMenu);
bool eventFilter(QObject * watched, QEvent * event) override;
Document::OpenResult doOpenFile(const QMimeType &mime, const QString &fileNameToOpen, bool *isCompressedFile);
void setupViewerActions();
......
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