Qt 4.8
qtextformat.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qtextformat.h"
43 #include "qtextformat_p.h"
44 
45 #include <qvariant.h>
46 #include <qdatastream.h>
47 #include <qdebug.h>
48 #include <qmap.h>
49 #include <qhash.h>
50 
52 
173 QTextLength::operator QVariant() const
174 {
175  return QVariant(QVariant::TextLength, this);
176 }
177 
178 #ifndef QT_NO_DATASTREAM
180 {
181  return stream << qint32(length.lengthType) << double(length.fixedValueOrPercentage);
182 }
183 
185 {
186  qint32 type;
187  double fixedValueOrPercentage;
188  stream >> type >> fixedValueOrPercentage;
189  length.fixedValueOrPercentage = fixedValueOrPercentage;
190  length.lengthType = QTextLength::Type(type);
191  return stream;
192 }
193 #endif // QT_NO_DATASTREAM
194 
196 {
197 public:
199 
200  struct Property
201  {
202  inline Property(qint32 k, const QVariant &v) : key(k), value(v) {}
203  inline Property() {}
204 
207 
208  inline bool operator==(const Property &other) const
209  { return key == other.key && value == other.value; }
210  inline bool operator!=(const Property &other) const
211  { return key != other.key || value != other.value; }
212  };
213 
214  inline uint hash() const
215  {
216  if (!hashDirty)
217  return hashValue;
218  return recalcHash();
219  }
220 
221  inline bool operator==(const QTextFormatPrivate &rhs) const {
222  if (hash() != rhs.hash())
223  return false;
224 
225  return props == rhs.props;
226  }
227 
228  inline void insertProperty(qint32 key, const QVariant &value)
229  {
230  hashDirty = true;
232  fontDirty = true;
233  for (int i = 0; i < props.count(); ++i)
234  if (props.at(i).key == key) {
235  props[i].value = value;
236  return;
237  }
238  props.append(Property(key, value));
239  }
240 
241  inline void clearProperty(qint32 key)
242  {
243  for (int i = 0; i < props.count(); ++i)
244  if (props.at(i).key == key) {
245  hashDirty = true;
247  fontDirty = true;
248  props.remove(i);
249  return;
250  }
251  }
252 
253  inline int propertyIndex(qint32 key) const
254  {
255  for (int i = 0; i < props.count(); ++i)
256  if (props.at(i).key == key)
257  return i;
258  return -1;
259  }
260 
261  inline QVariant property(qint32 key) const
262  {
263  const int idx = propertyIndex(key);
264  if (idx < 0)
265  return QVariant();
266  return props.at(idx).value;
267  }
268 
269  inline bool hasProperty(qint32 key) const
270  { return propertyIndex(key) != -1; }
271 
272  void resolveFont(const QFont &defaultFont);
273 
274  inline const QFont &font() const {
275  if (fontDirty)
276  recalcFont();
277  return fnt;
278  }
279 
281 private:
282 
283  uint recalcHash() const;
284  void recalcFont() const;
285 
286  mutable bool hashDirty;
287  mutable bool fontDirty;
288  mutable uint hashValue;
289  mutable QFont fnt;
290 
291  friend QDataStream &operator<<(QDataStream &, const QTextFormat &);
293 };
294 
295 // this is only safe because sizeof(int) == sizeof(float)
296 static inline uint hash(float d)
297 {
298 #ifdef Q_CC_GNU
299  // this is a GCC extension and isn't guaranteed to work in other compilers
300  // the reinterpret_cast below generates a strict-aliasing warning with GCC
301  union { float f; uint u; } cvt;
302  cvt.f = d;
303  return cvt.u;
304 #else
305  return reinterpret_cast<uint&>(d);
306 #endif
307 }
308 
309 static inline uint hash(const QColor &color)
310 {
311  return (color.isValid()) ? color.rgba() : 0x234109;
312 }
313 
314 static inline uint hash(const QPen &pen)
315 {
316  return hash(pen.color()) + hash(pen.widthF());
317 }
318 
319 static inline uint hash(const QBrush &brush)
320 {
321  return hash(brush.color()) + (brush.style() << 3);
322 }
323 
324 static inline uint variantHash(const QVariant &variant)
325 {
326  // simple and fast hash functions to differentiate between type and value
327  switch (variant.userType()) { // sorted by occurrence frequency
328  case QVariant::String: return qHash(variant.toString());
329  case QVariant::Double: return hash(variant.toDouble());
330  case QVariant::Int: return 0x811890 + variant.toInt();
331  case QVariant::Brush:
332  return 0x01010101 + hash(qvariant_cast<QBrush>(variant));
333  case QVariant::Bool: return 0x371818 + variant.toBool();
334  case QVariant::Pen: return 0x02020202 + hash(qvariant_cast<QPen>(variant));
335  case QVariant::List:
336  return 0x8377 + qvariant_cast<QVariantList>(variant).count();
337  case QVariant::Color: return hash(qvariant_cast<QColor>(variant));
339  return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue());
340  case QMetaType::Float: return hash(variant.toFloat());
341  case QVariant::Invalid: return 0;
342  default: break;
343  }
344  return qHash(variant.typeName());
345 }
346 
347 static inline int getHash(const QTextFormatPrivate *d, int format)
348 {
349  return (d ? d->hash() : 0) + format;
350 }
351 
353 {
354  hashValue = 0;
355  for (QVector<Property>::ConstIterator it = props.constBegin(); it != props.constEnd(); ++it)
356  hashValue += (it->key << 16) + variantHash(it->value);
357 
358  hashDirty = false;
359 
360  return hashValue;
361 }
362 
363 void QTextFormatPrivate::resolveFont(const QFont &defaultFont)
364 {
365  recalcFont();
366  const uint oldMask = fnt.resolve();
367  fnt = fnt.resolve(defaultFont);
368 
370  const qreal scaleFactors[7] = {qreal(0.7), qreal(0.8), qreal(1.0), qreal(1.2), qreal(1.5), qreal(2), qreal(2.4)};
371 
372  const int htmlFontSize = qBound(0, property(QTextFormat::FontSizeAdjustment).toInt() + 3 - 1, 6);
373 
374 
375  if (defaultFont.pointSize() <= 0) {
376  qreal pixelSize = scaleFactors[htmlFontSize] * defaultFont.pixelSize();
377  fnt.setPixelSize(qRound(pixelSize));
378  } else {
379  qreal pointSize = scaleFactors[htmlFontSize] * defaultFont.pointSizeF();
380  fnt.setPointSizeF(pointSize);
381  }
382  }
383 
384  fnt.resolve(oldMask);
385 }
386 
388 {
389  // update cached font as well
390  QFont f;
391 
392  for (int i = 0; i < props.count(); ++i) {
393  switch (props.at(i).key) {
395  f.setFamily(props.at(i).value.toString());
396  break;
398  f.setPointSizeF(props.at(i).value.toReal());
399  break;
401  f.setPixelSize(props.at(i).value.toInt());
402  break;
404  int weight = props.at(i).value.toInt();
405  if (weight == 0) weight = QFont::Normal;
406  f.setWeight(weight);
407  break; }
409  f.setItalic(props.at(i).value.toBool());
410  break;
412  if (! hasProperty(QTextFormat::TextUnderlineStyle)) // don't use the old one if the new one is there.
413  f.setUnderline(props.at(i).value.toBool());
414  break;
416  f.setUnderline(static_cast<QTextCharFormat::UnderlineStyle>(props.at(i).value.toInt()) == QTextCharFormat::SingleUnderline);
417  break;
419  f.setOverline(props.at(i).value.toBool());
420  break;
422  f.setStrikeOut(props.at(i).value.toBool());
423  break;
425  f.setLetterSpacing(QFont::PercentageSpacing, props.at(i).value.toReal());
426  break;
428  f.setWordSpacing(props.at(i).value.toReal());
429  break;
431  f.setCapitalization(static_cast<QFont::Capitalization> (props.at(i).value.toInt()));
432  break;
434  const bool value = props.at(i).value.toBool();
435  if (f.fixedPitch() != value)
436  f.setFixedPitch(value);
437  break; }
439  f.setStyleHint(static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());
440  break;
442  f.setHintingPreference(static_cast<QFont::HintingPreference>(props.at(i).value.toInt()));
443  break;
445  f.setStyleStrategy(static_cast<QFont::StyleStrategy>(props.at(i).value.toInt()));
446  break;
448  f.setKerning(props.at(i).value.toBool());
449  break;
450  default:
451  break;
452  }
453  }
454  fnt = f;
455  fontDirty = false;
456 }
457 
458 #ifndef QT_NO_DATASTREAM
460 {
461  stream << fmt.format_type << fmt.properties();
462  return stream;
463 }
464 
466 {
468  stream >> fmt.format_type >> properties;
469 
470  // QTextFormat's default constructor doesn't allocate the private structure, so
471  // we have to do this, in case fmt is a default constructed value.
472  if(!fmt.d)
473  fmt.d = new QTextFormatPrivate();
474 
476  it != properties.constEnd(); ++it)
477  fmt.d->insertProperty(it.key(), it.value());
478 
479  return stream;
480 }
481 #endif // QT_NO_DATASTREAM
482 
815  : format_type(InvalidFormat)
816 {
817 }
818 
825  : format_type(type)
826 {
827 }
828 
829 
840  : d(rhs.d), format_type(rhs.format_type)
841 {
842 }
843 
854 {
855  d = rhs.d;
856  format_type = rhs.format_type;
857  return *this;
858 }
859 
864 {
865 }
866 
867 
871 QTextFormat::operator QVariant() const
872 {
873  return QVariant(QVariant::TextFormat, this);
874 }
875 
880 void QTextFormat::merge(const QTextFormat &other)
881 {
882  if (format_type != other.format_type)
883  return;
884 
885  if (!d) {
886  d = other.d;
887  return;
888  }
889 
890  if (!other.d)
891  return;
892 
893  QTextFormatPrivate *d = this->d;
894 
895  const QVector<QTextFormatPrivate::Property> &otherProps = other.d->props;
896  d->props.reserve(d->props.size() + otherProps.size());
897  for (int i = 0; i < otherProps.count(); ++i) {
898  const QTextFormatPrivate::Property &p = otherProps.at(i);
899  d->insertProperty(p.key, p.value);
900  }
901 }
902 
908 int QTextFormat::type() const
909 {
910  return format_type;
911 }
912 
917 {
918  return QTextBlockFormat(*this);
919 }
920 
925 {
926  return QTextCharFormat(*this);
927 }
928 
933 {
934  return QTextListFormat(*this);
935 }
936 
941 {
942  return QTextTableFormat(*this);
943 }
944 
949 {
950  return QTextFrameFormat(*this);
951 }
952 
957 {
958  return QTextImageFormat(*this);
959 }
960 
970 {
971  return QTextTableCellFormat(*this);
972 }
973 
980 bool QTextFormat::boolProperty(int propertyId) const
981 {
982  if (!d)
983  return false;
984  const QVariant prop = d->property(propertyId);
985  if (prop.userType() != QVariant::Bool)
986  return false;
987  return prop.toBool();
988 }
989 
996 int QTextFormat::intProperty(int propertyId) const
997 {
998  // required, since the default layout direction has to be LayoutDirectionAuto, which is not integer 0
999  int def = (propertyId == QTextFormat::LayoutDirection) ? int(Qt::LayoutDirectionAuto) : 0;
1000 
1001  if (!d)
1002  return def;
1003  const QVariant prop = d->property(propertyId);
1004  if (prop.userType() != QVariant::Int)
1005  return def;
1006  return prop.toInt();
1007 }
1008 
1016 qreal QTextFormat::doubleProperty(int propertyId) const
1017 {
1018  if (!d)
1019  return 0.;
1020  const QVariant prop = d->property(propertyId);
1021  if (prop.userType() != QVariant::Double && prop.userType() != QMetaType::Float)
1022  return 0.;
1023  return qvariant_cast<qreal>(prop);
1024 }
1025 
1034 {
1035  if (!d)
1036  return QString();
1037  const QVariant prop = d->property(propertyId);
1038  if (prop.userType() != QVariant::String)
1039  return QString();
1040  return prop.toString();
1041 }
1042 
1051 QColor QTextFormat::colorProperty(int propertyId) const
1052 {
1053  if (!d)
1054  return QColor();
1055  const QVariant prop = d->property(propertyId);
1056  if (prop.userType() != QVariant::Color)
1057  return QColor();
1058  return qvariant_cast<QColor>(prop);
1059 }
1060 
1068 QPen QTextFormat::penProperty(int propertyId) const
1069 {
1070  if (!d)
1071  return QPen(Qt::NoPen);
1072  const QVariant prop = d->property(propertyId);
1073  if (prop.userType() != QVariant::Pen)
1074  return QPen(Qt::NoPen);
1075  return qvariant_cast<QPen>(prop);
1076 }
1077 
1085 QBrush QTextFormat::brushProperty(int propertyId) const
1086 {
1087  if (!d)
1088  return QBrush(Qt::NoBrush);
1089  const QVariant prop = d->property(propertyId);
1090  if (prop.userType() != QVariant::Brush)
1091  return QBrush(Qt::NoBrush);
1092  return qvariant_cast<QBrush>(prop);
1093 }
1094 
1101 {
1102  if (!d)
1103  return QTextLength();
1104  return qvariant_cast<QTextLength>(d->property(propertyId));
1105 }
1106 
1115 {
1116  QVector<QTextLength> vector;
1117  if (!d)
1118  return vector;
1119  const QVariant prop = d->property(propertyId);
1120  if (prop.userType() != QVariant::List)
1121  return vector;
1122 
1123  QList<QVariant> propertyList = prop.toList();
1124  for (int i=0; i<propertyList.size(); ++i) {
1125  QVariant var = propertyList.at(i);
1126  if (var.userType() == QVariant::TextLength)
1127  vector.append(qvariant_cast<QTextLength>(var));
1128  }
1129 
1130  return vector;
1131 }
1132 
1138 QVariant QTextFormat::property(int propertyId) const
1139 {
1140  return d ? d->property(propertyId) : QVariant();
1141 }
1142 
1148 void QTextFormat::setProperty(int propertyId, const QVariant &value)
1149 {
1150  if (!d)
1151  d = new QTextFormatPrivate;
1152  if (!value.isValid())
1153  clearProperty(propertyId);
1154  else
1155  d->insertProperty(propertyId, value);
1156 }
1157 
1163 void QTextFormat::setProperty(int propertyId, const QVector<QTextLength> &value)
1164 {
1165  if (!d)
1166  d = new QTextFormatPrivate;
1167  QVariantList list;
1168  for (int i=0; i<value.size(); ++i)
1169  list << value.at(i);
1170  d->insertProperty(propertyId, list);
1171 }
1172 
1178 void QTextFormat::clearProperty(int propertyId)
1179 {
1180  if (!d)
1181  return;
1182  d->clearProperty(propertyId);
1183 }
1184 
1185 
1216 {
1217  if (!d)
1218  return -1;
1219  const QVariant prop = d->property(ObjectIndex);
1220  if (prop.userType() != QVariant::Int) // ####
1221  return -1;
1222  return prop.toInt();
1223 }
1224 
1236 {
1237  if (o == -1) {
1238  if (d)
1240  } else {
1241  if (!d)
1242  d = new QTextFormatPrivate;
1243  // ### type
1245  }
1246 }
1247 
1254 bool QTextFormat::hasProperty(int propertyId) const
1255 {
1256  return d ? d->hasProperty(propertyId) : false;
1257 }
1258 
1259 /*
1260  Returns the property type for the given \a propertyId.
1261 
1262  \sa hasProperty() allPropertyIds() Property
1263 */
1264 
1269 {
1271  if (d) {
1272  for (int i = 0; i < d->props.count(); ++i)
1273  map.insert(d->props.at(i).key, d->props.at(i).value);
1274  }
1275  return map;
1276 }
1277 
1286 {
1287  return d ? d->props.count() : 0;
1288 }
1289 
1310 bool QTextFormat::operator==(const QTextFormat &rhs) const
1311 {
1312  if (format_type != rhs.format_type)
1313  return false;
1314 
1315  if (d == rhs.d)
1316  return true;
1317 
1318  if (d && d->props.isEmpty() && !rhs.d)
1319  return true;
1320 
1321  if (!d && rhs.d && rhs.d->props.isEmpty())
1322  return true;
1323 
1324  if (!d || !rhs.d)
1325  return false;
1326 
1327  return *d == *rhs.d;
1328 }
1329 
1417 
1429  : QTextFormat(fmt)
1430 {
1431 }
1432 
1567 {
1569  return underlineStyle() == SingleUnderline;
1570  return boolProperty(FontUnderline);
1571 }
1572 
1593 {
1595  // for compatibility
1597 }
1598 
1965 {
1966  QVariant prop = property(AnchorName);
1967  if (prop.userType() == QVariant::StringList)
1968  return prop.toStringList().value(0);
1969  else if (prop.userType() != QVariant::String)
1970  return QString();
1971  return prop.toString();
1972 }
1973 
1986 {
1987  QVariant prop = property(AnchorName);
1988  if (prop.userType() == QVariant::StringList)
1989  return prop.toStringList();
1990  else if (prop.userType() != QVariant::String)
1991  return QStringList();
1992  return QStringList(prop.toString());
1993 }
1994 
1995 
2094 {
2095  setFontFamily(font.family());
2096 
2097  const qreal pointSize = font.pointSizeF();
2098  if (pointSize > 0) {
2099  setFontPointSize(pointSize);
2100  } else {
2101  const int pixelSize = font.pixelSize();
2102  if (pixelSize > 0)
2104  }
2105 
2106  setFontWeight(font.weight());
2107  setFontItalic(font.italic());
2109  setFontOverline(font.overline());
2110  setFontStrikeOut(font.strikeOut());
2111  setFontFixedPitch(font.fixedPitch());
2116  setFontStyleHint(font.styleHint());
2118  setFontKerning(font.kerning());
2119 }
2120 
2125 {
2126  return d ? d->font() : QFont();
2127 }
2128 
2200 
2212  : QTextFormat(fmt)
2213 {
2214 }
2215 
2227 {
2228  QList<QVariant> list;
2230  while (iter != tabs.constEnd()) {
2231  QVariant v;
2232  v.setValue<QTextOption::Tab>(*iter);
2233  list.append(v);
2234  ++iter;
2235  }
2236  setProperty(TabPositions, list);
2237 }
2238 
2249 {
2251  if(variant.isNull())
2252  return QList<QTextOption::Tab>();
2253  QList<QTextOption::Tab> answer;
2255  QList<QVariant>::Iterator iter = variantsList.begin();
2256  while(iter != variantsList.end()) {
2257  answer.append( qvariant_cast<QTextOption::Tab>(*iter));
2258  ++iter;
2259  }
2260  return answer;
2261 }
2262 
2645 {
2646  setIndent(1);
2647 }
2648 
2660  : QTextFormat(fmt)
2661 {
2662 }
2663 
2864 {
2867 }
2868 
2880  : QTextFormat(fmt)
2881 {
2882 }
2883 
2982 {
2983  setProperty(FrameMargin, amargin);
2984  setProperty(FrameTopMargin, amargin);
2985  setProperty(FrameBottomMargin, amargin);
2986  setProperty(FrameLeftMargin, amargin);
2987  setProperty(FrameRightMargin, amargin);
2988 }
2989 
2990 
3020 {
3022  return margin();
3024 }
3025 
3046 {
3048  return margin();
3050 }
3051 
3072 {
3074  return margin();
3076 }
3077 
3098 {
3100  return margin();
3102 }
3103 
3263  : QTextFrameFormat()
3264 {
3266  setCellSpacing(2);
3267  setBorder(1);
3268 }
3269 
3281  : QTextFrameFormat(fmt)
3282 {
3283 }
3284 
3508 
3520  : QTextCharFormat(fmt)
3521 {
3522 }
3523 
3571 // ### Qt5 qreal replace with a QTextLength
3596 // ### Qt5 qreal replace with a QTextLength
3806  : QTextCharFormat()
3807 {
3809 }
3810 
3822  : QTextCharFormat(fmt)
3823 {
3824 }
3825 
3849 // ------------------------------------------------------
3850 
3851 
3853 {
3854  formats = rhs.formats;
3855  objFormats = rhs.objFormats;
3856 }
3857 
3859 {
3860  formats = rhs.formats;
3861  objFormats = rhs.objFormats;
3862  return *this;
3863 }
3864 
3866 {
3867 }
3868 
3870 {
3871  uint hash = getHash(format.d, format.format_type);
3873  while (i != hashes.end() && i.key() == hash) {
3874  if (formats.value(i.value()) == format) {
3875  return i.value();
3876  }
3877  ++i;
3878  }
3879 
3880  int idx = formats.size();
3881  formats.append(format);
3882 
3883  QT_TRY{
3884  QTextFormat &f = formats.last();
3885  if (!f.d)
3886  f.d = new QTextFormatPrivate;
3887  f.d->resolveFont(defaultFnt);
3888 
3889  if (!hashes.contains(hash, idx))
3890  hashes.insert(hash, idx);
3891 
3892  } QT_CATCH(...) {
3893  formats.pop_back();
3894  QT_RETHROW;
3895  }
3896  return idx;
3897 }
3898 
3900 {
3901  uint hash = getHash(format.d, format.format_type);
3903  while (i != hashes.end() && i.key() == hash) {
3904  if (formats.value(i.value()) == format) {
3905  return true;
3906  }
3907  ++i;
3908  }
3909  return false;
3910 }
3911 
3913 {
3914  if (objectIndex == -1)
3915  return QTextFormat();
3916  return format(objFormats.at(objectIndex));
3917 }
3918 
3920 {
3921  const int formatIndex = indexForFormat(f);
3922  objFormats[objectIndex] = formatIndex;
3923 }
3924 
3926 {
3927  if (objectIndex == -1)
3928  return -1;
3929  return objFormats.at(objectIndex);
3930 }
3931 
3933 {
3934  objFormats[objectIndex] = formatIndex;
3935 }
3936 
3938 {
3939  const int objectIndex = objFormats.size();
3940  objFormats.append(indexForFormat(f));
3941  return objectIndex;
3942 }
3943 
3945 {
3946  if (idx < 0 || idx >= formats.count())
3947  return QTextFormat();
3948 
3949  return formats.at(idx);
3950 }
3951 
3953 {
3954  defaultFnt = f;
3955  for (int i = 0; i < formats.count(); ++i)
3956  if (formats[i].d)
3957  formats[i].d->resolveFont(defaultFnt);
3958 }
3959 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int objectIndex() const
Returns the index of the format object, or -1 if the format object is invalid.
The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes.
Definition: qcontainerfwd.h:58
void setWordSpacing(qreal spacing)
Sets the word spacing for the font to spacing.
Definition: qfont.cpp:1757
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
void setFontKerning(bool enable)
Enables kerning for this font if enable is true; otherwise disables it.
Definition: qtextformat.h:475
QTextTableFormat()
Constructs a new table format object.
QStringList anchorNames() const
Returns the anchor names associated with this text format, or an empty string list if none has been s...
QFont font() const
Returns the font for this character format.
uint qHash(const QProcEnvKey &key)
Definition: qprocess_p.h:96
QTextFormat()
Creates a new text format with an InvalidFormat.
void setCapitalization(Capitalization)
Sets the capitalization of the text in this font to caps.
Definition: qfont.cpp:1798
int objectFormatIndex(int objectIndex) const
void setBorderBrush(const QBrush &brush)
Sets the brush used for the frame&#39;s border.
Definition: qtextformat.h:765
int type
Definition: qmetatype.cpp:239
friend QDataStream & operator<<(QDataStream &, const QTextFormat &)
void setFontItalic(bool italic)
If italic is true, sets the text format&#39;s font to be italic; otherwise the font will be non-italic...
Definition: qtextformat.h:415
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
double qreal
Definition: qglobal.h:1193
The QTextListFormat class provides formatting information for lists in a QTextDocument.
Definition: qtextformat.h:642
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
int qint32
Definition: qglobal.h:937
uint hash() const
void setKerning(bool)
Enables kerning for this font if enable is true; otherwise disables it.
Definition: qfont.cpp:1432
static int getHash(const QTextFormatPrivate *d, int format)
Property(qint32 k, const QVariant &v)
void setBorder(qreal border)
Sets the width (in pixels) of the frame&#39;s border.
Definition: qtextformat.h:816
void setFontStrikeOut(bool strikeOut)
If strikeOut is true, sets the text format&#39;s font with strike-out enabled (with a horizontal line thr...
Definition: qtextformat.h:441
void clearProperty(qint32 key)
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
#define it(className, varName)
QColor colorProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn&#39;t of QVariant::Color type...
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
void setBorderStyle(BorderStyle style)
Sets the style of the frame&#39;s border.
Definition: qtextformat.h:770
bool underline() const
Returns true if underline has been set; otherwise returns false.
Definition: qfont.cpp:1320
void setProperty(int propertyId, const QVariant &value)
Sets the property specified by the propertyId to the given value.
void setUnderline(bool)
If enable is true, sets underline on; otherwise sets underline off.
Definition: qfont.cpp:1331
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
QTextTableCellFormat toTableCellFormat() const
Returns this format as a table cell format.
int pixelSize() const
Returns the pixel size of the font if it was set with setPixelSize().
Definition: qfont.cpp:1178
QBrush brushProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn&#39;t of QVariant::Brush type...
QTextBlockFormat()
Constructs a new QTextBlockFormat.
void setIndent(int indent)
Sets the list format&#39;s indentation.
Definition: qtextformat.h:685
const QFont & font() const
void setFontOverline(bool overline)
If overline is true, sets the text format&#39;s font to be overlined; otherwise the font is displayed non...
Definition: qtextformat.h:436
friend class QTextCharFormat
Definition: qtextformat.h:362
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
bool operator==(const QTextFormatPrivate &rhs) const
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
void setFont(const QFont &font)
Sets the text format&#39;s font.
void setFontStyleStrategy(QFont::StyleStrategy strategy)
Sets the font style strategy.
Definition: qtextformat.h:458
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
Capitalization capitalization() const
Returns the current capitalization type of the font.
Definition: qfont.cpp:1819
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
int createObjectIndex(const QTextFormat &f)
QTextFormatCollection & operator=(const QTextFormatCollection &rhs)
QMap< int, QVariant > properties() const
Returns a map with all properties of this text format.
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
QString anchorName() const
This function is deprecated.
quint16 u
void setFontFixedPitch(bool fixedPitch)
If fixedPitch is true, sets the text format&#39;s font to be fixed pitch; otherwise a non-fixed pitch fon...
Definition: qtextformat.h:451
Type
This enum describes the different types a length object can have.
Definition: qtextformat.h:87
QTextCharFormat()
Constructs a new character format object.
QVector< QTextLength > lengthVectorProperty(int propertyId) const
Returns the value of the property given by propertyId.
qreal leftMargin() const
Returns the width of the frame&#39;s left margin in pixels.
QTextTableFormat toTableFormat() const
Returns this format as a table format.
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setItalic(bool b)
Sets the style() of the font to QFont::StyleItalic if enable is true; otherwise the style is set to Q...
Definition: qfont.h:360
QTextFormat format(int idx) const
QTextFormat objectFormat(int objectIndex) const
void setValue(const T &value)
Stores a copy of value.
Definition: qvariant.h:527
void setTabPositions(const QList< QTextOption::Tab > &tabs)
Sets the tab positions for the text block to those specified by tabs.
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QVariant property(qint32 key) const
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
bool kerning() const
Returns true if kerning should be used when drawing text with this font.
Definition: qfont.cpp:1416
QHash< Key, T >::iterator find(const Key &key, const T &value)
Returns an iterator pointing to the item with the key and value.
Definition: qhash.h:972
void setHintingPreference(HintingPreference hintingPreference)
Set the preference for the hinting level of the glyphs to hintingPreference.
Definition: qfont.cpp:1071
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
void setStyleStrategy(StyleStrategy s)
Sets the style strategy for the font to s.
Definition: qfont.cpp:1578
QTextListFormat()
Constructs a new list format object.
bool hasProperty(qint32 key) const
void recalcFont() const
void setFontWeight(int weight)
Sets the text format&#39;s font weight to weight.
Definition: qtextformat.h:411
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
QTextFrameFormat toFrameFormat() const
Returns this format as a frame format.
void setFamily(const QString &)
Sets the family name of the font.
Definition: qfont.cpp:924
bool operator==(const Property &other) const
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
int type() const
Returns the type of this format.
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition: qfont.cpp:1983
#define QT_RETHROW
Definition: qglobal.h:1539
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
Definition: qvariant.cpp:2259
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QTextFrameFormat()
Constructs a text frame format object with the default properties.
The QTextImageFormat class provides formatting information for images in a QTextDocument.
Definition: qtextformat.h:694
QFuture< void > map(Sequence &sequence, MapFunction function)
uint recalcHash() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
qreal pointSizeF() const
Returns the point size of the font.
Definition: qfont.cpp:1142
UnderlineStyle underlineStyle() const
Returns the style of underlining the text.
Definition: qtextformat.h:481
qreal topMargin() const
Returns the width of the frame&#39;s top margin in pixels.
UnderlineStyle
This enum describes the different ways drawing underlined text.
Definition: qtextformat.h:384
friend QDataStream & operator>>(QDataStream &, QTextFormat &)
static FILE * stream
qreal margin() const
Returns the width of the frame&#39;s external margin in pixels.
Definition: qtextformat.h:776
void resolveFont(const QFont &defaultFont)
qreal bottomMargin() const
Returns the width of the frame&#39;s bottom margin in pixels.
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
bool overline() const
Returns true if overline has been set; otherwise returns false.
Definition: qfont.cpp:1344
static uint hash(float d)
void setFontCapitalization(QFont::Capitalization capitalization)
Sets the capitalization of the text that apppears in this font to capitalization. ...
Definition: qtextformat.h:419
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
void setStrikeOut(bool)
If enable is true, sets strikeout on; otherwise sets strikeout off.
Definition: qfont.cpp:1378
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
void setDefaultFont(const QFont &f)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QTextOption::Tab > tabPositions() const
Returns a list of tab positions defined for the text block.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
Type lengthType
Definition: qtextformat.h:115
void setFontLetterSpacing(qreal spacing)
Sets the letter spacing of this format to the given spacing, in percent.
Definition: qtextformat.h:423
static int toInt(const QByteArray &str)
Definition: generator.cpp:167
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
SpacingType letterSpacingType() const
Returns the spacing type used for letter spacing.
Definition: qfont.cpp:1721
unsigned int uint
Definition: qglobal.h:996
QTextBlockFormat toBlockFormat() const
Returns this format as a block format.
void setFontPointSize(qreal size)
Sets the text format&#39;s font size.
Definition: qtextformat.h:406
QTextListFormat toListFormat() const
Returns this format as a list format.
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
void setStyleHint(StyleHint, StyleStrategy=PreferDefault)
Sets the style hint and strategy to hint and strategy, respectively.
Definition: qfont.cpp:1554
void setObjectFormat(int objectIndex, const QTextFormat &format)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
#define QT_CATCH(A)
Definition: qglobal.h:1537
qreal wordSpacing() const
Returns the word spacing for the font.
Definition: qfont.cpp:1735
void setObjectType(int type)
Sets the text format&#39;s object type to type.
Definition: qtextformat.h:367
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int propertyIndex(qint32 key) const
qint32 format_type
Definition: qtextformat.h:359
QTextTableCellFormat()
Constructs a new table cell format object.
FormatVector formats
Definition: qtextformat_p.h:98
void setObjectFormatIndex(int objectIndex, int formatIndex)
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
Definition: qmap.h:301
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
QTextImageFormat toImageFormat() const
Returns this format as an image format.
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
void setCellSpacing(qreal spacing)
Sets the cell spacing for the table.
Definition: qtextformat.h:864
qreal fixedValueOrPercentage
Definition: qtextformat.h:116
int size() const
Returns the number of items in the hash.
Definition: qhash.h:295
bool fixedPitch() const
Returns true if fixed pitch has been set; otherwise returns false.
Definition: qfont.cpp:1391
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
void merge(const QTextFormat &other)
Merges the other format with this format; where there are conflicts the other format takes precedence...
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
~QTextFormat()
Destroys this text format.
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
QString family() const
Returns the requested font family name, i.e.
Definition: qfont.cpp:906
void setOverline(bool)
If enable is true, sets overline on; otherwise sets overline off.
Definition: qfont.cpp:1354
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674
void setFixedPitch(bool)
If enable is true, sets fixed pitch on; otherwise sets fixed pitch off.
Definition: qfont.cpp:1402
QVariant property(int propertyId) const
Returns the property specified by the given propertyId.
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfont.h:343
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
qreal rightMargin() const
Returns the width of the frame&#39;s right margin in pixels.
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
Definition: qtextformat.h:727
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QTextLength class encapsulates the different types of length used in a QTextDocument.
Definition: qtextformat.h:84
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
float toFloat(bool *ok=0) const
Returns the variant as a float if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2725
void setFontFamily(const QString &family)
Sets the text format&#39;s font family.
Definition: qtextformat.h:401
bool boolProperty(int propertyId) const
Returns the value of the property specified by propertyId.
void setWeight(int)
Sets the weight the font to weight, which should be a value from the QFont::Weight enumeration...
Definition: qfont.cpp:1278
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
int weight() const
Returns the weight of the font which is one of the enumerated values from QFont::Weight.
Definition: qfont.cpp:1248
QVector< Property > props
void setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy=QFont::PreferDefault)
Sets the font style hint and strategy.
Definition: qtextformat.h:456
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
void insertProperty(qint32 key, const QVariant &value)
void setFontWordSpacing(qreal spacing)
Sets the word spacing of this format to the given spacing, in pixels.
Definition: qtextformat.h:427
The QTextTableCellFormat class provides formatting information for table cells in a QTextDocument...
Definition: qtextformat.h:898
QString stringProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn&#39;t of QVariant::String type...
void setPointSizeF(qreal)
Sets the point size to pointSize.
Definition: qfont.cpp:1121
QVector< qint32 > objFormats
Definition: qtextformat_p.h:99
The QTextTableFormat class provides formatting information for tables in a QTextDocument.
Definition: qtextformat.h:842
void setMargin(qreal margin)
Sets the frame&#39;s margin in pixels.
static uint variantHash(const QVariant &variant)
QTextCharFormat toCharFormat() const
Returns this format as a character format.
bool italic() const
Returns true if the style() of the font is not QFont::StyleNormal.
Definition: qfont.h:355
int pointSize() const
Returns the point size of the font.
Definition: qfont.cpp:981
const_iterator ConstIterator
Qt-style synonym for QVector::const_iterator.
Definition: qvector.h:279
bool operator!=(const Property &other) const
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
const char * variant
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
void setLetterSpacing(SpacingType type, qreal spacing)
Sets the letter spacing for the font to spacing and the type of spacing to type.
Definition: qfont.cpp:1696
int intProperty(int propertyId) const
Returns the value of the property specified by propertyId.
StyleStrategy styleStrategy() const
Returns the StyleStrategy.
Definition: qfont.cpp:1447
void setPixelSize(int)
Sets the font size to pixelSize pixels.
Definition: qfont.cpp:1156
void setObjectIndex(int object)
Sets the format object&#39;s object index.
bool strikeOut() const
Returns true if strikeout has been set; otherwise returns false.
Definition: qfont.cpp:1367
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
QTextImageFormat()
Creates a new image format object.
StyleHint styleHint() const
Returns the StyleHint.
Definition: qfont.cpp:1460
QPen penProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn&#39;t of QVariant::Pen type...
void setUnderlineStyle(UnderlineStyle style)
Sets the style of underlining the text to style.
bool hasFormatCached(const QTextFormat &format) const
int indexForFormat(const QTextFormat &f)
int propertyCount() const
Returns the number of properties stored in the format.
qreal doubleProperty(int propertyId) const
Returns the value of the property specified by propertyId.
QDataStream & operator<<(QDataStream &out, const QUrl &url)
Writes url url to the stream out and returns a reference to the stream.
Definition: qurl.cpp:6757
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
#define QT_TRY
Definition: qglobal.h:1536
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QTextFormat & operator=(const QTextFormat &rhs)
Assigns the other text format to this text format, and returns a reference to this text format...
bool fontUnderline() const
Returns true if the text format&#39;s font is underlined; otherwise returns false.
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
bool operator==(const QTextFormat &rhs) const
Returns true if this text format is the same as the other text format.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
qreal letterSpacing() const
Returns the letter spacing for the font.
Definition: qfont.cpp:1677
Each tab definition is represented by this struct.
Definition: qtextoption.h:69
QDataStream & operator>>(QDataStream &in, QUrl &url)
Reads a url into url from the stream in and returns a reference to the stream.
Definition: qurl.cpp:6774
QTextLength lengthProperty(int propertyId) const
Returns the value of the property given by propertyId.