2011-09-23 22:06:21 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
2011-09-23 22:06:21 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-09-21 14:20:49 +02:00
|
|
|
#include "pagescreen.h"
|
|
|
|
#include "ui_pagescreen.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "tabbedwebview.h"
|
2012-04-03 19:28:12 +02:00
|
|
|
#include "webpage.h"
|
2011-09-21 14:20:49 +02:00
|
|
|
#include "globalfunctions.h"
|
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QWebFrame>
|
2012-03-05 14:33:24 +01:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QMovie>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
2012-12-20 14:45:35 +01:00
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
#include <QtConcurrent/QtConcurrentRun>
|
|
|
|
#else
|
|
|
|
#include <QtConcurrentRun>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-10-26 19:23:50 +02:00
|
|
|
PageScreen::PageScreen(WebView* view, QWidget* parent)
|
|
|
|
: QDialog(parent)
|
2011-09-21 14:20:49 +02:00
|
|
|
, ui(new Ui::PageScreen)
|
|
|
|
, m_view(view)
|
2012-03-07 12:19:54 +01:00
|
|
|
, m_imageScaling(0)
|
|
|
|
, m_horizontalScrollbarSize(0)
|
|
|
|
, m_verticalScrollbarSize(0)
|
2011-09-21 14:20:49 +02:00
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2012-03-05 14:33:24 +01:00
|
|
|
QMovie* mov = new QMovie(":html/loading.gif");
|
|
|
|
ui->label->setMovie(mov);
|
|
|
|
mov->start();
|
2011-09-21 14:20:49 +02:00
|
|
|
|
2012-03-07 12:19:54 +01:00
|
|
|
m_pageTitle = m_view->title();
|
|
|
|
|
2012-03-05 14:33:24 +01:00
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), this, SLOT(dialogAccepted()));
|
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(close()));
|
|
|
|
|
|
|
|
QTimer::singleShot(200, this, SLOT(createThumbnail()));
|
2011-09-21 14:20:49 +02:00
|
|
|
}
|
|
|
|
|
2012-03-05 14:33:24 +01:00
|
|
|
void PageScreen::dialogAccepted()
|
2011-09-21 14:20:49 +02:00
|
|
|
{
|
2012-03-17 16:01:12 +01:00
|
|
|
const QString &suggestedPath = QDir::homePath() + "/" + QString("%1.png").arg(qz_filterCharsFromFilename(m_pageTitle));
|
|
|
|
QString path = QFileDialog::getSaveFileName(this, tr("Save Page Screen..."),
|
2012-03-22 19:41:12 +01:00
|
|
|
suggestedPath);
|
2011-09-21 14:20:49 +02:00
|
|
|
|
2012-03-05 14:33:24 +01:00
|
|
|
if (!path.isEmpty()) {
|
2012-09-04 12:42:45 +02:00
|
|
|
if (!path.endsWith(QLatin1String(".png"), Qt::CaseInsensitive)) {
|
|
|
|
path.append(QLatin1String(".png"));
|
2012-03-17 16:01:12 +01:00
|
|
|
}
|
2012-03-07 20:01:57 +01:00
|
|
|
|
2012-03-17 16:01:12 +01:00
|
|
|
m_pageImage.save(path, "PNG");
|
2012-03-07 20:01:57 +01:00
|
|
|
QTimer::singleShot(0, this, SLOT(close()));
|
2011-09-21 14:20:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-05 14:33:24 +01:00
|
|
|
void PageScreen::createThumbnail()
|
2011-09-21 14:20:49 +02:00
|
|
|
{
|
|
|
|
QWebPage* page = m_view->page();
|
|
|
|
QSize originalSize = page->viewportSize();
|
|
|
|
page->setViewportSize(page->mainFrame()->contentsSize());
|
|
|
|
|
2012-03-05 20:41:54 +01:00
|
|
|
m_pageImage = QImage(page->viewportSize(), QImage::Format_ARGB32_Premultiplied);
|
2012-03-05 14:33:24 +01:00
|
|
|
QPainter painter(&m_pageImage);
|
2011-09-21 14:20:49 +02:00
|
|
|
page->mainFrame()->render(&painter);
|
|
|
|
painter.end();
|
|
|
|
|
2012-03-07 12:19:54 +01:00
|
|
|
m_verticalScrollbarSize = page->mainFrame()->scrollBarGeometry(Qt::Vertical).width();
|
|
|
|
m_horizontalScrollbarSize = page->mainFrame()->scrollBarGeometry(Qt::Horizontal).height();
|
|
|
|
|
2011-09-21 14:20:49 +02:00
|
|
|
page->setViewportSize(originalSize);
|
2012-03-05 14:33:24 +01:00
|
|
|
|
|
|
|
m_imageScaling = new QFutureWatcher<QImage>(this);
|
|
|
|
connect(m_imageScaling, SIGNAL(finished()), SLOT(showImage()));
|
|
|
|
|
2012-03-07 12:19:54 +01:00
|
|
|
m_imageScaling->setFuture(QtConcurrent::run(this, &PageScreen::scaleImage));
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage PageScreen::scaleImage()
|
|
|
|
{
|
|
|
|
if (m_verticalScrollbarSize > 0 || m_horizontalScrollbarSize > 0) {
|
|
|
|
QRect newRect = m_pageImage.rect();
|
|
|
|
newRect.setWidth(newRect.width() - m_verticalScrollbarSize);
|
|
|
|
newRect.setHeight(newRect.height() - m_horizontalScrollbarSize);
|
|
|
|
|
|
|
|
m_pageImage = m_pageImage.copy(newRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_pageImage.scaledToWidth(450, Qt::SmoothTransformation);
|
2012-03-05 14:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PageScreen::showImage()
|
|
|
|
{
|
|
|
|
delete ui->label->movie();
|
|
|
|
|
|
|
|
ui->label->setPixmap(QPixmap::fromImage(m_imageScaling->result()));
|
2011-09-21 14:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PageScreen::~PageScreen()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|