- engine_doc_click, engine_doc_pump e engine_doc_deliver non avevano catch_unwind: un panic Rust attraverso il confine C non e' un errore, e' un comportamento indefinito, e sul telefono l'app sparisce. Ora sono protetti e il messaggio finisce su stderr - insertAdjacentHTML poteva chiedere un indice oltre la lunghezza del padre e panicare: l'inserimento ora si ferma alla lunghezza corrente - la pagina di prova del telefono e' demo.html (la stessa del desktop), spedita nel pacchetto e caricata dal guscio; via la vecchia demo scritta dentro la QML
327 lines
12 KiB
QML
327 lines
12 KiB
QML
import QtQuick 2.2
|
|
import Sailfish.Silica 1.0
|
|
import Harbour.Mosaic 1.0
|
|
|
|
Page {
|
|
id: page
|
|
|
|
/* Lo zoom vive nelle impostazioni: il pinch lo cambia e il valore
|
|
* sopravvive alla chiusura. Default 2.0 perché a scala 1 un testo da 16px
|
|
* su uno schermo da 1080 px è illeggibile. */
|
|
property real zoom: appSettings ? appSettings.zoom : 2.0
|
|
property real pinchStartZoom: 2.0
|
|
/* Zoom mostrato durante il pinch: scala l'immagine già pronta, senza
|
|
* ri-rasterizzare a ogni evento (un render costa ~40 ms sul telefono). */
|
|
property real liveZoom: zoom
|
|
|
|
onZoomChanged: if (appSettings) appSettings.zoom = zoom
|
|
|
|
property string demoCss:
|
|
"@font-face { font-family: SerifMosaic; src: url(fonts/DejaVuSerif.ttf) }" +
|
|
"body { background: #dcdcdc; }" +
|
|
"h1 { color: #000080; }" +
|
|
"h2 { color: #000000; font-size: 20px; }" +
|
|
"p { color: #202020; font-size: 15px; }" +
|
|
"table { width: 100%; }" +
|
|
"th, td { border: 1px solid #808080; padding: 4px; font-size: 13px }" +
|
|
"th { background: #e8e8d8 }" +
|
|
".scheda { background: #f4f4e8; border: 1px solid #808080; padding: 4px; font-size: 13px }"
|
|
|
|
PageHeader {
|
|
id: header
|
|
title: qsTr("Mosaic")
|
|
}
|
|
|
|
/* Flickable semplice: con SilicaFlickable e un menu in pagina i tocchi non
|
|
* arrivavano ai controlli. Il percorso che funziona è questo. */
|
|
Flickable {
|
|
id: flick
|
|
anchors.top: avvisoRete.visible ? avvisoRete.bottom : header.bottom
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.bottom: statusBar.top
|
|
contentWidth: width
|
|
contentHeight: Math.max(view.contentHeight, height)
|
|
clip: true
|
|
boundsBehavior: Flickable.StopAtBounds
|
|
|
|
Item {
|
|
id: content
|
|
width: flick.width
|
|
height: view.contentHeight > 0 ? view.contentHeight : flick.height
|
|
|
|
transform: Scale {
|
|
origin.x: 0
|
|
origin.y: 0
|
|
xScale: page.liveZoom / page.zoom
|
|
yScale: page.liveZoom / page.zoom
|
|
}
|
|
|
|
EngineView {
|
|
id: view
|
|
width: content.width
|
|
height: content.height
|
|
zoom: page.zoom
|
|
Component.onCompleted: view.caricaDemo()
|
|
extraCss: page.demoCss
|
|
}
|
|
|
|
/* Editor multi-riga per le textarea: gli a capo restano. */
|
|
TextEdit {
|
|
id: editorMulti
|
|
width: 1
|
|
height: 1
|
|
opacity: 0
|
|
onTextChanged: {
|
|
if (activeFocus && view.focusedKey !== "") {
|
|
view.setValue(view.focusedKey, text)
|
|
view.setCaret(cursorPosition)
|
|
}
|
|
}
|
|
onCursorPositionChanged: if (activeFocus) view.setCaret(cursorPosition)
|
|
}
|
|
|
|
/* Editor invisibile: esiste solo per aprire la tastiera virtuale e
|
|
* consegnare il testo al controllo che ha il fuoco. */
|
|
TextInput {
|
|
id: editor
|
|
width: 1
|
|
height: 1
|
|
opacity: 0
|
|
onTextChanged: {
|
|
if (activeFocus && view.focusedKey !== "") {
|
|
view.setValue(view.focusedKey, text)
|
|
view.setCaret(cursorPosition)
|
|
}
|
|
}
|
|
/* cursore e selezione: il motore li disegna sul controllo che ha
|
|
* il fuoco, il TextInput fornisce solo la posizione */
|
|
onCursorPositionChanged: if (activeFocus) view.setCaret(cursorPosition)
|
|
onSelectionStartChanged: if (activeFocus && selectionStart >= 0)
|
|
view.setSelection(selectionStart, selectionEnd)
|
|
onSelectionEndChanged: if (activeFocus && selectionEnd >= 0)
|
|
view.setSelection(selectionStart, selectionEnd)
|
|
}
|
|
}
|
|
|
|
/* Pinch a due dita per lo zoom; con un dito resta lo scroll.
|
|
* Durante il gesto si scala l'immagine, al rilascio si ricalcola nitido. */
|
|
PinchArea {
|
|
anchors.fill: parent
|
|
pinch.minimumScale: 0.75
|
|
pinch.maximumScale: 4.0
|
|
|
|
onPinchStarted: {
|
|
page.pinchStartZoom = page.zoom
|
|
page.liveZoom = page.zoom
|
|
}
|
|
onPinchUpdated: {
|
|
var ratio = pinch.previousScale > 0 ? pinch.scale / pinch.previousScale : 1
|
|
page.liveZoom = Math.max(0.75, Math.min(4.0, page.liveZoom * ratio))
|
|
}
|
|
onPinchFinished: page.zoom = page.liveZoom
|
|
|
|
/* Tocco sui controlli di modulo. Il MouseArea sta DENTRO la PinchArea:
|
|
* fuori, la PinchArea copre la vista e si mangia i tocchi (era il
|
|
* motivo per cui caselle e campi non rispondevano sul telefono).
|
|
* Il rettangolo dei controlli lo fornisce il motore, quindi il guscio
|
|
* non duplica la geometria. */
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: {
|
|
var cx = (mouse.x + flick.contentX) / view.zoom
|
|
var cy = (mouse.y + flick.contentY) / view.zoom
|
|
|
|
/* 1) elenco aperto: il tocco su una voce la sceglie */
|
|
var controlli = view.controls
|
|
for (var i = 0; i < controlli.length; i++) {
|
|
var pop = controlli[i].popup
|
|
if (!pop) continue
|
|
if (cx >= pop.x && cx <= pop.x + pop.w &&
|
|
cy >= pop.y && cy <= pop.y + pop.h) {
|
|
var riga = Math.floor((cy - pop.y) / controlli[i].rowHeight)
|
|
view.chooseOption(controlli[i].key, riga)
|
|
return
|
|
}
|
|
/* tocco fuori dall'elenco: si chiude */
|
|
view.setOpenSelect("")
|
|
}
|
|
|
|
/* Prima gli eventi della pagina (listener e attributi inline),
|
|
* poi la gestione dei controlli: è l'ordine del browser. */
|
|
view.clicCss(cx, cy)
|
|
|
|
var key = view.controlAt(cx, cy)
|
|
console.log("mosaic: tocco css=" + cx.toFixed(1) + "," + cy.toFixed(1) +
|
|
" controllo=" + key + " tipo=" + view.kindOf(key))
|
|
if (key === "") {
|
|
view.setOpenSelect("")
|
|
view.setFocus("")
|
|
editor.focus = false
|
|
return
|
|
}
|
|
view.setFocus(key)
|
|
var tipo = view.kindOf(key)
|
|
if (tipo === "checkbox" || tipo === "radio") {
|
|
view.toggle(key)
|
|
} else if (tipo === "select") {
|
|
/* un solo posto tiene lo stato: il C++ */
|
|
view.toggleSelect(key)
|
|
} else if (tipo === "textarea") {
|
|
/* la textarea accetta gli a capo: serve un editor multi-riga */
|
|
editorMulti.text = view.hasValue(key) ? view.value(key)
|
|
: view.textOf(key)
|
|
editorMulti.cursorPosition = editorMulti.length
|
|
editorMulti.forceActiveFocus()
|
|
} else if (tipo === "text" || tipo === "password") {
|
|
editor.text = view.hasValue(key) ? view.value(key) : view.textOf(key)
|
|
editor.cursorPosition = editor.length
|
|
editor.forceActiveFocus()
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
/* Errore del motore: banner esplicito, mai pagina bianca muta. */
|
|
Rectangle {
|
|
id: errorBanner
|
|
visible: view.lastError !== ""
|
|
anchors.top: header.bottom
|
|
width: parent.width
|
|
height: Theme.itemSizeSmall
|
|
color: Theme.rgba("#cc0000", 0.9)
|
|
|
|
Label {
|
|
anchors.centerIn: parent
|
|
width: parent.width - 2 * Theme.paddingMedium
|
|
text: view.lastError
|
|
color: "white"
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
wrapMode: Text.Wrap
|
|
horizontalAlignment: Text.AlignHCenter
|
|
}
|
|
}
|
|
|
|
Item {
|
|
id: statusBar
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.bottom: parent.bottom
|
|
height: Theme.itemSizeExtraSmall
|
|
|
|
Label {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
x: Theme.paddingMedium
|
|
text: qsTr("motore M1") + " · " + Math.round(page.zoom * 100) + "% · "
|
|
+ view.renderMs + qsTr(" ms")
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
color: Theme.secondaryColor
|
|
}
|
|
|
|
Label {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
anchors.right: parent.right
|
|
x: -Theme.paddingMedium
|
|
text: qsTr("pinch: zoom")
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
color: Theme.secondaryColor
|
|
}
|
|
}
|
|
|
|
/* Rete (M2.6): l'indirizzo si apre dal menu a tendina della testata.
|
|
* Il caricamento gira su un thread del guscio: la finestra non si blocca. */
|
|
/* Ingresso all'indirizzo con un pulsante: nessun gesto da indovinare e
|
|
* nessun widget che possa intercettare i tocchi della pagina. */
|
|
Button {
|
|
id: pulsanteIndirizzo
|
|
anchors.top: header.bottom
|
|
anchors.right: parent.right
|
|
anchors.rightMargin: Theme.paddingMedium
|
|
anchors.topMargin: Theme.paddingSmall
|
|
z: 20
|
|
text: qsTr("Indirizzo")
|
|
onClicked: pannelloIndirizzo.open = true
|
|
}
|
|
|
|
DockedPanel {
|
|
id: pannelloIndirizzo
|
|
width: parent.width
|
|
height: colonna.height + Theme.paddingLarge
|
|
|
|
Column {
|
|
id: colonna
|
|
width: parent.width
|
|
spacing: Theme.paddingSmall
|
|
|
|
/* Column in QtQuick 2.2 non ha topPadding: un errore del genere rende
|
|
* la Page indisponibile e lo schermo resta bianco. Si usa un distanziale. */
|
|
Item {
|
|
width: 1
|
|
height: Theme.paddingLarge
|
|
}
|
|
|
|
TextField {
|
|
id: campoIndirizzo
|
|
x: Theme.horizontalPageMargin
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
placeholderText: qsTr("https://esempio.it")
|
|
label: qsTr("Indirizzo")
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
|
|
EnterKey.onClicked: {
|
|
view.loadUrl(text)
|
|
pannelloIndirizzo.close()
|
|
}
|
|
}
|
|
Row {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
spacing: Theme.paddingMedium
|
|
|
|
Button {
|
|
text: qsTr("Apri")
|
|
onClicked: {
|
|
view.loadUrl(campoIndirizzo.text)
|
|
pannelloIndirizzo.close()
|
|
}
|
|
}
|
|
Button {
|
|
text: qsTr("Ricarica")
|
|
onClicked: {
|
|
if (view.url.length > 0)
|
|
view.loadUrl(view.url)
|
|
else
|
|
view.caricaDemo()
|
|
pannelloIndirizzo.close()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Avviso di rete: il caricamento e l'errore non devono essere invisibili. */
|
|
Rectangle {
|
|
id: avvisoRete
|
|
anchors.top: header.bottom
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
height: Theme.itemSizeExtraSmall
|
|
visible: view.loadState === 1 || view.loadState === 3
|
|
color: view.loadState === 3 ? "#b03030" : "#205080"
|
|
z: 10
|
|
|
|
Label {
|
|
anchors.centerIn: parent
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
horizontalAlignment: Text.AlignHCenter
|
|
truncationMode: TruncationMode.Fade
|
|
color: "white"
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
text: view.loadState === 1
|
|
? qsTr("Caricamento di %1…").arg(view.url)
|
|
: view.networkError
|
|
}
|
|
}
|
|
}
|