diff --git a/YACReader/goto_flow.cpp b/YACReader/goto_flow.cpp index fdb17057..8ef1fd39 100644 --- a/YACReader/goto_flow.cpp +++ b/YACReader/goto_flow.cpp @@ -225,6 +225,12 @@ void GoToFlow::updateConfig(QSettings * settings) { Q_UNUSED(settings) } + +void GoToFlow::setFlowRightToLeft(bool b) +{ + flow->setFlowRightToLeft(b); +} + //----------------------------------------------------------------------------- //SlideInitializer //----------------------------------------------------------------------------- diff --git a/YACReader/goto_flow.h b/YACReader/goto_flow.h index 53176d1c..a82d78ff 100644 --- a/YACReader/goto_flow.h +++ b/YACReader/goto_flow.h @@ -63,6 +63,8 @@ private slots: void setFlowType(FlowType flowType); void updateSize(); void updateConfig(QSettings * settings); + void setFlowRightToLeft(bool b); + signals: void goToPage(unsigned int page); diff --git a/YACReader/goto_flow_gl.cpp b/YACReader/goto_flow_gl.cpp index 0612540a..14cbe424 100644 --- a/YACReader/goto_flow_gl.cpp +++ b/YACReader/goto_flow_gl.cpp @@ -164,3 +164,8 @@ void GoToFlowGL::resizeEvent(QResizeEvent *event) toolBar->move(0, event->size().height() - toolBar->height()); toolBar->setFixedWidth(width()); } + +void GoToFlowGL::setFlowRightToLeft(bool b) +{ + flow->setFlowRightToLeft(b); +} diff --git a/YACReader/goto_flow_gl.h b/YACReader/goto_flow_gl.h index 31bd65e0..00a8ab81 100644 --- a/YACReader/goto_flow_gl.h +++ b/YACReader/goto_flow_gl.h @@ -26,6 +26,7 @@ public: void updateSize(); void updateConfig(QSettings * settings); + void setFlowRightToLeft(bool b); signals: void goToPage(unsigned int page); diff --git a/YACReader/goto_flow_widget.h b/YACReader/goto_flow_widget.h index fbb05028..845a4b05 100644 --- a/YACReader/goto_flow_widget.h +++ b/YACReader/goto_flow_widget.h @@ -29,6 +29,7 @@ public slots: virtual void setImageReady(int index,const QByteArray & image) = 0; virtual void updateSize() = 0; virtual void updateConfig(QSettings * settings) = 0; + virtual void setFlowRightToLeft(bool b) = 0; protected: void keyPressEvent(QKeyEvent* event); diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index 35634b9b..420e725d 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -963,6 +963,7 @@ void Viewer::doubleMangaPageSwitch() doubleMangaPage = !doubleMangaPage; render->doubleMangaPageSwitch(); Configuration::getConfiguration().setDoubleMangaPage(doubleMangaPage); + goToFlow->setFlowRightToLeft(doubleMangaPage); } void Viewer::resetContent() diff --git a/common/gl/yacreader_flow_gl.cpp b/common/gl/yacreader_flow_gl.cpp index 9730b941..fe5b2e8b 100644 --- a/common/gl/yacreader_flow_gl.cpp +++ b/common/gl/yacreader_flow_gl.cpp @@ -200,7 +200,7 @@ struct Preset pressetYACReaderFlowDownConfig = { }; /*Constructor*/ YACReaderFlowGL::YACReaderFlowGL(QWidget *parent,struct Preset p) - :QOpenGLWidget(/*QOpenGLWidget migration QGLFormat(QGL::SampleBuffers),*/ parent),numObjects(0),lazyPopulateObjects(-1),bUseVSync(false),hasBeenInitialized(false) + :QOpenGLWidget(/*QOpenGLWidget migration QGLFormat(QGL::SampleBuffers),*/ parent),numObjects(0),lazyPopulateObjects(-1),bUseVSync(false),hasBeenInitialized(false),flowRightToLeft(false) { updateCount = 0; config = p; @@ -385,7 +385,11 @@ void YACReaderFlowGL::udpatePerspective(int width, int height) /*Private*/ void YACReaderFlowGL::calcPos(YACReader3DImage & image, int pos) { - if(pos == 0){ + if(flowRightToLeft){ + pos = pos * -1; + } + + if(pos == 0){ image.current = centerPos; }else{ if(pos > 0){ @@ -1052,6 +1056,11 @@ void YACReaderFlowGL::render() //do nothing } +void YACReaderFlowGL::setFlowRightToLeft(bool b) +{ + flowRightToLeft = b; +} + //EVENTOS void YACReaderFlowGL::wheelEvent(QWheelEvent * event) @@ -1073,7 +1082,7 @@ void YACReaderFlowGL::wheelEvent(QWheelEvent * event) void YACReaderFlowGL::keyPressEvent(QKeyEvent *event) { - if(event->key() == Qt::Key_Left) + if((event->key() == Qt::Key_Left && !flowRightToLeft) || (event->key() == Qt::Key_Right && flowRightToLeft)) { if(event->modifiers() == Qt::ControlModifier) setCurrentIndex((currentSelected-10<0)?0:currentSelected-10); @@ -1083,7 +1092,7 @@ void YACReaderFlowGL::keyPressEvent(QKeyEvent *event) return; } - if(event->key() == Qt::Key_Right) + if((event->key() == Qt::Key_Right && !flowRightToLeft) || (event->key() == Qt::Key_Left && flowRightToLeft)) { if(event->modifiers() == Qt::ControlModifier) setCurrentIndex((currentSelected+10>=numObjects)?numObjects-1:currentSelected+10); @@ -1128,7 +1137,7 @@ void YACReaderFlowGL::mousePressEvent(QMouseEvent *event) gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ); - if(posX >= 0.5) + if((posX >= 0.5 && !flowRightToLeft) || (posX <=-0.5 && flowRightToLeft)) { //int index = currentSelected+1; //while((cfImages[index].current.x-cfImages[index].width/(2.0*config.rotation)) < posX) @@ -1136,7 +1145,7 @@ void YACReaderFlowGL::mousePressEvent(QMouseEvent *event) //setCurrentIndex(index-1); showNext(); } - else if(posX <=-0.5) + else if((posX <=-0.5 && !flowRightToLeft) || (posX >= 0.5 && flowRightToLeft) ) showPrevious(); } else QOpenGLWidget::mousePressEvent(event); diff --git a/common/gl/yacreader_flow_gl.h b/common/gl/yacreader_flow_gl.h index 2fc37d51..60cd8ce5 100644 --- a/common/gl/yacreader_flow_gl.h +++ b/common/gl/yacreader_flow_gl.h @@ -173,6 +173,9 @@ protected: //sets the updateInterval in ms static int updateInterval; + // sets flow direction right-to-left (manga mode) + bool flowRightToLeft; + void startAnimationTimer(); void stopAnimationTimer(); @@ -251,6 +254,8 @@ public: void useVSync(bool b); + void setFlowRightToLeft(bool b); + virtual void updateImageData() = 0; void reset(); diff --git a/common/pictureflow.cpp b/common/pictureflow.cpp index d92f4299..61fe2d60 100644 --- a/common/pictureflow.cpp +++ b/common/pictureflow.cpp @@ -207,6 +207,8 @@ public: QVector leftSlides; QVector rightSlides; int centerIndex; + + bool flowRightToLeft; }; class PictureFlowAnimator @@ -281,7 +283,7 @@ private: PictureFlowState::PictureFlowState(int a, float sr): backgroundColor(0), slideWidth(150), slideHeight(200), -reflectionEffect(PictureFlow::BlurredReflection), centerIndex(0) , rawAngle(a), spacingRatio(sr) +reflectionEffect(PictureFlow::BlurredReflection), centerIndex(0) , rawAngle(a), spacingRatio(sr), flowRightToLeft(false) { } @@ -327,7 +329,10 @@ void PictureFlowState::reset() si.angle = angle; si.cx = -(offsetX + spacing*(i)*PFREAL_ONE); si.cy = offsetY; - si.slideIndex = centerIndex-1-i; + if(!flowRightToLeft) + si.slideIndex = centerIndex-1-i; + else + si.slideIndex = centerIndex+1+i; si.blend = 200; if(i == (int)leftSlides.count()-2) si.blend = 128; @@ -344,7 +349,10 @@ void PictureFlowState::reset() si.angle = -angle; si.cx = offsetX + spacing*(i)*PFREAL_ONE; si.cy = offsetY; - si.slideIndex = centerIndex+1+i; + if(!flowRightToLeft) + si.slideIndex = centerIndex+1+i; + else + si.slideIndex = centerIndex-1-i; si.blend = 200; if(i == (int)rightSlides.count()-2) si.blend = 128; @@ -423,13 +431,31 @@ void PictureFlowAnimator::update() frame = index << 16; state->centerSlide.slideIndex = state->centerIndex; for(int i = 0; i < (int)state->leftSlides.count(); i++) - state->leftSlides[i].slideIndex = state->centerIndex-1-i; + { + if(!state->flowRightToLeft) + state->leftSlides[i].slideIndex = state->centerIndex-1-i; + else + state->leftSlides[i].slideIndex = state->centerIndex+1+i; + } for(int i = 0; i < (int)state->rightSlides.count(); i++) - state->rightSlides[i].slideIndex = state->centerIndex+1+i; + { + if(!state->flowRightToLeft) + state->rightSlides[i].slideIndex = state->centerIndex+1+i; + else + state->rightSlides[i].slideIndex = state->centerIndex-1-i; + } } - state->centerSlide.angle = (step * tick * state->angle) >> 16; - state->centerSlide.cx = -step * fmul(state->offsetX, ftick); + if(!state->flowRightToLeft) + { + state->centerSlide.angle = (step * tick * state->angle) >> 16; + state->centerSlide.cx = -step * fmul(state->offsetX, ftick); + } + else + { + state->centerSlide.angle = (-step * tick * state->angle) >> 16; + state->centerSlide.cx = step * fmul(state->offsetX, ftick); + } state->centerSlide.cy = fmul(state->offsetY, ftick); if(state->centerIndex == target) @@ -443,7 +469,10 @@ void PictureFlowAnimator::update() { SlideInfo& si = state->leftSlides[i]; si.angle = state->angle; - si.cx = -(state->offsetX + state->spacing*(i)*PFREAL_ONE + step*state->spacing*ftick); + if(!state->flowRightToLeft) + si.cx = -(state->offsetX + state->spacing*(i)*PFREAL_ONE + step*state->spacing*ftick); + else + si.cx = -(state->offsetX + state->spacing*(i)*PFREAL_ONE - step*state->spacing*ftick); si.cy = state->offsetY; } @@ -451,24 +480,41 @@ void PictureFlowAnimator::update() { SlideInfo& si = state->rightSlides[i]; si.angle = -state->angle; - si.cx = state->offsetX + state->spacing*(i)*PFREAL_ONE - step*state->spacing*ftick; + if(!state->flowRightToLeft) + si.cx = state->offsetX + state->spacing*(i)*PFREAL_ONE - step*state->spacing*ftick; + else + si.cx = state->offsetX + state->spacing*(i)*PFREAL_ONE + step*state->spacing*ftick; si.cy = state->offsetY; } - if(step > 0) + if(step > 0 && !state->flowRightToLeft) { PFreal ftick = (neg * PFREAL_ONE) >> 16; state->rightSlides[0].angle = -(neg * state->angle) >> 16; state->rightSlides[0].cx = fmul(state->offsetX, ftick); state->rightSlides[0].cy = fmul(state->offsetY, ftick); } - else + else if(!state->flowRightToLeft) { PFreal ftick = (pos * PFREAL_ONE) >> 16; state->leftSlides[0].angle = (pos * state->angle) >> 16; state->leftSlides[0].cx = -fmul(state->offsetX, ftick); state->leftSlides[0].cy = fmul(state->offsetY, ftick); } + else if(step < 0) + { + PFreal ftick = (pos * PFREAL_ONE) >> 16; + state->rightSlides[0].angle = -(pos * state->angle) >> 16; + state->rightSlides[0].cx = fmul(state->offsetX, ftick); + state->rightSlides[0].cy = fmul(state->offsetY, ftick); + } + else + { + PFreal ftick = (neg * PFREAL_ONE) >> 16; + state->leftSlides[0].angle = (neg * state->angle) >> 16; + state->leftSlides[0].cx = -fmul(state->offsetX, ftick); + state->leftSlides[0].cy = fmul(state->offsetY, ftick); + } // must change direction ? if(target < index) if(step > 0) @@ -1053,6 +1099,13 @@ void PictureFlow::setReflectionEffect(ReflectionEffect effect) triggerRender(); } +void PictureFlow::setFlowRightToLeft(bool b) +{ + d->state->flowRightToLeft = b; + d->state->reset(); + triggerRender(); +} + QImage PictureFlow::slide(int index) const { QImage* i = 0; @@ -1225,7 +1278,8 @@ void PictureFlow::showSlide(unsigned int index) void PictureFlow::keyPressEvent(QKeyEvent* event) { - if(event->key() == Qt::Key_Left) + if((event->key() == Qt::Key_Left && !(d->state->flowRightToLeft)) + || (event->key() == Qt::Key_Right && d->state->flowRightToLeft)) { /*if(event->modifiers() == Qt::ControlModifier) showSlide(centerIndex()-10); @@ -1235,7 +1289,8 @@ void PictureFlow::keyPressEvent(QKeyEvent* event) return; } - if(event->key() == Qt::Key_Right) + if((event->key() == Qt::Key_Right && !(d->state->flowRightToLeft)) + || (event->key() == Qt::Key_Left && d->state->flowRightToLeft)) { /*if(event->modifiers() == Qt::ControlModifier) showSlide(centerIndex()+10); @@ -1256,10 +1311,19 @@ void PictureFlow::keyPressEvent(QKeyEvent* event) void PictureFlow::mousePressEvent(QMouseEvent* event) { - if(event->x() > width()/2) + mousePressEvent(event, 0); +} + +void PictureFlow::mousePressEvent(QMouseEvent* event, int slideWidth) +{ + if((event->x() > (width() + slideWidth)/2 && !(d->state->flowRightToLeft)) + || (event->x() < (width() - slideWidth)/2 && d->state->flowRightToLeft)) showNext(); - else - showPrevious(); + else if((event->x() < (width() - slideWidth)/2 && !(d->state->flowRightToLeft)) + || (event->x() > (width() + slideWidth)/2 && d->state->flowRightToLeft)) + showPrevious(); + + //else (centered slide space) } void PictureFlow::paintEvent(QPaintEvent* event) diff --git a/common/pictureflow.h b/common/pictureflow.h index 0ac197d4..df071d2a 100644 --- a/common/pictureflow.h +++ b/common/pictureflow.h @@ -119,7 +119,12 @@ public: */ void setReflectionEffect(ReflectionEffect effect); + /*! + Sets the flow direction right-to-left (manga mode) + */ + void setFlowRightToLeft(bool b); + public slots: /*! @@ -213,6 +218,7 @@ public: void paintEvent(QPaintEvent *event); void keyPressEvent(QKeyEvent* event); void mousePressEvent(QMouseEvent* event); + void mousePressEvent(QMouseEvent* event, int slideWidth); void resizeEvent(QResizeEvent* event); private slots: diff --git a/custom_widgets/yacreader_flow.cpp b/custom_widgets/yacreader_flow.cpp index e40507d3..7da4715f 100644 --- a/custom_widgets/yacreader_flow.cpp +++ b/custom_widgets/yacreader_flow.cpp @@ -7,12 +7,7 @@ YACReaderFlow::YACReaderFlow(QWidget * parent,FlowType flowType) : PictureFlow(p void YACReaderFlow::mousePressEvent(QMouseEvent* event) { - if(event->x() > (width()+slideSize().width())/2) - showNext(); - else - if(event->x() < (width()-slideSize().width())/2) - showPrevious(); - //else (centered cover space) + PictureFlow::mousePressEvent(event, slideSize().width()); } void YACReaderFlow::mouseDoubleClickEvent(QMouseEvent* event)