diff --git a/YACReaderLibrary/info_comics_view.cpp b/YACReaderLibrary/info_comics_view.cpp index 8367e9c5..47f8e3c8 100644 --- a/YACReaderLibrary/info_comics_view.cpp +++ b/YACReaderLibrary/info_comics_view.cpp @@ -1,9 +1,32 @@ #include "info_comics_view.h" +#include + +#include "comic_model.h" + +#include "QsLog.h" + InfoComicsView::InfoComicsView(QWidget *parent) :ComicsView(parent) { - int FIXME; + qmlRegisterType("com.yacreader.ComicModel",1,0,"ComicModel"); + + view = new QQuickView(); + container = QWidget::createWindowContainer(view, this); + + container->setFocusPolicy(Qt::StrongFocus); + + view->setSource(QUrl("qrc:/qml/InfoComicsView.qml")); + + QVBoxLayout * l = new QVBoxLayout; + l->addWidget(container); + this->setLayout(l); + + setContentsMargins(0,0,0,0); + l->setContentsMargins(0,0,0,0); + l->setSpacing(0); + + QLOG_TRACE() << "GridComicsView"; } void InfoComicsView::setToolBar(QToolBar *toolBar) @@ -15,7 +38,36 @@ void InfoComicsView::setToolBar(QToolBar *toolBar) void InfoComicsView::setModel(ComicModel *model) { - int FIXME; + if(model == NULL) + return; + + ComicsView::setModel(model); + + QQmlContext *ctxt = view->rootContext(); + + /*if(_selectionModel != NULL) + delete _selectionModel; + + _selectionModel = new QItemSelectionModel(model);*/ + + //TODO fix crash in the following line on comics views switch + + int row = currentIndex().row(); + ctxt->setContextProperty("comicsList", model); + ctxt->setContextProperty("backgroundImage", this->model->data(this->model->index(0, 0), ComicModel::CoverPathRole)); + + /*ctxt->setContextProperty("comicsSelection", _selectionModel); + ctxt->setContextProperty("contextMenuHelper",this); + ctxt->setContextProperty("comicsSelectionHelper", this); + ctxt->setContextProperty("comicRatingHelper", this); + ctxt->setContextProperty("dummyValue", true); + ctxt->setContextProperty("dragManager", this); + ctxt->setContextProperty("dropManager", this); + + updateBackgroundConfig();*/ + + if(model->rowCount()>0) + setCurrentIndex(model->index(0,0)); } void InfoComicsView::setCurrentIndex(const QModelIndex &index) diff --git a/YACReaderLibrary/info_comics_view.h b/YACReaderLibrary/info_comics_view.h index 12206681..010016bf 100644 --- a/YACReaderLibrary/info_comics_view.h +++ b/YACReaderLibrary/info_comics_view.h @@ -5,6 +5,10 @@ +class QQuickView; + + + class InfoComicsView : public ComicsView { Q_OBJECT @@ -25,6 +29,10 @@ public: public slots: void setShowMarks(bool show); void selectAll(); + +protected: + QQuickView *view; + QWidget *container; }; #endif // INFOCOMICSVIEW_H diff --git a/YACReaderLibrary/qml.qrc b/YACReaderLibrary/qml.qrc index 9952ca07..9d54b1a1 100644 --- a/YACReaderLibrary/qml.qrc +++ b/YACReaderLibrary/qml.qrc @@ -6,5 +6,10 @@ qml/reading.png qml/star_menu.png qml/star_menu@2x.png + qml/InfoComicsView.qml + qml/FlowView.qml + qml/info-indicator.png + qml/info-shadow.png + qml/info-top-shadow.png diff --git a/YACReaderLibrary/qml/FlowView.qml b/YACReaderLibrary/qml/FlowView.qml new file mode 100644 index 00000000..0fe9de0e --- /dev/null +++ b/YACReaderLibrary/qml/FlowView.qml @@ -0,0 +1,180 @@ +import QtQuick 2.3 + +import QtGraphicalEffects 1.0 + +import com.yacreader.ComicModel 1.0 + +Rectangle { + property url backgroundImageURL; + + property real backgroundBlurRadius : 100; + property real backgroundBlurOpacity : 0.25; + property bool backgroundBlurVisible : true; + + property real additionalBottomSpace; + + property real verticalPadding: 11 + + Rectangle { + id: background + color: "#2A2A2A" + anchors.fill: backgroundImg + } + + Image { + id: backgroundImg + width: parent.width + height: parent.height + additionalBottomSpace + 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 + } + + anchors.margins: 0 + + + MouseArea { + anchors.fill : list + onWheel: { + var ci + if(wheel.angleDelta.y < 0) { + ci = Math.min(list.currentIndex+1, list.count); + } + else if(wheel.angleDelta.y > 0) { + ci = Math.max(0,list.currentIndex-1); + } else { + return; + } + + list.currentIndex = ci; + } + } + + ListView { + id: list + anchors.fill: parent + + property int previousIndex; + + orientation: Qt.Horizontal + pixelAligned: true + + model: comicsList + + spacing: 16 + anchors.leftMargin: 11 + + snapMode: ListView.SnapToItem + + highlightFollowsCurrentItem: true + highlightRangeMode: ListView.StrictlyEnforceRange + preferredHighlightEnd: 50 + + delegate: Component { + + //cover + Rectangle { + width: Math.floor((list.height - (verticalPadding * 2)) * 0.65); + height: list.height - (verticalPadding * 2); + anchors.verticalCenter: parent.verticalCenter + + color:"transparent" + + DropShadow { + anchors.fill: coverElement + horizontalOffset: 0 + verticalOffset: 0 + radius: 6 + samples: 17 + color: "#BB000000" + source: coverElement + visible: (Qt.platform.os === "osx") ? false : true; + } + + Image { + id: coverElement + anchors.fill: parent + source: cover_path + fillMode: Image.PreserveAspectCrop + smooth: true + mipmap: true + asynchronous : true + cache: false + } + + //border + Rectangle { + width: coverElement.width + height: coverElement.height + anchors.centerIn: coverElement + color: "transparent" + border { + color: "#30FFFFFF" + width: 1 + } + } + + MouseArea { + id: mouseArea + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + + onClicked: { + gotoIndex(index); + } + } + + NumberAnimation { + id: anim; + target: list; + property: "contentX"; + duration: Math.min(850, Math.max(350, 75 * Math.abs(list.currentIndex - list.previousIndex))) + } + + function gotoIndex(idx) { + var pos = list.contentX; + var destPos; + list.previousIndex = list.currentIndex + list.positionViewAtIndex(idx, ListView.Beginning); + destPos = list.contentX; + anim.from = pos; + anim.to = destPos; + anim.running = true; + } + } + } + + focus: true + Keys.onPressed: { + if (event.modifiers & Qt.ControlModifier || event.modifiers & Qt.ShiftModifier) + return; + var ci + if (event.key === Qt.Key_Right) { + ci = Math.min(list.currentIndex+1, list.count); + } + else if (event.key === Qt.Key_Left) { + ci = Math.max(0,list.currentIndex-1); + } else { + return; + } + + list.currentIndex = ci; + + event.accepted = true; + } + + } +} diff --git a/YACReaderLibrary/qml/InfoComicsView.qml b/YACReaderLibrary/qml/InfoComicsView.qml new file mode 100644 index 00000000..a172e61f --- /dev/null +++ b/YACReaderLibrary/qml/InfoComicsView.qml @@ -0,0 +1,62 @@ +import QtQuick 2.3 + +import QtQuick.Controls 1.2 +import QtGraphicalEffects 1.0 + +import com.yacreader.ComicModel 1.0 + +Rectangle { + id: main + + color: "#2e2e2e" + + width: parent.width + height: parent.height + anchors.margins: 0 + + FlowView { + id: flow + height: 256 //TODO dynamic size? + + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + + additionalBottomSpace: indicator.height + } + + Image { + id: top_shadow + source: "info-top-shadow.png" + width: parent.width + fillMode: Image.TileHorizontally + } + + Rectangle { + width: parent.width + y: 250 + + Image { + id: indicator + source: "info-indicator.png" + } + + Image { + id: bottom_shadow + x: indicator.width + width: parent.width - indicator.width + source: "info-shadow.png" + fillMode: Image.TileHorizontally + } + } + Rectangle { + id: info_container + width: parent.width + y: flow.height + flow.additionalBottomSpace - 6 + height: parent.height + + color: "#2e2e2e" + } + + +} diff --git a/YACReaderLibrary/qml/info-indicator.png b/YACReaderLibrary/qml/info-indicator.png new file mode 100644 index 00000000..af4a616a Binary files /dev/null and b/YACReaderLibrary/qml/info-indicator.png differ diff --git a/YACReaderLibrary/qml/info-shadow.png b/YACReaderLibrary/qml/info-shadow.png new file mode 100644 index 00000000..3508da2e Binary files /dev/null and b/YACReaderLibrary/qml/info-shadow.png differ diff --git a/YACReaderLibrary/qml/info-top-shadow.png b/YACReaderLibrary/qml/info-top-shadow.png new file mode 100644 index 00000000..1fd60281 Binary files /dev/null and b/YACReaderLibrary/qml/info-top-shadow.png differ