mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-24 02:13:02 -07:00
[UserList] Fix context menu crash by correctly parenting (#7145)
Took 5 minutes Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
fe53f9c3eb
commit
3de7882f0c
2 changed files with 10 additions and 6 deletions
|
|
@ -336,11 +336,12 @@ constexpr int UserInfo = Qt::UserRole + 2;
|
||||||
// rows (UserListTWI, which uses QTreeWidgetItem::Type) by this item type.
|
// rows (UserListTWI, which uses QTreeWidgetItem::Type) by this item type.
|
||||||
constexpr int SectionItemType = QTreeWidgetItem::UserType + 1;
|
constexpr int SectionItemType = QTreeWidgetItem::UserType + 1;
|
||||||
|
|
||||||
UserListItemDelegate::UserListItemDelegate(QTreeWidget *tree,
|
UserListItemDelegate::UserListItemDelegate(UserListWidget *owner,
|
||||||
|
QTreeWidget *tree,
|
||||||
const QMap<QString, QPixmap> *avatarCache,
|
const QMap<QString, QPixmap> *avatarCache,
|
||||||
const QMap<QString, QPixmap> *cardArtCache,
|
const QMap<QString, QPixmap> *cardArtCache,
|
||||||
const QMap<QString, CardArtParams> *cardArtParamsMap)
|
const QMap<QString, CardArtParams> *cardArtParamsMap)
|
||||||
: QStyledItemDelegate(tree), tree(tree), avatarCache(avatarCache), cardArtCache(cardArtCache),
|
: QStyledItemDelegate(tree), tree(tree), owner(owner), avatarCache(avatarCache), cardArtCache(cardArtCache),
|
||||||
cardArtParamsMap(cardArtParamsMap)
|
cardArtParamsMap(cardArtParamsMap)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -353,7 +354,7 @@ bool UserListItemDelegate::editorEvent(QEvent *event,
|
||||||
if ((event->type() == QEvent::MouseButtonPress) && index.isValid()) {
|
if ((event->type() == QEvent::MouseButtonPress) && index.isValid()) {
|
||||||
QMouseEvent *const mouseEvent = static_cast<QMouseEvent *>(event);
|
QMouseEvent *const mouseEvent = static_cast<QMouseEvent *>(event);
|
||||||
if (mouseEvent->button() == Qt::RightButton) {
|
if (mouseEvent->button() == Qt::RightButton) {
|
||||||
static_cast<UserListWidget *>(parent())->showContextMenu(mouseEvent->globalPosition().toPoint(), index);
|
owner->showContextMenu(mouseEvent->globalPosition().toPoint(), index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -593,8 +594,8 @@ UserListWidget::UserListWidget(TabSupervisor *_tabSupervisor,
|
||||||
userTree->setHeaderHidden(true);
|
userTree->setHeaderHidden(true);
|
||||||
userTree->setRootIsDecorated(false);
|
userTree->setRootIsDecorated(false);
|
||||||
userTree->setIconSize(QSize(20, 18));
|
userTree->setIconSize(QSize(20, 18));
|
||||||
itemDelegate =
|
itemDelegate = new UserListItemDelegate(this, userTree, &avatarProvider->cache(), &cardArtProvider->cache(),
|
||||||
new UserListItemDelegate(userTree, &avatarProvider->cache(), &cardArtProvider->cache(), &cardArtParamsMap);
|
&cardArtParamsMap);
|
||||||
userTree->setItemDelegate(itemDelegate);
|
userTree->setItemDelegate(itemDelegate);
|
||||||
userTree->setAlternatingRowColors(true);
|
userTree->setAlternatingRowColors(true);
|
||||||
userTree->hideColumn(1);
|
userTree->hideColumn(1);
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ class QPlainTextEdit;
|
||||||
class Response;
|
class Response;
|
||||||
class CommandContainer;
|
class CommandContainer;
|
||||||
class UserContextMenu;
|
class UserContextMenu;
|
||||||
|
class UserListWidget;
|
||||||
class QShowEvent;
|
class QShowEvent;
|
||||||
|
|
||||||
class BanDialog : public QDialog
|
class BanDialog : public QDialog
|
||||||
|
|
@ -105,12 +106,14 @@ public:
|
||||||
class UserListItemDelegate : public QStyledItemDelegate
|
class UserListItemDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
QTreeWidget *tree;
|
QTreeWidget *tree;
|
||||||
|
UserListWidget *owner;
|
||||||
const QMap<QString, QPixmap> *avatarCache;
|
const QMap<QString, QPixmap> *avatarCache;
|
||||||
const QMap<QString, QPixmap> *cardArtCache;
|
const QMap<QString, QPixmap> *cardArtCache;
|
||||||
const QMap<QString, CardArtParams> *cardArtParamsMap;
|
const QMap<QString, CardArtParams> *cardArtParamsMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit UserListItemDelegate(QTreeWidget *tree,
|
explicit UserListItemDelegate(UserListWidget *owner,
|
||||||
|
QTreeWidget *tree,
|
||||||
const QMap<QString, QPixmap> *avatarCache,
|
const QMap<QString, QPixmap> *avatarCache,
|
||||||
const QMap<QString, QPixmap> *cardArtCache,
|
const QMap<QString, QPixmap> *cardArtCache,
|
||||||
const QMap<QString, CardArtParams> *cardArtParamsMap);
|
const QMap<QString, CardArtParams> *cardArtParamsMap);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue