📄 q3stylesheet.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the Qt3Support 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://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 gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** 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.**** 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.******************************************************************************/#include "q3stylesheet.h"#ifndef QT_NO_RICHTEXT#include "qlayout.h"#include "qpainter.h"#include "q3cleanuphandler.h"#include <qtextdocument.h>#include <stdio.h>class Q3StyleSheetItemData{public: Q3StyleSheetItem::DisplayMode disp; int fontitalic; int fontunderline; int fontstrikeout; int fontweight; int fontsize; int fontsizelog; int fontsizestep; int lineSpacing; QString fontfamily; Q3StyleSheetItem *parentstyle; QString stylename; int ncolumns; QColor col; bool anchor; int align; Q3StyleSheetItem::VerticalAlignment valign; int margin[5]; Q3StyleSheetItem::ListStyle list; Q3StyleSheetItem::WhiteSpaceMode whitespacemode; QString contxt; bool selfnest; Q3StyleSheet* sheet;};/*! \class Q3StyleSheetItem qstylesheet.h \brief The Q3StyleSheetItem class provides an encapsulation of a set of text styles. \compat A style sheet item consists of a name and a set of attributes that specify its font, color, etc. When used in a \link Q3StyleSheet style sheet\endlink (see styleSheet()), items define the name() of a rich text tag and the display property changes associated with it. The \link Q3StyleSheetItem::DisplayMode display mode\endlink attribute indicates whether the item is a block, an inline element or a list element; see setDisplayMode(). The treatment of whitespace is controlled by the \link Q3StyleSheetItem::WhiteSpaceMode white space mode\endlink; see setWhiteSpaceMode(). An item's margins are set with setMargin(), In the case of list items, the list style is set with setListStyle(). An item may be a hypertext link anchor; see setAnchor(). Other attributes are set with setAlignment(), setVerticalAlignment(), setFontFamily(), setFontSize(), setFontWeight(), setFontItalic(), setFontUnderline(), setFontStrikeOut and setColor().*//*! \enum Q3StyleSheetItem::AdditionalStyleValues \internal*//*! \enum Q3StyleSheetItem::WhiteSpaceMode This enum defines the ways in which Q3StyleSheet can treat whitespace. \value WhiteSpaceNormal any sequence of whitespace (including line-breaks) is equivalent to a single space. \value WhiteSpacePre whitespace must be output exactly as given in the input. \value WhiteSpaceNoWrap multiple spaces are collapsed as with WhiteSpaceNormal, but no automatic line-breaks occur. To break lines manually, use the \c{<br>} tag. \omitvalue WhiteSpaceModeUndefined*//*! \enum Q3StyleSheetItem::Margin \value MarginLeft left margin \value MarginRight right margin \value MarginTop top margin \value MarginBottom bottom margin \value MarginAll all margins (left, right, top and bottom) \value MarginVertical top and bottom margins \value MarginHorizontal left and right margins \value MarginFirstLine margin (indentation) of the first line of a paragarph (in addition to the MarginLeft of the paragraph) \value MarginUndefined*//*! Constructs a new style called \a name for the stylesheet \a parent. All properties in Q3StyleSheetItem are initially in the "do not change" state, except \link Q3StyleSheetItem::DisplayMode display mode\endlink, which defaults to \c DisplayInline.*/Q3StyleSheetItem::Q3StyleSheetItem(Q3StyleSheet* parent, const QString& name){ d = new Q3StyleSheetItemData; d->stylename = name.toLower(); d->sheet = parent; init(); if (parent) parent->insert(this);}/*! Copy constructor. Constructs a copy of \a other that is not bound to any style sheet.*/Q3StyleSheetItem::Q3StyleSheetItem(const Q3StyleSheetItem & other){ d = new Q3StyleSheetItemData; *d = *other.d;}/*! Destroys the style. Note that Q3StyleSheetItem objects become owned by Q3StyleSheet when they are created.*/Q3StyleSheetItem::~Q3StyleSheetItem(){ delete d;}/*! Assignment. Assings a copy of \a other that is not bound to any style sheet. Unbounds first from previous style sheet. */Q3StyleSheetItem& Q3StyleSheetItem::operator=(const Q3StyleSheetItem& other){ if (&other == this) return *this; delete d; d = new Q3StyleSheetItemData; *d = *other.d; return *this;}/*! Returns the style sheet this item is in.*/Q3StyleSheet* Q3StyleSheetItem::styleSheet(){ return d->sheet;}/*! \overload Returns the style sheet this item is in.*/const Q3StyleSheet* Q3StyleSheetItem::styleSheet() const{ return d->sheet;}/*! \internal Internal initialization */void Q3StyleSheetItem::init(){ d->disp = DisplayInline; d->fontitalic = Undefined; d->fontunderline = Undefined; d->fontstrikeout = Undefined; d->fontweight = Undefined; d->fontsize = Undefined; d->fontsizelog = Undefined; d->fontsizestep = 0; d->ncolumns = Undefined; d->col = QColor(); // !isValid() d->anchor = false; d->align = Undefined; d->valign = VAlignBaseline; d->margin[0] = Undefined; d->margin[1] = Undefined; d->margin[2] = Undefined; d->margin[3] = Undefined; d->margin[4] = Undefined; d->list = ListStyleUndefined; d->whitespacemode = WhiteSpaceModeUndefined; d->selfnest = true; d->lineSpacing = Undefined;}/*! Returns the name of the style item.*/QString Q3StyleSheetItem::name() const{ return d->stylename;}/*! Returns the \link Q3StyleSheetItem::DisplayMode display mode\endlink of the style. \sa setDisplayMode()*/Q3StyleSheetItem::DisplayMode Q3StyleSheetItem::displayMode() const{ return d->disp;}/*! \enum Q3StyleSheetItem::DisplayMode This enum type defines the way adjacent elements are displayed. \value DisplayBlock elements are displayed as a rectangular block (e.g. \c{<p>...</p>}). \value DisplayInline elements are displayed in a horizontally flowing sequence (e.g. \c{<em>...</em>}). \value DisplayListItem elements are displayed in a vertical sequence (e.g. \c{<li>...</li>}). \value DisplayNone elements are not displayed at all. \omitvalue DisplayModeUndefined*//*! Sets the display mode of the style to \a m. \sa displayMode() */void Q3StyleSheetItem::setDisplayMode(DisplayMode m){ d->disp=m;}/*! Returns the alignment of this style. Possible values are Qt::AlignAuto, Qt::AlignLeft, Qt::AlignRight, Qt::AlignCenter or Qt::AlignJustify. \sa setAlignment(), Qt::Alignment*/int Q3StyleSheetItem::alignment() const{ return d->align;}/*! Sets the alignment to \a f. This only makes sense for styles with a \link Q3StyleSheetItem::DisplayMode display mode\endlink of DisplayBlock. Possible values are Qt::AlignAuto, Qt::AlignLeft, Qt::AlignRight, Qt::AlignCenter or Qt::AlignJustify. \sa alignment(), displayMode(), Qt::Alignment*/void Q3StyleSheetItem::setAlignment(int f){ d->align = f;}/*! Returns the vertical alignment of the style. Possible values are VAlignBaseline, VAlignSub or VAlignSuper. \sa setVerticalAlignment()*/Q3StyleSheetItem::VerticalAlignment Q3StyleSheetItem::verticalAlignment() const{ return d->valign;}/*! \enum Q3StyleSheetItem::VerticalAlignment This enum type defines the way elements are aligned vertically. This is only supported for text elements. \value VAlignBaseline align the baseline of the element (or the bottom, if the element doesn't have a baseline) with the baseline of the parent \value VAlignSub subscript the element \value VAlignSuper superscript the element*//*! Sets the vertical alignment to \a valign. Possible values are VAlignBaseline, VAlignSub or VAlignSuper. The vertical alignment property is not inherited. \sa verticalAlignment()*/void Q3StyleSheetItem::setVerticalAlignment(VerticalAlignment valign){ d->valign = valign;}/*! Returns true if the style sets an italic font; otherwise returns false. \sa setFontItalic(), definesFontItalic()*/bool Q3StyleSheetItem::fontItalic() const{ return d->fontitalic > 0;}/*! If \a italic is true sets italic for the style; otherwise sets upright. \sa fontItalic(), definesFontItalic()*/void Q3StyleSheetItem::setFontItalic(bool italic){ d->fontitalic = italic?1:0;}/*! Returns true if the style defines a font shape; otherwise returns false. A style does not define any shape until setFontItalic() is called. \sa setFontItalic(), fontItalic()*/bool Q3StyleSheetItem::definesFontItalic() const{ return d->fontitalic != Undefined;}/*! Returns true if the style sets an underlined font; otherwise returns false. \sa setFontUnderline(), definesFontUnderline()*/bool Q3StyleSheetItem::fontUnderline() const{ return d->fontunderline > 0;}/*! If \a underline is true, sets underline for the style; otherwise sets no underline. \sa fontUnderline(), definesFontUnderline()*/void Q3StyleSheetItem::setFontUnderline(bool underline){ d->fontunderline = underline?1:0;}/*! Returns true if the style defines a setting for the underline property of the font; otherwise returns false. A style does not define this until setFontUnderline() is called. \sa setFontUnderline(), fontUnderline()*/bool Q3StyleSheetItem::definesFontUnderline() const{ return d->fontunderline != Undefined;}/*! Returns true if the style sets a strike out font; otherwise returns false. \sa setFontStrikeOut(), definesFontStrikeOut()*/bool Q3StyleSheetItem::fontStrikeOut() const{ return d->fontstrikeout > 0;}/*! If \a strikeOut is true, sets strike out for the style; otherwise sets no strike out. \sa fontStrikeOut(), definesFontStrikeOut()*/void Q3StyleSheetItem::setFontStrikeOut(bool strikeOut){ d->fontstrikeout = strikeOut?1:0;}/*! Returns true if the style defines a setting for the strikeOut property of the font; otherwise returns false. A style does not define this until setFontStrikeOut() is called. \sa setFontStrikeOut(), fontStrikeOut()*/bool Q3StyleSheetItem::definesFontStrikeOut() const{ return d->fontstrikeout != Undefined;}/*! Returns the font weight setting of the style. This is either a valid QFont::Weight or the value Q3StyleSheetItem::Undefined. \sa setFontWeight(), QFont*/int Q3StyleSheetItem::fontWeight() const{ return d->fontweight;}/*! Sets the font weight setting of the style to \a w. Valid values are those defined by QFont::Weight. \sa QFont, fontWeight()*/void Q3StyleSheetItem::setFontWeight(int w){ d->fontweight = w;}/*! Returns the logical font size setting of the style. This is either a valid size between 1 and 7 or Q3StyleSheetItem::Undefined. \sa setLogicalFontSize(), setLogicalFontSizeStep(), QFont::pointSize(), QFont::setPointSize()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -