Make uncheckable menu items invisible
parent
62fdcbdced
commit
2a7554b852
|
@ -83,56 +83,59 @@ void SkeletonGraphicsWidget::showContextMenu(const QPoint &pos)
|
|||
});
|
||||
contextMenu.addAction(&addAction);
|
||||
|
||||
contextMenu.addSeparator();
|
||||
|
||||
QAction deleteAction("Delete", this);
|
||||
if (!m_rangeSelectionSet.empty()) {
|
||||
connect(&deleteAction, &QAction::triggered, this, &SkeletonGraphicsWidget::deleteSelected);
|
||||
deleteAction.setEnabled(!m_rangeSelectionSet.empty());
|
||||
contextMenu.addAction(&deleteAction);
|
||||
}
|
||||
|
||||
QAction cutAction("Cut", this);
|
||||
if (!m_rangeSelectionSet.empty()) {
|
||||
connect(&cutAction, &QAction::triggered, this, &SkeletonGraphicsWidget::cut);
|
||||
cutAction.setEnabled(!m_rangeSelectionSet.empty());
|
||||
contextMenu.addAction(&cutAction);
|
||||
}
|
||||
|
||||
QAction copyAction("Copy", this);
|
||||
if (!m_rangeSelectionSet.empty()) {
|
||||
connect(©Action, &QAction::triggered, this, &SkeletonGraphicsWidget::copy);
|
||||
copyAction.setEnabled(!m_rangeSelectionSet.empty());
|
||||
contextMenu.addAction(©Action);
|
||||
}
|
||||
|
||||
QAction pasteAction("Paste", this);
|
||||
if (m_document->hasPastableContentInClipboard()) {
|
||||
connect(&pasteAction, &QAction::triggered, m_document, &SkeletonDocument::paste);
|
||||
pasteAction.setEnabled(m_document->hasPastableContentInClipboard());
|
||||
contextMenu.addAction(&pasteAction);
|
||||
|
||||
contextMenu.addSeparator();
|
||||
}
|
||||
|
||||
QAction flipHorizontallyAction("H Flip", this);
|
||||
if (!m_rangeSelectionSet.empty() && !isSingleNodeSelected()) {
|
||||
connect(&flipHorizontallyAction, &QAction::triggered, this, &SkeletonGraphicsWidget::flipHorizontally);
|
||||
flipHorizontallyAction.setEnabled(!m_rangeSelectionSet.empty());
|
||||
contextMenu.addAction(&flipHorizontallyAction);
|
||||
}
|
||||
|
||||
QAction flipVerticallyAction("V Flip", this);
|
||||
if (!m_rangeSelectionSet.empty() && !isSingleNodeSelected()) {
|
||||
connect(&flipVerticallyAction, &QAction::triggered, this, &SkeletonGraphicsWidget::flipVertically);
|
||||
flipVerticallyAction.setEnabled(!m_rangeSelectionSet.empty());
|
||||
contextMenu.addAction(&flipVerticallyAction);
|
||||
|
||||
contextMenu.addSeparator();
|
||||
}
|
||||
|
||||
QAction selectAllAction("Select All", this);
|
||||
if (!nodeItemMap.empty()) {
|
||||
connect(&selectAllAction, &QAction::triggered, this, &SkeletonGraphicsWidget::selectAll);
|
||||
selectAllAction.setEnabled(!nodeItemMap.empty());
|
||||
contextMenu.addAction(&selectAllAction);
|
||||
}
|
||||
|
||||
QAction selectPartAllAction("Select Part", this);
|
||||
if (!nodeItemMap.empty()) {
|
||||
connect(&selectPartAllAction, &QAction::triggered, this, &SkeletonGraphicsWidget::selectPartAll);
|
||||
selectPartAllAction.setEnabled(!nodeItemMap.empty());
|
||||
contextMenu.addAction(&selectPartAllAction);
|
||||
}
|
||||
|
||||
QAction unselectAllAction("Unselect All", this);
|
||||
if (!m_rangeSelectionSet.empty()) {
|
||||
connect(&unselectAllAction, &QAction::triggered, this, &SkeletonGraphicsWidget::unselectAll);
|
||||
unselectAllAction.setEnabled(!m_rangeSelectionSet.empty());
|
||||
contextMenu.addAction(&unselectAllAction);
|
||||
}
|
||||
|
||||
contextMenu.addSeparator();
|
||||
|
||||
|
@ -1138,5 +1141,12 @@ void SkeletonGraphicsWidget::copy()
|
|||
clipboard->setText(snapshotXml);
|
||||
}
|
||||
|
||||
|
||||
bool SkeletonGraphicsWidget::isSingleNodeSelected()
|
||||
{
|
||||
if (m_rangeSelectionSet.size() != 1)
|
||||
return false;
|
||||
const auto &it = m_rangeSelectionSet.begin();
|
||||
QGraphicsItem *item = *it;
|
||||
return item->data(0) == "node";
|
||||
}
|
||||
|
||||
|
|
|
@ -324,6 +324,7 @@ private:
|
|||
void clearRangeSelection();
|
||||
void removeItem(QGraphicsItem *item);
|
||||
QVector2D centerOfNodeItemSet(const std::set<SkeletonGraphicsNodeItem *> &set);
|
||||
bool isSingleNodeSelected();
|
||||
private:
|
||||
QGraphicsPixmapItem *m_backgroundItem;
|
||||
const SkeletonDocument *m_document;
|
||||
|
|
Loading…
Reference in New Issue