mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
[PageScreen] Add option to choose in which format to save.
Also makes the dialog less confusing whether the image was saved or not. Closes #902
This commit is contained in:
parent
1a2e7ef788
commit
bb03cfb133
@ -39,76 +39,97 @@ PageScreen::PageScreen(WebView* view, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::PageScreen)
|
||||
, m_view(view)
|
||||
, m_blockClose(false)
|
||||
, m_fileSaving(0)
|
||||
, m_imageScaling(0)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
ui->setupUi(this);
|
||||
|
||||
m_formats[0] = QLatin1String("PNG");
|
||||
m_formats[1] = QLatin1String("BMP");
|
||||
m_formats[2] = QLatin1String("JPG");
|
||||
m_formats[3] = QLatin1String("PPM");
|
||||
m_formats[4] = QLatin1String("TIFF");
|
||||
|
||||
QHashIterator<int, QString> i(m_formats);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
ui->formats->addItem(tr("Save as %1").arg(i.value()));
|
||||
}
|
||||
|
||||
// Set png as a default format
|
||||
m_pageTitle = m_view->title();
|
||||
ui->location->setText(QString("%1/%2.png").arg(QDir::homePath(), QzTools::filterCharsFromFilename(m_pageTitle)));
|
||||
|
||||
QMovie* mov = new QMovie(":html/loading.gif");
|
||||
ui->label->setMovie(mov);
|
||||
mov->start();
|
||||
|
||||
m_pageTitle = m_view->title();
|
||||
|
||||
connect(ui->changeLocation, SIGNAL(clicked()), this, SLOT(changeLocation()));
|
||||
connect(ui->formats, SIGNAL(currentIndexChanged(int)), this, SLOT(formatChanged()));
|
||||
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::formatChanged()
|
||||
{
|
||||
QString text = ui->location->text();
|
||||
int pos = text.lastIndexOf(QLatin1Char('.'));
|
||||
|
||||
if (pos > -1) {
|
||||
text = text.left(pos + 1) + m_formats[ui->formats->currentIndex()].toLower();
|
||||
}
|
||||
else {
|
||||
text.append(QLatin1Char('.') + m_formats[ui->formats->currentIndex()].toLower());
|
||||
}
|
||||
|
||||
ui->location->setText(text);
|
||||
}
|
||||
|
||||
void PageScreen::changeLocation()
|
||||
{
|
||||
const QString &suggestedPath = QString("%1/%2.%3").arg(QDir::homePath(), QzTools::filterCharsFromFilename(m_pageTitle),
|
||||
m_formats[ui->formats->currentIndex()].toLower());
|
||||
const QString &path = QFileDialog::getSaveFileName(this, tr("Save Page Screen..."), suggestedPath);
|
||||
|
||||
if (!path.isEmpty()) {
|
||||
ui->location->setText(path);
|
||||
}
|
||||
}
|
||||
|
||||
void PageScreen::dialogAccepted()
|
||||
{
|
||||
const QString &suggestedPath = QString("%1/%2.png").arg(QDir::homePath(),
|
||||
QzTools::filterCharsFromFilename(m_pageTitle));
|
||||
m_filePath = QFileDialog::getSaveFileName(this, tr("Save Page Screen..."), suggestedPath);
|
||||
|
||||
if (!m_filePath.isEmpty()) {
|
||||
if (!ui->location->text().isEmpty()) {
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
m_blockClose = true;
|
||||
saveScreen();
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
m_fileSaving = new QFutureWatcher<void>(this);
|
||||
m_fileSaving->setFuture(QtConcurrent::run(this, &PageScreen::saveScreen));
|
||||
connect(m_fileSaving, SIGNAL(finished()), SLOT(screenSaved()));
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
void PageScreen::saveScreen()
|
||||
{
|
||||
QString pathWithoutSuffix = m_filePath;
|
||||
if (pathWithoutSuffix.endsWith(QLatin1String(".png"), Qt::CaseInsensitive)) {
|
||||
pathWithoutSuffix = pathWithoutSuffix.mid(0, pathWithoutSuffix.length() - 4);
|
||||
const QString &format = m_formats[ui->formats->currentIndex()];
|
||||
const QString &suffix = QLatin1Char('.') + m_formats[ui->formats->currentIndex()].toLower();
|
||||
|
||||
QString pathWithoutSuffix = ui->location->text();
|
||||
if (pathWithoutSuffix.endsWith(suffix, Qt::CaseInsensitive)) {
|
||||
pathWithoutSuffix = pathWithoutSuffix.mid(0, pathWithoutSuffix.length() - suffix.length());
|
||||
}
|
||||
|
||||
if (m_pageImages.count() == 1) {
|
||||
m_pageImages.first().save(pathWithoutSuffix + ".png", "PNG");
|
||||
m_pageImages.first().save(pathWithoutSuffix + suffix, format.toUtf8());
|
||||
}
|
||||
else {
|
||||
int part = 1;
|
||||
foreach (const QImage &image, m_pageImages) {
|
||||
const QString &fileName = pathWithoutSuffix + ".part" + QString::number(part);
|
||||
image.save(fileName + ".png", "PNG");
|
||||
image.save(fileName + suffix, format.toUtf8());
|
||||
part++;
|
||||
}
|
||||
}
|
||||
|
||||
m_blockClose = false;
|
||||
}
|
||||
|
||||
void PageScreen::screenSaved()
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void PageScreen::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
if (m_blockClose) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
QDialog::closeEvent(event);
|
||||
}
|
||||
|
||||
void PageScreen::createThumbnail()
|
||||
|
@ -44,23 +44,21 @@ private slots:
|
||||
void createThumbnail();
|
||||
void showImage();
|
||||
|
||||
void formatChanged();
|
||||
void changeLocation();
|
||||
void dialogAccepted();
|
||||
void saveScreen();
|
||||
void screenSaved();
|
||||
|
||||
private:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
void saveScreen();
|
||||
void createPixmap();
|
||||
|
||||
Ui::PageScreen* ui;
|
||||
WebView* m_view;
|
||||
QString m_pageTitle;
|
||||
bool m_blockClose;
|
||||
|
||||
QFutureWatcher<void>* m_fileSaving;
|
||||
QFutureWatcher<QImage>* m_imageScaling;
|
||||
QString m_filePath;
|
||||
QVector<QImage> m_pageImages;
|
||||
QHash<int, QString> m_formats;
|
||||
};
|
||||
|
||||
#endif // PAGESCREEN_H
|
||||
|
@ -6,23 +6,14 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>562</width>
|
||||
<height>332</height>
|
||||
<width>539</width>
|
||||
<height>368</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Page Screen</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="frameShape">
|
||||
@ -36,8 +27,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>562</width>
|
||||
<height>277</height>
|
||||
<width>531</width>
|
||||
<height>271</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
@ -58,6 +49,81 @@
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Format:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="formats"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Location:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="location">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="changeLocation">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
|
@ -2398,7 +2398,27 @@
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/lib/other/pagescreen.cpp" line="65"/>
|
||||
<location filename="../src/lib/other/pagescreen.ui" line="75"/>
|
||||
<source>Format:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/lib/other/pagescreen.ui" line="85"/>
|
||||
<source>Location:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/lib/other/pagescreen.ui" line="104"/>
|
||||
<source>...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/lib/other/pagescreen.cpp" line="56"/>
|
||||
<source>Save as %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/lib/other/pagescreen.cpp" line="94"/>
|
||||
<source>Save Page Screen...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
Loading…
Reference in New Issue
Block a user