-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlabelsizecontroller.cpp
137 lines (117 loc) · 3.6 KB
/
labelsizecontroller.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* File: labelsizecontroller.cpp
* Author: Rachel Bood
* Date: 2014/11/07 (?)
* Version: 1.5
*
* Purpose: Initializes a QGraphicsView that is used to house the QGraphicsScene
*
* Modification history:
* Nov 13, 2019 (JD, V1.1):
* (a) Renamed setWeightLabelSize() -> setEdgeLabelSize().
* (b) Removed apparently redundant "|| edge != 0" in setEdgeLabelSize().
* Nov 24, 2019 (JD, V1.2):
* (a) Fixed bugs in the (node and edge) constructors which
* incorrectly set the text size box value.
* (b) Minor formatting tweaks, comment additions.
* (c) Removed apparently redundant "|| box != 0" tests.
* Dec 1, 2019 (JD, V1.3)
* (a) Previously if there was no label, the label size in the "Edit
* Graph" tab would get sizes of 12, rather than whatever size
* was stored in the edge/node object. Henceforth recognize the
* size in that field even when there is currently no label.
* (Assumption: the label sizes have been set to meaningful
* values.)
* (b) Make the font sizes integers strictly larger than 0. See note
* below in LabelSizeController(edge, box) comment.
* June 9, 2020 (IC V1.4)
* (a) Changed QDoubleSpinBox to QSpinBox and Double to Int where applicable.
* Aug 21, 2020 (IC V1.5)
* (a) Use new name of the function which sets an edge label.
*/
#include "labelsizecontroller.h"
/*
* Name: LabelSizeController()
* Purpose:
* Arguments:
* Outputs:
* Modifies:
* Returns:
* Assumptions:
* Bugs:
* Notes: It would seem that, at least in Qt 5.9.8 on Linux,
* fractional parts of font sizes are ignored (or rounded down?)
* and setting a font size of 0 causes Qt to spit out a
* complaint. So make the font size spin boxes show no
* decimal places, and also start at 1 and go up from there.
* UPDATE: No longer doublespinboxes so no need to set decimals.
*/
LabelSizeController::LabelSizeController(Edge * anEdge, QSpinBox * aBox)
{
edge = anEdge;
box = aBox;
if (box != nullptr)
{
box->setMinimum(1);
box->setValue(edge->getLabelSize());
connect(box, SIGNAL(valueChanged(int)),
this, SLOT(setEdgeLabelSize(int)));
connect(anEdge, SIGNAL(destroyed(QObject*)),
this, SLOT(deletedSpinBox()));
connect(anEdge, SIGNAL(destroyed(QObject*)),
this, SLOT(deleteLater()));
}
}
LabelSizeController::LabelSizeController(Node * aNode, QSpinBox * aBox)
{
node = aNode;
box = aBox;
if (box != nullptr)
{
box->setMinimum(1);
box->setValue(node->getLabelSize());
connect(box, SIGNAL(valueChanged(int)),
this, SLOT(setNodeLabelSize(int)));
connect(aNode, SIGNAL(destroyed(QObject*)),
this, SLOT(deletedSpinBox()));
connect(aNode, SIGNAL(destroyed(QObject*)),
this, SLOT(deleteLater()));
}
}
/*
* Name: setNodeLabelSize()
* Purpose: Set the size of the node label.
* Arguments: The size, in points.
* Outputs: Nothing.
* Modifies: The node label size.
* Returns: Nothing.
* Assumptions: None.
* Bugs: ?
* Notes: Can node possibly be null?
*/
void LabelSizeController::setNodeLabelSize(int ptSize)
{
if (node != nullptr)
node->setNodeLabelSize(ptSize);
}
void LabelSizeController::deletedSpinBox()
{
delete box;
}
/*
* Name: setEdgeLabelSize()
* Purpose: Set the size of the edge label.
* Arguments: The size, in points.
* Outputs: Nothing.
* Modifies: The edge label size.
* Returns: Nothing.
* Assumptions: None.
* Bugs: ?
* Notes: Can edge possibly be null?
*/
void
LabelSizeController::setEdgeLabelSize(int ptSize)
{
if (edge != nullptr)
edge->setEdgeLabelSize(ptSize);
}