-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathenvironmentscene.cpp
181 lines (155 loc) · 5.27 KB
/
environmentscene.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
* @file
* Environment Scene
*
* All REvoSim code is released under the GNU General Public License.
* See LICENSE.md files in the programme directory.
*
* All REvoSim code is Copyright 2018 by Mark Sutton, Russell Garwood,
* and Alan R.T. Spencer.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY.
*/
#include "environmentscene.h"
#include "simmanager.h"
#include <QGraphicsView>
#include <QDebug>
#include <QPointF>
#include "mainwindow.h"
/*********************************************
Subclassed QGraphicsScene object -
basically just has mouse handlers for main window
**********************************************/
EnvironmentScene::EnvironmentScene() : QGraphicsScene()
{
button=0;
grabbed=-1;
}
void EnvironmentScene::DoMouse(int x, int y)
{
if (button==1 && x>=0 && x<gridX && y>=0 && y<gridY)
{
if (grabbed==-1)
{
int closestFR = MainWin->FRW->findclosest(x,y,6);
if (closestFR>=0)
{
//grab one
grabbed=closestFR;
}
}
if (grabbed!=-1)
{
MainWin->FRW->FossilRecords[grabbed]->xpos=x;
MainWin->FRW->FossilRecords[grabbed]->ypos=y;
MainWin->FRW->RefreshMe();
}
}
}
void EnvironmentScene::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
//this gets string of calls if mouse button is held
{
QPointF position=event->scenePos();
int x,y;
x=(int)position.x();
y=(int)position.y();
if (button!=0) DoMouse(x,y);
return;
}
void EnvironmentScene::mousePressEvent(QGraphicsSceneMouseEvent * event )
{
QPointF position=event->scenePos();
int x,y;
x=(int)position.x();
y=(int)position.y();
button=0;
if (event->button()==Qt::LeftButton) button=1;
if (event->button()==Qt::RightButton) button=2;
DoMouse(x,y);
return;
}
void EnvironmentScene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{
QPointF position=event->scenePos();
int x,y;
grabbed=-1;
x=(int)position.x();
y=(int)position.y();
Q_UNUSED(x);
Q_UNUSED(y);
return;
}
void EnvironmentScene::DrawLocations(QList <FossilRecord *> frlist, bool show)
{
if (show)
{
QList <bool> selecteds = MainWin->FRW->GetSelections();
//add any new items needed
while (frlist.count()>HorizontalLineList.count())
{
QGraphicsLineItem *temp1=new QGraphicsLineItem;
HorizontalLineList.append(temp1);
QGraphicsLineItem *temp2=new QGraphicsLineItem;
VerticalLineList.append(temp2);
QGraphicsSimpleTextItem *temp3=new QGraphicsSimpleTextItem;
LabelsList.append(temp3);
addItem(temp1);
addItem(temp2);
addItem(temp3);
}
//now remove any spurious ones
while (frlist.count()<HorizontalLineList.count())
{
QGraphicsLineItem *r1=HorizontalLineList.takeLast();
QGraphicsLineItem *r2=VerticalLineList.takeLast();
QGraphicsSimpleTextItem *t=LabelsList.takeLast();
removeItem(r1);
removeItem(r2);
removeItem(t);
}
//now set them up
for (int i=0; i<frlist.count(); i++)
{
HorizontalLineList[i]->setLine(frlist[i]->xpos-.5,frlist[i]->ypos+.5, frlist[i]->xpos+1.5,frlist[i]->ypos+.5);
VerticalLineList[i]->setLine(frlist[i]->xpos+.5,frlist[i]->ypos-.5, frlist[i]->xpos+.5,frlist[i]->ypos+1.5);
HorizontalLineList[i]->setVisible(selecteds[i]);
VerticalLineList[i]->setVisible(selecteds[i]);
VerticalLineList[i]->setZValue(i+1);
HorizontalLineList[i]->setZValue(i+1);
LabelsList[i]->setText(frlist[i]->name);
LabelsList[i]->setX(frlist[i]->xpos+1);
LabelsList[i]->setY(frlist[i]->ypos-2);
LabelsList[i]->setFont(QFont("Arial",12));
LabelsList[i]->setScale(.15);
LabelsList[i]->setVisible(selecteds[i]);
LabelsList[i]->setZValue(i+1);
//sort out colours
int bright = (int)(environment[frlist[i]->xpos][frlist[i]->ypos][0])
+ (int)(environment[frlist[i]->xpos][frlist[i]->ypos][1])
+ (int)(environment[frlist[i]->xpos][frlist[i]->ypos][2]);
if (bright>250)
{
VerticalLineList[i]->setPen(QPen(Qt::black));
HorizontalLineList[i]->setPen(QPen(Qt::black));
LabelsList[i]->setBrush(QBrush(Qt::black));
}
else
{
VerticalLineList[i]->setPen(QPen(Qt::white));
HorizontalLineList[i]->setPen(QPen(Qt::white));
LabelsList[i]->setBrush(QBrush(Qt::white));
}
}
}
else
for (int i=0; i<VerticalLineList.count(); i++)
{
HorizontalLineList[i]->setVisible(false);
VerticalLineList[i]->setVisible(false);
LabelsList[i]->setVisible(false);
}
}