src/declarative/graphicsitems/qdeclarativetext.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
   160 
   160 
   161 QSet<QUrl> QTextDocumentWithImageResources::errors;
   161 QSet<QUrl> QTextDocumentWithImageResources::errors;
   162 
   162 
   163 /*!
   163 /*!
   164     \qmlclass Text QDeclarativeText
   164     \qmlclass Text QDeclarativeText
   165   \since 4.7
   165     \ingroup qml-basic-visual-elements
       
   166     \since 4.7
   166     \brief The Text item allows you to add formatted text to a scene.
   167     \brief The Text item allows you to add formatted text to a scene.
   167     \inherits Item
   168     \inherits Item
   168 
   169 
   169     A Text item can display both plain and rich text. For example:
   170     A Text item can display both plain and rich text. For example:
   170 
   171 
   186     HTML img tags that load remote images, the text is reloaded.
   187     HTML img tags that load remote images, the text is reloaded.
   187 
   188 
   188     Text provides read-only text. For editable text, see \l TextEdit.
   189     Text provides read-only text. For editable text, see \l TextEdit.
   189 
   190 
   190     \sa {declarative/text/fonts}{Fonts example}
   191     \sa {declarative/text/fonts}{Fonts example}
   191 */
       
   192 
       
   193 /*!
       
   194     \internal
       
   195     \class QDeclarativeText
       
   196     \qmlclass Text
       
   197 
       
   198     \brief The QDeclarativeText class provides a formatted text item that you can add to a QDeclarativeView.
       
   199 
       
   200     Text was designed for read-only text; it does not allow for any text editing.
       
   201     It can display both plain and rich text. For example:
       
   202 
       
   203     \qml
       
   204     Text { text: "Hello World!"; font.family: "Helvetica"; font.pointSize: 24; color: "red" }
       
   205     Text { text: "<b>Hello</b> <i>World!</i>" }
       
   206     \endqml
       
   207 
       
   208     \image text.png
       
   209 
       
   210     If height and width are not explicitly set, Text will attempt to determine how
       
   211     much room is needed and set it accordingly. Unless \c wrapMode is set, it will always
       
   212     prefer width to height (all text will be placed on a single line).
       
   213 
       
   214     The \c elide property can alternatively be used to fit a line of plain text to a set width.
       
   215 
       
   216     A QDeclarativeText object can be instantiated in QML using the tag \c Text.
       
   217 */
   192 */
   218 QDeclarativeText::QDeclarativeText(QDeclarativeItem *parent)
   193 QDeclarativeText::QDeclarativeText(QDeclarativeItem *parent)
   219   : QDeclarativeItem(*(new QDeclarativeTextPrivate), parent)
   194   : QDeclarativeItem(*(new QDeclarativeTextPrivate), parent)
   220 {
   195 {
   221 }
   196 }
  1044     qt_applefontsmoothing_enabled = oldSmooth;
  1019     qt_applefontsmoothing_enabled = oldSmooth;
  1045 #endif
  1020 #endif
  1046 
  1021 
  1047     QAbstractTextDocumentLayout::PaintContext context;
  1022     QAbstractTextDocumentLayout::PaintContext context;
  1048 
  1023 
       
  1024     QTextOption oldOption(doc->defaultTextOption());
  1049     if (drawStyle) {
  1025     if (drawStyle) {
  1050         context.palette.setColor(QPalette::Text, styleColor);
  1026         context.palette.setColor(QPalette::Text, styleColor);
  1051         // ### Do we really want this?
  1027         QTextOption colorOption(doc->defaultTextOption());
  1052         QTextOption colorOption;
       
  1053         colorOption.setFlags(QTextOption::SuppressColors);
  1028         colorOption.setFlags(QTextOption::SuppressColors);
  1054         doc->setDefaultTextOption(colorOption);
  1029         doc->setDefaultTextOption(colorOption);
  1055     } else {
  1030     } else {
  1056         context.palette.setColor(QPalette::Text, color);
  1031         context.palette.setColor(QPalette::Text, color);
  1057     }
  1032     }
  1058     doc->documentLayout()->draw(&p, context);
  1033     doc->documentLayout()->draw(&p, context);
  1059     if (drawStyle)
  1034     if (drawStyle)
  1060         doc->setDefaultTextOption(QTextOption());
  1035         doc->setDefaultTextOption(oldOption);
  1061     return img;
  1036     return img;
  1062 }
  1037 }
  1063 
  1038 
  1064 void QDeclarativeTextPrivate::checkImgCache()
  1039 void QDeclarativeTextPrivate::checkImgCache()
  1065 {
  1040 {
  1215 {
  1190 {
  1216     Q_D(QDeclarativeText);
  1191     Q_D(QDeclarativeText);
  1217 
  1192 
  1218     if (!d->richText || !d->doc || d->doc->documentLayout()->anchorAt(event->pos()).isEmpty()) {
  1193     if (!d->richText || !d->doc || d->doc->documentLayout()->anchorAt(event->pos()).isEmpty()) {
  1219         event->setAccepted(false);
  1194         event->setAccepted(false);
  1220         d->activeLink = QString();
  1195         d->activeLink.clear();
  1221     } else {
  1196     } else {
  1222         d->activeLink = d->doc->documentLayout()->anchorAt(event->pos());
  1197         d->activeLink = d->doc->documentLayout()->anchorAt(event->pos());
  1223     }
  1198     }
  1224 
  1199 
  1225     // ### may malfunction if two of the same links are clicked & dragged onto each other)
  1200     // ### may malfunction if two of the same links are clicked & dragged onto each other)