From de59cbd9e3235371c5d871888efa43991f002719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 7 Dec 2015 21:28:36 +0100 Subject: [PATCH] Added support for showing the first cover of a folder as the background image in the grid view. The setting strings have been added too, but by now they are not written, only the defaults are read when the folder's content is loaded. --- YACReaderLibrary/grid_comics_view.cpp | 31 +++++++++++++++++++++++++ YACReaderLibrary/qml/GridComicsView.qml | 29 ++++++++++++++++++++--- common/yacreader_global.h | 4 ++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/YACReaderLibrary/grid_comics_view.cpp b/YACReaderLibrary/grid_comics_view.cpp index 1fdae2ce..4b02b2e1 100644 --- a/YACReaderLibrary/grid_comics_view.cpp +++ b/YACReaderLibrary/grid_comics_view.cpp @@ -160,6 +160,37 @@ void GridComicsView::setModel(ComicModel *model) ctxt->setContextProperty("dragManager", this); ctxt->setContextProperty("dropManager", this); + + //backgroun image configuration + bool useBackgroundImage = settings->value(USE_BACKGROUND_IMAGE_IN_GRID_VIEW, true).toBool(); + + if(useBackgroundImage) + { + float opacity = settings->value(OPACITY_BACKGROUND_IMAGE_IN_GRID_VIEW, 0.2).toFloat(); + float blurRadius = settings->value(BLUR_RADIUS_BACKGROUND_IMAGE_IN_GRID_VIEW, 75).toFloat(); + + ctxt->setContextProperty("backgroundImage", this->model->data(this->model->index(0, 0), ComicModel::CoverPathRole)); + ctxt->setContextProperty("backgroundBlurOpacity", opacity); + ctxt->setContextProperty("backgroundBlurRadius", blurRadius); + ctxt->setContextProperty("backgroundBlurVisible", true); + } + else + { + ctxt->setContextProperty("backgroundImage", QVariant()); + ctxt->setContextProperty("backgroundBlurOpacity", 0); + ctxt->setContextProperty("backgroundBlurRadius", 0); + ctxt->setContextProperty("backgroundBlurVisible", false); + } + + +#ifdef Q_OS_MAC + ctxt->setContextProperty("cellColor", useBackgroundImage?"#99FFFFFF":"#FFFFFF"); + ctxt->setContextProperty("selectedColor", "#FFFFFF"); +#else + ctxt->setContextProperty("cellColor", useBackgroundImage?"#99212121":"#212121"); + ctxt->setContextProperty("selectedColor", "#121212"); +#endif + if(model->rowCount()>0) setCurrentIndex(model->index(0,0)); } diff --git a/YACReaderLibrary/qml/GridComicsView.qml b/YACReaderLibrary/qml/GridComicsView.qml index 49d41405..7c877b89 100644 --- a/YACReaderLibrary/qml/GridComicsView.qml +++ b/YACReaderLibrary/qml/GridComicsView.qml @@ -2,9 +2,33 @@ import QtQuick 2.3 import QtQuick.Controls 1.2 import comicModel 1.0 +import QtGraphicalEffects 1.0 Rectangle { id: main + clip: true + + Image { + id: backgroundImg + anchors.fill: parent + source: backgroundImage + fillMode: Image.PreserveAspectCrop + smooth: true + mipmap: true + asynchronous : true + cache: false //TODO clear cache only when it is needed + opacity: 0 + visible: false + } + + FastBlur { + anchors.fill: backgroundImg + source: backgroundImg + radius: backgroundBlurRadius + opacity: backgroundBlurOpacity + visible: backgroundBlurVisible + } + color: backgroundColor width: parent.width height: parent.height @@ -25,7 +49,7 @@ Rectangle { id: cell width: grid.cellWidth height: grid.cellHeight - color: backgroundColor + color: "#00000000" Rectangle { @@ -54,7 +78,6 @@ Rectangle { color: ((dummyValue || !dummyValue) && comicsSelectionHelper.isSelectedIndex(index))?selectedColor:cellColor; border.color: ((dummyValue || !dummyValue) && comicsSelectionHelper.isSelectedIndex(index))?selectedBorderColor:borderColor; border.width: (Qt.platform.os === "osx")?1:0; - anchors.horizontalCenter: parent.horizontalCenter MouseArea { @@ -367,7 +390,7 @@ Rectangle { footer: Rectangle { //fix for the scroll issue, TODO find what causes the issue (some times the bottoms cells are hidden for the toolbar, no full scroll) height : 25 width : parent.width - color : backgroundColor + color : "#00000000" } move: Transition { diff --git a/common/yacreader_global.h b/common/yacreader_global.h index 8b97656a..caf4086a 100644 --- a/common/yacreader_global.h +++ b/common/yacreader_global.h @@ -62,6 +62,10 @@ #define SIDEBAR_SPLITTER_STATUS "SIDEBAR_SPLITTER_STATUS" #define COMICS_GRID_COVER_SIZES "COMICS_GRID_COVER_SIZES" +#define USE_BACKGROUND_IMAGE_IN_GRID_VIEW "USE_BACKGROUND_IMAGE_IN_GRID_VIEW" +#define OPACITY_BACKGROUND_IMAGE_IN_GRID_VIEW "OPACITY_BACKGROUND_IMAGE_IN_GRID_VIEW" +#define BLUR_RADIUS_BACKGROUND_IMAGE_IN_GRID_VIEW "BLUR_RADIUS_BACKGROUND_IMAGE_IN_GRID_VIEW" + #define NUM_DAYS_BETWEEN_VERSION_CHECKS "NUM_DAYS_BETWEEN_VERSION_CHECKS" #define LAST_VERSION_CHECK "LAST_VERSION_CHECK"