From 72f4fbd658f738b06f4fc895106d700801ff3ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 22 Dec 2013 12:29:36 +0100 Subject: [PATCH] fixed wrong cover being loaded after deleting a comic --- YACReaderLibrary/comic_flow.cpp | 19 +++++++++++++++++- YACReaderLibrary/comic_flow.h | 2 ++ common/yacreader_flow_gl.cpp | 34 +++++++++++++++++++++++++++------ common/yacreader_flow_gl.h | 7 +++++-- 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/YACReaderLibrary/comic_flow.cpp b/YACReaderLibrary/comic_flow.cpp index 72e15bc0..6404e817 100644 --- a/YACReaderLibrary/comic_flow.cpp +++ b/YACReaderLibrary/comic_flow.cpp @@ -129,6 +129,10 @@ void ComicFlow::wheelEvent(QWheelEvent * event) void ComicFlow::removeSlide(int cover) { + worker->lock(); + + worker->reset(); + imageFiles.removeAt(cover); if(imagesLoaded[cover]) numImagesLoaded--; @@ -136,6 +140,9 @@ void ComicFlow::removeSlide(int cover) imagesSetted.remove(cover); YACReaderFlow::removeSlide(cover); + worker->unlock(); + + preload(); } //----------------------------------------------------------------------------- //ImageLoader @@ -188,6 +195,16 @@ void ImageLoader::generate(int index, const QString& fileName, QSize size) } } +void ImageLoader::lock() +{ + mutex.lock(); +} + +void ImageLoader::unlock() +{ + mutex.unlock(); +} + void ImageLoader::run() { for(;;) @@ -218,4 +235,4 @@ void ImageLoader::run() QImage ImageLoader::result() { return img; -} \ No newline at end of file +} diff --git a/YACReaderLibrary/comic_flow.h b/YACReaderLibrary/comic_flow.h index 7d173550..632e4871 100644 --- a/YACReaderLibrary/comic_flow.h +++ b/YACReaderLibrary/comic_flow.h @@ -54,6 +54,8 @@ public: void generate(int index, const QString& fileName, QSize size); void reset(){idx = -1;}; int index() const { return idx; }; + void lock(); + void unlock(); QImage result(); protected: diff --git a/common/yacreader_flow_gl.cpp b/common/yacreader_flow_gl.cpp index 9dc08f02..9e999688 100644 --- a/common/yacreader_flow_gl.cpp +++ b/common/yacreader_flow_gl.cpp @@ -691,11 +691,15 @@ CFImage YACReaderFlowGL::getCurrentSelected() void YACReaderFlowGL::replace(char *name, GLuint Tex, float x, float y,int item) { Q_UNUSED(name) - cfImages[item].img = Tex; - cfImages[item].width = x; - cfImages[item].height = y; - //strcpy(cfImages[item].name,name); - loaded[item]=true; + if(cfImages[item].index == item) + { + cfImages[item].img = Tex; + cfImages[item].width = x; + cfImages[item].height = y; + loaded[item]=true; + } + else + loaded[item]=false; } void YACReaderFlowGL::populate(int n) @@ -1081,7 +1085,7 @@ void YACReaderComicFlowGL::updateImageData() CFImages[idx].height = y; CFImages[idx].img = worker->resultTexture; strcpy(CFImages[idx].name,"cover");*/ - loaded[idx] = true; + //loaded[idx] = true; //numImagesLoaded++; } } @@ -1134,6 +1138,14 @@ void YACReaderComicFlowGL::updateImageData() } } +void YACReaderComicFlowGL::remove(int item) +{ + worker->lock(); + worker->reset(); + YACReaderFlowGL::remove(item); + worker->unlock(); +} + YACReaderPageFlowGL::YACReaderPageFlowGL(QWidget *parent,struct Preset p ) :YACReaderFlowGL(parent,p) @@ -1312,6 +1324,16 @@ void ImageLoaderGL::generate(int index, const QString& fileName) } } +void ImageLoaderGL::lock() +{ + mutex.lock(); +} + +void ImageLoaderGL::unlock() +{ + mutex.unlock(); +} + void ImageLoaderGL::run() { for(;;) diff --git a/common/yacreader_flow_gl.h b/common/yacreader_flow_gl.h index 44eb7c5b..d885ad36 100644 --- a/common/yacreader_flow_gl.h +++ b/common/yacreader_flow_gl.h @@ -196,7 +196,7 @@ public: //otherwise a new entry is set void insert(char *name, GLuint Tex, float x, float y,int item = -1); //removes a item - void remove(int item); + virtual void remove(int item); //replaces the texture of the item 'item' with Tex void replace(char *name, GLuint Tex, float x, float y,int item); //create n covers with the default nu @@ -292,6 +292,7 @@ public: YACReaderComicFlowGL(QWidget *parent = 0,struct Preset p = defaultYACReaderFlowConfig); void setImagePaths(QStringList paths); void updateImageData(); + void remove(int item); friend class ImageLoaderGL; private: ImageLoaderGL * worker; @@ -323,6 +324,8 @@ public: void generate(int index, const QString& fileName); void reset(){idx = -1;fileName="";}; int index() const { return idx; }; + void lock(); + void unlock(); QImage result(); YACReaderFlowGL * flow; GLuint resultTexture; @@ -389,4 +392,4 @@ private: // //}; -#endif \ No newline at end of file +#endif