Skip to content

Commit c6f68a2

Browse files
committed
Fix GitHub Issue #206: An option to change the size of the arrows
- Toolbar now includes a spinner widget to set the arrow size
1 parent f0d1e90 commit c6f68a2

21 files changed

+225
-58
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ New features:
77

88
* Add German translations
99

10+
* Fix GitHub Issue #206: An option to change the size of the arrows
11+
- Toolbar now includes a spinner widget to set the arrow size
12+
1013
Bug fixes:
1114

1215
* Fix GitHub Issue #205: Click dragging from an existing node,

src/alz_serializer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ namespace MindMap {
4040

4141
const auto APPLICATION_VERSION = "version";
4242

43+
const auto ARROW_SIZE = "arrow-size";
44+
4345
const auto COLOR = "color";
4446

4547
const auto CORNER_RADIUS = "corner-radius";
@@ -446,6 +448,9 @@ std::unique_ptr<MindMapData> fromXml(QDomDocument document)
446448
readChildren(root, { { QString(DataKeywords::MindMap::GRAPH), [&data](const QDomElement & e) {
447449
readGraph(e, *data);
448450
} },
451+
{ QString(DataKeywords::MindMap::ARROW_SIZE), [&data](const QDomElement & e) {
452+
data->setArrowSize(readFirstTextNodeContent(e).toDouble() / SCALE);
453+
} },
449454
{ QString(DataKeywords::MindMap::COLOR), [&data](const QDomElement & e) {
450455
data->setBackgroundColor(readColorElement(e));
451456
} },
@@ -505,6 +510,10 @@ QDomDocument toXml(MindMapData & mindMapData)
505510

506511
writeColor(root, doc, mindMapData.gridColor(), DataKeywords::MindMap::GRID_COLOR);
507512

513+
auto arrowSizeElement = doc.createElement(DataKeywords::MindMap::ARROW_SIZE);
514+
arrowSizeElement.appendChild(doc.createTextNode(QString::number(static_cast<int>(mindMapData.arrowSize() * SCALE))));
515+
root.appendChild(arrowSizeElement);
516+
508517
auto edgeWidthElement = doc.createElement(DataKeywords::MindMap::EDGE_THICKNESS);
509518
edgeWidthElement.appendChild(doc.createTextNode(QString::number(static_cast<int>(mindMapData.edgeWidth() * SCALE))));
510519
root.appendChild(edgeWidthElement);

src/application.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ Application::Application(int & argc, char ** argv)
155155

156156
// Connect views and StateMachine together
157157
connect(this, &Application::actionTriggered, m_stateMachine.get(), &StateMachine::calculateState);
158-
connect(m_editorView, &EditorView::actionTriggered, [this](StateMachine::Action action) {
158+
connect(m_editorView, &EditorView::actionTriggered, m_stateMachine.get(), [this](StateMachine::Action action) {
159159
m_stateMachine->calculateState(action);
160160
});
161161
connect(m_mainWindow.get(), &MainWindow::actionTriggered, m_stateMachine.get(), &StateMachine::calculateState);
162162
connect(m_stateMachine.get(), &StateMachine::stateChanged, this, &Application::runState);
163163

164-
connect(m_editorData.get(), &EditorData::isModifiedChanged, [=](bool isModified) {
164+
connect(m_editorData.get(), &EditorData::isModifiedChanged, m_mainWindow.get(), [=](bool isModified) {
165165
m_mainWindow->enableSave(isModified || m_mediator->canBeSaved());
166166
});
167167

@@ -171,12 +171,13 @@ Application::Application(int & argc, char ** argv)
171171
connect(m_mediator.get(), &Mediator::pngExportFinished, m_pngExportDialog.get(), &PngExportDialog::finishExport);
172172
connect(m_mediator.get(), &Mediator::svgExportFinished, m_svgExportDialog.get(), &SvgExportDialog::finishExport);
173173

174+
connect(m_mainWindow.get(), &MainWindow::arrowSizeChanged, m_mediator.get(), &Mediator::setArrowSize);
174175
connect(m_mainWindow.get(), &MainWindow::cornerRadiusChanged, m_mediator.get(), &Mediator::setCornerRadius);
175176
connect(m_mainWindow.get(), &MainWindow::edgeWidthChanged, m_mediator.get(), &Mediator::setEdgeWidth);
176177
connect(m_mainWindow.get(), &MainWindow::fontChanged, m_mediator.get(), &Mediator::changeFont);
177178
connect(m_mainWindow.get(), &MainWindow::textSizeChanged, m_mediator.get(), &Mediator::setTextSize);
178179
connect(m_mainWindow.get(), &MainWindow::gridSizeChanged, m_mediator.get(), &Mediator::setGridSize);
179-
connect(m_mainWindow.get(), &MainWindow::gridVisibleChanged, [this](int state) {
180+
connect(m_mainWindow.get(), &MainWindow::gridVisibleChanged, m_editorView, [this](int state) {
180181
bool visible = state == Qt::Checked;
181182
m_editorView->setGridVisible(visible);
182183
});

src/constants.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ static constexpr auto TRANSLATIONS_RESOURCE_BASE = ":/translations/heimer_";
5151

5252
namespace Edge {
5353

54-
static const double ARROW_LENGTH = 10;
54+
static const double ARROW_SIZE_STEP = 5;
5555

5656
static const double ARROW_OPENING = 150;
5757

5858
static const double CORNER_RADIUS_SCALE = 0.3;
5959

6060
static const QVector DASH_PATTERN { qreal(5), qreal(5) };
6161

62+
static const double DEFAULT_ARROW_SIZE = 10;
63+
6264
static const QColor DOT_COLOR { 255, 0, 0, 192 };
6365

6466
static const int DOT_DURATION = 2000;
@@ -69,11 +71,15 @@ static const QColor LABEL_COLOR { 0xff, 0xee, 0xaa };
6971

7072
static const int LABEL_DURATION = 2000;
7173

72-
static const double MIN_SIZE = 0.1;
74+
static const double MIN_ARROW_SIZE = 5;
75+
76+
static const double MAX_ARROW_SIZE = 99;
77+
78+
static const double MIN_EDGE_WIDTH = 0.1;
7379

74-
static const double MAX_SIZE = 5.0;
80+
static const double MAX_EDGE_WIDTH = 5.0;
7581

76-
static const double STEP = 0.1;
82+
static const double EDGE_WIDTH_STEP = 0.1;
7783

7884
static const int TEXT_EDIT_ANIMATION_DURATION = 150;
7985

src/edge.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Edge::Edge(NodeP sourceNode, NodeP targetNode, bool enableAnimations, bool enabl
6969
m_label->setZValue(static_cast<int>(Layers::EdgeLabel));
7070
m_label->setBackgroundColor(Constants::Edge::LABEL_COLOR);
7171

72-
connect(m_label, &TextEdit::textChanged, [=](const QString & text) {
72+
connect(m_label, &TextEdit::textChanged, this, [=](const QString & text) {
7373
updateLabel();
7474
m_text = text;
7575
});
@@ -79,7 +79,7 @@ Edge::Edge(NodeP sourceNode, NodeP targetNode, bool enableAnimations, bool enabl
7979
m_labelVisibilityTimer.setSingleShot(true);
8080
m_labelVisibilityTimer.setInterval(Constants::Edge::LABEL_DURATION);
8181

82-
connect(&m_labelVisibilityTimer, &QTimer::timeout, [=] {
82+
connect(&m_labelVisibilityTimer, &QTimer::timeout, this, [=] {
8383
setLabelVisible(false);
8484
});
8585
}
@@ -120,7 +120,7 @@ void Edge::hoverLeaveEvent(QGraphicsSceneHoverEvent * event)
120120

121121
QPen Edge::buildPen(bool ignoreDashSetting) const
122122
{
123-
QPen pen { QBrush { QColor { m_color.red(), m_color.green(), m_color.blue() } }, m_width };
123+
QPen pen { QBrush { QColor { m_color.red(), m_color.green(), m_color.blue() } }, m_edgeWidth };
124124
pen.setCapStyle(Qt::PenCapStyle::RoundCap);
125125
if (!ignoreDashSetting && m_dashedLine) {
126126
pen.setDashPattern(Constants::Edge::DASH_PATTERN);
@@ -199,9 +199,9 @@ void Edge::setLabelVisible(bool visible, EdgeTextEdit::VisibilityChangeReason vc
199199
}
200200
}
201201

202-
void Edge::setWidth(double width)
202+
void Edge::setEdgeWidth(double edgeWidth)
203203
{
204-
m_width = width;
204+
m_edgeWidth = edgeWidth;
205205

206206
updateLine();
207207
}
@@ -216,6 +216,13 @@ void Edge::setArrowMode(ArrowMode arrowMode)
216216
}
217217
}
218218

219+
void Edge::setArrowSize(double arrowSize)
220+
{
221+
m_arrowSize = arrowSize;
222+
223+
updateLine();
224+
}
225+
219226
void Edge::setColor(const QColor & color)
220227
{
221228
m_color = color;
@@ -299,10 +306,10 @@ void Edge::updateArrowhead()
299306
case ArrowMode::Single: {
300307
lineL0.setP1(point0);
301308
const auto angleL = qDegreesToRadians(angle0 + Constants::Edge::ARROW_OPENING);
302-
lineL0.setP2(point0 + QPointF(std::cos(angleL), std::sin(angleL)) * Constants::Edge::ARROW_LENGTH);
309+
lineL0.setP2(point0 + QPointF(std::cos(angleL), std::sin(angleL)) * m_arrowSize);
303310
lineR0.setP1(point0);
304311
const auto angleR = qDegreesToRadians(angle0 - Constants::Edge::ARROW_OPENING);
305-
lineR0.setP2(point0 + QPointF(std::cos(angleR), std::sin(angleR)) * Constants::Edge::ARROW_LENGTH);
312+
lineR0.setP2(point0 + QPointF(std::cos(angleR), std::sin(angleR)) * m_arrowSize);
306313
m_arrowheadL0->setLine(lineL0);
307314
m_arrowheadR0->setLine(lineR0);
308315
m_arrowheadL0->show();
@@ -314,20 +321,20 @@ void Edge::updateArrowhead()
314321
case ArrowMode::Double: {
315322
lineL0.setP1(point0);
316323
const auto angleL0 = qDegreesToRadians(angle0 + Constants::Edge::ARROW_OPENING);
317-
lineL0.setP2(point0 + QPointF(std::cos(angleL0), std::sin(angleL0)) * Constants::Edge::ARROW_LENGTH);
324+
lineL0.setP2(point0 + QPointF(std::cos(angleL0), std::sin(angleL0)) * m_arrowSize);
318325
lineR0.setP1(point0);
319326
const auto angleR0 = qDegreesToRadians(angle0 - Constants::Edge::ARROW_OPENING);
320-
lineR0.setP2(point0 + QPointF(std::cos(angleR0), std::sin(angleR0)) * Constants::Edge::ARROW_LENGTH);
327+
lineR0.setP2(point0 + QPointF(std::cos(angleR0), std::sin(angleR0)) * m_arrowSize);
321328
lineL1.setP1(point1);
322329
m_arrowheadL0->setLine(lineL0);
323330
m_arrowheadR0->setLine(lineR0);
324331
m_arrowheadL0->show();
325332
m_arrowheadR0->show();
326333
const auto angleL1 = qDegreesToRadians(angle1 + Constants::Edge::ARROW_OPENING);
327-
lineL1.setP2(point1 + QPointF(std::cos(angleL1), std::sin(angleL1)) * Constants::Edge::ARROW_LENGTH);
334+
lineL1.setP2(point1 + QPointF(std::cos(angleL1), std::sin(angleL1)) * m_arrowSize);
328335
lineR1.setP1(point1);
329336
const auto angleR1 = qDegreesToRadians(angle1 - Constants::Edge::ARROW_OPENING);
330-
lineR1.setP2(point1 + QPointF(std::cos(angleR1), std::sin(angleR1)) * Constants::Edge::ARROW_LENGTH);
337+
lineR1.setP2(point1 + QPointF(std::cos(angleR1), std::sin(angleR1)) * m_arrowSize);
331338
m_arrowheadL1->setLine(lineL1);
332339
m_arrowheadR1->setLine(lineR1);
333340
m_arrowheadL1->show();
@@ -424,7 +431,7 @@ void Edge::updateLine()
424431
setLine(QLineF(
425432
p1 + (nearestPoints.first.isCorner ? Constants::Edge::CORNER_RADIUS_SCALE * (direction1 * static_cast<float>(sourceNode().cornerRadius())).toPointF() : QPointF { 0, 0 }),
426433
p2 + (nearestPoints.second.isCorner ? Constants::Edge::CORNER_RADIUS_SCALE * (direction2 * static_cast<float>(targetNode().cornerRadius())).toPointF() : QPointF { 0, 0 }) - //
427-
(direction2 * static_cast<float>(m_width)).toPointF() * Constants::Edge::WIDTH_SCALE));
434+
(direction2 * static_cast<float>(m_edgeWidth)).toPointF() * Constants::Edge::WIDTH_SCALE));
428435

429436
updateDots();
430437
updateLabel(LabelUpdateReason::EdgeGeometryChanged);

src/edge.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <map>
2323
#include <memory>
2424

25+
#include "constants.hpp"
2526
#include "edge_point.hpp"
2627
#include "edge_text_edit.hpp"
2728
#include "types.hpp"
@@ -90,11 +91,13 @@ public slots:
9091

9192
void setArrowMode(ArrowMode arrowMode);
9293

94+
void setArrowSize(double arrowSize);
95+
9396
void setColor(const QColor & color);
9497

9598
void setDashedLine(bool enable);
9699

97-
void setWidth(double width);
100+
void setEdgeWidth(double edgeWidth);
98101

99102
void setText(const QString & text);
100103

@@ -137,7 +140,9 @@ public slots:
137140

138141
QString m_text;
139142

140-
double m_width = 2;
143+
double m_arrowSize = Constants::Edge::DEFAULT_ARROW_SIZE;
144+
145+
double m_edgeWidth = Constants::MindMap::DEFAULT_EDGE_WIDTH;
141146

142147
int m_textSize = 11; // Not sure if we should set yet another default value here..
143148

src/editor_view.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,9 @@ void EditorView::showDummyDragEdge(bool show)
408408
}
409409
}
410410

411+
m_dummyDragEdge->setArrowSize(m_arrowSize);
411412
m_dummyDragEdge->setColor(m_edgeColor);
412-
m_dummyDragEdge->setWidth(m_edgeWidth);
413+
m_dummyDragEdge->setEdgeWidth(m_edgeWidth);
413414
m_dummyDragEdge->setVisible(show);
414415
}
415416

@@ -456,38 +457,43 @@ void EditorView::saveZoom()
456457
m_savedZoom = { scene()->sceneRect(), mapToScene(viewport()->rect().center()), m_scale };
457458
}
458459

460+
void EditorView::setArrowSize(double arrowSize)
461+
{
462+
m_arrowSize = arrowSize;
463+
}
464+
459465
void EditorView::setCornerRadius(int cornerRadius)
460466
{
461467
m_cornerRadius = cornerRadius;
462468
}
463469

464-
void EditorView::setGridSize(int size)
470+
void EditorView::setEdgeColor(const QColor & edgeColor)
465471
{
466-
m_grid.setSize(size);
467-
if (scene())
468-
scene()->update();
472+
m_edgeColor = edgeColor;
469473
}
470474

471-
void EditorView::setGridVisible(bool visible)
475+
void EditorView::setEdgeWidth(double edgeWidth)
472476
{
473-
m_gridVisible = visible;
474-
if (scene())
475-
scene()->update();
477+
m_edgeWidth = edgeWidth;
476478
}
477479

478-
void EditorView::setEdgeColor(const QColor & edgeColor)
480+
void EditorView::setGridSize(int size)
479481
{
480-
m_edgeColor = edgeColor;
482+
m_grid.setSize(size);
483+
if (scene())
484+
scene()->update();
481485
}
482486

483487
void EditorView::setGridColor(const QColor & gridColor)
484488
{
485489
m_mediator.mindMapData()->setGridColor(gridColor);
486490
}
487491

488-
void EditorView::setEdgeWidth(double edgeWidth)
492+
void EditorView::setGridVisible(bool visible)
489493
{
490-
m_edgeWidth = edgeWidth;
494+
m_gridVisible = visible;
495+
if (scene())
496+
scene()->update();
491497
}
492498

493499
void EditorView::wheelEvent(QWheelEvent * event)

src/editor_view.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef EDITOR_VIEW_HPP
1717
#define EDITOR_VIEW_HPP
1818

19+
#include "constants.hpp"
1920
#include "grid.hpp"
2021
#include "main_context_menu.hpp"
2122
#include "state_machine.hpp"
@@ -67,15 +68,16 @@ class EditorView : public QGraphicsView
6768
QString dropFile() const;
6869

6970
public slots:
71+
void setArrowSize(double arrowSize);
7072

7173
void setCornerRadius(int cornerRadius);
7274

7375
void setEdgeColor(const QColor & edgeColor);
7476

75-
void setGridColor(const QColor & edgeColor);
76-
7777
void setEdgeWidth(double edgeWidth);
7878

79+
void setGridColor(const QColor & edgeColor);
80+
7981
void setGridSize(int size);
8082

8183
void setGridVisible(bool visible);
@@ -169,8 +171,11 @@ public slots:
169171

170172
int m_cornerRadius = 0;
171173

174+
// Arrow size for the dummy drag edge
175+
double m_arrowSize = Constants::Edge::DEFAULT_ARROW_SIZE;
176+
172177
// Width for the dummy drag edge
173-
double m_edgeWidth = 1.5;
178+
double m_edgeWidth = Constants::MindMap::DEFAULT_EDGE_WIDTH;
174179

175180
QColor m_edgeColor;
176181

src/main_window.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ void MainWindow::connectToolBar()
127127
{
128128
connect(m_toolBar, &ToolBar::gridVisibleChanged, this, &MainWindow::gridVisibleChanged);
129129

130+
connect(m_toolBar, &ToolBar::arrowSizeChanged, this, &MainWindow::arrowSizeChanged);
131+
130132
connect(m_toolBar, &ToolBar::cornerRadiusChanged, this, &MainWindow::cornerRadiusChanged);
131133

132134
connect(m_toolBar, &ToolBar::edgeWidthChanged, this, &MainWindow::edgeWidthChanged);
@@ -491,6 +493,11 @@ void MainWindow::enableWidgetSignals(bool enable)
491493
m_toolBar->enableWidgetSignals(enable);
492494
}
493495

496+
void MainWindow::setArrowSize(double value)
497+
{
498+
m_toolBar->setArrowSize(value);
499+
}
500+
494501
void MainWindow::setCornerRadius(int value)
495502
{
496503
m_toolBar->setCornerRadius(value);

src/main_window.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public slots:
9191

9292
void enableSave(bool enable);
9393

94+
void setArrowSize(double value);
95+
9496
void setCornerRadius(int value);
9597

9698
void setEdgeWidth(double value);
@@ -106,6 +108,8 @@ public slots:
106108

107109
void actionTriggered(StateMachine::Action action);
108110

111+
void arrowSizeChanged(double arrowSize);
112+
109113
void cornerRadiusChanged(int size);
110114

111115
void edgeWidthChanged(double width);

0 commit comments

Comments
 (0)