Logo Search packages:      
Sourcecode: qt4-x11 version File versions

qtextformat.h

/****************************************************************************
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.  Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://www.trolltech.com/products/qt/licensing.html or contact the
** sales department at sales@trolltech.com.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#ifndef QTEXTFORMAT_H
#define QTEXTFORMAT_H

#include <QtGui/qcolor.h>
#include <QtGui/qfont.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qvector.h>
#include <QtCore/qvariant.h>
#include <QtGui/qpen.h>
#include <QtGui/qbrush.h>

QT_BEGIN_HEADER

QT_MODULE(Gui)

class QString;
class QVariant;
class QFont;

class QTextFormatCollection;
class QTextFormatPrivate;
class QTextBlockFormat;
class QTextCharFormat;
class QTextListFormat;
class QTextTableFormat;
class QTextFrameFormat;
class QTextImageFormat;
class QTextFormat;
class QTextObject;
class QTextCursor;
class QTextDocument;
class QTextLength;

Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextLength &);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &);

00060 class Q_GUI_EXPORT QTextLength
{
public:
00063     enum Type { VariableLength = 0, FixedLength, PercentageLength };

00065     inline QTextLength() : lengthType(VariableLength), fixedValueOrPercentage(0) {}

    inline explicit QTextLength(Type type, qreal value);

00069     inline Type type() const { return lengthType; }
00070     inline qreal value(qreal maximumLength) const
    {
        switch (lengthType) {
            case FixedLength: return fixedValueOrPercentage;
            case VariableLength: return maximumLength;
            case PercentageLength: return fixedValueOrPercentage * maximumLength / qreal(100);
        }
        return -1;
    }

00080     inline qreal rawValue() const { return fixedValueOrPercentage; }

00082     inline bool operator==(const QTextLength &other) const
    { return lengthType == other.lengthType
             && qFuzzyCompare(fixedValueOrPercentage, other.fixedValueOrPercentage); }
00085     inline bool operator!=(const QTextLength &other) const
    { return lengthType != other.lengthType
             || !qFuzzyCompare(fixedValueOrPercentage, other.fixedValueOrPercentage); }
    operator QVariant() const;

private:
    Type lengthType;
    qreal fixedValueOrPercentage;
    friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextLength &);
    friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &);
};

00097 inline QTextLength::QTextLength(Type atype, qreal avalue)
    : lengthType(atype), fixedValueOrPercentage(avalue) {}

Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &);

00103 class Q_GUI_EXPORT QTextFormat
{
    Q_GADGET
    Q_ENUMS(FormatType Property ObjectTypes)
public:
00108     enum FormatType {
        InvalidFormat = -1,
        BlockFormat = 1,
        CharFormat = 2,
        ListFormat = 3,
        TableFormat = 4,
        FrameFormat = 5,

        UserFormat = 100
    };

00119     enum Property {
        ObjectIndex = 0x0,

        // paragraph and char
        CssFloat = 0x0800,
        LayoutDirection = 0x0801,

        OutlinePen = 0x810,
        BackgroundBrush = 0x820,
        ForegroundBrush = 0x821,

        // paragraph
        BlockAlignment = 0x1010,
        BlockTopMargin = 0x1030,
        BlockBottomMargin = 0x1031,
        BlockLeftMargin = 0x1032,
        BlockRightMargin = 0x1033,
        TextIndent = 0x1034,
        BlockIndent = 0x1040,
        BlockNonBreakableLines = 0x1050,
        BlockTrailingHorizontalRulerWidth = 0x1060,

        // character properties
        FontFamily = 0x2000,
        FontPointSize = 0x2001,
        FontSizeAdjustment = 0x2002,
        FontSizeIncrement = FontSizeAdjustment, // old name, compat
        FontWeight = 0x2003,
        FontItalic = 0x2004,
        FontUnderline = 0x2005, // deprecated, use TextUnderlineStyle instead
        FontOverline = 0x2006,
        FontStrikeOut = 0x2007,
        FontFixedPitch = 0x2008,
        FontPixelSize = 0x2009,

        TextUnderlineColor = 0x2010,
        TextVerticalAlignment = 0x2021,
        TextOutline = 0x2022,
        TextUnderlineStyle = 0x2023,

        IsAnchor = 0x2030,
        AnchorHref = 0x2031,
        AnchorName = 0x2032,

        ObjectType = 0x2f00,

        // list properties
        ListStyle = 0x3000,
        ListIndent = 0x3001,

        // table and frame properties
        FrameBorder = 0x4000,
        FrameMargin = 0x4001,
        FramePadding = 0x4002,
        FrameWidth = 0x4003,
        FrameHeight = 0x4004,
        TableColumns = 0x4100,
        TableColumnWidthConstraints = 0x4101,
        TableCellSpacing = 0x4102,
        TableCellPadding = 0x4103,
        TableHeaderRowCount = 0x4104,

        // table cell properties
        TableCellRowSpan = 0x4810,
        TableCellColumnSpan = 0x4811,

        // image properties
        ImageName = 0x5000,
        ImageWidth = 0x5010,
        ImageHeight = 0x5011,

        // selection properties
        FullWidthSelection = 0x06000,

        // page break properties
        PageBreakPolicy = 0x7000,

        // --
        UserProperty = 0x100000
    };

00200     enum ObjectTypes {
        NoObject,
        ImageObject,
        TableObject,

        UserObject = 0x1000
    };

00208     enum PageBreakFlag {
        PageBreak_Auto = 0,
        PageBreak_AlwaysBefore = 0x001,
        PageBreak_AlwaysAfter  = 0x010
        // PageBreak_AlwaysInside = 0x100
    };
    Q_DECLARE_FLAGS(PageBreakFlags, PageBreakFlag)

    QTextFormat();

    explicit QTextFormat(int type);

    QTextFormat(const QTextFormat &rhs);
    QTextFormat &operator=(const QTextFormat &rhs);
    ~QTextFormat();

    void merge(const QTextFormat &other);

00226     inline bool isValid() const { return type() != InvalidFormat; }

    int type() const;

    int objectIndex() const;
    void setObjectIndex(int object);

    QVariant property(int propertyId) const;
    void setProperty(int propertyId, const QVariant &value);
    void clearProperty(int propertyId);
    bool hasProperty(int propertyId) const;

    bool boolProperty(int propertyId) const;
    int intProperty(int propertyId) const;
    qreal doubleProperty(int propertyId) const;
    QString stringProperty(int propertyId) const;
    QColor colorProperty(int propertyId) const;
    QPen penProperty(int propertyId) const;
    QBrush brushProperty(int propertyId) const;
    QTextLength lengthProperty(int propertyId) const;
    QVector<QTextLength> lengthVectorProperty(int propertyId) const;

    void setProperty(int propertyId, const QVector<QTextLength> &lengths);


    QMap<int, QVariant> properties() const;

    inline void setObjectType(int type);
00254     inline int objectType() const
    { return intProperty(ObjectType); }

00257     inline bool isCharFormat() const { return type() == CharFormat; }
00258     inline bool isBlockFormat() const { return type() == BlockFormat; }
00259     inline bool isListFormat() const { return type() == ListFormat; }
00260     inline bool isFrameFormat() const { return type() == FrameFormat; }
00261     inline bool isImageFormat() const { return type() == CharFormat && objectType() == ImageObject; }
00262     inline bool isTableFormat() const { return type() == FrameFormat && objectType() == TableObject; }

    QTextBlockFormat toBlockFormat() const;
    QTextCharFormat toCharFormat() const;
    QTextListFormat toListFormat() const;
    QTextTableFormat toTableFormat() const;
    QTextFrameFormat toFrameFormat() const;
    QTextImageFormat toImageFormat() const;

    bool operator==(const QTextFormat &rhs) const;
00272     inline bool operator!=(const QTextFormat &rhs) const { return !operator==(rhs); }
    operator QVariant() const;

00275     inline void setLayoutDirection(Qt::LayoutDirection direction)
        { setProperty(QTextFormat::LayoutDirection, direction); }
00277     inline Qt::LayoutDirection layoutDirection() const
        { return Qt::LayoutDirection(intProperty(QTextFormat::LayoutDirection)); }

00280     inline void setBackground(const QBrush &brush)
    { setProperty(BackgroundBrush, brush); }
00282     inline QBrush background() const
    { return brushProperty(BackgroundBrush); }
00284     inline void clearBackground()
    { clearProperty(BackgroundBrush); }

00287     inline void setForeground(const QBrush &brush)
    { setProperty(ForegroundBrush, brush); }
00289     inline QBrush foreground() const
    { return brushProperty(ForegroundBrush); }
00291     inline void clearForeground()
    { clearProperty(ForegroundBrush); }

private:
    QSharedDataPointer<QTextFormatPrivate> d;
    qint32 format_type;

    friend class QTextFormatCollection;
    friend class QTextCharFormat;
    friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &);
    friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &);
};

00304 inline void QTextFormat::setObjectType(int atype)
{ setProperty(ObjectType, atype); }

Q_DECLARE_OPERATORS_FOR_FLAGS(QTextFormat::PageBreakFlags)

00309 class Q_GUI_EXPORT QTextCharFormat : public QTextFormat
{
public:
00312     enum VerticalAlignment { AlignNormal = 0, AlignSuperScript, AlignSubScript };
00313     enum UnderlineStyle { // keep in sync with Qt::PenStyle!
        NoUnderline,
        SingleUnderline,
        DashUnderline,
        DotLine,
        DashDotLine,
        DashDotDotLine,
        WaveUnderline,
        SpellCheckUnderline
    };

    QTextCharFormat();

00326     bool isValid() const { return isCharFormat(); }
    void setFont(const QFont &font);
    QFont font() const;

00330     inline void setFontFamily(const QString &family)
    { setProperty(FontFamily, family); }
00332     inline QString fontFamily() const
    { return stringProperty(FontFamily); }

00335     inline void setFontPointSize(qreal size)
    { setProperty(FontPointSize, size); }
00337     inline qreal fontPointSize() const
    { return doubleProperty(FontPointSize); }

00340     inline void setFontWeight(int weight)
    { if (weight == QFont::Normal) weight = 0; setProperty(FontWeight, weight); }
00342     inline int fontWeight() const
    { int weight = intProperty(FontWeight); if (weight == 0) weight = QFont::Normal; return weight; }
00344     inline void setFontItalic(bool italic)
    { setProperty(FontItalic, italic); }
00346     inline bool fontItalic() const
    { return boolProperty(FontItalic); }

00349     inline void setFontUnderline(bool underline)
    { setProperty(TextUnderlineStyle, underline ? SingleUnderline : NoUnderline); }
    bool fontUnderline() const;

00353     inline void setFontOverline(bool overline)
    { setProperty(FontOverline, overline); }
00355     inline bool fontOverline() const
    { return boolProperty(FontOverline); }

00358     inline void setFontStrikeOut(bool strikeOut)
    { setProperty(FontStrikeOut, strikeOut); }
00360     inline bool fontStrikeOut() const
    { return boolProperty(FontStrikeOut); }

00363     inline void setUnderlineColor(const QColor &color)
    { setProperty(TextUnderlineColor, color); }
00365     inline QColor underlineColor() const
    { return colorProperty(TextUnderlineColor); }

00368     inline void setFontFixedPitch(bool fixedPitch)
    { setProperty(FontFixedPitch, fixedPitch); }
00370     inline bool fontFixedPitch() const
    { return boolProperty(FontFixedPitch); }

    void setUnderlineStyle(UnderlineStyle style);
00374     inline UnderlineStyle underlineStyle() const
    { return static_cast<UnderlineStyle>(intProperty(TextUnderlineStyle)); }

00377     inline void setVerticalAlignment(VerticalAlignment alignment)
    { setProperty(TextVerticalAlignment, alignment); }
00379     inline VerticalAlignment verticalAlignment() const
    { return static_cast<VerticalAlignment>(intProperty(TextVerticalAlignment)); }

00382     inline void setTextOutline(const QPen &pen)
    { setProperty(TextOutline, pen); }
00384     inline QPen textOutline() const
    { return penProperty(TextOutline); }

00387     inline void setAnchor(bool anchor)
    { setProperty(IsAnchor, anchor); }
00389     inline bool isAnchor() const
    { return boolProperty(IsAnchor); }

00392     inline void setAnchorHref(const QString &value)
    { setProperty(AnchorHref, value); }
00394     inline QString anchorHref() const
    { return stringProperty(AnchorHref); }

00397     inline void setAnchorName(const QString &name)
    { setProperty(AnchorName, name); }
00399     inline QString anchorName() const
    { return stringProperty(AnchorName); }

    inline void setTableCellRowSpan(int tableCellRowSpan);
00403     inline int tableCellRowSpan() const
    { int s = intProperty(TableCellRowSpan); if (s == 0) s = 1; return s; }
    inline void setTableCellColumnSpan(int tableCellColumnSpan);
00406     inline int tableCellColumnSpan() const
    { int s = intProperty(TableCellColumnSpan); if (s == 0) s = 1; return s; }
};

00410 inline void QTextCharFormat::setTableCellRowSpan(int atableCellRowSpan)
{
    if (atableCellRowSpan == 1)
      atableCellRowSpan = 0;
    setProperty(TableCellRowSpan, atableCellRowSpan);
}

00417 inline void QTextCharFormat::setTableCellColumnSpan(int atableCellColumnSpan)
{
    if (atableCellColumnSpan == 1)
      atableCellColumnSpan = 0;
    setProperty(TableCellColumnSpan, atableCellColumnSpan);
}

00424 class Q_GUI_EXPORT QTextBlockFormat : public QTextFormat
{
public:
    QTextBlockFormat();

00429     bool isValid() const { return isBlockFormat(); }

    inline void setAlignment(Qt::Alignment alignment);
00432     inline Qt::Alignment alignment() const
    { int a = intProperty(BlockAlignment); if (a == 0) a = Qt::AlignLeft; return QFlag(a); }

00435     inline void setTopMargin(qreal margin)
    { setProperty(BlockTopMargin, margin); }
00437     inline qreal topMargin() const
    { return doubleProperty(BlockTopMargin); }

00440     inline void setBottomMargin(qreal margin)
    { setProperty(BlockBottomMargin, margin); }
00442     inline qreal bottomMargin() const
    { return doubleProperty(BlockBottomMargin); }

00445     inline void setLeftMargin(qreal margin)
    { setProperty(BlockLeftMargin, margin); }
00447     inline qreal leftMargin() const
    { return doubleProperty(BlockLeftMargin); }

00450     inline void setRightMargin(qreal margin)
    { setProperty(BlockRightMargin, margin); }
00452     inline qreal rightMargin() const
    { return doubleProperty(BlockRightMargin); }

00455     inline void setTextIndent(qreal margin)
    { setProperty(TextIndent, margin); }
00457     inline qreal textIndent() const
    { return doubleProperty(TextIndent); }

    inline void setIndent(int indent);
00461     inline int indent() const
    { return intProperty(BlockIndent); }

00464     inline void setNonBreakableLines(bool b)
    { setProperty(BlockNonBreakableLines, b); }
00466     inline bool nonBreakableLines() const
    { return boolProperty(BlockNonBreakableLines); }

00469     inline void setPageBreakPolicy(PageBreakFlags flags)
    { setProperty(PageBreakPolicy, int(flags)); }
00471     inline PageBreakFlags pageBreakPolicy() const
    { return PageBreakFlags(intProperty(PageBreakPolicy)); }
};

00475 inline void QTextBlockFormat::setAlignment(Qt::Alignment aalignment)
{ setProperty(BlockAlignment, int(aalignment)); }

00478 inline void QTextBlockFormat::setIndent(int aindent)
{ setProperty(BlockIndent, aindent); }

00481 class Q_GUI_EXPORT QTextListFormat : public QTextFormat
{
public:
    QTextListFormat();

00486     bool isValid() const { return isListFormat(); }

00488     enum Style {
        ListDisc = -1,
        ListCircle = -2,
        ListSquare = -3,
        ListDecimal = -4,
        ListLowerAlpha = -5,
        ListUpperAlpha = -6,
        ListStyleUndefined = 0
    };

    inline void setStyle(Style style);
00499     inline Style style() const
    { return static_cast<Style>(intProperty(ListStyle)); }

    inline void setIndent(int indent);
00503     inline int indent() const
    { return intProperty(ListIndent); }

};

00508 inline void QTextListFormat::setStyle(Style astyle)
{ setProperty(ListStyle, astyle); }

00511 inline void QTextListFormat::setIndent(int aindent)
{ setProperty(ListIndent, aindent); }

00514 class Q_GUI_EXPORT QTextImageFormat : public QTextCharFormat
{
public:
    QTextImageFormat();

00519     bool isValid() const { return isImageFormat(); }

    inline void setName(const QString &name);
00522     inline QString name() const
    { return stringProperty(ImageName); }

    inline void setWidth(qreal width);
00526     inline qreal width() const
    { return doubleProperty(ImageWidth); }

    inline void setHeight(qreal height);
00530     inline qreal height() const
    { return doubleProperty(ImageHeight); }
};

00534 inline void QTextImageFormat::setName(const QString &aname)
{ setProperty(ImageName, aname); }

00537 inline void QTextImageFormat::setWidth(qreal awidth)
{ setProperty(ImageWidth, awidth); }

00540 inline void QTextImageFormat::setHeight(qreal aheight)
{ setProperty(ImageHeight, aheight); }

00543 class Q_GUI_EXPORT QTextFrameFormat : public QTextFormat
{
public:
    QTextFrameFormat();

00548     bool isValid() const { return isFrameFormat(); }

00550     enum Position {
        InFlow,
        FloatLeft,
        FloatRight
        // ######
//        Absolute
    };

00558     inline void setPosition(Position f)
    { setProperty(CssFloat, f); }
00560     inline Position position() const
    { return static_cast<Position>(intProperty(CssFloat)); }

    inline void setBorder(qreal border);
00564     inline qreal border() const
    { return doubleProperty(FrameBorder); }

    inline void setMargin(qreal margin);
00568     inline qreal margin() const
    { return doubleProperty(FrameMargin); }

    inline void setPadding(qreal padding);
00572     inline qreal padding() const
    { return doubleProperty(FramePadding); }

    inline void setWidth(qreal width);
00576     inline void setWidth(const QTextLength &length)
    { setProperty(FrameWidth, length); }
00578     inline QTextLength width() const
    { return lengthProperty(FrameWidth); }

    inline void setHeight(qreal height);
    inline void setHeight(const QTextLength &height);
00583     inline QTextLength height() const
    { return lengthProperty(FrameHeight); }

00586     inline void setPageBreakPolicy(PageBreakFlags flags)
    { setProperty(PageBreakPolicy, int(flags)); }
00588     inline PageBreakFlags pageBreakPolicy() const
    { return PageBreakFlags(intProperty(PageBreakPolicy)); }
};

00592 inline void QTextFrameFormat::setBorder(qreal aborder)
{ setProperty(FrameBorder, aborder); }

00595 inline void QTextFrameFormat::setMargin(qreal amargin)
{ setProperty(FrameMargin, amargin); }

00598 inline void QTextFrameFormat::setPadding(qreal apadding)
{ setProperty(FramePadding, apadding); }

00601 inline void QTextFrameFormat::setWidth(qreal awidth)
{ setProperty(FrameWidth, QTextLength(QTextLength::FixedLength, awidth)); }

00604 inline void QTextFrameFormat::setHeight(qreal aheight)
{ setProperty(FrameHeight, QTextLength(QTextLength::FixedLength, aheight)); }
00606 inline void QTextFrameFormat::setHeight(const QTextLength &aheight)
{ setProperty(FrameHeight, aheight); }

00609 class Q_GUI_EXPORT QTextTableFormat : public QTextFrameFormat
{
public:
    QTextTableFormat();

00614     inline bool isValid() const { return isTableFormat(); }

00616     inline int columns() const
    { int cols = intProperty(TableColumns); if (cols == 0) cols = 1; return cols; }
    inline void setColumns(int columns);

00620     inline void setColumnWidthConstraints(const QVector<QTextLength> &constraints)
    { setProperty(TableColumnWidthConstraints, constraints); }

00623     inline QVector<QTextLength> columnWidthConstraints() const
    { return lengthVectorProperty(TableColumnWidthConstraints); }

00626     inline void clearColumnWidthConstraints()
    { clearProperty(TableColumnWidthConstraints); }

00629     inline qreal cellSpacing() const
    { return doubleProperty(TableCellSpacing); }
00631     inline void setCellSpacing(qreal spacing)
    { setProperty(TableCellSpacing, spacing); }

00634     inline qreal cellPadding() const
    { return doubleProperty(TableCellPadding); }
    inline void setCellPadding(qreal padding);

    inline void setAlignment(Qt::Alignment alignment);
00639     inline Qt::Alignment alignment() const
    { return QFlag(intProperty(BlockAlignment)); }

00642     inline void setHeaderRowCount(int count)
    { setProperty(TableHeaderRowCount, count); }
00644     inline int headerRowCount() const
    { return intProperty(TableHeaderRowCount); }
};

00648 inline void QTextTableFormat::setColumns(int acolumns)
{
    if (acolumns == 1)
        acolumns = 0;
    setProperty(TableColumns, acolumns);
}

00655 inline void QTextTableFormat::setCellPadding(qreal apadding)
{ setProperty(TableCellPadding, apadding); }

00658 inline void QTextTableFormat::setAlignment(Qt::Alignment aalignment)
{ setProperty(BlockAlignment, int(aalignment)); }

QT_END_HEADER

#endif // QTEXTFORMAT_H

Generated by  Doxygen 1.6.0   Back to index