Invert colors on double-click

This commit is contained in:
Slava Monich 2015-07-11 01:35:13 +03:00
parent 0efb865586
commit d6cacd2fd1
9 changed files with 125 additions and 25 deletions

View file

@ -100,8 +100,26 @@ Item {
Behavior on opacity { FadeAnimation {} } Behavior on opacity { FadeAnimation {} }
} }
// For some reason this MouseArea receives clicks but not double-click
// events. It was easier to reimplement double-click functionality than
// to figure out what's wrong with double clicks.
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: view.pageClicked() onClicked: {
if (!clickTimer.running) {
// If there're no more clicks within DoubleClickInterval
// then it's a single click
clickTimer.start()
} else {
// Otherwise it's a double click
clickTimer.stop()
settings.invertColors = !settings.invertColors
}
}
Timer {
id: clickTimer
interval: DoubleClickInterval
onTriggered: view.pageClicked()
}
} }
} }

View file

@ -51,7 +51,7 @@ public:
bool paint(QPainter* aPainter); bool paint(QPainter* aPainter);
public: public:
shared_ptr<ZLView> iView; shared_ptr<BooksTextView> iView;
shared_ptr<ZLTextModel> iModel; shared_ptr<ZLTextModel> iModel;
BooksPaintContext iPaintContext; BooksPaintContext iPaintContext;
}; };
@ -169,7 +169,7 @@ BooksPageWidget::BooksPageWidget(QQuickItem* aParent) :
iPage(-1) iPage(-1)
{ {
setFlag(ItemHasContents, true); setFlag(ItemHasContents, true);
setFillColor(Qt::white); setFillColor(qtColor(BooksTextView::DEFAULT_BACKGROUND));
iResizeTimer->setSingleShot(true); iResizeTimer->setSingleShot(true);
iResizeTimer->setInterval(0); iResizeTimer->setInterval(0);
connect(iResizeTimer, SIGNAL(timeout()), SLOT(onResizeTimeout())); connect(iResizeTimer, SIGNAL(timeout()), SLOT(onResizeTimeout()));
@ -220,17 +220,36 @@ void BooksPageWidget::setModel(BooksBookModel* aModel)
void BooksPageWidget::setSettings(BooksSettings* aSettings) void BooksPageWidget::setSettings(BooksSettings* aSettings)
{ {
if (iSettings != aSettings) { if (iSettings != aSettings) {
const bool colorsWereInverted = invertColors();
shared_ptr<ZLTextStyle> oldTextStyle(iTextStyle); shared_ptr<ZLTextStyle> oldTextStyle(iTextStyle);
if (iSettings) iSettings->disconnect(this); if (iSettings) iSettings->disconnect(this);
iSettings = aSettings; iSettings = aSettings;
if (iSettings) { if (iSettings) {
iTextStyle = iSettings->textStyle(); iTextStyle = iSettings->textStyle();
connect(iSettings, SIGNAL(textStyleChanged()), SLOT(onTextStyleChanged())); connect(iSettings,
SIGNAL(textStyleChanged()),
SLOT(onTextStyleChanged()));
connect(iSettings,
SIGNAL(invertColorsChanged()),
SLOT(onInvertColorsChanged()));
} else { } else {
iTextStyle = BooksTextStyle::defaults(); iTextStyle = BooksTextStyle::defaults();
} }
const bool colorsAreInverted = invertColors();
if (colorsWereInverted != colorsAreInverted) {
setFillColor(qtColor(colorsAreInverted ?
BooksTextView::INVERTED_BACKGROUND :
BooksTextView::DEFAULT_BACKGROUND));
}
if (!BooksTextStyle::equalLayout(oldTextStyle, iTextStyle)) { if (!BooksTextStyle::equalLayout(oldTextStyle, iTextStyle)) {
resetView(); resetView();
} else if (colorsWereInverted != colorsAreInverted) {
if (!iData.isNull() && !iData->iView.isNull()) {
iData->iView->setInvertColors(colorsAreInverted);
scheduleRepaint();
} else {
update();
}
} }
Q_EMIT settingsChanged(); Q_EMIT settingsChanged();
} }
@ -239,10 +258,21 @@ void BooksPageWidget::setSettings(BooksSettings* aSettings)
void BooksPageWidget::onTextStyleChanged() void BooksPageWidget::onTextStyleChanged()
{ {
HDEBUG(iPage); HDEBUG(iPage);
HASSERT(sender() == iSettings);
iTextStyle = iSettings->textStyle(); iTextStyle = iSettings->textStyle();
resetView(); resetView();
} }
void BooksPageWidget::onInvertColorsChanged()
{
HDEBUG(iPage);
HASSERT(sender() == iSettings);
if (!iData.isNull() && !iData->iView.isNull()) {
iData->iView->setInvertColors(iSettings->invertColors());
scheduleRepaint();
}
}
void BooksPageWidget::onBookModelChanged() void BooksPageWidget::onBookModelChanged()
{ {
HDEBUG(iModel->title()); HDEBUG(iModel->title());
@ -402,8 +432,11 @@ void BooksPageWidget::scheduleRepaint()
{ {
BooksLoadingSignalBlocker block(this); BooksLoadingSignalBlocker block(this);
cancelRepaint(); cancelRepaint();
if (width() > 0 && height() > 0 && !iData.isNull()) { const int w = width();
iRenderTask = new RenderTask(iData, width(), height()); const int h = height();
if (w > 0 && h > 0 && !iData.isNull() && !iData->iView.isNull()) {
iData->iView->setInvertColors(invertColors());
iRenderTask = new RenderTask(iData, w, h);
iTaskQueue->submit(iRenderTask, this, SLOT(onRenderTaskDone())); iTaskQueue->submit(iRenderTask, this, SLOT(onRenderTaskDone()));
} else { } else {
update(); update();

View file

@ -109,6 +109,7 @@ private Q_SLOTS:
void onBookModelPageMarksChanged(); void onBookModelPageMarksChanged();
void onBookModelLoadingChanged(); void onBookModelLoadingChanged();
void onTextStyleChanged(); void onTextStyleChanged();
void onInvertColorsChanged();
void onResetTaskDone(); void onResetTaskDone();
void onRenderTaskDone(); void onRenderTaskDone();
@ -118,6 +119,7 @@ private:
void resetView(); void resetView();
void scheduleRepaint(); void scheduleRepaint();
void cancelRepaint(); void cancelRepaint();
bool invertColors() const;
private: private:
class ResetTask; class ResetTask;
@ -138,4 +140,7 @@ private:
int iPage; int iPage;
}; };
inline bool BooksPageWidget::invertColors() const
{ return iSettings && iSettings->invertColors(); }
#endif // BOOKS_PAGE_WIDGET_H #endif // BOOKS_PAGE_WIDGET_H

View file

@ -43,9 +43,11 @@
#define KEY_FONT_SIZE "fontSize" #define KEY_FONT_SIZE "fontSize"
#define KEY_PAGE_DETAILS "pageDetails" #define KEY_PAGE_DETAILS "pageDetails"
#define KEY_CURRENT_BOOK "currentBook" #define KEY_CURRENT_BOOK "currentBook"
#define KEY_INVERT_COLORS "invertColors"
#define DEFAULT_FONT_SIZE 0 #define DEFAULT_FONT_SIZE 0
#define DEFAULT_PAGE_DETAILS 0 #define DEFAULT_PAGE_DETAILS 0
#define DEFAULT_CURRENT_BOOK QString() #define DEFAULT_CURRENT_BOOK QString()
#define DEFAULT_INVERT_COLORS false
// ========================================================================== // ==========================================================================
// BooksSettings::TextStyle // BooksSettings::TextStyle
@ -191,6 +193,7 @@ BooksSettings::BooksSettings(QObject* aParent) :
QObject(aParent), QObject(aParent),
iFontSize(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)), iFontSize(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)),
iPageDetails(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS, this)), iPageDetails(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS, this)),
iInvertColors(new MGConfItem(DCONF_PATH KEY_INVERT_COLORS, this)),
iCurrentBookPath(new MGConfItem(DCONF_PATH KEY_CURRENT_BOOK, this)), iCurrentBookPath(new MGConfItem(DCONF_PATH KEY_CURRENT_BOOK, this)),
iCurrentBook(NULL) iCurrentBook(NULL)
{ {
@ -198,6 +201,7 @@ BooksSettings::BooksSettings(QObject* aParent) :
updateCurrentBook(); updateCurrentBook();
connect(iFontSize, SIGNAL(valueChanged()), SLOT(onFontSizeValueChanged())); connect(iFontSize, SIGNAL(valueChanged()), SLOT(onFontSizeValueChanged()));
connect(iPageDetails, SIGNAL(valueChanged()), SIGNAL(pageDetailsChanged())); connect(iPageDetails, SIGNAL(valueChanged()), SIGNAL(pageDetailsChanged()));
connect(iInvertColors, SIGNAL(valueChanged()), SIGNAL(invertColorsChanged()));
connect(iCurrentBookPath, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged())); connect(iCurrentBookPath, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged()));
} }
@ -239,6 +243,20 @@ BooksSettings::setPageDetails(
iPageDetails->set(aValue); iPageDetails->set(aValue);
} }
bool
BooksSettings::invertColors() const
{
return iInvertColors->value(DEFAULT_INVERT_COLORS).toBool();
}
void
BooksSettings::setInvertColors(
bool aValue)
{
HDEBUG(aValue);
iInvertColors->set(aValue);
}
QObject* QObject*
BooksSettings::currentBook() const BooksSettings::currentBook() const
{ {

View file

@ -46,6 +46,7 @@ class BooksSettings : public QObject
Q_ENUMS(FontSize) Q_ENUMS(FontSize)
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(int pageDetails READ pageDetails WRITE setPageDetails NOTIFY pageDetailsChanged) Q_PROPERTY(int pageDetails READ pageDetails WRITE setPageDetails NOTIFY pageDetailsChanged)
Q_PROPERTY(bool invertColors READ invertColors WRITE setInvertColors NOTIFY invertColorsChanged)
Q_PROPERTY(QObject* currentBook READ currentBook WRITE setCurrentBook NOTIFY currentBookChanged) Q_PROPERTY(QObject* currentBook READ currentBook WRITE setCurrentBook NOTIFY currentBookChanged)
class TextStyle; class TextStyle;
@ -66,6 +67,9 @@ public:
shared_ptr<ZLTextStyle> textStyle() const { return iTextStyle; } shared_ptr<ZLTextStyle> textStyle() const { return iTextStyle; }
bool invertColors() const;
void setInvertColors(bool aValue);
QObject* currentBook() const; QObject* currentBook() const;
void setCurrentBook(QObject* aBook); void setCurrentBook(QObject* aBook);
@ -73,6 +77,7 @@ signals:
void fontSizeChanged(); void fontSizeChanged();
void textStyleChanged(); void textStyleChanged();
void pageDetailsChanged(); void pageDetailsChanged();
void invertColorsChanged();
void currentBookChanged(); void currentBookChanged();
private Q_SLOTS: private Q_SLOTS:
@ -86,6 +91,7 @@ private:
private: private:
MGConfItem* iFontSize; MGConfItem* iFontSize;
MGConfItem* iPageDetails; MGConfItem* iPageDetails;
MGConfItem* iInvertColors;
MGConfItem* iCurrentBookPath; MGConfItem* iCurrentBookPath;
shared_ptr<ZLTextStyle> iTextStyle; shared_ptr<ZLTextStyle> iTextStyle;
BooksBook* iCurrentBook; BooksBook* iCurrentBook;

View file

@ -34,17 +34,18 @@
#include "BooksTextView.h" #include "BooksTextView.h"
#include "BooksTextStyle.h" #include "BooksTextStyle.h"
#include "options/FBOptions.h"
#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(
ZLPaintContext& aContext, ZLPaintContext& aContext,
shared_ptr<ZLTextStyle> aTextStyle, shared_ptr<ZLTextStyle> aTextStyle,
BooksMargins aMargins) : BooksMargins aMargins) :
SUPER(aContext), SUPER(aContext),
iMargins(aMargins), iMargins(aMargins),
iBackgroundColor(255, 255, 255), iInvertColors(false),
iTextStyle(aTextStyle) iTextStyle(aTextStyle)
{ {
} }
@ -81,12 +82,30 @@ int BooksTextView::bottomMargin() const
ZLColor BooksTextView::backgroundColor() const ZLColor BooksTextView::backgroundColor() const
{ {
return iBackgroundColor; return iInvertColors ? INVERTED_BACKGROUND : DEFAULT_BACKGROUND;
} }
ZLColor BooksTextView::color(const std::string &colorStyle) const ZLColor BooksTextView::color(const std::string &aStyle) const
{ {
return FBOptions::Instance().colorOption(colorStyle).value(); static const std::string INTERNAL_HYPERLINK("internal");
static const std::string EXTERNAL_HYPERLINK("external");
static const std::string BOOK_HYPERLINK("book");
if (aStyle == INTERNAL_HYPERLINK) {
return ZLColor(33, 96, 180);
} else if (aStyle == EXTERNAL_HYPERLINK) {
return ZLColor(33, 96, 180);
} else if (aStyle == BOOK_HYPERLINK) {
return ZLColor(23, 68, 128);
} else if (aStyle == ZLTextStyle::SELECTION_BACKGROUND) {
return ZLColor(82, 131, 194);
} else if (aStyle == ZLTextStyle::HIGHLIGHTED_TEXT) {
return ZLColor(60, 139, 255);
} else if (iInvertColors) {
return ZLColor(255, 255, 255);
} else {
return ZLColor(0, 0, 0);
}
} }
shared_ptr<ZLTextStyle> BooksTextView::baseStyle() const shared_ptr<ZLTextStyle> BooksTextView::baseStyle() const

View file

@ -50,9 +50,13 @@ 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();
void setInvertColors(bool aInvertColors);
void gotoPosition(const BooksPos& aPos); void gotoPosition(const BooksPos& aPos);
bool nextPage(); bool nextPage();
void paint(); void paint();
@ -74,16 +78,16 @@ public:
virtual ZLColor color(const std::string &style = std::string()) const; virtual ZLColor color(const std::string &style = std::string()) const;
virtual bool isSelectionEnabled() const; virtual bool isSelectionEnabled() const;
public:
BooksMargins iMargins;
ZLColor iBackgroundColor;
private: private:
BooksMargins iMargins;
bool iInvertColors;
std::string iCaption; std::string iCaption;
shared_ptr<ZLTextStyle> iTextStyle; shared_ptr<ZLTextStyle> iTextStyle;
}; };
inline BooksPos BooksTextView::position() const inline BooksPos BooksTextView::position() const
{ return BooksPos(textArea().startCursor()); } { return BooksPos(textArea().startCursor()); }
inline void BooksTextView::setInvertColors(bool aInvertColors)
{ iInvertColors = aInvertColors; }
#endif // BOOKS_TEXT_VIEW_H #endif // BOOKS_TEXT_VIEW_H

View file

@ -166,7 +166,11 @@ void ZLibrary::run(ZLApplication* aApp)
QQuickView* view = SailfishApp::createView(); QQuickView* view = SailfishApp::createView();
view->setSource(QUrl::fromLocalFile(qml)); view->setSource(QUrl::fromLocalFile(qml));
view->rootContext()->setContextProperty("PointsPerInch", BOOKS_PPI);
QQmlContext* root = view->rootContext();
root->setContextProperty("PointsPerInch", BOOKS_PPI);
root->setContextProperty("DoubleClickInterval",
qApp->styleHints()->mouseDoubleClickInterval());
view->show(); view->show();
HDEBUG("started"); HDEBUG("started");

View file

@ -273,14 +273,10 @@ FBREADER_SRC = $$FBREADER_DIR/fbreader/src
SOURCES += \ SOURCES += \
$$FBREADER_SRC/migration/BookInfo.cpp \ $$FBREADER_SRC/migration/BookInfo.cpp \
$$FBREADER_SRC/options/FBOptions.cpp \
$$FBREADER_SRC/options/FBCategoryKey.cpp \ $$FBREADER_SRC/options/FBCategoryKey.cpp \
$$FBREADER_SRC/fbreader/PreferencesPopupData.cpp \
$$FBREADER_SRC/fbreader/TimeUpdater.cpp \
$$FBREADER_SRC/fbreader/SearchActions.cpp \ $$FBREADER_SRC/fbreader/SearchActions.cpp \
$$FBREADER_SRC/fbreader/ContentsView.cpp \ $$FBREADER_SRC/fbreader/ContentsView.cpp \
$$FBREADER_SRC/fbreader/BookTextView.cpp \ $$FBREADER_SRC/fbreader/BookTextView.cpp \
$$FBREADER_SRC/fbreader/RecentBooksPopupData.cpp \
$$FBREADER_SRC/library/Book.cpp \ $$FBREADER_SRC/library/Book.cpp \
$$FBREADER_SRC/library/Comparators.cpp \ $$FBREADER_SRC/library/Comparators.cpp \
$$FBREADER_SRC/library/Library.cpp \ $$FBREADER_SRC/library/Library.cpp \
@ -373,14 +369,11 @@ SOURCES += \
HEADERS += \ HEADERS += \
$$FBREADER_SRC/migration/BookInfo.h \ $$FBREADER_SRC/migration/BookInfo.h \
$$FBREADER_SRC/options/FBOptions.h \ $$FBREADER_SRC/options/FBCategoryKey.h \
$$FBREADER_SRC/fbreader/FBView.h \ $$FBREADER_SRC/fbreader/FBView.h \
$$FBREADER_SRC/fbreader/ReadingState.h \ $$FBREADER_SRC/fbreader/ReadingState.h \
$$FBREADER_SRC/fbreader/FBReaderActions.h \ $$FBREADER_SRC/fbreader/FBReaderActions.h \
$$FBREADER_SRC/fbreader/PreferencesPopupData.h \
$$FBREADER_SRC/fbreader/TimeUpdater.h \
$$FBREADER_SRC/fbreader/ContentsView.h \ $$FBREADER_SRC/fbreader/ContentsView.h \
$$FBREADER_SRC/fbreader/RecentBooksPopupData.h \
$$FBREADER_SRC/fbreader/FootnoteView.h \ $$FBREADER_SRC/fbreader/FootnoteView.h \
$$FBREADER_SRC/fbreader/BookTextView.h \ $$FBREADER_SRC/fbreader/BookTextView.h \
$$FBREADER_SRC/library/Author.h \ $$FBREADER_SRC/library/Author.h \