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,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