Skip to content
Browse files

Removed superfluous code

  • Loading branch information...
1 parent 205e2fe commit cefe6a1ec481ed075a25b713283651579831a3d5 @raphaelcruzeiro committed May 25, 2012
Showing with 18 additions and 58 deletions.
  1. +1 −19 main.cpp
  2. +15 −35 snapshot.cpp
  3. +2 −4 snapshot.h
View
20 main.cpp
@@ -27,19 +27,8 @@ int main(int argc, char *argv[])
QUrl url;
QString output;
QSize size(1024, 768);
- QSize scaleTo(0, 0);
- bool ignoreVerticalLimit = false;
- bool useSystemUI = false;
for(int i = 0; i < argc; i++) {
- if(strcmp(argv[i], "ignore-vertical-limit") == 0) {
- ignoreVerticalLimit = true;
- continue;
- } else if (strcmp(argv[i], "use-system-ui") == 0) {
- useSystemUI = true;
- continue;
- }
-
switch (i) {
case 1:
url = QUrl(QString(argv[1]));
@@ -55,18 +44,11 @@ int main(int argc, char *argv[])
QString(argv[3]).split(QChar('x'))[1].toInt()
);
break;
-
- case 4:
- scaleTo = QSize(
- QString(argv[4]).split(QChar('x'))[0].toInt(),
- QString(argv[4]).split(QChar('x'))[1].toInt()
- );
- break;
}
}
Snapshot shot;
- shot.shot(url, size, &output, scaleTo, ignoreVerticalLimit, useSystemUI);
+ shot.shot(url, size, &output);
return a.exec();
}
View
50 snapshot.cpp
@@ -22,22 +22,17 @@ Snapshot::Snapshot(QObject *parent) : QObject(parent), page(new CustomWebPage),
{
}
-void Snapshot::shot(QUrl url, QSize &size, QString *outputFilename, QSize scaleTo, bool ignoreVerticalLimit, bool useSystemUI, int quality)
+void Snapshot::shot(QUrl url, QSize &size, QString *outputFilename, int quality)
{
- this->scaleTo = scaleTo;
- this->ignoreVerticalLimit = ignoreVerticalLimit;
this->size = size;
- this->useSystemUI = useSystemUI;
this->quality = quality;
- if(useSystemUI) {
- qDebug() << "Loading UI...";
- view = new QWebView;
- view->setPage(page);
- QSize newSize = this->size;
- newSize.setHeight(7000);
- view->setMinimumSize(newSize);
- }
+ qDebug() << "Loading fake UI...";
+ view = new QWebView;
+ view->setPage(page);
+ QSize newSize = this->size;
+ newSize.setHeight(7000);
+ view->setMinimumSize(newSize);
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), SLOT(doneWaiting()));
@@ -66,31 +61,16 @@ void Snapshot::doneWaiting()
statusCode != 303
) {
- if(!useSystemUI) {
- QImage image(page->viewportSize(), QImage::Format_ARGB32);
- QPainter painter(&image);
-
- page->mainFrame()->render(&painter);
- painter.end();
-
- if(this->scaleTo != QSize(0, 0)) {
- qDebug() << "Scaling to " << scaleTo.width() << "x" << scaleTo.height();
- image = image.scaled(scaleTo);
- }
+ view->setMaximumHeight(page->mainFrame()->contentsSize().height());
+ view->repaint();
+ QPixmap pix = QPixmap::grabWidget(view, 0, 0, size.width(), page->mainFrame()->contentsSize().height());
+ pix.save(*outputFilename, "JPEG", quality);
- image.save(*outputFilename, "JPEG");
- } else {
- view->setMaximumHeight(page->mainFrame()->contentsSize().height());
- view->repaint();
- QPixmap pix = QPixmap::grabWidget(view, 0, 0, size.width(), page->mainFrame()->contentsSize().height());
- pix.save(*outputFilename, "JPEG", quality);
-
- QString thumbFilename = QString("%1_thumb.jpg").arg(outputFilename->split('.')[0]);
- QSize thumbSize((size.width() / 100) * 50, (page->mainFrame()->contentsSize().height() / 100) * 50);
- pix =pix.scaled(thumbSize, Qt::KeepAspectRatio);
- pix.save(thumbFilename, "JPEG", quality);
- }
+ QString thumbFilename = QString("%1_thumb.jpg").arg(outputFilename->split('.')[0]);
+ QSize thumbSize((size.width() / 100) * 50, (page->mainFrame()->contentsSize().height() / 100) * 50);
+ pix =pix.scaled(thumbSize, Qt::KeepAspectRatio);
+ pix.save(thumbFilename, "JPEG", quality);
QApplication::quit();
}
View
6 snapshot.h
@@ -33,16 +33,14 @@ class Snapshot : QObject
QTimer *timer;
int statusCode;
QUrl redirectUrl;
- QSize scaleTo, size;
- bool ignoreVerticalLimit, useSystemUI;
QWebView *view;
+ QSize size;
int tries, quality;
public:
Snapshot(QObject *parent = 0);
- void shot(QUrl url, QSize &size, QString *outputFilename = new QString("output.png"),
- QSize scaleTo = QSize(0, 0), bool ignoreVerticalLimit = false, bool useSystemUI = false, int quality = -1);
+ void shot(QUrl url, QSize &size, QString *outputFilename = new QString("output.png"), int quality = -1);
private slots:
void doneLoading(bool);

0 comments on commit cefe6a1

Please sign in to comment.
Something went wrong with that request. Please try again.