Restore the ability to associate menus with actions

This commit is contained in:
Kovid Goyal 2021-11-21 20:39:43 +05:30
parent 2eb32da7d6
commit 6928a3a0f5
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 25 additions and 1 deletions

View File

@ -431,3 +431,13 @@ void draw_snake_spinner(QPainter &painter, QRect rect, int angle, const QColor &
painter.drawArc(drawing_rect, angle * 16, (360 - gap) * 16);
painter.restore();
}
void
set_menu_on_action(QAction* ac, QMenu* menu) {
ac->setMenu<QMenu*>(menu);
}
QMenu*
menu_for_action(QAction *ac) {
return ac->menu<QMenu*>();
}

View File

@ -5,6 +5,7 @@
#include <QColor>
#include <QHash>
#include <QPainter>
#include <QMenu>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
@ -140,3 +141,5 @@ private:
int load_style(const QHash<unsigned long,QString> &icon_map, int transient_scroller=0);
void set_no_activate_on_click(QWidget *widget);
void draw_snake_spinner(QPainter &painter, QRect rect, int angle, const QColor & light, const QColor & dark);
void set_menu_on_action(QAction* ac, QMenu* menu);
QMenu* menu_for_action(QAction *ac);

View File

@ -86,3 +86,5 @@ int load_style(SIP_PYDICT icon_map_, int transient_scroller);
%End
void set_no_activate_on_click(QWidget *widget);
void draw_snake_spinner(QPainter &painter, QRect rect, int angle, const QColor & light, const QColor & dark) /ReleaseGIL/;
void set_menu_on_action(QAction* ac, QMenu* menu);
QMenu* menu_for_action(QAction *ac);

View File

@ -6,8 +6,12 @@
# for no good reason. Since we have a huge body of poorly maintained third
# party plugin code, we NEED backward compat.
from qt.core import QSinglePointEvent, QDialog, QMenu, QDrag, QEventLoop, QThread, QMessageBox
from qt.core import (
QAction, QDialog, QDrag, QEventLoop, QMenu, QMessageBox, QSinglePointEvent,
QThread
)
from calibre_extensions import progress_indicator
# Restore removed functions from QMouseEvent
QSinglePointEvent.x = lambda self: int(self.position().x())
@ -27,3 +31,8 @@ QDrag.exec_ = QDrag.exec
QEventLoop.exec_ = QEventLoop.exec
QThread.exec_ = QThread.exec
QMessageBox.exec_ = QMessageBox.exec
# Restore ability to associate a menu with an action
QAction.setMenu = lambda self, menu: progress_indicator.set_menu_on_action(self, menu)
QAction.menu = lambda self, menu: progress_indicator.menu_for_action(self)