/**************************************************************************** ** ** Copyright (C) 1992-2008 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 versions 2.0 or 3.0 as published by the Free Software ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3 ** included in the packaging of this file. Alternatively you may (at ** your option) use any later version of the GNU General Public ** License if such license has been publicly approved by Trolltech ASA ** (or its successors, if any) and the KDE Free Qt Foundation. In ** addition, as a special exception, Trolltech gives you certain ** additional rights. These rights are described in the Trolltech GPL ** Exception version 1.1, which can be found at ** http://www.trolltech.com/products/qt/gplexception/ and in the file ** GPL_EXCEPTION.txt in this package. ** ** Please review the following information to ensure GNU General ** Public Licensing requirements will be met: ** http://trolltech.com/products/qt/licenses/licensing/opensource/. If ** you are unsure which license is appropriate for your use, please ** review the following information: ** http://trolltech.com/products/qt/licenses/licensing/licensingoverview ** or contact the sales department at sales@trolltech.com. ** ** In addition, as a special exception, Trolltech, as the sole ** copyright holder for Qt Designer, grants users of the Qt/Eclipse ** Integration plug-in the right for the Qt/Eclipse Integration to ** link to functionality provided by Qt Designer and its related ** libraries. ** ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly ** granted herein. ** ** 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 &); 00080 class Q_GUI_EXPORT QTextLength { public: 00083 enum Type { VariableLength = 0, FixedLength, PercentageLength }; 00085 inline QTextLength() : lengthType(VariableLength), fixedValueOrPercentage(0) {} inline explicit QTextLength(Type type, qreal value); 00089 inline Type type() const { return lengthType; } 00090 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; } 00100 inline qreal rawValue() const { return fixedValueOrPercentage; } 00102 inline bool operator==(const QTextLength &other) const { return lengthType == other.lengthType && qFuzzyCompare(fixedValueOrPercentage, other.fixedValueOrPercentage); } 00105 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 &); }; 00117 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 &); 00123 class Q_GUI_EXPORT QTextFormat { Q_GADGET Q_ENUMS(FormatType Property ObjectTypes) public: 00128 enum FormatType { InvalidFormat = -1, BlockFormat = 1, CharFormat = 2, ListFormat = 3, TableFormat = 4, FrameFormat = 5, UserFormat = 100 }; 00139 enum Property { ObjectIndex = 0x0, // paragraph and char CssFloat = 0x0800, LayoutDirection = 0x0801, OutlinePen = 0x810, BackgroundBrush = 0x820, ForegroundBrush = 0x821, // Internal to qtextlayout.cpp: ObjectSelectionBrush = 0x822 // 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, TextToolTip = 0x2024, 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, FrameTopMargin = 0x4005, FrameBottomMargin = 0x4006, FrameLeftMargin = 0x4007, FrameRightMargin = 0x4008, FrameBorderBrush = 0x4009, FrameBorderStyle = 0x4010, 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 }; 00229 enum ObjectTypes { NoObject, ImageObject, TableObject, UserObject = 0x1000 }; 00237 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); 00255 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; int propertyCount() const; inline void setObjectType(int type); 00283 inline int objectType() const { return intProperty(ObjectType); } 00286 inline bool isCharFormat() const { return type() == CharFormat; } 00287 inline bool isBlockFormat() const { return type() == BlockFormat; } 00288 inline bool isListFormat() const { return type() == ListFormat; } 00289 inline bool isFrameFormat() const { return type() == FrameFormat; } 00290 inline bool isImageFormat() const { return type() == CharFormat && objectType() == ImageObject; } 00291 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; 00301 inline bool operator!=(const QTextFormat &rhs) const { return !operator==(rhs); } operator QVariant() const; 00304 inline void setLayoutDirection(Qt::LayoutDirection direction) { setProperty(QTextFormat::LayoutDirection, direction); } 00306 inline Qt::LayoutDirection layoutDirection() const { return Qt::LayoutDirection(intProperty(QTextFormat::LayoutDirection)); } 00309 inline void setBackground(const QBrush &brush) { setProperty(BackgroundBrush, brush); } 00311 inline QBrush background() const { return brushProperty(BackgroundBrush); } 00313 inline void clearBackground() { clearProperty(BackgroundBrush); } 00316 inline void setForeground(const QBrush &brush) { setProperty(ForegroundBrush, brush); } 00318 inline QBrush foreground() const { return brushProperty(ForegroundBrush); } 00320 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 &); }; 00333 inline void QTextFormat::setObjectType(int atype) { setProperty(ObjectType, atype); } Q_DECLARE_OPERATORS_FOR_FLAGS(QTextFormat::PageBreakFlags) 00338 class Q_GUI_EXPORT QTextCharFormat : public QTextFormat { public: 00341 enum VerticalAlignment { AlignNormal = 0, AlignSuperScript, AlignSubScript, AlignMiddle, AlignTop, AlignBottom }; 00349 enum UnderlineStyle { // keep in sync with Qt::PenStyle! NoUnderline, SingleUnderline, DashUnderline, DotLine, DashDotLine, DashDotDotLine, WaveUnderline, SpellCheckUnderline }; QTextCharFormat(); 00362 bool isValid() const { return isCharFormat(); } void setFont(const QFont &font); QFont font() const; 00366 inline void setFontFamily(const QString &family) { setProperty(FontFamily, family); } 00368 inline QString fontFamily() const { return stringProperty(FontFamily); } 00371 inline void setFontPointSize(qreal size) { setProperty(FontPointSize, size); } 00373 inline qreal fontPointSize() const { return doubleProperty(FontPointSize); } 00376 inline void setFontWeight(int weight) { if (weight == QFont::Normal) weight = 0; setProperty(FontWeight, weight); } 00378 inline int fontWeight() const { int weight = intProperty(FontWeight); if (weight == 0) weight = QFont::Normal; return weight; } 00380 inline void setFontItalic(bool italic) { setProperty(FontItalic, italic); } 00382 inline bool fontItalic() const { return boolProperty(FontItalic); } 00385 inline void setFontUnderline(bool underline) { setProperty(TextUnderlineStyle, underline ? SingleUnderline : NoUnderline); } bool fontUnderline() const; 00389 inline void setFontOverline(bool overline) { setProperty(FontOverline, overline); } 00391 inline bool fontOverline() const { return boolProperty(FontOverline); } 00394 inline void setFontStrikeOut(bool strikeOut) { setProperty(FontStrikeOut, strikeOut); } 00396 inline bool fontStrikeOut() const { return boolProperty(FontStrikeOut); } 00399 inline void setUnderlineColor(const QColor &color) { setProperty(TextUnderlineColor, color); } 00401 inline QColor underlineColor() const { return colorProperty(TextUnderlineColor); } 00404 inline void setFontFixedPitch(bool fixedPitch) { setProperty(FontFixedPitch, fixedPitch); } 00406 inline bool fontFixedPitch() const { return boolProperty(FontFixedPitch); } void setUnderlineStyle(UnderlineStyle style); 00410 inline UnderlineStyle underlineStyle() const { return static_cast<UnderlineStyle>(intProperty(TextUnderlineStyle)); } 00413 inline void setVerticalAlignment(VerticalAlignment alignment) { setProperty(TextVerticalAlignment, alignment); } 00415 inline VerticalAlignment verticalAlignment() const { return static_cast<VerticalAlignment>(intProperty(TextVerticalAlignment)); } 00418 inline void setTextOutline(const QPen &pen) { setProperty(TextOutline, pen); } 00420 inline QPen textOutline() const { return penProperty(TextOutline); } 00423 inline void setToolTip(const QString &tip) { setProperty(TextToolTip, tip); } 00425 inline QString toolTip() const { return stringProperty(TextToolTip); } 00428 inline void setAnchor(bool anchor) { setProperty(IsAnchor, anchor); } 00430 inline bool isAnchor() const { return boolProperty(IsAnchor); } 00433 inline void setAnchorHref(const QString &value) { setProperty(AnchorHref, value); } 00435 inline QString anchorHref() const { return stringProperty(AnchorHref); } 00438 inline void setAnchorName(const QString &name) { setAnchorNames(QStringList(name)); } QString anchorName() const; 00442 inline void setAnchorNames(const QStringList &names) { setProperty(AnchorName, names); } QStringList anchorNames() const; inline void setTableCellRowSpan(int tableCellRowSpan); 00447 inline int tableCellRowSpan() const { int s = intProperty(TableCellRowSpan); if (s == 0) s = 1; return s; } inline void setTableCellColumnSpan(int tableCellColumnSpan); 00450 inline int tableCellColumnSpan() const { int s = intProperty(TableCellColumnSpan); if (s == 0) s = 1; return s; } }; 00454 inline void QTextCharFormat::setTableCellRowSpan(int atableCellRowSpan) { if (atableCellRowSpan == 1) atableCellRowSpan = 0; setProperty(TableCellRowSpan, atableCellRowSpan); } 00461 inline void QTextCharFormat::setTableCellColumnSpan(int atableCellColumnSpan) { if (atableCellColumnSpan == 1) atableCellColumnSpan = 0; setProperty(TableCellColumnSpan, atableCellColumnSpan); } 00468 class Q_GUI_EXPORT QTextBlockFormat : public QTextFormat { public: QTextBlockFormat(); 00473 bool isValid() const { return isBlockFormat(); } inline void setAlignment(Qt::Alignment alignment); 00476 inline Qt::Alignment alignment() const { int a = intProperty(BlockAlignment); if (a == 0) a = Qt::AlignLeft; return QFlag(a); } 00479 inline void setTopMargin(qreal margin) { setProperty(BlockTopMargin, margin); } 00481 inline qreal topMargin() const { return doubleProperty(BlockTopMargin); } 00484 inline void setBottomMargin(qreal margin) { setProperty(BlockBottomMargin, margin); } 00486 inline qreal bottomMargin() const { return doubleProperty(BlockBottomMargin); } 00489 inline void setLeftMargin(qreal margin) { setProperty(BlockLeftMargin, margin); } 00491 inline qreal leftMargin() const { return doubleProperty(BlockLeftMargin); } 00494 inline void setRightMargin(qreal margin) { setProperty(BlockRightMargin, margin); } 00496 inline qreal rightMargin() const { return doubleProperty(BlockRightMargin); } 00499 inline void setTextIndent(qreal margin) { setProperty(TextIndent, margin); } 00501 inline qreal textIndent() const { return doubleProperty(TextIndent); } inline void setIndent(int indent); 00505 inline int indent() const { return intProperty(BlockIndent); } 00508 inline void setNonBreakableLines(bool b) { setProperty(BlockNonBreakableLines, b); } 00510 inline bool nonBreakableLines() const { return boolProperty(BlockNonBreakableLines); } 00513 inline void setPageBreakPolicy(PageBreakFlags flags) { setProperty(PageBreakPolicy, int(flags)); } 00515 inline PageBreakFlags pageBreakPolicy() const { return PageBreakFlags(intProperty(PageBreakPolicy)); } }; 00519 inline void QTextBlockFormat::setAlignment(Qt::Alignment aalignment) { setProperty(BlockAlignment, int(aalignment)); } 00522 inline void QTextBlockFormat::setIndent(int aindent) { setProperty(BlockIndent, aindent); } 00525 class Q_GUI_EXPORT QTextListFormat : public QTextFormat { public: QTextListFormat(); 00530 bool isValid() const { return isListFormat(); } 00532 enum Style { ListDisc = -1, ListCircle = -2, ListSquare = -3, ListDecimal = -4, ListLowerAlpha = -5, ListUpperAlpha = -6, ListStyleUndefined = 0 }; inline void setStyle(Style style); 00543 inline Style style() const { return static_cast<Style>(intProperty(ListStyle)); } inline void setIndent(int indent); 00547 inline int indent() const { return intProperty(ListIndent); } }; 00552 inline void QTextListFormat::setStyle(Style astyle) { setProperty(ListStyle, astyle); } 00555 inline void QTextListFormat::setIndent(int aindent) { setProperty(ListIndent, aindent); } 00558 class Q_GUI_EXPORT QTextImageFormat : public QTextCharFormat { public: QTextImageFormat(); 00563 bool isValid() const { return isImageFormat(); } inline void setName(const QString &name); 00566 inline QString name() const { return stringProperty(ImageName); } inline void setWidth(qreal width); 00570 inline qreal width() const { return doubleProperty(ImageWidth); } inline void setHeight(qreal height); 00574 inline qreal height() const { return doubleProperty(ImageHeight); } }; 00578 inline void QTextImageFormat::setName(const QString &aname) { setProperty(ImageName, aname); } 00581 inline void QTextImageFormat::setWidth(qreal awidth) { setProperty(ImageWidth, awidth); } 00584 inline void QTextImageFormat::setHeight(qreal aheight) { setProperty(ImageHeight, aheight); } 00587 class Q_GUI_EXPORT QTextFrameFormat : public QTextFormat { public: QTextFrameFormat(); 00592 bool isValid() const { return isFrameFormat(); } 00594 enum Position { InFlow, FloatLeft, FloatRight // ###### // Absolute }; 00602 enum BorderStyle { BorderStyle_None, BorderStyle_Dotted, BorderStyle_Dashed, BorderStyle_Solid, BorderStyle_Double, BorderStyle_DotDash, BorderStyle_DotDotDash, BorderStyle_Groove, BorderStyle_Ridge, BorderStyle_Inset, BorderStyle_Outset }; 00616 inline void setPosition(Position f) { setProperty(CssFloat, f); } 00618 inline Position position() const { return static_cast<Position>(intProperty(CssFloat)); } inline void setBorder(qreal border); 00622 inline qreal border() const { return doubleProperty(FrameBorder); } 00625 inline void setBorderBrush(const QBrush &brush) { setProperty(FrameBorderBrush, brush); } 00627 inline QBrush borderBrush() const { return brushProperty(FrameBorderBrush); } 00630 inline void setBorderStyle(BorderStyle style) { setProperty(FrameBorderStyle, style); } 00632 inline BorderStyle borderStyle() const { return static_cast<BorderStyle>(intProperty(FrameBorderStyle)); } void setMargin(qreal margin); 00636 inline qreal margin() const { return doubleProperty(FrameMargin); } inline void setTopMargin(qreal margin); qreal topMargin() const; inline void setBottomMargin(qreal margin); qreal bottomMargin() const; inline void setLeftMargin(qreal margin); qreal leftMargin() const; inline void setRightMargin(qreal margin); qreal rightMargin() const; inline void setPadding(qreal padding); 00652 inline qreal padding() const { return doubleProperty(FramePadding); } inline void setWidth(qreal width); 00656 inline void setWidth(const QTextLength &length) { setProperty(FrameWidth, length); } 00658 inline QTextLength width() const { return lengthProperty(FrameWidth); } inline void setHeight(qreal height); inline void setHeight(const QTextLength &height); 00663 inline QTextLength height() const { return lengthProperty(FrameHeight); } 00666 inline void setPageBreakPolicy(PageBreakFlags flags) { setProperty(PageBreakPolicy, int(flags)); } 00668 inline PageBreakFlags pageBreakPolicy() const { return PageBreakFlags(intProperty(PageBreakPolicy)); } }; 00672 inline void QTextFrameFormat::setBorder(qreal aborder) { setProperty(FrameBorder, aborder); } 00675 inline void QTextFrameFormat::setPadding(qreal apadding) { setProperty(FramePadding, apadding); } 00678 inline void QTextFrameFormat::setWidth(qreal awidth) { setProperty(FrameWidth, QTextLength(QTextLength::FixedLength, awidth)); } 00681 inline void QTextFrameFormat::setHeight(qreal aheight) { setProperty(FrameHeight, QTextLength(QTextLength::FixedLength, aheight)); } 00683 inline void QTextFrameFormat::setHeight(const QTextLength &aheight) { setProperty(FrameHeight, aheight); } 00686 inline void QTextFrameFormat::setTopMargin(qreal amargin) { setProperty(FrameTopMargin, amargin); } 00689 inline void QTextFrameFormat::setBottomMargin(qreal amargin) { setProperty(FrameBottomMargin, amargin); } 00692 inline void QTextFrameFormat::setLeftMargin(qreal amargin) { setProperty(FrameLeftMargin, amargin); } 00695 inline void QTextFrameFormat::setRightMargin(qreal amargin) { setProperty(FrameRightMargin, amargin); } 00698 class Q_GUI_EXPORT QTextTableFormat : public QTextFrameFormat { public: QTextTableFormat(); 00703 inline bool isValid() const { return isTableFormat(); } 00705 inline int columns() const { int cols = intProperty(TableColumns); if (cols == 0) cols = 1; return cols; } inline void setColumns(int columns); 00709 inline void setColumnWidthConstraints(const QVector<QTextLength> &constraints) { setProperty(TableColumnWidthConstraints, constraints); } 00712 inline QVector<QTextLength> columnWidthConstraints() const { return lengthVectorProperty(TableColumnWidthConstraints); } 00715 inline void clearColumnWidthConstraints() { clearProperty(TableColumnWidthConstraints); } 00718 inline qreal cellSpacing() const { return doubleProperty(TableCellSpacing); } 00720 inline void setCellSpacing(qreal spacing) { setProperty(TableCellSpacing, spacing); } 00723 inline qreal cellPadding() const { return doubleProperty(TableCellPadding); } inline void setCellPadding(qreal padding); inline void setAlignment(Qt::Alignment alignment); 00728 inline Qt::Alignment alignment() const { return QFlag(intProperty(BlockAlignment)); } 00731 inline void setHeaderRowCount(int count) { setProperty(TableHeaderRowCount, count); } 00733 inline int headerRowCount() const { return intProperty(TableHeaderRowCount); } }; 00737 inline void QTextTableFormat::setColumns(int acolumns) { if (acolumns == 1) acolumns = 0; setProperty(TableColumns, acolumns); } 00744 inline void QTextTableFormat::setCellPadding(qreal apadding) { setProperty(TableCellPadding, apadding); } 00747 inline void QTextTableFormat::setAlignment(Qt::Alignment aalignment) { setProperty(BlockAlignment, int(aalignment)); } QT_END_HEADER #endif // QTEXTFORMAT_H