1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Improved "Save Page Screen" dialog.

- it is now loading page screen in new thread
- it now resizes thumbnail to fit the dialog size
This commit is contained in:
nowrep 2012-03-05 14:33:24 +01:00
parent 1be705e9af
commit 6878522c31
4 changed files with 55 additions and 42 deletions

View File

@ -22,6 +22,15 @@
#include <QFileDialog>
#include <QWebFrame>
#include <QTimer>
#include <QMovie>
#include <QtConcurrentRun>
#include <QPushButton>
QImage scale(QImage image)
{
return image.scaled(QSize(470, 370), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
}
PageScreen::PageScreen(WebView* view, QWidget* parent)
: QDialog(parent)
@ -31,48 +40,50 @@ PageScreen::PageScreen(WebView* view, QWidget* parent)
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
createPixmap();
ui->label->setPixmap(m_pagePixmap);
QMovie* mov = new QMovie(":html/loading.gif");
ui->label->setMovie(mov);
mov->start();
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
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()));
}
void PageScreen::buttonClicked(QAbstractButton* b)
void PageScreen::dialogAccepted()
{
QString path;
const QString &path = QFileDialog::getSaveFileName(this, tr("Save Page Screen..."), tr("screen.png"));
switch (ui->buttonBox->standardButton(b)) {
case QDialogButtonBox::Cancel:
if (!path.isEmpty()) {
m_pageImage.save(path);
close();
break;
case QDialogButtonBox::Save:
path = QFileDialog::getSaveFileName(this, tr("Save Page Screen..."), tr("screen.png"));
if (!path.isEmpty()) {
m_pagePixmap.save(path);
close();
}
break;
default:
break;
}
}
void PageScreen::createPixmap()
void PageScreen::createThumbnail()
{
QWebPage* page = m_view->page();
QSize originalSize = page->viewportSize();
page->setViewportSize(page->mainFrame()->contentsSize());
QImage image(page->viewportSize(), QImage::Format_ARGB32);
QPainter painter(&image);
m_pageImage = QImage(page->viewportSize(), QImage::Format_ARGB32);
QPainter painter(&m_pageImage);
page->mainFrame()->render(&painter);
painter.end();
m_pagePixmap = QPixmap::fromImage(image);
page->setViewportSize(originalSize);
m_imageScaling = new QFutureWatcher<QImage>(this);
connect(m_imageScaling, SIGNAL(finished()), SLOT(showImage()));
m_imageScaling->setFuture(QtConcurrent::run(scale, m_pageImage));
}
void PageScreen::showImage()
{
delete ui->label->movie();
ui->label->setPixmap(QPixmap::fromImage(m_imageScaling->result()));
}
PageScreen::~PageScreen()

View File

@ -19,6 +19,7 @@
#define PAGESCREEN_H
#include <QDialog>
#include <QFutureWatcher>
#include "qz_namespace.h"
@ -40,6 +41,11 @@ public:
~PageScreen();
private slots:
void createThumbnail();
void showImage();
void dialogAccepted();
void buttonClicked(QAbstractButton* b);
private:
@ -47,7 +53,9 @@ private:
Ui::PageScreen* ui;
WebView* m_view;
QPixmap m_pagePixmap;
QImage m_pageImage;
QFutureWatcher<QImage>* m_imageScaling;
};
#endif // PAGESCREEN_H

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>470</width>
<height>425</height>
<width>472</width>
<height>421</height>
</rect>
</property>
<property name="windowTitle">
@ -28,12 +28,6 @@
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
@ -42,11 +36,11 @@
<rect>
<x>0</x>
<y>0</y>
<width>470</width>
<height>376</height>
<width>472</width>
<height>372</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
@ -56,7 +50,7 @@
<item>
<widget class="QLabel" name="label">
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>

View File

@ -42,11 +42,6 @@ AKN_Settings::AKN_Settings(AKN_Handler* handler, QWidget* parent)
connect(this, SIGNAL(accepted()), this, SLOT(dialogAccepted()));
}
AKN_Settings::~AKN_Settings()
{
delete ui;
}
void AKN_Settings::dialogAccepted()
{
QSettings settings(m_settingsPath, QSettings::IniFormat);
@ -64,3 +59,8 @@ void AKN_Settings::showLicence()
v->setLicenseFile(":accesskeysnavigation/data/copyright");
v->show();
}
AKN_Settings::~AKN_Settings()
{
delete ui;
}