1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick.Shapes
Europe_generated {
id: map
property int containsMode: Shape.FillContains
property bool zoomedIn: false
signal zoomTo(Item child, string name, var childRect, var textRect)
property var lookupTable: {
"fi" : "Finland"
,"se" : "Sweden"
,"dk" : "Denmark"
,"gb-nir" : "Northern Ireland"
,"gb-main" : "Great Britain"
,"ie" : "Ireland"
,"nl" : "The Netherlands"
,"be" : "Belgium"
,"lu" : "Luxembourg"
,"de" : "Germany"
,"fr" : "France"
,"es" : "Spain"
,"pt" : "Portugal"
,"at" : "Austria"
,"it" : "Italy"
,"gr" : "Greece"
,"ee" : "Estonia"
,"lv" : "Latvia"
,"lt" : "Lithuania"
,"pl" : "Poland"
,"cz" : "Czechia"
,"sk" : "Slovakia"
,"si" : "Slovenia"
,"hu" : "Hungary"
,"ro" : "Romania"
,"bg" : "Bulgaria"
,"cy" : "Cyprus"
,"mt" : "Malta"
,"hr" : "Croatia"
,"ba" : "Bosnia and Herzegovina"
,"me" : "Montenegro"
,"rs" : "Serbia"
,"rs-km" : "Kosovo"
,"mk" : "North Makedonia"
,"al" : "Albania"
,"is" : "Iceland"
,"by" : "Belarus"
,"no" : "Norway"
,"ua" : "Ukraine"
,"ch" : "Switzerland"
,"md" : "Moldova"
,"ad" : "Andorra"
,"mc" : "Monaco"
,"li" : "Liechtenstein"
,"ru-kgd" : "Kaliningrad"
,"im" : "Isle of Man"
,"fo" : "Faroe Islands"
}
property var overrideRects: {
"fi": {x: 6616, y: 1996, width: 1920, height: 800, rotation: 65},
"no": {x: 4794, y: 1967, width: 3360, height: 680, rotation: -65},
"se": {x: 5739, y: 2560, width: 1920, height: 800, rotation: -80},
"it": {x: 5734, y: 6483, width: 1680, height: 440, rotation: 45},
"pt": {x: 3105, y: 6783, width: 960, height: 320, rotation: -70},
"md": {x: 8294, y: 5472, width: 480, height: 200, rotation: 45},
"rs": {x: 7233, y: 6168, width: 840, height: 320, rotation: 45},
"gb-main": {x: 3943, y: 3998, width: 1800, height: 800, rotation: 75},
"ba": {x: 6570, y: 6289, width: 1440, height: 200, rotation: 0},
"al": {x: 7312, y: 6830, width: 600, height: 200, rotation: 75},
"be": {x: 5237, y: 5126, width: 600, height: 200, rotation: 40},
"hr": {x: 6705, y: 6053, width: 840, height: 200, rotation: 0},
"at": {x: 6191, y: 5556, width: 1080, height: 440, rotation: -25},
"cy": {x: 9509, y: 7497, width: 480, height: 200, rotation: -35},
}
MouseArea {
id: mouseArea
anchors.fill: parent
property Item currentChild: null
property color prevColor
property color selectedColor: "#dbd6c8"
acceptedButtons: Qt.LeftButton
function traverseChildren(item, x, y) {
let p = item.mapFromItem(mouseArea, x, y)
if (item.objectName) {
if (item.contains(p))
return item;
}
for (var i = 0; i < item.children.length; i++) {
let r = traverseChildren(item.children[i], x, y)
if (r)
return r;
}
return null;
}
function findChild(x, y) {
return traverseChildren(map, x, y)
}
function findMatchingPath(node) {
if (!node)
return null
let pathName = "svg_path:" + node.objectName
for (var i = 0; i < node.data.length; i++) {
let child = node.data[i]
if (child.objectName === pathName)
return child
}
return null
}
onPressed: (mouse)=> {
if (!map.zoomedIn) {
currentChild = findChild(mouse.x, mouse.y)
let path = findMatchingPath(currentChild)
if (path) {
prevColor = path.fillColor
path.fillColor = selectedColor
currentChild.z = 1
}
}
}
onPositionChanged: (mouse)=> {
if (currentChild) {
let localPos = currentChild.mapFromItem(mouseArea, mouse.x, mouse.y)
let path = findMatchingPath(currentChild)
if (path) {
if (currentChild.contains(localPos)) {
path.fillColor = selectedColor
} else {
path.fillColor = prevColor
}
}
}
}
onReleased: (mouse) => {
if (map.zoomedIn) {
zoomTo(null, null, null, null)
zoomedIn = false
if (currentChild) {
let path = findMatchingPath(currentChild)
if (path)
path.fillColor = prevColor
currentChild.z = 0
currentChild = null
}
} else if (currentChild) {
let localPos = currentChild.mapFromItem(mouseArea, mouse.x, mouse.y)
if (currentChild.contains(localPos)) {
let br = currentChild.boundingRect
let rot = 0
let or = overrideRects[currentChild.objectName]
if (or) {
rot = or.rotation
let r = currentChild.mapToItem(map, or.x, or.y, or.width, or.height)
or = {x: r.x, y: r.y, width: r.width, height: r.height, rotation: rot}
}
let rect = currentChild.mapToItem(map, br)
zoomTo(currentChild, lookupTable[currentChild.objectName], rect, or )
zoomedIn = true
}
}
}
}
}
|