Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
BalaSwecha
Density
Commits
30548a76
Commit
30548a76
authored
Oct 29, 2014
by
vikram
Browse files
drag and drop improvements
parent
20d6d2ad
Changes
8
Hide whitespace changes
Inline
Side-by-side
qml/view/DensityWin.qml
View file @
30548a76
...
...
@@ -3,8 +3,6 @@ import QtQuick.Controls 1.2
Item
{
id
:
densityWin
//width: densityWin.width
//height: densityWin.height
property
ObjImage
droppedObject
property
double
beakerPointHt
:
(
densityExperimentArea
.
height
/
1.20
)
/
50
property
double
liquidLevel
:
30
*
beakerPointHt
...
...
@@ -72,7 +70,7 @@ Item {
horizontalAlignment
:
TextEdit
.
AlignHCenter
verticalAlignment
:
TextEdit
.
AlignVCenter
font.pixelSize
:
parent
.
height
/
2
color
:
"
red
"
color
:
"
black
"
}
color
:
liquidList
.
getColor
(
index
,
"
black
"
)
...
...
@@ -110,10 +108,7 @@ Item {
height
:
(
4
*
densityWin
.
height
)
/
10
anchors
{
left
:
liquidTypeArea
.
left
//TODO:
top
:
liquidTypeArea
.
bottom
//leftMargin: 20
//bottomMargin: 20
}
}
...
...
@@ -134,7 +129,7 @@ Item {
}
radius
:
20
opacity
:
0.3
color
:
"
blue
"
color
:
"
#006aff
"
}
...
...
@@ -169,11 +164,8 @@ Item {
droppedObject
=
drag
.
source
droppedObject
.
changePosition
(
droppedObject
.
x
,
droppedObject
.
y
+
(
height
-
drag
.
y
-
getObjectBottomSinkLevel
(
liquidArea
.
density
)))
droppedObject
.
setState
(
"
inBeaker
"
)
droppedObject
.
disableParentDragging
()
//updateWaterLevel(drag.source.volume/10)
resultsGrid
.
addRow
(
droppedObject
.
imgName
,
liquidArea
.
type
,
liquidArea
.
density
,
droppedObject
.
getSinkStatus
(
liquidArea
.
density
))
setImageObject
(
droppedObject
)
}
onExited
:
{
drag
.
source
.
opacity
=
1
...
...
@@ -196,10 +188,12 @@ Item {
}
function
reset
()
{
droppedObject
=
null
showDensityExperiment
(
false
)
liquidArea
.
height
=
liquidLevel
formulaArea
.
reset
()
if
(
droppedObject
!==
null
)
droppedObject
.
opacity
=
0
droppedObject
=
null
}
function
getObjectBottomSinkLevel
(
liquidDensity
)
{
...
...
qml/view/LiquidTypeList.qml
View file @
30548a76
...
...
@@ -3,29 +3,29 @@ import QtQuick 2.0
Item
{
//density is in gm/ml
property
list
<
Rectangle
>
liquidTypeList
:
[
Rectangle
{
property
string
recName
:
"
w
ater
"
property
string
recColor
:
"
blue
"
property
double
recOpacity
:
0.
3
Rectangle
{
property
string
recName
:
"
W
ater
"
property
string
recColor
:
"
#006aff
"
property
double
recOpacity
:
0.
5
property
double
recDensity
:
1
},
Rectangle
{
property
string
recName
:
"
o
il
"
Rectangle
{
property
string
recName
:
"
O
il
"
property
string
recColor
:
"
yellow
"
property
double
recOpacity
:
1
property
double
recDensity
:
1.6
},
Rectangle
{
property
string
recName
:
"
p
etrol
"
property
string
recColor
:
"
#FFD700
"
property
double
recOpacity
:
0.7
Rectangle
{
property
string
recName
:
"
P
etrol
"
property
string
recColor
:
"
gold
"
property
double
recOpacity
:
1
property
double
recDensity
:
1
},
Rectangle
{
property
string
recName
:
"
Sea Water
"
property
string
recColor
:
"
violet
"
property
double
recOpacity
:
0.5
property
string
recColor
:
"
slateblue
"
property
double
recOpacity
:
1
property
double
recDensity
:
1.025
},
Rectangle
{
property
string
recName
:
"
Corn Syrup
"
property
string
recColor
:
"
green
"
property
double
recOpacity
:
0.8
property
string
recColor
:
"
teal
"
property
double
recOpacity
:
1
property
double
recDensity
:
1.33
}
]
...
...
qml/view/Main.qml
View file @
30548a76
import
QtQuick
2.2
Item
{
id
:
mainWin
width
:
900
height
:
700
property
ObjImage
activeImageObject
property
double
calculatedVolume
:
0.0
property
double
calculatedWeight
:
0.0
property
bool
dropCatched
:
false
Image
{
width
:
parent
.
width
...
...
@@ -15,71 +15,88 @@ Item {
source
:
"
images/background.jpeg
"
}
property
int
firstRowHeight
:
mainWin
.
height
/
15
property
int
secondRowHeight
:
(
mainWin
.
height
-
2
*
firstRowHeight
)
/
1.1
property
int
firstRowHeight
:
height
/
15
property
int
secondRowHeight
:
(
height
-
2
*
firstRowHeight
)
/
1.1
/*first row, only one column*/
ObjectCollectionWin
{
id
:
objectArea
height
:
firstRowHeight
width
:
mainWin
.
width
DropArea
{
id
:
mainWin
anchors
{
top
:
mainWin
.
top
left
:
mainWin
.
left
anchors
{
fill
:
parent
}
z
:
2
}
//invisible height after the object grid
Rectangle
{
id
:
emptyAreaBelowObjs
visible
:
false
height
:
firstRowHeight
width
:
mainWin
.
width
anchors
{
top
:
objectArea
.
bottom
left
:
objectArea
.
left
}
z
:
2
}
/*second row, first column*/
WeightWin
{
id
:
weightArea
height
:
secondRowHeight
width
:
mainWin
.
width
/
4
onDropped
:
{
if
(
dropCatched
===
false
&&
drag
.
source
!==
null
)
{
drag
.
source
.
opacity
=
0
reset
()
}
dropCatched
=
false
}
anchors
{
left
:
mainWin
.
left
top
:
emptyAreaBelowObjs
.
bottom
/*first row, only one column*/
ObjectCollectionWin
{
id
:
objectArea
height
:
firstRowHeight
width
:
mainWin
.
width
anchors
{
top
:
mainWin
.
top
left
:
mainWin
.
left
}
z
:
2
}
//invisible height after the object grid
Rectangle
{
id
:
emptyAreaBelowObjs
visible
:
false
height
:
firstRowHeight
width
:
mainWin
.
width
anchors
{
top
:
objectArea
.
bottom
left
:
objectArea
.
left
}
z
:
2
}
}
/*second row, first column*/
WeightWin
{
id
:
weightArea
height
:
secondRowHeight
width
:
mainWin
.
width
/
4
anchors
{
left
:
mainWin
.
left
top
:
emptyAreaBelowObjs
.
bottom
}
/*second row, second column*/
VolumeWin
{
id
:
volArea
height
:
secondRowHeight
width
:
mainWin
.
width
/
4
anchors
{
left
:
weightArea
.
right
top
:
weightArea
.
top
}
}
/*second row, third column*/
DensityWin
{
id
:
densityArea
height
:
secondRowHeight
width
:
mainWin
.
width
/
2
anchors
{
left
:
volArea
.
right
top
:
emptyAreaBelowObjs
.
bottom
/*second row, second column*/
VolumeWin
{
id
:
volArea
height
:
secondRowHeight
width
:
mainWin
.
width
/
4
anchors
{
left
:
weightArea
.
right
top
:
weightArea
.
top
}
}
/*second row, third column*/
DensityWin
{
id
:
densityArea
height
:
secondRowHeight
width
:
mainWin
.
width
/
2
anchors
{
left
:
volArea
.
right
top
:
emptyAreaBelowObjs
.
bottom
}
}
}
function
setImageObject
(
imageObj
)
{
dropCatched
=
true
if
(
activeImageObject
===
null
)
{
activeImageObject
=
imageObj
}
else
{
...
...
@@ -104,10 +121,14 @@ Item {
weightArea
.
reset
()
volArea
.
reset
()
densityArea
.
reset
()
if
(
activeImageObject
!==
null
)
{
activeImageObject
.
opacity
=
0
}
}
function
addValuesToFormula
()
{
densityArea
.
formulaWin
.
addValuesToFormula
()
if
(
calculatedVolume
>
0
&&
calculatedWeight
>
0
)
densityArea
.
formulaWin
.
addValuesToFormula
()
}
}
qml/view/ObjImage.qml
View file @
30548a76
import
QtQuick
2.0
Flickable
{
Item
{
id
:
objImgId
property
string
imgSource
property
string
imgName
property
string
backColor
property
double
weight
:
0.00
property
double
volume
:
0.00
property
double
density
:
0.00
property
int
parentX
:
0
property
int
parentY
:
0
z
:
10
state
:
"
inGrid
"
...
...
@@ -28,8 +25,7 @@ Flickable {
id
:
imageMouseArea
hoverEnabled
:
true
anchors.fill
:
imageArea
drag.target
:
(
objImgId
.
parent
.
dragEnabled
===
true
||
objImgId
.
state
!=
"
inGrid
"
)
?
imageArea
:
null
drag.target
:
imageArea
onEntered
:
{
imgText
.
textVisible
=
true
...
...
@@ -49,7 +45,19 @@ Flickable {
}
onClicked
:
{
}
onPressed
:
{
if
(
objImgId
.
state
==
"
inGrid
"
)
{
parentReset
()
var
newObj
=
Qt
.
createQmlObject
(
getQmlObjectString
(),
objImgId
.
parent
,
"
objImgId
"
);
drag
.
source
=
newObj
}
}
onReleased
:
{
imgText
.
textVisible
=
false
imageArea
.
Drag
.
drop
()
...
...
@@ -95,6 +103,9 @@ Flickable {
State
{
name
:
"
inVolume
"
},
State
{
name
:
"
inBeaker
"
},
State
{
name
:
"
none
"
}
...
...
@@ -103,12 +114,7 @@ Flickable {
function
setState
(
newState
)
{
state
=
newState
}
function
disableParentDragging
(){
this
.
parent
.
disableDragging
()
}
function
enableParentDragging
(){
this
.
parent
.
enableDragging
()
}
function
updaetVolume
(
volume
)
{
this
.
volume
=
volume
}
...
...
@@ -150,6 +156,27 @@ Flickable {
Behavior
on
y
{
PropertyAnimation
{
duration
:
400
;
}
}
function
getQmlObjectString
()
{
var
str
=
"
import QtQuick 2.0; ObjImage {
"
+
"
\n
"
+
"
width:
"
+
objImgId
.
width
+
"
\n
"
+
"
height:
"
+
objImgId
.
height
+
"
\n
"
+
"
imgSource :
\"
"
+
objImgId
.
imgSource
+
"
\"\n
"
+
"
imgName :
\"
"
+
objImgId
.
imgName
+
"
\"\n
"
+
"
weight :
"
+
objImgId
.
weight
+
"
\n
"
+
"
density:
"
+
objImgId
.
density
+
"
\n
"
+
"
opacity :
"
+
objImgId
.
opacity
+
"
\n
"
+
"
x :
"
+
x
+
"
\n
"
+
"
y :
"
+
y
+
"
\n
"
+
"
z :
"
+
z
+
"
\n
}
"
+
"
\n
"
return
str
}
function
parentReset
()
{
objImgId
.
parent
.
parentReset
()
}
function
reset
()
{
}
...
...
qml/view/ObjectCollectionWin.qml
View file @
30548a76
...
...
@@ -5,6 +5,7 @@ Item {
z
:
5
anchors
{
topMargin
:
objectCollWin
.
height
*
0.1
leftMargin
:
objectCollWin
.
width
*
0.1
}
ObjectList
{
...
...
@@ -13,7 +14,6 @@ Item {
Grid
{
id
:
objGrid
property
bool
dragEnabled
:
true
rows
:
1
columns
:
12
spacing
:
5
...
...
@@ -33,36 +33,17 @@ Item {
weight
:
objList
.
getWeight
(
index
,
"
00.00
"
)
density
:
objList
.
getDensity
(
index
,
"
00.00
"
)
opacity
:
objList
.
validIndex
(
index
)
?
1
:
0
z
:
5
}
}
function
enableDragging
()
{
objGrid
.
dragEnabled
=
true
}
function
disableDragging
()
{
objGrid
.
dragEnabled
=
false
function
parentReset
()
{
objGrid
.
parent
.
parentReset
()
}
}
DropArea
{
id
:
dropArea
anchors
{
fill
:
objectCollWin
}
onDropped
:
{
reset
(
drag
.
source
)
}
}
function
reset
(
imageObject
)
{
objGrid
.
enableDragging
()
imageObject
.
setState
(
"
inGrid
"
)
parent
.
reset
()
function
parentReset
()
{
reset
()
}
}
qml/view/ObjectList.qml
View file @
30548a76
...
...
@@ -4,21 +4,6 @@ import QtQuick 2.0
Item
{
property
list
<
Rectangle
>
objPropertiesList
:
[
//left empty cell for easy dragging of first object
Rectangle
{
property
string
imgSource
:
""
;
property
string
imgName
:
""
;
property
double
weight
:
00.00
property
double
density
:
1.00
property
int
horizontalSpacing
:
0
property
int
verticalSpacing
:
0
},
Rectangle
{
property
string
imgSource
:
"
images/iron-ball.png
"
;
property
string
imgName
:
"
Iron Ball
"
;
property
double
weight
:
100.00
property
double
density
:
7.86
property
int
horizontalSpacing
:
20
property
int
verticalSpacing
:
10
},
Rectangle
{
property
string
imgSource
:
"
images/golf-ball.png
"
;
property
string
imgName
:
"
Golf Ball
"
;
property
double
weight
:
40.96
...
...
@@ -85,6 +70,13 @@ import QtQuick 2.0
property
double
density
:
7.18
property
int
horizontalSpacing
:
10
property
int
verticalSpacing
:
5
},
Rectangle
{
property
string
imgSource
:
"
images/iron-ball.png
"
;
property
string
imgName
:
"
Iron Ball
"
;
property
double
weight
:
100.00
property
double
density
:
7.86
property
int
horizontalSpacing
:
20
property
int
verticalSpacing
:
10
}
]
...
...
qml/view/VolumeWin.qml
View file @
30548a76
...
...
@@ -41,7 +41,7 @@ Flickable {
width
:
cylinderImage
.
width
/
2.233
height
:
volumeWin
.
liquidLevel
opacity
:
0.3
color
:
"
blue
"
color
:
"
#006aff
"
z
:
2
anchors
{
bottom
:
baseArea
.
top
...
...
@@ -72,7 +72,7 @@ Flickable {
height
:
baseArea
.
height
/
2
font.pixelSize
:
height
/
1.8
textFormat
:
TextEdit
.
AutoText
color
:
"
red
"
color
:
"
yellow
"
text
:
droppedObject
==
null
?
"
00.00
"
:
droppedObject
.
getCalculatedVolume
()
horizontalAlignment
:
TextEdit
.
AlignHCenter
verticalAlignment
:
TextEdit
.
AlignVCenter
...
...
@@ -86,7 +86,13 @@ Flickable {
DropArea
{
anchors.fill
:
cylinderArea
id
:
dropArea
width
:
cylinderArea
.
width
height
:
cylinderArea
.
height
anchors
{
left
:
cylinderArea
.
left
bottom
:
cylinderArea
.
bottom
}
onEntered
:
{
drag
.
source
.
opacity
=
0.5
}
...
...
@@ -94,7 +100,6 @@ Flickable {
onDropped
:
{
droppedObject
=
drag
.
source
droppedObject
.
setState
(
"
inVolume
"
)
droppedObject
.
disableParentDragging
()
updateWaterLevel
(
droppedObject
.
getCalculatedVolume
()
/
10
)
droppedObject
.
changePosition
(
droppedObject
.
x
,
droppedObject
.
y
+
(
height
-
drag
.
y
-
getObjectBottomSinkLevel
(
1
)))
volumeText
.
text
=
droppedObject
.
getCalculatedVolume
()
...
...
@@ -128,8 +133,11 @@ Flickable {
}
function
reset
()
{
droppedObject
=
null
volumeText
.
text
=
"
00.00
"
increasePointHt
=
0
if
(
droppedObject
!==
null
)
{
droppedObject
.
opacity
=
0
}
droppedObject
=
null
}
}
qml/view/WeightWin.qml
View file @
30548a76
...
...
@@ -20,7 +20,7 @@ Item {
DropArea
{
id
:
dropArea
height
:
weightWin
.
height
-
weighingScaleArea
.
height
width
:
weighingScaleArea
.
width
-
20
width
:
weighingScaleArea
.
width
*
0.7
anchors
{
bottom
:
weighingScaleArea
.
top
...
...
@@ -32,10 +32,10 @@ Item {
droppedObject
=
drag
.
source
droppedObject
.
changePosition
(
droppedObject
.
x
,
droppedObject
.
y
+
(
height
-
drag
.
y
)
-
droppedObject
.
height
)
droppedObject
.
setState
(
"
inWeight
"
)
droppedObject
.
disableParentDragging
()
weightText
.
text
=
droppedObject
.
weight
setImageObject
(
droppedObject
)
setWeight
(
droppedObject
.
weight
)
addValuesToFormula
()
}
onEntered
:
{
...
...
@@ -73,7 +73,9 @@ Item {
}
function
reset
()
{
droppedObject
=
null
weightText
.
text
=
"
00.00
"
if
(
droppedObject
!==
null
)
droppedObject
.
opacity
=
0
droppedObject
=
null
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment