Commit 72489ad8 authored by rahulde's avatar rahulde

Build implemented for Digestive System

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