| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the Qt3Support module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "q3textbrowser.h"
|
|---|
| 43 | #ifndef QT_NO_TEXTBROWSER
|
|---|
| 44 | #include <private/q3richtext_p.h>
|
|---|
| 45 |
|
|---|
| 46 | #include "qevent.h"
|
|---|
| 47 | #include "qdesktopwidget.h"
|
|---|
| 48 | #include "qapplication.h"
|
|---|
| 49 | #include "qlayout.h"
|
|---|
| 50 | #include "qpainter.h"
|
|---|
| 51 | #include "qstack.h"
|
|---|
| 52 | #include "stdio.h"
|
|---|
| 53 | #include "qfile.h"
|
|---|
| 54 | #include "qtextstream.h"
|
|---|
| 55 | #include "qbitmap.h"
|
|---|
| 56 | #include "qtimer.h"
|
|---|
| 57 | #include "qimage.h"
|
|---|
| 58 | #include "q3simplerichtext.h"
|
|---|
| 59 | #include "q3dragobject.h"
|
|---|
| 60 | #include "qurl.h"
|
|---|
| 61 | #include "qcursor.h"
|
|---|
| 62 |
|
|---|
| 63 | QT_BEGIN_NAMESPACE
|
|---|
| 64 |
|
|---|
| 65 | /*!
|
|---|
| 66 | \class Q3TextBrowser
|
|---|
| 67 | \brief The Q3TextBrowser class provides a rich text browser with hypertext navigation.
|
|---|
| 68 |
|
|---|
| 69 | \compat
|
|---|
| 70 |
|
|---|
| 71 | This class extends Q3TextEdit (in read-only mode), adding some
|
|---|
| 72 | navigation functionality so that users can follow links in
|
|---|
| 73 | hypertext documents. The contents of Q3TextEdit is set with
|
|---|
| 74 | setText(), but Q3TextBrowser has an additional function,
|
|---|
| 75 | setSource(), which makes it possible to set the text to a named
|
|---|
| 76 | document. The name is looked up in the text view's mime source
|
|---|
| 77 | factory. If a document name ends with an anchor (for example, "\c
|
|---|
| 78 | #anchor"), the text browser automatically scrolls to that position
|
|---|
| 79 | (using scrollToAnchor()). When the user clicks on a hyperlink, the
|
|---|
| 80 | browser will call setSource() itself, with the link's \c href
|
|---|
| 81 | value as argument. You can track the current source by connetion
|
|---|
| 82 | to the sourceChanged() signal.
|
|---|
| 83 |
|
|---|
| 84 | Q3TextBrowser provides backward() and forward() slots which you can
|
|---|
| 85 | use to implement Back and Forward buttons. The home() slot sets
|
|---|
| 86 | the text to the very first document displayed. The linkClicked()
|
|---|
| 87 | signal is emitted when the user clicks a link.
|
|---|
| 88 |
|
|---|
| 89 | By using Q3TextEdit::setMimeSourceFactory() you can provide your
|
|---|
| 90 | own subclass of Q3MimeSourceFactory. This makes it possible to
|
|---|
| 91 | access data from anywhere, for example from a network or from a
|
|---|
| 92 | database. See Q3MimeSourceFactory::data() for details.
|
|---|
| 93 |
|
|---|
| 94 | If you intend using the mime factory to read the data directly
|
|---|
| 95 | from the file system, you may have to specify the encoding for the
|
|---|
| 96 | file extension you are using. For example:
|
|---|
| 97 | \snippet doc/src/snippets/code/src_qt3support_text_q3textbrowser.cpp 0
|
|---|
| 98 | This is to ensure that the factory is able to resolve the document
|
|---|
| 99 | names.
|
|---|
| 100 |
|
|---|
| 101 | Q3TextBrowser interprets the tags it processes in accordance with
|
|---|
| 102 | the default style sheet. Change the style sheet with
|
|---|
| 103 | \l{setStyleSheet()}; see QStyleSheet for details.
|
|---|
| 104 |
|
|---|
| 105 | If you want to provide your users with editable rich text use
|
|---|
| 106 | Q3TextEdit. If you want a text browser without hypertext navigation
|
|---|
| 107 | use Q3TextEdit, and use Q3TextEdit::setReadOnly() to disable
|
|---|
| 108 | editing. If you just need to display a small piece of rich text
|
|---|
| 109 | use QSimpleRichText or QLabel.
|
|---|
| 110 | */
|
|---|
| 111 |
|
|---|
| 112 | class Q3TextBrowserData
|
|---|
| 113 | {
|
|---|
| 114 | public:
|
|---|
| 115 | Q3TextBrowserData():textOrSourceChanged(false) {}
|
|---|
| 116 |
|
|---|
|
|---|