Commit 177785ca authored by Harald Sitter's avatar Harald Sitter 💎

introduce support for clickable area management

the last area in the array is a the click target when calling assert and
click on a needle. support this visually as it makes click needle building
less cumbersome as one gets away with one needle for two things

the clickable area is yellow now
parent 0a0cbad1
......@@ -29,6 +29,7 @@ Rectangle {
property ObjectModel model
property string type: "match"
property double match: 95
property bool clickArea: false
// This is the hard limit offset, we'll coerce the rect inside a given
// maxX and maxY with this offset. As a result this is effectively the
......@@ -102,7 +103,7 @@ Rectangle {
Rectangle {
id: fill
anchors.fill: parent
color: "steelblue"
color: clickArea ? "yellow" : "steelblue"
opacity: 0.6
}
......@@ -165,6 +166,11 @@ Rectangle {
onTriggered: { propDialog.open() }
}
MenuItem {
text: "mark as click target"
onTriggered: { model.setClickArea(rect) }
}
MenuItem {
text: "delete"
onTriggered: { model.removeObject(rect) }
......@@ -184,6 +190,8 @@ Rectangle {
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: {
if (mouse.button == Qt.RightButton) {
contextMenuComponent.x = mouse.x
contextMenuComponent.y = mouse.y
contextMenuComponent.open()
return;
}
......
......@@ -143,6 +143,7 @@ ApplicationWindow {
Layout.fillHeight: true
Item {
id: imageItem
// Scrollview doesn't care about scales, so to actually represent the scaled image we
// need to explicitly tell the view the dimensions
width: image.width * image.scale
......@@ -264,6 +265,10 @@ ApplicationWindow {
console.debug("area " + a.area[i])
var select = selector.createObject()
select.fromObject(a.area[i])
if (i == a.area.length - 1) { // last
select.clickArea = true
}
selectorModel.append(select)
}
......@@ -277,8 +282,20 @@ ApplicationWindow {
function toJSON() {
var areas = []
console.debug("model count " + selectorModel.count)
var last = null
for (var i = 0; i < selectorModel.count; ++i) {
areas.push(selectorModel.get(i).toObject())
var selector = selectorModel.get(i)
if (selector.clickArea) {
// openqa clicks the last area in the area array, so we'll
// remember the intended click area and push it onto the array
// once all others are in.
last = selector.toObject()
continue
}
areas.push(selector.toObject())
}
if (last !== null) {
areas.push(last)
}
var needle = {
area: areas,
......@@ -298,6 +315,19 @@ ApplicationWindow {
}
}
}
// Sets all but the passed selector as not clickable and the passed one
// as clickable.
function setClickArea(obj) {
for (var i = 0; i < selectorModel.count; ++i) {
var item = selectorModel.get(i)
if (item === obj) {
item.clickArea = true
} else {
item.clickArea = false
}
}
}
}
Repeater {
......
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