src/gui/text/qtextcontrol_p.h
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QTEXTCONTROL_P_H
       
    43 #define QTEXTCONTROL_P_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists purely as an
       
    50 // implementation detail.  This header file may change from version to
       
    51 // version without notice, or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 
       
    56 #include <QtGui/qtextdocument.h>
       
    57 #include <QtGui/qtextoption.h>
       
    58 #include <QtGui/qtextcursor.h>
       
    59 #include <QtGui/qtextformat.h>
       
    60 #include <QtGui/qtextedit.h>
       
    61 #include <QtGui/qmenu.h>
       
    62 #include <QtCore/qrect.h>
       
    63 #include <QtGui/qabstracttextdocumentlayout.h>
       
    64 #include <QtGui/qtextdocumentfragment.h>
       
    65 
       
    66 #ifdef QT3_SUPPORT
       
    67 #include <QtGui/qtextobject.h>
       
    68 #include <QtGui/qtextlayout.h>
       
    69 #endif
       
    70 
       
    71 QT_BEGIN_HEADER
       
    72 
       
    73 QT_BEGIN_NAMESPACE
       
    74 
       
    75 QT_MODULE(Gui)
       
    76 
       
    77 class QStyleSheet;
       
    78 class QTextDocument;
       
    79 class QMenu;
       
    80 class QTextControlPrivate;
       
    81 class QMimeData;
       
    82 class QAbstractScrollArea;
       
    83 class QEvent;
       
    84 class QTimerEvent;
       
    85 
       
    86 class Q_GUI_EXPORT QTextControl : public QObject
       
    87 {
       
    88     Q_OBJECT
       
    89     Q_DECLARE_PRIVATE(QTextControl)
       
    90 #ifndef QT_NO_TEXTHTMLPARSER
       
    91     Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
       
    92 #endif
       
    93     Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
       
    94     Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText)
       
    95     Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
       
    96     Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
       
    97     Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
       
    98 public:
       
    99     explicit QTextControl(QObject *parent = 0);
       
   100     explicit QTextControl(const QString &text, QObject *parent = 0);
       
   101     explicit QTextControl(QTextDocument *doc, QObject *parent = 0);
       
   102     virtual ~QTextControl();
       
   103 
       
   104     void setDocument(QTextDocument *document);
       
   105     QTextDocument *document() const;
       
   106 
       
   107     void setTextCursor(const QTextCursor &cursor);
       
   108     QTextCursor textCursor() const;
       
   109 
       
   110     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
       
   111     Qt::TextInteractionFlags textInteractionFlags() const;
       
   112 
       
   113     void mergeCurrentCharFormat(const QTextCharFormat &modifier);
       
   114 
       
   115     void setCurrentCharFormat(const QTextCharFormat &format);
       
   116     QTextCharFormat currentCharFormat() const;
       
   117 
       
   118     bool find(const QString &exp, QTextDocument::FindFlags options = 0);
       
   119 
       
   120     inline QString toPlainText() const
       
   121     { return document()->toPlainText(); }
       
   122 #ifndef QT_NO_TEXTHTMLPARSER
       
   123     inline QString toHtml() const
       
   124     { return document()->toHtml(); }
       
   125 #endif
       
   126 
       
   127     virtual void ensureCursorVisible();
       
   128 
       
   129     virtual QVariant loadResource(int type, const QUrl &name);
       
   130 #ifndef QT_NO_CONTEXTMENU
       
   131     QMenu *createStandardContextMenu(const QPointF &pos, QWidget *parent);
       
   132 #endif
       
   133 
       
   134     QTextCursor cursorForPosition(const QPointF &pos) const;
       
   135     QRectF cursorRect(const QTextCursor &cursor) const;
       
   136     QRectF cursorRect() const;
       
   137     QRectF selectionRect(const QTextCursor &cursor) const;
       
   138     QRectF selectionRect() const;
       
   139 
       
   140     QString anchorAt(const QPointF &pos) const;
       
   141     QPointF anchorPosition(const QString &name) const;
       
   142 
       
   143     QString anchorAtCursor() const;
       
   144 
       
   145     bool overwriteMode() const;
       
   146     void setOverwriteMode(bool overwrite);
       
   147 
       
   148     int cursorWidth() const;
       
   149     void setCursorWidth(int width);
       
   150 
       
   151     bool acceptRichText() const;
       
   152     void setAcceptRichText(bool accept);
       
   153 
       
   154 #ifndef QT_NO_TEXTEDIT
       
   155     void setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections);
       
   156     QList<QTextEdit::ExtraSelection> extraSelections() const;
       
   157 #endif
       
   158 
       
   159     void setTextWidth(qreal width);
       
   160     qreal textWidth() const;
       
   161     QSizeF size() const;
       
   162 
       
   163     void setOpenExternalLinks(bool open);
       
   164     bool openExternalLinks() const;
       
   165 
       
   166     void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
       
   167 
       
   168     bool canPaste() const;
       
   169 
       
   170     void setCursorIsFocusIndicator(bool b);
       
   171     bool cursorIsFocusIndicator() const;
       
   172 
       
   173 #ifndef QT_NO_PRINTER
       
   174     void print(QPrinter *printer) const;
       
   175 #endif
       
   176 
       
   177     virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const;
       
   178     virtual QRectF blockBoundingRect(const QTextBlock &block) const;
       
   179     QAbstractTextDocumentLayout::PaintContext getPaintContext(QWidget *widget) const;
       
   180 
       
   181 
       
   182 
       
   183 public Q_SLOTS:
       
   184     void setPlainText(const QString &text);
       
   185     void setHtml(const QString &text);
       
   186 
       
   187 #ifndef QT_NO_CLIPBOARD
       
   188     void cut();
       
   189     void copy();
       
   190     void paste();
       
   191 #endif
       
   192 
       
   193     void undo();
       
   194     void redo();
       
   195 
       
   196     void clear();
       
   197     void selectAll();
       
   198 
       
   199     void insertPlainText(const QString &text);
       
   200 #ifndef QT_NO_TEXTHTMLPARSER
       
   201     void insertHtml(const QString &text);
       
   202 #endif
       
   203 
       
   204     void append(const QString &text);
       
   205     void appendHtml(const QString &html);
       
   206     void appendPlainText(const QString &text);
       
   207 
       
   208     void adjustSize();
       
   209 
       
   210 Q_SIGNALS:
       
   211     void textChanged();
       
   212     void undoAvailable(bool b);
       
   213     void redoAvailable(bool b);
       
   214     void currentCharFormatChanged(const QTextCharFormat &format);
       
   215     void copyAvailable(bool b);
       
   216     void selectionChanged();
       
   217     void cursorPositionChanged();
       
   218 
       
   219     // control signals
       
   220     void updateRequest(const QRectF &rect = QRectF());
       
   221     void documentSizeChanged(const QSizeF &);
       
   222     void blockCountChanged(int newBlockCount);
       
   223     void visibilityRequest(const QRectF &rect);
       
   224     void microFocusChanged();
       
   225     void linkActivated(const QString &link);
       
   226     void linkHovered(const QString &);
       
   227     void modificationChanged(bool m);
       
   228 
       
   229 public:
       
   230     // control properties
       
   231     QPalette palette() const;
       
   232     void setPalette(const QPalette &pal);
       
   233 
       
   234     virtual void processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget = 0);
       
   235     void processEvent(QEvent *e, const QPointF &coordinateOffset = QPointF(), QWidget *contextWidget = 0);
       
   236 
       
   237     // control methods
       
   238     void drawContents(QPainter *painter, const QRectF &rect = QRectF(), QWidget *widget = 0);
       
   239 
       
   240     void setFocus(bool focus, Qt::FocusReason = Qt::OtherFocusReason);
       
   241 
       
   242     virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
       
   243 
       
   244     virtual QMimeData *createMimeDataFromSelection() const;
       
   245     virtual bool canInsertFromMimeData(const QMimeData *source) const;
       
   246     virtual void insertFromMimeData(const QMimeData *source);
       
   247 
       
   248     bool setFocusToAnchor(const QTextCursor &newCursor);
       
   249     bool setFocusToNextOrPreviousAnchor(bool next);
       
   250     bool findNextPrevAnchor(const QTextCursor& from, bool next, QTextCursor& newAnchor);
       
   251 
       
   252 protected:
       
   253     virtual void timerEvent(QTimerEvent *e);
       
   254 
       
   255     virtual bool event(QEvent *e);
       
   256 
       
   257 private:
       
   258     Q_DISABLE_COPY(QTextControl)
       
   259     Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentCharFormatAndSelection())
       
   260     Q_PRIVATE_SLOT(d_func(), void _q_emitCursorPosChanged(const QTextCursor &))
       
   261     Q_PRIVATE_SLOT(d_func(), void _q_deleteSelected())
       
   262     Q_PRIVATE_SLOT(d_func(), void _q_copyLink())
       
   263     Q_PRIVATE_SLOT(d_func(), void _q_updateBlock(const QTextBlock &))
       
   264     Q_PRIVATE_SLOT(d_func(), void _q_documentLayoutChanged())
       
   265 };
       
   266 
       
   267 
       
   268 #ifndef QT_NO_CONTEXTMENU
       
   269 class QUnicodeControlCharacterMenu : public QMenu
       
   270 {
       
   271     Q_OBJECT
       
   272 public:
       
   273     QUnicodeControlCharacterMenu(QObject *editWidget, QWidget *parent);
       
   274 
       
   275 private Q_SLOTS:
       
   276     void menuActionTriggered();
       
   277 
       
   278 private:
       
   279     QObject *editWidget;
       
   280 };
       
   281 #endif // QT_NO_CONTEXTMENU
       
   282 
       
   283 
       
   284 // also used by QLabel
       
   285 class QTextEditMimeData : public QMimeData
       
   286 {
       
   287 public:
       
   288     inline QTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {}
       
   289 
       
   290     virtual QStringList formats() const;
       
   291 protected:
       
   292     virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
       
   293 private:
       
   294     void setup() const;
       
   295 
       
   296     mutable QTextDocumentFragment fragment;
       
   297 };
       
   298 
       
   299 QT_END_NAMESPACE
       
   300 
       
   301 QT_END_HEADER
       
   302 
       
   303 #endif // QTEXTCONTROL_H