From 024f6df9de3780f6a3185a565d4a0adc684b4bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 13 Aug 2023 11:15:47 +0200 Subject: [PATCH] Add methods to the flow implementations to add new items dynamically --- common/gl/yacreader_flow_gl.cpp | 34 ++++++++++++++++++++++++++++++++- common/gl/yacreader_flow_gl.h | 3 +++ common/pictureflow.cpp | 7 +++++++ common/pictureflow.h | 7 ++++++- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/common/gl/yacreader_flow_gl.cpp b/common/gl/yacreader_flow_gl.cpp index a5f8aa72..b75cf0b8 100644 --- a/common/gl/yacreader_flow_gl.cpp +++ b/common/gl/yacreader_flow_gl.cpp @@ -724,6 +724,24 @@ void YACReaderFlowGL::remove(int item) numObjects--; } +void YACReaderFlowGL::add(int item) +{ + float x = 1; + float y = 1 * (700.f / 480.0f); + QString s = "cover"; + + images.insert(item, YACReader3DImage()); + loaded.insert(item, false); + marks.insert(item, Unread); + numObjects++; + + for (int i = item + 1; i < numObjects; i++) { + images[i].index++; + } + + insert(s.toLocal8Bit().data(), defaultTexture, x, y, item); +} + /*Info*/ YACReader3DImage YACReaderFlowGL::getCurrentSelected() { @@ -747,6 +765,7 @@ void YACReaderFlowGL::replace(char *name, QOpenGLTexture *texture, float x, floa void YACReaderFlowGL::populate(int n) { emit centerIndexChanged(0); + float x = 1; float y = 1 * (700.f / 480.0f); int i; @@ -1218,8 +1237,21 @@ void YACReaderComicFlowGL::remove(int item) worker->lock(); worker->reset(); YACReaderFlowGL::remove(item); - if (item >= 0 && item < paths.size()) + if (item >= 0 && item < paths.size()) { paths.removeAt(item); + } + worker->unlock(); +} + +void YACReaderComicFlowGL::add(const QString &path, int index) +{ + worker->lock(); + worker->reset(); + + paths.insert(index, path); + + YACReaderFlowGL::add(index); + worker->unlock(); } diff --git a/common/gl/yacreader_flow_gl.h b/common/gl/yacreader_flow_gl.h index e594c4f4..b40ea412 100644 --- a/common/gl/yacreader_flow_gl.h +++ b/common/gl/yacreader_flow_gl.h @@ -207,6 +207,8 @@ public: void insert(char *name, QOpenGLTexture *texture, float x, float y, int item = -1); // removes a item virtual void remove(int item); + // inserts a default texture into `item` and set is as pending to load + void add(int item); // replaces the texture of the item 'item' with Tex void replace(char *name, QOpenGLTexture *texture, float x, float y, int item); // create n covers with the default nu @@ -295,6 +297,7 @@ public: void setImagePaths(QStringList paths); void updateImageData(); void remove(int item); + void add(const QString &path, int index); void resortCovers(QList newOrder); friend class ImageLoaderGL; diff --git a/common/pictureflow.cpp b/common/pictureflow.cpp index 4e552a50..323db42f 100644 --- a/common/pictureflow.cpp +++ b/common/pictureflow.cpp @@ -1084,6 +1084,13 @@ void PictureFlow::addSlide(const QPixmap &pixmap) addSlide(pixmap.toImage()); } +void PictureFlow::insertSlide(int index) +{ + d->state->slideImages.insert(index, new QImage()); + d->state->marks.insert(index, YACReader::Unread); + triggerRender(); +} + void PictureFlow::removeSlide(int index) { int c = d->state->slideImages.count(); diff --git a/common/pictureflow.h b/common/pictureflow.h index d7d6ea05..e1d9c68d 100644 --- a/common/pictureflow.h +++ b/common/pictureflow.h @@ -133,7 +133,12 @@ public slots: void addSlide(const QPixmap &pixmap); /*! - Removes an existing slide. + Insert and empty slide at index. + */ + void insertSlide(int index); + + /*! + Removes an existing slide. */ void removeSlide(int index);