Set Elsewhen's here by tapping a city on the globe (#13438)
A city on this machine's zone becomes homeCity, the zone's own city clears it, and a city on another zone leaves it alone. Ported from omacom/elsewhen#5. Co-authored-by: Shawn Yeager <shawn@shawnyeager.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
5 files changed
+38
-3
No files matched your search
@@ -56,6 +56,7 @@ Item {
|
||||
signal offsetModeToggleRequested()
|
||||
// Only real selections: -1 means "no city" here but "home" in the list.
|
||||
signal citySelected(string label, string zone)
|
||||
signal cityTapped(string label, string zone)
|
||||
|
||||
// ---- data -------------------------------------------------------------
|
||||
property var land: [] // coastline rings, flat [lon,lat,...]
|
||||
@@ -96,7 +97,10 @@ Item {
|
||||
function pickAt(cx, cy) {
|
||||
var hit = hitAt(cx, cy)
|
||||
selectAt(hit)
|
||||
if (hit >= 0) flyTo(allCities[hit][2], allCities[hit][3])
|
||||
if (hit >= 0) {
|
||||
flyTo(allCities[hit][2], allCities[hit][3])
|
||||
cityTapped(allCities[hit][0], allCities[hit][1])
|
||||
}
|
||||
return hit
|
||||
}
|
||||
|
||||
|
||||
@@ -272,6 +272,18 @@ function labelForZoneId(id) {
|
||||
return String(id || "").split("/").pop().replace(/_/g, " ")
|
||||
}
|
||||
|
||||
// Tapping a city on this machine's clock makes it "here", and the zone's own
|
||||
// city clears the choice. The new homeCity setting, or null to leave it.
|
||||
function homeCityAfterTap(label, zoneId, homeOverride, localZone) {
|
||||
var name = String(label || "").trim()
|
||||
var local = String(localZone || "")
|
||||
if (name === "" || local === "" || String(zoneId || "") !== local) return null
|
||||
var override = String(homeOverride || "").trim()
|
||||
var zoneCity = labelForZoneId(local)
|
||||
if (name === (override === "" ? zoneCity : override)) return null
|
||||
return name === zoneCity ? "" : name
|
||||
}
|
||||
|
||||
function serializeZones(zones) {
|
||||
var parts = []
|
||||
for (var i = 0; i < zones.length; i++) {
|
||||
@@ -880,6 +892,7 @@ if (typeof module !== "undefined") {
|
||||
indexOfZone: indexOfZone,
|
||||
indexOfZoneKey: indexOfZoneKey,
|
||||
labelForZoneId: labelForZoneId,
|
||||
homeCityAfterTap: homeCityAfterTap,
|
||||
serializeZones: serializeZones,
|
||||
addZone: addZone,
|
||||
removeZoneAt: removeZoneAt,
|
||||
|
||||
@@ -118,6 +118,13 @@ Panel {
|
||||
else g.showHome()
|
||||
}
|
||||
|
||||
function claimHome(label, zone) {
|
||||
var stored = Model.homeCityAfterTap(label, zone, setting("homeCity", ""), localZone)
|
||||
if (stored === null) return
|
||||
persistSettings({ homeCity: stored })
|
||||
refreshFacts()
|
||||
}
|
||||
|
||||
function focusFromGlobe(label, zone) {
|
||||
var i = Model.indexOfZone(zones, label, zone)
|
||||
if (i >= 0) focusOn(i)
|
||||
@@ -876,6 +883,7 @@ Panel {
|
||||
item.exitRequested.connect(function() { root.setGlobeMode(false, false) })
|
||||
item.jumpDismissed.connect(function() { Qt.callLater(function() { keyCatcher.forceActiveFocus() }) })
|
||||
item.citySelected.connect(function(label, zone) { root.focusFromGlobe(label, zone) })
|
||||
item.cityTapped.connect(function(label, zone) { root.claimHome(label, zone) })
|
||||
// A cold start can finish loading after the mode switched on.
|
||||
if (root.globeMode) root.showFocusOnGlobe()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user