Commit 72489ad8 authored by rahulde's avatar rahulde

Build implemented for Digestive System

parent 12f9e29c
#include "imagemousearea.h"
#include <QImage>
ImageMouseArea::ImageMouseArea(QQuickItem *parent) : QQuickItem(parent)
{
ImageMouseArea::ImageMouseArea(QQuickItem *parent) : QQuickItem(parent) {
setAcceptedMouseButtons(Qt::LeftButton);
setClip(true);
}
bool ImageMouseArea::contains(const QPointF &point) const
{
bool ImageMouseArea::contains(const QPointF &point) const {
auto newString = m_imageName;
QImage image(newString.replace("file://", ""));
return image.rect().contains(point.toPoint()) && qAlpha(image.pixel(point.toPoint())) > 0;
}
void ImageMouseArea::mousePressEvent(QMouseEvent *event)
{
void ImageMouseArea::mousePressEvent(QMouseEvent *event) {
emit clicked();
event->accept();
}
......@@ -3,8 +3,7 @@
#include <QQuickItem>
class ImageMouseArea : public QQuickItem
{
class ImageMouseArea : public QQuickItem {
Q_OBJECT
Q_PROPERTY(QString imageName READ imageName WRITE setImageName)
......
......@@ -5,8 +5,7 @@
#include <QFile>
#include <QTextStream>
class JSONReader : public QObject
{
class JSONReader : public QObject {
Q_OBJECT
public:
explicit JSONReader(QObject *parent = 0);
......
......@@ -5,8 +5,7 @@
#include <QtQml>
#include <jsonreader.h>
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
qmlRegisterType<ImageMouseArea>("org.swecha.humanatlas", 1, 0, "ImageMouseArea");
......
......@@ -2,7 +2,7 @@ import QtQuick 2.0
import QtQuick.Layouts 1.1
import QtWebKit 3.0
import QtQuick.Controls 1.2
import QtQuick.LocalStorage 2.0
import JSONReader 1.0
import components 1.0 as Components
......@@ -12,41 +12,107 @@ RowLayout {
property string organSystem
property string currentOrgan
property int organMatches: 0
property variant coordinatesSheet: {"liver": {"x": 50, "y": 50, "z": 1},
"intestine": {"x": 50, "y": 300},
"stomach": {"x": 50, "y": 200}
}
property int numberOfOrgans: 0
property variant referenceCoordinates
property variant coordinatesSheet: {
"mouth": {
"coordinates": {
"x": 0,
"y": 0,
"z": 1
}
},
"oesophagus": {
"coordinates": {
"x": 0,
"y": 0,
"z": 1
}
},
"liver": {
"coordinates": {
"x": 0,
"y": 0,
"z": -1
}
},
"stomach": {
"coordinates": {
"x": 0,
"y": 0
}
},
"small_intestine": {
"coordinates": {
"x": 0,
"y": 0,
"z": 2
}
},
"large_intestine": {
"coordinates": {
"x": 0,
"y": 0,
"z": 1
}
},
"anus": {
"coordinates": {
"x": 0,
"y": 0,
"z": 1
}
},
"pancreas": {
"coordinates": {
"x": 0,
"y": 0,
"z": -1
}
},
"gall_bladder": {
"coordinates": {
"x": 0,
"y": 0,
"z": 1
}
}
}
anchors.fill: parent
JSONReader {
id: myFile
source: _organismsDataDirectory + "/" + root.organism + "/" + root.organSystem + "/" + "data.json"
onError: console.log(msg)
}
Rectangle {
width: parent.width/2
width: parent.width / 2
height: parent.height
anchors.left: parent.left
TableView {
id: organsTable
headerVisible: true
Text {
anchors.fill: parent
text: qsTr("Organs")
font.bold: true
font.pixelSize: 14
horizontalAlignment: Text.AlignHCenter
}
TableViewColumn {
role: "title" ;
title: "List of organs";
horizontalAlignment: Text.AlignHCenter;
}
Organs {
id:buildSpaceOrgansList
organism: root.organism
organSystem: root.organSystem
currentOrgan: root.currentOrgan
dragOrgans: true
coordinatesSheet: root.coordinatesSheet
}
}
Organs {
id: buildSpaceOrgansList
organism: root.organism
organSystem: root.organSystem
currentOrgan: root.currentOrgan
dragOrgans: true
coordinatesSheet: root.coordinatesSheet
}
Button {
text: "Back"
style: Components.ButtonStyle {}
style: Components.ButtonStyle {
}
width: 50
height: 50
x: 400
......@@ -58,28 +124,50 @@ RowLayout {
}
DropArea {
id:dropArea
width: parent.width/2
id: dropArea
width: parent.width / 2
height: parent.height
anchors.right: parent.right
property string droppedOrgan
Drag.active: true
Drag.active: false
property int droppedX
property int droppedY
Text {
id: dropAreaText
anchors.fill: parent
text: qsTr("Work" + " space")
text: qsTr("Work space")
font.bold: true
font.pixelSize: 14
horizontalAlignment: Text.AlignHCenter
}
onDropped: {
droppedOrgan = drag.source.organ
var droppedOrgan = drag.source.organ,
droppedX = drag.x,
droppedY = drag.y,
refX = referenceCoordinates[droppedOrgan].coordinates.x,
refY = referenceCoordinates[droppedOrgan].coordinates.y,
threshold = 10; // needs to be verified
if ((droppedX <= refX + threshold) && (droppedY <= refY + threshold) || (droppedX <= refX - threshold) && (droppedY <= refY - threshold))
organMatches++;
}
Image {
id: background
anchors {
left: parent.left
top: parent.top
leftMargin: -45
topMargin: -20
}
source: _organismsDataDirectory + "/" + root.organism + "/" + root.organSystem + "/background.png"
z: -2
}
Organs {
id:workSpaceOrgansList
id: workSpaceOrgansList
organism: root.organism
organSystem: root.organSystem
currentOrgan: root.currentOrgan
......@@ -87,37 +175,6 @@ RowLayout {
displayOrganLabel: true
opacity: 0
property string clickedOrgan
onClicked: {
clickedOrgan = organ
//TODO: Implement a better functionality to check whether the 2 organs matche
// Here we're just checking if the names of the two organs matche
if (dropArea.droppedOrgan == workSpaceOrgansList.clickedOrgan) {
root.organMatches +=1
}
}
}
Text {
text: " 1"
x: workSpaceOrgansList.coordinatesSheet["stomach"].x
y: workSpaceOrgansList.coordinatesSheet["stomach"].y
}
Text {
text: " 2"
x: workSpaceOrgansList.coordinatesSheet["liver"].x
y: workSpaceOrgansList.coordinatesSheet["liver"].y
z: workSpaceOrgansList.coordinatesSheet["liver"].z
}
Text {
text: " 3"
x: workSpaceOrgansList.coordinatesSheet["intestine"].x + 200
y:workSpaceOrgansList.coordinatesSheet["intestine"].y
z:1
}
Text {
......@@ -132,37 +189,32 @@ RowLayout {
Button {
id: feedbackButton
style: Components.ButtonStyle {}
style: Components.ButtonStyle {
}
text: "Feedback"
x: 130
y: 630
x: 0
y: 670
width: 100
height: 50
onClicked: {
if (feedbackButton.text == "Reset") {
stack.push(buildSelection)
}
else {
// 3 here represents the total number of organs
// We should be able to make this more generic
if (root.organMatches >= 3) {
stack.push(buildSelection)
} else {
if (root.organMatches >= numberOfOrgans) {
feedbackText.color = "green"
feedbackText.text += "Good job! You have learnt the "
+ root.organSystem + "!\n"
+ root.organSystem + "!"
dropAreaText.color = "green"
}
else {
} else {
workSpaceOrgansList.opacity = 1
buildSpaceOrgansList.opacity = 0.2
feedbackText.text += "Check what you got wrong" + "\n"
feedbackText.text += "Check what you got wrong"
dropAreaText.color = "red"
}
feedbackButton.text = "Reset"
dropArea.feedbackReset()
feedbackButton.text = "Reset"
dropArea.feedbackReset()
}
}
}
......@@ -170,10 +222,17 @@ RowLayout {
function feedbackReset() {
if (feedbackButton.text == "Reset") {
feedbackButton.enabled = true
}
else {
} else {
feedbackButton.enabled = false
}
}
}
}
Component.onCompleted: {
referenceCoordinates = JSON.parse(myFile.read());
for (var key in referenceCoordinates)
if(referenceCoordinates.hasOwnProperty(key))
numberOfOrgans++;
}
}
......@@ -15,6 +15,7 @@ Item {
//property variant organsList: [ "mouth","oesophagus"]
Image {
id: background
anchors {
left: parent.left
top: parent.top
......@@ -84,8 +85,6 @@ Item {
y: 0
onClicked: root.clicked(organ)
}
Components.OrganImage {
......@@ -216,35 +215,27 @@ Item {
Repeater{
model:getModel()
Image {
source: root.coordinatesSheet.lines[modelData + "Line"].source
x:root.coordinatesSheet.lines[modelData + "Line"].coordinates.x;
y:root.coordinatesSheet.lines[modelData + "Line"].coordinates.y
z:root.coordinatesSheet.lines[modelData + "Line"].coordinates.z
width:root.coordinatesSheet.lines[modelData + "Line"].width
visible: root.displayOrganLabel
Image {
Image {
source: root.coordinatesSheet.lines[modelData + "Line"].sourceArrow
x:root.coordinatesSheet.lines[modelData + "Line"].coordinatesArrow.x;
y:root.coordinatesSheet.lines[modelData + "Line"].coordinatesArrow.y
z:root.coordinatesSheet.lines[modelData + "Line"].coordinatesArrow.z
width:root.coordinatesSheet.lines[modelData + "Line"].widthArrow
visible: root.displayOrganLabel
}
}
function getModel(){
root.coordinatesSheet = JSON.parse(myFile.read());
return organsList
}
}
......@@ -259,7 +250,10 @@ Item {
}
Component.onCompleted: {
root.coordinatesSheet = JSON.parse(myFile.read());
if (dragOrgans) {
background.visible = false;
return;
}
mouthImage.x = root.coordinatesSheet.mouth.coordinates.x;
mouthImage.y = root.coordinatesSheet.mouth.coordinates.y;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment