Skip to content

Commit

Permalink
avoid cyclical image downscaling in lite mode
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Dec 13, 2023
1 parent 9be4c2c commit 8b91d47
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/librssguard/gui/webviewers/qtextbrowser/textbrowserviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "network-web/networkfactory.h"
#include "network-web/webfactory.h"

#include <QBuffer>
#include <QContextMenuEvent>
#include <QFileIconProvider>
#include <QScrollBar>
Expand Down Expand Up @@ -79,16 +80,28 @@ QVariant TextBrowserViewer::loadOneResource(int type, const QUrl& name) {
}

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;

tmr.start();
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"
<< 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;
Expand Down Expand Up @@ -465,7 +478,7 @@ void TextBrowserViewer::downloadNextNeededResource() {
void TextBrowserViewer::resourceDownloaded(const QUrl& url,
QNetworkReply::NetworkError status,
int http_code,
QByteArray contents) {
const QByteArray& contents) {
Q_UNUSED(http_code)

if (status == QNetworkReply::NetworkError::NoError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TextBrowserViewer : public QTextBrowser, public WebViewer {
void resourceDownloaded(const QUrl& url,
QNetworkReply::NetworkError status,
int http_code,
QByteArray contents = QByteArray());
const QByteArray &contents = QByteArray());

signals:
void reloadDocument();
Expand Down

0 comments on commit 8b91d47

Please sign in to comment.