You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

259 lines
4.9 KiB

import QtQuick 2.0
import "qrc:/theme"
import "qrc:/const"
Item {
id: control
property bool centerButDown: centerBut.down
property bool leftButDown
property bool rightButDown
property bool topButDown
property bool bottomButDown
width: 2 * (Const.radiusLong + Const.margin)
height: 2 * (Const.radiusLong + Const.margin)
SegmentButton {
id: topBut
angle: 45
x: Const.margin
}
SegmentButton {
id: bottomBut
angle: -135
x: Const.margin
y: 2 * Const.margin
}
SegmentButton {
id: leftBut
angle: -45
y: Const.margin
}
SegmentButton {
id: rightBut
angle: 135
x: 2 * Const.margin
y: Const.margin
}
Rectangle {
color: "transparent"
anchors.fill: parent
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onPressed: {
if(beInCenter()) {
// inside
} else if (isOutside()) {
// outside
} else {
if(beInNorthOrWest()) {
if(beInNorthOrEast()) {
// top key
topButPressed()
} else {
// left key
leftButPressed()
}
} else {
if(beInNorthOrEast()) {
// right key
rightButPressed()
} else {
// bottom key
bottomButPressed()
}
}
}
}
onReleased: {
topButReleased()
leftButReleased()
rightButReleased()
bottomButReleased()
}
onMouseXChanged: {
if(!mouseArea.pressed) {
if(beInCenter()) {
// inside
topButExit()
leftButExit()
rightButExit()
bottomButExit()
} else if (isOutside()) {
// outside
topButExit()
leftButExit()
rightButExit()
bottomButExit()
} else {
if(beInNorthOrWest()) {
if(beInNorthOrEast()) {
// top key
topButHover()
leftButExit()
rightButExit()
bottomButExit()
} else {
// left key
leftButHover()
topButExit()
rightButExit()
bottomButExit()
}
} else {
if(beInNorthOrEast()) {
// right key
rightButHover()
topButExit()
leftButExit()
bottomButExit()
} else {
// bottom key
bottomButHover()
topButExit()
leftButExit()
rightButExit()
}
}
}
}
}
onExited: {
topButExit()
leftButExit()
rightButExit()
bottomButExit()
}
function beInNorthOrWest() {
var verDist = (Const.radiusLong + Const.margin) - mouseY
var horDist = mouseX - (Const.radiusLong + Const.margin)
var inNorthorWest = (verDist > horDist)
return inNorthorWest
}
function beInNorthOrEast() {
var verDist = (Const.radiusLong + Const.margin) - mouseY
var horDist = mouseX - (Const.radiusLong + Const.margin)
var inNorthorEast = (verDist > - horDist)
return inNorthorEast
}
function beInCenter() {
var verLength = (mouseY - (Const.radiusLong + Const.margin)) ** 2
var horLength = (mouseX - (Const.radiusLong + Const.margin)) ** 2
var inCenter = (verLength + horLength < ((Const.radiusShort + Const.margin) ** 2))
return inCenter
}
function isOutside() {
var verLength = (mouseY - (Const.radiusLong + Const.margin)) ** 2
var horLength = (mouseX - (Const.radiusLong + Const.margin)) ** 2
var isOut = (verLength + horLength > ((Const.radiusLong + Const.margin) ** 2))
return isOut
}
}
}
NeuButton {
id: centerBut
width: 2 * (Const.radiusShort - Const.margin)
height: 2 * (Const.radiusShort - Const.margin)
anchors.centerIn: parent
}
/***********************************/
function leftButPressed() {
leftButDown = true
leftBut.state = "Pressed"
leftBut.pressed()
}
function leftButReleased() {
leftButDown = false
leftBut.released()
leftBut.state = ""
}
function leftButHover() {
leftBut.state = "Hovering"
}
function leftButExit() {
leftBut.state = ""
}
/***********************************/
function rightButPressed() {
rightButDown = true
rightBut.state = "Pressed"
rightBut.pressed()
}
function rightButReleased() {
rightButDown = false
rightBut.released()
rightBut.state = ""
}
function rightButHover() {
rightBut.state = "Hovering"
}
function rightButExit() {
rightBut.state = ""
}
/***********************************/
function topButPressed() {
topButDown = true
topBut.state = "Pressed"
topBut.pressed()
}
function topButReleased() {
topButDown = false
topBut.released()
topBut.state = ""
}
function topButHover() {
topBut.state = "Hovering"
}
function topButExit() {
topBut.state = ""
}
/***********************************/
function bottomButPressed() {
bottomButDown = true
bottomBut.state = "Pressed"
bottomBut.pressed()
}
function bottomButReleased() {
bottomButDown = false
bottomBut.released()
bottomBut.state = ""
}
function bottomButHover() {
bottomBut.state = "Hovering"
}
function bottomButExit() {
bottomBut.state = ""
}
}