avoid cyclical image downscaling in lite mode
This commit is contained in:
parent
9be4c2c489
commit
8b91d4709f
2 changed files with 17 additions and 4 deletions
|
@ -15,6 +15,7 @@
|
||||||
#include "network-web/networkfactory.h"
|
#include "network-web/networkfactory.h"
|
||||||
#include "network-web/webfactory.h"
|
#include "network-web/webfactory.h"
|
||||||
|
|
||||||
|
#include <QBuffer>
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
#include <QFileIconProvider>
|
#include <QFileIconProvider>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
@ -79,16 +80,28 @@ QVariant TextBrowserViewer::loadOneResource(int type, const QUrl& name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int acceptable_width = int(width() * ACCEPTABLE_IMAGE_PERCENTUAL_WIDTH);
|
int acceptable_width = int(width() * ACCEPTABLE_IMAGE_PERCENTUAL_WIDTH);
|
||||||
|
int img_width = img.width();
|
||||||
|
|
||||||
if (img.width() > acceptable_width) {
|
if (img_width > acceptable_width) {
|
||||||
QElapsedTimer tmr;
|
QElapsedTimer tmr;
|
||||||
|
|
||||||
tmr.start();
|
tmr.start();
|
||||||
img = img.scaledToWidth(acceptable_width, Qt::TransformationMode::SmoothTransformation);
|
img = img.scaledToWidth(acceptable_width, Qt::TransformationMode::SmoothTransformation);
|
||||||
|
|
||||||
qWarningNN << LOGSEC_GUI << "Picture" << QUOTE_W_SPACE(name)
|
qWarningNN << LOGSEC_GUI << "Picture" << QUOTE_W_SPACE(name) << "with width" << QUOTE_W_SPACE(img_width)
|
||||||
<< "is too wide, down-scaling to prevent horizontal scrollbars. Scaling took"
|
<< "is too wide, down-scaling to prevent horizontal scrollbars. Scaling took"
|
||||||
<< NONQUOTE_W_SPACE(tmr.elapsed()) << "miliseconds.";
|
<< NONQUOTE_W_SPACE(tmr.elapsed()) << "miliseconds.";
|
||||||
|
|
||||||
|
QByteArray save_arr;
|
||||||
|
QBuffer save_buf(&save_arr, this);
|
||||||
|
|
||||||
|
if (img.save(&save_buf, "PNG", 100)) {
|
||||||
|
save_buf.close();
|
||||||
|
m_loadedResources.insert(resolved_name, save_arr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qWarningNN << LOGSEC_GUI << "Failed to save modified image" << QUOTE_W_SPACE(name) << "to cache.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
|
@ -465,7 +478,7 @@ void TextBrowserViewer::downloadNextNeededResource() {
|
||||||
void TextBrowserViewer::resourceDownloaded(const QUrl& url,
|
void TextBrowserViewer::resourceDownloaded(const QUrl& url,
|
||||||
QNetworkReply::NetworkError status,
|
QNetworkReply::NetworkError status,
|
||||||
int http_code,
|
int http_code,
|
||||||
QByteArray contents) {
|
const QByteArray& contents) {
|
||||||
Q_UNUSED(http_code)
|
Q_UNUSED(http_code)
|
||||||
|
|
||||||
if (status == QNetworkReply::NetworkError::NoError) {
|
if (status == QNetworkReply::NetworkError::NoError) {
|
||||||
|
|
|
@ -78,7 +78,7 @@ class TextBrowserViewer : public QTextBrowser, public WebViewer {
|
||||||
void resourceDownloaded(const QUrl& url,
|
void resourceDownloaded(const QUrl& url,
|
||||||
QNetworkReply::NetworkError status,
|
QNetworkReply::NetworkError status,
|
||||||
int http_code,
|
int http_code,
|
||||||
QByteArray contents = QByteArray());
|
const QByteArray &contents = QByteArray());
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void reloadDocument();
|
void reloadDocument();
|
||||||
|
|
Loading…
Add table
Reference in a new issue