diff --git a/YACReaderLibrary/classic_comics_view.cpp b/YACReaderLibrary/classic_comics_view.cpp index 4a72fd54..162367b2 100644 --- a/YACReaderLibrary/classic_comics_view.cpp +++ b/YACReaderLibrary/classic_comics_view.cpp @@ -337,12 +337,12 @@ void ClassicComicsView::removeItemsFromFlow(const QModelIndex &parent, int from, void ClassicComicsView::closeEvent(QCloseEvent *event) { + toolbar->removeAction(toolBarStretchAction); + toolbar->removeAction(hideFlowViewAction); + saveTableHeadersStatus(); saveSplitterStatus(); ComicsView::closeEvent(event); - - toolbar->removeAction(toolBarStretchAction); - toolbar->removeAction(hideFlowViewAction); } void ClassicComicsView::setupSearchingIcon() diff --git a/YACReaderLibrary/grid_comics_view.cpp b/YACReaderLibrary/grid_comics_view.cpp index 8f4602a5..601f6b5d 100644 --- a/YACReaderLibrary/grid_comics_view.cpp +++ b/YACReaderLibrary/grid_comics_view.cpp @@ -1,16 +1,37 @@ #include "grid_comics_view.h" -#include #include +#include -#include "yacreader_global.h" #include "comic.h" #include "comic_files_manager.h" #include "QsLog.h" +#include "yacreader_global.h" +#include "yacreader_tool_bar_stretch.h" + +//values relative to visible cells +const unsigned int YACREADER_MIN_GRID_ZOOM_WIDTH = 156; +const unsigned int YACREADER_MAX_GRID_ZOOM_WIDTH = 312; + +//GridView cells +const unsigned int YACREADER_MIN_CELL_CUSTOM_HEIGHT = 295; +const unsigned int YACREADER_MIN_CELL_CUSTOM_WIDTH = 185; + +//Covers +const unsigned int YACREADER_MAX_COVER_HEIGHT = 236; +const unsigned int YACREADER_MIN_COVER_WIDTH = YACREADER_MIN_GRID_ZOOM_WIDTH; + +//visible cells (realCell in qml), grid cells size is used to create faux inner margings +const unsigned int YACREADER_MIN_ITEM_HEIGHT = YACREADER_MAX_COVER_HEIGHT + 51; //51 is the height of the bottom rectangle used for title and other info +const unsigned int YACREADER_MIN_ITEM_WIDTH = YACREADER_MIN_COVER_WIDTH; + GridComicsView::GridComicsView(QWidget *parent) : ComicsView(parent),_selectionModel(NULL) { + settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini", QSettings::IniFormat, this); + settings->beginGroup("libraryConfig"); + qmlRegisterType("comicModel",1,0,"TableModel"); view = new QQuickView(); @@ -20,60 +41,15 @@ GridComicsView::GridComicsView(QWidget *parent) : container->setFocusPolicy(Qt::TabFocus); view->setSource(QUrl("qrc:/qml/GridComicsView.qml")); - setShowMarks(true);//TODO save this in settings + createCoverSizeSliderWidget(); - QVBoxLayout * l = new QVBoxLayout; - l->addWidget(container); - this->setLayout(l); + int coverSize = settings->value(COMICS_GRID_COVER_SIZES, YACREADER_MIN_COVER_WIDTH).toInt(); - setContentsMargins(0,0,0,0); - l->setContentsMargins(0,0,0,0); - l->setSpacing(0); - - QLOG_INFO() << "GridComicsView"; -} - -GridComicsView::~GridComicsView() -{ - delete view; -} - -void GridComicsView::setToolBar(QToolBar *toolBar) -{ - QLOG_INFO() << "setToolBar"; - static_cast(this->layout())->insertWidget(1,toolBar); - this->toolbar = toolBar; -} - -void GridComicsView::setModel(ComicModel *model) -{ - QLOG_INFO() << "setModel"; + coverSizeSlider->setValue(coverSize); + setCoversSize(coverSize); QQmlContext *ctxt = view->rootContext(); - //there is only one mothel in the system - ComicsView::setModel(model); - if(this->model != NULL) - { - QLOG_INFO() << "xxx"; - - if(_selectionModel != NULL) - delete _selectionModel; - _selectionModel = new QItemSelectionModel(this->model); - - ctxt->setContextProperty("comicsList", this->model); - 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); - - if(model->rowCount()>0) - setCurrentIndex(model->index(0,0)); - } - #ifdef Q_OS_MAC ctxt->setContextProperty("backgroundColor", "#F5F5F5"); ctxt->setContextProperty("cellColor", "#FFFFFF"); @@ -105,6 +81,90 @@ void GridComicsView::setModel(ComicModel *model) ctxt->setContextProperty("fontSpacing", 0.5); #endif + setShowMarks(true);//TODO save this in settings + + 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_INFO() << "GridComicsView"; +} + +GridComicsView::~GridComicsView() +{ + delete view; +} + +void GridComicsView::createCoverSizeSliderWidget() +{ + toolBarStretch = new YACReaderToolBarStretch(this); + coverSizeSliderWidget = new QWidget(this); + coverSizeSliderWidget->setFixedWidth(200); + coverSizeSlider = new QSlider(); + coverSizeSlider->setOrientation(Qt::Horizontal); + coverSizeSlider->setRange(YACREADER_MIN_GRID_ZOOM_WIDTH, YACREADER_MAX_GRID_ZOOM_WIDTH); + + QHBoxLayout * horizontalLayout = new QHBoxLayout(); + QLabel * smallLabel = new QLabel(); + smallLabel->setPixmap(QPixmap(":/images/small_size_grid_zoom.png")); + horizontalLayout->addWidget(smallLabel); + horizontalLayout->addWidget(coverSizeSlider, 0, Qt::AlignVCenter); + QLabel * bigLabel = new QLabel(); + bigLabel->setPixmap(QPixmap(":/images/big_size_grid_zoom.png")); + horizontalLayout->addWidget(bigLabel); + horizontalLayout->addSpacing(10); + horizontalLayout->setMargin(0); + + coverSizeSliderWidget->setLayout(horizontalLayout); + //TODO add shortcuts (ctrl-+ and ctrl-- for zooming in out, + ctrl-0 for reseting the zoom) + + connect(coverSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(setCoversSize(int))); +} + +void GridComicsView::setToolBar(QToolBar *toolBar) +{ + QLOG_INFO() << "setToolBar"; + static_cast(this->layout())->insertWidget(1,toolBar); + this->toolbar = toolBar; + + toolBarStretchAction = toolBar->addWidget(toolBarStretch); + coverSizeSliderAction = toolBar->addWidget(coverSizeSliderWidget); +} + +void GridComicsView::setModel(ComicModel *model) +{ + QLOG_INFO() << "setModel"; + + QQmlContext *ctxt = view->rootContext(); + + //there is only one mothel in the system + ComicsView::setModel(model); + if(this->model != NULL) + { + QLOG_INFO() << "xxx"; + + if(_selectionModel != NULL) + delete _selectionModel; + _selectionModel = new QItemSelectionModel(this->model); + + ctxt->setContextProperty("comicsList", this->model); + 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); + + if(model->rowCount()>0) + setCurrentIndex(model->index(0,0)); + } + + } @@ -185,6 +245,32 @@ void GridComicsView::requestedContextMenu(const QPoint &point) emit customContextMenuViewRequested(point); } +void GridComicsView::setCoversSize(int width) +{ + QQmlContext *ctxt = view->rootContext(); + + QQuickItem * grid = view->rootObject()->findChild(QStringLiteral("grid")); + + if(grid != 0) + { + QLOG_INFO() << "method invoked"; + QVariant cellCustomWidth = (width * YACREADER_MIN_CELL_CUSTOM_WIDTH) / YACREADER_MIN_GRID_ZOOM_WIDTH; + QMetaObject::invokeMethod(grid, "calculateCellWidths", + Q_ARG(QVariant, cellCustomWidth)); + } + + int cellBottomMarging = 8 * (1 + 2*(1 - (float(YACREADER_MAX_GRID_ZOOM_WIDTH - width) / (YACREADER_MAX_GRID_ZOOM_WIDTH - YACREADER_MIN_GRID_ZOOM_WIDTH))) ); + + ctxt->setContextProperty("cellCustomHeight", ((width * YACREADER_MAX_COVER_HEIGHT) / YACREADER_MIN_COVER_WIDTH) + 51 + cellBottomMarging); + ctxt->setContextProperty("cellCustomWidth", (width * YACREADER_MIN_CELL_CUSTOM_WIDTH) / YACREADER_MIN_COVER_WIDTH ); + + ctxt->setContextProperty("itemWidth", width); + ctxt->setContextProperty("itemHeight", ((width * YACREADER_MAX_COVER_HEIGHT) / YACREADER_MIN_COVER_WIDTH) + 51); + + ctxt->setContextProperty("coverWidth", width); + ctxt->setContextProperty("coverHeight", (width * YACREADER_MAX_COVER_HEIGHT) / YACREADER_MIN_COVER_WIDTH); +} + QSize GridComicsView::sizeHint() { QLOG_INFO() << "sizeHint"; @@ -333,6 +419,9 @@ void GridComicsView::setShowMarks(bool show) void GridComicsView::closeEvent(QCloseEvent *event) { + toolbar->removeAction(toolBarStretchAction); + toolbar->removeAction(coverSizeSliderAction); + QLOG_INFO() << "closeEvent"; QObject *object = view->rootObject(); QMetaObject::invokeMethod(object, "exit"); @@ -340,4 +429,7 @@ void GridComicsView::closeEvent(QCloseEvent *event) view->close(); event->accept(); ComicsView::closeEvent(event); + + //save settings + settings->setValue(COMICS_GRID_COVER_SIZES, coverSizeSlider->value()); } diff --git a/YACReaderLibrary/grid_comics_view.h b/YACReaderLibrary/grid_comics_view.h index 77d3c343..da8a894c 100644 --- a/YACReaderLibrary/grid_comics_view.h +++ b/YACReaderLibrary/grid_comics_view.h @@ -10,6 +10,7 @@ class QItemSelectionModel; class QQuickView; class QQuickView; +class YACReaderToolBarStretch; class GridComicsView : public ComicsView { @@ -65,14 +66,22 @@ public slots: protected slots: void requestedContextMenu(const QPoint & point); + void setCoversSize(int width); private: + QSettings * settings; QToolBar * toolbar; + YACReaderToolBarStretch * toolBarStretch; + QAction * toolBarStretchAction; + QWidget * coverSizeSliderWidget; + QSlider * coverSizeSlider; + QAction * coverSizeSliderAction; QItemSelectionModel * _selectionModel; QQuickView *view; QWidget *container; bool dummy; void closeEvent ( QCloseEvent * event ); + void createCoverSizeSliderWidget(); }; diff --git a/YACReaderLibrary/images.qrc b/YACReaderLibrary/images.qrc index caffa5a1..3b1a3bce 100644 --- a/YACReaderLibrary/images.qrc +++ b/YACReaderLibrary/images.qrc @@ -30,6 +30,8 @@ ../images/editComic.png ../images/selectAll.png ../images/hideComicFlow.png + ../images/small_size_grid_zoom.png + ../images/big_size_grid_zoom.png ../images/exportComicsInfo.png ../images/importComicsInfo.png ../images/exportComicsInfoIcon.png diff --git a/YACReaderLibrary/qml/GridComicsView.qml b/YACReaderLibrary/qml/GridComicsView.qml index c8c04d11..99e1536c 100644 --- a/YACReaderLibrary/qml/GridComicsView.qml +++ b/YACReaderLibrary/qml/GridComicsView.qml @@ -48,7 +48,9 @@ Rectangle { dragging = false; } - width: 156; height: 287 + width: itemWidth + height: itemHeight + 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; @@ -159,9 +161,7 @@ Rectangle { } } } - } - } /**/ @@ -169,8 +169,8 @@ Rectangle { //cover Image { id: coverElement - width: 156 - height: 236 + width: coverWidth + height: coverHeight anchors {horizontalCenter: parent.horizontalCenter; top: realCell.top; topMargin: 0} source: cover_path fillMode: Image.PreserveAspectCrop @@ -183,8 +183,8 @@ Rectangle { //border Rectangle { - width: 156 - height: 236 + width: coverElement.width + height: coverElement.height anchors {horizontalCenter: parent.horizontalCenter; top: realCell.top; topMargin: 0} color: "transparent" border { @@ -206,8 +206,8 @@ Rectangle { //title Text { id : titleText - anchors { top: realCell.top; left: realCell.left; leftMargin: 4; rightMargin: 4; topMargin: 238; } - width: 148 + anchors { top: coverElement.bottom; left: realCell.left; leftMargin: 4; rightMargin: 4; topMargin: 4; } + width: itemWidth - 8 maximumLineCount: 2 wrapMode: Text.WordWrap text: title @@ -218,6 +218,7 @@ Rectangle { font.pointSize: fontSize font.family: fontFamily } + //number Text { anchors {bottom: realCell.bottom; left: realCell.left; margins: 4} @@ -227,12 +228,14 @@ Rectangle { font.pointSize: fontSize font.family: fontFamily } + //page icon Image { id: pageImage anchors {bottom: realCell.bottom; right: realCell.right; bottomMargin: 5; rightMargin: 4; leftMargin: 4} source: "page.png" } + //numPages Text { id: pages @@ -243,6 +246,7 @@ Rectangle { font.pointSize: fontSize font.family: fontFamily } + //rating icon Image { id: ratingImage @@ -282,7 +286,7 @@ Rectangle { } } - YACReaderScrollView{ + Rectangle{ id: scrollView anchors.fill: parent anchors.margins: 0 @@ -335,13 +339,13 @@ Rectangle { } } } - } GridView { id:grid + objectName: "grid" anchors.fill: parent - cellHeight: 295 + cellHeight: cellCustomHeight highlight: appHighlight focus: true model: comicsList @@ -388,20 +392,23 @@ Rectangle { } function numCellsPerRow() { - return Math.floor(width / 185); + return Math.floor(width / cellCustomWidth); } - onWidthChanged: { - var numCells = numCellsPerRow(); - var rest = width % 185; - - if(numCells > 0) - { - cellWidth = Math.floor(width / numCells) ; - //console.log("numCells=",numCells,"rest=",rest,"cellWidth=",cellWidth,"width=",width); - } + onWidthChanged: { + calculateCellWidths(cellCustomWidth); } + + function calculateCellWidths(cWidth) { + + var wholeCells = Math.floor(width / cWidth); + var rest = width - (cWidth * wholeCells) + + grid.cellWidth = cWidth + Math.floor(rest / wholeCells); + console.log("cWidth",cWidth,"wholeCells=",wholeCells,"rest=",rest,"cellWidth=",cellWidth,"width=",width); + } } + focus: true Keys.onPressed: { if (event.modifiers & Qt.ControlModifier || event.modifiers & Qt.ShiftModifier) diff --git a/common/yacreader_global.h b/common/yacreader_global.h index 74ce104e..8b97656a 100644 --- a/common/yacreader_global.h +++ b/common/yacreader_global.h @@ -60,6 +60,7 @@ #define COMICS_VIEW_STATUS "COMICS_VIEW_STATUS" #define COMICS_VIEW_FLOW_SPLITTER_STATUS "COMICS_VIEW_FLOW_SPLITTER_STATUS" #define SIDEBAR_SPLITTER_STATUS "SIDEBAR_SPLITTER_STATUS" +#define COMICS_GRID_COVER_SIZES "COMICS_GRID_COVER_SIZES" #define NUM_DAYS_BETWEEN_VERSION_CHECKS "NUM_DAYS_BETWEEN_VERSION_CHECKS" #define LAST_VERSION_CHECK "LAST_VERSION_CHECK" diff --git a/images/big_size_grid_zoom.png b/images/big_size_grid_zoom.png new file mode 100644 index 00000000..7497c8c5 Binary files /dev/null and b/images/big_size_grid_zoom.png differ diff --git a/images/small_size_grid_zoom.png b/images/small_size_grid_zoom.png new file mode 100644 index 00000000..a49972df Binary files /dev/null and b/images/small_size_grid_zoom.png differ