summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@digia.com>2014-09-10 11:41:29 +0200
committerOswald Buddenhagen <oswald.buddenhagen@digia.com>2014-09-10 11:42:50 +0200
commitd572ab1bb446e880fcb8d27294ba8149550f1659 (patch)
treed29c449b551e47569c6d9f146ba9e86810c05353 /src/gui
parent211cef46f6d9d8738c09f906f9c0c3080b445dc8 (diff)
parent71df09b6cca7cd7a673bf39f49d0dda28b78a860 (diff)
Merge remote-tracking branch 'origin/5.4' into dev
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/accessible/qaccessible.cpp96
-rw-r--r--src/gui/image/qiconloader.cpp9
-rw-r--r--src/gui/image/qimage.cpp2
-rw-r--r--src/gui/image/qimage.h2
-rw-r--r--src/gui/kernel/qopenglwindow.h6
-rw-r--r--src/gui/opengl/qopengl.h6
-rw-r--r--src/gui/opengl/qopenglfunctions.h2
-rw-r--r--src/gui/opengl/qopenglgradientcache.cpp2
-rw-r--r--src/gui/opengl/qopenglvertexarrayobject.cpp10
-rw-r--r--src/gui/painting/qregion.cpp3
-rw-r--r--src/gui/text/qfontengine_ft.cpp25
-rw-r--r--src/gui/text/qfontengine_ft_p.h3
-rw-r--r--src/gui/text/qtextengine.cpp3
13 files changed, 141 insertions, 28 deletions
diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp
index f9fbc92d20..b3d7843506 100644
--- a/src/gui/accessible/qaccessible.cpp
+++ b/src/gui/accessible/qaccessible.cpp
@@ -1897,16 +1897,65 @@ QDebug operator<<(QDebug d, const QAccessibleEvent &ev)
*/
/*!
+ \internal
+ Helper for finding line breaks in textBeforeOffset/textAtOffset/textAfterOffset.
+ \a beforeAtAfter is the line we look for. -1 for before, 0 for at and 1 for after.
+*/
+static QString textLineBoundary(int beforeAtAfter, const QString &text, int offset, int *startOffset, int *endOffset)
+{
+ Q_ASSERT(beforeAtAfter >= -1 && beforeAtAfter <= 1);
+ Q_ASSERT(*startOffset == -1 && *endOffset == -1);
+ int length = text.length();
+ Q_ASSERT(offset >= 0 && offset <= length);
+
+ // move offset into the right range (if asking for line before or after
+ if (beforeAtAfter == 1) {
+ offset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1));
+ if (offset < 0)
+ return QString(); // after the last line comes nothing
+ ++offset; // move after the newline
+ } else if (beforeAtAfter == -1) {
+ offset = text.lastIndexOf(QChar::LineFeed, qMax(offset - 1, 0));
+ if (offset < 0)
+ return QString(); // before first line comes nothing
+ }
+
+ if (offset > 0)
+ *startOffset = text.lastIndexOf(QChar::LineFeed, offset - 1);
+ ++*startOffset; // move to the char after the newline (0 if lastIndexOf returned -1)
+
+ *endOffset = text.indexOf(QChar::LineFeed, qMin(offset, length - 1)) + 1; // include newline char
+ if (*endOffset <= 0 || *endOffset > length)
+ *endOffset = length; // if the text doesn't end with a newline it ends at length
+
+ return text.mid(*startOffset, *endOffset - *startOffset);
+}
+
+/*!
Returns the text item of type \a boundaryType that is close to offset \a offset
and sets \a startOffset and \a endOffset values to the start and end positions
of that item; returns an empty string if there is no such an item.
Sets \a startOffset and \a endOffset values to -1 on error.
+
+ This default implementation is provided for small text edits. A word processor or
+ text editor should provide their own efficient implementations. This function makes no
+ distinction between paragraphs and lines.
+
+ \note this function can not take the cursor position into account. By convention
+ an \a offset of -2 means that this function should use the cursor position as offset.
+ Thus an offset of -2 must be converted to the cursor position before calling this
+ function.
+ An offset of -1 is used for the text length and custom implementations of this function
+ have to return the result as if the length was passed in as offset.
*/
QString QAccessibleTextInterface::textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType,
int *startOffset, int *endOffset) const
{
const QString txt = text(0, characterCount());
+ if (offset == -1)
+ offset = txt.length();
+
*startOffset = *endOffset = -1;
if (txt.isEmpty() || offset <= 0 || offset > txt.length())
return QString();
@@ -1922,7 +1971,11 @@ QString QAccessibleTextInterface::textBeforeOffset(int offset, QAccessible::Text
case QAccessible::SentenceBoundary:
type = QTextBoundaryFinder::Sentence;
break;
- default:
+ case QAccessible::LineBoundary:
+ case QAccessible::ParagraphBoundary:
+ // Lines can not use QTextBoundaryFinder since Line there means any potential line-break.
+ return textLineBoundary(-1, txt, offset, startOffset, endOffset);
+ case QAccessible::NoBoundary:
// return empty, this function currently only supports single lines, so there can be no line before
return QString();
}
@@ -1954,12 +2007,26 @@ QString QAccessibleTextInterface::textBeforeOffset(int offset, QAccessible::Text
and sets \a startOffset and \a endOffset values to the start and end positions
of that item; returns an empty string if there is no such an item.
Sets \a startOffset and \a endOffset values to -1 on error.
+
+ This default implementation is provided for small text edits. A word processor or
+ text editor should provide their own efficient implementations. This function makes no
+ distinction between paragraphs and lines.
+
+ \note this function can not take the cursor position into account. By convention
+ an \a offset of -2 means that this function should use the cursor position as offset.
+ Thus an offset of -2 must be converted to the cursor position before calling this
+ function.
+ An offset of -1 is used for the text length and custom implementations of this function
+ have to return the result as if the length was passed in as offset.
*/
QString QAccessibleTextInterface::textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType,
int *startOffset, int *endOffset) const
{
const QString txt = text(0, characterCount());
+ if (offset == -1)
+ offset = txt.length();
+
*startOffset = *endOffset = -1;
if (txt.isEmpty() || offset < 0 || offset >= txt.length())
return QString();
@@ -1975,7 +2042,11 @@ QString QAccessibleTextInterface::textAfterOffset(int offset, QAccessible::TextB
case QAccessible::SentenceBoundary:
type = QTextBoundaryFinder::Sentence;
break;
- default:
+ case QAccessible::LineBoundary:
+ case QAccessible::ParagraphBoundary:
+ // Lines can not use QTextBoundaryFinder since Line there means any potential line-break.
+ return textLineBoundary(1, txt, offset, startOffset, endOffset);
+ case QAccessible::NoBoundary:
// return empty, this function currently only supports single lines, so there can be no line after
return QString();
}
@@ -2018,12 +2089,26 @@ QString QAccessibleTextInterface::textAfterOffset(int offset, QAccessible::TextB
and sets \a startOffset and \a endOffset values to the start and end positions
of that item; returns an empty string if there is no such an item.
Sets \a startOffset and \a endOffset values to -1 on error.
+
+ This default implementation is provided for small text edits. A word processor or
+ text editor should provide their own efficient implementations. This function makes no
+ distinction between paragraphs and lines.
+
+ \note this function can not take the cursor position into account. By convention
+ an \a offset of -2 means that this function should use the cursor position as offset.
+ Thus an offset of -2 must be converted to the cursor position before calling this
+ function.
+ An offset of -1 is used for the text length and custom implementations of this function
+ have to return the result as if the length was passed in as offset.
*/
QString QAccessibleTextInterface::textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType,
int *startOffset, int *endOffset) const
{
const QString txt = text(0, characterCount());
+ if (offset == -1)
+ offset = txt.length();
+
*startOffset = *endOffset = -1;
if (txt.isEmpty() || offset < 0 || offset > txt.length())
return QString();
@@ -2042,8 +2127,11 @@ QString QAccessibleTextInterface::textAtOffset(int offset, QAccessible::TextBoun
case QAccessible::SentenceBoundary:
type = QTextBoundaryFinder::Sentence;
break;
- default:
- // return the whole line
+ case QAccessible::LineBoundary:
+ case QAccessible::ParagraphBoundary:
+ // Lines can not use QTextBoundaryFinder since Line there means any potential line-break.
+ return textLineBoundary(0, txt, offset, startOffset, endOffset);
+ case QAccessible::NoBoundary:
*startOffset = 0;
*endOffset = txt.length();
return txt;
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
index 12d9f9f14d..5a4460dea3 100644
--- a/src/gui/image/qiconloader.cpp
+++ b/src/gui/image/qiconloader.cpp
@@ -69,7 +69,7 @@ Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
static QString fallbackTheme()
{
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
- const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconThemeName);
+ const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconFallbackThemeName);
if (themeHint.isValid())
return themeHint.toString();
}
@@ -561,15 +561,16 @@ void QIconLoaderEngine::virtual_hook(int id, void *data)
{
QIconEngine::AvailableSizesArgument &arg
= *reinterpret_cast<QIconEngine::AvailableSizesArgument*>(data);
- arg.sizes.clear();
const int N = m_entries.size();
- arg.sizes.reserve(N);
+ QList<QSize> sizes;
+ sizes.reserve(N);
// Gets all sizes from the DirectoryInfo entries
for (int i = 0; i < N; ++i) {
int size = m_entries.at(i)->dir.size;
- arg.sizes.append(QSize(size, size));
+ sizes.append(QSize(size, size));
}
+ arg.sizes.swap(sizes); // commit
}
break;
case QIconEngine::IconNameHook:
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index c3b4b1444a..5de686c1ea 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -1368,7 +1368,7 @@ void QImage::setColorTable(const QVector<QRgb> colors)
if (!d)
return;
- d->colortable = colors;
+ d->colortable = qMove(const_cast<QVector<QRgb>&>(colors));
d->has_alpha_clut = false;
for (int i = 0; i < d->colortable.size(); ++i) {
if (qAlpha(d->colortable.at(i)) != 255) {
diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h
index 844bbb2eba..3e73462efc 100644
--- a/src/gui/image/qimage.h
+++ b/src/gui/image/qimage.h
@@ -232,7 +232,7 @@ public:
void setPixel(const QPoint &pt, uint index_or_rgb);
QVector<QRgb> colorTable() const;
- void setColorTable(const QVector<QRgb> colors);
+ void setColorTable(const QVector<QRgb> colors); // ### Qt 6: remove const
qreal devicePixelRatio() const;
void setDevicePixelRatio(qreal scaleFactor);
diff --git a/src/gui/kernel/qopenglwindow.h b/src/gui/kernel/qopenglwindow.h
index 294bd90116..e30de3b6ac 100644
--- a/src/gui/kernel/qopenglwindow.h
+++ b/src/gui/kernel/qopenglwindow.h
@@ -42,6 +42,10 @@
#ifndef QOPENGLWINDOW_H
#define QOPENGLWINDOW_H
+#include <QtCore/qglobal.h>
+
+#ifndef QT_NO_OPENGL
+
#include <QtGui/QPaintDeviceWindow>
#include <QtGui/QOpenGLContext>
#include <QtGui/QImage>
@@ -97,4 +101,6 @@ private:
QT_END_NAMESPACE
+#endif // QT_NO_OPENGL
+
#endif
diff --git a/src/gui/opengl/qopengl.h b/src/gui/opengl/qopengl.h
index 65bfc7f868..56e99ee8b8 100644
--- a/src/gui/opengl/qopengl.h
+++ b/src/gui/opengl/qopengl.h
@@ -117,12 +117,6 @@ typedef char GLchar;
# include <QtGui/qopengles2ext.h>
# endif // Q_OS_MAC
-# ifndef GL_DOUBLE
-# define GL_DOUBLE GL_FLOAT
-# endif
-# ifndef GLdouble
-typedef GLfloat GLdouble;
-# endif
#else // non-ES2 platforms
# if defined(Q_OS_MAC)
# include <OpenGL/gl.h>
diff --git a/src/gui/opengl/qopenglfunctions.h b/src/gui/opengl/qopenglfunctions.h
index de1de39db2..b9e7523aad 100644
--- a/src/gui/opengl/qopenglfunctions.h
+++ b/src/gui/opengl/qopenglfunctions.h
@@ -563,8 +563,10 @@ struct QOpenGLFunctionsPrivate
void (QOPENGLF_APIENTRYP VertexAttribPointer)(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr);
// Special non-ES OpenGL variants, not to be called directly
+#ifndef QT_OPENGL_ES_2
void (QOPENGLF_APIENTRYP ClearDepth)(GLdouble depth);
void (QOPENGLF_APIENTRYP DepthRange)(GLdouble zNear, GLdouble zFar);
+#endif
};
// GLES2 + OpenGL1 common subset
diff --git a/src/gui/opengl/qopenglgradientcache.cpp b/src/gui/opengl/qopenglgradientcache.cpp
index 91b4d08474..f8060fc6a0 100644
--- a/src/gui/opengl/qopenglgradientcache.cpp
+++ b/src/gui/opengl/qopenglgradientcache.cpp
@@ -102,13 +102,13 @@ void QOpenGL2GradientCache::cleanCache()
GLuint QOpenGL2GradientCache::getBuffer(const QGradient &gradient, qreal opacity)
{
- QMutexLocker lock(&m_mutex);
quint64 hash_val = 0;
QGradientStops stops = gradient.stops();
for (int i = 0; i < stops.size() && i <= 2; i++)
hash_val += stops[i].second.rgba();
+ const QMutexLocker lock(&m_mutex);
QOpenGLGradientColorTableHash::const_iterator it = cache.constFind(hash_val);
if (it == cache.constEnd())
diff --git a/src/gui/opengl/qopenglvertexarrayobject.cpp b/src/gui/opengl/qopenglvertexarrayobject.cpp
index f39b10dc60..15f08ddfce 100644
--- a/src/gui/opengl/qopenglvertexarrayobject.cpp
+++ b/src/gui/opengl/qopenglvertexarrayobject.cpp
@@ -391,6 +391,16 @@ QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject()
that supports vertex array objects current for this function to succeed.
Returns \c true if the OpenGL vertex array object was successfully created.
+
+ When the return value is \c false, vertex array object support is not available. This
+ is not an error: on systems with OpenGL 2.x or OpenGL ES 2.0 vertex array objects may
+ not be supported. The application is free to continue execution in this case, but it
+ then has to be prepared to operate in a VAO-less manner too. This means that instead
+ of merely calling bind(), the value of isCreated() must be checked and the vertex
+ arrays has to be initialized in the traditional way when there is no vertex array
+ object present.
+
+ \sa isCreated()
*/
bool QOpenGLVertexArrayObject::create()
{
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp
index eb197378ad..549dce2923 100644
--- a/src/gui/painting/qregion.cpp
+++ b/src/gui/painting/qregion.cpp
@@ -3521,8 +3521,7 @@ static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule)
POINTBLOCK *tmpPtBlock;
int numFullPtBlocks = 0;
- if (!(region = new QRegionPrivate))
- return 0;
+ region = new QRegionPrivate;
/* special case a rectangle */
if (((Count == 4) ||
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index cb3cb34d27..0a22038bb4 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -132,6 +132,7 @@ static bool ft_getSfntTable(void *user_data, uint tag, uchar *buffer, uint *leng
return result;
}
+static QFontEngineFT::Glyph emptyGlyph = {0, 0, 0, 0, 0, 0, 0, 0};
// -------------------------- Freetype support ------------------------------
@@ -858,6 +859,9 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph,
if (g && g->format == format && (fetchMetricsOnly || g->data))
return g;
+ if (!g && set && set->isGlyphMissing(glyph))
+ return &emptyGlyph;
+
QFontEngineFT::GlyphInfo info;
Q_ASSERT(format != Format_None);
@@ -894,8 +898,12 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph,
load_flags |= FT_LOAD_FORCE_AUTOHINT;
err = FT_Load_Glyph(face, glyph, load_flags);
}
- if (err != FT_Err_Ok)
+ if (err != FT_Err_Ok) {
qWarning("load glyph failed err=%x face=%p, glyph=%d", err, face, glyph);
+ if (set)
+ set->setGlyphMissing(glyph);
+ return &emptyGlyph;
+ }
FT_GlyphSlot slot = face->glyph;
@@ -1633,9 +1641,12 @@ void QFontEngineFT::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlag
if (!face)
face = lockFace();
g = loadGlyph(cacheEnabled ? &defaultGlyphSet : 0, glyphs->glyphs[i], 0, Format_None, true);
- glyphs->advances[i] = design ? QFixed::fromFixed(face->glyph->linearHoriAdvance >> 10)
- : QFixed::fromFixed(face->glyph->metrics.horiAdvance).round();
- if (!cacheEnabled)
+ if (g)
+ glyphs->advances[i] = design ? QFixed::fromFixed(g->linearAdvance) : QFixed(g->advance);
+ else
+ glyphs->advances[i] = design ? QFixed::fromFixed(face->glyph->linearHoriAdvance >> 10)
+ : QFixed::fromFixed(face->glyph->metrics.horiAdvance).round();
+ if (!cacheEnabled && g != &emptyGlyph)
delete g;
}
}
@@ -1674,7 +1685,7 @@ glyph_metrics_t QFontEngineFT::boundingBox(const QGlyphLayout &glyphs)
xmax = qMax(xmax, x + g->width);
ymax = qMax(ymax, y + g->height);
overall.xoff += g->advance;
- if (!cacheEnabled)
+ if (!cacheEnabled && g != &emptyGlyph)
delete g;
} else {
int left = FLOOR(face->glyph->metrics.horiBearingX);
@@ -1717,7 +1728,7 @@ glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph)
overall.xoff = g->advance;
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics)
overall.xoff = overall.xoff.round();
- if (!cacheEnabled)
+ if (!cacheEnabled && g != &emptyGlyph)
delete g;
} else {
int left = FLOOR(face->glyph->metrics.horiBearingX);
@@ -1808,7 +1819,7 @@ glyph_metrics_t QFontEngineFT::alphaMapBoundingBox(glyph_t glyph, QFixed subPixe
overall.width = g->width;
overall.height = g->height;
overall.xoff = g->advance;
- if (!glyphSet)
+ if (!glyphSet && g != &emptyGlyph)
delete g;
} else {
int left = FLOOR(face->glyph->metrics.horiBearingX);
diff --git a/src/gui/text/qfontengine_ft_p.h b/src/gui/text/qfontengine_ft_p.h
index 09c70c5083..e23024e472 100644
--- a/src/gui/text/qfontengine_ft_p.h
+++ b/src/gui/text/qfontengine_ft_p.h
@@ -187,8 +187,11 @@ public:
inline Glyph *getGlyph(glyph_t index, QFixed subPixelPosition = 0) const;
void setGlyph(glyph_t index, QFixed spp, Glyph *glyph);
+ inline bool isGlyphMissing(glyph_t index) const { return missing_glyphs.contains(index); }
+ inline void setGlyphMissing(glyph_t index) const { missing_glyphs.insert(index); }
private:
mutable QHash<GlyphAndSubPixelPosition, Glyph *> glyph_data; // maps from glyph index to glyph data
+ mutable QSet<glyph_t> missing_glyphs;
mutable Glyph *fast_glyph_data[256]; // for fast lookup of glyphs < 256
mutable int fast_glyph_count;
};
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 17bc4fde98..2db8b3fc1b 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -2385,8 +2385,7 @@ bool QTextEngine::LayoutData::reallocate(int totalGlyphs)
return false;
}
- void **newMem = memory;
- newMem = (void **)::realloc(memory_on_stack ? 0 : memory, newAllocated*sizeof(void *));
+ void **newMem = (void **)::realloc(memory_on_stack ? 0 : memory, newAllocated*sizeof(void *));
if (!newMem) {
layoutState = LayoutFailed;
return false;