Margini alto/basso (Settings.readerMarginV) + applicazione a caldo senza reload: i margini si sovrascrivono via runJavaScript (setProperty !important) sul documento aperto, anteprima live nel dialogo e al ritorno dalle impostazioni
This commit is contained in:
+7
-4
@@ -406,7 +406,7 @@ QVariantList EpubBook::chapterList() const
|
||||
return list;
|
||||
}
|
||||
|
||||
QString EpubBook::chapterHtml(int index, int fontSizePx, int marginPx) const
|
||||
QString EpubBook::chapterHtml(int index, int fontSizePx, int marginPx, int marginVerticalPx) const
|
||||
{
|
||||
if (index < 0 || index >= m_chapters.size())
|
||||
return QString();
|
||||
@@ -415,12 +415,15 @@ QString EpubBook::chapterHtml(int index, int fontSizePx, int marginPx) const
|
||||
return QString();
|
||||
QString html = QString::fromUtf8(f.readAll());
|
||||
|
||||
// stile di reflow iniettato nel documento: !important vince sui CSS del libro
|
||||
// stile di reflow iniettato nel documento: !important vince sui CSS del libro.
|
||||
// I margini si possono aggiornare a caldo via runJavaScript (setProperty con
|
||||
// 'important' inline), senza ricaricare il capitolo.
|
||||
const QString style = QStringLiteral(
|
||||
"<style id=\"cw-font\">html,body{font-size:%1px!important;"
|
||||
"margin-left:%2px!important;margin-right:%2px!important}"
|
||||
"margin-left:%2px!important;margin-right:%2px!important;"
|
||||
"margin-top:%3px!important;margin-bottom:%3px!important}"
|
||||
"p,div,li,td,blockquote,section{font-size:1em!important}</style>")
|
||||
.arg(fontSizePx).arg(marginPx);
|
||||
.arg(fontSizePx).arg(marginPx).arg(marginVerticalPx);
|
||||
const int headEnd = html.indexOf(QStringLiteral("</head>"), 0, Qt::CaseInsensitive);
|
||||
if (headEnd >= 0)
|
||||
html.insert(headEnd, style);
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public:
|
||||
// elenco [{index, title}] per la lista capitoli
|
||||
Q_INVOKABLE QVariantList chapterList() const;
|
||||
// HTML del capitolo con lo stile di reflow iniettato (font-size e margini in px)
|
||||
Q_INVOKABLE QString chapterHtml(int index, int fontSizePx, int marginPx) const;
|
||||
Q_INVOKABLE QString chapterHtml(int index, int fontSizePx, int marginPx, int marginVerticalPx) const;
|
||||
// base URL (file://) per risolvere immagini/CSS relativi del capitolo
|
||||
Q_INVOKABLE QString chapterBaseUrl(int index) const;
|
||||
|
||||
|
||||
+16
-1
@@ -11,7 +11,8 @@ Settings::Settings(QObject *parent)
|
||||
// diagnostica: path reale del file di configurazione e valori letti all'avvio
|
||||
qDebug() << "Settings file:" << m_settings.fileName();
|
||||
qDebug() << "Settings read: serverUrl=[" << serverUrl() << "] user=[" << username()
|
||||
<< "] ssl=" << ignoreSslErrors() << "margin=" << readerMargin();
|
||||
<< "] ssl=" << ignoreSslErrors() << "margin=" << readerMargin()
|
||||
<< "marginV=" << readerMarginV();
|
||||
}
|
||||
|
||||
QString Settings::serverUrl() const
|
||||
@@ -85,6 +86,20 @@ void Settings::setReaderMargin(int value)
|
||||
emit readerMarginChanged();
|
||||
}
|
||||
|
||||
int Settings::readerMarginV() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral("readerMarginV"), 0).toInt();
|
||||
}
|
||||
|
||||
void Settings::setReaderMarginV(int value)
|
||||
{
|
||||
if (value == readerMarginV())
|
||||
return;
|
||||
m_settings.setValue(QStringLiteral("readerMarginV"), value);
|
||||
m_settings.sync();
|
||||
emit readerMarginVChanged();
|
||||
}
|
||||
|
||||
QString Settings::downloadDir() const
|
||||
{
|
||||
QString dir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||
|
||||
@@ -13,6 +13,7 @@ class Settings : public QObject
|
||||
Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
|
||||
Q_PROPERTY(bool ignoreSslErrors READ ignoreSslErrors WRITE setIgnoreSslErrors NOTIFY ignoreSslErrorsChanged)
|
||||
Q_PROPERTY(int readerMargin READ readerMargin WRITE setReaderMargin NOTIFY readerMarginChanged)
|
||||
Q_PROPERTY(int readerMarginV READ readerMarginV WRITE setReaderMarginV NOTIFY readerMarginVChanged)
|
||||
Q_PROPERTY(QString downloadDir READ downloadDir CONSTANT)
|
||||
// derivata da serverUrl (senza slash finale): accesso QML come appSettings.baseUrl
|
||||
Q_PROPERTY(QString baseUrl READ baseUrl NOTIFY baseUrlChanged)
|
||||
@@ -36,6 +37,10 @@ public:
|
||||
int readerMargin() const;
|
||||
void setReaderMargin(int value);
|
||||
|
||||
// margine verticale (alto e basso, simmetrico) del testo nel lettore, in px
|
||||
int readerMarginV() const;
|
||||
void setReaderMarginV(int value);
|
||||
|
||||
QString downloadDir() const;
|
||||
|
||||
// Header "Authorization: Basic ..." pronto da usare, vuoto se utente non impostato
|
||||
@@ -57,6 +62,7 @@ signals:
|
||||
void passwordChanged();
|
||||
void ignoreSslErrorsChanged();
|
||||
void readerMarginChanged();
|
||||
void readerMarginVChanged();
|
||||
void baseUrlChanged();
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user