Added more settings
This commit is contained in:
6 files changed
+266
-72
No files matched your search
@@ -64,14 +64,44 @@ void AppState::setLastScrollOffset(qreal offset)
|
||||
emit lastScrollOffsetChanged();
|
||||
}
|
||||
|
||||
QString AppState::pageFlipMode() const { return m_pageFlipMode; }
|
||||
int AppState::horizontalMargin() const { return m_horizontalMargin; }
|
||||
|
||||
void AppState::setPageFlipMode(const QString &mode)
|
||||
void AppState::setHorizontalMargin(int margin)
|
||||
{
|
||||
if (m_pageFlipMode == mode)
|
||||
if (m_horizontalMargin == margin)
|
||||
return;
|
||||
m_pageFlipMode = mode;
|
||||
emit pageFlipModeChanged();
|
||||
m_horizontalMargin = margin;
|
||||
emit horizontalMarginChanged();
|
||||
}
|
||||
|
||||
int AppState::verticalMargin() const { return m_verticalMargin; }
|
||||
|
||||
void AppState::setVerticalMargin(int margin)
|
||||
{
|
||||
if (m_verticalMargin == margin)
|
||||
return;
|
||||
m_verticalMargin = margin;
|
||||
emit verticalMarginChanged();
|
||||
}
|
||||
|
||||
int AppState::fontSize() const { return m_fontSize; }
|
||||
|
||||
void AppState::setFontSize(int size)
|
||||
{
|
||||
if (m_fontSize == size)
|
||||
return;
|
||||
m_fontSize = size;
|
||||
emit fontSizeChanged();
|
||||
}
|
||||
|
||||
qreal AppState::lineSpacing() const { return m_lineSpacing; }
|
||||
|
||||
void AppState::setLineSpacing(qreal spacing)
|
||||
{
|
||||
if (qFuzzyCompare(m_lineSpacing, spacing))
|
||||
return;
|
||||
m_lineSpacing = spacing;
|
||||
emit lineSpacingChanged();
|
||||
}
|
||||
|
||||
int AppState::windowWidth() const { return m_windowWidth; }
|
||||
@@ -250,7 +280,10 @@ void AppState::save()
|
||||
s.setValue(QStringLiteral("session/lastScrollOffset"), m_lastScrollOffset);
|
||||
s.setValue(QStringLiteral("session/lastPage"), m_lastPage);
|
||||
s.setValue(QStringLiteral("session/sidebarOpen"), m_sidebarOpen);
|
||||
s.setValue(QStringLiteral("preferences/pageFlipMode"), m_pageFlipMode);
|
||||
s.setValue(QStringLiteral("preferences/horizontalMargin"), m_horizontalMargin);
|
||||
s.setValue(QStringLiteral("preferences/verticalMargin"), m_verticalMargin);
|
||||
s.setValue(QStringLiteral("preferences/fontSize"), m_fontSize);
|
||||
s.setValue(QStringLiteral("preferences/lineSpacing"), m_lineSpacing);
|
||||
s.setValue(QStringLiteral("window/width"), m_windowWidth);
|
||||
s.setValue(QStringLiteral("window/height"), m_windowHeight);
|
||||
s.setValue(QStringLiteral("window/x"), m_windowX);
|
||||
@@ -268,7 +301,10 @@ void AppState::restore()
|
||||
m_lastScrollOffset = s.value(QStringLiteral("session/lastScrollOffset"), 0.0).toDouble();
|
||||
m_lastPage = s.value(QStringLiteral("session/lastPage"), QStringLiteral("starter")).toString();
|
||||
m_sidebarOpen = s.value(QStringLiteral("session/sidebarOpen"), false).toBool();
|
||||
m_pageFlipMode = s.value(QStringLiteral("preferences/pageFlipMode"), QStringLiteral("scroll")).toString();
|
||||
m_horizontalMargin = s.value(QStringLiteral("preferences/horizontalMargin"), 32).toInt();
|
||||
m_verticalMargin = s.value(QStringLiteral("preferences/verticalMargin"), 8).toInt();
|
||||
m_fontSize = s.value(QStringLiteral("preferences/fontSize"), 16).toInt();
|
||||
m_lineSpacing = s.value(QStringLiteral("preferences/lineSpacing"), 1.6).toDouble();
|
||||
m_windowWidth = s.value(QStringLiteral("window/width"), 1024).toInt();
|
||||
m_windowHeight = s.value(QStringLiteral("window/height"), 768).toInt();
|
||||
m_windowX = s.value(QStringLiteral("window/x"), -1).toInt();
|
||||
|
||||
+23
-5
@@ -14,7 +14,10 @@ class AppState : public QObject {
|
||||
Q_PROPERTY(qreal lastScrollPosition READ lastScrollPosition WRITE setLastScrollPosition NOTIFY lastScrollPositionChanged)
|
||||
Q_PROPERTY(int lastScrollIndex READ lastScrollIndex WRITE setLastScrollIndex NOTIFY lastScrollIndexChanged)
|
||||
Q_PROPERTY(qreal lastScrollOffset READ lastScrollOffset WRITE setLastScrollOffset NOTIFY lastScrollOffsetChanged)
|
||||
Q_PROPERTY(QString pageFlipMode READ pageFlipMode WRITE setPageFlipMode NOTIFY pageFlipModeChanged)
|
||||
Q_PROPERTY(int horizontalMargin READ horizontalMargin WRITE setHorizontalMargin NOTIFY horizontalMarginChanged)
|
||||
Q_PROPERTY(int verticalMargin READ verticalMargin WRITE setVerticalMargin NOTIFY verticalMarginChanged)
|
||||
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
|
||||
Q_PROPERTY(qreal lineSpacing READ lineSpacing WRITE setLineSpacing NOTIFY lineSpacingChanged)
|
||||
Q_PROPERTY(int windowWidth READ windowWidth WRITE setWindowWidth NOTIFY windowWidthChanged)
|
||||
Q_PROPERTY(int windowHeight READ windowHeight WRITE setWindowHeight NOTIFY windowHeightChanged)
|
||||
Q_PROPERTY(int windowX READ windowX WRITE setWindowX NOTIFY windowXChanged)
|
||||
@@ -41,8 +44,17 @@ public:
|
||||
qreal lastScrollOffset() const;
|
||||
void setLastScrollOffset(qreal offset);
|
||||
|
||||
QString pageFlipMode() const;
|
||||
void setPageFlipMode(const QString &mode);
|
||||
int horizontalMargin() const;
|
||||
void setHorizontalMargin(int margin);
|
||||
|
||||
int verticalMargin() const;
|
||||
void setVerticalMargin(int margin);
|
||||
|
||||
int fontSize() const;
|
||||
void setFontSize(int size);
|
||||
|
||||
qreal lineSpacing() const;
|
||||
void setLineSpacing(qreal spacing);
|
||||
|
||||
int windowWidth() const;
|
||||
void setWindowWidth(int width);
|
||||
@@ -80,7 +92,10 @@ signals:
|
||||
void lastScrollPositionChanged();
|
||||
void lastScrollIndexChanged();
|
||||
void lastScrollOffsetChanged();
|
||||
void pageFlipModeChanged();
|
||||
void horizontalMarginChanged();
|
||||
void verticalMarginChanged();
|
||||
void fontSizeChanged();
|
||||
void lineSpacingChanged();
|
||||
void stateRestored();
|
||||
void windowWidthChanged();
|
||||
void windowHeightChanged();
|
||||
@@ -98,7 +113,10 @@ private:
|
||||
qreal m_lastScrollPosition = 0.0;
|
||||
int m_lastScrollIndex = 0;
|
||||
qreal m_lastScrollOffset = 0.0;
|
||||
QString m_pageFlipMode = QStringLiteral("scroll");
|
||||
int m_horizontalMargin = 32;
|
||||
int m_verticalMargin = 8;
|
||||
int m_fontSize = 16;
|
||||
qreal m_lineSpacing = 1.6;
|
||||
int m_windowWidth = 1024;
|
||||
int m_windowHeight = 768;
|
||||
int m_windowX = -1;
|
||||
|
||||
@@ -99,14 +99,9 @@ void ReadingModel::setScrollInfo(int topChunkIndex, qreal offsetInChunk, bool at
|
||||
|
||||
void ReadingModel::computeChunkHeights()
|
||||
{
|
||||
// Text width matches the QML delegate:
|
||||
// ListView left margin: 12, delegate rightPadding: 2
|
||||
// delegate width = listView.width - 18 (hardcoded in QML)
|
||||
// text layout width = delegate.width - rightPadding = listView.width - 20
|
||||
// m_viewportWidth = chunkListView.width = parent.width - leftMargin(12)
|
||||
// so delegate.width = m_viewportWidth - 18
|
||||
// text width = delegate.width - rightPadding(2) = m_viewportWidth - 20
|
||||
qreal textWidth = m_viewportWidth - 20.0;
|
||||
// Caller passes effective text width:
|
||||
// chunkListView.width - 18 (scrollbar) - 2 * horizontalMargin (delegate padding)
|
||||
qreal textWidth = m_viewportWidth;
|
||||
if (textWidth <= 0)
|
||||
textWidth = 1;
|
||||
|
||||
|
||||
@@ -16,18 +16,20 @@ Rectangle {
|
||||
ListView {
|
||||
id: chunkListView
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: 12
|
||||
anchors.topMargin: appState.verticalMargin
|
||||
anchors.bottomMargin: appState.verticalMargin
|
||||
model: bookController.hasBook ? readingModel : null
|
||||
cacheBuffer: 2000
|
||||
clip: true
|
||||
|
||||
delegate: Text {
|
||||
width: ListView.view.width - 18
|
||||
rightPadding: 2
|
||||
leftPadding: appState.horizontalMargin
|
||||
rightPadding: appState.horizontalMargin
|
||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
||||
textFormat: Text.RichText
|
||||
font.pixelSize: 16
|
||||
lineHeight: 1.6
|
||||
font.pixelSize: appState.fontSize
|
||||
lineHeight: appState.lineSpacing
|
||||
color: Theme.readingText
|
||||
text: model.content
|
||||
}
|
||||
@@ -76,7 +78,7 @@ Rectangle {
|
||||
interval: 50
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
readingModel.setViewportSize(chunkListView.width, chunkListView.height)
|
||||
readingModel.setViewportSize(chunkListView.width - 18 - 2 * appState.horizontalMargin, chunkListView.height)
|
||||
var idx = chunkListView.indexAt(0, chunkListView.contentY)
|
||||
if (idx >= 0) {
|
||||
var item = chunkListView.itemAtIndex(idx)
|
||||
@@ -122,7 +124,7 @@ Rectangle {
|
||||
chunkListView.positionViewAtIndex(savedScrollIndex, ListView.Beginning)
|
||||
chunkListView.contentY += savedScrollOffset
|
||||
}
|
||||
readingModel.setViewportSize(chunkListView.width, chunkListView.height)
|
||||
readingModel.setViewportSize(chunkListView.width - 18 - 2 * appState.horizontalMargin, chunkListView.height)
|
||||
if (savedScrollIndex > 0) {
|
||||
var idx = chunkListView.indexAt(0, chunkListView.contentY)
|
||||
if (idx >= 0) {
|
||||
@@ -141,7 +143,7 @@ Rectangle {
|
||||
function onChapterChanged() {
|
||||
if (!_restoring) {
|
||||
Qt.callLater(function() {
|
||||
readingModel.setViewportSize(chunkListView.width, chunkListView.height)
|
||||
readingModel.setViewportSize(chunkListView.width - 18 - 2 * appState.horizontalMargin, chunkListView.height)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+135
-36
@@ -26,52 +26,151 @@ Rectangle {
|
||||
leftPadding: 4
|
||||
}
|
||||
|
||||
// Page flip mode selector
|
||||
// Horizontal margin slider
|
||||
Column {
|
||||
width: parent.width
|
||||
spacing: 0
|
||||
|
||||
Text {
|
||||
text: "Page flip"
|
||||
font.pixelSize: 15
|
||||
color: Theme.uiText
|
||||
bottomPadding: 12
|
||||
leftPadding: 4
|
||||
}
|
||||
|
||||
Row {
|
||||
spacing: 8
|
||||
|
||||
Repeater {
|
||||
model: [
|
||||
{ label: "Scroll", value: "scroll" },
|
||||
{ label: "Page", value: "page" }
|
||||
]
|
||||
|
||||
delegate: Rectangle {
|
||||
width: 100
|
||||
height: 40
|
||||
radius: 6
|
||||
color: appState.pageFlipMode === modelData.value
|
||||
? Theme.primaryAccent
|
||||
: Theme.surface
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: Math.max(labelH.implicitHeight, valueH.implicitHeight)
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: modelData.label
|
||||
font.pixelSize: 14
|
||||
color: appState.pageFlipMode === modelData.value
|
||||
? Theme.readingText
|
||||
: Theme.uiText
|
||||
id: labelH
|
||||
text: "Horizontal margin"
|
||||
font.pixelSize: 15
|
||||
color: Theme.uiText
|
||||
leftPadding: 4
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
Text {
|
||||
id: valueH
|
||||
text: appState.horizontalMargin + " px"
|
||||
font.pixelSize: 13
|
||||
color: Theme.dimText
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 4
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: appState.pageFlipMode = modelData.value
|
||||
Slider {
|
||||
width: parent.width
|
||||
from: 0
|
||||
to: 120
|
||||
stepSize: 1
|
||||
value: appState.horizontalMargin
|
||||
onValueChanged: appState.horizontalMargin = value
|
||||
}
|
||||
}
|
||||
|
||||
// Vertical margin slider
|
||||
Column {
|
||||
width: parent.width
|
||||
spacing: 8
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: Math.max(labelV.implicitHeight, valueV.implicitHeight)
|
||||
Text {
|
||||
id: labelV
|
||||
text: "Vertical margin"
|
||||
font.pixelSize: 15
|
||||
color: Theme.uiText
|
||||
leftPadding: 4
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
Text {
|
||||
id: valueV
|
||||
text: appState.verticalMargin + " px"
|
||||
font.pixelSize: 13
|
||||
color: Theme.dimText
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 4
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
|
||||
Slider {
|
||||
width: parent.width
|
||||
from: 0
|
||||
to: 80
|
||||
stepSize: 1
|
||||
value: appState.verticalMargin
|
||||
onValueChanged: appState.verticalMargin = value
|
||||
}
|
||||
}
|
||||
|
||||
// Font size slider
|
||||
Column {
|
||||
width: parent.width
|
||||
spacing: 8
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: Math.max(labelF.implicitHeight, valueF.implicitHeight)
|
||||
Text {
|
||||
id: labelF
|
||||
text: "Font size"
|
||||
font.pixelSize: 15
|
||||
color: Theme.uiText
|
||||
leftPadding: 4
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
Text {
|
||||
id: valueF
|
||||
text: appState.fontSize + " px"
|
||||
font.pixelSize: 13
|
||||
color: Theme.dimText
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 4
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
|
||||
Slider {
|
||||
width: parent.width
|
||||
from: 10
|
||||
to: 32
|
||||
stepSize: 1
|
||||
value: appState.fontSize
|
||||
onValueChanged: appState.fontSize = value
|
||||
}
|
||||
}
|
||||
|
||||
// Line spacing slider
|
||||
Column {
|
||||
width: parent.width
|
||||
spacing: 8
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: Math.max(labelL.implicitHeight, valueL.implicitHeight)
|
||||
Text {
|
||||
id: labelL
|
||||
text: "Line spacing"
|
||||
font.pixelSize: 15
|
||||
color: Theme.uiText
|
||||
leftPadding: 4
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
Text {
|
||||
id: valueL
|
||||
text: appState.lineSpacing.toFixed(1) + "×"
|
||||
font.pixelSize: 13
|
||||
color: Theme.dimText
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 4
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
|
||||
Slider {
|
||||
width: parent.width
|
||||
from: 0.5
|
||||
to: 3.0
|
||||
stepSize: 0.1
|
||||
value: appState.lineSpacing
|
||||
onValueChanged: appState.lineSpacing = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+53
-9
@@ -78,16 +78,42 @@ private slots:
|
||||
QCOMPARE(state2.lastScrollOffset(), 123.75);
|
||||
}
|
||||
|
||||
void saveAndRestorePageFlipMode()
|
||||
void saveAndRestoreMargins()
|
||||
{
|
||||
{
|
||||
AppState state;
|
||||
state.setPageFlipMode(QStringLiteral("page"));
|
||||
state.setHorizontalMargin(64);
|
||||
state.setVerticalMargin(24);
|
||||
state.save();
|
||||
}
|
||||
AppState state2;
|
||||
state2.restore();
|
||||
QCOMPARE(state2.pageFlipMode(), QStringLiteral("page"));
|
||||
QCOMPARE(state2.horizontalMargin(), 64);
|
||||
QCOMPARE(state2.verticalMargin(), 24);
|
||||
}
|
||||
|
||||
void saveAndRestoreFontSize()
|
||||
{
|
||||
{
|
||||
AppState state;
|
||||
state.setFontSize(22);
|
||||
state.save();
|
||||
}
|
||||
AppState state2;
|
||||
state2.restore();
|
||||
QCOMPARE(state2.fontSize(), 22);
|
||||
}
|
||||
|
||||
void saveAndRestoreLineSpacing()
|
||||
{
|
||||
{
|
||||
AppState state;
|
||||
state.setLineSpacing(2.0);
|
||||
state.save();
|
||||
}
|
||||
AppState state2;
|
||||
state2.restore();
|
||||
QCOMPARE(state2.lineSpacing(), 2.0);
|
||||
}
|
||||
|
||||
void saveAndRestoreWindowGeometry()
|
||||
@@ -117,7 +143,10 @@ private slots:
|
||||
QCOMPARE(state.lastScrollPosition(), 0.0);
|
||||
QCOMPARE(state.lastScrollIndex(), 0);
|
||||
QCOMPARE(state.lastScrollOffset(), 0.0);
|
||||
QCOMPARE(state.pageFlipMode(), QStringLiteral("scroll"));
|
||||
QCOMPARE(state.horizontalMargin(), 32);
|
||||
QCOMPARE(state.verticalMargin(), 8);
|
||||
QCOMPARE(state.fontSize(), 16);
|
||||
QCOMPARE(state.lineSpacing(), 1.6);
|
||||
QCOMPARE(state.windowWidth(), 1024);
|
||||
QCOMPARE(state.windowHeight(), 768);
|
||||
QCOMPARE(state.windowX(), -1);
|
||||
@@ -132,7 +161,10 @@ private slots:
|
||||
QSignalSpy spyScroll(&state, &AppState::lastScrollPositionChanged);
|
||||
QSignalSpy spyScrollIndex(&state, &AppState::lastScrollIndexChanged);
|
||||
QSignalSpy spyScrollOffset(&state, &AppState::lastScrollOffsetChanged);
|
||||
QSignalSpy spyFlip(&state, &AppState::pageFlipModeChanged);
|
||||
QSignalSpy spyHMargin(&state, &AppState::horizontalMarginChanged);
|
||||
QSignalSpy spyVMargin(&state, &AppState::verticalMarginChanged);
|
||||
QSignalSpy spyFontSize(&state, &AppState::fontSizeChanged);
|
||||
QSignalSpy spyLineSpacing(&state, &AppState::lineSpacingChanged);
|
||||
QSignalSpy spyWidth(&state, &AppState::windowWidthChanged);
|
||||
QSignalSpy spyHeight(&state, &AppState::windowHeightChanged);
|
||||
QSignalSpy spyX(&state, &AppState::windowXChanged);
|
||||
@@ -143,7 +175,10 @@ private slots:
|
||||
state.setLastScrollPosition(10.5);
|
||||
state.setLastScrollIndex(7);
|
||||
state.setLastScrollOffset(55.25);
|
||||
state.setPageFlipMode(QStringLiteral("page"));
|
||||
state.setHorizontalMargin(64);
|
||||
state.setVerticalMargin(24);
|
||||
state.setFontSize(20);
|
||||
state.setLineSpacing(2.0);
|
||||
state.setWindowWidth(800);
|
||||
state.setWindowHeight(600);
|
||||
state.setWindowX(200);
|
||||
@@ -154,7 +189,10 @@ private slots:
|
||||
QCOMPARE(spyScroll.count(), 1);
|
||||
QCOMPARE(spyScrollIndex.count(), 1);
|
||||
QCOMPARE(spyScrollOffset.count(), 1);
|
||||
QCOMPARE(spyFlip.count(), 1);
|
||||
QCOMPARE(spyHMargin.count(), 1);
|
||||
QCOMPARE(spyVMargin.count(), 1);
|
||||
QCOMPARE(spyFontSize.count(), 1);
|
||||
QCOMPARE(spyLineSpacing.count(), 1);
|
||||
QCOMPARE(spyWidth.count(), 1);
|
||||
QCOMPARE(spyHeight.count(), 1);
|
||||
QCOMPARE(spyX.count(), 1);
|
||||
@@ -219,7 +257,10 @@ private slots:
|
||||
QSignalSpy spyScroll(&state, &AppState::lastScrollPositionChanged);
|
||||
QSignalSpy spyScrollIndex(&state, &AppState::lastScrollIndexChanged);
|
||||
QSignalSpy spyScrollOffset(&state, &AppState::lastScrollOffsetChanged);
|
||||
QSignalSpy spyFlip(&state, &AppState::pageFlipModeChanged);
|
||||
QSignalSpy spyHMargin(&state, &AppState::horizontalMarginChanged);
|
||||
QSignalSpy spyVMargin(&state, &AppState::verticalMarginChanged);
|
||||
QSignalSpy spyFontSize(&state, &AppState::fontSizeChanged);
|
||||
QSignalSpy spyLineSpacing(&state, &AppState::lineSpacingChanged);
|
||||
QSignalSpy spyWidth(&state, &AppState::windowWidthChanged);
|
||||
QSignalSpy spyHeight(&state, &AppState::windowHeightChanged);
|
||||
QSignalSpy spyX(&state, &AppState::windowXChanged);
|
||||
@@ -233,7 +274,10 @@ private slots:
|
||||
QCOMPARE(spyScroll.count(), 0);
|
||||
QCOMPARE(spyScrollIndex.count(), 0);
|
||||
QCOMPARE(spyScrollOffset.count(), 0);
|
||||
QCOMPARE(spyFlip.count(), 0);
|
||||
QCOMPARE(spyHMargin.count(), 0);
|
||||
QCOMPARE(spyVMargin.count(), 0);
|
||||
QCOMPARE(spyFontSize.count(), 0);
|
||||
QCOMPARE(spyLineSpacing.count(), 0);
|
||||
QCOMPARE(spyWidth.count(), 0);
|
||||
QCOMPARE(spyHeight.count(), 0);
|
||||
QCOMPARE(spyX.count(), 0);
|
||||
|
||||
Reference in new issue
Block a user