[app] Made night mode brightness configurable

Brightness control is implemented by rendering content with transparent
background, providing background as a separate item behind the content
and adjusting opacity of the content item according to the selected
brightness.
This commit is contained in:
Slava Monich 2020-09-20 19:15:45 +03:00
parent 09c5f99e11
commit e4cbab0301
14 changed files with 364 additions and 202 deletions

View file

@ -53,6 +53,7 @@ OTHER_FILES += \
icons/harbour-books.svg \ icons/harbour-books.svg \
harbour-books.desktop \ harbour-books.desktop \
qml/*.qml \ qml/*.qml \
qml/*.js \
qml/images/* \ qml/images/* \
settings/*.qml \ settings/*.qml \
settings/*.json \ settings/*.json \

5
app/qml/Books.js Normal file
View file

@ -0,0 +1,5 @@
.pragma library
function contentOpacity(brightness) {
return 0.5 + brightness * 0.5
}

View file

@ -1,6 +1,6 @@
/* /*
Copyright (C) 2016 Jolla Ltd. Copyright (C) 2015-2020 Jolla Ltd.
Contact: Slava Monich <slava.monich@jolla.com> Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
You may use this file under the terms of BSD license as follows: You may use this file under the terms of BSD license as follows:
@ -8,14 +8,15 @@
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
* Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer
documentation and/or other materials provided with the distribution. in the documentation and/or other materials provided with the
* Neither the name of Jolla Ltd nor the names of its contributors may distribution.
be used to endorse or promote products derived from this software 3. Neither the names of the copyright holders nor the names of its
without specific prior written permission. contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -32,9 +33,13 @@
import QtQuick 2.0 import QtQuick 2.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import harbour.books 1.0
import "Books.js" as Books
Rectangle { Rectangle {
id: root id: root
visible: opacity > 0 visible: opacity > 0
opacity: 0.0 opacity: 0.0
anchors.fill: parent anchors.fill: parent
@ -47,7 +52,7 @@ Rectangle {
function show(startX,startY,text,url) { function show(startX,startY,text,url) {
flickable.scrollToTop() flickable.scrollToTop()
image.source = url content.source = url
if (state !== "show") { if (state !== "show") {
footnoteItem.scale = 0 footnoteItem.scale = 0
footnoteItem.x = startX footnoteItem.x = startX
@ -77,6 +82,7 @@ Rectangle {
Item { Item {
id: footnoteItem id: footnoteItem
x: footnoteX x: footnoteX
y: footnoteY y: footnoteY
width: footnote.width width: footnote.width
@ -85,42 +91,50 @@ Rectangle {
Label { Label {
id: footnoteLabel id: footnoteLabel
anchors {
top: parent.top
bottom: footnote.top
bottomMargin: Theme.paddingMedium
}
width: parent.width width: parent.width
height: Math.round(root.height - footnote.height/2) - 2*Theme.paddingMedium height: Math.round(root.height - footnote.height/2) - 2*Theme.paddingMedium
color: Theme.highlightColor color: Theme.highlightColor
verticalAlignment: Text.AlignBottom verticalAlignment: Text.AlignBottom
maximumLineCount: 4 maximumLineCount: 4
visible: opacity > 0 visible: opacity > 0
Behavior on opacity { FadeAnimation {} } Behavior on opacity { FadeAnimation {} }
anchors {
top: parent.top
bottom: footnote.top
bottomMargin: Theme.paddingMedium
}
} }
Rectangle { Rectangle {
id: footnote id: footnote
radius: Theme.paddingMedium/2 radius: Theme.paddingMedium/2
border.color: Settings.invertedPageBackgroundColor border.color: Settings.invertedPageBackgroundColor
color: Settings.pageBackgroundColor color: Settings.pageBackgroundColor
width: image.width + 2*Theme.paddingMedium width: content.width + 2*Theme.paddingMedium
height: Math.min(root.height/2, image.height + 2*Theme.paddingMedium) height: Math.min(root.height/2, content.height + 2*Theme.paddingMedium)
anchors { anchors.bottom: parent.bottom
bottom: parent.bottom
}
SilicaFlickable { SilicaFlickable {
id: flickable id: flickable
anchors { anchors {
fill: parent fill: parent
margins: Theme.paddingMedium margins: Theme.paddingMedium
} }
clip: true clip: true
contentWidth: image.width contentWidth: content.width
contentHeight: image.height contentHeight: content.height
Image { Image {
id: image id: content
opacity: Books.contentOpacity(Settings.brightness)
cache: false
} }
VerticalScrollDecorator {} VerticalScrollDecorator {}
} }
} }

View file

@ -35,9 +35,13 @@ import QtQuick 2.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import harbour.books 1.0 import harbour.books 1.0
Item { import "Books.js" as Books
Rectangle {
id: view id: view
color: Settings.pageBackgroundColor
property alias model: widget.model property alias model: widget.model
property alias page: widget.page property alias page: widget.page
property alias leftMargin: widget.leftMargin property alias leftMargin: widget.leftMargin
@ -62,9 +66,12 @@ Item {
PageWidget { PageWidget {
id: widget id: widget
anchors.fill: parent anchors.fill: parent
model: bookModel model: bookModel
pressed: mouseArea.pressed pressed: mouseArea.pressed
opacity: Books.contentOpacity(Settings.brightness)
onBrowserLinkPressed: view.browserLinkPressed(url) onBrowserLinkPressed: view.browserLinkPressed(url)
onImagePressed: view.imagePressed(imageId, rect) onImagePressed: view.imagePressed(imageId, rect)
onActiveTouch: pressImage.animate(touchX, touchY) onActiveTouch: pressImage.animate(touchX, touchY)
@ -75,6 +82,7 @@ Item {
BooksTitleLabel { BooksTitleLabel {
id: titleLabel id: titleLabel
anchors { anchors {
top: parent.top top: parent.top
left: parent.left left: parent.left
@ -99,6 +107,7 @@ Item {
Image { Image {
id: pressImage id: pressImage
source: Settings.invertColors ? "images/press-invert.svg" : "images/press.svg" source: Settings.invertColors ? "images/press-invert.svg" : "images/press.svg"
visible: opacity > 0 visible: opacity > 0
opacity: 0 opacity: 0
@ -162,6 +171,7 @@ Item {
MouseArea { MouseArea {
id: mouseArea id: mouseArea
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
if (widget.selectionEmpty) { if (widget.selectionEmpty) {

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2018 Jolla Ltd. * Copyright (C) 2015-2020 Jolla Ltd.
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -8,15 +8,15 @@
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* * Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer
* the documentation and/or other materials provided with the * in the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Jolla Ltd nor the names of its contributors * 3. Neither the names of the copyright holders nor the names of its
* may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived
* software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -157,7 +157,7 @@ void BooksPageWidget::RenderTask::performTask()
{ {
if (!isCanceled() && !iData.isNull() && !iData->iView.isNull() && if (!isCanceled() && !iData.isNull() && !iData->iView.isNull() &&
iWidth > 0 && iHeight > 0) { iWidth > 0 && iHeight > 0) {
iImage = QImage(iWidth, iHeight, QImage::Format_RGB32); iImage = QImage(iWidth, iHeight, QImage::Format_ARGB32_Premultiplied);
if (!isCanceled()) { if (!isCanceled()) {
QPainter painter(&iImage); QPainter painter(&iImage);
iData->paint(&painter); iData->paint(&painter);
@ -192,7 +192,7 @@ void BooksPageWidget::ClearSelectionTask::performTask()
const ZLTextArea& area = iData->iView->textArea(); const ZLTextArea& area = iData->iView->textArea();
if (!area.selectionIsEmpty()) { if (!area.selectionIsEmpty()) {
area.clearSelection(); area.clearSelection();
iImage = QImage(iWidth, iHeight, QImage::Format_RGB32); iImage = QImage(iWidth, iHeight, QImage::Format_ARGB32_Premultiplied);
if (!isCanceled()) { if (!isCanceled()) {
QPainter painter(&iImage); QPainter painter(&iImage);
iData->paint(&painter); iData->paint(&painter);
@ -288,10 +288,10 @@ public:
FootnoteTask(QThreadPool* aPool, int aX, int aY, int aMaxWidth, int aMaxHeight, FootnoteTask(QThreadPool* aPool, int aX, int aY, int aMaxWidth, int aMaxHeight,
QString aPath, QString aLinkText, QString aRef, QString aPath, QString aLinkText, QString aRef,
shared_ptr<ZLTextModel> aTextModel, shared_ptr<ZLTextStyle> aTextStyle, shared_ptr<ZLTextModel> aTextModel, shared_ptr<ZLTextStyle> aTextStyle,
bool aInvertColors) : HarbourTask(aPool), const BooksSettings* aSettings) : HarbourTask(aPool),
iTextModel(aTextModel), iTextStyle(aTextStyle), iTextModel(aTextModel), iTextStyle(aTextStyle),
iInvertColors(aInvertColors), iX(aX), iY(aY), iInvertColors(aSettings->invertColors()),
iMaxWidth(aMaxWidth), iMaxHeight(aMaxHeight), iX(aX), iY(aY), iMaxWidth(aMaxWidth), iMaxHeight(aMaxHeight),
iRef(aRef), iLinkText(aLinkText), iPath(aPath) {} iRef(aRef), iLinkText(aLinkText), iPath(aPath) {}
~FootnoteTask(); ~FootnoteTask();
@ -354,12 +354,10 @@ void BooksPageWidget::FootnoteTask::performTask()
BooksPaintContext paintContext(size.myWidth, size.myHeight); BooksPaintContext paintContext(size.myWidth, size.myHeight);
paintContext.setInvertColors(iInvertColors); paintContext.setInvertColors(iInvertColors);
ZLTextAreaController paintController(paintContext, *this, &cache); ZLTextAreaController paintController(paintContext, *this, &cache);
iImage = QImage(size.myWidth, size.myHeight, QImage::Format_RGB32); iImage = QImage(size.myWidth, size.myHeight, QImage::Format_ARGB32_Premultiplied);
QPainter painter(&iImage); QPainter painter(&iImage);
paintContext.beginPaint(&painter); paintContext.beginPaint(&painter);
paintContext.clear(iInvertColors ? paintContext.clear(ZLColor(0 /* transparent */));
BooksTextView::INVERTED_BACKGROUND :
BooksTextView::DEFAULT_BACKGROUND);
paintController.setModel(iTextModel); paintController.setModel(iTextModel);
paintController.preparePaintInfo(); paintController.preparePaintInfo();
paintController.area().paint(); paintController.area().paint();
@ -512,12 +510,7 @@ BooksPageWidget::BooksPageWidget(QQuickItem* aParent) :
iCurrentPage(false), iCurrentPage(false),
iPage(-1) iPage(-1)
{ {
connect(iSettings.data(), connect(iSettings.data(), SIGNAL(invertColorsChanged()), SLOT(onColorsChanged()));
SIGNAL(invertColorsChanged()),
SLOT(onInvertColorsChanged()));
setFillColor(qtColor(iSettings->invertColors() ?
BooksTextView::INVERTED_BACKGROUND :
BooksTextView::DEFAULT_BACKGROUND));
setFlag(ItemHasContents, true); setFlag(ItemHasContents, true);
iResizeTimer->setSingleShot(true); iResizeTimer->setSingleShot(true);
iResizeTimer->setInterval(0); iResizeTimer->setInterval(0);
@ -613,14 +606,11 @@ void BooksPageWidget::onTextStyleChanged()
resetView(); resetView();
} }
void BooksPageWidget::onInvertColorsChanged() void BooksPageWidget::onColorsChanged()
{ {
HDEBUG(iPage); HDEBUG(iPage);
HASSERT(sender() == iSettings); HASSERT(sender() == iSettings);
if (!iData.isNull() && !iData->iView.isNull()) { scheduleRepaint();
iData->iView->setInvertColors(iSettings->invertColors());
scheduleRepaint();
}
} }
void BooksPageWidget::onBookModelChanged() void BooksPageWidget::onBookModelChanged()
@ -797,7 +787,9 @@ void BooksPageWidget::scheduleRepaint()
const int w = width(); const int w = width();
const int h = height(); const int h = height();
if (w > 0 && h > 0 && !iData.isNull() && !iData->iView.isNull()) { if (w > 0 && h > 0 && !iData.isNull() && !iData->iView.isNull()) {
iData->iView->setInvertColors(invertColors()); const shared_ptr<BooksTextView> view(iData->iView);
BooksSettings* settings = iSettings.data();
view->setInvertColors(settings->invertColors());
(iRenderTask = new RenderTask(iTaskQueue->pool(), iData, w, h))-> (iRenderTask = new RenderTask(iTaskQueue->pool(), iData, w, h))->
submit(this, SLOT(onRenderTaskDone())); submit(this, SLOT(onRenderTaskDone()));
} else { } else {
@ -970,7 +962,7 @@ void BooksPageWidget::onLongPressTaskDone()
(iFootnoteTask = new FootnoteTask(iTaskQueue->pool(), (iFootnoteTask = new FootnoteTask(iTaskQueue->pool(),
task->iX, task->iY, width()*3/4, height()*10, book->path(), task->iX, task->iY, width()*3/4, height()*10, book->path(),
task->iLinkText, QString::fromStdString(task->iLink), note, task->iLinkText, QString::fromStdString(task->iLink), note,
iTextStyle, iSettings->invertColors()))-> iTextStyle, iSettings.data()))->
submit(this, SLOT(onFootnoteTaskDone())); submit(this, SLOT(onFootnoteTaskDone()));
} else { } else {
HDEBUG("bad footnote" << QString(task->iLink.c_str())); HDEBUG("bad footnote" << QString(task->iLink.c_str()));

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2018 Jolla Ltd. * Copyright (C) 2015-2020 Jolla Ltd.
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -8,15 +8,15 @@
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* * Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer
* the documentation and/or other materials provided with the * in the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Jolla Ltd nor the names of its contributors * 3. Neither the names of the copyright holders nor the names of its
* may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived
* software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -130,7 +130,7 @@ private Q_SLOTS:
void onBookModelPageMarksChanged(); void onBookModelPageMarksChanged();
void onBookModelLoadingChanged(); void onBookModelLoadingChanged();
void onTextStyleChanged(); void onTextStyleChanged();
void onInvertColorsChanged(); void onColorsChanged();
void onResetTaskDone(); void onResetTaskDone();
void onRenderTaskDone(); void onRenderTaskDone();
void onClearSelectionTaskDone(); void onClearSelectionTaskDone();
@ -147,7 +147,6 @@ private:
void releaseExtendSelectionTasks(); void releaseExtendSelectionTasks();
void scheduleRepaint(); void scheduleRepaint();
void cancelRepaint(); void cancelRepaint();
bool invertColors() const;
private: private:
class ResetTask; class ResetTask;
@ -205,7 +204,5 @@ inline int BooksPageWidget::bottomMargin() const
{ return iMargins.iBottom; } { return iMargins.iBottom; }
inline BooksMargins BooksPageWidget::margins() const inline BooksMargins BooksPageWidget::margins() const
{ return iMargins; } { return iMargins; }
inline bool BooksPageWidget::invertColors() const
{ return iSettings && iSettings->invertColors(); }
#endif // BOOKS_PAGE_WIDGET_H #endif // BOOKS_PAGE_WIDGET_H

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2018 Jolla Ltd. * Copyright (C) 2015-2020 Jolla Ltd.
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -8,15 +8,15 @@
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* * Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer
* the documentation and/or other materials provided with the * in the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Jolla Ltd nor the names of its contributors * 3. Neither the names of the copyright holders nor the names of its
* may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived
* software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -243,7 +243,9 @@ void BooksPaintContext::drawFilledCircle(int x, int y, int r)
void BooksPaintContext::clear(ZLColor aColor) void BooksPaintContext::clear(ZLColor aColor)
{ {
if (iPainter) { if (iPainter) {
iPainter->setCompositionMode(QPainter::CompositionMode_Source);
iPainter->fillRect(0, 0, iWidth, iHeight, qtColor(aColor)); iPainter->fillRect(0, 0, iWidth, iHeight, qtColor(aColor));
iPainter->setCompositionMode(QPainter::CompositionMode_SourceOver);
} }
} }
@ -257,11 +259,15 @@ int BooksPaintContext::height() const
return iHeight; return iHeight;
} }
ZLColor BooksPaintContext::realColor(quint8 aRed, quint8 aGreen, quint8 aBlue, bool aInvert) ZLColor BooksPaintContext::realColor(uchar aRed, uchar aGreen, uchar aBlue, uchar aAlpha,
bool aInvertColors)
{ {
return aInvert ? if (aInvertColors) {
ZLColor(255-aRed, 255-aGreen, 255-aBlue) : aRed = 255 - aRed;
ZLColor(aRed, aGreen, aBlue); aGreen = 255 - aGreen;
aBlue = 255 - aBlue;
}
return ZLColor(aRed, aGreen, aBlue, aAlpha);
} }
ZLColor BooksPaintContext::realColor(const std::string& aStyle, bool aInvert) ZLColor BooksPaintContext::realColor(const std::string& aStyle, bool aInvert)
@ -269,33 +275,46 @@ ZLColor BooksPaintContext::realColor(const std::string& aStyle, bool aInvert)
static const std::string INTERNAL_HYPERLINK("internal"); static const std::string INTERNAL_HYPERLINK("internal");
static const std::string EXTERNAL_HYPERLINK("external"); static const std::string EXTERNAL_HYPERLINK("external");
static const std::string BOOK_HYPERLINK("book"); static const std::string BOOK_HYPERLINK("book");
unsigned long argb = ZLColor::rgbValue(0);
if (ZLStringUtil::startsWith(aStyle, '#')) { if (ZLStringUtil::startsWith(aStyle, '#')) {
if (aStyle.length() == 7) { const size_t len = aStyle.length();
int i, value = 0; if (len == 7 || len == 9) {
int i;
unsigned long rgb = 0;
for (i=1; i<7; i++) { for (i=1; i<7; i++) {
int nibble = ZLStringUtil::fromHex(aStyle[i]); int nibble = ZLStringUtil::fromHex(aStyle[i]);
if (nibble >= 0) { if (nibble >= 0) {
value <<= 4; rgb <<= 4;
value |= nibble; rgb |= nibble;
} else { } else {
break; break;
} }
} }
if (i == 7) { if (i == 7) {
return realColor(ZLColor(value), aInvert); if (len == 9) {
int a1 = ZLStringUtil::fromHex(aStyle[7]);
int a2 = ZLStringUtil::fromHex(aStyle[8]);
if (a1 >= 0 && a2 >= 0) {
argb = ZLColor::rgbValue(rgb, (a1 << 4) | a2);
} else {
argb = ZLColor::rgbValue(rgb);
}
} else {
argb = ZLColor::rgbValue(rgb);
}
} }
} }
} else if (aStyle == INTERNAL_HYPERLINK) { } else if (aStyle == INTERNAL_HYPERLINK) {
return realColor(33, 96, 180, aInvert); argb = ZLColor::rgbValue(0x2160b4);
} else if (aStyle == EXTERNAL_HYPERLINK) { } else if (aStyle == EXTERNAL_HYPERLINK) {
return realColor(33, 96, 180, aInvert); argb = ZLColor::rgbValue(0x2160b4);
} else if (aStyle == BOOK_HYPERLINK) { } else if (aStyle == BOOK_HYPERLINK) {
return realColor(23, 68, 128, aInvert); argb = ZLColor::rgbValue(0x174480);
} else if (aStyle == ZLTextStyle::SELECTION_BACKGROUND) { } else if (aStyle == ZLTextStyle::SELECTION_BACKGROUND) {
return realColor(60, 139, 255, aInvert); argb = ZLColor::rgbValue(0x3c8bff);
} else if (aStyle == ZLTextStyle::HIGHLIGHTED_TEXT) { } else if (aStyle == ZLTextStyle::HIGHLIGHTED_TEXT) {
return realColor(60, 139, 255, aInvert); argb = ZLColor::rgbValue(0x3c8bff);
} }
return realColor(0, 0, 0, aInvert); return realColor(ZLColor(argb), aInvert);
} }

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2016 Jolla Ltd. * Copyright (C) 2015-2020 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -8,15 +8,15 @@
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* * Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer
* the documentation and/or other materials provided with the * in the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors * 3. Neither the names of the copyright holders nor the names of its
* may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived
* software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -46,7 +46,6 @@
class QPainter; class QPainter;
class BooksPaintContext : public ZLPaintContext { class BooksPaintContext : public ZLPaintContext {
public: public:
BooksPaintContext(int aWidth, int aHeight); BooksPaintContext(int aWidth, int aHeight);
BooksPaintContext(); BooksPaintContext();
@ -88,12 +87,15 @@ public:
void drawFilledCircle(int x, int y, int r); void drawFilledCircle(int x, int y, int r);
void setInvertColors(bool aInvertColors); void setInvertColors(bool aInvertColors);
static ZLColor realColor(const std::string& aStyle, bool aInvertColors);
static ZLColor realColor(quint8 aRed, quint8 aGreen, quint8 aBlue, bool aInvert);
static ZLColor realColor(const ZLColor aColor, bool aInvert);
ZLColor realColor(const std::string& aStyle) const;
ZLColor realColor(quint8 aRed, quint8 aGreen, quint8 aBlue) const;
ZLColor realColor(const ZLColor aColor) const; ZLColor realColor(const ZLColor aColor) const;
ZLColor realColor(const std::string& aStyle) const;
static ZLColor realColor(const std::string& aStyle, bool aInvert);
private:
ZLColor realColor(uchar aRed, uchar aGreen, uchar aBlue, uchar aAlpha) const;
static ZLColor realColor(uchar aRed, uchar aGreen, uchar aBlue, uchar aAlpha, bool aInvert);
static ZLColor realColor(const ZLColor aColor, bool aInvert);
private: private:
QPainter* iPainter; QPainter* iPainter;
@ -117,13 +119,13 @@ inline QSize BooksPaintContext::size() const
{ return QSize(iWidth, iHeight); } { return QSize(iWidth, iHeight); }
inline QColor qtColor(const ZLColor& aColor) inline QColor qtColor(const ZLColor& aColor)
{ return QColor(aColor.Red, aColor.Green, aColor.Blue); } { return QColor(aColor.Red, aColor.Green, aColor.Blue, aColor.Alpha); }
inline ZLColor BooksPaintContext::realColor(const ZLColor aColor) const inline ZLColor BooksPaintContext::realColor(const ZLColor aColor) const
{ return realColor(aColor.Red, aColor.Green, aColor.Blue); } { return realColor(aColor.Red, aColor.Green, aColor.Blue, aColor.Alpha); }
inline ZLColor BooksPaintContext::realColor(quint8 aRed, quint8 aGreen, quint8 aBlue) const inline ZLColor BooksPaintContext::realColor(uchar aRed, uchar aGreen, uchar aBlue, uchar aAlpha) const
{ return realColor(aRed, aGreen, aBlue, iInvertColors); } { return realColor(aRed, aGreen, aBlue, aAlpha, iInvertColors); }
inline ZLColor BooksPaintContext::realColor(const ZLColor aColor, bool aInvert) inline ZLColor BooksPaintContext::realColor(const ZLColor aColor, bool aInvert)
{ return realColor(aColor.Red, aColor.Green, aColor.Blue, aInvert); } { return realColor(aColor.Red, aColor.Green, aColor.Blue, aColor.Alpha, aInvert); }
inline ZLColor BooksPaintContext::realColor(const std::string& aStyle) const inline ZLColor BooksPaintContext::realColor(const std::string& aStyle) const
{ return realColor(aStyle, iInvertColors); } { return realColor(aStyle, iInvertColors); }
inline void BooksPaintContext::setInvertColors(bool aInvertColors) inline void BooksPaintContext::setInvertColors(bool aInvertColors)

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2019 Jolla Ltd. * Copyright (C) 2015-2020 Jolla Ltd.
* Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -32,6 +32,7 @@
*/ */
#include "BooksSettings.h" #include "BooksSettings.h"
#include "BooksPaintContext.h"
#include "BooksTextStyle.h" #include "BooksTextStyle.h"
#include "BooksTextView.h" #include "BooksTextView.h"
#include "BooksBook.h" #include "BooksBook.h"
@ -45,6 +46,7 @@
#define DCONF_PATH BOOKS_DCONF_ROOT #define DCONF_PATH BOOKS_DCONF_ROOT
#define KEY_FONT_SIZE "fontSize" #define KEY_FONT_SIZE "fontSize"
#define KEY_PAGE_DETAILS "pageDetails" #define KEY_PAGE_DETAILS "pageDetails"
#define KEY_NIGHT_MODE_BRIGHTNESS "nightModeBrightness"
#define KEY_PAGE_DETAILS_FIXED "pageDetailsFixed" #define KEY_PAGE_DETAILS_FIXED "pageDetailsFixed"
#define KEY_TURN_PAGE_BY_TAP "turnPageByTap" #define KEY_TURN_PAGE_BY_TAP "turnPageByTap"
#define KEY_SAMPLE_BOOK_COPIED "sampleBookCopied" #define KEY_SAMPLE_BOOK_COPIED "sampleBookCopied"
@ -58,6 +60,7 @@
#define KEY_ORIENTATION "orientation" #define KEY_ORIENTATION "orientation"
#define DEFAULT_FONT_SIZE 0 #define DEFAULT_FONT_SIZE 0
#define DEFAULT_NIGHT_BRIGHTNESS 1.0
#define DEFAULT_PAGE_DETAILS 0 #define DEFAULT_PAGE_DETAILS 0
#define DEFAULT_PAGE_DETAILS_FIXED false #define DEFAULT_PAGE_DETAILS_FIXED false
#define DEFAULT_TURN_PAGE_BY_TAP false #define DEFAULT_TURN_PAGE_BY_TAP false
@ -71,6 +74,8 @@
#define DEFAULT_VOLUME_DOWN_ACTION (BooksSettings::ActionPreviousPage) #define DEFAULT_VOLUME_DOWN_ACTION (BooksSettings::ActionPreviousPage)
#define DEFAULT_ORIENTATION (BooksSettings::OrientationAny) #define DEFAULT_ORIENTATION (BooksSettings::OrientationAny)
#define DEFAULT_BACKGROUND QColor(Qt::white)
#define INVERTED_BACKGROUND QColor(Qt::black)
#define PAGETOOL_COLOR QColor(128,128,128) // any bg #define PAGETOOL_COLOR QColor(128,128,128) // any bg
#define NORMAL_PAGETOOL_HIGHLIGHT_COLOR QColor(64,64,64) // on white #define NORMAL_PAGETOOL_HIGHLIGHT_COLOR QColor(64,64,64) // on white
#define INVERTED_PAGETOOL_HIGHLIGHT_COLOR QColor(192,192,192) // on black #define INVERTED_PAGETOOL_HIGHLIGHT_COLOR QColor(192,192,192) // on black
@ -220,24 +225,32 @@ class BooksSettings::Private : public QObject {
public: public:
Private(BooksSettings* aParent); Private(BooksSettings* aParent);
BooksSettings* parentSettings() const;
bool updateCurrentBook(); bool updateCurrentBook();
bool updateCurrentStorage(); bool updateCurrentStorage();
int currentFontSize() const; bool updateBrightness();
bool invertColors() const;
int fontSizeValue() const;
int fontSize(int aFontSizeAdjust) const; int fontSize(int aFontSizeAdjust) const;
qreal brightnessValue() const;
qreal nightModeBrightness() const;
QString currentFolder() const; QString currentFolder() const;
shared_ptr<ZLTextStyle> textStyle(int aFontSizeAdjust) const; shared_ptr<ZLTextStyle> textStyle(int aFontSizeAdjust) const;
void setCurrentBook(QObject* aBook); void setCurrentBook(QObject* aBook);
static Action getAction(MGConfItem* aItem, Action aDefault); static Action getAction(MGConfItem* aItem, Action aDefault);
static qreal normalizeBrightness(qreal aBrightness);
private Q_SLOTS: private Q_SLOTS:
void onInvertColorsChanged();
void onNightModeBrightnessChanged();
void onFontSizeValueChanged(); void onFontSizeValueChanged();
void onCurrentBookPathChanged(); void onCurrentBookPathChanged();
void onCurrentFolderChanged(); void onCurrentFolderChanged();
public: public:
static QWeakPointer<BooksSettings> sSharedInstance; static QWeakPointer<BooksSettings> sSharedInstance;
BooksSettings* iParent;
MGConfItem* iFontSizeConf; MGConfItem* iFontSizeConf;
MGConfItem* iNightModeBrightnessConf;
MGConfItem* iPageDetailsConf; MGConfItem* iPageDetailsConf;
MGConfItem* iPageDetailsFixedConf; MGConfItem* iPageDetailsFixedConf;
MGConfItem* iTurnPageByTapConf; MGConfItem* iTurnPageByTapConf;
@ -254,14 +267,15 @@ public:
BooksBook* iCurrentBook; BooksBook* iCurrentBook;
QString iCurrentStorageDevice; QString iCurrentStorageDevice;
int iFontSize; int iFontSize;
qreal iBrightness;
}; };
QWeakPointer<BooksSettings> BooksSettings::Private::sSharedInstance; QWeakPointer<BooksSettings> BooksSettings::Private::sSharedInstance;
BooksSettings::Private::Private(BooksSettings* aParent) : BooksSettings::Private::Private(BooksSettings* aParent) :
QObject(aParent), QObject(aParent),
iParent(aParent),
iFontSizeConf(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)), iFontSizeConf(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)),
iNightModeBrightnessConf(new MGConfItem(DCONF_PATH KEY_NIGHT_MODE_BRIGHTNESS, this)),
iPageDetailsConf(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS, this)), iPageDetailsConf(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS, this)),
iPageDetailsFixedConf(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS_FIXED, this)), iPageDetailsFixedConf(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS_FIXED, this)),
iTurnPageByTapConf(new MGConfItem(DCONF_PATH KEY_TURN_PAGE_BY_TAP, this)), iTurnPageByTapConf(new MGConfItem(DCONF_PATH KEY_TURN_PAGE_BY_TAP, this)),
@ -276,33 +290,106 @@ BooksSettings::Private::Private(BooksSettings* aParent) :
iRemovableRootConf(new MGConfItem(DCONF_PATH KEY_REMOVABLE_ROOT, this)), iRemovableRootConf(new MGConfItem(DCONF_PATH KEY_REMOVABLE_ROOT, this)),
iCurrentBook(NULL) iCurrentBook(NULL)
{ {
iFontSize = currentFontSize(); iFontSize = fontSizeValue();
iBrightness = brightnessValue();
connect(iFontSizeConf, SIGNAL(valueChanged()), SLOT(onFontSizeValueChanged())); connect(iFontSizeConf, SIGNAL(valueChanged()), SLOT(onFontSizeValueChanged()));
connect(iCurrentFolderConf, SIGNAL(valueChanged()), SLOT(onCurrentFolderChanged())); connect(iCurrentFolderConf, SIGNAL(valueChanged()), SLOT(onCurrentFolderChanged()));
connect(iCurrentBookPathConf, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged())); connect(iCurrentBookPathConf, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged()));
connect(iPageDetailsConf, SIGNAL(valueChanged()), iParent, SIGNAL(pageDetailsChanged())); connect(iInvertColorsConf, SIGNAL(valueChanged()), SLOT(onInvertColorsChanged()));
connect(iPageDetailsFixedConf, SIGNAL(valueChanged()), iParent, SIGNAL(pageDetailsFixedChanged())); connect(iNightModeBrightnessConf, SIGNAL(valueChanged()), SLOT(onNightModeBrightnessChanged()));
connect(iTurnPageByTapConf, SIGNAL(valueChanged()), iParent, SIGNAL(turnPageByTapChanged())); connect(iPageDetailsConf, SIGNAL(valueChanged()), aParent, SIGNAL(pageDetailsChanged()));
connect(iInvertColorsConf, SIGNAL(valueChanged()), iParent, SIGNAL(invertColorsChanged())); connect(iPageDetailsFixedConf, SIGNAL(valueChanged()), aParent, SIGNAL(pageDetailsFixedChanged()));
connect(iInvertColorsConf, SIGNAL(valueChanged()), iParent, SIGNAL(pageBackgroundColorChanged())); connect(iTurnPageByTapConf, SIGNAL(valueChanged()), aParent, SIGNAL(turnPageByTapChanged()));
connect(iSampleBookCopiedConf, SIGNAL(valueChanged()), iParent, SIGNAL(sampleBookCopiedChanged())); connect(iSampleBookCopiedConf, SIGNAL(valueChanged()), aParent, SIGNAL(sampleBookCopiedChanged()));
connect(iKeepDisplayOnConf, SIGNAL(valueChanged()), iParent, SIGNAL(keepDisplayOnChanged())); connect(iKeepDisplayOnConf, SIGNAL(valueChanged()), aParent, SIGNAL(keepDisplayOnChanged()));
connect(iVolumeUpActionConf, SIGNAL(valueChanged()), iParent, SIGNAL(volumeUpActionChanged())); connect(iVolumeUpActionConf, SIGNAL(valueChanged()), aParent, SIGNAL(volumeUpActionChanged()));
connect(iVolumeDownActionConf, SIGNAL(valueChanged()), iParent, SIGNAL(volumeDownActionChanged())); connect(iVolumeDownActionConf, SIGNAL(valueChanged()), aParent, SIGNAL(volumeDownActionChanged()));
connect(iOrientationConf, SIGNAL(valueChanged()), iParent, SIGNAL(orientationChanged())); connect(iOrientationConf, SIGNAL(valueChanged()), aParent, SIGNAL(orientationChanged()));
connect(iRemovableRootConf, SIGNAL(valueChanged()), iParent, SIGNAL(removableRootChanged())); connect(iRemovableRootConf, SIGNAL(valueChanged()), aParent, SIGNAL(removableRootChanged()));
}
inline BooksSettings*
BooksSettings::Private::parentSettings() const
{
return qobject_cast<BooksSettings*>(parent());
}
inline bool
BooksSettings::Private::invertColors() const
{
return iInvertColorsConf->value(DEFAULT_INVERT_COLORS).toBool();
}
inline qreal
BooksSettings::Private::normalizeBrightness(
qreal aBrightness)
{
return (aBrightness < 0) ? 0 : (aBrightness > 1) ? 1 : aBrightness;
}
qreal
BooksSettings::Private::nightModeBrightness() const
{
bool ok;
QVariant var(iNightModeBrightnessConf->value(DEFAULT_NIGHT_BRIGHTNESS));
const qreal value = var.toReal(&ok);
return ok ? normalizeBrightness(value) : DEFAULT_NIGHT_BRIGHTNESS;
}
inline qreal
BooksSettings::Private::brightnessValue() const
{
return invertColors() ? nightModeBrightness() : 1.0;
}
bool
BooksSettings::Private::updateBrightness()
{
const qreal newBrightness = brightnessValue();
if (iBrightness != newBrightness) {
iBrightness = newBrightness;
HDEBUG(iBrightness);
return true;
}
return false;
}
void
BooksSettings::Private::onInvertColorsChanged()
{
BooksSettings* settings = parentSettings();
if (updateBrightness()) {
Q_EMIT settings->brightnessChanged();
}
Q_EMIT settings->invertColorsChanged();
Q_EMIT settings->pageBackgroundColorChanged();
}
void
BooksSettings::Private::onNightModeBrightnessChanged()
{
BooksSettings* settings = parentSettings();
if (updateBrightness()) {
Q_EMIT settings->brightnessChanged();
}
Q_EMIT settings->nightModeBrightnessChanged();
} }
int int
BooksSettings::Private::currentFontSize() const BooksSettings::Private::fontSizeValue() const
{ {
const int fontSize = iFontSizeConf->value(DEFAULT_FONT_SIZE).toInt(); bool ok;
if (fontSize < MinFontSize) { const int fontSize = iFontSizeConf->value(DEFAULT_FONT_SIZE).toInt(&ok);
return MinFontSize; if (ok) {
} else if (fontSize > MaxFontSize) { if (fontSize < MinFontSize) {
return MaxFontSize; return MinFontSize;
} else if (fontSize > MaxFontSize) {
return MaxFontSize;
} else {
return fontSize;
}
} else { } else {
return fontSize; return iFontSize;
} }
} }
@ -355,7 +442,7 @@ BooksSettings::Private::setCurrentBook(
iCurrentBook = NULL; iCurrentBook = NULL;
iCurrentBookPathConf->set(QString()); iCurrentBookPathConf->set(QString());
} }
Q_EMIT iParent->currentBookChanged(); Q_EMIT parentSettings()->currentBookChanged();
} }
} }
@ -407,33 +494,35 @@ BooksSettings::Private::updateCurrentStorage()
void void
BooksSettings::Private::onFontSizeValueChanged() BooksSettings::Private::onFontSizeValueChanged()
{ {
const int newSize = currentFontSize(); const int newSize = fontSizeValue();
HDEBUG(newSize); HDEBUG(newSize);
if (iFontSize != newSize) { if (iFontSize != newSize) {
iFontSize = newSize; iFontSize = newSize;
for (int i=0; i<=FontSizeSteps; i++) { for (int i=0; i<=FontSizeSteps; i++) {
iTextStyle[i].reset(); iTextStyle[i].reset();
} }
Q_EMIT iParent->fontSizeChanged(); BooksSettings* settings = parentSettings();
Q_EMIT iParent->textStyleChanged(); Q_EMIT settings->fontSizeChanged();
Q_EMIT settings->textStyleChanged();
} }
} }
void void
BooksSettings::Private::onCurrentFolderChanged() BooksSettings::Private::onCurrentFolderChanged()
{ {
BooksSettings* settings = parentSettings();
if (updateCurrentStorage()) { if (updateCurrentStorage()) {
Q_EMIT iParent->currentStorageChanged(); Q_EMIT settings->currentStorageChanged();
} }
Q_EMIT iParent->currentFolderChanged(); Q_EMIT settings->currentFolderChanged();
Q_EMIT iParent->relativePathChanged(); Q_EMIT settings->relativePathChanged();
} }
void void
BooksSettings::Private::onCurrentBookPathChanged() BooksSettings::Private::onCurrentBookPathChanged()
{ {
if (updateCurrentBook()) { if (updateCurrentBook()) {
Q_EMIT iParent->currentBookChanged(); Q_EMIT parentSettings()->currentBookChanged();
} }
} }
@ -522,6 +611,26 @@ BooksSettings::fontSize() const
return iPrivate->iFontSize; return iPrivate->iFontSize;
} }
void
BooksSettings::setNightModeBrightness(
qreal aValue)
{
HDEBUG(aValue);
iPrivate->iNightModeBrightnessConf->set(Private::normalizeBrightness(aValue));
}
qreal
BooksSettings::brightness() const
{
return iPrivate->iBrightness;
}
qreal
BooksSettings::nightModeBrightness() const
{
return iPrivate->nightModeBrightness();
}
QString QString
BooksSettings::currentStorage() const BooksSettings::currentStorage() const
{ {
@ -580,7 +689,7 @@ BooksSettings::setTurnPageByTap(
bool bool
BooksSettings::invertColors() const BooksSettings::invertColors() const
{ {
return iPrivate->iInvertColorsConf->value(DEFAULT_INVERT_COLORS).toBool(); return iPrivate->invertColors();
} }
void void
@ -698,7 +807,7 @@ BooksSettings::primaryPageToolColor() const
QColor QColor
BooksSettings::highlightPageToolColor() const BooksSettings::highlightPageToolColor() const
{ {
return invertColors() ? return iPrivate->invertColors() ?
INVERTED_PAGETOOL_HIGHLIGHT_COLOR : INVERTED_PAGETOOL_HIGHLIGHT_COLOR :
NORMAL_PAGETOOL_HIGHLIGHT_COLOR; NORMAL_PAGETOOL_HIGHLIGHT_COLOR;
} }
@ -706,9 +815,9 @@ BooksSettings::highlightPageToolColor() const
QColor QColor
BooksSettings::pageBackgroundColor() const BooksSettings::pageBackgroundColor() const
{ {
return qtColor(invertColors() ? return iPrivate->invertColors() ?
BooksTextView::INVERTED_BACKGROUND : INVERTED_BACKGROUND :
BooksTextView::DEFAULT_BACKGROUND); DEFAULT_BACKGROUND;
} }
BooksSettings::Orientation BooksSettings::Orientation

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2019 Jolla Ltd. * Copyright (C) 2015-2020 Jolla Ltd.
* Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -47,6 +47,8 @@ class BooksSettings : public QObject
Q_ENUMS(Orientation) Q_ENUMS(Orientation)
Q_ENUMS(Action) Q_ENUMS(Action)
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(qreal brightness READ brightness NOTIFY brightnessChanged)
Q_PROPERTY(qreal nightModeBrightness READ nightModeBrightness WRITE setNightModeBrightness NOTIFY nightModeBrightnessChanged)
Q_PROPERTY(int pageDetails READ pageDetails WRITE setPageDetails NOTIFY pageDetailsChanged) Q_PROPERTY(int pageDetails READ pageDetails WRITE setPageDetails NOTIFY pageDetailsChanged)
Q_PROPERTY(bool pageDetailsFixed READ pageDetailsFixed WRITE setPageDetailsFixed NOTIFY pageDetailsFixedChanged) Q_PROPERTY(bool pageDetailsFixed READ pageDetailsFixed WRITE setPageDetailsFixed NOTIFY pageDetailsFixedChanged)
Q_PROPERTY(bool turnPageByTap READ turnPageByTap WRITE setTurnPageByTap NOTIFY turnPageByTapChanged) Q_PROPERTY(bool turnPageByTap READ turnPageByTap WRITE setTurnPageByTap NOTIFY turnPageByTapChanged)
@ -99,6 +101,10 @@ public:
int fontSize() const; int fontSize() const;
void setFontSize(int aValue); void setFontSize(int aValue);
qreal brightness() const;
qreal nightModeBrightness() const;
void setNightModeBrightness(qreal aValue);
int pageDetails() const; int pageDetails() const;
void setPageDetails(int aValue); void setPageDetails(int aValue);
@ -108,7 +114,7 @@ public:
bool turnPageByTap() const; bool turnPageByTap() const;
void setTurnPageByTap(bool aValue); void setTurnPageByTap(bool aValue);
bool invertColors() const; bool invertColors() const; // Night mode
void setInvertColors(bool aValue); void setInvertColors(bool aValue);
bool sampleBookCopied() const; bool sampleBookCopied() const;
@ -140,6 +146,8 @@ public:
Q_SIGNALS: Q_SIGNALS:
void fontSizeChanged(); void fontSizeChanged();
void nightModeBrightnessChanged();
void brightnessChanged();
void textStyleChanged(); void textStyleChanged();
void pageDetailsChanged(); void pageDetailsChanged();
void pageDetailsFixedChanged(); void pageDetailsFixedChanged();

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2017 Jolla Ltd. * Copyright (C) 2015-2020 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -8,15 +8,15 @@
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* * Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer
* the documentation and/or other materials provided with the * in the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Jolla Ltd nor the names of its contributors * 3. Neither the names of the copyright holders nor the names of its
* may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived
* software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -38,9 +38,6 @@
#define SUPER ZLTextView #define SUPER ZLTextView
const ZLColor BooksTextView::DEFAULT_BACKGROUND(255, 255, 255);
const ZLColor BooksTextView::INVERTED_BACKGROUND(0, 0, 0);
BooksTextView::BooksTextView( BooksTextView::BooksTextView(
BooksPaintContext& aContext, BooksPaintContext& aContext,
shared_ptr<ZLTextStyle> aTextStyle, shared_ptr<ZLTextStyle> aTextStyle,
@ -84,7 +81,8 @@ int BooksTextView::bottomMargin() const
ZLColor BooksTextView::backgroundColor() const ZLColor BooksTextView::backgroundColor() const
{ {
return iPaintContext.realColor(DEFAULT_BACKGROUND); // Background is provided by QML UI, return fully transparent color
return ZLColor(0);
} }
ZLColor BooksTextView::color(const std::string& aStyle) const ZLColor BooksTextView::color(const std::string& aStyle) const

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2017 Jolla Ltd. * Copyright (C) 2015-2020 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -8,15 +8,15 @@
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* * Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer
* the documentation and/or other materials provided with the * in the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Jolla Ltd nor the names of its contributors * 3. Neither the names of the copyright holders nor the names of its
* may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived
* software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -51,9 +51,6 @@ public:
shared_ptr<ZLTextStyle> aTextStyle, shared_ptr<ZLTextStyle> aTextStyle,
BooksMargins aMargin); BooksMargins aMargin);
static const ZLColor DEFAULT_BACKGROUND;
static const ZLColor INVERTED_BACKGROUND;
public: public:
BooksPos position() const; BooksPos position() const;
const BooksPos rewind(); const BooksPos rewind();

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com> * Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -183,8 +184,8 @@ public:
void setValue(ZLColor value); void setValue(ZLColor value);
private: private:
mutable long myIntValue; mutable unsigned long myIntValue;
const long myDefaultIntValue; const unsigned long myDefaultIntValue;
}; };
class ZLDoubleOption : public ZLOption { class ZLDoubleOption : public ZLOption {

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com> * Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2015 Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -22,25 +22,34 @@
#define __ZLCOLOR_H__ #define __ZLCOLOR_H__
struct ZLColor { struct ZLColor {
unsigned char Alpha;
unsigned char Red; unsigned char Red;
unsigned char Green; unsigned char Green;
unsigned char Blue; unsigned char Blue;
static const unsigned long ALPHA_MASK = 0xff000000;
ZLColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
ZLColor(unsigned char r, unsigned char g, unsigned char b); ZLColor(unsigned char r, unsigned char g, unsigned char b);
ZLColor(long longValue = 0); ZLColor(unsigned long argb = ALPHA_MASK);
void setIntValue(long longValue); void setIntValue(unsigned long argb);
long intValue(); unsigned long intValue();
static unsigned long rgbValue(unsigned long rgb, unsigned char a = 0xff);
bool equals(const ZLColor color) const;
bool operator == (const ZLColor &color) const; bool operator == (const ZLColor &color) const;
bool operator != (const ZLColor &color) const; bool operator != (const ZLColor &color) const;
}; };
inline ZLColor::ZLColor(unsigned char r, unsigned char g, unsigned char b) : Red(r), Green(g), Blue(b) {} inline ZLColor::ZLColor(unsigned char r, unsigned char g, unsigned char b) : Alpha(0xff), Red(r), Green(g), Blue(b) {}
inline ZLColor::ZLColor(long longValue) : Red((unsigned char)(longValue >> 16)), Green((unsigned char)(longValue >> 8)), Blue((unsigned char)longValue) {} inline ZLColor::ZLColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a) : Alpha(a), Red(r), Green(g), Blue(b) {}
inline void ZLColor::setIntValue(long longValue) { Red = (unsigned char)(longValue >> 16); Green = (unsigned char)(longValue >> 8); Blue = (unsigned char)longValue; } inline ZLColor::ZLColor(unsigned long argb) : Alpha((unsigned char)(argb >> 24)), Red((unsigned char)(argb >> 16)), Green((unsigned char)(argb >> 8)), Blue((unsigned char)argb) {}
inline long ZLColor::intValue() { return (((long)Red) << 16) + (((long)Green) << 8) + Blue; } inline void ZLColor::setIntValue(unsigned long argb) { Alpha = (unsigned char)(argb >> 24); Red = (unsigned char)(argb >> 16); Green = (unsigned char)(argb >> 8); Blue = (unsigned char)argb; }
inline bool ZLColor::operator == (const ZLColor &color) const { return (Red == color.Red) && (Green == color.Green) && (Blue == color.Blue); } inline unsigned long ZLColor::intValue() { return (((unsigned long)Alpha) << 24) | (((unsigned long)Red) << 16) | (((unsigned long)Green) << 8) | (unsigned long)Blue; }
inline bool ZLColor::operator != (const ZLColor &color) const { return !operator==(color); } inline unsigned long ZLColor::rgbValue(unsigned long rgb, unsigned char a) { return (((unsigned long)a) << 24) | rgb; }
inline bool ZLColor::equals(const ZLColor color) const { return (Red == color.Red) && (Green == color.Green) && (Blue == color.Blue) && (Alpha == color.Alpha); }
inline bool ZLColor::operator == (const ZLColor &color) const { return equals(color); }
inline bool ZLColor::operator != (const ZLColor &color) const { return !equals(color); }
#endif /* __ZLCOLOR_H__ */ #endif /* __ZLCOLOR_H__ */