Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qlitehtmlwidget.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#pragma once
5
7
8#include <QAbstractScrollArea>
9#include <QTextDocument>
10
11#include <functional>
12
14
15class QLITEHTML_EXPORT QLiteHtmlWidget : public QAbstractScrollArea
16{
17 Q_OBJECT
18public:
19 explicit QLiteHtmlWidget(QWidget *parent = nullptr);
20 ~QLiteHtmlWidget() override;
21
22 // declaring the getters Q_INVOKABLE to make them Squish-testable
23 void setUrl(const QUrl &url);
24 Q_INVOKABLE QUrl url() const;
25 void setHtml(const QString &content);
26 Q_INVOKABLE QString html() const;
27 Q_INVOKABLE QString title() const;
28
29 void setZoomFactor(qreal scale);
30 qreal zoomFactor() const;
31
32 bool findText(const QString &text,
33 QTextDocument::FindFlags flags,
34 bool incremental,
35 bool *wrapped = nullptr);
36
37 void setDefaultFont(const QFont &font);
38 QFont defaultFont() const;
39 void setAntialias(bool on);
40
41 void scrollToAnchor(const QString &name);
42
43 using ResourceHandler = std::function<QByteArray(QUrl)>;
44 void setResourceHandler(const ResourceHandler &handler);
45
46 // declaring this Q_INVOKABLE to make it Squish-testable
47 Q_INVOKABLE QString selectedText() const;
48
49signals:
50 void linkClicked(const QUrl &url);
51 void linkHighlighted(const QUrl &url);
52 void copyAvailable(bool available);
53 void contextMenuRequested(const QPoint &pos, const QUrl &url);
54
55protected:
56 void paintEvent(QPaintEvent *event) override;
57 void resizeEvent(QResizeEvent *event) override;
58 void mouseMoveEvent(QMouseEvent *event) override;
59 void mousePressEvent(QMouseEvent *event) override;
60 void mouseReleaseEvent(QMouseEvent *event) override;
61 void mouseDoubleClickEvent(QMouseEvent *event) override;
62 void leaveEvent(QEvent *event) override;
63 void contextMenuEvent(QContextMenuEvent *event) override;
64 void keyPressEvent(QKeyEvent *event) override;
65
66private:
67 void updateHightlightedLink();
68 void setHightlightedLink(const QUrl &url);
69 void withFixedTextPosition(const std::function<void()> &action);
70 void render();
71 QPoint scrollPosition() const;
72 void htmlPos(const QPoint &pos, QPoint *viewportPos, QPoint *htmlPos) const;
73 QPoint toVirtual(const QPoint &p) const;
74 QSize toVirtual(const QSize &s) const;
75 QRect toVirtual(const QRect &r) const;
76 QRect fromVirtual(const QRect &r) const;
77
78 QLiteHtmlWidgetPrivate *d;
79};
static HelpEngineWrapper & instance()
HistoryItem currentHistoryItem() const
std::vector< HistoryItem > m_backItems
std::vector< HistoryItem > m_forwardItems
void applyZoom(int percentage)
QLiteHtmlWidget * m_viewer
void incrementZoom(int steps)
void setSourceInternal(const QUrl &url, int *vscroll=nullptr, bool reload=false)
void setViewerFont(const QFont &font)
void scaleUp()
QString title() const
void setSource(const QUrl &url)
void resetScale()
QString selectedText() const
void forward()
void scaleDown()
void reload()
bool isForwardAvailable() const
void backward()
QFont viewerFont() const
~HelpViewer() override
QUrl source() const
bool findText(const QString &text, FindFlags flags, bool incremental, bool fromSearch)
qreal scale() const
bool isBackwardAvailable() const
bool eventFilter(QObject *src, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
static QByteArray getData(const QUrl &url)
static QTextDocument::FindFlags textDocumentFlagsForFindFlags(HelpViewer::FindFlags flags)
const int kMaxHistoryItems
Combined button and popup list for selecting options.
#define QLITEHTML_EXPORT
const char * mimeType
const char * extension
#define TRACE_OBJ
Definition tracer.h:34