Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: item context menu not updated #948

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions frame/window/quickpluginwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ void QuickPluginWindow::onUpdatePlugin(PluginsItemInterface *itemInter, const Do

QuickDockItem *quickDockItem = getDockItemByPlugin(itemInter);
if (quickDockItem) {
quickDockItem->updateContextMenu();
updateDockItemSize(quickDockItem);
quickDockItem->update();
}
Expand Down Expand Up @@ -828,30 +829,12 @@ void QuickDockItem::mousePressEvent(QMouseEvent *event)
if (event->button() != Qt::RightButton)
return QWidget::mousePressEvent(event);

if (m_contextMenu->actions().isEmpty()) {
const QString menuJson = m_pluginItem->itemContextMenu(m_itemKey);
if (menuJson.isEmpty())
return;

QJsonDocument jsonDocument = QJsonDocument::fromJson(menuJson.toLocal8Bit().data());
if (jsonDocument.isNull())
return;

QJsonObject jsonMenu = jsonDocument.object();

QJsonArray jsonMenuItems = jsonMenu.value("items").toArray();
for (auto item : jsonMenuItems) {
QJsonObject itemObj = item.toObject();
QAction *action = new QAction(itemObj.value("itemText").toString());
action->setCheckable(itemObj.value("isCheckable").toBool());
action->setChecked(itemObj.value("checked").toBool());
action->setData(itemObj.value("itemId").toString());
action->setEnabled(itemObj.value("isActive").toBool());
m_contextMenu->addAction(action);
}
}
static std::once_flag contextMenuInitialized;
std::call_once(contextMenuInitialized, &QuickDockItem::updateContextMenu, this);

m_contextMenu->exec(QCursor::pos());
if (!m_contextMenu->actions().isEmpty()) {
m_contextMenu->exec(QCursor::pos());
}
}

void QuickDockItem::enterEvent(QEvent *event)
Expand Down Expand Up @@ -1017,6 +1000,31 @@ int QuickDockItem::iconSize() const
return 30;
}

void QuickDockItem::updateContextMenu()
{
m_contextMenu->clear();
const QString menuJson = m_pluginItem->itemContextMenu(m_itemKey);
if (menuJson.isEmpty())
return;

QJsonDocument jsonDocument = QJsonDocument::fromJson(menuJson.toLocal8Bit().data());
if (jsonDocument.isNull())
return;

QJsonObject jsonMenu = jsonDocument.object();

QJsonArray jsonMenuItems = jsonMenu.value("items").toArray();
for (auto item : jsonMenuItems) {
QJsonObject itemObj = item.toObject();
QAction *action = new QAction(itemObj.value("itemText").toString());
action->setCheckable(itemObj.value("isCheckable").toBool());
action->setChecked(itemObj.value("checked").toBool());
action->setData(itemObj.value("itemId").toString());
action->setEnabled(itemObj.value("isActive").toBool());
m_contextMenu->addAction(action);
}
}

QPoint QuickDockItem::topleftPoint() const
{
QPoint p = this->pos();
Expand Down
1 change: 1 addition & 0 deletions frame/window/quickpluginwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class QuickDockItem : public QWidget
bool canInsert() const;
bool canMove() const;
void hideToolTip();
void updateContextMenu();

QSize suitableSize() const;

Expand Down