src/declarative/graphicsitems/qdeclarativetext_p.h
changeset 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 QtDeclarative 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 QDECLARATIVETEXT_H
       
    43 #define QDECLARATIVETEXT_H
       
    44 
       
    45 #include <QtGui/qtextoption.h>
       
    46 #include "qdeclarativeitem.h"
       
    47 
       
    48 QT_BEGIN_HEADER
       
    49 
       
    50 QT_BEGIN_NAMESPACE
       
    51 
       
    52 QT_MODULE(Declarative)
       
    53 class QDeclarativeTextPrivate;
       
    54 class Q_DECLARATIVE_EXPORT QDeclarativeText : public QDeclarativeItem
       
    55 {
       
    56     Q_OBJECT
       
    57     Q_ENUMS(HAlignment)
       
    58     Q_ENUMS(VAlignment)
       
    59     Q_ENUMS(TextStyle)
       
    60     Q_ENUMS(TextFormat)
       
    61     Q_ENUMS(TextElideMode)
       
    62     Q_ENUMS(WrapMode)
       
    63 
       
    64     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
       
    65     Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
       
    66     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
       
    67     Q_PROPERTY(TextStyle style READ style WRITE setStyle NOTIFY styleChanged)
       
    68     Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor NOTIFY styleColorChanged)
       
    69     Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign NOTIFY horizontalAlignmentChanged)
       
    70     Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
       
    71     Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
       
    72     Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
       
    73     Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged) //### elideMode?
       
    74 
       
    75 public:
       
    76     QDeclarativeText(QDeclarativeItem *parent=0);
       
    77     ~QDeclarativeText();
       
    78 
       
    79     enum HAlignment { AlignLeft = Qt::AlignLeft,
       
    80                        AlignRight = Qt::AlignRight,
       
    81                        AlignHCenter = Qt::AlignHCenter };
       
    82     enum VAlignment { AlignTop = Qt::AlignTop,
       
    83                        AlignBottom = Qt::AlignBottom,
       
    84                        AlignVCenter = Qt::AlignVCenter };
       
    85     enum TextStyle { Normal,
       
    86                       Outline,
       
    87                       Raised,
       
    88                       Sunken };
       
    89     enum TextFormat { PlainText = Qt::PlainText,
       
    90                        RichText = Qt::RichText,
       
    91                        AutoText = Qt::AutoText,
       
    92                        StyledText = 4 };
       
    93     enum TextElideMode { ElideLeft = Qt::ElideLeft,
       
    94                           ElideRight = Qt::ElideRight,
       
    95                           ElideMiddle = Qt::ElideMiddle,
       
    96                           ElideNone = Qt::ElideNone };
       
    97 
       
    98     enum WrapMode { NoWrap = QTextOption::NoWrap,
       
    99                     WordWrap = QTextOption::WordWrap,
       
   100                     WrapAnywhere = QTextOption::WrapAnywhere,
       
   101                     WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere
       
   102                   };
       
   103 
       
   104     QString text() const;
       
   105     void setText(const QString &);
       
   106 
       
   107     QFont font() const;
       
   108     void setFont(const QFont &font);
       
   109 
       
   110     QColor color() const;
       
   111     void setColor(const QColor &c);
       
   112 
       
   113     TextStyle style() const;
       
   114     void setStyle(TextStyle style);
       
   115 
       
   116     QColor styleColor() const;
       
   117     void setStyleColor(const QColor &c);
       
   118 
       
   119     HAlignment hAlign() const;
       
   120     void setHAlign(HAlignment align);
       
   121 
       
   122     VAlignment vAlign() const;
       
   123     void setVAlign(VAlignment align);
       
   124 
       
   125     WrapMode wrapMode() const;
       
   126     void setWrapMode(WrapMode w);
       
   127 
       
   128     TextFormat textFormat() const;
       
   129     void setTextFormat(TextFormat format);
       
   130 
       
   131     TextElideMode elideMode() const;
       
   132     void setElideMode(TextElideMode);
       
   133 
       
   134     void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
       
   135 
       
   136     virtual void componentComplete();
       
   137 
       
   138     int resourcesLoading() const; // mainly for testing
       
   139 
       
   140 Q_SIGNALS:
       
   141     void textChanged(const QString &text);
       
   142     void linkActivated(const QString &link);
       
   143     void fontChanged(const QFont &font);
       
   144     void colorChanged(const QColor &color);
       
   145     void styleChanged(TextStyle style);
       
   146     void styleColorChanged(const QColor &color);
       
   147     void horizontalAlignmentChanged(HAlignment alignment);
       
   148     void verticalAlignmentChanged(VAlignment alignment);
       
   149     void wrapModeChanged();
       
   150     void textFormatChanged(TextFormat textFormat);
       
   151     void elideModeChanged(TextElideMode mode);
       
   152 
       
   153 protected:
       
   154     void mousePressEvent(QGraphicsSceneMouseEvent *event);
       
   155     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
       
   156     virtual void geometryChanged(const QRectF &newGeometry,
       
   157                                  const QRectF &oldGeometry);
       
   158 
       
   159 private:
       
   160     Q_DISABLE_COPY(QDeclarativeText)
       
   161     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeText)
       
   162 
       
   163     friend class QTextDocumentWithImageResources;
       
   164     void reloadWithResources();
       
   165 };
       
   166 
       
   167 QT_END_NAMESPACE
       
   168 
       
   169 QML_DECLARE_TYPE(QDeclarativeText)
       
   170 
       
   171 QT_END_HEADER
       
   172 
       
   173 #endif