optimizado thumbnailcreator para que no escale si target==""

nuevo di?log de propiedades ya funcional
This commit is contained in:
Luis Ángel San Martín
2013-06-20 16:26:31 +02:00
parent ec1d3d96e9
commit 3ac85ccb7b
3 changed files with 196 additions and 61 deletions

View File

@ -445,14 +445,17 @@ void ThumbnailCreator::create()
QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72); //TODO check if the the page is valid QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72); //TODO check if the the page is valid
_cover = QPixmap::fromImage(p); _cover = QPixmap::fromImage(p);
QImage scaled; if(_target!="")
if(p.width()>p.height()) //landscape?? {
scaled = p.scaledToWidth(640,Qt::SmoothTransformation); QImage scaled;
else if(p.width()>p.height()) //landscape??
scaled = p.scaledToWidth(480,Qt::SmoothTransformation); scaled = p.scaledToWidth(640,Qt::SmoothTransformation);
scaled.save(_target,0,75); else
scaled = p.scaledToWidth(480,Qt::SmoothTransformation);
scaled.save(_target,0,75);
}
} }
else else if(_target!="")
{ {
QImage p; QImage p;
p.load(":/images/notCover.png"); p.load(":/images/notCover.png");

View File

@ -5,7 +5,7 @@
#include "yacreader_field_edit.h" #include "yacreader_field_edit.h"
#include "yacreader_field_plain_text_edit.h" #include "yacreader_field_plain_text_edit.h"
#include "db_helper.h" #include "db_helper.h"
#include "yacreader_busy_widget.h" //#include "yacreader_busy_widget.h"
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QApplication> #include <QApplication>
@ -48,7 +48,7 @@ PropertiesDialog::PropertiesDialog(QWidget * parent)
int sHeight,sWidth; int sHeight,sWidth;
sHeight = static_cast<int>(heightDesktopResolution*0.65); sHeight = static_cast<int>(heightDesktopResolution*0.65);
sWidth = static_cast<int>(sHeight*1.4); sWidth = static_cast<int>(sHeight*1.4);
setCover(QPixmap(":/images/notCover.png")); //setCover(QPixmap(":/images/notCover.png"));
this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2)); this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2));
setModal(true); setModal(true);
@ -84,22 +84,22 @@ void PropertiesDialog::createCoverBox()
coverPageEdit = new YACReaderFieldEdit(); coverPageEdit = new YACReaderFieldEdit();
QToolButton * previous = new QToolButton(); showPreviousCoverPageButton = new QToolButton();
previous->setIcon(QIcon(":/images/previousCoverPage.png")); showPreviousCoverPageButton->setIcon(QIcon(":/images/previousCoverPage.png"));
previous->setStyleSheet("QToolButton {border:none;}"); showPreviousCoverPageButton->setStyleSheet("QToolButton {border:none;}");
QToolButton * next = new QToolButton(); showNextCoverPageButton = new QToolButton();
next->setIcon(QIcon(":/images/nextCoverPage.png")); showNextCoverPageButton->setIcon(QIcon(":/images/nextCoverPage.png"));
next->setStyleSheet("QToolButton {border:none;}"); showNextCoverPageButton->setStyleSheet("QToolButton {border:none;}");
QLabel * coverPageNumberLabel = new QLabel("1"); coverPageNumberLabel = new QLabel("-");
coverPageNumberLabel->setStyleSheet("QLabel {color: white; font-weight:bold; font-size:14px;}"); coverPageNumberLabel->setStyleSheet("QLabel {color: white; font-weight:bold; font-size:14px;}");
layout->addWidget(previous); layout->addWidget(showPreviousCoverPageButton);
layout->addSpacing(5); layout->addSpacing(5);
layout->addWidget(coverPageNumberLabel); layout->addWidget(coverPageNumberLabel);
layout->addSpacing(5); layout->addSpacing(5);
layout->addWidget(next); layout->addWidget(showNextCoverPageButton);
coverPageEdit->setStyleSheet("QLineEdit {border:none;}"); coverPageEdit->setStyleSheet("QLineEdit {border:none;}");
layout->setSpacing(0); layout->setSpacing(0);
@ -110,8 +110,12 @@ void PropertiesDialog::createCoverBox()
coverBox->move(0,444-28); coverBox->move(0,444-28);
layout->setContentsMargins(5,4,5,0); layout->setContentsMargins(5,4,5,0);
busyIndicator = new YACReaderBusyWidget(this); //busyIndicator = new YACReaderBusyWidget(this);
busyIndicator->move((280-busyIndicator->width())/2,(444-busyIndicator->height()-28)/2); //busyIndicator->move((280-busyIndicator->width())/2,(444-busyIndicator->height()-28)/2);
//busyIndicator->hide();
connect(showPreviousCoverPageButton,SIGNAL(pressed()),this,SLOT(loadPreviousCover()));
connect(showNextCoverPageButton,SIGNAL(pressed()),this,SLOT(loadNextCover()));
} }
@ -283,7 +287,73 @@ void PropertiesDialog::createButtonBox()
connect(saveButton, SIGNAL(clicked()), this, SLOT(save())); connect(saveButton, SIGNAL(clicked()), this, SLOT(save()));
} }
QImage blurred(const QImage& image, const QRect& rect, int radius, bool alphaOnly = false)
{
int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
int alpha = (radius < 1) ? 16 : (radius > 17) ? 1 : tab[radius-1];
QImage result = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
int r1 = rect.top();
int r2 = rect.bottom();
int c1 = rect.left();
int c2 = rect.right();
int bpl = result.bytesPerLine();
int rgba[4];
unsigned char* p;
int i1 = 0;
int i2 = 3;
if (alphaOnly)
i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3);
for (int col = c1; col <= c2; col++) {
p = result.scanLine(r1) + col * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p += bpl;
for (int j = r1; j < r2; j++, p += bpl)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
for (int row = r1; row <= r2; row++) {
p = result.scanLine(row) + c1 * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p += 4;
for (int j = c1; j < c2; j++, p += 4)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
for (int col = c1; col <= c2; col++) {
p = result.scanLine(r2) + col * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p -= bpl;
for (int j = r1; j < r2; j++, p -= bpl)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
for (int row = r1; row <= r2; row++) {
p = result.scanLine(row) + c2 * 4;
for (int i = i1; i <= i2; i++)
rgba[i] = p[i] << 4;
p -= 4;
for (int j = c1; j < c2; j++, p -= 4)
for (int i = i1; i <= i2; i++)
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}
return result;
}
void PropertiesDialog::setComics(QList<ComicDB> comics) void PropertiesDialog::setComics(QList<ComicDB> comics)
{ {
@ -294,11 +364,26 @@ void PropertiesDialog::setComics(QList<ComicDB> comics)
if(comic.info.title != NULL) if(comic.info.title != NULL)
title->setText(*comic.info.title); title->setText(*comic.info.title);
if(comic.info.coverPage != NULL) if(comics.length()==1 &&comic.info.coverPage != NULL)
{ {
coverPageEdit->setText(QString::number(*comic.info.coverPage)); coverPageEdit->setText(QString::number(*comic.info.coverPage));
coverPageValidator.setRange(1,*comic.info.numPages); coverPageValidator.setRange(1,*comic.info.numPages);
coverPageEdit->setValidator(&coverPageValidator); coverPageEdit->setValidator(&coverPageValidator);
//----------
int coverPage = *comic.info.coverPage;
coverPageNumberLabel->setText(QString::number(coverPage));
coverPageNumberLabel->adjustSize();
showPreviousCoverPageButton->setEnabled(true);
showNextCoverPageButton->setEnabled(true);
if(coverPage == 1)
showPreviousCoverPageButton->setDisabled(true);
if(coverPage == *comic.info.numPages)
showNextCoverPageButton->setDisabled(true);
coverChanged = false;
coverBox->show();
} }
/*if(comic.info.numPages != NULL) /*if(comic.info.numPages != NULL)
numPagesEdit->setText(QString::number(*comic.info.numPages));*/ numPagesEdit->setText(QString::number(*comic.info.numPages));*/
@ -367,9 +452,11 @@ void PropertiesDialog::setComics(QList<ComicDB> comics)
if(comics.length() > 1) if(comics.length() > 1)
{ {
coverBox->hide();
setDisableUniqueValues(true); setDisableUniqueValues(true);
this->setWindowTitle(tr("Edit selected comics information")); this->setWindowTitle(tr("Edit selected comics information"));
setCover(QPixmap(":/images/editComic.png")); setMultipleCover();
QList<ComicDB>::iterator itr; QList<ComicDB>::iterator itr;
for(itr = ++comics.begin();itr!=comics.end();itr++) for(itr = ++comics.begin();itr!=comics.end();itr++)
@ -445,8 +532,6 @@ void PropertiesDialog::setComics(QList<ComicDB> comics)
} }
void PropertiesDialog::updateComics() void PropertiesDialog::updateComics()
{ {
QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath);
@ -462,39 +547,21 @@ void PropertiesDialog::updateComics()
db.close(); db.close();
QSqlDatabase::removeDatabase(databasePath); QSqlDatabase::removeDatabase(databasePath);
} }
//Deprecated
void PropertiesDialog::setMultipleCover()
{
ComicDB lastComic = comics.last();
QPixmap last = lastComic.info.getCover(basePath);
last = last.scaledToHeight(444,Qt::SmoothTransformation);
coverImage = QPixmap::fromImage(blurred(last.toImage(),QRect(0,0,last.width(),last.height()),15));
}
void PropertiesDialog::setCover(const QPixmap & coverI) void PropertiesDialog::setCover(const QPixmap & coverI)
{ {
coverImage = coverI.scaledToHeight(444,Qt::SmoothTransformation); coverImage = coverI.scaledToHeight(444,Qt::SmoothTransformation);
//cover->setPixmap(coverImage.scaledToWidth(125,Qt::SmoothTransformation));
//cover->repaint();
//float aspectRatio = (float)coverImage.width()/coverImage.height();
//int heightDesktopResolution = QApplication::desktop()->screenGeometry().height();
//int widthDesktopResolution = QApplication::desktop()->screenGeometry().width();
//int sHeight,sWidth;
//sHeight = static_cast<int>(heightDesktopResolution*0.65);
//if(aspectRatio<1)
//{
// sWidth = static_cast<int>(sHeight*1.4);
// //this->resize(sWidth,sHeight);
// this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2));
// //sa->resize(sa->width(),sa->width()*1.333);
// /*cover->resize(static_cast<int>((sa->height())*aspectRatio),
// (sa->height()));*/
//}
//else
//{
// sWidth = static_cast<int>(sHeight/1.16);
// //this->resize(sWidth,sHeight);
// this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2));
// cover->resize((width()-25),
// static_cast<int>((width()-25)/aspectRatio));
//}
} }
void PropertiesDialog::setFilename(const QString & nameString) void PropertiesDialog::setFilename(const QString & nameString)
{ {
title->setText(nameString); title->setText(nameString);
@ -524,9 +591,9 @@ void PropertiesDialog::save()
} }
if(comics.size()==1) if(comics.size()==1)
if(coverPageEdit->isModified() && !coverPageEdit->text().isEmpty() && coverPageEdit->text().toInt() != 0) if(coverChanged)
{ {
itr->info.setCoverPage(coverPageEdit->text().toInt()); itr->info.setCoverPage(coverPageNumberLabel->text().toInt());
edited = true; edited = true;
} }
@ -657,7 +724,7 @@ void PropertiesDialog::save()
updateComics(); updateComics();
if(comics.count() == 1) if(comics.count() == 1)
{ {
if(coverPageEdit->isModified())// && coverPageEdit->text().toInt() != *comics[0].info.coverPage) if(coverChanged)// && coverPageEdit->text().toInt() != *comics[0].info.coverPage)
{ {
ThumbnailCreator tc(basePath+comics[0].path,basePath+"/.yacreaderlibrary/covers/"+comics[0].info.hash+".jpg",*comics[0].info.coverPage); ThumbnailCreator tc(basePath+comics[0].path,basePath+"/.yacreaderlibrary/covers/"+comics[0].info.hash+".jpg",*comics[0].info.coverPage);
tc.create(); tc.create();
@ -728,8 +795,60 @@ void PropertiesDialog::paintEvent(QPaintEvent * event)
p.drawPixmap(0,0,coverImage); p.drawPixmap(0,0,coverImage);
QPixmap shadow(":/images/social_dialog/shadow.png"); //QPixmap shadow(":/images/social_dialog/shadow.png");
p.drawPixmap(280-shadow.width(),0,shadow.width(),444,shadow); //p.drawPixmap(280-shadow.width(),0,shadow.width(),444,shadow);
p.drawLine(279,0,279,444);
if(comics.length()==1)
p.fillRect(0,444-28,280,28,QColor(0,0,0,153));
}
p.fillRect(0,444-28,280,28,QColor(0,0,0,153)); void PropertiesDialog::updateCoverPageNumberLabel(int n)
{
coverPageNumberLabel->setText(QString::number(n));
coverPageNumberLabel->adjustSize();
}
void PropertiesDialog::loadNextCover()
{
int current = coverPageNumberLabel->text().toInt();
if(current < *(comics.at(0).info.numPages))
{
updateCoverPageNumberLabel(current+1);
ThumbnailCreator tc(basePath+comics[0].path,"",current+1);
tc.create();
setCover(tc.getCover());
repaint();
if((current+1) == *(comics.at(0).info.numPages))
{
showNextCoverPageButton->setDisabled(true);
}
showPreviousCoverPageButton->setEnabled(true);
//busyIndicator->show();
coverChanged = true;
}
}
void PropertiesDialog::loadPreviousCover()
{
int current = coverPageNumberLabel->text().toInt();
if(current!=1)
{
updateCoverPageNumberLabel(current-1);
ThumbnailCreator tc(basePath+comics[0].path,"",current-1);
tc.create();
setCover(tc.getCover());
repaint();
if((current-1) == 1)
{
showPreviousCoverPageButton->setDisabled(true);
}
showNextCoverPageButton->setEnabled(true);
//busyIndicator->show();
coverChanged = true;
}
} }

View File

@ -15,7 +15,8 @@ class YACReaderFieldEdit;
class YACReaderFieldPlainTextEdit; class YACReaderFieldPlainTextEdit;
class QDialogButtonBox; class QDialogButtonBox;
class QCheckBox; class QCheckBox;
class YACReaderBusyWidget; //class YACReaderBusyWidget;
class QToolButton;
#include "comic_db.h" #include "comic_db.h"
@ -24,7 +25,7 @@ class YACReaderBusyWidget;
Q_OBJECT Q_OBJECT
private: private:
QWidget * mainWidget; QWidget * mainWidget;
YACReaderBusyWidget * busyIndicator; //YACReaderBusyWidget * busyIndicator;
QGridLayout * mainLayout; QGridLayout * mainLayout;
@ -92,6 +93,10 @@ class YACReaderBusyWidget;
QPixmap coverImage; QPixmap coverImage;
QToolButton * showPreviousCoverPageButton;
QToolButton * showNextCoverPageButton;
QLabel * coverPageNumberLabel;
void createTabBar(); void createTabBar();
void createCoverBox(); void createCoverBox();
void createGeneralInfoBox(); void createGeneralInfoBox();
@ -105,6 +110,10 @@ class YACReaderBusyWidget;
QList<ComicDB> comics; QList<ComicDB> comics;
void closeEvent ( QCloseEvent * e ); void closeEvent ( QCloseEvent * e );
void updateCoverPageNumberLabel(int n);
bool coverChanged;
public: public:
PropertiesDialog(QWidget * parent = 0); PropertiesDialog(QWidget * parent = 0);
QString databasePath; QString databasePath;
@ -118,9 +127,13 @@ class YACReaderBusyWidget;
void save(); void save();
//Deprecated //Deprecated
void setCover(const QPixmap & cover); void setCover(const QPixmap & cover);
void setMultipleCover();
void setFilename(const QString & name); void setFilename(const QString & name);
void setNumpages(int pages); void setNumpages(int pages);
void setSize(float size); void setSize(float size);
void loadNextCover();
void loadPreviousCover();
}; };
#endif #endif