summaryrefslogtreecommitdiff
path: root/src/frontend/htmldialogs/bttabhtmldialog.h
blob: 3ccdc0fefc22890ace2af736a9be6ac350d15e48 (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
75
76
77
78
79
80
81
82
83
84
85
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2009 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#ifndef BTTABDIALOG_H
#define BTTABDIALOG_H

#include <QDialog>
#include <QString>
#include <QUrl>
#include <QWebView>

class QTabWidget;
class QMenu;

// This class creates a dialog with zero or more tabs. For zero tabs it is
// just a single QWebView inside the dialog. For 1 or more tabs, each tab
// contains a separate QWebView. Each QWebView can have either plain text or
// html text. The class will automatically delete itself when closed.
// The class can either be directly called or subclassed. The dialog is not modal.

// Typical direct usage:
//
//                        Zero tabs
// BtTabHtmlDialog* dlg = new BtTabHtmlDialog("My Title", 0, parent);
// dlg->setHtml(htmlText);
// dlg->show();
//
//     or
//
//                        Two tabs
// BtTabHtmlDialog* dlg = new BtTabHtmlDialog("My Title", 2, parent);
// dlg->selectTab(0);
// dlg->setTabText(nameOfTab0);
// dlg->setHtml(htmlText0);
// dlg->selectTab(1);
// dlg->setTabText(nameOfTab1);
// dlg->setHtml(htmlText1);
// dlg->show();


class BtTabHtmlDialog : public QDialog {
        Q_OBJECT
    public:
        BtTabHtmlDialog(const QString& title, int numberTabs, QWidget *parent = 0, Qt::WindowFlags wflags = Qt::Dialog);
        ~BtTabHtmlDialog();
        void selectTab(int tab);
        void setTabText(const QString& tabName);

// See QWebView::setHtml()
        void setHtml(const QString& html, const QUrl& baseUrl = QUrl());

// See QWebView::setUrl()
        void setUrl(const QUrl& url);

    private slots:
        void linkClicked(const QUrl url);

    private:
        void init_connections(QWebView* webView);
        QWebView* webView();

        QWebView*   m_webView;
        QTabWidget* m_tabWidget;
        int m_tabs;
};


class BtWebView : public QWebView {
    public:
        BtWebView(QWidget* parent = 0);

    protected:
        void contextMenuEvent(QContextMenuEvent* event);

    private:
        QMenu* m_popup;
};

#endif