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
6#include "qlitehtml_global.h"
7
8#include <QAbstractScrollArea>
9#include <QTextDocument>
10
11QT_FORWARD_DECLARE_CLASS(QPrinter)
12
13#include <functional>
14
15class QLiteHtmlWidgetPrivate;
16
17class QLITEHTML_EXPORT QLiteHtmlWidget : public QAbstractScrollArea
18{
19 Q_OBJECT
20public:
21 explicit QLiteHtmlWidget(QWidget *parent = nullptr);
22 ~QLiteHtmlWidget() override;
23
24 // declaring the getters Q_INVOKABLE to make them Squish-testable
25 void setUrl(const QUrl &url);
26 Q_INVOKABLE QUrl url() const;
27 void setHtml(const QString &content);
28 Q_INVOKABLE QString html() const;
29 Q_INVOKABLE QString title() const;
30
31 void setZoomFactor(qreal scale);
32 qreal zoomFactor() const;
33
34 bool findText(const QString &text,
35 QTextDocument::FindFlags flags,
36 bool incremental,
37 bool *wrapped = nullptr);
38
39 void setDefaultFont(const QFont &font);
40 QFont defaultFont() const;
41 void setAntialias(bool on);
42
43 void scrollToAnchor(const QString &name);
44
45 using ResourceHandler = std::function<QByteArray(QUrl)>;
46 void setResourceHandler(const ResourceHandler &handler);
47
48 // declaring this Q_INVOKABLE to make it Squish-testable
49 Q_INVOKABLE QString selectedText() const;
50
51 void print(QPrinter *printer);
52
53signals:
54 void linkClicked(const QUrl &url);
55 void linkHighlighted(const QUrl &url);
56 void copyAvailable(bool available);
57 void contextMenuRequested(const QPoint &pos, const QUrl &url);
58
59protected:
60 void paintEvent(QPaintEvent *event) override;
61 void resizeEvent(QResizeEvent *event) override;
62 void mouseMoveEvent(QMouseEvent *event) override;
63 void mousePressEvent(QMouseEvent *event) override;
64 void mouseReleaseEvent(QMouseEvent *event) override;
65 void mouseDoubleClickEvent(QMouseEvent *event) override;
66 void leaveEvent(QEvent *event) override;
67 void contextMenuEvent(QContextMenuEvent *event) override;
68 void keyPressEvent(QKeyEvent *event) override;
69
70private:
71 void updateHightlightedLink();
72 void setHightlightedLink(const QUrl &url);
73 void withFixedTextPosition(const std::function<void()> &action);
74 void render();
75 QPoint scrollPosition() const;
76 void htmlPos(const QPoint &pos, QPoint *viewportPos, QPoint *htmlPos) const;
77 QPoint toVirtual(const QPoint &p) const;
78 QSize toVirtual(const QSize &s) const;
79 QRect toVirtual(const QRect &r) const;
80 QRect fromVirtual(const QRect &r) const;
81
82 QLiteHtmlWidgetPrivate *d;
83};
84

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qttools/src/assistant/qlitehtml/src/qlitehtmlwidget.h