Merged in selmf/yacreader (pull request #9)

Add support for double page suppression for spread pages and inverse reading order (aka manga mode) in double page mode
This commit is contained in:
Luis Ángel San Martín
2014-11-09 09:25:53 +01:00
13 changed files with 371 additions and 315 deletions

View File

@ -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<int>(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++;
}
}
}

View File

@ -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<QColor>();}

View File

@ -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;

View File

@ -108,6 +108,7 @@ class EditShortcutsDialog;
QAction *showInfoAction;
QAction *closeAction;
QAction *doublePageAction;
QAction *doubleMangaPageAction;
QAction *showShorcutsAction;
QAction *showDictionaryAction;
QAction *alwaysOnTopAction;

View File

@ -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<ImageFilter *> 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;i<filters.size();i++)
{
auxImg = filters[i]->setFilter(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<73>n listas, y se est<73>n cargando en el c<>mic
emit processingPage(); //para evitar confusiones esta se<73>al deber<65>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<73>n listas, y se est<73>n cargando en el c<>mic
emit processingPage(); //para evitar confusiones esta se<73>al deber<65>a llamarse de otra forma
//las p<>ginas no est<73>n listas, y se est<73>n cargando en el c<>mic
emit processingPage(); //para evitar confusiones esta se<73>al deber<65>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<73>al pageReady del hilo, con el SLOT prepareAvailablePage
connect(pageRenders[currentPageBufferedIndex],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int)));
//se emite la se<73>al de procesando, debido a que los hilos se arrancan aqu<71>
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<73> lista
emit currentPageReady();
//se renderizan las p<>ginas restantes para llenar el buffer.
if(doublePage)
fillBufferDoublePage();
else
fillBuffer();
// la p<>gina actual est<73> 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<63>l ser<65> la pr<70>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<63>l debe ser en funci<63>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<63>l ser<65> la pr<70>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<63>l ser<65> la pr<70>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<65>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<63>n y se libera la memoria (de hilos e im<69>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;
}

View File

@ -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;
};

View File

@ -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."));

View File

@ -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;

View File

@ -3,6 +3,7 @@
<file>../images/viewer_toolbar/bookmark.png</file>
<file>../images/viewer_toolbar/close.png</file>
<file>../images/viewer_toolbar/doublePage.png</file>
<file>../images/viewer_toolbar/doubleMangaPage.png</file>
<file>../images/viewer_toolbar/flow.png</file>
<file>../images/viewer_toolbar/full.png</file>
<file>../images/viewer_toolbar/goto.png</file>

View File

@ -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"

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B

View File

@ -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);

View File

@ -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"