1 /*
2  *    Copyright 2012, 2013, 2014 Thomas Schöps
3  *    Copyright 2012-2015, 2017 Kai Pastor
4  *
5  *    This file is part of OpenOrienteering.
6  *
7  *    OpenOrienteering is free software: you can redistribute it and/or modify
8  *    it under the terms of the GNU General Public License as published by
9  *    the Free Software Foundation, either version 3 of the License, or
10  *    (at your option) any later version.
11  *
12  *    OpenOrienteering is distributed in the hope that it will be useful,
13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *    GNU General Public License for more details.
16  *
17  *    You should have received a copy of the GNU General Public License
18  *    along with OpenOrienteering.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef OPENORIENTEERING_TEXT_BROWSER_DIALOG_H
22 #define OPENORIENTEERING_TEXT_BROWSER_DIALOG_H
23 
24 #include <QDialog>
25 #include <QObject>
26 #include <QSize>
27 #include <QString>
28 
29 class QWidget;
30 
31 class QTextBrowser;
32 class QUrl;
33 
34 
35 namespace OpenOrienteering {
36 
37 /**
38  * @brief A dialog for basic browsing of HTML pages.
39  */
40 class TextBrowserDialog : public QDialog
41 {
42 Q_OBJECT
43 protected:
44 	explicit TextBrowserDialog(QWidget* parent = nullptr);
45 
46 public:
47 	/**
48 	 * @brief Construct a new dialog and loads the text from the initial_url.
49 	 */
50 	TextBrowserDialog(const QUrl& initial_url, QWidget* parent = nullptr);
51 
52 	/**
53 	 * @brief Construct a new dialog and sets the given text.
54 	 */
55 	TextBrowserDialog(const QString& text, QWidget* parent = nullptr);
56 
57 	~TextBrowserDialog() override;
58 
59 protected slots:
60 	/**
61 	 * @brief Sets custom HTML content when the URL identifies the first page.
62 	 */
63 	virtual void sourceChanged(const QUrl& url);
64 
65 	/**
66 	 * @brief Updates the window title from the current document title.
67 	 */
68 	virtual void updateWindowTitle();
69 
70 	/**
71 	 * @brief Displays a tooltip showing the link if is an external document.
72 	 */
73 	void highlighted(const QString& link);
74 
75 protected:
76 	/**
77 	 * @brief Returns a size hint based on the text browser's content.
78 	 */
79 	QSize sizeHint() const override;
80 
81 	/**
82 	 * @brief The TextBrowser is the main widget of this dialog.
83 	 */
84 	QTextBrowser* const text_browser;
85 };
86 
87 
88 }  // namespace OpenOrienteering
89 
90 #endif
91