mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-04 19:27:33 +01:00
fix zooming
This commit is contained in:
parent
994c377049
commit
bc2dbfe70e
@ -29,6 +29,12 @@ TextBrowserViewer::TextBrowserViewer(QWidget* parent) : QTextBrowser(parent), m_
|
||||
}
|
||||
|
||||
QVariant TextBrowserViewer::loadResource(int type, const QUrl& name) {
|
||||
if (!m_reloadingWithResources) {
|
||||
if (type == QTextDocument::ResourceType::ImageResource) {
|
||||
m_resourcesForHtml.append(name);
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -127,11 +133,19 @@ void TextBrowserViewer::bindToBrowser(WebBrowser* browser) {
|
||||
|
||||
void TextBrowserViewer::findText(const QString& text, bool backwards) {
|
||||
if (!text.isEmpty()) {
|
||||
QTextBrowser::find(text, backwards ? QTextDocument::FindFlag::FindBackward : QTextDocument::FindFlag(0));
|
||||
bool found =
|
||||
QTextBrowser::find(text, backwards ? QTextDocument::FindFlag::FindBackward : QTextDocument::FindFlag(0));
|
||||
|
||||
if (!found) {
|
||||
textCursor().clearSelection();
|
||||
moveCursor(QTextCursor::MoveOperation::Start);
|
||||
|
||||
QTextBrowser::find(text, backwards ? QTextDocument::FindFlag::FindBackward : QTextDocument::FindFlag(0));
|
||||
}
|
||||
}
|
||||
else {
|
||||
textCursor().clearSelection();
|
||||
moveCursor(QTextCursor::MoveOperation::Left);
|
||||
moveCursor(QTextCursor::MoveOperation::Start);
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,6 +218,10 @@ void TextBrowserViewer::setUrl(const QUrl& url) {
|
||||
void TextBrowserViewer::setHtml(const QString& html, const QUrl& base_url) {
|
||||
m_currentUrl = base_url;
|
||||
|
||||
if (!m_reloadingWithResources) {
|
||||
m_resourcesForHtml.clear();
|
||||
}
|
||||
|
||||
QTextBrowser::setHtml(html);
|
||||
|
||||
setZoomFactor(m_zoomFactor);
|
||||
@ -243,20 +261,23 @@ void TextBrowserViewer::setVerticalScrollBarPosition(double pos) {
|
||||
}
|
||||
|
||||
void TextBrowserViewer::applyFont(const QFont& fon) {
|
||||
m_baseFont = fon;
|
||||
setFont(fon);
|
||||
setZoomFactor(zoomFactor());
|
||||
}
|
||||
|
||||
qreal TextBrowserViewer::zoomFactor() const {
|
||||
return font().pointSizeF() / 8.0;
|
||||
return m_zoomFactor;
|
||||
}
|
||||
|
||||
void TextBrowserViewer::setZoomFactor(qreal zoom_factor) {
|
||||
m_zoomFactor = zoom_factor;
|
||||
|
||||
auto fon = font();
|
||||
fon.setPointSizeF(8.0 * zoom_factor);
|
||||
|
||||
applyFont(fon);
|
||||
fon.setPointSizeF(m_baseFont.pointSizeF() * zoom_factor);
|
||||
|
||||
setFont(fon);
|
||||
}
|
||||
|
||||
void TextBrowserViewer::contextMenuEvent(QContextMenuEvent* event) {
|
||||
@ -268,6 +289,14 @@ void TextBrowserViewer::contextMenuEvent(QContextMenuEvent* event) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_actionReloadWithImages.isNull()) {
|
||||
m_actionReloadWithImages.reset(new QAction(qApp->icons()->fromTheme(QSL("viewimage"), QSL("view-refresh")),
|
||||
tr("Reload with images"),
|
||||
this));
|
||||
|
||||
connect(m_actionReloadWithImages.data(), &QAction::triggered, this, &TextBrowserViewer::reloadWithImages);
|
||||
}
|
||||
|
||||
auto anchor = anchorAt(event->pos());
|
||||
|
||||
if (!anchor.isEmpty()) {
|
||||
@ -314,10 +343,18 @@ void TextBrowserViewer::resizeEvent(QResizeEvent* event) {
|
||||
}
|
||||
|
||||
void TextBrowserViewer::wheelEvent(QWheelEvent* event) {
|
||||
// NOTE: Skip base class implemetation.
|
||||
QAbstractScrollArea::wheelEvent(event);
|
||||
updateMicroFocus();
|
||||
}
|
||||
|
||||
void TextBrowserViewer::reloadWithImages() {
|
||||
m_reloadingWithResources = true;
|
||||
m_loadedResources.clear();
|
||||
|
||||
setHtml(html(), m_currentUrl);
|
||||
}
|
||||
|
||||
void TextBrowserViewer::onAnchorClicked(const QUrl& url) {
|
||||
if (!url.isEmpty()) {
|
||||
bool open_externally_now =
|
||||
|
@ -47,6 +47,7 @@ class TextBrowserViewer : public QTextBrowser, public WebViewer {
|
||||
virtual void wheelEvent(QWheelEvent* event);
|
||||
|
||||
private slots:
|
||||
void reloadWithImages();
|
||||
void onAnchorClicked(const QUrl& url);
|
||||
|
||||
signals:
|
||||
@ -68,7 +69,12 @@ class TextBrowserViewer : public QTextBrowser, public WebViewer {
|
||||
private:
|
||||
QUrl m_currentUrl;
|
||||
QPointer<RootItem> m_root;
|
||||
QFont m_baseFont;
|
||||
qreal m_zoomFactor = 1.0;
|
||||
QScopedPointer<QAction> m_actionReloadWithImages;
|
||||
bool m_reloadingWithResources;
|
||||
QList<QUrl> m_resourcesForHtml;
|
||||
QMap<QUrl, QByteArray> m_loadedResources;
|
||||
};
|
||||
|
||||
#endif // TEXTBROWSERVIEWER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user