-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmolecule.cpp
More file actions
115 lines (94 loc) · 2.72 KB
/
Copy pathmolecule.cpp
File metadata and controls
115 lines (94 loc) · 2.72 KB
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
#include "molecule.h"
#include "visualeditor.h"
#include "attribute.h"
/////////////////////////////////////////////////////////////////
Molecule::Molecule()
{
attributes = new AttributeList();
Attribute* newName = new Attribute(Attribute::STRING, "name");
newName->setData(std::string("New Molecule"));
connect(newName, SIGNAL(VisualDataUpdated()), this, SLOT(updateMoleculeLabel()));
Attribute* newColor = new Attribute(Attribute::COLOR, "color");
newColor->setData(Qt::green);
connect(newName, SIGNAL(VisualDataUpdated()), this, SLOT(updateMoleculeLabel()));
attributes->Push(newName);
attributes->Push(newColor);
}
Molecule::~Molecule()
{
}
//Name getter and setter
void Molecule::setName(std::string nameInput)
{
attributes->Get("name")->setData(std::string(nameInput));
}
std::string Molecule::getName()
{
return attributes->Get("name")->GetText();
}
QLabel* Molecule::DrawMolecule(QFrame* parent)
{
//load the image into a pixmap
QPixmap* pix = new QPixmap(150,100);
pix->fill(Qt::transparent);
QPainter painter;
painter.begin(pix);
painter.setBrush(getColor());
painter.drawEllipse(0,0,150,100);
painter.drawText(pix->rect(),Qt::AlignCenter, QString::fromStdString(getName()));
painter.end();
//make it viewable
QLabel* newLabel = new QLabel(parent);
newLabel->setPixmap(*pix);
newLabel->setAlignment(Qt::AlignCenter);
newLabel->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
newLabel->setAttribute(Qt::WA_DeleteOnClose);
newLabel->show();
delete pix;
label = newLabel;
return newLabel;
}
void Molecule::EditMolecule(QFrame* parent)
{
editor = new VisualEditor(parent, attributes);
}
void Molecule::updateMoleculeLabel()
{
//load the image into a pixmap
QPixmap* pix = new QPixmap(150,100);//":/snip1.png");
pix->fill(Qt::transparent);
QPainter painter;
painter.begin(pix);
painter.setBrush(getColor());
painter.drawEllipse(0,0,150,100);
painter.drawText(pix->rect(),Qt::AlignCenter, QString::fromStdString(getName()));
painter.end();
label->setPixmap(*pix);
label->show();
}
void Molecule::setColor(int input)
{
QColor currentColor;
//very temporary
if(input == 0)
{
currentColor = Qt::white;
}
else if(input == 1)
{
currentColor = Qt::red;
}
else if(input == 2)
{
currentColor = Qt::blue;
}
else
{
currentColor = Qt::darkGreen;
}
attributes->Get("color")->setData(currentColor);
}
QColor Molecule::getColor()
{
return attributes->Get("color")->GetColor();
}