diff options
Diffstat (limited to 'src/gui')
25 files changed, 473 insertions, 84 deletions
diff --git a/src/gui/dialogs/qfilesystemmodel.cpp b/src/gui/dialogs/qfilesystemmodel.cpp index 2c46ae4..bdf0909 100644 --- a/src/gui/dialogs/qfilesystemmodel.cpp +++ b/src/gui/dialogs/qfilesystemmodel.cpp @@ -381,16 +381,12 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) { - if (!pathElements.at(0).contains(QLatin1String(":"))) -#if defined(Q_CC_NOKIAX86) - { - // Workaround for bizarre compiler crash. + if (!pathElements.at(0).contains(QLatin1String(":"))) { + // The reason we express it like this instead of with anonymous, temporary + // variables, is to workaround a compiler crash with Q_CC_NOKIAX86. QString rootPath = QDir(longPath).rootPath(); pathElements.prepend(rootPath); } -#else - pathElements.prepend(QDir(longPath).rootPath()); -#endif if (pathElements.at(0).endsWith(QLatin1Char('/'))) pathElements[0].chop(1); } diff --git a/src/gui/dialogs/qfscompleter_p.h b/src/gui/dialogs/qfscompleter_p.h index 2e5a674..fde7706 100644 --- a/src/gui/dialogs/qfscompleter_p.h +++ b/src/gui/dialogs/qfscompleter_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QCOMPLETOR_P_H -#define QCOMPLETOR_P_H +#ifndef QFSCOMPLETOR_P_H +#define QFSCOMPLETOR_P_H // // W A R N I N G @@ -78,5 +78,5 @@ public: }; #endif // QT_NO_COMPLETER QT_END_NAMESPACE -#endif // QCOMPLETOR_P_H +#endif // QFSCOMPLETOR_P_H diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp index e5b8632..ab02999 100644 --- a/src/gui/effects/qgraphicseffect.cpp +++ b/src/gui/effects/qgraphicseffect.cpp @@ -52,9 +52,10 @@ disabled by calling setEnabled(); if the effect is disabled, the source is rendered directly. - If you want to add a visual effect to a QGraphicsItem, you can either use + If you want to add a visual effect to a e.g. a QGraphicsItem, you can either use one of the standard effects, or create your own effect by making a subclass - of QGraphicsEffect. + of QGraphicsEffect. The effect can then be installed on the item by calling + QGraphicsItem::setGraphicsEffect. Qt provides several standard effects, including: @@ -64,7 +65,8 @@ \o QGraphicsPixelizeEffect - pixelizes the item with any pixel size \o QGraphicsBlurEffect - blurs the item by a given radius \o QGraphicsDropShadowEffect - renders a dropshadow behind the item - \o QGraphicsBlurEffect - renders the item with an opacity + \o QGraphicsOpacityEffect - renders the item with an opacity + \o QGrahicsShaderEffect - renders the item with a pixel shader fragment \endlist If all you want is to add an effect to an item, you should visit the @@ -90,7 +92,8 @@ the source's bounding rectangle has changed (e.g., if the source is a QGraphicsRectItem, then if the rectangle parameters have changed). - \sa QGraphicsItem::setGraphicsEffect() + \sa QGraphicsItem::setGraphicsEffect(), QWidget::setGraphicsEffect(), + QGraphicsEffectSource */ #include "qgraphicseffect_p.h" @@ -102,6 +105,21 @@ QT_BEGIN_NAMESPACE +/*! + \class QGraphicsEffectSource + \brief The QGraphicsEffectSource represents the source of which a QGraphicsEffect + is installed on. + \since 4.6 + + When a QGraphicsEffect is installed on e.g. a QGraphicsItem, this class will act as + a wrapper around QGraphicsItem. E.g. calling update() is effectively the same as + calling QGraphicsItem::update(). + + It also provides a pixmap() function which creates a pixmap with the source + painted into it. + + \sa QGraphicsItem::setGraphicsEffect(), QWidget::setGraphicsEffect. +*/ QGraphicsEffectSource::QGraphicsEffectSource(QGraphicsEffectSourcePrivate &dd, QObject *parent) : QObject(dd, parent) {} @@ -109,46 +127,115 @@ QGraphicsEffectSource::QGraphicsEffectSource(QGraphicsEffectSourcePrivate &dd, Q QGraphicsEffectSource::~QGraphicsEffectSource() {} +/*! + Returns the bounds of the current painter's device. + + This function is useful when you e.g. want to draw something in device coordinates + and want to make sure the size of the pixmap is not bigger than the device's size. + + Note that calling QGraphicsEffectSource::pixmap(Qt::DeviceCoordinates) always returns + a pixmap which is bound to the device's size. + + \sa pixmap() +*/ QRect QGraphicsEffectSource::deviceRect() const { return d_func()->deviceRect(); } +/*! + Returns the bounding rectangle of the source mapped to the \a system specified. + + \sa draw() +*/ QRectF QGraphicsEffectSource::boundingRect(Qt::CoordinateSystem system) const { return d_func()->boundingRect(system); } +/*! + Returns a pointer to the item if this source is a QGraphicsItem; + otherwise returns 0; + + \sa widget() +*/ const QGraphicsItem *QGraphicsEffectSource::graphicsItem() const { return d_func()->graphicsItem(); } +/*! + Returns a pointer to the widget if this source is a QWidget; + otherwise returns 0; + + \sa graphicsItem() +*/ const QWidget *QGraphicsEffectSource::widget() const { return d_func()->widget(); } +/*! + Returns a pointer to the style options (used when drawing the source) + if available; otherwise returns 0. + + \sa graphicsItem(), widget() +*/ const QStyleOption *QGraphicsEffectSource::styleOption() const { return d_func()->styleOption(); } +/*! + Draws the source using the \a painter specified. + + This function should only be called from QGraphicsEffect::draw(). + For example: + + \snippet doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp 0 + + \sa QGraphicsEffect::draw() +*/ + void QGraphicsEffectSource::draw(QPainter *painter) { d_func()->draw(painter); } +/*! + Schedules a redraw of the source. You can call this function whenever the + source needs to be redrawn. + + \sa QGraphicsEffect::updateBoundingRect(), QWidget::update(), QGraphicsItem::update(), +*/ void QGraphicsEffectSource::update() { d_func()->update(); } +/*! + Returns true if the source effectively is a pixmap, e.g. a QGraphicsPixmapItem. + + This function is useful for optimization purposes, e.g. there's no point in + drawing the source in device coordinates to avoid pixmap scaling if this function + returns true; the source pixmap will be scaled anyways. +*/ bool QGraphicsEffectSource::isPixmap() const { return d_func()->isPixmap(); } +/*! + Returns a pixmap with the source painted into it. The \a system specifies which + coordinate system to be used for the source. The optional out parameter + \a offset returns the offset of which the pixmap should be painted + at using the current painter. + + Note that the returned pixmap is bound to the current painter's device + rect when the specified \a system is Qt::DeviceCoordinates. + + \sa QGraphicsEffect::draw(), boundingRect(), deviceRect() +*/ QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offset) const { return d_func()->pixmap(system, offset); @@ -217,6 +304,8 @@ QRectF QGraphicsEffect::boundingRectFor(const QRectF &rect) const This property is provided so that you can disable certain effects on slow platforms, in order to ensure that the user interface is responsive. + + \sa enabledChanged() */ bool QGraphicsEffect::isEnabled() const { @@ -237,6 +326,14 @@ void QGraphicsEffect::setEnabled(bool enable) } /*! + \fn void QGraphicsEffect::enabledChanged(bool enabled) + + This signal is emitted whenever the effect is enabled or disabled. + + \sa isEnabled() +*/ + +/*! Returns a pointer to the source, which provides extra context information that can be useful for the effect. @@ -264,6 +361,36 @@ void QGraphicsEffect::updateBoundingRect() } /*! + \fn virtual void QGraphicsEffect::draw(QPainter *painter, + QGraphicsEffectSource *source) = 0 + + This pure virtual function draws the effect and is called whenever the source() + needs to be drawn. + + Reimplement this function in a QGraphicsEffect subclass to provide the effect's + drawing implementation, using \a painter. The \a source parameter is provided + for convenience; its value is the same as source(). Example: + + \snippet doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp 1 + + Note that this function should not be called explicitly by the user, since it's + meant for re-implementation purposes only. + + \sa QGraphicsEffectSource +*/ + +/*! + \enum QGraphicsEffect::ChangeFlag + + This enum describes what has changed in QGraphicsEffectSource. + + \value SourceAttached The effect is installed on a source. + \value SourceDetached The effect is uninstalled on a source. + \value SourceBoundingRectChanged The bounding rect of the source has changed. + \value SourceInvalidated The visual appearance of the source has changed. +*/ + +/*! This virtual function is called by QGraphicsEffect to notify the effect that the source has changed. If the effect applies any cache, then this cache must be purged in order to reflect the new appearance of the source. @@ -275,6 +402,15 @@ void QGraphicsEffect::sourceChanged(ChangeFlags flags) Q_UNUSED(flags); } +/*! + \class QGraphicsGrayscaleEffect + \brief The QGraphicsGrayscaleEffect class provides a grayscale effect. + \since 4.6 + + A grayscale effect renders the source in shades of gray. + + \sa QGraphicsColorizeEffect +*/ QGraphicsGrayscaleEffect::QGraphicsGrayscaleEffect(QObject *parent) : QGraphicsEffect(*new QGraphicsGrayscaleEffectPrivate, parent) { @@ -304,6 +440,18 @@ void QGraphicsGrayscaleEffect::draw(QPainter *painter, QGraphicsEffectSource *so } +/*! + \class QGraphicsColorizeEffect + \brief The QGraphicsColorizeEffect provides a colorize effect. + \since 4.6 + + A colorize effect renders the source with a tint of its color(). The + color can be modified using the setColor() function. + + By default, the color is light blue (QColor(0, 0, 192)). + + \sa QGraphicsGrayscaleEffect +*/ QGraphicsColorizeEffect::QGraphicsColorizeEffect(QObject *parent) : QGraphicsEffect(*new QGraphicsColorizeEffectPrivate, parent) { @@ -313,22 +461,38 @@ QGraphicsColorizeEffect::~QGraphicsColorizeEffect() { } +/*! + Returns the color. + + \sa setColor(), colorChanged() +*/ QColor QGraphicsColorizeEffect::color() const { Q_D(const QGraphicsColorizeEffect); return d->filter->color(); } -void QGraphicsColorizeEffect::setColor(const QColor &c) +/*! + Sets the color to the \a color specified. + + \sa color(), colorChanged() +*/ +void QGraphicsColorizeEffect::setColor(const QColor &color) { Q_D(QGraphicsColorizeEffect); - if (d->filter->color() == c) + if (d->filter->color() == color) return; - d->filter->setColor(c); - emit colorChanged(c); + d->filter->setColor(color); + emit colorChanged(color); } +/*! + \fn void QGraphicsColorizeEffect::colorChanged(const QColor &color) + + This signal is emitted whenever the effect's color changes. +*/ + void QGraphicsColorizeEffect::draw(QPainter *painter, QGraphicsEffectSource *source) { Q_D(QGraphicsColorizeEffect); @@ -348,6 +512,19 @@ void QGraphicsColorizeEffect::draw(QPainter *painter, QGraphicsEffectSource *sou painter->setWorldTransform(restoreTransform); } +/*! + \class QGraphicsPixelizeEffect + \brief The QGraphicsPixelizeEffect provides a pixelize effect. + \since 4.6 + + A pixelize effect renders the source in lower resolution. This effect + is useful for reducing details, in e.g. a censorship. The resolution + can be modified using the setPixelSize() function. + + By default, the pixel size is 3. + + \sa QGraphicsBlurEffect +*/ QGraphicsPixelizeEffect::QGraphicsPixelizeEffect(QObject *parent) : QGraphicsEffect(*new QGraphicsPixelizeEffectPrivate, parent) { @@ -357,12 +534,26 @@ QGraphicsPixelizeEffect::~QGraphicsPixelizeEffect() { } +/*! + Returns the size of a pixel. + + \sa setPixelSize(), pixelSizeChanged() +*/ int QGraphicsPixelizeEffect::pixelSize() const { Q_D(const QGraphicsPixelizeEffect); return d->pixelSize; } +/*! + Sets the size of a pixel to the \a size specified. + + Setting the \a size to e.g. 2 means two pixels in the source will + be used to represent one pixel. Using a bigger size results in + lower resolution. + + \sa pixelSize(), pixelSizeChanged() +*/ void QGraphicsPixelizeEffect::setPixelSize(int size) { Q_D(QGraphicsPixelizeEffect); @@ -373,6 +564,12 @@ void QGraphicsPixelizeEffect::setPixelSize(int size) emit pixelSizeChanged(size); } +/*! + \fn void QGraphicsPixelizeEffect::pixelSizeChanged(int size) + + This signal is emitted whenever the effect's pixel size changes. +*/ + static inline void pixelize(QImage *image, int pixelSize) { Q_ASSERT(pixelSize > 0); @@ -424,6 +621,20 @@ void QGraphicsPixelizeEffect::draw(QPainter *painter, QGraphicsEffectSource *sou painter->setWorldTransform(restoreTransform); } +/*! + \class QGraphicsBlurEffect + \brief The QGraphicsBlurEffect provides a blur effect. + \since 4.6 + + A blur effect blurs the source. This effect is useful for reducing details, + e.g. when the source loses focus and you want to draw attention to other + elements. The level of detail can be modified using the setBlurRadius() + function. + + By default, the blur radius is 5 pixels. + + \sa QGraphicsPixelizeEffect +*/ QGraphicsBlurEffect::QGraphicsBlurEffect(QObject *parent) : QGraphicsEffect(*new QGraphicsBlurEffectPrivate, parent) { @@ -433,12 +644,25 @@ QGraphicsBlurEffect::~QGraphicsBlurEffect() { } +/*! + Returns the blur radius. + + \sa setBlurRadius(), blurRadiusChanged() +*/ int QGraphicsBlurEffect::blurRadius() const { Q_D(const QGraphicsBlurEffect); return d->filter->radius(); } +/*! + Sets the blur radius to the \a radius specified. + + Using a smaller radius results in a sharper appearance, whereas a + bigger radius results in a more blurry appearance. + + \sa blurRadius(), blurRadiusChanged() +*/ void QGraphicsBlurEffect::setBlurRadius(int radius) { Q_D(QGraphicsBlurEffect); @@ -450,6 +674,12 @@ void QGraphicsBlurEffect::setBlurRadius(int radius) emit blurRadiusChanged(radius); } +/*! + \fn void QGraphicsBlurEffect::blurRadiusChanged(int radius) + + This signal is emitted whenever the effect's blur radius changes. +*/ + QRectF QGraphicsBlurEffect::boundingRectFor(const QRectF &rect) const { Q_D(const QGraphicsBlurEffect); @@ -480,6 +710,21 @@ void QGraphicsBlurEffect::draw(QPainter *painter, QGraphicsEffectSource *source) painter->setWorldTransform(restoreTransform); } +/*! + \class QGraphicsDropShadowEffect + \brief The QGraphicsDropShadowEffect class provides a drop shadow effect. + \since 4.6 + + A drop shadow effect renders the source with a drop shadow. The color of + the drop shadow can be modified using the setColor() function, the drop + shadow offset can be modified using the setOffset function, and the blur + radius of the drop shadow can be changed through the setBlurRadius() + function. + + By default, the drop shadow is a semi-transparent dark gray + (QColor(63, 63, 63, 180)) shadow, blurred with a radius of 1 at an + offset of 8 pixels towards the lower right. +*/ QGraphicsDropShadowEffect::QGraphicsDropShadowEffect(QObject *parent) : QGraphicsEffect(*new QGraphicsDropShadowEffectPrivate, parent) { @@ -489,29 +734,59 @@ QGraphicsDropShadowEffect::~QGraphicsDropShadowEffect() { } +/*! + Returns the shadow offset in pixels. + + \sa setOffset(), blurRadius(), color(), offsetChanged() +*/ QPointF QGraphicsDropShadowEffect::offset() const { Q_D(const QGraphicsDropShadowEffect); return d->filter->offset(); } -void QGraphicsDropShadowEffect::setOffset(const QPointF &ofs) +/*! + Sets the shadow offset in pixels to the \a offset specified. + + \sa offset(), setBlurRadius(), setColor(), offsetChanged() +*/ +void QGraphicsDropShadowEffect::setOffset(const QPointF &offset) { Q_D(QGraphicsDropShadowEffect); - if (d->filter->offset() == ofs) + if (d->filter->offset() == offset) return; - d->filter->setOffset(ofs); + d->filter->setOffset(offset); updateBoundingRect(); - emit offsetChanged(ofs); + emit offsetChanged(offset); } +/*! + \fn void QGraphicsDropShadowEffect::offsetChanged(const QPoint &offset) + + This signal is emitted whenever the effect's shadow offset changes. +*/ + +/*! + Returns the radius in pixels of the blur on the drop shadow. + + \sa setBlurRadius(), color(), offset(), blurRadiusChanged() +*/ int QGraphicsDropShadowEffect::blurRadius() const { Q_D(const QGraphicsDropShadowEffect); return d->filter->blurRadius(); } +/*! + Sets the radius in pixels of the blur on the drop shadow to the + \a blurRadius specified. + + Using a smaller radius results in a sharper shadow, whereas using + a bigger radius results in a more blurry shadow. + + \sa blurRadius(), setColor(), setOffset(), blurRadiusChanged() +*/ void QGraphicsDropShadowEffect::setBlurRadius(int blurRadius) { Q_D(QGraphicsDropShadowEffect); @@ -523,12 +798,28 @@ void QGraphicsDropShadowEffect::setBlurRadius(int blurRadius) emit blurRadiusChanged(blurRadius); } +/*! + \fn void QGraphicsDropShadowEffect::blurRadiusChanged(int blurRadius) + + This signal is emitted whenever the effect's blur radius changes. +*/ + +/*! + Returns the color of the drop shadow. + + \sa setColor, offset(), blurRadius(), colorChanged() +*/ QColor QGraphicsDropShadowEffect::color() const { Q_D(const QGraphicsDropShadowEffect); return d->filter->color(); } +/*! + Sets the color of the drop shadow to the \a color specified. + + \sa color(), setOffset(), setBlurRadius(), colorChanged() +*/ void QGraphicsDropShadowEffect::setColor(const QColor &color) { Q_D(QGraphicsDropShadowEffect); @@ -539,6 +830,12 @@ void QGraphicsDropShadowEffect::setColor(const QColor &color) emit colorChanged(color); } +/*! + \fn void QGraphicsDropShadowEffect::colorChanged(const QColor &color) + + This signal is emitted whenever the effect's color changes. +*/ + QRectF QGraphicsDropShadowEffect::boundingRectFor(const QRectF &rect) const { Q_D(const QGraphicsDropShadowEffect); @@ -569,6 +866,17 @@ void QGraphicsDropShadowEffect::draw(QPainter *painter, QGraphicsEffectSource *s painter->setWorldTransform(restoreTransform); } +/*! + \class QGraphicsOpacityEffect + \brief The QGraphicsOpacityEffect class provides an opacity effect. + \since 4.6 + + An opacity effects renders the source with an opacity. This effect is useful + for making the source semi-transparent, in e.g. a fade-in/fade-out sequence. + The opacity can be modified using the setOpacity() function. + + By default, the opacity is 0.7. +*/ QGraphicsOpacityEffect::QGraphicsOpacityEffect(QObject *parent) : QGraphicsEffect(*new QGraphicsOpacityEffectPrivate, parent) { @@ -578,21 +886,42 @@ QGraphicsOpacityEffect::~QGraphicsOpacityEffect() { } +/*! + Returns the opacity. + + \sa setOpacity(), opacityChanged() +*/ qreal QGraphicsOpacityEffect::opacity() const { Q_D(const QGraphicsOpacityEffect); return d->opacity; } +/*! + Sets the opacity to the \a opacity specified. The value should be in + the range 0.0 to 1.0, where 0.0 is fully transparent and 1.0 is + fully opaque. + + \sa opacity(), opacityChanged() +*/ void QGraphicsOpacityEffect::setOpacity(qreal opacity) { Q_D(QGraphicsOpacityEffect); + opacity = qBound(qreal(0.0), opacity, qreal(1.0)); + if (qFuzzyCompare(d->opacity, opacity)) return; + d->opacity = opacity; emit opacityChanged(opacity); } +/*! + \fn void QGraphicsOpacityEffect::opacityChanged(qreal opacity) + + This signal is emitted whenever the effect's opacity changes. +*/ + void QGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *source) { Q_D(QGraphicsOpacityEffect); diff --git a/src/gui/graphicsview/qgraph_p.h b/src/gui/graphicsview/qgraph_p.h index 796d645..895ee0c 100644 --- a/src/gui/graphicsview/qgraph_p.h +++ b/src/gui/graphicsview/qgraph_p.h @@ -155,8 +155,7 @@ public: #endif if (edgeData(first, second)) { #ifdef QT_DEBUG - qWarning(qPrintable(QString::fromAscii("%1-%2 already has an edge") - .arg(first->toString()).arg(second->toString()))); + qWarning("%s-%s already has an edge", qPrintable(first->toString()), qPrintable(second->toString())); #endif } createDirectedEdge(first, second, data); diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 033723a..7f9fe65 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -381,6 +381,8 @@ void QGraphicsWidget::setGeometry(const QRectF &rect) QSizeF oldSize = size(); QGraphicsLayoutItem::setGeometry(newGeom); + wd->invalidateCachedClipPathRecursively(); + // Send resize event bool resized = newGeom.size() != oldSize; if (resized) { diff --git a/src/gui/image/qnativeimage.cpp b/src/gui/image/qnativeimage.cpp index 1e1c7fd..f273c3c 100644 --- a/src/gui/image/qnativeimage.cpp +++ b/src/gui/image/qnativeimage.cpp @@ -148,11 +148,15 @@ QImage::Format QNativeImage::systemFormat() #elif defined(Q_WS_X11) && !defined(QT_NO_MITSHM) QNativeImage::QNativeImage(int width, int height, QImage::Format format,bool /* isTextBuffer */, QWidget *widget) + : xshmimg(0), xshmpm(0) { if (!X11->use_mitshm) { - xshmimg = 0; - xshmpm = 0; image = QImage(width, height, format); + // follow good coding practice and set xshminfo attributes, though values not used in this case + xshminfo.readOnly = true; + xshminfo.shmaddr = 0; + xshminfo.shmid = 0; + xshminfo.shmseg = 0; return; } diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 00e78ad..658b8e0 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -832,20 +832,11 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers if (QPixmapCache::find(key, *this)) return true; - QImage image = QImageReader(fileName, format).read(); - if (image.isNull()) - return false; - - QPixmap pm; - if (data->pixelType() == QPixmapData::BitmapType) - pm = QBitmap::fromImage(image, flags); - else - pm = fromImage(image, flags); - if (!pm.isNull()) { - *this = pm; + if (data->fromFile(fileName, format, flags)) { QPixmapCache::insert(key, *this); return true; } + return false; } @@ -870,21 +861,7 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags) { - QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len); - QBuffer b(&a); - b.open(QIODevice::ReadOnly); - - QImage image = QImageReader(&b, format).read(); - QPixmap pm; - if (data->pixelType() == QPixmapData::BitmapType) - pm = QBitmap::fromImage(image, flags); - else - pm = fromImage(image, flags); - if (!pm.isNull()) { - *this = pm; - return true; - } - return false; + return data->fromData(buf, len, format, flags); } /*! diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp index b8d6ac1..81071ee 100644 --- a/src/gui/image/qpixmapcache.cpp +++ b/src/gui/image/qpixmapcache.cpp @@ -82,6 +82,11 @@ QT_BEGIN_NAMESPACE A pixmap takes roughly (\e{width} * \e{height} * \e{depth})/8 bytes of memory. + The \e{Qt Quarterly} article + \l{http://qt.nokia.com/doc/qq/qq12-qpixmapcache.html}{Optimizing + with QPixmapCache} explains how to use QPixmapCache to speed up + applications by caching the results of painting. + \sa QCache, QPixmap */ diff --git a/src/gui/image/qpixmapdata.cpp b/src/gui/image/qpixmapdata.cpp index 001a930..c8b91db 100644 --- a/src/gui/image/qpixmapdata.cpp +++ b/src/gui/image/qpixmapdata.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qpixmapdata_p.h" +#include <QtCore/qbuffer.h> #include <QtGui/qbitmap.h> #include <QtGui/qimagereader.h> @@ -66,14 +67,44 @@ QPixmapData::~QPixmapData() { } -void QPixmapData::fromFile(const QString &fileName, const char *format, +static QImage makeBitmapCompliantIfNeeded(QPixmapData *d, const QImage &image, Qt::ImageConversionFlags flags) +{ + if (d->pixelType() == QPixmapData::BitmapType) { + QImage img = image.convertToFormat(QImage::Format_MonoLSB, flags); + + // make sure image.color(0) == Qt::color0 (white) + // and image.color(1) == Qt::color1 (black) + const QRgb c0 = QColor(Qt::black).rgb(); + const QRgb c1 = QColor(Qt::white).rgb(); + if (img.color(0) == c0 && img.color(1) == c1) { + img.invertPixels(); + img.setColor(0, c1); + img.setColor(1, c0); + } + return img; + } + + return image; +} + +bool QPixmapData::fromFile(const QString &fileName, const char *format, Qt::ImageConversionFlags flags) { - const QImage image = QImageReader(fileName, format).read(); + QImage image = QImageReader(fileName, format).read(); if (image.isNull()) - return; + return false; + fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags); + return !isNull(); +} - fromImage(image, flags); +bool QPixmapData::fromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags) +{ + QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len); + QBuffer b(&a); + b.open(QIODevice::ReadOnly); + QImage image = QImageReader(&b, format).read(); + fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags); + return !isNull(); } void QPixmapData::copy(const QPixmapData *data, const QRect &rect) diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h index 70890c0..9040641 100644 --- a/src/gui/image/qpixmapdata_p.h +++ b/src/gui/image/qpixmapdata_p.h @@ -75,8 +75,12 @@ public: virtual void resize(int width, int height) = 0; virtual void fromImage(const QImage &image, Qt::ImageConversionFlags flags) = 0; - virtual void fromFile(const QString &filename, const char *format, + + virtual bool fromFile(const QString &filename, const char *format, + Qt::ImageConversionFlags flags); + virtual bool fromData(const uchar *buffer, uint len, const char *format, Qt::ImageConversionFlags flags); + virtual void copy(const QPixmapData *data, const QRect &rect); virtual bool scroll(int dx, int dy, const QRect &rect); diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index c7d06f7..8489817 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -7,6 +7,7 @@ PRECOMPILED_HEADER = kernel/qt_gui_pch.h KERNEL_P= kernel HEADERS += \ kernel/qaction.h \ + kernel/qaction_p.h \ kernel/qactiongroup.h \ kernel/qapplication.h \ kernel/qapplication_p.h \ diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp index 00cba04..f5e1f29 100644 --- a/src/gui/kernel/qaction.cpp +++ b/src/gui/kernel/qaction.cpp @@ -262,6 +262,11 @@ void QActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map) \c{Info.plist} file in the application's bundle (See \l{Deploying an Application on Mac OS X}). \value PreferencesRole This action should be placed where the "Preferences..." menu item is in the application menu. \value QuitRole This action should be placed where the Quit menu item is in the application menu. + + Setting this value only has effect on items that are in the immediate menus + of the menubar, not the submenus of those menus. For example, if you have + File menu in your menubar and the File menu has a submenu, setting the + MenuRole for the actions in that submenu have no effect. They will never be moved. */ /*! diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index 12cd879..b2cde4d 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -323,6 +323,7 @@ extern HRGN qt_tryCreateRegion(QRegion::RegionType type, int left, int top, int #define APPCOMMAND_BASS_UP 21 #define APPCOMMAND_TREBLE_DOWN 22 #define APPCOMMAND_TREBLE_UP 23 +#endif // FAPPCOMMAND_MOUSE // New commands from Windows XP (some even Sp1) #ifndef APPCOMMAND_MICROPHONE_VOLUME_MUTE @@ -357,8 +358,6 @@ extern HRGN qt_tryCreateRegion(QRegion::RegionType type, int left, int top, int #define APPCOMMAND_MEDIA_CHANNEL_DOWN 52 #endif // APPCOMMAND_MICROPHONE_VOLUME_MUTE -#endif // FAPPCOMMAND_MOUSE - #if (_WIN32_WINNT < 0x0400) // This struct is defined in winuser.h if the _WIN32_WINNT >= 0x0400 -- in the // other cases we have to define it on our own. @@ -1809,6 +1808,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam case APPCOMMAND_VOLUME_UP: key = Qt::Key_VolumeUp; break; +#if defined(WINVER) && WINVER >= 0x0501 // Commands new in Windows XP case APPCOMMAND_HELP: key = Qt::Key_Help; @@ -1822,6 +1822,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam case APPCOMMAND_MEDIA_PLAY: key = Qt::Key_MediaPlay; break; +#endif default: break; } diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index 0d07a02..170224d 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -1915,9 +1915,12 @@ void qt_init(QApplicationPrivate *priv, int, bool local = displayName.isEmpty() || displayName.lastIndexOf(QLatin1Char(':')) == 0; if (local && (qgetenv("QT_X11_NO_MITSHM").toInt() == 0)) { Visual *defaultVisual = DefaultVisual(X11->display, DefaultScreen(X11->display)); - X11->use_mitshm = mitshm_pixmaps && (defaultVisual->red_mask == 0xff0000 - && defaultVisual->green_mask == 0xff00 - && defaultVisual->blue_mask == 0xff); + X11->use_mitshm = mitshm_pixmaps && ((defaultVisual->red_mask == 0xff0000 + || defaultVisual->red_mask == 0xf800) + && (defaultVisual->green_mask == 0xff00 + || defaultVisual->green_mask == 0x7e0) + && (defaultVisual->blue_mask == 0xff + || defaultVisual->blue_mask == 0x1f)); } } #endif // QT_NO_MITSHM @@ -5401,7 +5404,8 @@ class QSessionManagerPrivate : public QObjectPrivate { public: QSessionManagerPrivate(QSessionManager* mgr, QString& id, QString& key) - : QObjectPrivate(), sm(mgr), sessionId(id), sessionKey(key), eventLoop(0) {} + : QObjectPrivate(), sm(mgr), sessionId(id), sessionKey(key), + restartHint(QSessionManager::RestartIfRunning), eventLoop(0) {} QSessionManager* sm; QStringList restartCommand; QStringList discardCommand; diff --git a/src/gui/kernel/qwidget_wince.cpp b/src/gui/kernel/qwidget_wince.cpp index bcc9cfd..fa71925 100644 --- a/src/gui/kernel/qwidget_wince.cpp +++ b/src/gui/kernel/qwidget_wince.cpp @@ -316,7 +316,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO if (desktop) { q->setAttribute(Qt::WA_WState_Visible); - } else if (topLevel) { + } else if (topLevel && !q->testAttribute(Qt::WA_DontShowOnScreen)) { RECT cr; GetClientRect(id, &cr); // one cannot trust cr.left and cr.top, use a correction POINT instead diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index b005842..a52a270 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -389,20 +389,20 @@ void QBrush::init(const QColor &color, Qt::BrushStyle style) { switch(style) { case Qt::NoBrush: - d.data_ptr() = nullBrushInstance(); + d.reset(nullBrushInstance()); d->ref.ref(); if (d->color != color) setColor(color); return; case Qt::TexturePattern: - d.data_ptr() = new QTexturedBrushData; + d.reset(new QTexturedBrushData); break; case Qt::LinearGradientPattern: case Qt::RadialGradientPattern: case Qt::ConicalGradientPattern: - d.data_ptr() = new QGradientBrushData; + d.reset(new QGradientBrushData); break; default: - d.data_ptr() = new QBrushData; + d.reset(new QBrushData); break; } d->ref = 1; @@ -460,7 +460,7 @@ QBrush::QBrush(Qt::BrushStyle style) if (qbrush_check_type(style)) init(Qt::black, style); else { - d.data_ptr() = nullBrushInstance(); + d.reset(nullBrushInstance()); d->ref.ref(); } } @@ -476,7 +476,7 @@ QBrush::QBrush(const QColor &color, Qt::BrushStyle style) if (qbrush_check_type(style)) init(color, style); else { - d.data_ptr() = nullBrushInstance(); + d.reset(nullBrushInstance()); d->ref.ref(); } } @@ -493,7 +493,7 @@ QBrush::QBrush(Qt::GlobalColor color, Qt::BrushStyle style) if (qbrush_check_type(style)) init(color, style); else { - d.data_ptr() = nullBrushInstance(); + d.reset(nullBrushInstance()); d->ref.ref(); } } diff --git a/src/gui/painting/qbrush.h b/src/gui/painting/qbrush.h index 51b108e..9f9819c 100644 --- a/src/gui/painting/qbrush.h +++ b/src/gui/painting/qbrush.h @@ -137,13 +137,13 @@ private: friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush); void detach(Qt::BrushStyle newStyle); void init(const QColor &color, Qt::BrushStyle bs); - QCustomScopedPointer<QBrushData, QBrushDataPointerDeleter> d; + QScopedPointer<QBrushData, QBrushDataPointerDeleter> d; void cleanUp(QBrushData *x); public: inline bool isDetached() const; - typedef QBrushData * DataPtr; - inline DataPtr &data_ptr() { return d.data_ptr(); } + typedef QScopedPointer<QBrushData, QBrushDataPointerDeleter> DataPtr; + inline DataPtr &data_ptr() { return d; } }; inline void QBrush::setColor(Qt::GlobalColor acolor) diff --git a/src/gui/painting/qregion_win.cpp b/src/gui/painting/qregion_win.cpp index 29ae65f..ecabd6e 100644 --- a/src/gui/painting/qregion_win.cpp +++ b/src/gui/painting/qregion_win.cpp @@ -47,7 +47,6 @@ #include "qregion.h" #include "qt_windows.h" #include "qpainterpath.h" -#include "qguifunctions_wince.h" QT_BEGIN_NAMESPACE diff --git a/src/gui/painting/qwindowsurface_raster.cpp b/src/gui/painting/qwindowsurface_raster.cpp index 7cb65c7..7b52b05 100644 --- a/src/gui/painting/qwindowsurface_raster.cpp +++ b/src/gui/painting/qwindowsurface_raster.cpp @@ -147,7 +147,10 @@ void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoi QRect br = rgn.boundingRect(); #ifndef Q_WS_WINCE - if (!qt_widget_private(window())->isOpaque && window()->testAttribute(Qt::WA_TranslucentBackground)) { + if (!qt_widget_private(window())->isOpaque + && window()->testAttribute(Qt::WA_TranslucentBackground) + && (qt_widget_private(window())->data.window_flags & Qt::FramelessWindowHint)) + { QRect r = window()->frameGeometry(); QPoint frameOffset = qt_widget_private(window())->frameStrut().topLeft(); QRect dirtyRect = br.translated(offset + frameOffset); diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index d1bed3e..d4488ec 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -918,7 +918,7 @@ QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItemV4 *option, in widthUsed = qMax(widthUsed, line.naturalTextWidth()); } textLayout.endLayout(); - const QSize size = QSizeF(widthUsed, height).toSize(); + const QSize size(qCeil(widthUsed), qCeil(height)); return QSize(size.width() + 2 * textMargin, size.height()); } break; diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index a795c1f..7b36b9d 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -1994,9 +1994,12 @@ void QTextDocumentLayoutPrivate::positionFloat(QTextFrame *frame, QTextLine *cur } } - if (y + layoutStruct->frameY + fd->size.height > layoutStruct->pageBottom) { + bool frameSpansIntoNextPage = (y + layoutStruct->frameY + fd->size.height > layoutStruct->pageBottom); + if (frameSpansIntoNextPage && fd->size.height <= layoutStruct->pageHeight) { layoutStruct->newPage(); y = layoutStruct->y; + + frameSpansIntoNextPage = false; } y = findY(y, layoutStruct, fd->size.width); @@ -2017,6 +2020,11 @@ void QTextDocumentLayoutPrivate::positionFloat(QTextFrame *frame, QTextLine *cur // qDebug()<< "float positioned at " << fd->position.x << fd->position.y; fd->layoutDirty = false; + + // If the frame is a table, then positioning it will affect the size if it covers more than + // one page, because of page breaks and repeating the header. + if (qobject_cast<QTextTable *>(frame) != 0) + fd->sizeDirty = frameSpansIntoNextPage; } QRectF QTextDocumentLayoutPrivate::layoutFrame(QTextFrame *f, int layoutFrom, int layoutTo, QFixed parentY) @@ -2349,6 +2357,10 @@ void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QLayoutStru positionFloat(c); + // If the size was made dirty when the position was set, layout again + if (cd->sizeDirty) + updateRect = layoutFrame(c, layoutFrom, layoutTo); + QRectF frameRect(cd->position.toPointF(), cd->size.toSizeF()); if (frameRect == oldFrameRect && updateRect.isValid()) diff --git a/src/gui/util/qsystemtrayicon_win.cpp b/src/gui/util/qsystemtrayicon_win.cpp index ea7fbde..56872ac 100644 --- a/src/gui/util/qsystemtrayicon_win.cpp +++ b/src/gui/util/qsystemtrayicon_win.cpp @@ -132,12 +132,15 @@ QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object) : hIcon(0), q(object), ignoreNextMouseRelease(false) { -#ifndef Q_OS_WINCE - notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, guidItem); // NOTIFYICONDATAW_V2_SIZE; - maxTipLength = 128; -#else +#ifdef Q_OS_WINCE notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, szTip[64]); // NOTIFYICONDATAW_V1_SIZE; maxTipLength = 64; +#elif WINVER <= 0x0500 + notifyIconSize = sizeof(NOTIFYICONDATA); + maxTipLength = 64; +#else + notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, guidItem); // NOTIFYICONDATAW_V2_SIZE; + maxTipLength = 128; #endif // For restoring the tray icon after explorer crashes diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index bf0d52b..b1e9c79 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -2449,7 +2449,16 @@ void QComboBox::showPopup() && !style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this) && !window()->testAttribute(Qt::WA_DontShowOnScreen)) qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150); #endif + +// Don't disable updates on Mac OS X. Windows are displayed immediately on this platform, +// which means that the window will be visible before the call to container->show() returns. +// If updates are disabled at this point we'll miss our chance at painting the popup +// menu before it's shown, causing flicker since the window then displays the standard gray +// background. +#ifndef Q_WS_MAC container->setUpdatesEnabled(false); +#endif + container->raise(); container->show(); container->updateScrollers(); @@ -2460,7 +2469,10 @@ void QComboBox::showPopup() ? QAbstractItemView::PositionAtCenter : QAbstractItemView::EnsureVisible); +#ifndef Q_WS_MAC container->setUpdatesEnabled(updatesEnabled); +#endif + container->update(); #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm index 8089473..d59e1c9 100644 --- a/src/gui/widgets/qmenu_mac.mm +++ b/src/gui/widgets/qmenu_mac.mm @@ -1361,7 +1361,7 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action) if (!action->action->icon().isNull() && action->action->isIconVisibleInMenu()) { data.iconType = kMenuIconRefType; - data.iconHandle = (Handle)qt_mac_create_iconref(action->action->icon().pixmap(22, QIcon::Normal)); + data.iconHandle = (Handle)qt_mac_create_iconref(action->action->icon().pixmap(16, QIcon::Normal)); } else { data.iconType = kMenuNoIcon; } @@ -1400,7 +1400,7 @@ QMenuPrivate::QMacMenuPrivate::syncAction(QMacMenuAction *action) // Cocoa icon NSImage *nsimage = 0; if (!action->action->icon().isNull() && action->action->isIconVisibleInMenu()) { - nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(action->action->icon().pixmap(22, QIcon::Normal))); + nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(action->action->icon().pixmap(16, QIcon::Normal))); } [item setImage:nsimage]; [nsimage release]; diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 82b3769..0967f71 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -1695,6 +1695,7 @@ QSize QMenuBar::sizeHint() const ensurePolished(); QSize ret(0, 0); + const_cast<QMenuBarPrivate*>(d)->updateGeometries(); const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this); const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); @@ -1750,6 +1751,7 @@ int QMenuBar::heightForWidth(int) const const bool as_gui_menubar = true; #endif + const_cast<QMenuBarPrivate*>(d)->updateGeometries(); int height = 0; const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); |