summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qdistancefield.cpp5
-rw-r--r--src/gui/text/qfontdatabase.cpp80
-rw-r--r--src/gui/text/qfontengine.cpp25
-rw-r--r--src/gui/text/qfontengine_ft.cpp11
-rw-r--r--src/gui/text/qfontengine_qpf2.cpp2
-rw-r--r--src/gui/text/qfragmentmap_p.h2
-rw-r--r--src/gui/text/qtextdocument.cpp166
-rw-r--r--src/gui/text/qtextdocument.h10
-rw-r--r--src/gui/text/qtextformat.cpp20
9 files changed, 229 insertions, 92 deletions
diff --git a/src/gui/text/qdistancefield.cpp b/src/gui/text/qdistancefield.cpp
index ca6cafb13c..38215cd418 100644
--- a/src/gui/text/qdistancefield.cpp
+++ b/src/gui/text/qdistancefield.cpp
@@ -34,6 +34,7 @@
#include "qdistancefield_p.h"
#include <qmath.h>
#include <private/qdatabuffer_p.h>
+#include <private/qimage_p.h>
#include <private/qpathsimplifier_p.h>
QT_BEGIN_NAMESPACE
@@ -987,12 +988,12 @@ QImage QDistanceField::toImage(QImage::Format format) const
if (isNull())
return QImage();
- QImage image(d->width, d->height, format == QImage::Format_Indexed8 ?
+ QImage image(d->width, d->height, qt_depthForFormat(format) == 8 ?
format : QImage::Format_ARGB32_Premultiplied);
if (image.isNull())
return image;
- if (format == QImage::Format_Indexed8) {
+ if (image.depth() == 8) {
for (int y = 0; y < d->height; ++y)
memcpy(image.scanLine(y), scanLine(y), d->width);
} else {
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 1322a088e0..decf2fe121 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -84,20 +84,22 @@ static int getFontWeight(const QString &weightString)
{
QString s = weightString.toLower();
- // Test in decreasing order of commonness
- if (s == QLatin1String("normal")
- || s.compare(QCoreApplication::translate("QFontDatabase", "Normal"), Qt::CaseInsensitive) == 0)
+ // Order here is important. We want to match the common cases first, but we
+ // must also take care to acknowledge the cost of our tests.
+ //
+ // As a result, we test in two orders; the order of commonness, and the
+ // order of "expense".
+ //
+ // A simple string test is the cheapest, so let's do that first.
+ if (s == QLatin1String("normal"))
return QFont::Normal;
if (s == QLatin1String("medium"))
return qt_mediumFontWeight;
- if (s == QLatin1String("bold")
- || s.compare(QCoreApplication::translate("QFontDatabase", "Bold"), Qt::CaseInsensitive) == 0)
+ if (s == QLatin1String("bold"))
return QFont::Bold;
- if (s == QLatin1String("demibold") || s == QLatin1String("demi bold")
- || s.compare(QCoreApplication::translate("QFontDatabase", "Demi Bold"), Qt::CaseInsensitive) == 0)
+ if (s == QLatin1String("demibold") || s == QLatin1String("demi bold"))
return QFont::DemiBold;
- if (s == QLatin1String("black")
- || s.compare(QCoreApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
+ if (s == QLatin1String("black"))
return QFont::Black;
if (s == QLatin1String("light"))
return QFont::Light;
@@ -106,23 +108,48 @@ static int getFontWeight(const QString &weightString)
if (s == QLatin1String("extralight"))
return qt_extralightFontWeight;
- if (s.contains(QLatin1String("bold"))
- || s.contains(QCoreApplication::translate("QFontDatabase", "Bold"), Qt::CaseInsensitive)) {
- if (s.contains(QLatin1String("demi"))
- || s.compare(QCoreApplication::translate("QFontDatabase", "Demi"), Qt::CaseInsensitive) == 0)
- return (int) QFont::DemiBold;
- return (int) QFont::Bold;
+ // Next up, let's see if contains() matches: slightly more expensive, but
+ // still fast enough.
+ if (s.contains(QLatin1String("bold"))) {
+ if (s.contains(QLatin1String("demi")))
+ return QFont::DemiBold;
+ return QFont::Bold;
}
+ if (s.contains(QLatin1String("light")))
+ return QFont::Light;
+ if (s.contains(QLatin1String("black")))
+ return QFont::Black;
- if (s.contains(QLatin1String("light"))
- || s.compare(QCoreApplication::translate("QFontDatabase", "Light"), Qt::CaseInsensitive) == 0)
- return (int) QFont::Light;
+ // Now, we perform string translations & comparisons with those.
+ // These are (very) slow compared to simple string ops, so we do these last.
+ // As using translated values for such things is not very common, this should
+ // not be too bad.
+ QString translatedNormal = QCoreApplication::translate("QFontDatabase", "Normal").toLower();
+ if (s == translatedNormal)
+ return QFont::Normal;
+ QString translatedBold = QCoreApplication::translate("QFontDatabase", "Bold").toLower();
+ if (s == translatedBold)
+ return QFont::Bold;
+ QString translatedDemiBold = QCoreApplication::translate("QFontDatabase", "Demi Bold").toLower();
+ if (s == translatedDemiBold)
+ return QFont::DemiBold;
+ QString translatedBlack = QCoreApplication::translate("QFontDatabase", "Black").toLower();
+ if (s == translatedBlack)
+ return QFont::Black;
- if (s.contains(QLatin1String("black"))
- || s.compare(QCoreApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
- return (int) QFont::Black;
+ // And now the contains() checks for the translated strings.
+ if (s.contains(translatedBold)) {
+ QString translatedDemi = QCoreApplication::translate("QFontDatabase", "Demi").toLower();
+ if (s == translatedDemi)
+ return QFont::DemiBold;
+ return QFont::Bold;
+ }
+
+ QString translatedLight = QCoreApplication::translate("QFontDatabase", "Light").toLower();
+ if (s == translatedLight || s.contains(translatedLight))
+ return QFont::Light;
- return (int) QFont::Normal;
+ return QFont::Normal;
}
// convert 0 ~ 1000 integer to QFont::Weight
@@ -1562,6 +1589,15 @@ bool QFontDatabase::isSmoothlyScalable(const QString &family, const QString &sty
QtFontStyle::Key styleKey(style);
QtFontFamily *f = d->family(familyName);
+ if (!f) {
+ for (int i = 0; i < d->count; i++) {
+ if (d->families[i]->matchesFamilyName(familyName)) {
+ f = d->families[i];
+ f->ensurePopulated();
+ break;
+ }
+ }
+ }
if (!f) return smoothScalable;
for (int j = 0; j < f->count; j++) {
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index 6a34a4c117..fe0f9fa943 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -763,7 +763,7 @@ QImage QFontEngine::alphaMapForGlyph(glyph_t glyph, const QTransform &t)
{
QImage i = alphaMapForGlyph(glyph);
if (t.type() > QTransform::TxTranslate)
- i = i.transformed(t).convertToFormat(QImage::Format_Indexed8);
+ i = i.transformed(t).convertToFormat(QImage::Format_Alpha8);
Q_ASSERT(i.depth() <= 8); // To verify that transformed didn't change the format...
return i;
@@ -776,7 +776,7 @@ QImage QFontEngine::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, con
QImage i = alphaMapForGlyph(glyph, subPixelPosition);
if (t.type() > QTransform::TxTranslate)
- i = i.transformed(t).convertToFormat(QImage::Format_Indexed8);
+ i = i.transformed(t).convertToFormat(QImage::Format_Alpha8);
Q_ASSERT(i.depth() <= 8); // To verify that transformed didn't change the format...
return i;
@@ -787,12 +787,11 @@ QImage QFontEngine::alphaRGBMapForGlyph(glyph_t glyph, QFixed /*subPixelPosition
QImage alphaMask = alphaMapForGlyph(glyph, t);
QImage rgbMask(alphaMask.width(), alphaMask.height(), QImage::Format_RGB32);
- QVector<QRgb> colorTable = alphaMask.colorTable();
for (int y=0; y<alphaMask.height(); ++y) {
uint *dst = (uint *) rgbMask.scanLine(y);
uchar *src = (uchar *) alphaMask.scanLine(y);
for (int x=0; x<alphaMask.width(); ++x) {
- int val = qAlpha(colorTable.at(src[x]));
+ int val = src[x];
dst[x] = qRgb(val, val, val);
}
}
@@ -873,20 +872,16 @@ QImage QFontEngine::alphaMapForGlyph(glyph_t glyph)
p.drawPath(path);
p.end();
- QImage indexed(im.width(), im.height(), QImage::Format_Indexed8);
- QVector<QRgb> colors(256);
- for (int i=0; i<256; ++i)
- colors[i] = qRgba(0, 0, 0, i);
- indexed.setColorTable(colors);
+ QImage alphaMap(im.width(), im.height(), QImage::Format_Alpha8);
for (int y=0; y<im.height(); ++y) {
- uchar *dst = (uchar *) indexed.scanLine(y);
+ uchar *dst = (uchar *) alphaMap.scanLine(y);
uint *src = (uint *) im.scanLine(y);
for (int x=0; x<im.width(); ++x)
dst[x] = qAlpha(src[x]);
}
- return indexed;
+ return alphaMap;
}
void QFontEngine::removeGlyphFromCache(glyph_t)
@@ -1537,14 +1532,10 @@ bool QFontEngineBox::canRender(const QChar *, int) const
QImage QFontEngineBox::alphaMapForGlyph(glyph_t)
{
- QImage image(_size, _size, QImage::Format_Indexed8);
- QVector<QRgb> colors(256);
- for (int i=0; i<256; ++i)
- colors[i] = qRgba(0, 0, 0, i);
- image.setColorTable(colors);
+ QImage image(_size, _size, QImage::Format_Alpha8);
image.fill(0);
- // can't use qpainter for index8; so use setPixel to draw our rectangle.
+ // FIXME: use qpainter
for (int i=2; i <= _size-3; ++i) {
image.setPixel(i, 2, 255);
image.setPixel(i, _size-3, 255);
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index b0cfa49b36..b44eb43be5 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -1851,7 +1851,7 @@ QImage *QFontEngineFT::lockedAlphaMapForGlyph(glyph_t glyphIndex, QFixed subPixe
format = QImage::Format_Mono;
break;
case Format_A8:
- format = QImage::Format_Indexed8;
+ format = QImage::Format_Alpha8;
break;
case Format_A32:
format = QImage::Format_ARGB32;
@@ -1961,13 +1961,8 @@ QImage QFontEngineFT::alphaMapForGlyph(glyph_t g, QFixed subPixelPosition)
const int pitch = antialias ? (glyph->width + 3) & ~3 : ((glyph->width + 31)/32) * 4;
- QImage img(glyph->width, glyph->height, antialias ? QImage::Format_Indexed8 : QImage::Format_Mono);
- if (antialias) {
- QVector<QRgb> colors(256);
- for (int i=0; i<256; ++i)
- colors[i] = qRgba(0, 0, 0, i);
- img.setColorTable(colors);
- } else {
+ QImage img(glyph->width, glyph->height, antialias ? QImage::Format_Alpha8 : QImage::Format_Mono);
+ if (!antialias) {
QVector<QRgb> colors(2);
colors[0] = qRgba(0, 0, 0, 0);
colors[1] = qRgba(0, 0, 0, 255);
diff --git a/src/gui/text/qfontengine_qpf2.cpp b/src/gui/text/qfontengine_qpf2.cpp
index 4785902c99..8e924102e5 100644
--- a/src/gui/text/qfontengine_qpf2.cpp
+++ b/src/gui/text/qfontengine_qpf2.cpp
@@ -396,7 +396,7 @@ QImage QFontEngineQPF2::alphaMapForGlyph(glyph_t g)
const uchar *bits = ((const uchar *) glyph) + sizeof(Glyph);
- QImage image(bits,glyph->width, glyph->height, glyph->bytesPerLine, QImage::Format_Indexed8);
+ QImage image(bits,glyph->width, glyph->height, glyph->bytesPerLine, QImage::Format_Alpha8);
return image;
}
diff --git a/src/gui/text/qfragmentmap_p.h b/src/gui/text/qfragmentmap_p.h
index 012d3c25ce..a19e3d9ea3 100644
--- a/src/gui/text/qfragmentmap_p.h
+++ b/src/gui/text/qfragmentmap_p.h
@@ -249,6 +249,8 @@ uint QFragmentMapData<Fragment>::createFragment()
uint freePos = head->freelist;
if (freePos == head->allocated) {
// need to create some free space
+ if (freePos >= uint(MaxAllocSize) / fragmentSize)
+ qBadAlloc();
uint needed = qAllocMore((freePos+1)*fragmentSize, 0);
Q_ASSERT(needed/fragmentSize > head->allocated);
Fragment *newFragments = (Fragment *)realloc(fragments, needed);
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index ea2b794feb..3820b415a3 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -40,6 +40,7 @@
#include "qtextlist.h"
#include <qdebug.h>
#include <qregexp.h>
+#include <qregularexpression.h>
#include <qvarlengtharray.h>
#include <qtextcodec.h>
#include <qthread.h>
@@ -1269,8 +1270,6 @@ QTextCursor QTextDocument::find(const QString &subString, int from, FindFlags op
}
/*!
- \fn QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &cursor, FindFlags options) const
-
Finds the next occurrence of the string, \a subString, in the document.
The search starts at the position of the given \a cursor, and proceeds
forwards through the document unless specified otherwise in the search
@@ -1285,14 +1284,14 @@ QTextCursor QTextDocument::find(const QString &subString, int from, FindFlags op
By default the search is case-sensitive, and can match text anywhere in the
document.
*/
-QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &from, FindFlags options) const
+QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &cursor, FindFlags options) const
{
int pos = 0;
- if (!from.isNull()) {
+ if (!cursor.isNull()) {
if (options & QTextDocument::FindBackward)
- pos = from.selectionStart();
+ pos = cursor.selectionStart();
else
- pos = from.selectionEnd();
+ pos = cursor.selectionEnd();
}
QRegExp expr(subString);
expr.setPatternSyntax(QRegExp::FixedString);
@@ -1303,7 +1302,7 @@ QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &fro
static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int offset,
- QTextDocument::FindFlags options, QTextCursor &cursor)
+ QTextDocument::FindFlags options, QTextCursor *cursor)
{
QRegExp expr(expression);
QString text = block.text();
@@ -1332,18 +1331,16 @@ static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int
}
if (idx == -1)
return false;
- cursor = QTextCursor(block.docHandle(), block.position() + idx);
- cursor.setPosition(cursor.position() + expr.matchedLength(), QTextCursor::KeepAnchor);
+ *cursor = QTextCursor(block.docHandle(), block.position() + idx);
+ cursor->setPosition(cursor->position() + expr.matchedLength(), QTextCursor::KeepAnchor);
return true;
}
/*!
- \fn QTextCursor QTextDocument::find(const QRegExp & expr, int position, FindFlags options) const
-
\overload
Finds the next occurrence, matching the regular expression, \a expr, in the document.
- The search starts at the given \a position, and proceeds forwards
+ The search starts at the given \a from position, and proceeds forwards
through the document unless specified otherwise in the search options.
The \a options control the type of search performed. The FindCaseSensitively
option is ignored for this overload, use QRegExp::caseSensitivity instead.
@@ -1351,7 +1348,7 @@ static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int
Returns a cursor with the match selected if a match was found; otherwise
returns a null cursor.
- If the \a position is 0 (the default) the search begins from the beginning
+ If the \a from position is 0 (the default) the search begins from the beginning
of the document; otherwise it begins at the specified position.
*/
QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags options) const
@@ -1376,7 +1373,7 @@ QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags option
if (!(options & FindBackward)) {
int blockOffset = qMax(0, pos - block.position());
while (block.isValid()) {
- if (findInBlock(block, expr, blockOffset, options, cursor))
+ if (findInBlock(block, expr, blockOffset, options, &cursor))
return cursor;
blockOffset = 0;
block = block.next();
@@ -1384,7 +1381,7 @@ QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags option
} else {
int blockOffset = pos - block.position();
while (block.isValid()) {
- if (findInBlock(block, expr, blockOffset, options, cursor))
+ if (findInBlock(block, expr, blockOffset, options, &cursor))
return cursor;
block = block.previous();
blockOffset = block.length() - 1;
@@ -1395,10 +1392,10 @@ QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags option
}
/*!
- \fn QTextCursor QTextDocument::find(const QRegExp &expr, const QTextCursor &cursor, FindFlags options) const
+ \overload
Finds the next occurrence, matching the regular expression, \a expr, in the document.
- The search starts at the position of the given \a cursor, and proceeds
+ The search starts at the position of the given \a from cursor, and proceeds
forwards through the document unless specified otherwise in the search
options. The \a options control the type of search performed. The FindCaseSensitively
option is ignored for this overload, use QRegExp::caseSensitivity instead.
@@ -1406,24 +1403,149 @@ QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags option
Returns a cursor with the match selected if a match was found; otherwise
returns a null cursor.
- If the given \a cursor has a selection, the search begins after the
+ If the given \a from cursor has a selection, the search begins after the
selection; otherwise it begins at the cursor's position.
By default the search is case-sensitive, and can match text anywhere in the
document.
*/
-QTextCursor QTextDocument::find(const QRegExp &expr, const QTextCursor &from, FindFlags options) const
+QTextCursor QTextDocument::find(const QRegExp &expr, const QTextCursor &cursor, FindFlags options) const
{
int pos = 0;
- if (!from.isNull()) {
+ if (!cursor.isNull()) {
if (options & QTextDocument::FindBackward)
- pos = from.selectionStart();
+ pos = cursor.selectionStart();
else
- pos = from.selectionEnd();
+ pos = cursor.selectionEnd();
}
return find(expr, pos, options);
}
+#ifndef QT_NO_REGULAREXPRESSION
+static bool findInBlock(const QTextBlock &block, const QRegularExpression &expression, int offset,
+ QTextDocument::FindFlags options, QTextCursor *cursor)
+{
+ QRegularExpression expr(expression);
+ if (!(options & QTextDocument::FindCaseSensitively))
+ expr.setPatternOptions(expr.patternOptions() | QRegularExpression::CaseInsensitiveOption);
+ else
+ expr.setPatternOptions(expr.patternOptions() & ~QRegularExpression::CaseInsensitiveOption);
+
+ QString text = block.text();
+ text.replace(QChar::Nbsp, QLatin1Char(' '));
+ QRegularExpressionMatch match;
+ int idx = -1;
+
+ while (offset >= 0 && offset <= text.length()) {
+ idx = (options & QTextDocument::FindBackward) ?
+ text.lastIndexOf(expr, offset, &match) : text.indexOf(expr, offset, &match);
+ if (idx == -1)
+ return false;
+
+ if (options & QTextDocument::FindWholeWords) {
+ const int start = idx;
+ const int end = start + match.capturedLength();
+ if ((start != 0 && text.at(start - 1).isLetterOrNumber())
+ || (end != text.length() && text.at(end).isLetterOrNumber())) {
+ //if this is not a whole word, continue the search in the string
+ offset = (options & QTextDocument::FindBackward) ? idx-1 : end+1;
+ idx = -1;
+ continue;
+ }
+ }
+ //we have a hit, return the cursor for that.
+ break;
+ }
+ if (idx == -1)
+ return false;
+ *cursor = qMove(QTextCursor(block.docHandle(), block.position() + idx));
+ cursor->setPosition(cursor->position() + match.capturedLength(), QTextCursor::KeepAnchor);
+ return true;
+}
+
+/*!
+ \since 5.5
+
+ Finds the next occurrence, matching the regular expression, \a expr, in the document.
+ The search starts at the given \a from position, and proceeds forwards
+ through the document unless specified otherwise in the search options.
+ The \a options control the type of search performed.
+
+ Returns a cursor with the match selected if a match was found; otherwise
+ returns a null cursor.
+
+ If the \a from position is 0 (the default) the search begins from the beginning
+ of the document; otherwise it begins at the specified position.
+*/
+QTextCursor QTextDocument::find(const QRegularExpression &expr, int from, FindFlags options) const
+{
+ Q_D(const QTextDocument);
+
+ if (!expr.isValid())
+ return QTextCursor();
+
+ int pos = from;
+ //the cursor is positioned between characters, so for a backward search
+ //do not include the character given in the position.
+ if (options & FindBackward) {
+ --pos ;
+ if (pos < 0)
+ return QTextCursor();
+ }
+
+ QTextCursor cursor;
+ QTextBlock block = d->blocksFind(pos);
+
+ if (!(options & FindBackward)) {
+ int blockOffset = qMax(0, pos - block.position());
+ while (block.isValid()) {
+ if (findInBlock(block, expr, blockOffset, options, &cursor))
+ return cursor;
+ blockOffset = 0;
+ block = block.next();
+ }
+ } else {
+ int blockOffset = pos - block.position();
+ while (block.isValid()) {
+ if (findInBlock(block, expr, blockOffset, options, &cursor))
+ return cursor;
+ block = block.previous();
+ blockOffset = block.length() - 1;
+ }
+ }
+
+ return QTextCursor();
+}
+
+/*!
+ \since 5.5
+
+ Finds the next occurrence, matching the regular expression, \a expr, in the document.
+ The search starts at the position of the given \a cursor, and proceeds
+ forwards through the document unless specified otherwise in the search
+ options. The \a options control the type of search performed.
+
+ Returns a cursor with the match selected if a match was found; otherwise
+ returns a null cursor.
+
+ If the given \a cursor has a selection, the search begins after the
+ selection; otherwise it begins at the cursor's position.
+
+ By default the search is case-sensitive, and can match text anywhere in the
+ document.
+*/
+QTextCursor QTextDocument::find(const QRegularExpression &expr, const QTextCursor &cursor, FindFlags options) const
+{
+ int pos = 0;
+ if (!cursor.isNull()) {
+ if (options & QTextDocument::FindBackward)
+ pos = cursor.selectionStart();
+ else
+ pos = cursor.selectionEnd();
+ }
+ return find(expr, pos, options);
+}
+#endif // QT_NO_REGULAREXPRESSION
/*!
\fn QTextObject *QTextDocument::createObject(const QTextFormat &format)
diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h
index 2329a9e721..83e255bd96 100644
--- a/src/gui/text/qtextdocument.h
+++ b/src/gui/text/qtextdocument.h
@@ -160,10 +160,14 @@ public:
Q_DECLARE_FLAGS(FindFlags, FindFlag)
QTextCursor find(const QString &subString, int from = 0, FindFlags options = 0) const;
- QTextCursor find(const QString &subString, const QTextCursor &from, FindFlags options = 0) const;
-
+ QTextCursor find(const QString &subString, const QTextCursor &cursor, FindFlags options = 0) const;
QTextCursor find(const QRegExp &expr, int from = 0, FindFlags options = 0) const;
- QTextCursor find(const QRegExp &expr, const QTextCursor &from, FindFlags options = 0) const;
+ QTextCursor find(const QRegExp &expr, const QTextCursor &cursor, FindFlags options = 0) const;
+
+#ifndef QT_NO_REGULAREXPRESSION
+ QTextCursor find(const QRegularExpression &expr, int from = 0, FindFlags options = 0) const;
+ QTextCursor find(const QRegularExpression &expr, const QTextCursor &cursor, FindFlags options = 0) const;
+#endif
QTextFrame *frameAt(int pos) const;
QTextFrame *rootFrame() const;
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index cecfd85df1..1502758ee8 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -258,20 +258,6 @@ private:
friend QDataStream &operator>>(QDataStream &, QTextFormat &);
};
-// this is only safe because sizeof(int) == sizeof(float)
-static inline uint hash(float d)
-{
-#ifdef Q_CC_GNU
- // this is a GCC extension and isn't guaranteed to work in other compilers
- // the reinterpret_cast below generates a strict-aliasing warning with GCC
- union { float f; uint u; } cvt;
- cvt.f = d;
- return cvt.u;
-#else
- return reinterpret_cast<uint&>(d);
-#endif
-}
-
static inline uint hash(const QColor &color)
{
return (color.isValid()) ? color.rgba() : 0x234109;
@@ -279,7 +265,7 @@ static inline uint hash(const QColor &color)
static inline uint hash(const QPen &pen)
{
- return hash(pen.color()) + hash(pen.widthF());
+ return hash(pen.color()) + qHash(pen.widthF());
}
static inline uint hash(const QBrush &brush)
@@ -292,7 +278,7 @@ static inline uint variantHash(const QVariant &variant)
// simple and fast hash functions to differentiate between type and value
switch (variant.userType()) { // sorted by occurrence frequency
case QVariant::String: return qHash(variant.toString());
- case QVariant::Double: return hash(variant.toDouble());
+ case QVariant::Double: return qHash(variant.toDouble());
case QVariant::Int: return 0x811890 + variant.toInt();
case QVariant::Brush:
return 0x01010101 + hash(qvariant_cast<QBrush>(variant));
@@ -303,7 +289,7 @@ static inline uint variantHash(const QVariant &variant)
case QVariant::Color: return hash(qvariant_cast<QColor>(variant));
case QVariant::TextLength:
return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue());
- case QMetaType::Float: return hash(variant.toFloat());
+ case QMetaType::Float: return qHash(variant.toFloat());
case QVariant::Invalid: return 0;
default: break;
}