aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/help/litehtmlhelpviewer.h
blob: 3f8b231edaeb1d13d291ad249d789be6a565fb59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#pragma once

#include "helpviewer.h"
#include "openpagesmanager.h"

#include <utils/optional.h>

#include <qlitehtmlwidget.h>

#include <QTextBrowser>

namespace Help {
namespace Internal {

class LiteHtmlHelpViewer : public HelpViewer
{
    Q_OBJECT

public:
    explicit LiteHtmlHelpViewer(QWidget *parent = nullptr);
    ~LiteHtmlHelpViewer() override;

    void setViewerFont(const QFont &font) override;

    void setScale(qreal scale) override;

    QString title() const override;

    QUrl source() const override;
    void setSource(const QUrl &url) override;

    void setHtml(const QString &html) override;

    QString selectedText() const override;
    bool isForwardAvailable() const override;
    bool isBackwardAvailable() const override;
    void addBackHistoryItems(QMenu *backMenu) override;
    void addForwardHistoryItems(QMenu *forwardMenu) override;

    bool findText(const QString &text, Core::FindFlags flags,
                  bool incremental, bool fromSearch, bool *wrapped = nullptr) override;

    void copy() override;
    void stop() override;
    void forward() override;
    void backward() override;
    void print(QPrinter *printer) override;

    bool eventFilter(QObject *src, QEvent *e) override;

private:
    void goForward(int count);
    void goBackward(int count);
    void setSourceInternal(const QUrl &url, Utils::optional<int> vscroll = Utils::nullopt);
    void showContextMenu(const QPoint &pos, const QUrl &url);

    struct HistoryItem
    {
        QUrl url;
        QString title;
        int vscroll;
    };
    HistoryItem currentHistoryItem() const;

    QLiteHtmlWidget *m_viewer;
    std::vector<HistoryItem> m_backItems;
    std::vector<HistoryItem> m_forwardItems;
};

}   // namespace Internal
}   // namespace Help