diff --git a/YACReader/configuration.cpp b/YACReader/configuration.cpp index a89aab3d..13e7a9b2 100644 --- a/YACReader/configuration.cpp +++ b/YACReader/configuration.cpp @@ -55,108 +55,4 @@ void Configuration::load(QSettings * settings) settings->setValue(ALWAYS_ON_TOP,false); if(!settings->contains(SHOW_TOOLBARS)) settings->setValue(SHOW_TOOLBARS, true); -} - -void Configuration::load(const QString & path) -{ - //load default configuration - defaultPath = "."; - magnifyingGlassSize = QSize(350,175); - gotoSlideSize = QSize(126,200); //normal - //gotoSlideSize = QSize(79,125); //small - //gotoSlideSize = QSize(173,275); //big - //gotoSlideSize = QSize(220,350); //huge - zoomLevel = 0.5; - adjustToWidth = true; - flowType = Strip; - fullScreen = false; - fitToWidthRatio = 1; - windowSize = QSize(0,0); - maximized = false; - doublePage = false; - adjustToFullSize = false; - backgroundColor = QColor(40,40,40); - alwaysOnTop = false; - - //load from file - QFile f(YACReader::getSettingsPath()+path); - f.open(QIODevice::ReadOnly); - QTextStream txtS(&f); - QString content = txtS.readAll(); - QStringList lines = content.split('\n'); - QString line,name; - int i=0; - foreach(line,lines) - { - if((i%2)==0) - { - name = line.trimmed(); - } - else - { - if(name==PATH) - defaultPath = line.trimmed(); - else - if(name==MAG_GLASS_SIZE) - { - QStringList values = line.split(','); - magnifyingGlassSize = QSize(values[0].toInt(),values[1].toInt()); - } - else - if(name==ZOOM_LEVEL) - zoomLevel = line.toFloat(); - else - if(name==SLIDE_SIZE) - { - int height = line.toInt(); - gotoSlideSize = QSize(static_cast(height/SLIDE_ASPECT_RATIO),height); - } - else - if(name==FIT) - adjustToWidth = line.toInt(); - else - if(name==FLOW_TYPE) - flowType = (FlowType)line.toInt(); - else - if(name==FULLSCREEN) - fullScreen = line.toInt(); - else - if(name==FIT_TO_WIDTH_RATIO) - fitToWidthRatio = line.toFloat(); - else - if(name==Y_WINDOW_POS) - { - QStringList l = line.split(','); - windowPos = QPoint(l[0].toInt(),l[1].toInt()); - } - else - if(name==Y_WINDOW_SIZE) - { - QStringList l = line.split(','); - windowSize = QSize(l[0].toInt(),l[1].toInt()); - } - else - if(name==MAXIMIZED) - maximized = line.toInt(); - else - if(name==DOUBLE_PAGE) - doublePage = line.toInt(); - else - if(name==ADJUST_TO_FULL_SIZE) - adjustToFullSize = line.toInt(); - else - if(name==BACKGROUND_COLOR) - { - QStringList l = line.split(','); - backgroundColor = QColor(l[0].toInt(),l[1].toInt(),l[2].toInt()); - } - else - if(name==ALWAYS_ON_TOP) - alwaysOnTop = line.toInt(); - - - - } - i++; - } -} +} \ No newline at end of file diff --git a/YACReader/configuration.h b/YACReader/configuration.h index 7ef6b7ff..ba9e1531 100644 --- a/YACReader/configuration.h +++ b/YACReader/configuration.h @@ -35,6 +35,7 @@ using namespace YACReader; QSize windowSize; bool maximized; bool doublePage; + bool doubleMangaPage; bool alwaysOnTop; bool adjustToFullSize; QColor backgroundColor; @@ -75,6 +76,8 @@ using namespace YACReader; void setMaximized(bool b){settings->setValue(MAXIMIZED,b);} bool getDoublePage(){return settings->value(DOUBLE_PAGE).toBool();} void setDoublePage(bool b){settings->setValue(DOUBLE_PAGE,b);} + bool getDoubleMangaPage(){return settings->value(DOUBLE_MANGA_PAGE).toBool();} + void setDoubleMangaPage(bool b){settings->setValue(DOUBLE_MANGA_PAGE,b);} bool getAdjustToFullSize(){return settings->value(ADJUST_TO_FULL_SIZE).toBool();} void setAdjustToFullSize(bool b){settings->setValue(ADJUST_TO_FULL_SIZE,b);} QColor getBackgroundColor(){return settings->value(BACKGROUND_COLOR).value();} diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index d753705c..73f5638b 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -94,6 +94,7 @@ MainWindowViewer::~MainWindowViewer() delete leftRotationAction; delete rightRotationAction; delete doublePageAction; + delete doubleMangaPageAction; delete goToPageAction; delete optionsAction; delete helpAboutAction; @@ -301,7 +302,18 @@ void MainWindowViewer::createActions() doublePageAction->setData(DOUBLE_PAGE_ACTION_Y); doublePageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(DOUBLE_PAGE_ACTION_Y)); connect(doublePageAction, SIGNAL(triggered()),viewer,SLOT(doublePageSwitch())); - + + //inversed pictures mode + doubleMangaPageAction = new QAction(tr("Double page manga mode"),this); + doubleMangaPageAction->setToolTip(tr("Reverse reading order in double page mode")); + doubleMangaPageAction->setIcon(QIcon(":/images/viewer_toolbar/doubleMangaPage.png")); + doubleMangaPageAction->setDisabled(true); + doubleMangaPageAction->setCheckable(true); + doubleMangaPageAction->setChecked(Configuration::getConfiguration().getDoubleMangaPage()); + doubleMangaPageAction->setData(DOUBLE_MANGA_PAGE_ACTION_Y); + doubleMangaPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(DOUBLE_MANGA_PAGE_ACTION_Y)); + connect(doubleMangaPageAction, SIGNAL(triggered()),viewer,SLOT(doubleMangaPageSwitch())); + goToPageAction = new QAction(tr("Go To"),this); goToPageAction->setIcon(QIcon(":/images/viewer_toolbar/goto.png")); goToPageAction->setDisabled(true); @@ -506,6 +518,7 @@ void MainWindowViewer::createToolBars() comicToolBar->addAction(leftRotationAction); comicToolBar->addAction(rightRotationAction); comicToolBar->addAction(doublePageAction); + comicToolBar->addAction(doubleMangaPageAction); comicToolBar->addSeparator(); @@ -785,6 +798,7 @@ void MainWindowViewer::enableActions() rightRotationAction->setDisabled(false); showMagnifyingGlassAction->setDisabled(false); doublePageAction->setDisabled(false); + doubleMangaPageAction->setDisabled(false); adjustToFullSizeAction->setDisabled(false); //setBookmark->setDisabled(false); showBookmarksAction->setDisabled(false); @@ -805,6 +819,7 @@ void MainWindowViewer::disableActions() rightRotationAction->setDisabled(true); showMagnifyingGlassAction->setDisabled(true); doublePageAction->setDisabled(true); + doubleMangaPageAction->setDisabled(true); adjustToFullSizeAction->setDisabled(true); setBookmarkAction->setDisabled(true); showBookmarksAction->setDisabled(true); @@ -1057,6 +1072,7 @@ void MainWindowViewer::setUpShortcutsManagement() << leftRotationAction << rightRotationAction << doublePageAction + << doubleMangaPageAction << adjustToFullSizeAction); allActions << tmpList; diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 348a6886..f8b94b05 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -108,6 +108,7 @@ class EditShortcutsDialog; QAction *showInfoAction; QAction *closeAction; QAction *doublePageAction; + QAction *doubleMangaPageAction; QAction *showShorcutsAction; QAction *showDictionaryAction; QAction *alwaysOnTopAction; diff --git a/YACReader/render.cpp b/YACReader/render.cpp index ccfebcb7..5f311657 100644 --- a/YACReader/render.cpp +++ b/YACReader/render.cpp @@ -392,94 +392,12 @@ void PageRender::run() emit pageReady(numPage); } -//----------------------------------------------------------------------------- -// DoublePageRender -//----------------------------------------------------------------------------- - -DoublePageRender::DoublePageRender(Render * r, int np, const QByteArray & rd, const QByteArray & rd2, QImage * p,unsigned int d, QVector f) -:PageRender(), -render(r), -numPage(np), -data(rd), -data2(rd2), -page(p), -degrees(d), -filters(f) -{ - -} - -void DoublePageRender::run() -{ - //QImage result; - QMutexLocker locker(&(render->mutex)); - QImage img, img2; - if(!data.isEmpty()) - img.loadFromData(data); - if(!data2.isEmpty()) - img2.loadFromData(data2); - /*if(img.isNull()) - img = QPixmap(img2.width(),img2.height()); - if(img2.isNull()) - img2 = QPixmap(img.width(),img.height());*/ - - if(img.isNull() && !img2.isNull()) - { - img = img2; - img2 = QImage(); - } - - - int totalWidth,totalHeight; - //x = img.width()+img2.width(); - totalHeight = qMax(img.height(),img2.height()); - - //widths fiting the normalized height - int width1, width2; - - //altura normalizada - if(!img2.isNull()) - { - if(img.height()!=totalHeight) - totalWidth = (width1 = ((img.width() * totalHeight) / img.height())) + (width2 = img2.width()); - else - totalWidth = (width1 = img.width()) + (width2 = ((img2.width() * totalHeight) / img2.height())); - } - else - totalWidth = width1 = img.width(); - - - - - QImage auxImg(totalWidth,totalHeight,QImage::Format_RGB32); - QPainter painter(&auxImg); - painter.drawImage(QRect(0,0,width1,totalHeight),img); - if(!img2.isNull()) - painter.drawImage(QRect(width1,0,width2,totalHeight),img2); - painter.end(); - - if(degrees > 0) - { - QMatrix m; - m.rotate(degrees); - auxImg = auxImg.transformed(m,Qt::SmoothTransformation); - } - for(int i=0;isetFilter(auxImg); - } - - *page = auxImg; - - emit pageReady(numPage); -} - //----------------------------------------------------------------------------- // Render //----------------------------------------------------------------------------- Render::Render() -:currentIndex(0),doublePage(false),comic(0),loadedComic(false),imageRotation(0),numLeftPages(2),numRightPages(2) +:currentIndex(0),doublePage(false),doubleMangaPage(false),comic(0),loadedComic(false),imageRotation(0),numLeftPages(4),numRightPages(4) { int size = numLeftPages+numRightPages+1; currentPageBufferedIndex = numLeftPages; @@ -522,23 +440,13 @@ void Render::render() { if(pagesReady.size()>0) { - if(doublePage) + if(pagesReady[currentIndex]) { - if(pagesReady[currentIndex] && pagesReady[qMin(currentIndex+1,(int)comic->numPages()-1)]) - if(currentIndex+1 > (int)comic->numPages()-1) - pageRenders[currentPageBufferedIndex] = new DoublePageRender(this,currentIndex,comic->getRawData()->at(currentIndex),QByteArray(),buffer[currentPageBufferedIndex],imageRotation,filters); - else - pageRenders[currentPageBufferedIndex] = new DoublePageRender(this,currentIndex,comic->getRawData()->at(currentIndex),comic->getRawData()->at(currentIndex+1),buffer[currentPageBufferedIndex],imageRotation,filters); - else - //las páginas no están listas, y se están cargando en el cómic - emit processingPage(); //para evitar confusiones esta señal debería llamarse de otra forma + pageRenders[currentPageBufferedIndex] = new PageRender(this,currentIndex,comic->getRawData()->at(currentIndex),buffer[currentPageBufferedIndex],imageRotation,filters); } else - if(pagesReady[currentIndex]) - pageRenders[currentPageBufferedIndex] = new PageRender(this,currentIndex,comic->getRawData()->at(currentIndex),buffer[currentPageBufferedIndex],imageRotation,filters); - else - //las páginas no están listas, y se están cargando en el cómic - emit processingPage(); //para evitar confusiones esta señal debería llamarse de otra forma + //las páginas no están listas, y se están cargando en el cómic + emit processingPage(); //para evitar confusiones esta señal debería llamarse de otra forma //si se ha creado un hilo para renderizar la página actual, se arranca if(pageRenders[currentPageBufferedIndex]!=0) @@ -546,7 +454,7 @@ void Render::render() //se conecta la señal pageReady del hilo, con el SLOT prepareAvailablePage connect(pageRenders[currentPageBufferedIndex],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); //se emite la señal de procesando, debido a que los hilos se arrancan aquí - if(doublePage || filters.size()>0) + if(filters.size()>0) emit processingPage(); pageRenders[currentPageBufferedIndex]->start(); pageRenders[currentPageBufferedIndex]->setPriority(QThread::TimeCriticalPriority); @@ -560,14 +468,13 @@ void Render::render() emit processingPage(); } else - // la página actual está lista - emit currentPageReady(); - - //se renderizan las páginas restantes para llenar el buffer. - if(doublePage) - fillBufferDoublePage(); - else - fillBuffer(); + // la página actual está lista + { + //emit currentPageReady(); + //make prepareAvailablePage the only function that emits currentPageReady() + prepareAvailablePage(currentIndex); + } + fillBuffer(); } QPixmap * Render::getCurrentPage() @@ -577,6 +484,190 @@ QPixmap * Render::getCurrentPage() return page; } +QPixmap * Render::getCurrentDoublePage() +{ + if (currentPageIsDoublePage()) + { + QPoint leftpage(0,0); + QPoint rightpage(0,0); + QSize leftsize = buffer[currentPageBufferedIndex]->size(); + QSize rightsize = buffer[currentPageBufferedIndex+1]->size(); + int totalWidth,totalHeight; + switch (imageRotation) + { + case 0: + totalHeight = qMax(leftsize.rheight(),rightsize.rheight()); + leftsize.scale(leftsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + rightsize.scale(rightsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + totalWidth = leftsize.rwidth() + rightsize.rwidth(); + rightpage.setX(leftsize.rwidth()); + break; + case 90: + totalWidth = qMax(leftsize.rwidth(), rightsize.rwidth()); + leftsize.scale(totalWidth, leftsize.rheight(), Qt::KeepAspectRatioByExpanding); + rightsize.scale(totalWidth, rightsize.rheight(), Qt::KeepAspectRatioByExpanding); + totalHeight = leftsize.rheight() + rightsize.rheight(); + rightpage.setY(leftsize.rheight()); + break; + case 180: + totalHeight = qMax(leftsize.rheight(),rightsize.rheight()); + leftsize.scale(leftsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + rightsize.scale(rightsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + totalWidth = leftsize.rwidth() + rightsize.rwidth(); + leftpage.setX(rightsize.rwidth()); + break; + case 270: + totalWidth = qMax(leftsize.rwidth(), rightsize.rwidth()); + leftsize.scale(totalWidth, leftsize.rheight(), Qt::KeepAspectRatioByExpanding); + rightsize.scale(totalWidth, rightsize.rheight(), Qt::KeepAspectRatioByExpanding); + totalHeight = leftsize.rheight() + rightsize.rheight(); + leftpage.setY(rightsize.rheight()); + break; + default: + return NULL; + } + QPixmap * page = new QPixmap(totalWidth, totalHeight); + QPainter painter(page); + painter.drawImage(QRect(leftpage,leftsize), *buffer[currentPageBufferedIndex]); + painter.drawImage(QRect(rightpage,rightsize), *buffer[currentPageBufferedIndex+1]); + return page; + } + else + { + return NULL; + } +} + +QPixmap * Render::getCurrentDoubleMangaPage() +{ + if (currentPageIsDoublePage()) + { + QPoint leftpage(0,0); + QPoint rightpage(0,0); + QSize leftsize = buffer[currentPageBufferedIndex+1]->size(); + QSize rightsize = buffer[currentPageBufferedIndex]->size(); + int totalWidth,totalHeight; + switch (imageRotation) + { + case 0: + totalHeight = qMax(leftsize.rheight(),rightsize.rheight()); + leftsize.scale(leftsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + rightsize.scale(rightsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + totalWidth = leftsize.rwidth() + rightsize.rwidth(); + rightpage.setX(leftsize.rwidth()); + break; + case 90: + totalWidth = qMax(leftsize.rwidth(), rightsize.rwidth()); + leftsize.scale(totalWidth, leftsize.rheight(), Qt::KeepAspectRatioByExpanding); + rightsize.scale(totalWidth, rightsize.rheight(), Qt::KeepAspectRatioByExpanding); + totalHeight = leftsize.rheight() + rightsize.rheight(); + rightpage.setY(leftsize.rheight()); + break; + case 180: + totalHeight = qMax(leftsize.rheight(),rightsize.rheight()); + leftsize.scale(leftsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + rightsize.scale(rightsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + totalWidth = leftsize.rwidth() + rightsize.rwidth(); + leftpage.setX(rightsize.rwidth()); + break; + case 270: + totalWidth = qMax(leftsize.rwidth(), rightsize.rwidth()); + leftsize.scale(totalWidth, leftsize.rheight(), Qt::KeepAspectRatioByExpanding); + rightsize.scale(totalWidth, rightsize.rheight(), Qt::KeepAspectRatioByExpanding); + totalHeight = leftsize.rheight() + rightsize.rheight(); + leftpage.setY(rightsize.rheight()); + break; + default: + return NULL; + } + QPixmap * page = new QPixmap(totalWidth, totalHeight); + QPainter painter(page); + painter.drawImage(QRect(rightpage, rightsize), *buffer[currentPageBufferedIndex]); + painter.drawImage(QRect(leftpage, leftsize), *buffer[currentPageBufferedIndex+1]); + return page; + } + else + { + return NULL; + } +} + +bool Render::currentPageIsDoublePage() +{ + if (buffer[currentPageBufferedIndex]->isNull() || buffer[currentPageBufferedIndex+1]->isNull()) + { + return false; + } + if (imageRotation == 0 || imageRotation == 180) + { + if (buffer[currentPageBufferedIndex]->height() > buffer[currentPageBufferedIndex]->width() && + buffer[currentPageBufferedIndex+1]->height() > buffer[currentPageBufferedIndex+1]->width()) + { + return true; + } + } + else if (imageRotation == 90 || imageRotation == 270) + { + if (buffer[currentPageBufferedIndex]->width() > buffer[currentPageBufferedIndex]->height() && + buffer[currentPageBufferedIndex+1]->width() > buffer[currentPageBufferedIndex+1]->height()) + { + return true; + } + } + return false; +} + +bool Render::nextPageIsDoublePage() +{ + //this function is not used right now + if (buffer[currentPageBufferedIndex+2]->isNull() || buffer[currentPageBufferedIndex+3]->isNull()) + { + return false; + } + if (imageRotation == 0 || imageRotation == 180) + { + if (buffer[currentPageBufferedIndex+2]->height() > buffer[currentPageBufferedIndex+2]->width() && + buffer[currentPageBufferedIndex+3]->height() > buffer[currentPageBufferedIndex+3]->width()) + { + return true; + } + } + else if (imageRotation == 90 || imageRotation == 270) + { + if (buffer[currentPageBufferedIndex]->width() > buffer[currentPageBufferedIndex]->height() && + buffer[currentPageBufferedIndex+1]->width() > buffer[currentPageBufferedIndex+1]->height()) + { + return true; + } + } + return false; +} + +bool Render::previousPageIsDoublePage() +{ + if (buffer[currentPageBufferedIndex-1]->isNull() || buffer[currentPageBufferedIndex-2]->isNull()) + { + return false; + } + if (imageRotation == 0 || imageRotation == 180) + { + if (buffer[currentPageBufferedIndex-1]->height() > buffer[currentPageBufferedIndex-1]->width() && + buffer[currentPageBufferedIndex-2]->height() > buffer[currentPageBufferedIndex-2]->width()) + { + return true; + } + } + else if (imageRotation == 90 || imageRotation == 270) + { + if (buffer[currentPageBufferedIndex-1]->width() > buffer[currentPageBufferedIndex-1]->height() && + buffer[currentPageBufferedIndex-2]->width() > buffer[currentPageBufferedIndex-2]->height()) + { + return true; + } + } + return false; +} + void Render::setRotation(int degrees) { Q_UNUSED(degrees) @@ -595,8 +686,26 @@ void Render::setComic(Comic * c) void Render::prepareAvailablePage(int page) { - if(currentIndex == page) - emit currentPageReady(); + if(!doublePage) + { + if (currentIndex == page) + { + emit currentPageReady(); + } + } + else + { + //check for last page in double page mode + if ((currentIndex == page) && (currentIndex + 1) >= (int)comic->numPages()) + { + emit currentPageReady(); + } + else if ((currentIndex == page && !buffer[currentPageBufferedIndex+1]->isNull()) || + (currentIndex+1 == page && !buffer[currentPageBufferedIndex]->isNull())) + { + emit currentPageReady(); + } + } } void Render::update() @@ -731,21 +840,7 @@ void Render::reset() void Render::nextPage() { int nextPage; //indica cuál será la próxima página - if(doublePage) - { - nextPage = currentIndex; - if(currentIndex+2<(int)comic->numPages()) - { - nextPage = currentIndex+2; - if(currentIndex != nextPage) - comic->setIndex(nextPage); - } - } - else - { - nextPage = comic->nextPage(); - } - + nextPage = comic->nextPage(); //se fuerza renderizado si la página ha cambiado if(currentIndex != nextPage) { @@ -755,28 +850,42 @@ void Render::nextPage() emit pageChanged(currentIndex); } else + { emit isLast(); + } } +void Render::nextDoublePage() +{ + int nextPage; + if (currentIndex +2 < (int)comic->numPages()) + { + nextPage = currentIndex+2; + } + else + { + nextPage = currentIndex; + } + if(currentIndex != nextPage) + { + comic->setIndex(nextPage); + previousIndex = currentIndex; + currentIndex = nextPage; + update(); + emit pageChanged(currentIndex); + } + else + { + emit isLast(); + } +} + //si se solicita la página anterior, se calcula cuál debe ser en función de si se lee en modo a doble página o no. //la página sólo se renderiza, si realmente ha cambiado. void Render::previousPage() { int previousPage; //indica cuál será la próxima página - if(doublePage) - { - if(currentIndex == 1) - invalidate(); - previousPage = qMax(currentIndex-2,0); - if(currentIndex != previousPage) - { - comic->setIndex(previousPage); - } - } - else - { - previousPage = comic->previousPage(); - } - + previousPage = comic->previousPage(); + //se fuerza renderizado si la página ha cambiado if(currentIndex != previousPage) { @@ -786,8 +895,25 @@ void Render::previousPage() emit pageChanged(currentIndex); } else + { emit isCover(); + } } + +void Render::previousDoublePage() +{ + int previousPage; //indica cuál será la próxima página + previousPage = qMax(currentIndex-2,0); + if(currentIndex != previousPage) + { + comic->setIndex(previousPage); + previousIndex = currentIndex; + currentIndex = previousPage; + update(); + emit pageChanged(currentIndex); + } +} + unsigned int Render::getIndex() { return comic->getIndex(); @@ -819,18 +945,6 @@ void Render::pageRawDataReady(int page) pagesReady[pagesEmited.at(i)] = true; if(pagesEmited.at(i) == currentIndex) update(); - - if(doublePage) - { - if(pagesEmited.at(i)==currentIndex+1) - update(); - - if ( ((pagesEmited.at(i) < currentIndex) && (pagesEmited.at(i) > currentIndex-2*numLeftPages)) || - ((pagesEmited.at(i) > currentIndex+1) && (pagesEmited.at(i) < currentIndex+1+2*numRightPages)) ) - { - fillBufferDoublePage(); - } - } else { if ( ((pagesEmited.at(i) < currentIndex) && (pagesEmited.at(i) > currentIndex-numLeftPages)) || @@ -853,12 +967,6 @@ void Render::goTo(int index) comic->setIndex(index); previousIndex = currentIndex; currentIndex = index; - - //si cambia la paridad de las página en modo a doble página, se rellena el buffer. - //esto solo debería orcurrir al llegar al principio o al final - if(doublePage && ((previousIndex - index) % 2)!=0) - invalidate(); - update(); emit pageChanged(currentIndex); } @@ -885,13 +993,7 @@ void Render::updateBuffer() { QMutexLocker locker(&mutex); int windowSize = currentIndex - previousIndex; - if(doublePage) - { - windowSize = windowSize/2; - if(currentIndex == 0 && windowSize == 0 && previousIndex == 1) - windowSize = -1; - - } + if(windowSize > 0)//add pages to right pages and remove on the left { windowSize = qMin(windowSize,buffer.size()); @@ -951,10 +1053,10 @@ void Render::fillBuffer() buffer[currentPageBufferedIndex+i]->isNull() && i <= numRightPages && pageRenders[currentPageBufferedIndex+i]==0 && - pagesReady[currentIndex+1]) //preload next pages + pagesReady[currentIndex+i]) //preload next pages { pageRenders[currentPageBufferedIndex+i] = new PageRender(this,currentIndex+i,comic->getRawData()->at(currentIndex+i),buffer[currentPageBufferedIndex+i],imageRotation,filters); - connect(pageRenders[currentPageBufferedIndex],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); + connect(pageRenders[currentPageBufferedIndex+i],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); pageRenders[currentPageBufferedIndex+i]->start(); } @@ -962,48 +1064,15 @@ void Render::fillBuffer() buffer[currentPageBufferedIndex-i]->isNull() && i <= numLeftPages && pageRenders[currentPageBufferedIndex-i]==0 && - pagesReady[currentIndex-1]) //preload previous pages + pagesReady[currentIndex-i]) //preload previous pages { pageRenders[currentPageBufferedIndex-i] = new PageRender(this,currentIndex-i,comic->getRawData()->at(currentIndex-i),buffer[currentPageBufferedIndex-i],imageRotation,filters); - connect(pageRenders[currentPageBufferedIndex],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); + connect(pageRenders[currentPageBufferedIndex-i],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); pageRenders[currentPageBufferedIndex-i]->start(); } } } -void Render::fillBufferDoublePage() -{ - for(int i = 1; i <= qMax(numLeftPages,numRightPages); i++) - { - if ((currentIndex+2*i < (int)comic->numPages()) && - buffer[currentPageBufferedIndex+i]->isNull() && - i <= numRightPages && - pageRenders[currentPageBufferedIndex+i]==0 && - (pagesReady[currentIndex+2*i] && pagesReady[qMin(currentIndex+(2*i)+1,(int)comic->numPages()-1)])) //preload next pages - { - if(currentIndex+(2*i)+1 > (int)comic->numPages()-1) - pageRenders[currentPageBufferedIndex+i] = new DoublePageRender(this,currentIndex+2*i,comic->getRawData()->at(currentIndex+(2*i)),QByteArray(),buffer[currentPageBufferedIndex+i],imageRotation,filters); - else - pageRenders[currentPageBufferedIndex+i] = new DoublePageRender(this,currentIndex+2*i,comic->getRawData()->at(currentIndex+(2*i)),comic->getRawData()->at(currentIndex+(2*i)+1),buffer[currentPageBufferedIndex+i],imageRotation,filters); - connect(pageRenders[currentPageBufferedIndex],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); - pageRenders[currentPageBufferedIndex+i]->start(); - } - - if ((currentIndex-2*i >= -1) && - buffer[currentPageBufferedIndex-i]->isNull() && - i <= numLeftPages && - pageRenders[currentPageBufferedIndex-i]==0 && - (pagesReady[qMax(currentIndex-2*i,0)] && pagesReady[qMin(currentIndex-(2*i)+1,(int)comic->numPages()-1)])) //preload previous pages - { - if(currentIndex-2*i == -1) - pageRenders[currentPageBufferedIndex-i] = new DoublePageRender(this,0,QByteArray(),comic->getRawData()->at(0),buffer[currentPageBufferedIndex-i],imageRotation,filters); - else - pageRenders[currentPageBufferedIndex-i] = new DoublePageRender(this,currentIndex-2*i,comic->getRawData()->at(currentIndex-(2*i)),comic->getRawData()->at(currentIndex-(2*i)+1),buffer[currentPageBufferedIndex-i],imageRotation,filters); - connect(pageRenders[currentPageBufferedIndex],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); - pageRenders[currentPageBufferedIndex-i]->start(); - } - } -} //Método que debe ser llamado cada vez que la estructura del buffer se vuelve inconsistente con el modo de lectura actual. //se terminan todos los hilos en ejecución y se libera la memoria (de hilos e imágenes) @@ -1031,7 +1100,17 @@ void Render::doublePageSwitch() doublePage = !doublePage; if(comic) { - invalidate(); + //invalidate(); + update(); + } +} + +void Render::doubleMangaPageSwitch() +{ + doubleMangaPage = !doubleMangaPage; + if(comic&&doublePage) + { + //invalidate(); update(); } } @@ -1040,7 +1119,15 @@ QString Render::getCurrentPagesInformation() { QString s = QString::number(currentIndex+1); if (doublePage && (currentIndex+1 < (int)comic->numPages())) - s += "-"+QString::number(currentIndex+2); + { + if (currentPageIsDoublePage()) + { + if (doubleMangaPage) + s = QString::number(currentIndex+2) + "-" + s; + else + s += "-"+QString::number(currentIndex+2); + } + } s += "/"+QString::number(comic->numPages()); return s; } diff --git a/YACReader/render.h b/YACReader/render.h index 423d7955..9c525c55 100644 --- a/YACReader/render.h +++ b/YACReader/render.h @@ -95,7 +95,7 @@ signals: // RENDER //----------------------------------------------------------------------------- -class DoublePageRender : public PageRender +/*class DoublePageRender : public PageRender { Q_OBJECT public: @@ -113,7 +113,7 @@ signals: void pageReady(int); }; - +*/ class Render : public QObject { Q_OBJECT @@ -124,8 +124,14 @@ public: public slots: void render(); QPixmap * getCurrentPage(); + QPixmap * getCurrentDoublePage(); + QPixmap * getCurrentDoubleMangaPage(); + bool currentPageIsDoublePage(); + bool nextPageIsDoublePage(); + bool previousPageIsDoublePage(); void goTo(int index); void doublePageSwitch(); + void doubleMangaPageSwitch(); void setRotation(int degrees); void setComic(Comic * c); void prepareAvailablePage(int page); @@ -135,6 +141,8 @@ public slots: //--comic interface void nextPage(); void previousPage(); + void nextDoublePage(); + void previousDoublePage(); void load(const QString & path, const ComicDB & comic); void load(const QString & path, int atPage); void createComic(const QString & path); @@ -148,7 +156,6 @@ public slots: bool hasLoadedComic(); void updateBuffer(); void fillBuffer(); - void fillBufferDoublePage(); void invalidate(); QString getCurrentPagesInformation(); void setBookmark(); @@ -182,6 +189,7 @@ signals: private: Comic * comic; bool doublePage; + bool doubleMangaPage; int previousIndex; int currentIndex; //QPixmap * currentPage; @@ -201,8 +209,6 @@ private: QMutex mutex; friend class PageRender; - friend class DoublePageRender; - }; diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index c08eb7a3..917abeb1 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -25,6 +25,7 @@ fullscreen(false), information(false), adjustToWidthRatio(1), doublePage(false), +doubleMangaPage(false), wheelStop(false), direction(1), restoreMagnifyingGlass(false), @@ -90,6 +91,9 @@ shouldOpenPrevious(false) if(Configuration::getConfiguration().getDoublePage()) doublePageSwitch(); + + if(Configuration::getConfiguration().getDoubleMangaPage()) + doubleMangaPageSwitch(); createConnections(); @@ -226,7 +230,14 @@ void Viewer::processCRCError(QString message) void Viewer::next() { direction = 1; - render->nextPage(); + if (doublePage && render->currentPageIsDoublePage()) + { + render->nextDoublePage(); + } + else + { + render->nextPage(); + } updateInformation(); shouldOpenPrevious = false; } @@ -234,7 +245,14 @@ void Viewer::next() void Viewer::prev() { direction = -1; + if (doublePage && render->previousPageIsDoublePage()) + { + render->previousDoublePage(); + } + else + { render->previousPage(); + } updateInformation(); shouldOpenNext = false; } @@ -251,7 +269,23 @@ void Viewer::goTo(unsigned int page) void Viewer::updatePage() { QPixmap * previousPage = currentPage; - currentPage = render->getCurrentPage(); + if (doublePage) + { + if (!doubleMangaPage) + currentPage = render->getCurrentDoublePage(); + else + { + currentPage = render->getCurrentDoubleMangaPage(); + } + if (currentPage == NULL) + { + currentPage = render->getCurrentPage(); + } + } + else + { + currentPage = render->getCurrentPage(); + } content->setPixmap(*currentPage); updateContentSize(); updateVerticalScrollBar(); @@ -692,6 +726,13 @@ void Viewer::doublePageSwitch() Configuration::getConfiguration().setDoublePage(doublePage); } +void Viewer::doubleMangaPageSwitch() +{ + doubleMangaPage = !doubleMangaPage; + render->doubleMangaPageSwitch(); + Configuration::getConfiguration().setDoubleMangaPage(doubleMangaPage); +} + void Viewer::resetContent() { configureContent(tr("Press 'O' to open comic.")); diff --git a/YACReader/viewer.h b/YACReader/viewer.h index 4abd7ec7..e2ff3291 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -64,6 +64,7 @@ class NotificationsLabelWidget; void setBookmark(bool); void save(); void doublePageSwitch(); + void doubleMangaPageSwitch(); void resetContent(); void setLoadingMessage(); void setPageUnavailableMessage(); @@ -93,6 +94,7 @@ virtual void mouseReleaseEvent ( QMouseEvent * event ); private: bool information; bool doublePage; + bool doubleMangaPage; PageLabelWidget * informationLabel; //QTimer * scroller; QPropertyAnimation * verticalScroller; diff --git a/YACReader/yacreader_images_win.qrc b/YACReader/yacreader_images_win.qrc index 3476e623..e7251da4 100644 --- a/YACReader/yacreader_images_win.qrc +++ b/YACReader/yacreader_images_win.qrc @@ -3,6 +3,7 @@ ../images/viewer_toolbar/bookmark.png ../images/viewer_toolbar/close.png ../images/viewer_toolbar/doublePage.png + ../images/viewer_toolbar/doubleMangaPage.png ../images/viewer_toolbar/flow.png ../images/viewer_toolbar/full.png ../images/viewer_toolbar/goto.png diff --git a/common/yacreader_global.h b/common/yacreader_global.h index 3bbd5d66..86b24de0 100644 --- a/common/yacreader_global.h +++ b/common/yacreader_global.h @@ -25,6 +25,7 @@ #define Y_WINDOW_SIZE "SIZE" #define MAXIMIZED "MAXIMIZED" #define DOUBLE_PAGE "DOUBLE_PAGE" +#define DOUBLE_MANGA_PAGE "DOUBLE_MANGA_PAGE" #define ADJUST_TO_FULL_SIZE "ADJUST_TO_FULL_SIZE" #define BACKGROUND_COLOR "BACKGROUND_COLOR" #define ALWAYS_ON_TOP "ALWAYS_ON_TOP" diff --git a/images/viewer_toolbar/doubleMangaPage.png b/images/viewer_toolbar/doubleMangaPage.png new file mode 100644 index 00000000..99ee1720 Binary files /dev/null and b/images/viewer_toolbar/doubleMangaPage.png differ diff --git a/shortcuts_management/shortcuts_manager.cpp b/shortcuts_management/shortcuts_manager.cpp index 64c07d4a..40e725de 100644 --- a/shortcuts_management/shortcuts_manager.cpp +++ b/shortcuts_management/shortcuts_manager.cpp @@ -39,6 +39,7 @@ void ShortcutsManager::initDefaultShorcuts() defaultShorcuts.insert(LEFT_ROTATION_ACTION_Y, Qt::Key_L); defaultShorcuts.insert(RIGHT_ROTATION_ACTION_Y, Qt::Key_R); defaultShorcuts.insert(DOUBLE_PAGE_ACTION_Y, Qt::Key_D); + defaultShorcuts.insert(DOUBLE_MANGA_PAGE_ACTION_Y, Qt::Key_J); defaultShorcuts.insert(GO_TO_PAGE_ACTION_Y, Qt::Key_G); defaultShorcuts.insert(OPTIONS_ACTION_Y, Qt::Key_C); defaultShorcuts.insert(HELP_ABOUT_ACTION_Y, Qt::Key_F1); diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h index 7c435fd7..cdeacd58 100644 --- a/shortcuts_management/shortcuts_manager.h +++ b/shortcuts_management/shortcuts_manager.h @@ -94,6 +94,7 @@ public: #define LEFT_ROTATION_ACTION_Y "LEFT_ROTATION_ACTION_Y" #define RIGHT_ROTATION_ACTION_Y "RIGHT_ROTATION_ACTION_Y" #define DOUBLE_PAGE_ACTION_Y "DOUBLE_PAGE_ACTION_Y" +#define DOUBLE_MANGA_PAGE_ACTION_Y "DOUBLE_MANGA_PAGE_ACTION_Y" #define GO_TO_PAGE_ACTION_Y "GO_TO_PAGE_ACTION_Y" #define OPTIONS_ACTION_Y "OPTIONS_ACTION_Y" #define HELP_ABOUT_ACTION_Y "HELP_ABOUT_ACTION_Y"