Add context menu
parent
cd6a973fe7
commit
b8e5d31169
16
src/main.cpp
16
src/main.cpp
|
@ -25,19 +25,19 @@ int main(int argc, char ** argv)
|
|||
// https://gist.github.com/QuantumCD/6245215
|
||||
qApp->setStyle(QStyleFactory::create("Fusion"));
|
||||
QPalette darkPalette;
|
||||
darkPalette.setColor(QPalette::Window, QColor(0x25,0x25,0x25));
|
||||
darkPalette.setColor(QPalette::WindowText, QColor(239,239,239));
|
||||
darkPalette.setColor(QPalette::Window, Theme::black);
|
||||
darkPalette.setColor(QPalette::WindowText, Theme::white);
|
||||
darkPalette.setColor(QPalette::Base, QColor(25,25,25));
|
||||
darkPalette.setColor(QPalette::AlternateBase, QColor(53,53,53));
|
||||
darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
|
||||
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
|
||||
darkPalette.setColor(QPalette::Text, Qt::white);
|
||||
darkPalette.setColor(QPalette::ToolTipBase, Theme::white);
|
||||
darkPalette.setColor(QPalette::ToolTipText, Theme::white);
|
||||
darkPalette.setColor(QPalette::Text, Theme::white);
|
||||
darkPalette.setColor(QPalette::Button, QColor(53,53,53));
|
||||
darkPalette.setColor(QPalette::ButtonText, QColor(239,239,239));
|
||||
darkPalette.setColor(QPalette::BrightText, Qt::red);
|
||||
darkPalette.setColor(QPalette::ButtonText, Theme::white);
|
||||
darkPalette.setColor(QPalette::BrightText, Theme::red);
|
||||
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
|
||||
darkPalette.setColor(QPalette::Highlight, Theme::white);
|
||||
darkPalette.setColor(QPalette::HighlightedText, Qt::white);
|
||||
darkPalette.setColor(QPalette::HighlightedText, Theme::black);
|
||||
qApp->setPalette(darkPalette);
|
||||
qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #fc6621; border: 1px solid white; }");
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QtGlobal>
|
||||
#include <algorithm>
|
||||
#include <QVector2D>
|
||||
#include <QMenu>
|
||||
#include "skeletongraphicswidget.h"
|
||||
#include "theme.h"
|
||||
#include "util.h"
|
||||
|
@ -55,6 +56,48 @@ SkeletonGraphicsWidget::SkeletonGraphicsWidget(const SkeletonDocument *document)
|
|||
scene()->setSceneRect(rect());
|
||||
|
||||
setMouseTracking(true);
|
||||
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &SkeletonGraphicsWidget::customContextMenuRequested, this, &SkeletonGraphicsWidget::showContextMenu);
|
||||
}
|
||||
|
||||
void SkeletonGraphicsWidget::showContextMenu(const QPoint &pos)
|
||||
{
|
||||
if (SkeletonDocumentEditMode::Add == m_document->editMode) {
|
||||
emit setEditMode(SkeletonDocumentEditMode::Select);
|
||||
return;
|
||||
}
|
||||
|
||||
if (SkeletonDocumentEditMode::Select != m_document->editMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
QMenu contextMenu(this);
|
||||
|
||||
QAction addAction("Add..", this);
|
||||
connect(&addAction, &QAction::triggered, [=]() {
|
||||
emit setEditMode(SkeletonDocumentEditMode::Add);
|
||||
});
|
||||
contextMenu.addAction(&addAction);
|
||||
contextMenu.addSeparator();
|
||||
|
||||
QAction deleteAction("Delete", this);
|
||||
connect(&deleteAction, &QAction::triggered, this, &SkeletonGraphicsWidget::deleteSelected);
|
||||
deleteAction.setEnabled(!m_rangeSelectionSet.empty());
|
||||
contextMenu.addAction(&deleteAction);
|
||||
contextMenu.addSeparator();
|
||||
|
||||
QAction selectAllAction("Select All", this);
|
||||
connect(&selectAllAction, &QAction::triggered, this, &SkeletonGraphicsWidget::selectAll);
|
||||
selectAllAction.setEnabled(!nodeItemMap.empty());
|
||||
contextMenu.addAction(&selectAllAction);
|
||||
|
||||
QAction unselectAllAction("Unselect All", this);
|
||||
connect(&unselectAllAction, &QAction::triggered, this, &SkeletonGraphicsWidget::unselectAll);
|
||||
unselectAllAction.setEnabled(!m_rangeSelectionSet.empty());
|
||||
contextMenu.addAction(&unselectAllAction);
|
||||
|
||||
contextMenu.exec(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void SkeletonGraphicsWidget::updateItems()
|
||||
|
@ -525,22 +568,28 @@ bool SkeletonGraphicsWidget::mouseDoubleClick(QMouseEvent *event)
|
|||
return false;
|
||||
}
|
||||
|
||||
void SkeletonGraphicsWidget::deleteSelected()
|
||||
{
|
||||
if (!m_rangeSelectionSet.empty()) {
|
||||
std::set<QUuid> nodeIdSet;
|
||||
std::set<QUuid> edgeIdSet;
|
||||
readSkeletonNodeAndEdgeIdSetFromRangeSelection(&nodeIdSet, &edgeIdSet);
|
||||
for (const auto &id: edgeIdSet) {
|
||||
emit removeEdge(id);
|
||||
}
|
||||
for (const auto &id: nodeIdSet) {
|
||||
emit removeNode(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SkeletonGraphicsWidget::keyPress(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Delete || event->key() ==Qt::Key_Backspace) {
|
||||
bool processed = false;
|
||||
if (!m_rangeSelectionSet.empty()) {
|
||||
std::set<QUuid> nodeIdSet;
|
||||
std::set<QUuid> edgeIdSet;
|
||||
readSkeletonNodeAndEdgeIdSetFromRangeSelection(&nodeIdSet, &edgeIdSet);
|
||||
for (const auto &id: edgeIdSet) {
|
||||
emit removeEdge(id);
|
||||
processed = true;
|
||||
}
|
||||
for (const auto &id: nodeIdSet) {
|
||||
emit removeNode(id);
|
||||
processed = true;
|
||||
}
|
||||
deleteSelected();
|
||||
processed = true;
|
||||
}
|
||||
if (processed) {
|
||||
emit groupOperationAdded();
|
||||
|
@ -854,3 +903,31 @@ void SkeletonGraphicsWidget::readSkeletonNodeAndEdgeIdSetFromRangeSelection(std:
|
|||
}
|
||||
}
|
||||
|
||||
void SkeletonGraphicsWidget::selectAll()
|
||||
{
|
||||
unselectAll();
|
||||
SkeletonProfile choosenProfile = SkeletonProfile::Main;
|
||||
if (m_hoveredNodeItem) {
|
||||
choosenProfile = m_hoveredNodeItem->profile();
|
||||
} else if (m_hoveredEdgeItem) {
|
||||
choosenProfile = m_hoveredEdgeItem->profile();
|
||||
}
|
||||
for (const auto &it: nodeItemMap) {
|
||||
SkeletonGraphicsNodeItem *item = SkeletonProfile::Main == choosenProfile ? it.second.first : it.second.second;
|
||||
checkSkeletonItem(item, true);
|
||||
m_rangeSelectionSet.insert(item);
|
||||
}
|
||||
for (const auto &it: edgeItemMap) {
|
||||
SkeletonGraphicsEdgeItem *item = SkeletonProfile::Main == choosenProfile ? it.second.first : it.second.second;
|
||||
checkSkeletonItem(item, true);
|
||||
m_rangeSelectionSet.insert(item);
|
||||
}
|
||||
}
|
||||
|
||||
void SkeletonGraphicsWidget::unselectAll()
|
||||
{
|
||||
for (const auto &item: m_rangeSelectionSet) {
|
||||
checkSkeletonItem(item, false);
|
||||
}
|
||||
m_rangeSelectionSet.clear();
|
||||
}
|
||||
|
|
|
@ -296,6 +296,10 @@ public slots:
|
|||
void editModeChanged();
|
||||
void updateCursor();
|
||||
void partVisibleStateChanged(QUuid partId);
|
||||
void showContextMenu(const QPoint &pos);
|
||||
void deleteSelected();
|
||||
void selectAll();
|
||||
void unselectAll();
|
||||
private slots:
|
||||
void turnaroundImageReady();
|
||||
private:
|
||||
|
|
|
@ -18,6 +18,7 @@ QColor Theme::red = QColor(0xfc, 0x66, 0x21);
|
|||
QColor Theme::green = QColor(0xaa, 0xeb, 0xc4);
|
||||
QColor Theme::blue = QColor(0x2a, 0x5a, 0xac);
|
||||
QColor Theme::white = QColor(0xf7, 0xd9, 0xc8);
|
||||
QColor Theme::black = QColor(0x25,0x25,0x25);
|
||||
float Theme::normalAlpha = 96.0 / 255;
|
||||
float Theme::branchAlpha = 64.0 / 255;
|
||||
float Theme::checkedAlpha = 1.0;
|
||||
|
|
|
@ -12,6 +12,7 @@ public:
|
|||
static QColor green;
|
||||
static QColor blue;
|
||||
static QColor white;
|
||||
static QColor black;
|
||||
static float normalAlpha;
|
||||
static float checkedAlpha;
|
||||
static float branchAlpha;
|
||||
|
|
Loading…
Reference in New Issue