diff --git a/src/main.cpp b/src/main.cpp index 5e04e35e..aa6fc1d3 100644 --- a/src/main.cpp +++ b/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; }"); diff --git a/src/skeletongraphicswidget.cpp b/src/skeletongraphicswidget.cpp index 83481928..f9f4ef64 100644 --- a/src/skeletongraphicswidget.cpp +++ b/src/skeletongraphicswidget.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #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 nodeIdSet; + std::set 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 nodeIdSet; - std::set 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(); +} diff --git a/src/skeletongraphicswidget.h b/src/skeletongraphicswidget.h index 7096e3ae..04ebd4f0 100644 --- a/src/skeletongraphicswidget.h +++ b/src/skeletongraphicswidget.h @@ -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: diff --git a/src/theme.cpp b/src/theme.cpp index c46f6b7e..112e1ca7 100644 --- a/src/theme.cpp +++ b/src/theme.cpp @@ -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; diff --git a/src/theme.h b/src/theme.h index 35dc9092..4a762ed9 100644 --- a/src/theme.h +++ b/src/theme.h @@ -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;