From f17f2a4f902fed525b6a47f4be68a2e10f51b227 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 10 Apr 2020 15:09:02 +0100 Subject: toggle show node labels from View menu (closes #62) --- src/gui/mainmenu.cpp | 6 ++++++ src/gui/mainmenu.h | 1 + src/gui/mainmenu.ui | 15 +++++++++++++++ src/gui/nodeitem.cpp | 8 +++++++- src/gui/tikzscene.cpp | 11 +++++++++++ src/gui/tikzscene.h | 4 ++++ 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index 35ab736..fe291a2 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -301,6 +301,12 @@ void MainMenu::on_actionZoom_Out_triggered() if (tikzit->activeWindow() != 0) tikzit->activeWindow()->tikzView()->zoomOut(); } +void MainMenu::on_actionShow_Node_Labels_triggered() +{ + tikzit->activeWindow()->tikzScene()->setDrawNodeLabels(ui.actionShow_Node_Labels->isChecked()); + tikzit->activeWindow()->tikzScene()->invalidate(); +} + void MainMenu::on_actionAbout_triggered() { QMessageBox::about(this, diff --git a/src/gui/mainmenu.h b/src/gui/mainmenu.h index 51d7d3c..220e3bd 100644 --- a/src/gui/mainmenu.h +++ b/src/gui/mainmenu.h @@ -78,6 +78,7 @@ public slots: // View void on_actionZoom_In_triggered(); void on_actionZoom_Out_triggered(); + void on_actionShow_Node_Labels_triggered(); // Help void on_actionAbout_triggered(); diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui index 692f82e..eb3bed3 100644 --- a/src/gui/mainmenu.ui +++ b/src/gui/mainmenu.ui @@ -92,6 +92,7 @@ + @@ -383,6 +384,20 @@ Ctrl+M + + + true + + + true + + + Show Node Labels + + + Ctrl+Shift+L + + diff --git a/src/gui/nodeitem.cpp b/src/gui/nodeitem.cpp index 82692f2..7ae4c4a 100644 --- a/src/gui/nodeitem.cpp +++ b/src/gui/nodeitem.cpp @@ -91,7 +91,13 @@ void NodeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge painter->drawPath(shape()); } - if (_node->label() != "") { + bool drawLabel = _node->label() != ""; + if (scene()) { + TikzScene *sc = static_cast(scene()); + drawLabel= drawLabel && sc->drawNodeLabels(); + } + + if (drawLabel) { QRectF rect = labelRect(); QPen pen(QColor(200,0,0,120)); QVector d; diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index 4577981..969a355 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -38,6 +38,7 @@ TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, { _modifyEdgeItem = nullptr; _edgeStartNodeItem = nullptr; + _drawNodeLabels = true; _drawEdgeItem = new QGraphicsLineItem(); _rubberBandItem = new QGraphicsRectItem(); _enabled = true; @@ -907,6 +908,16 @@ void TikzScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) } } +bool TikzScene::drawNodeLabels() const +{ + return _drawNodeLabels; +} + +void TikzScene::setDrawNodeLabels(bool drawNodeLabels) +{ + _drawNodeLabels = drawNodeLabels; +} + bool TikzScene::highlightTails() const { return _highlightTails && getSelectedNodes().isEmpty(); diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h index f8dc7ec..1edd50a 100644 --- a/src/gui/tikzscene.h +++ b/src/gui/tikzscene.h @@ -90,6 +90,9 @@ public: bool highlightHeads() const; bool highlightTails() const; + bool drawNodeLabels() const; + void setDrawNodeLabels(bool drawNodeLabels); + public slots: void graphReplaced(); void refreshZIndices(); @@ -115,6 +118,7 @@ private: bool _firstControlPoint; QPointF _mouseDownPos; bool _draggingNodes; + bool _drawNodeLabels; QMap _oldNodePositions; qreal _oldWeight; -- cgit v1.2.3