Mosaic: motore di rendering proprio, gusci desktop e Sailfish
Primo commit del progetto: motore Rust con parser HTML, cascata CSS, layout, raster CPU, formulari, bidi, flex, tabelle, JavaScript (Boa) con eventi e costruzione di nodi, rete HTTP/HTTPS con TLS, sotto-risorse, invio dei formulari; guscio grafico per Sailfish (QML/Silica) e per desktop (minifb, distribuito come AppImage), con 11 documenti di specifica e 91 casi di reftest.
This commit is contained in:
commit
577682ae22
173 files changed
+23685
No files matched your search
@@ -0,0 +1,9 @@
|
||||
/target
|
||||
/libs/libengine.a
|
||||
/fonts/DejaVuSans.ttf
|
||||
/RPMS
|
||||
/rpm/*.tar.gz
|
||||
/Makefile
|
||||
*.o
|
||||
moc_*
|
||||
/harbour-mosaic
|
||||
@@ -0,0 +1,75 @@
|
||||
# harbour-mosaic — guscio Sailfish del motore (M0)
|
||||
|
||||
Applicazione Sailfish OS che incorpora il motore di `../engine` e ne presenta il raster in
|
||||
un elemento QML. È il banco di prova descritto in [`../docs/11-browser-sailfish-test.md`](../docs/11-browser-sailfish-test.md).
|
||||
|
||||
## Struttura
|
||||
|
||||
```
|
||||
harbour-mosaic/
|
||||
├── harbour-mosaic.pro # linka libs/libengine.a, installa font e QML
|
||||
├── src/main.cpp # SailfishApp, registrazione del tipo EngineView
|
||||
├── src/engineview.{h,cpp} # QQuickPaintedItem: chiama engine_render, mostra/segnala errori
|
||||
├── qml/… # Silica: PageHeader, EngineView, banner errori, barra stato
|
||||
├── include/engine.h # copiato dal motore dallo script
|
||||
├── libs/libengine.a # staticlib per l'architettura scelta (non versionata)
|
||||
├── fonts/DejaVuSans.ttf # il motore riceve il font come parametro: bundle esplicito
|
||||
└── scripts/build.sh # staticlib → copie → tarball → sfdk build
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
./scripts/build.sh # aarch64 (device)
|
||||
./scripts/build.sh armv7hl # 32 bit
|
||||
./scripts/build.sh i486 # emulatore
|
||||
```
|
||||
|
||||
Lo script compila la staticlib per il target (una staticlib non richiede linker di
|
||||
cross-compilazione), la copia in `libs/`, crea il tarball sorgente e lancia `sfdk build`.
|
||||
L'RPM esce in `RPMS/`.
|
||||
|
||||
## Zoom e scorrimento
|
||||
|
||||
- `zoom` è il fattore CSS → dispositivo. Il motore impagina con un viewport CSS largo
|
||||
`larghezza / zoom` e rasterizza a `zoom`: **si scala la geometria, non l'immagine**,
|
||||
quindi il testo resta nitido a ogni livello.
|
||||
- Zoom iniziale proporzionato allo schermo (`larghezza / 380`, cioè un viewport CSS da
|
||||
telefono: su 1080 px vale ~2,8), poi salvato in `~/.config/harbour/harbour-mosaic/`.
|
||||
- Pinch a due dita per cambiare zoom; durante il gesto l'immagine viene scalata, al
|
||||
rilascio si ri-rasterizza alla nuova scala (un render costa decine di ms sul device).
|
||||
- L'immagine è alta quanto il documento (`auto_height`), così il Flickable scorre tutto
|
||||
il contenuto e non solo il primo schermo.
|
||||
|
||||
## Stato verificato (2026-11-11)
|
||||
|
||||
- `harbour-mosaic-0.2.1-1.aarch64.rpm`: binario ELF aarch64, desktop file, QML, font e
|
||||
icone (86/108/128/172) inclusi.
|
||||
- Dipendenze dichiarate: Qt5Core/Gui/Qml/Quick, `libsailfishapp`, `sailfishsilica-qt5`.
|
||||
- glibc richiesta 2.39, disponibile nel target (2.41).
|
||||
|
||||
## Non verificato
|
||||
|
||||
- Primo avvio sul telefono (installazione RPM + log da terminale). Sotto `qemu-aarch64` con
|
||||
il sysroot del target il processo termina con SIGABRT prima di scrivere qualsiasi
|
||||
messaggio: non è una prova, serve il device.
|
||||
- Al primo avvio controllare: font trovato (`/usr/share/harbour-mosaic/fonts/DejaVuSans.ttf`),
|
||||
documento demo disegnato, `renderMs` nella barra di stato.
|
||||
|
||||
## Verifica della demo senza device
|
||||
|
||||
`scripts/check-demo.py` estrae `demoHtml`/`demoCss` da `qml/pages/MainPage.qml`
|
||||
(concatenazioni e escape compresi) e li rende col motore a 380 px CSS, zoom 2,85:
|
||||
quello che si vede nel PNG è quello che il guscio mostra sul telefono.
|
||||
|
||||
```bash
|
||||
scripts/check-demo.py /tmp/mobile-demo.png
|
||||
```
|
||||
|
||||
## Note di integrazione
|
||||
|
||||
- Il motore è sincrono e veloce su documenti M0: la chiamata avviene sul thread grafico.
|
||||
Con la rete (M1) passerà a un thread dedicato senza cambiare la superficie QML.
|
||||
- Gli errori del motore non producono pagine bianche: `EngineView.lastError` alimenta un
|
||||
banner in alto con il messaggio vero.
|
||||
- `SailfishApp::pathTo(...)` per il QML: un URL relativo non caricherebbe dal launcher.
|
||||
Whitespace-only changes.
Binary file not shown.
@@ -0,0 +1,49 @@
|
||||
TEMPLATE = app
|
||||
TARGET = harbour-mosaic
|
||||
|
||||
CONFIG += sailfishapp
|
||||
CONFIG += c++11
|
||||
|
||||
QT += quick qml
|
||||
|
||||
# Motore di rendering (Rust, staticlib). La lib per l'architettura del target
|
||||
# viene copiata in libs/ da scripts/build.sh — un solo percorso, niente scelte
|
||||
# implicite sull'architettura sbagliata.
|
||||
INCLUDEPATH += $$PWD/include
|
||||
LIBS += -L$$PWD/libs -lengine
|
||||
# dipendenze della staticlib Rust
|
||||
LIBS += -lpthread -ldl -lm
|
||||
|
||||
SOURCES += \
|
||||
src/main.cpp \
|
||||
src/engineview.cpp \
|
||||
src/appsettings.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/engineview.h \
|
||||
src/appsettings.h
|
||||
|
||||
OTHER_FILES += \
|
||||
qml/harbour-mosaic.qml \
|
||||
qml/pages/*.qml \
|
||||
rpm/harbour-mosaic.spec \
|
||||
rpm/harbour-mosaic.desktop
|
||||
|
||||
DISTFILES += $$OTHER_FILES
|
||||
|
||||
# Icone: struttura standard Sailfish (una cartella per dimensione)
|
||||
icons86.path = /usr/share/icons/hicolor/86x86/apps
|
||||
icons86.files = $$PWD/icons/86x86/harbour-mosaic.png
|
||||
icons108.path = /usr/share/icons/hicolor/108x108/apps
|
||||
icons108.files = $$PWD/icons/108x108/harbour-mosaic.png
|
||||
icons128.path = /usr/share/icons/hicolor/128x128/apps
|
||||
icons128.files = $$PWD/icons/128x128/harbour-mosaic.png
|
||||
icons172.path = /usr/share/icons/hicolor/172x172/apps
|
||||
icons172.files = $$PWD/icons/172x172/harbour-mosaic.png
|
||||
INSTALLS += icons86 icons108 icons128 icons172
|
||||
|
||||
# Font bundling: il motore riceve il font come parametro esplicito, quindi il
|
||||
# pacchetto se lo porta dietro e i test sono ripetibili su ogni device.
|
||||
fonts.path = /usr/share/$$TARGET/fonts
|
||||
fonts.files = $$files($$PWD/fonts/*.ttf)
|
||||
INSTALLS += fonts
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@@ -0,0 +1,61 @@
|
||||
/* API C del motore di rendering — M0.
|
||||
* Unico confine fra il motore (Rust) e il guscio (C++/Qt).
|
||||
* Ogni immagine restituita va liberata con engine_image_free(). */
|
||||
#ifndef ENGINE_H
|
||||
#define ENGINE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct EngineImage {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint8_t *pixels; /* RGBA8, len byte; NULL in caso di errore */
|
||||
uintptr_t len;
|
||||
char *error; /* messaggio di errore o NULL */
|
||||
char *controls; /* JSON [{key,kind,x,y,w,h}], pixel CSS; NULL se nessuno */
|
||||
} EngineImage;
|
||||
|
||||
const char *engine_version(void);
|
||||
|
||||
/* Renderizza html/css nel viewport indicato. Non fa I/O di rete e non tocca il DOM
|
||||
* del guscio: è una funzione pura byte -> pixel.
|
||||
* scale: pixel CSS -> pixel dispositivo (zoom/DPI).
|
||||
* auto_height: se diverso da 0 l'immagine cresce fino all'altezza del documento
|
||||
* (height diventa il minimo), così il guscio può scorrere il contenuto.
|
||||
* font_path deve puntare a un TTF leggibile dal processo.
|
||||
* base_dir è la cartella con cui si risolvono i `src` relativi delle immagini
|
||||
* (stringa vuota = directory corrente). */
|
||||
EngineImage *engine_render(const char *html, const char *css,
|
||||
uint32_t width, uint32_t height,
|
||||
float scale, int auto_height,
|
||||
const char *font_path, const char *base_dir);
|
||||
|
||||
/* Come engine_render, con lo stato dei moduli.
|
||||
* state_json: {"values": {"chiave": "valore"}, "focus": "chiave"} oppure NULL.
|
||||
* Nel risultato, `controls` elenca i controlli con tipo e rettangolo in pixel CSS. */
|
||||
EngineImage *engine_render_form(const char *html, const char *css,
|
||||
uint32_t width, uint32_t height,
|
||||
float scale, int auto_height,
|
||||
const char *font_path, const char *base_dir,
|
||||
const char *state_json);
|
||||
|
||||
void engine_image_free(EngineImage *img);
|
||||
|
||||
/* Scarica un documento (http:// o https://) e ne restituisce il testo UTF-8.
|
||||
* Liberare con engine_string_free(). In caso di errore restituisce NULL e scrive
|
||||
* il messaggio in *error (anch'esso da liberare). *status riceve il codice HTTP,
|
||||
* 0 se la richiesta non è arrivata a risposta. */
|
||||
char *engine_fetch(const char *url, int *status, char **error);
|
||||
|
||||
/* Libera una stringa restituita da engine_fetch(). */
|
||||
void engine_string_free(char *s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ENGINE_H */
|
||||
@@ -0,0 +1,9 @@
|
||||
import QtQuick 2.2
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
import "pages"
|
||||
|
||||
ApplicationWindow {
|
||||
id: app
|
||||
initialPage: Component { MainPage { } }
|
||||
}
|
||||
@@ -0,0 +1,371 @@
|
||||
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
|
||||
|
||||
/* Documento di prova M0: è il contenuto che il motore sa impaginare oggi
|
||||
* (blocchi, testo, elenchi, sfondi, bordi, colore inline). Documentazione
|
||||
* completa del perimetro in docs/01-requisiti.md. */
|
||||
property string demoHtml:
|
||||
"<h1>NCSA Mosaic</h1>" +
|
||||
"<p>Riedizione 2026 con un motore di rendering scritto da zero: nessun WebKit, nessun Blink.</p>" +
|
||||
"<div style=\"width:200px;height:6px;background:#000080\"></div>" +
|
||||
"<h2>Modulo di prova</h2>" +
|
||||
"<p style=\"font-size:15px\">Nome: <input type=\"text\" value=\"Mosaic\"></p>" +
|
||||
"<p style=\"font-size:15px\"><input type=\"checkbox\" checked> attivo" +
|
||||
" <input type=\"radio\" checked> A <input type=\"radio\"> B</p>" +
|
||||
"<p style=\"font-size:15px\">Modalità: <select><option>uno</option>" +
|
||||
"<option selected>due</option></select> " +
|
||||
"<input type=\"submit\" value=\"Invia\"></p>" +
|
||||
"<p style=\"font-size:15px\">Note: <textarea style=\"width:100%;height:44px\">" +
|
||||
"testo lungo</textarea></p>" +
|
||||
"<h2>Tabella</h2>" +
|
||||
"<table style=\"width:100%\">" +
|
||||
"<tr><th style=\"width:40%\">funzione</th><th>stato</th></tr>" +
|
||||
"<tr><td>tabelle</td><td>colspan e colonne automatiche</td></tr>" +
|
||||
"<tr><td>flex</td><td>riga, colonna, grow, gap</td></tr>" +
|
||||
"<tr><td colspan=\"2\">bidi: paragrafi da destra</td></tr>" +
|
||||
"</table>" +
|
||||
"<h2>Disposizione con flex</h2>" +
|
||||
"<div style=\"display:flex;gap:8px;height:56px\">" +
|
||||
"<div class=\"scheda\" style=\"flex:1\">uno</div>" +
|
||||
"<div class=\"scheda\" style=\"flex:2\">due</div>" +
|
||||
"<div class=\"scheda\" style=\"flex:1\">tre</div>" +
|
||||
"</div>" +
|
||||
"<h2>Testo da destra</h2>" +
|
||||
"<p dir=\"rtl\">שלום עולם — paragrafo RTL</p>" +
|
||||
"<h2>Che cosa sa fare il motore, oggi</h2>" +
|
||||
"<ul>" +
|
||||
"<li>parse HTML con recupero dagli errori</li>" +
|
||||
"<li>cascata CSS con @media, var() e margini collassanti</li>" +
|
||||
"<li>layout a blocchi e inline, testo con kerning e legature</li>" +
|
||||
"<li>immagini PNG, JPEG e WebP</li>" +
|
||||
"</ul>" +
|
||||
"<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC\" width=\"48\" height=\"48\">" +
|
||||
"<p>Colori ereditati: <span style=\"color:#800000\">questo testo è rosso scuro</span> e questo no.</p>" +
|
||||
"<div style=\"width:120px;height:40px;border:2px solid #000000;background:#ffffcc\"></div>" +
|
||||
"<p>Due colonne con float:</p>" +
|
||||
"<div style=\"width:100%;font-size:15px\">" +
|
||||
"<div style=\"float:left;width:80px;height:60px;background:#3f9b46\"></div>" +
|
||||
"<p>Questo testo scorre accanto al riquadro verde, come in una pagina del 1994.</p></div>" +
|
||||
"<p style=\"font-family:SerifMosaic\">Questo paragrafo usa un font caricato con "
|
||||
+ "@font-face dal pacchetto.</p>" +
|
||||
"<p>Ancora fuori ambito: grid, script, rete.</p>"
|
||||
|
||||
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
|
||||
html: page.demoHtml
|
||||
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("")
|
||||
}
|
||||
|
||||
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.setHtml(page.demoHtml)
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Mosaic
|
||||
GenericName=Web Browser
|
||||
Comment=Browser Mosaic con motore di rendering indipendente (M0)
|
||||
Exec=harbour-mosaic
|
||||
Icon=harbour-mosaic
|
||||
Terminal=false
|
||||
Categories=Network;WebBrowser;
|
||||
Keywords=web;browser;mosaic;retro;hypertext;
|
||||
StartupNotify=true
|
||||
StartupWMClass=Mosaic
|
||||
|
||||
[X-Sailjail]
|
||||
Permissions=Internet
|
||||
OrganizationName=harbour
|
||||
ApplicationName=harbour-mosaic
|
||||
@@ -0,0 +1,210 @@
|
||||
Name: harbour-mosaic
|
||||
Summary: Mosaic browser with an independent rendering engine
|
||||
Version: 0.8.4
|
||||
Release: 1
|
||||
Group: Qt/Qt
|
||||
License: MIT
|
||||
URL: https://carlobaratto.it
|
||||
Source0: %{name}-%{version}.tar.gz
|
||||
Source1: %{name}.desktop
|
||||
|
||||
Requires: sailfishsilica-qt5 >= 0.10.9
|
||||
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
|
||||
BuildRequires: pkgconfig(Qt5Core)
|
||||
BuildRequires: pkgconfig(Qt5Qml)
|
||||
BuildRequires: pkgconfig(Qt5Quick)
|
||||
BuildRequires: desktop-file-utils
|
||||
|
||||
%description
|
||||
Browser with the NCSA Mosaic user interface, rendering through a new
|
||||
engine written from scratch (no WebKit, Blink, Gecko or Servo code).
|
||||
Milestone M0: HTML parsing, CSS cascade, block layout and CPU raster.
|
||||
|
||||
%changelog
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.8.4-1
|
||||
- Tocchi sul telefono: tolti PullDownMenu e SilicaFlickable, che intercettavano i
|
||||
tocchi (con la 0.8.3 non arrivavano piu' ai controlli). Si torna al Flickable
|
||||
semplice; l'indirizzo si apre con un pulsante in alto a destra, senza gesti
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.8.3-1
|
||||
- Pagina bianca risolta: "Column.topPadding is not available in QtQuick 2.2"
|
||||
rendeva l'intera MainPage indisponibile. Sostituito con un distanziale, e lo
|
||||
script di build ora si ferma se ricompare una spaziatura dei positioner
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.8.2-1
|
||||
- Pagina bianca: il PullDownMenu stava prima della Flickable e in Silica il primo
|
||||
figlio della Page e' il contenuto. Ora il contenuto torna primo e il flickable
|
||||
e' SilicaFlickable, che e' quello a cui il menu si aggancia
|
||||
- Menu a tendina: il controllo non mostrava la voce scelta dal guscio quando le
|
||||
opzioni non hanno l'attributo value (vale il testo dell'opzione). Il confronto
|
||||
guardava solo l'attributo, quindi la voce restava quella dell'HTML
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.8.1-1
|
||||
- Guscio: menu "Apri indirizzo…" e "Ricarica", pannello con il campo
|
||||
dell'indirizzo, avviso di caricamento/errore. La richiesta gira su un thread e
|
||||
torna al thread grafico via coda: la finestra resta viva
|
||||
- Nuova funzione del confine C engine_fetch (testo o messaggio d'errore)
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.8.0-1
|
||||
- Rete (M2.6): GET su http e https con verifica dei certificati (rustls), corpi
|
||||
Content-Length e chunked, reindirizzamenti, limiti di tempo e dimensione
|
||||
- TLS: ring porta codice C e assembly, quindi il cross-build aarch64 passa da
|
||||
gcc-aarch64-linux-gnu (CC/AR impostati in scripts/build.sh)
|
||||
- CSS: scorciatoia font, max-width con margini automatici, unita vh/vw, ordine
|
||||
di rem/em (rem non veniva mai letto) — difetti emersi caricando example.com
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.13-1
|
||||
- Corretto il vero motivo per cui il menu a tendina non si apriva sul telefono:
|
||||
parse_form_state (confine C) leggeva solo values e focus, ignorando
|
||||
open_select, caret e selection. Il desktop non lo mostrava perche' chiama il
|
||||
Rust direttamente. Aggiunta una prova del confine C che verifica il round-trip
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.12-1
|
||||
- Elenco a tendina: lo stato di apertura vive solo nel C++ (toggleSelect). Il QML
|
||||
lo confrontava con focusedKey e chiudeva subito un elenco appena aperto: dal log
|
||||
del device si vedeva setOpenSelect "" al primo tocco
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.11-1
|
||||
- Elenco a tendina: se non c'è spazio sotto il controllo si apre verso l'alto,
|
||||
riferito al viewport (prima usciva dallo schermo e sembrava non reagire)
|
||||
- Log diagnostico sul tocco e sul fuoco (console.log + qDebug) per capire dal
|
||||
terminale dove si ferma un tocco che non produce effetto
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.10-1
|
||||
- JavaScript anche qui: installato gcc-aarch64-linux-gnu, la cdylib di Boa si
|
||||
cross-compila e il linker e' dichiarato in engine/.cargo/config.toml
|
||||
- Input sul telefono: il MouseArea dei controlli sta dentro la PinchArea, che
|
||||
prima copriva la vista e si mangiava i tocchi (caselle e campi non rispondevano)
|
||||
- Il campo di testo si apre con il valore mostrato dal motore, non vuoto
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.9-1
|
||||
- Correzione del changelog precedente: questo pacchetto NON include l'interprete
|
||||
JavaScript. Boa dichiara una cdylib che non si cross-compila per aarch64 senza
|
||||
un linker aarch64 (assente sull'host di build e nel container dell'SDK), quindi
|
||||
il motore per Sailfish e' compilato con --no-default-features. Se una pagina
|
||||
contiene script, il guscio riporta "JavaScript non incluso in questa build"
|
||||
invece di restare muto. Il desktop (AppImage) ha l'interprete attivo.
|
||||
- Restano validi i casi 89-90 nella suite dell'host, dove JavaScript e' attivo
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.8-1
|
||||
- Motore JavaScript (Boa) integrato nel motore: script inline prima di stile e
|
||||
layout con document.getElementById e textContent (casi 89-90, solo build host)
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.7-1
|
||||
- Testo nei campi: ritaglio sul bordo e scorrimento orizzontale con il cursore in
|
||||
fondo; textarea multi-riga con gli a capo (casi 87-88)
|
||||
- Elenco a tendina e caselle: il tocco vale una volta sola (prima apriva e
|
||||
sceglieva la prima voce)
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.6-1
|
||||
- Textarea: il testo contenuto nell'elemento e' il valore iniziale (prima il campo
|
||||
appariva vuoto anche con contenuto in HTML) - caso 86
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.5-1
|
||||
- Menu a tendina a comparsa: il motore disegna l elenco delle opzioni sotto il
|
||||
select con la voce evidenziata; il guscio manda apertura e scelta (caso 85)
|
||||
- Demo mobile allineata alla desktop: textarea e pulsante Invia
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.4-1
|
||||
- Cursore e selezione nei campi di testo: il motore misura il testo che precede
|
||||
il cursore e disegna la barra e la fascia di selezione; il guscio manda
|
||||
caret e intervallo dal TextInput (casi 83-84)
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.3-1
|
||||
- Controlli di modulo centrati sulla riga di testo (vertical-align: middle):
|
||||
l'etichetta accanto a una textarea alta non finisce piu' in fondo al riquadro
|
||||
(caso 82)
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.2-1
|
||||
- Demo mobile con tabelle, flex e bidi; script check-demo.py che estrae l'HTML dal
|
||||
QML e lo rende col motore, per verificare senza device
|
||||
- Tabelle: le larghezze di colonna in percentuale si risolvono sulla tabella
|
||||
(40% di 400px = 160px) e non sullo spazio usato per misurare il contenuto
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.1-1
|
||||
- Formulari: input testo/password, checkbox, radio, select, textarea e pulsanti
|
||||
disegnati dal motore; fuoco con anello blu, tocco sul controllo, testo dalla
|
||||
tastiera virtuale via TextInput (casi 77-80)
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.7.0-1
|
||||
- Tabelle: modello a griglia con colspan, larghezze di colonna automatiche o
|
||||
dichiarate, gruppi thead/tbody/tfoot con le righe sollevate (casi 74-76)
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.6.0-1
|
||||
- Flexbox: display:flex, flex-direction (anche invertite), justify-content,
|
||||
align-items, gap, flex-grow/shrink/basis, flex-wrap (casi 68-73)
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.5.0-1
|
||||
- Bidi: sottinsieme dell'algoritmo UBA (classi L/R/AL/EN/AN, neutri, livelli,
|
||||
riordino visivo L2); supporto all'attributo dir e a direction, allineamento
|
||||
a destra come valore iniziale nei blocchi RTL (casi 63-66)
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.4.1-1
|
||||
- Corretto il posizionamento dei float: venivano impaginati in cima al contenitore
|
||||
invece che nel punto del flusso, quindi scavalcano titoli e paragrafi precedenti
|
||||
(difetto emerso con la pagina demo del guscio desktop, test 62)
|
||||
- Motore allineato all'AppImage desktop 0.1.0
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.4.0-1
|
||||
- Corretto il difetto di visualizzazione a zoom > 1: i glifi venivano rasterizzati
|
||||
alla dimensione del dispositivo ma gli avanzamenti restavano in pixel CSS, quindi
|
||||
a 300% le lettere si ammassavano e si sovrapponevano. Ora il passo della penna
|
||||
scala con il fattore CSS -> dispositivo (test di regressione su estensione inchiostro)
|
||||
- Etichetta della barra di stato aggiornata a "motore M1"
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.3.1-1
|
||||
- Demo: paragrafo in DejaVu Serif caricato con @font-face dal pacchetto
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.3.0-1
|
||||
- Motore: @font-face con font per famiglia, 60 reftest verdi
|
||||
- Corretto il tree builder: le liste annidate non si sfondano più
|
||||
(auto-chiusura di <li> limitata allo stesso elenco)
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.2.2-1
|
||||
- Corretto il float: i blocchi successivi si restringono accanto al float invece
|
||||
di finirci sopra; demo con esempio a due colonne
|
||||
|
||||
* Thu Nov 12 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.2.1-1
|
||||
- Motore: float, posizionamento relativo/assoluto/fisso (M1)
|
||||
- App: icona Mosaic nelle quattro dimensioni Sailfish
|
||||
|
||||
* Wed Nov 11 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.2.0-1
|
||||
- M1 nel motore: shaping con rustybuzz (kerning e legature), white-space,
|
||||
margini collassanti, @media, proprietà personalizzate con var(),
|
||||
immagini PNG/JPEG/WebP con dimensioni intrinseche
|
||||
- Confine C aggiornato (auto_height, base_dir per le immagini)
|
||||
|
||||
* Wed Nov 11 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.1.1-1
|
||||
- Zoom: scala della geometria nel motore (testo nitido, non immagine ingrandita),
|
||||
pinch a due dita, scorrimento verticale, zoom iniziale proporzionato allo schermo
|
||||
e salvato fra le sessioni
|
||||
- Prestazioni: cache dei glifi condivisa e riempimento righe a memcpy (da 98 a 12 ms
|
||||
su una pagina 1080x1544)
|
||||
|
||||
* Wed Nov 11 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.1.0-1
|
||||
- M0: motore Rust (parser, cascata, layout blocchi, raster), confine C,
|
||||
guscio QML/Silica che presenta il raster, harness di reftest
|
||||
|
||||
%prep
|
||||
%setup -q -n %{name}-%{version}
|
||||
|
||||
%build
|
||||
%qmake5
|
||||
make %{?_smp_mflags}
|
||||
|
||||
%install
|
||||
make install INSTALL_ROOT=%{buildroot}
|
||||
mkdir -p %{buildroot}%{_datadir}/applications
|
||||
install -m 0644 %{SOURCE1} %{buildroot}%{_datadir}/applications/%{name}.desktop
|
||||
desktop-file-validate %{buildroot}%{_datadir}/applications/%{name}.desktop || true
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
%{_bindir}/%{name}
|
||||
%{_datadir}/applications/%{name}.desktop
|
||||
%{_datadir}/%{name}/qml
|
||||
%{_datadir}/%{name}/fonts
|
||||
%{_datadir}/icons/hicolor/86x86/apps/%{name}.png
|
||||
%{_datadir}/icons/hicolor/108x108/apps/%{name}.png
|
||||
%{_datadir}/icons/hicolor/128x128/apps/%{name}.png
|
||||
%{_datadir}/icons/hicolor/172x172/apps/%{name}.png
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
#!/bin/sh
|
||||
# Costruisce harbour-mosaic per Sailfish OS.
|
||||
#
|
||||
# ./scripts/build.sh [arch] arch: aarch64 (default), armv7hl, i486
|
||||
#
|
||||
# Fa tre cose, in ordine, e si ferma al primo errore:
|
||||
# 1. compila la staticlib Rust per l'architettura del target (nessun linker
|
||||
# di cross-compilazione richiesto: una staticlib non si linka);
|
||||
# 2. la copia in libs/ insieme a include/engine.h e al font;
|
||||
# 3. crea il tarball sorgente e lancia sfdk build per il target.
|
||||
set -eu
|
||||
|
||||
ARCH="${1:-aarch64}"
|
||||
APP_DIR=$(cd "$(dirname "$0")/.." && pwd)
|
||||
ENGINE_DIR="$APP_DIR/../engine"
|
||||
TARGET="SailfishOS-5.1.0.11-$ARCH"
|
||||
|
||||
export PATH="$HOME/.cargo/bin:$PATH"
|
||||
export PATH="$HOME/SailfishOS/bin:$PATH"
|
||||
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
|
||||
# librerie Qt dell'SDK per sfdk su questo host (vedi AppSailfish/build-rpm.sh)
|
||||
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}${LD_LIBRARY_PATH:+:}/home/kaneda/sdk-dl/libs/root/usr/lib/x86_64-linux-gnu"
|
||||
|
||||
echo "== 1/4 staticlib $ARCH"
|
||||
rustup target list --installed | grep -qx "${ARCH}-unknown-linux-gnu" \
|
||||
|| rustup target add "${ARCH}-unknown-linux-gnu"
|
||||
# JavaScript incluso: il linker aarch64 è impostato in engine/.cargo/config.toml
|
||||
# e arriva dal pacchetto gcc-aarch64-linux-gnu. Per una build senza interprete:
|
||||
# aggiungere --no-default-features (e i casi 89-90 si saltano).
|
||||
# controllo QML: un errore di proprietà rende la Page indisponibile e lo schermo
|
||||
# resta bianco, senza che la build se ne accorga. QtQuick 2.2 (Sailfish) non ha
|
||||
# le spaziature dei positioner: se ricompaiono, meglio fermarsi qui.
|
||||
# solo le assegnazioni: i commenti che spiegano il divieto devono poter esistere
|
||||
if trovate=$(grep -rn -E "^[[:space:]]*(top|bottom|left|right)Padding[[:space:]]*:" qml/); then
|
||||
echo "errore: le spaziature dei Positioner non esistono in QtQuick 2.2 (usa un distanziale):" >&2
|
||||
echo "$trovate" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ring (TLS) porta C e assembly: al cross-compilatore va detto esplicitamente
|
||||
(cd "$ENGINE_DIR" && \
|
||||
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
|
||||
AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar \
|
||||
cargo build --release --target "${ARCH}-unknown-linux-gnu" --lib)
|
||||
|
||||
echo "== 2/4 copia lib, header e font"
|
||||
mkdir -p "$APP_DIR/libs" "$APP_DIR/include" "$APP_DIR/fonts"
|
||||
cp -f "$ENGINE_DIR/target/${ARCH}-unknown-linux-gnu/release/libengine.a" "$APP_DIR/libs/libengine.a"
|
||||
cp -f "$ENGINE_DIR/include/engine.h" "$APP_DIR/include/engine.h"
|
||||
if [ ! -f "$APP_DIR/fonts/DejaVuSans.ttf" ]; then
|
||||
cp -f /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf "$APP_DIR/fonts/DejaVuSans.ttf"
|
||||
fi
|
||||
ls -la "$APP_DIR/libs/libengine.a"
|
||||
|
||||
echo "== 3/4 tarball sorgente"
|
||||
VER=$(grep -m1 '^Version:' "$APP_DIR/rpm/harbour-mosaic.spec" | awk '{print $2}')
|
||||
STAGE=$(mktemp -d)
|
||||
mkdir -p "$STAGE/harbour-mosaic-$VER"
|
||||
(cd "$APP_DIR" && tar cf - --exclude='./RPMS' --exclude='./build-*' --exclude='*.tar.gz' \
|
||||
--exclude='./.sfdk' --exclude='./Makefile' --exclude='*.o' --exclude='moc_*' .) \
|
||||
| tar xf - -C "$STAGE/harbour-mosaic-$VER"
|
||||
tar czf "$APP_DIR/rpm/harbour-mosaic-$VER.tar.gz" -C "$STAGE" "harbour-mosaic-$VER"
|
||||
rm -rf "$STAGE"
|
||||
ls -la "$APP_DIR/rpm/harbour-mosaic-$VER.tar.gz"
|
||||
|
||||
echo "== 4/4 sfdk build ($TARGET)"
|
||||
# L'engine impiega minuti ad avviarsi: con il timeout di default (30 s) sfdk
|
||||
# fallisce e ritenta in raffica saturando gli slot di sshd.
|
||||
chmod 600 "$HOME/SailfishOS/vmshare/ssh/private_keys/sdk" 2>/dev/null || true
|
||||
if [ "$(sfdk engine show 2>/dev/null | awk -F': ' '/ssh.timeout/{print $2}')" != "900" ]; then
|
||||
sfdk engine set ssh.timeout=900 >/dev/null 2>&1 || true
|
||||
fi
|
||||
sfdk config target="$TARGET" >/dev/null 2>&1 || true
|
||||
cd "$APP_DIR"
|
||||
sfdk build < /dev/null
|
||||
|
||||
RPM=$(find "$APP_DIR/RPMS" -name 'harbour-mosaic-*.rpm' 2>/dev/null | head -1)
|
||||
if [ -n "$RPM" ]; then
|
||||
echo "RPM: $RPM"
|
||||
else
|
||||
echo "!! build dichiarata ok ma nessun RPM in RPMS/" >&2
|
||||
exit 1
|
||||
fi
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Estrae demoHtml/demoCss da qml/pages/MainPage.qml e li rende col motore.
|
||||
|
||||
Serve a verificare quello che il guscio Sailfish mostra davvero, senza device:
|
||||
si prende il testo esatto dal QML (concatenazioni e sequenze di escape comprese)
|
||||
e lo si passa al motore come farebbe EngineView.
|
||||
|
||||
Uso: scripts/check-demo.py [uscita.png] [larghezza_css] [scale]
|
||||
"""
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
RADICE = pathlib.Path(__file__).resolve().parent.parent
|
||||
QML = RADICE / "qml/pages/MainPage.qml"
|
||||
ENGINE = RADICE.parent / "engine/target/release/render"
|
||||
|
||||
|
||||
def estrai(blocco: str) -> str:
|
||||
"""Concatena i letterali di stringa del blocco, sciogliendo gli escape QML."""
|
||||
pezzi = re.findall(r'"((?:[^"\\]|\\.)*)"', blocco, re.S)
|
||||
testo = "".join(pezzi)
|
||||
return testo.replace('\\"', '"').replace("\\\\", "\\")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
uscita = sys.argv[1] if len(sys.argv) > 1 else "/tmp/mobile-demo.png"
|
||||
larghezza_css = float(sys.argv[2]) if len(sys.argv) > 2 else 380.0
|
||||
scala = float(sys.argv[3]) if len(sys.argv) > 3 else 2.85
|
||||
|
||||
sorgente = QML.read_text()
|
||||
i = sorgente.index("property string demoHtml:")
|
||||
j = sorgente.index("property string demoCss:")
|
||||
k = sorgente.index("\n\n", j)
|
||||
html = estrai(sorgente[i:j])
|
||||
css = estrai(sorgente[j:k])
|
||||
|
||||
tmp_html = pathlib.Path("/tmp/mobile-demo.html")
|
||||
tmp_css = pathlib.Path("/tmp/mobile-demo.css")
|
||||
tmp_html.write_text(html)
|
||||
tmp_css.write_text(css)
|
||||
|
||||
larghezza = int(round(larghezza_css * scala))
|
||||
cmd = [
|
||||
str(ENGINE),
|
||||
"--html",
|
||||
str(tmp_html),
|
||||
"--css",
|
||||
str(tmp_css),
|
||||
"--size",
|
||||
f"{larghezza}x2200",
|
||||
"--scale",
|
||||
str(scala),
|
||||
"--auto-height",
|
||||
"--base-dir",
|
||||
str(RADICE),
|
||||
"--out",
|
||||
uscita,
|
||||
]
|
||||
print(" ".join(cmd))
|
||||
return subprocess.call(cmd)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "appsettings.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include <QStandardPaths>
|
||||
|
||||
namespace {
|
||||
/* Zoom iniziale proporzionato allo schermo: un telefono da 1080 px di larghezza
|
||||
* corrisponde a un viewport CSS di ~380 px, come nei browser mobili. A scala 1
|
||||
* un testo da 16px sarebbe largo 16 px fisici: illeggibile. */
|
||||
qreal defaultZoom()
|
||||
{
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
if (!screen)
|
||||
return 2.0;
|
||||
const qreal w = screen->size().width();
|
||||
if (w <= 0)
|
||||
return 2.0;
|
||||
return qBound<qreal>(1.0, w / 380.0, 4.0);
|
||||
}
|
||||
}
|
||||
|
||||
AppSettings::AppSettings(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_settings(configPath(), QSettings::IniFormat)
|
||||
{
|
||||
const qreal fallback = defaultZoom();
|
||||
m_zoom = m_settings.value(QStringLiteral("view/zoom"), fallback).toReal();
|
||||
if (m_zoom < 0.75 || m_zoom > 4.0)
|
||||
m_zoom = fallback;
|
||||
qDebug() << "harbour-mosaic: settings" << m_settings.fileName() << "zoom" << m_zoom;
|
||||
}
|
||||
|
||||
QString AppSettings::configPath()
|
||||
{
|
||||
QString dir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||
if (dir.isEmpty())
|
||||
dir = QDir::homePath() + QStringLiteral("/.config/harbour/harbour-mosaic");
|
||||
QDir().mkpath(dir);
|
||||
return dir + QStringLiteral("/harbour-mosaic.conf");
|
||||
}
|
||||
|
||||
void AppSettings::setZoom(qreal zoom)
|
||||
{
|
||||
const qreal clamped = qBound<qreal>(0.75, zoom, 4.0);
|
||||
if (qFuzzyCompare(clamped, m_zoom))
|
||||
return;
|
||||
m_zoom = clamped;
|
||||
m_settings.setValue(QStringLiteral("view/zoom"), m_zoom);
|
||||
// sync esplicito: la chiusura brusca dell'app perderebbe il flush del distruttore.
|
||||
m_settings.sync();
|
||||
emit zoomChanged();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef APPSETTINGS_H
|
||||
#define APPSETTINGS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
|
||||
/* Preferenze dell'utente. Un solo valore per ora: lo zoom.
|
||||
*
|
||||
* Il file è su AppConfigLocation con path esplicito: è l'unica zona che la
|
||||
* sandbox SailJail rende persistente, e il costruttore QSettings(org, app) da
|
||||
* solo non basta quando l'app parte dal launcher.
|
||||
*/
|
||||
class AppSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(qreal zoom READ zoom WRITE setZoom NOTIFY zoomChanged)
|
||||
|
||||
public:
|
||||
explicit AppSettings(QObject *parent = nullptr);
|
||||
|
||||
qreal zoom() const { return m_zoom; }
|
||||
void setZoom(qreal zoom);
|
||||
|
||||
signals:
|
||||
void zoomChanged();
|
||||
|
||||
private:
|
||||
static QString configPath();
|
||||
QSettings m_settings;
|
||||
qreal m_zoom = 2.0;
|
||||
};
|
||||
|
||||
#endif // APPSETTINGS_H
|
||||
@@ -0,0 +1,395 @@
|
||||
#include "engineview.h"
|
||||
|
||||
#include "engine.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMetaObject>
|
||||
#include <QPointer>
|
||||
|
||||
#include <cstdint>
|
||||
#include <thread>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QElapsedTimer>
|
||||
#include <QFileInfo>
|
||||
#include <QPainter>
|
||||
#include <QStandardPaths>
|
||||
|
||||
extern "C" {
|
||||
#include "engine.h"
|
||||
}
|
||||
|
||||
EngineView::EngineView(QQuickItem *parent)
|
||||
: QQuickPaintedItem(parent)
|
||||
{
|
||||
m_vivo = std::make_shared<std::atomic<bool>>(true);
|
||||
setAntialiasing(false);
|
||||
m_fontPath = resolveFont();
|
||||
// Le immagini con src relativo si risolvono nella cartella dati dell'app.
|
||||
m_baseDir = QCoreApplication::applicationDirPath() + QStringLiteral("/../share/harbour-mosaic");
|
||||
if (!QFileInfo::exists(m_baseDir))
|
||||
m_baseDir = QStringLiteral("/usr/share/harbour-mosaic");
|
||||
if (m_fontPath.isEmpty()) {
|
||||
setError(QStringLiteral("font non trovato: /usr/share/harbour-mosaic/fonts/DejaVuSans.ttf"));
|
||||
}
|
||||
}
|
||||
|
||||
void EngineView::setHtml(const QString &html)
|
||||
{
|
||||
if (m_html == html)
|
||||
return;
|
||||
m_html = html;
|
||||
emit htmlChanged();
|
||||
rerender();
|
||||
}
|
||||
|
||||
void EngineView::setExtraCss(const QString &css)
|
||||
{
|
||||
if (m_css == css)
|
||||
return;
|
||||
m_css = css;
|
||||
emit extraCssChanged();
|
||||
rerender();
|
||||
}
|
||||
|
||||
void EngineView::setZoom(qreal zoom)
|
||||
{
|
||||
const qreal clamped = qBound<qreal>(0.75, zoom, 4.0);
|
||||
if (qFuzzyCompare(clamped, m_zoom))
|
||||
return;
|
||||
m_zoom = clamped;
|
||||
emit zoomChanged();
|
||||
rerender();
|
||||
}
|
||||
|
||||
void EngineView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
|
||||
{
|
||||
QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
|
||||
// Solo la larghezza cambia l'impaginazione: l'altezza la decide il documento
|
||||
// (altezza automatica), quindi reagire anche a quella chiuderebbe un ciclo
|
||||
// di binding fra height e contentHeight.
|
||||
if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width()))
|
||||
rerender();
|
||||
}
|
||||
|
||||
EngineView::~EngineView()
|
||||
{
|
||||
if (m_vivo) {
|
||||
m_vivo->store(false);
|
||||
}
|
||||
}
|
||||
|
||||
void EngineView::paint(QPainter *painter)
|
||||
{
|
||||
if (m_image.isNull()) {
|
||||
painter->fillRect(boundingRect(), Qt::white);
|
||||
return;
|
||||
}
|
||||
painter->drawImage(QPointF(0, 0), m_image);
|
||||
}
|
||||
|
||||
QString EngineView::resolveFont() const
|
||||
{
|
||||
QStringList candidates;
|
||||
const QByteArray env = qgetenv("HARBOUR_MOSAIC_FONT");
|
||||
if (!env.isEmpty())
|
||||
candidates << QString::fromLocal8Bit(env);
|
||||
candidates << QStringLiteral("/usr/share/harbour-mosaic/fonts/DejaVuSans.ttf")
|
||||
<< QStringLiteral("/usr/share/fonts/truetype/DejaVuSans.ttf")
|
||||
<< QStringLiteral("/usr/share/fonts/dejavu/DejaVuSans.ttf");
|
||||
for (const QString &c : candidates) {
|
||||
if (QFileInfo::exists(c))
|
||||
return c;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void EngineView::rerender()
|
||||
{
|
||||
if (m_html.isEmpty())
|
||||
return;
|
||||
const int w = int(width());
|
||||
if (w <= 0)
|
||||
return;
|
||||
if (m_fontPath.isEmpty()) {
|
||||
setError(QStringLiteral("font non trovato: il motore non può impaginare testo"));
|
||||
return;
|
||||
}
|
||||
// Altezza minima: il documento può essere più alto, mai più basso.
|
||||
const int minH = qMax(1, int(qMax<qreal>(0.0, height())));
|
||||
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
EngineImage *img = engine_render_form(m_html.toUtf8().constData(),
|
||||
m_css.toUtf8().constData(),
|
||||
quint32(w), quint32(minH),
|
||||
float(m_zoom),
|
||||
1 /* auto_height */,
|
||||
m_fontPath.toUtf8().constData(),
|
||||
m_baseDir.toUtf8().constData(),
|
||||
stateJson().toUtf8().constData());
|
||||
m_renderMs = int(timer.elapsed());
|
||||
emit renderMsChanged();
|
||||
|
||||
if (!img) {
|
||||
setError(QStringLiteral("engine_render ha restituito NULL"));
|
||||
return;
|
||||
}
|
||||
if (img->error) {
|
||||
setError(QString::fromUtf8(img->error));
|
||||
engine_image_free(img);
|
||||
return;
|
||||
}
|
||||
|
||||
// controlli del documento: chiave, tipo e rettangolo in pixel CSS
|
||||
if (img->controls) {
|
||||
const QJsonDocument doc = QJsonDocument::fromJson(QByteArray(img->controls));
|
||||
m_controls = doc.array().toVariantList();
|
||||
emit controlsChanged();
|
||||
} else if (!m_controls.isEmpty()) {
|
||||
m_controls.clear();
|
||||
emit controlsChanged();
|
||||
}
|
||||
if (img->pixels && img->width > 0 && img->height > 0) {
|
||||
QImage view(img->pixels, int(img->width), int(img->height), QImage::Format_RGBA8888);
|
||||
m_image = view.copy();
|
||||
setError(QString());
|
||||
emit contentChanged();
|
||||
update();
|
||||
}
|
||||
engine_image_free(img);
|
||||
}
|
||||
|
||||
void EngineView::setError(const QString &error)
|
||||
{
|
||||
if (m_error == error)
|
||||
return;
|
||||
m_error = error;
|
||||
if (!error.isEmpty())
|
||||
qWarning() << "harbour-mosaic:" << error;
|
||||
emit lastErrorChanged();
|
||||
}
|
||||
|
||||
QString EngineView::stateJson() const
|
||||
{
|
||||
QJsonObject values;
|
||||
for (auto it = m_values.constBegin(); it != m_values.constEnd(); ++it) {
|
||||
values.insert(it.key(), it.value());
|
||||
}
|
||||
QJsonObject stato;
|
||||
stato.insert(QStringLiteral("values"), values);
|
||||
if (!m_focus.isEmpty()) {
|
||||
stato.insert(QStringLiteral("focus"), m_focus);
|
||||
}
|
||||
if (m_caret >= 0) {
|
||||
stato.insert(QStringLiteral("caret"), m_caret);
|
||||
}
|
||||
if (!m_openSelect.isEmpty()) {
|
||||
stato.insert(QStringLiteral("open_select"), m_openSelect);
|
||||
}
|
||||
if (m_selectionStart >= 0 && m_selectionEnd >= 0 && m_selectionStart != m_selectionEnd) {
|
||||
stato.insert(
|
||||
QStringLiteral("selection"),
|
||||
QJsonArray{m_selectionStart, m_selectionEnd});
|
||||
}
|
||||
return QString::fromUtf8(QJsonDocument(stato).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
/// Controllo che contiene il punto indicato (pixel CSS): i rettangoli arrivano
|
||||
/// dal motore, quindi il guscio non duplica la geometria.
|
||||
QString EngineView::controlAt(qreal cssX, qreal cssY) const
|
||||
{
|
||||
for (const QVariant &v : m_controls) {
|
||||
const QVariantMap m = v.toMap();
|
||||
const qreal x = m.value(QStringLiteral("x")).toDouble();
|
||||
const qreal y = m.value(QStringLiteral("y")).toDouble();
|
||||
const qreal w = m.value(QStringLiteral("w")).toDouble();
|
||||
const qreal h = m.value(QStringLiteral("h")).toDouble();
|
||||
if (cssX >= x && cssX <= x + w && cssY >= y && cssY <= y + h) {
|
||||
return m.value(QStringLiteral("key")).toString();
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString EngineView::kindOf(const QString &key) const
|
||||
{
|
||||
for (const QVariant &v : m_controls) {
|
||||
const QVariantMap m = v.toMap();
|
||||
if (m.value(QStringLiteral("key")).toString() == key) {
|
||||
return m.value(QStringLiteral("kind")).toString();
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString EngineView::value(const QString &key) const
|
||||
{
|
||||
return m_values.value(key);
|
||||
}
|
||||
|
||||
void EngineView::setValue(const QString &key, const QString &value)
|
||||
{
|
||||
if (key.isEmpty() || m_values.value(key) == value) {
|
||||
return;
|
||||
}
|
||||
m_values.insert(key, value);
|
||||
rerender();
|
||||
}
|
||||
|
||||
void EngineView::setFocus(const QString &key)
|
||||
{
|
||||
qDebug() << "mosaic: setFocus" << key;
|
||||
if (m_focus == key) {
|
||||
return;
|
||||
}
|
||||
m_focus = key;
|
||||
emit focusedKeyChanged();
|
||||
rerender();
|
||||
}
|
||||
|
||||
void EngineView::toggle(const QString &key)
|
||||
{
|
||||
if (key.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
const bool acceso = m_values.value(key) == QLatin1String("on");
|
||||
m_values.insert(key, acceso ? QString() : QStringLiteral("on"));
|
||||
rerender();
|
||||
}
|
||||
|
||||
void EngineView::setCaret(int pos)
|
||||
{
|
||||
if (m_caret == pos) {
|
||||
return;
|
||||
}
|
||||
m_caret = pos;
|
||||
rerender();
|
||||
}
|
||||
|
||||
void EngineView::setSelection(int inizio, int fine)
|
||||
{
|
||||
if (m_selectionStart == inizio && m_selectionEnd == fine) {
|
||||
return;
|
||||
}
|
||||
m_selectionStart = inizio;
|
||||
m_selectionEnd = fine;
|
||||
rerender();
|
||||
}
|
||||
|
||||
void EngineView::setOpenSelect(const QString &key)
|
||||
{
|
||||
qDebug() << "mosaic: setOpenSelect" << key;
|
||||
if (m_openSelect == key) {
|
||||
return;
|
||||
}
|
||||
m_openSelect = key;
|
||||
rerender();
|
||||
}
|
||||
|
||||
void EngineView::chooseOption(const QString &key, int index)
|
||||
{
|
||||
qDebug() << "mosaic: chooseOption" << key << index;
|
||||
for (const QVariant &v : m_controls) {
|
||||
const QVariantMap m = v.toMap();
|
||||
if (m.value(QStringLiteral("key")).toString() != key) {
|
||||
continue;
|
||||
}
|
||||
const QVariantList valori = m.value(QStringLiteral("values")).toList();
|
||||
if (index >= 0 && index < valori.size()) {
|
||||
m_values.insert(key, valori.at(index).toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
m_openSelect.clear();
|
||||
rerender();
|
||||
}
|
||||
|
||||
QString EngineView::textOf(const QString &key) const
|
||||
{
|
||||
for (const QVariant &v : m_controls) {
|
||||
const QVariantMap m = v.toMap();
|
||||
if (m.value(QStringLiteral("key")).toString() == key) {
|
||||
return m.value(QStringLiteral("text")).toString();
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void EngineView::toggleSelect(const QString &key)
|
||||
{
|
||||
const QString nuovo = (m_openSelect == key) ? QString() : key;
|
||||
qDebug() << "mosaic: toggleSelect" << key << "->" << nuovo;
|
||||
setOpenSelect(nuovo);
|
||||
}
|
||||
|
||||
void EngineView::fetchDone(const QString &html, const QString &errore, int stato)
|
||||
{
|
||||
if (!errore.isEmpty()) {
|
||||
m_networkError = stato > 0
|
||||
? tr("HTTP %1: %2").arg(stato).arg(errore)
|
||||
: errore;
|
||||
m_loadState = 3;
|
||||
emit loadStateChanged();
|
||||
return;
|
||||
}
|
||||
setHtml(html);
|
||||
m_loadState = 2;
|
||||
emit loadStateChanged();
|
||||
}
|
||||
|
||||
void EngineView::loadUrl(const QString &url)
|
||||
{
|
||||
const QString indirizzo = url.trimmed();
|
||||
if (indirizzo.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!indirizzo.startsWith(QLatin1String("http://"))
|
||||
&& !indirizzo.startsWith(QLatin1String("https://"))) {
|
||||
m_networkError = tr("Indirizzo non valido: servono http:// o https://");
|
||||
m_loadState = 3;
|
||||
emit loadStateChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
m_url = indirizzo;
|
||||
m_networkError.clear();
|
||||
m_loadState = 1;
|
||||
emit urlChanged();
|
||||
emit loadStateChanged();
|
||||
|
||||
// la richiesta gira fuori dal thread grafico; il risultato torna via coda
|
||||
auto vivo = m_vivo;
|
||||
QPointer<EngineView> self(this);
|
||||
const std::string u = indirizzo.toStdString();
|
||||
std::thread([self, vivo, u]() {
|
||||
std::string html;
|
||||
std::string errore;
|
||||
int stato = 0;
|
||||
char *messaggio = nullptr;
|
||||
char *testo = engine_fetch(u.c_str(), &stato, &messaggio);
|
||||
if (testo) {
|
||||
html = testo;
|
||||
engine_string_free(testo);
|
||||
} else if (messaggio) {
|
||||
errore = messaggio;
|
||||
engine_string_free(messaggio);
|
||||
} else {
|
||||
errore = "richiesta fallita";
|
||||
}
|
||||
if (!vivo->load() || self.isNull()) {
|
||||
return; // il guscio non c'è più
|
||||
}
|
||||
// consegna per nome: la variante con lambda non c'è su tutte le Qt dell'SDK
|
||||
QMetaObject::invokeMethod(self.data(),
|
||||
"fetchDone",
|
||||
Qt::QueuedConnection,
|
||||
Q_ARG(QString, QString::fromStdString(html)),
|
||||
Q_ARG(QString, QString::fromStdString(errore)),
|
||||
Q_ARG(int, stato));
|
||||
}).detach();
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
#ifndef ENGINEVIEW_H
|
||||
#define ENGINEVIEW_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QImage>
|
||||
#include <QQuickPaintedItem>
|
||||
#include <QString>
|
||||
#include <QVariantList>
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
/* Elemento QML che presenta il raster prodotto dal motore.
|
||||
*
|
||||
* `zoom` è il fattore CSS -> dispositivo: il motore impagina con un viewport CSS
|
||||
* largo `width() / zoom` e rasterizza a `zoom`, quindi il testo resta nitido
|
||||
* (si scala la geometria, non l'immagine). Con l'altezza automatica l'immagine
|
||||
* copre tutto il documento e il guscio la scorre.
|
||||
*
|
||||
* Il motore è sincrono e veloce su documenti piccoli: M0 lo chiama sul thread
|
||||
* grafico. Con la rete (M1) la chiamata passerà a un thread dedicato con
|
||||
* consegna via coda: la superficie QML non cambia.
|
||||
*/
|
||||
class EngineView : public QQuickPaintedItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged)
|
||||
Q_PROPERTY(QString extraCss READ extraCss WRITE setExtraCss NOTIFY extraCssChanged)
|
||||
Q_PROPERTY(QString lastError READ lastError NOTIFY lastErrorChanged)
|
||||
Q_PROPERTY(int renderMs READ renderMs NOTIFY renderMsChanged)
|
||||
Q_PROPERTY(qreal zoom READ zoom WRITE setZoom NOTIFY zoomChanged)
|
||||
Q_PROPERTY(int contentHeight READ contentHeight NOTIFY contentChanged)
|
||||
Q_PROPERTY(int contentWidth READ contentWidth NOTIFY contentChanged)
|
||||
/// chiave del controllo che ha il fuoco ("" se nessuno)
|
||||
Q_PROPERTY(QString focusedKey READ focusedKey NOTIFY focusedKeyChanged)
|
||||
/// controlli del documento: [{key, kind, x, y, w, h}] in pixel CSS
|
||||
Q_PROPERTY(QVariantList controls READ controls NOTIFY controlsChanged)
|
||||
/// indirizzo dell'ultima richiesta ("" se il contenuto è locale)
|
||||
Q_PROPERTY(QString url READ url NOTIFY urlChanged)
|
||||
/// 0 fermo · 1 in caricamento · 2 riuscito · 3 errore
|
||||
Q_PROPERTY(int loadState READ loadState NOTIFY loadStateChanged)
|
||||
/// messaggio dell'ultimo errore di rete
|
||||
Q_PROPERTY(QString networkError READ networkError NOTIFY loadStateChanged)
|
||||
|
||||
public:
|
||||
explicit EngineView(QQuickItem *parent = nullptr);
|
||||
~EngineView() override;
|
||||
|
||||
void paint(QPainter *painter) override;
|
||||
|
||||
QString html() const { return m_html; }
|
||||
void setHtml(const QString &html);
|
||||
|
||||
QString extraCss() const { return m_css; }
|
||||
void setExtraCss(const QString &css);
|
||||
|
||||
QString lastError() const { return m_error; }
|
||||
int renderMs() const { return m_renderMs; }
|
||||
|
||||
qreal zoom() const { return m_zoom; }
|
||||
void setZoom(qreal zoom);
|
||||
|
||||
int contentHeight() const { return m_image.isNull() ? 0 : m_image.height(); }
|
||||
int contentWidth() const { return m_image.isNull() ? 0 : m_image.width(); }
|
||||
|
||||
/// Scarica l'indirizzo e lo impagina. La richiesta gira su un thread a parte:
|
||||
/// il thread grafico non si blocca e la finestra resta viva durante l'attesa.
|
||||
Q_INVOKABLE void loadUrl(const QString &url);
|
||||
/// come `loadUrl`, ma solo se l'indirizzo è http/https
|
||||
QString url() const { return m_url; }
|
||||
int loadState() const { return m_loadState; }
|
||||
QString networkError() const { return m_networkError; }
|
||||
|
||||
/// Chiave del controllo sotto il punto indicato (pixel CSS), "" se nessuno.
|
||||
Q_INVOKABLE QString controlAt(qreal cssX, qreal cssY) const;
|
||||
Q_INVOKABLE QString kindOf(const QString &key) const;
|
||||
Q_INVOKABLE QString value(const QString &key) const;
|
||||
/// vero se il controllo ha un valore già impostato dal guscio (anche vuoto)
|
||||
Q_INVOKABLE bool hasValue(const QString &key) const { return m_values.contains(key); }
|
||||
/// testo mostrato dal controllo (valore dell'HTML se non è stato modificato)
|
||||
Q_INVOKABLE QString textOf(const QString &key) const;
|
||||
Q_INVOKABLE void setValue(const QString &key, const QString &value);
|
||||
Q_INVOKABLE void setFocus(const QString &key);
|
||||
Q_INVOKABLE void toggle(const QString &key);
|
||||
/// posizione del cursore (caratteri, -1 per nasconderlo) e intervallo selezionato
|
||||
Q_INVOKABLE void setCaret(int pos);
|
||||
Q_INVOKABLE void setSelection(int inizio, int fine);
|
||||
Q_INVOKABLE int caret() const { return m_caret; }
|
||||
/// apre/chiude l'elenco di un `select` ("" per chiudere)
|
||||
Q_INVOKABLE void setOpenSelect(const QString &key);
|
||||
/// sceglie l'opzione `index` del `select` indicato e chiude l'elenco
|
||||
Q_INVOKABLE void chooseOption(const QString &key, int index);
|
||||
Q_INVOKABLE bool isSelectOpen(const QString &key) const { return m_openSelect == key; }
|
||||
/// inverte l'apertura dell'elenco: un solo posto tiene lo stato (qui, non in QML)
|
||||
Q_INVOKABLE void toggleSelect(const QString &key);
|
||||
|
||||
public slots:
|
||||
/// consegna del caricamento di rete, sempre sul thread grafico
|
||||
void fetchDone(const QString &html, const QString &errore, int stato);
|
||||
|
||||
signals:
|
||||
void focusedKeyChanged();
|
||||
void controlsChanged();
|
||||
void htmlChanged();
|
||||
void extraCssChanged();
|
||||
void lastErrorChanged();
|
||||
void renderMsChanged();
|
||||
void zoomChanged();
|
||||
void contentChanged();
|
||||
|
||||
protected:
|
||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
|
||||
|
||||
signals:
|
||||
void urlChanged();
|
||||
void loadStateChanged();
|
||||
|
||||
private:
|
||||
QString m_url;
|
||||
int m_loadState = 0;
|
||||
QString m_networkError;
|
||||
/// vivo finché l'oggetto esiste: un thread in corso lo controlla prima di consegnare
|
||||
std::shared_ptr<std::atomic<bool>> m_vivo;
|
||||
void rerender();
|
||||
void setError(const QString &error);
|
||||
QString resolveFont() const;
|
||||
|
||||
QImage m_image;
|
||||
QString m_html;
|
||||
QString m_css;
|
||||
QString m_error;
|
||||
QString m_fontPath;
|
||||
/// cartella per risolvere i `src` relativi delle immagini
|
||||
QString m_baseDir;
|
||||
qreal m_zoom = 2.0;
|
||||
int m_renderMs = 0;
|
||||
/// valori digitati nei moduli e chiave con il fuoco
|
||||
QHash<QString, QString> m_values;
|
||||
QString m_focus;
|
||||
int m_caret = -1;
|
||||
int m_selectionStart = -1;
|
||||
int m_selectionEnd = -1;
|
||||
QString m_openSelect;
|
||||
QVariantList m_controls;
|
||||
QString stateJson() const;
|
||||
QString focusedKey() const { return m_focus; }
|
||||
QVariantList controls() const { return m_controls; }
|
||||
};
|
||||
|
||||
#endif // ENGINEVIEW_H
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <sailfishapp.h>
|
||||
#include <QtQml>
|
||||
#include <QtQuick>
|
||||
|
||||
#include "appsettings.h"
|
||||
#include "engineview.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
|
||||
app->setOrganizationName(QStringLiteral("harbour"));
|
||||
app->setApplicationName(QStringLiteral("harbour-mosaic"));
|
||||
|
||||
QScopedPointer<QQuickView> view(SailfishApp::createView());
|
||||
qmlRegisterType<EngineView>("Harbour.Mosaic", 1, 0, "EngineView");
|
||||
|
||||
// Context property: le pagine aperte da pageStack non vedono le proprietà
|
||||
// dell'ApplicationWindow, quindi le impostazioni si passano da qui.
|
||||
AppSettings settings;
|
||||
view->rootContext()->setContextProperty(QStringLiteral("appSettings"), &settings);
|
||||
|
||||
// pathTo: un QUrl relativo si risolve sulla CWD, che dal launcher non è la
|
||||
// cartella dell'app — il QML non caricherebbe e la pagina sarebbe bianca.
|
||||
view->setSource(SailfishApp::pathTo(QStringLiteral("qml/harbour-mosaic.qml")));
|
||||
view->show();
|
||||
return app->exec();
|
||||
}
|
||||
Reference in new issue
Block a user