-
Notifications
You must be signed in to change notification settings - Fork 2
/
colourlinecontroller.cpp
108 lines (90 loc) · 2.61 KB
/
colourlinecontroller.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
/*
* File: colourlinecontroller.cpp
* Author: Rachel Bood 100088769
* Date: 2014 (?)
* Version: 1.3
*
* Purpose:
*
* Modification history:
* Jul 9, 2020 (IC V1.1)
* (a) BUTTON_STYLE moved to defuns.h.
* Oct 18, 2020 (JD V1.2)
* (a) Code tidying, spelling corrections, code simplifications.
* Nov 6, 2020 (JD V1.3)
* (a) Fix bug in setNodeOutlineColour() and setEdgeLineColour()
* which would clobber the old colour when getColor() was called
* and then cancelled, replacing the old colour with black.
*/
#include "colourlinecontroller.h"
#include <QColorDialog>
#include <QtCore>
ColourLineController::ColourLineController(Edge * anEdge, QPushButton * aButton)
{
edge = anEdge;
button = aButton;
if (button != nullptr || button != 0)
{
QColor colour = edge->getColour();
QString s("background: " + colour.name() + "; " + BUTTON_STYLE);
button->setStyleSheet(s);
connect(button, SIGNAL (clicked(bool)),
this, SLOT(setEdgeLineColour()));
connect(anEdge, SIGNAL(destroyed(QObject*)),
this, SLOT(deleteButton()));
connect(anEdge, SIGNAL(destroyed(QObject*)),
this, SLOT(deleteLater()));
}
}
ColourLineController::ColourLineController(Node * aNode, QPushButton * aButton)
{
node = aNode;
button = aButton;
if (button != nullptr || button != 0)
{
QColor colour = node->getLineColour();
QString s("background: " + colour.name() + "; " + BUTTON_STYLE);
button->setStyleSheet(s);
connect(button, SIGNAL (clicked(bool)),
this, SLOT(setNodeOutlineColour()));
connect(aNode, SIGNAL(destroyed(QObject*)),
this, SLOT(deleteButton()));
connect(aNode, SIGNAL(destroyed(QObject*)),
this, SLOT(deleteLater()));
}
}
// The original code always set the button stylesheet. Do we want that?
void
ColourLineController::setEdgeLineColour()
{
if (edge != 0 || edge != nullptr)
{
QColor colour = QColorDialog::getColor();
if (colour.isValid())
{
QString s("background: " + colour.name() + "; " + BUTTON_STYLE);
button->setStyleSheet(s);
edge->setColour(colour);
}
}
}
// The original code always set the button stylesheet. Do we want that?
void
ColourLineController::setNodeOutlineColour()
{
if (node != 0 || node != nullptr)
{
QColor colour = QColorDialog::getColor();
if (colour.isValid())
{
QString s("background: " + colour.name() + "; " + BUTTON_STYLE);
button->setStyleSheet(s);
node->setLineColour(colour);
}
}
}
void
ColourLineController::deleteButton()
{
delete button;
}