diff options
author | axis <qt-info@nokia.com> | 2009-11-04 14:07:39 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-11-04 14:07:39 (GMT) |
commit | 9cda9fb4bb496a7c589767bdcead131dbcdeeb79 (patch) | |
tree | 2302096f06d4629ea62a85317429daa74ce6f02d /src/gui | |
parent | be6357bfa96cdaffa5797fef99e95cac7121e5b3 (diff) | |
parent | 7905101fb5ef18c776be515b9287356b1efc5ceb (diff) | |
download | Qt-9cda9fb4bb496a7c589767bdcead131dbcdeeb79.zip Qt-9cda9fb4bb496a7c589767bdcead131dbcdeeb79.tar.gz Qt-9cda9fb4bb496a7c589767bdcead131dbcdeeb79.tar.bz2 |
Merge branch '4.6' of git@scm.dev.nokia.troll.no:qt/qt into 4.6-s60
Diffstat (limited to 'src/gui')
92 files changed, 2816 insertions, 2320 deletions
diff --git a/src/gui/dialogs/qfiledialog_mac.mm b/src/gui/dialogs/qfiledialog_mac.mm index d9bec27..4af5688 100644 --- a/src/gui/dialogs/qfiledialog_mac.mm +++ b/src/gui/dialogs/qfiledialog_mac.mm @@ -399,9 +399,13 @@ QT_USE_NAMESPACE - (void)panelSelectionDidChange:(id)sender { Q_UNUSED(sender); - *mCurrentSelection = QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString([mSavePanel filename])); - if (mPriv) - mPriv->QNSOpenSavePanelDelegate_selectionChanged(*mCurrentSelection); + if (mPriv) { + QString selection = QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString([mSavePanel filename])); + if (selection != mCurrentSelection) { + *mCurrentSelection = selection; + mPriv->QNSOpenSavePanelDelegate_selectionChanged(selection); + } + } } - (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp index 3815b60..83f4f79 100644 --- a/src/gui/effects/qgraphicseffect.cpp +++ b/src/gui/effects/qgraphicseffect.cpp @@ -97,6 +97,8 @@ */ #include "qgraphicseffect_p.h" +#include "private/qgraphicsitem_p.h" + #include <QtGui/qgraphicsitem.h> #include <QtGui/qimage.h> @@ -210,7 +212,23 @@ const QStyleOption *QGraphicsEffectSource::styleOption() const */ void QGraphicsEffectSource::draw(QPainter *painter) { - d_func()->draw(painter); + Q_D(const QGraphicsEffectSource); + + QPixmap pm; + if (QPixmapCache::find(d->m_cacheKey, &pm)) { + QTransform restoreTransform; + if (d->m_cachedSystem == Qt::DeviceCoordinates) { + restoreTransform = painter->worldTransform(); + painter->setWorldTransform(QTransform()); + } + + painter->drawPixmap(d->m_cachedOffset, pm); + + if (d->m_cachedSystem == Qt::DeviceCoordinates) + painter->setWorldTransform(restoreTransform); + } else { + d_func()->draw(painter); + } } /*! @@ -260,6 +278,12 @@ QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offse return ((QGraphicsPixmapItem *) item)->pixmap(); } + if (system == Qt::DeviceCoordinates && item + && !static_cast<const QGraphicsItemEffectSourcePrivate *>(d_func())->info) { + qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context"); + return QPixmap(); + } + QPixmap pm; if (d->m_cachedSystem == system && d->m_cachedMode == mode) QPixmapCache::find(d->m_cacheKey, &pm); @@ -279,6 +303,13 @@ QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offse return pm; } +void QGraphicsEffectSourcePrivate::invalidateCache(bool effectRectChanged) const +{ + if (effectRectChanged && m_cachedMode != QGraphicsEffectSource::ExpandToEffectRectPadMode) + return; + QPixmapCache::remove(m_cacheKey); +} + /*! Constructs a new QGraphicsEffect instance having the specified \a parent. @@ -418,7 +449,7 @@ void QGraphicsEffect::updateBoundingRect() Q_D(QGraphicsEffect); if (d->source) { d->source->d_func()->effectBoundingRectChanged(); - d->source->d_func()->invalidateCache(); + d->source->d_func()->invalidateCache(true); } } @@ -606,6 +637,26 @@ void QGraphicsColorizeEffect::draw(QPainter *painter, QGraphicsEffectSource *sou */ /*! + \enum QGraphicsBlurEffect::BlurHint + \since 4.6 + + This enum describes the possible hints that can be used to control how + blur effects are applied. The hints might not have an effect in all the + paint engines. + + \value QualityHint Indicates that rendering quality is the most important factor, + at the potential cost of lower performance. + + \value PerformanceHint Indicates that rendering performance is the most important factor, + at the potential cost of lower quality. + + \value AnimationHint Indicates that the blur radius is going to be animated, hinting + that the implementation can keep a cache of blurred verisons of the source pixmap. + Do not use this hint if the source item is going to be dynamically changing. +*/ + + +/*! Constructs a new QGraphicsBlurEffect instance. The \a parent parameter is passed to QGraphicsEffect's constructor. */ @@ -613,7 +664,7 @@ QGraphicsBlurEffect::QGraphicsBlurEffect(QObject *parent) : QGraphicsEffect(*new QGraphicsBlurEffectPrivate, parent) { Q_D(QGraphicsBlurEffect); - d->filter->setBlurHint(Qt::PerformanceHint); + d->filter->setBlurHint(QGraphicsBlurEffect::PerformanceHint); } /*! @@ -660,20 +711,19 @@ void QGraphicsBlurEffect::setBlurRadius(qreal radius) \property QGraphicsBlurEffect::blurHint \brief the blur hint of the effect. - Use the Qt::PerformanceHint hint to say that you want a faster blur, - and the Qt::QualityHint hint to say that you prefer a higher quality blur. - - When animating the blur radius it's recommended to use Qt::PerformanceHint. + Use the PerformanceHint hint to say that you want a faster blur, + the QualityHint hint to say that you prefer a higher quality blur, + or the AnimationHint when you want to animate the blur radius. - By default, the blur hint is Qt::PerformanceHint. + By default, the blur hint is PerformanceHint. */ -Qt::RenderHint QGraphicsBlurEffect::blurHint() const +QGraphicsBlurEffect::BlurHint QGraphicsBlurEffect::blurHint() const { Q_D(const QGraphicsBlurEffect); return d->filter->blurHint(); } -void QGraphicsBlurEffect::setBlurHint(Qt::RenderHint hint) +void QGraphicsBlurEffect::setBlurHint(QGraphicsBlurEffect::BlurHint hint) { Q_D(QGraphicsBlurEffect); if (d->filter->blurHint() == hint) @@ -684,7 +734,7 @@ void QGraphicsBlurEffect::setBlurHint(Qt::RenderHint hint) } /*! - \fn void QGraphicsBlurEffect::blurHintChanged(Qt::RenderHint hint) + \fn void QGraphicsBlurEffect::blurHintChanged(Qt::BlurHint hint) This signal is emitted whenever the effect's blur hint changes. The \a hint parameter holds the effect's new blur hint. diff --git a/src/gui/effects/qgraphicseffect.h b/src/gui/effects/qgraphicseffect.h index bf18581..7335a25 100644 --- a/src/gui/effects/qgraphicseffect.h +++ b/src/gui/effects/qgraphicseffect.h @@ -183,22 +183,28 @@ class Q_GUI_EXPORT QGraphicsBlurEffect: public QGraphicsEffect { Q_OBJECT Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged) - Q_PROPERTY(Qt::RenderHint blurHint READ blurHint WRITE setBlurHint NOTIFY blurHintChanged) + Q_PROPERTY(BlurHint blurHint READ blurHint WRITE setBlurHint NOTIFY blurHintChanged) public: + enum BlurHint { + QualityHint, + PerformanceHint, + AnimationHint + }; + QGraphicsBlurEffect(QObject *parent = 0); ~QGraphicsBlurEffect(); QRectF boundingRectFor(const QRectF &rect) const; qreal blurRadius() const; - Qt::RenderHint blurHint() const; + BlurHint blurHint() const; public Q_SLOTS: void setBlurRadius(qreal blurRadius); - void setBlurHint(Qt::RenderHint hint); + void setBlurHint(BlurHint hint); Q_SIGNALS: void blurRadiusChanged(qreal blurRadius); - void blurHintChanged(Qt::RenderHint hint); + void blurHintChanged(BlurHint hint); protected: void draw(QPainter *painter, QGraphicsEffectSource *source); diff --git a/src/gui/effects/qgraphicseffect_p.h b/src/gui/effects/qgraphicseffect_p.h index 1ed7103..0ff5794 100644 --- a/src/gui/effects/qgraphicseffect_p.h +++ b/src/gui/effects/qgraphicseffect_p.h @@ -85,7 +85,7 @@ public: virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset = 0, QGraphicsEffectSource::PixmapPadMode mode = QGraphicsEffectSource::ExpandToTransparentBorderPadMode) const = 0; virtual void effectBoundingRectChanged() = 0; - void invalidateCache() const { QPixmapCache::remove(m_cacheKey); } + void invalidateCache(bool effectRectChanged = false) const; friend class QGraphicsScenePrivate; friend class QGraphicsItem; diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index d70b039..2fd499d 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -7343,19 +7343,32 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent } /*! - Subscribes the graphics object to the given \a gesture for the specified \a context. + Subscribes the graphics object to the given \a gesture with specific \a flags. - \sa QGestureEvent + \sa ungrabGesture(), QGestureEvent */ - -void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureContext context) +void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags) { QGraphicsItemPrivate * const d = QGraphicsItem::d_func(); - d->gestureContext.insert(gesture, context); + d->gestureContext.insert(gesture, flags); (void)QGestureManager::instance(); // create a gesture manager } /*! + Unsubscribes the graphics object from the given \a gesture. + + \sa grabGesture(), QGestureEvent +*/ +void QGraphicsObject::ungrabGesture(Qt::GestureType gesture) +{ + QGraphicsItemPrivate * const d = QGraphicsItem::d_func(); + if (d->gestureContext.remove(gesture)) { + QGestureManager *manager = QGestureManager::instance(); + manager->cleanupCachedGestures(this, gesture); + } +} + +/*! \property QGraphicsObject::parent \brief the parent of the item diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index f3fe99c..f091e34 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -555,7 +555,8 @@ public: using QObject::children; #endif - void grabGesture(Qt::GestureType type, Qt::GestureContext context = Qt::ItemWithChildrenGesture); + void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags()); + void ungrabGesture(Qt::GestureType type); Q_SIGNALS: void parentChanged(); diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index ca56c18..51d2ffd 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -453,7 +453,7 @@ public: QGraphicsItem *focusScopeItem; Qt::InputMethodHints imHints; QGraphicsItem::PanelModality panelModality; - QMap<Qt::GestureType, Qt::GestureContext> gestureContext; + QMap<Qt::GestureType, Qt::GestureFlags> gestureContext; // Packed 32 bits quint32 acceptedMouseButtons : 5; diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index f982f4b..dc036f8 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -1064,9 +1064,8 @@ bool QGraphicsScenePrivate::filterEvent(QGraphicsItem *item, QEvent *event) bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event) { if (QGraphicsObject *object = item->toGraphicsObject()) { - QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); - if (qAppPriv->gestureManager) { - if (qAppPriv->gestureManager->filterEvent(object, event)) + if (qt_gestureManager) { + if (qt_gestureManager->filterEvent(object, event)) return true; } } @@ -5765,7 +5764,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) QWidget *viewport = event->widget(); if (!viewport) return; - QList<QGesture *> allGestures = event->allGestures(); + QList<QGesture *> allGestures = event->gestures(); DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" << "Delivering gestures:" << allGestures; @@ -5904,7 +5903,12 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) QGraphicsItemPrivate *gid = item->QGraphicsItem::d_func(); foreach(QGesture *g, alreadyIgnoredGestures) { - if (gid->gestureContext.contains(g->gestureType())) + QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit = + gid->gestureContext.find(g->gestureType()); + bool deliver = contextit != gid->gestureContext.end() && + (g->state() == Qt::GestureStarted || + (contextit.value() & Qt::ReceivePartialGestures)); + if (deliver) gestures += g; } if (gestures.isEmpty()) @@ -5917,8 +5921,12 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) sendEvent(item, &ev); QSet<QGesture *> ignoredGestures; foreach (QGesture *g, gestures) { - if (!ev.isAccepted() && !ev.isAccepted(g)) + if (!ev.isAccepted() && !ev.isAccepted(g)) { ignoredGestures.insert(g); + } else { + if (g->state() == Qt::GestureStarted) + gestureTargets[g] = item; + } } if (!ignoredGestures.isEmpty()) { // get a list of items under the (current) hotspot of each ignored @@ -5945,6 +5953,13 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) continue; } } + foreach (QGesture *g, startedGestures) { + if (g->gestureCancelPolicy() == QGesture::CancelAllInContext) { + DEBUG() << "lets try to cancel some"; + // find gestures in context in Qt::GestureStarted or Qt::GestureUpdated state and cancel them + cancelGesturesForChildren(g, event->widget()); + } + } // forget about targets for gestures that have ended foreach (QGesture *g, allGestures) { @@ -5959,6 +5974,88 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) } } +void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original, QWidget *viewport) +{ + Q_ASSERT(original); + QGraphicsItem *originalItem = gestureTargets.value(original); + Q_ASSERT(originalItem); + + // iterate over all active gestures and for each find the owner + // if the owner is part of our sub-hierarchy, cancel it. + + QSet<QGesture *> canceledGestures; + QHash<QGesture *, QGraphicsObject *>::Iterator iter = gestureTargets.begin(); + while (iter != gestureTargets.end()) { + QGraphicsObject *item = iter.value(); + // note that we don't touch the gestures for our originalItem + if (item != originalItem && originalItem->isAncestorOf(item)) { + DEBUG() << " found a gesture to cancel" << iter.key(); + iter.key()->d_func()->state = Qt::GestureCanceled; + canceledGestures << iter.key(); + } + ++iter; + } + + // sort them per target item by cherry picking from almostCanceledGestures and delivering + QSet<QGesture *> almostCanceledGestures = canceledGestures; + QSet<QGesture *>::Iterator setIter; + while (!almostCanceledGestures.isEmpty()) { + QGraphicsObject *target = 0; + QSet<QGesture*> gestures; + setIter = almostCanceledGestures.begin(); + // sort per target item + while (setIter != almostCanceledGestures.end()) { + QGraphicsObject *item = gestureTargets.value(*setIter); + if (target == 0) + target = item; + if (target == item) { + gestures << *setIter; + setIter = almostCanceledGestures.erase(setIter); + } else { + ++setIter; + } + } + Q_ASSERT(target); + + QList<QGesture *> list = gestures.toList(); + QGestureEvent ev(list); + sendEvent(target, &ev); + + foreach (QGesture *g, list) { + if (ev.isAccepted() || ev.isAccepted(g)) + gestures.remove(g); + } + + foreach (QGesture *g, gestures) { + if (!g->hasHotSpot()) + continue; + + QPoint screenPos = g->hotSpot().toPoint(); + QList<QGraphicsItem *> items = itemsAtPosition(screenPos, QPointF(), viewport); + for (int j = 0; j < items.size(); ++j) { + QGraphicsObject *item = items.at(j)->toGraphicsObject(); + if (!item) + continue; + QGraphicsItemPrivate *d = item->QGraphicsItem::d_func(); + if (d->gestureContext.contains(g->gestureType())) { + QList<QGesture *> list; + list << g; + QGestureEvent ev(list); + sendEvent(item, &ev); + if (ev.isAccepted() || ev.isAccepted(g)) + break; // successfully delivered + } + } + } + } + + Q_ASSERT(qt_gestureManager); // it would be very odd if we got called without a manager. + for (setIter = canceledGestures.begin(); setIter != canceledGestures.end(); ++setIter) { + qt_gestureManager->recycle(*setIter); + gestureTargets.remove(*setIter); + } +} + QT_END_NAMESPACE #include "moc_qgraphicsscene.cpp" diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index cd20fd0..f8db084 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -288,6 +288,7 @@ public: QMap<Qt::GestureType, QGesture *> *conflictedGestures, QList<QList<QGraphicsObject *> > *conflictedItems, QHash<QGesture *, QGraphicsObject *> *normalGestures); + void cancelGesturesForChildren(QGesture *original, QWidget *viewport); void updateInputMethodSensitivityInViews(); diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index f72aa8a..c88f678 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -281,6 +281,7 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime < #include <QtGui/qstyleoption.h> #include <QtGui/qinputcontext.h> #ifdef Q_WS_X11 +#include <QtGui/qpaintengine.h> #include <private/qt_x11_p.h> #endif @@ -3294,7 +3295,12 @@ void QGraphicsView::paintEvent(QPaintEvent *event) backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip); if (viewTransformed) backgroundPainter.setTransform(viewTransform); - backgroundPainter.setCompositionMode(QPainter::CompositionMode_Source); +#ifdef Q_WS_X11 +#undef X11 + if (backgroundPainter.paintEngine()->type() != QPaintEngine::X11) +#define X11 qt_x11Data +#endif + backgroundPainter.setCompositionMode(QPainter::CompositionMode_Source); drawBackground(&backgroundPainter, exposedSceneRect); d->backgroundPixmapExposed = QRegion(); } diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 234f271..15af7a2 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -61,7 +61,6 @@ #ifdef Q_WS_X11 #include <private/qt_x11_p.h> -#include <private/gtksymbols_p.h> #endif QT_BEGIN_NAMESPACE diff --git a/src/gui/image/qimagepixmapcleanuphooks.cpp b/src/gui/image/qimagepixmapcleanuphooks.cpp index ac30646..35322e9 100644 --- a/src/gui/image/qimagepixmapcleanuphooks.cpp +++ b/src/gui/image/qimagepixmapcleanuphooks.cpp @@ -40,7 +40,8 @@ ****************************************************************************/ #include "qimagepixmapcleanuphooks_p.h" -#include "qpixmapdata_p.h" +#include "private/qpixmapdata_p.h" +#include "private/qimage_p.h" QT_BEGIN_NAMESPACE @@ -132,4 +133,19 @@ void QImagePixmapCleanupHooks::executeImageHooks(qint64 key) qt_image_cleanup_hook_64(key); } +void QImagePixmapCleanupHooks::enableCleanupHooks(const QPixmap &pixmap) +{ + enableCleanupHooks(const_cast<QPixmap &>(pixmap).data_ptr().data()); +} + +void QImagePixmapCleanupHooks::enableCleanupHooks(QPixmapData *pixmapData) +{ + pixmapData->is_cached = true; +} + +void QImagePixmapCleanupHooks::enableCleanupHooks(const QImage &image) +{ + const_cast<QImage &>(image).data_ptr()->is_cached = true; +} + QT_END_NAMESPACE diff --git a/src/gui/image/qimagepixmapcleanuphooks_p.h b/src/gui/image/qimagepixmapcleanuphooks_p.h index 16c8974..9e490d7 100644 --- a/src/gui/image/qimagepixmapcleanuphooks_p.h +++ b/src/gui/image/qimagepixmapcleanuphooks_p.h @@ -70,6 +70,10 @@ public: static QImagePixmapCleanupHooks *instance(); + static void enableCleanupHooks(const QImage &image); + static void enableCleanupHooks(const QPixmap &pixmap); + static void enableCleanupHooks(QPixmapData *pixmapData); + // Gets called when a pixmap is about to be modified: void addPixmapModificationHook(_qt_pixmap_cleanup_hook_pm); diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 45ff5f4..c452b9a 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -113,13 +113,10 @@ void QPixmap::init(int w, int h, Type type) void QPixmap::init(int w, int h, int type) { - QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem(); - if (gs) - data = gs->createPixmapData(static_cast<QPixmapData::PixelType>(type)); + if ((w > 0 && h > 0) || type == QPixmapData::BitmapType) + data = QPixmapData::create(w, h, (QPixmapData::PixelType) type); else - data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type)); - - data->resize(w, h); + data = 0; } /*! @@ -307,7 +304,7 @@ QPixmap::QPixmap(const char * const xpm[]) QImage image(xpm); if (!image.isNull()) { - if (data->pixelType() == QPixmapData::BitmapType) + if (data && data->pixelType() == QPixmapData::BitmapType) *this = QBitmap::fromImage(image); else *this = fromImage(image); @@ -322,8 +319,8 @@ QPixmap::QPixmap(const char * const xpm[]) QPixmap::~QPixmap() { - Q_ASSERT(data->ref >= 1); // Catch if ref-counting changes again - if (data->is_cached && data->ref == 1) // ref will be decrememnted after destructor returns + Q_ASSERT(!data || data->ref >= 1); // Catch if ref-counting changes again + if (data && data->is_cached && data->ref == 1) // ref will be decrememnted after destructor returns QImagePixmapCleanupHooks::executePixmapDestructionHooks(this); } @@ -544,7 +541,7 @@ bool QPixmap::isQBitmap() const */ bool QPixmap::isNull() const { - return data->isNull(); + return !data || data->isNull(); } /*! @@ -556,7 +553,7 @@ bool QPixmap::isNull() const */ int QPixmap::width() const { - return data->width(); + return data ? data->width() : 0; } /*! @@ -568,7 +565,7 @@ int QPixmap::width() const */ int QPixmap::height() const { - return data->height(); + return data ? data->height() : 0; } /*! @@ -581,7 +578,7 @@ int QPixmap::height() const */ QSize QPixmap::size() const { - return QSize(data->width(), data->height()); + return data ? QSize(data->width(), data->height()) : QSize(); } /*! @@ -593,7 +590,7 @@ QSize QPixmap::size() const */ QRect QPixmap::rect() const { - return QRect(0, 0, data->width(), data->height()); + return data ? QRect(0, 0, data->width(), data->height()) : QRect(); } /*! @@ -609,7 +606,7 @@ QRect QPixmap::rect() const */ int QPixmap::depth() const { - return data->depth(); + return data ? data->depth() : 0; } /*! @@ -639,7 +636,7 @@ void QPixmap::resize_helper(const QSize &s) return; // Create new pixmap - QPixmap pm(QSize(w, h), data->type); + QPixmap pm(QSize(w, h), data ? data->type : QPixmapData::PixmapType); bool uninit = false; #if defined(Q_WS_X11) QX11PixmapData *x11Data = data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data.data()) : 0; @@ -728,6 +725,9 @@ void QPixmap::setMask(const QBitmap &mask) return; } + if (isNull()) + return; + if (static_cast<const QPixmap &>(mask).data == data) // trying to selfmask return; @@ -826,11 +826,14 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers QFileInfo info(fileName); QString key = QLatin1String("qt_pixmap_") + info.absoluteFilePath() + QLatin1Char('_') + QString::number(info.lastModified().toTime_t()) + QLatin1Char('_') + - QString::number(info.size()) + QLatin1Char('_') + QString::number(data->pixelType()); + QString::number(info.size()) + QLatin1Char('_') + QString::number(data ? data->pixelType() : QPixmapData::PixmapType); if (QPixmapCache::find(key, *this)) return true; + if (!data) + data = QPixmapData::create(0, 0, QPixmapData::PixmapType); + if (data->fromFile(fileName, format, flags)) { QPixmapCache::insert(key, *this); return true; @@ -863,6 +866,9 @@ bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::I if (len == 0 || buf == 0) return false; + if (!data) + data = QPixmapData::create(0, 0, QPixmapData::PixmapType); + return data->fromData(buf, len, format, flags); } @@ -1008,6 +1014,9 @@ int QPixmap::serialNumber() const */ qint64 QPixmap::cacheKey() const { + if (isNull()) + return 0; + int classKey = data->classId(); if (classKey >= 1024) classKey = -(classKey >> 10); @@ -1224,7 +1233,7 @@ QPixmap::QPixmap(const QImage& image) QPixmap &QPixmap::operator=(const QImage &image) { - if (data->pixelType() == QPixmapData::BitmapType) + if (data && data->pixelType() == QPixmapData::BitmapType) *this = QBitmap::fromImage(image); else *this = fromImage(image); @@ -1254,7 +1263,7 @@ bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Color */ bool QPixmap::convertFromImage(const QImage &image, ColorMode mode) { - if (data->pixelType() == QPixmapData::BitmapType) + if (data && data->pixelType() == QPixmapData::BitmapType) *this = QBitmap::fromImage(image, colorModeToFlags(mode)); else *this = fromImage(image, colorModeToFlags(mode)); @@ -1341,7 +1350,7 @@ Q_GUI_EXPORT void copyBlt(QPixmap *dst, int dx, int dy, bool QPixmap::isDetached() const { - return data->ref == 1; + return data && data->ref == 1; } /*! \internal @@ -1753,7 +1762,7 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode) */ bool QPixmap::hasAlpha() const { - return (data->hasAlphaChannel() || !data->mask().isNull()); + return data && (data->hasAlphaChannel() || !data->mask().isNull()); } /*! @@ -1764,7 +1773,7 @@ bool QPixmap::hasAlpha() const */ bool QPixmap::hasAlphaChannel() const { - return data->hasAlphaChannel(); + return data && data->hasAlphaChannel(); } /*! @@ -1772,7 +1781,7 @@ bool QPixmap::hasAlphaChannel() const */ int QPixmap::metric(PaintDeviceMetric metric) const { - return data->metric(metric); + return data ? data->metric(metric) : 0; } /*! @@ -1844,7 +1853,7 @@ void QPixmap::setAlphaChannel(const QPixmap &alphaChannel) */ QPixmap QPixmap::alphaChannel() const { - return data->alphaChannel(); + return data ? data->alphaChannel() : QPixmap(); } /*! @@ -1852,7 +1861,7 @@ QPixmap QPixmap::alphaChannel() const */ QPaintEngine *QPixmap::paintEngine() const { - return data->paintEngine(); + return data ? data->paintEngine() : 0; } /*! @@ -1867,7 +1876,7 @@ QPaintEngine *QPixmap::paintEngine() const */ QBitmap QPixmap::mask() const { - return data->mask(); + return data ? data->mask() : QBitmap(); } /*! @@ -1916,6 +1925,9 @@ int QPixmap::defaultDepth() */ void QPixmap::detach() { + if (!data) + return; + QPixmapData::ClassId id = data->classId(); if (id == QPixmapData::RasterClass) { QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data()); diff --git a/src/gui/image/qpixmap_mac.cpp b/src/gui/image/qpixmap_mac.cpp index afa6f83..9209d45 100644 --- a/src/gui/image/qpixmap_mac.cpp +++ b/src/gui/image/qpixmap_mac.cpp @@ -305,11 +305,15 @@ void QMacPixmapData::fromImage(const QImage &img, } break; } - case QImage::Format_Indexed8: - for (int x = 0; x < w; ++x) { - *(drow+x) = PREMUL(image.color(*(srow + x))); + case QImage::Format_Indexed8: { + int numColors = image.numColors(); + if (numColors > 0) { + for (int x = 0; x < w; ++x) { + int index = *(srow + x); + *(drow+x) = PREMUL(image.color(qMin(index, numColors))); + } } - break; + } break; case QImage::Format_RGB32: for (int x = 0; x < w; ++x) *(drow+x) = *(((quint32*)srow) + x) | 0xFF000000; @@ -965,6 +969,9 @@ Qt::HANDLE QPixmap::macQDAlphaHandle() const Qt::HANDLE QPixmap::macCGHandle() const { + if (isNull()) + return 0; + if (data->classId() == QPixmapData::MacClass) { QMacPixmapData *d = static_cast<QMacPixmapData *>(data.data()); if (!d->cg_data) diff --git a/src/gui/image/qpixmap_qws.cpp b/src/gui/image/qpixmap_qws.cpp index 6b4283e..a8516a5 100644 --- a/src/gui/image/qpixmap_qws.cpp +++ b/src/gui/image/qpixmap_qws.cpp @@ -114,7 +114,7 @@ QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h) QRgb* QPixmap::clut() const { - if (data->classId() == QPixmapData::RasterClass) { + if (data && data->classId() == QPixmapData::RasterClass) { const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data()); return d->image.colorTable().data(); } @@ -124,7 +124,7 @@ QRgb* QPixmap::clut() const int QPixmap::numCols() const { - if (data->classId() == QPixmapData::RasterClass) { + if (data && data->classId() == QPixmapData::RasterClass) { const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data()); return d->image.numColors(); } @@ -134,7 +134,7 @@ int QPixmap::numCols() const const uchar* QPixmap::qwsBits() const { - if (data->classId() == QPixmapData::RasterClass) { + if (data && data->classId() == QPixmapData::RasterClass) { const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data()); return d->image.bits(); } @@ -144,7 +144,7 @@ const uchar* QPixmap::qwsBits() const int QPixmap::qwsBytesPerLine() const { - if (data->classId() == QPixmapData::RasterClass) { + if (data && data->classId() == QPixmapData::RasterClass) { const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data()); return d->image.bytesPerLine(); } diff --git a/src/gui/image/qpixmap_s60.cpp b/src/gui/image/qpixmap_s60.cpp index 5c7e93f..cd8a4d4 100644 --- a/src/gui/image/qpixmap_s60.cpp +++ b/src/gui/image/qpixmap_s60.cpp @@ -311,7 +311,7 @@ QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h) CFbsBitmap *QPixmap::toSymbianCFbsBitmap() const { QPixmapData *data = pixmapData(); - if (data->isNull()) + if (!data || data->isNull()) return 0; return reinterpret_cast<CFbsBitmap*>(data->toNativeType(QPixmapData::FbsBitmap)); @@ -337,8 +337,9 @@ QPixmap QPixmap::fromSymbianCFbsBitmap(CFbsBitmap *bitmap) if (!bitmap) return QPixmap(); - QPixmap pixmap; - pixmap.pixmapData()->fromNativeType(reinterpret_cast<void*>(bitmap), QPixmapData::FbsBitmap); + QScopedPointer<QS60PixmapData> data(new QS60PixmapData(QPixmapData::PixmapType)); + data->fromNativeType(reinterpret_cast<void*>(bitmap), QPixmapData::FbsBitmap); + QPixmap pixmap(data.take()); return pixmap; } @@ -751,9 +752,9 @@ QPixmap QPixmap::fromSymbianRSgImage(RSgImage *sgImage) if (!sgImage) return QPixmap(); - QPixmap pixmap; - pixmap.pixmapData()->fromNativeType(reinterpret_cast<void*>(sgImage), QPixmapData::SgImage); - + QScopedPointer<QS60PixmapData> data(new QS60PixmapData(QPixmapData::PixmapType)); + data->fromNativeType(reinterpret_cast<void*>(sgImage), QPixmapData::SgImage); + QPixmap pixmap(data.take()); return pixmap; } diff --git a/src/gui/image/qpixmap_win.cpp b/src/gui/image/qpixmap_win.cpp index 1b61484..04027c1 100644 --- a/src/gui/image/qpixmap_win.cpp +++ b/src/gui/image/qpixmap_win.cpp @@ -121,6 +121,9 @@ QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h ) HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format) const { + if (isNull()) + return 0; + HBITMAP bitmap = 0; if (data->classId() == QPixmapData::RasterClass) { QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data.data()); diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index ea9eff9..8a0120a 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -1976,6 +1976,9 @@ void QPixmap::x11SetScreen(int screen) return; } + if (isNull()) + return; + if (data->classId() != QPixmapData::X11Class) return; @@ -2078,7 +2081,7 @@ bool QX11PixmapData::hasAlphaChannel() const const QX11Info &QPixmap::x11Info() const { - if (data->classId() == QPixmapData::X11Class) + if (data && data->classId() == QPixmapData::X11Class) return static_cast<QX11PixmapData*>(data.data())->xinfo; else { static QX11Info nullX11Info; @@ -2135,7 +2138,7 @@ QPaintEngine* QX11PixmapData::paintEngine() const Qt::HANDLE QPixmap::x11PictureHandle() const { #ifndef QT_NO_XRENDER - if (data->classId() == QPixmapData::X11Class) + if (data && data->classId() == QPixmapData::X11Class) return static_cast<const QX11PixmapData*>(data.data())->picture; else return 0; diff --git a/src/gui/image/qpixmapdata.cpp b/src/gui/image/qpixmapdata.cpp index 1ad1f02..10194e4 100644 --- a/src/gui/image/qpixmapdata.cpp +++ b/src/gui/image/qpixmapdata.cpp @@ -51,6 +51,19 @@ QT_BEGIN_NAMESPACE const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; +QPixmapData *QPixmapData::create(int w, int h, PixelType type) +{ + QPixmapData *data; + QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem(); + if (gs) + data = gs->createPixmapData(static_cast<QPixmapData::PixelType>(type)); + else + data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type)); + data->resize(w, h); + return data; +} + + QPixmapData::QPixmapData(PixelType pixelType, int objectId) : w(0), h(0), diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h index 2f4f201..d1bb92a 100644 --- a/src/gui/image/qpixmapdata_p.h +++ b/src/gui/image/qpixmapdata_p.h @@ -122,6 +122,8 @@ public: virtual void fromNativeType(void* pixmap, NativeType type); #endif + static QPixmapData *create(int w, int h, PixelType type); + protected: void setSerialNumber(int serNo); int w; @@ -131,12 +133,11 @@ protected: private: friend class QPixmap; - friend class QGLContextPrivate; friend class QX11PixmapData; friend class QS60PixmapData; + friend class QImagePixmapCleanupHooks; // Needs to set is_cached friend class QGLTextureCache; //Needs to check the reference count friend class QExplicitlySharedDataPointer<QPixmapData>; - friend bool qt_createEGLSurfaceForPixmap(QPixmapData*, bool); // Needs to set is_cached QAtomicInt ref; int detach_no; diff --git a/src/gui/image/qpixmapfilter.cpp b/src/gui/image/qpixmapfilter.cpp index d0de03e..e50cc8b 100644 --- a/src/gui/image/qpixmapfilter.cpp +++ b/src/gui/image/qpixmapfilter.cpp @@ -504,10 +504,10 @@ void QPixmapConvolutionFilter::draw(QPainter *painter, const QPointF &p, const Q class QPixmapBlurFilterPrivate : public QPixmapFilterPrivate { public: - QPixmapBlurFilterPrivate() : radius(5), hint(Qt::PerformanceHint) {} + QPixmapBlurFilterPrivate() : radius(5), hint(QGraphicsBlurEffect::PerformanceHint) {} qreal radius; - Qt::RenderHint hint; + QGraphicsBlurEffect::BlurHint hint; }; @@ -556,12 +556,18 @@ qreal QPixmapBlurFilter::radius() const Setting the blur hint to PerformanceHint causes the implementation to trade off visual quality to blur the image faster. Setting the blur hint to QualityHint causes the implementation to improve - visual quality at the expense of speed. The implementation is free - to ignore this value if it only has a single blur algorithm. + visual quality at the expense of speed. + + AnimationHint causes the implementation to optimize for animating + the blur radius, possibly by caching blurred versions of the source + pixmap. + + The implementation is free to ignore this value if it only has a single + blur algorithm. \internal */ -void QPixmapBlurFilter::setBlurHint(Qt::RenderHint hint) +void QPixmapBlurFilter::setBlurHint(QGraphicsBlurEffect::BlurHint hint) { Q_D(QPixmapBlurFilter); d->hint = hint; @@ -572,7 +578,7 @@ void QPixmapBlurFilter::setBlurHint(Qt::RenderHint hint) \internal */ -Qt::RenderHint QPixmapBlurFilter::blurHint() const +QGraphicsBlurEffect::BlurHint QPixmapBlurFilter::blurHint() const { Q_D(const QPixmapBlurFilter); return d->hint; diff --git a/src/gui/image/qpixmapfilter_p.h b/src/gui/image/qpixmapfilter_p.h index fc70795..6a96676 100644 --- a/src/gui/image/qpixmapfilter_p.h +++ b/src/gui/image/qpixmapfilter_p.h @@ -55,6 +55,7 @@ #include <QtCore/qnamespace.h> #include <QtGui/qpixmap.h> +#include <QtGui/qgraphicseffect.h> QT_BEGIN_HEADER @@ -130,10 +131,10 @@ public: ~QPixmapBlurFilter(); void setRadius(qreal radius); - void setBlurHint(Qt::RenderHint hint); + void setBlurHint(QGraphicsBlurEffect::BlurHint hint); qreal radius() const; - Qt::RenderHint blurHint() const; + QGraphicsBlurEffect::BlurHint blurHint() const; QRectF boundingRectFor(const QRectF &rect) const; void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const; diff --git a/src/gui/itemviews/qdirmodel.cpp b/src/gui/itemviews/qdirmodel.cpp index 2973741..942cfd7 100644 --- a/src/gui/itemviews/qdirmodel.cpp +++ b/src/gui/itemviews/qdirmodel.cpp @@ -1351,7 +1351,7 @@ QString QDirModelPrivate::size(const QModelIndex &index) const return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1)); if (bytes >= kb) return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb)); - return QFileSystemModel::tr("%1 bytes").arg(QLocale().toString(bytes)); + return QFileSystemModel::tr("%1 byte(s)").arg(QLocale().toString(bytes)); } QString QDirModelPrivate::type(const QModelIndex &index) const diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp index e3d17ad..6316797 100644 --- a/src/gui/itemviews/qfileiconprovider.cpp +++ b/src/gui/itemviews/qfileiconprovider.cpp @@ -47,24 +47,24 @@ #include <qdir.h> #include <qpixmapcache.h> #if defined(Q_WS_WIN) -#define _WIN32_IE 0x0500 -#include <qt_windows.h> -#include <commctrl.h> -#include <objbase.h> +# define _WIN32_IE 0x0500 +# include <qt_windows.h> +# include <commctrl.h> +# include <objbase.h> #elif defined(Q_WS_MAC) -#include <private/qt_cocoa_helpers_mac_p.h> -#endif - -#if defined(Q_WS_X11) && !defined(Q_NO_STYLE_GTK) -#include <private/qt_x11_p.h> -#include <private/gtksymbols_p.h> +# include <private/qt_cocoa_helpers_mac_p.h> #endif #include <private/qfunctions_p.h> #include <private/qguiplatformplugin_p.h> +#if defined(Q_WS_X11) && !defined(Q_NO_STYLE_GTK) +# include <private/qgtkstyle_p.h> +# include <private/qt_x11_p.h> +#endif + #ifndef SHGFI_ADDOVERLAYS -#define SHGFI_ADDOVERLAYS 0x000000020 +# define SHGFI_ADDOVERLAYS 0x000000020 #endif QT_BEGIN_NAMESPACE @@ -392,7 +392,7 @@ QIcon QFileIconProvider::icon(const QFileInfo &info) const #if defined(Q_WS_X11) && !defined(QT_NO_STYLE_GTK) if (X11->desktopEnvironment == DE_GNOME) { - QIcon gtkIcon = QGtk::getFilesystemIcon(info); + QIcon gtkIcon = QGtkStylePrivate::getFilesystemIcon(info); if (!gtkIcon.isNull()) return gtkIcon; } diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 1694434..987aa26 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -154,14 +154,6 @@ bool QApplicationPrivate::autoSipEnabled = false; bool QApplicationPrivate::autoSipEnabled = true; #endif -QGestureManager* QGestureManager::instance() -{ - QApplicationPrivate *d = qApp->d_func(); - if (!d->gestureManager) - d->gestureManager = new QGestureManager(qApp); - return d->gestureManager; -} - QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::Type type) : QCoreApplicationPrivate(argc, argv) { @@ -185,7 +177,7 @@ QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::T directPainters = 0; #endif - gestureManager = 0; + gestureWidget = 0; if (!self) self = this; @@ -3634,12 +3626,12 @@ bool QApplication::notify(QObject *receiver, QEvent *e) } // walk through parents and check for gestures - if (d->gestureManager) { + if (qt_gestureManager) { if (receiver->isWidgetType()) { - if (d->gestureManager->filterEvent(static_cast<QWidget *>(receiver), e)) + if (qt_gestureManager->filterEvent(static_cast<QWidget *>(receiver), e)) return true; } else if (QGesture *gesture = qobject_cast<QGesture *>(receiver)) { - if (d->gestureManager->filterEvent(gesture, e)) + if (qt_gestureManager->filterEvent(gesture, e)) return true; } } @@ -4152,7 +4144,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) if (receiver->isWidgetType()) { QWidget *w = static_cast<QWidget *>(receiver); QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(e); - QList<QGesture *> allGestures = gestureEvent->allGestures(); + QList<QGesture *> allGestures = gestureEvent->gestures(); bool eventAccepted = gestureEvent->isAccepted(); bool wasAccepted = eventAccepted; @@ -4163,7 +4155,12 @@ bool QApplication::notify(QObject *receiver, QEvent *e) for (int i = 0; i < allGestures.size();) { QGesture *g = allGestures.at(i); Qt::GestureType type = g->gestureType(); - if (wd->gestureContext.contains(type)) { + QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit = + wd->gestureContext.find(type); + bool deliver = contextit != wd->gestureContext.end() && + (g->state() == Qt::GestureStarted || w == receiver || + (contextit.value() & Qt::ReceivePartialGestures)); + if (deliver) { allGestures.removeAt(i); gestures.append(g); } else { @@ -5613,39 +5610,6 @@ Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window, QApplicationPrivate::translateRawTouchEvent(window, deviceType, touchPoints); } -/*! - \since 4.6 - - Registers the given \a recognizer in the gesture framework and returns a gesture ID - for it. - - The application takes ownership of the \a recognizer and returns the gesture type - ID associated with it. For gesture recognizers which handle custom QGesture - objects (i.e., those which return Qt::CustomGesture in a QGesture::gestureType() - function) the return value is a gesture ID between Qt::CustomGesture and - Qt::LastGestureType, inclusive. - - \sa unregisterGestureRecognizer(), QGestureRecognizer::createGesture(), QGesture -*/ -Qt::GestureType QApplication::registerGestureRecognizer(QGestureRecognizer *recognizer) -{ - return QGestureManager::instance()->registerGestureRecognizer(recognizer); -} - -/*! - \since 4.6 - - Unregisters all gesture recognizers of the specified \a type. - - \sa registerGestureRecognizer() -*/ -void QApplication::unregisterGestureRecognizer(Qt::GestureType type) -{ - QApplicationPrivate *d = qApp->d_func(); - if (d->gestureManager) - d->gestureManager->unregisterGestureRecognizer(type); -} - QT_END_NAMESPACE #include "moc_qapplication.cpp" diff --git a/src/gui/kernel/qapplication.h b/src/gui/kernel/qapplication.h index 5877ba4..e8c1281 100644 --- a/src/gui/kernel/qapplication.h +++ b/src/gui/kernel/qapplication.h @@ -86,7 +86,6 @@ class QSymbianEvent; class QApplication; class QApplicationPrivate; -class QGestureRecognizer; #if defined(qApp) #undef qApp #endif @@ -288,9 +287,6 @@ public: static Qt::NavigationMode navigationMode(); #endif - static Qt::GestureType registerGestureRecognizer(QGestureRecognizer *recognizer); - static void unregisterGestureRecognizer(Qt::GestureType type); - Q_SIGNALS: void lastWindowClosed(); void focusChanged(QWidget *old, QWidget *now); diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index ec308c0..992e4be 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -84,7 +84,6 @@ class QInputContext; class QObject; class QWidget; class QSocketNotifier; -class QGestureManager; extern bool qt_is_gui_used; #ifndef QT_NO_CLIPBOARD @@ -510,7 +509,7 @@ public: void sendSyntheticEnterLeave(QWidget *widget); #endif - QGestureManager *gestureManager; + QWidget *gestureWidget; QMap<int, QWidget *> widgetForTouchPointId; QMap<int, QTouchEvent::TouchPoint> appCurrentTouchPoints; diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index d98ecbb..387c29b 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -2499,24 +2499,24 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam if (qAppPriv->GetGestureInfo) bResult = qAppPriv->GetGestureInfo((HANDLE)msg.lParam, &gi); if (bResult) { -// if (gi.dwID == GID_BEGIN) { -// // find the alien widget for the gesture position. -// // This might not be accurate as the position is the center -// // point of two fingers for multi-finger gestures. -// QPoint pt(gi.ptsLocation.x, gi.ptsLocation.y); -// QWidget *w = widget->childAt(widget->mapFromGlobal(pt)); -// qAppPriv->gestureWidget = w ? w : widget; -// } -// if (qAppPriv->gestureWidget) -// static_cast<QETWidget*>(qAppPriv->gestureWidget)->translateGestureEvent(msg, gi); -// if (qAppPriv->CloseGestureInfoHandle) -// qAppPriv->CloseGestureInfoHandle((HANDLE)msg.lParam); -// if (gi.dwID == GID_END) -// qAppPriv->gestureWidget = 0; -// } else { -// DWORD dwErr = GetLastError(); -// if (dwErr > 0) -// qWarning() << "translateGestureEvent: error = " << dwErr; + if (gi.dwID == GID_BEGIN) { + // find the alien widget for the gesture position. + // This might not be accurate as the position is the center + // point of two fingers for multi-finger gestures. + QPoint pt(gi.ptsLocation.x, gi.ptsLocation.y); + QWidget *w = widget->childAt(widget->mapFromGlobal(pt)); + qAppPriv->gestureWidget = w ? w : widget; + } + if (qAppPriv->gestureWidget) + static_cast<QETWidget*>(qAppPriv->gestureWidget)->translateGestureEvent(msg, gi); + if (qAppPriv->CloseGestureInfoHandle) + qAppPriv->CloseGestureInfoHandle((HANDLE)msg.lParam); + if (gi.dwID == GID_END) + qAppPriv->gestureWidget = 0; + } else { + DWORD dwErr = GetLastError(); + if (dwErr > 0) + qWarning() << "translateGestureEvent: error = " << dwErr; } result = true; break; diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index b0ab760..b71ae73 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -79,7 +79,7 @@ #include <private/qcolor_p.h> #include <private/qcursor_p.h> #include <private/qiconloader_p.h> -#include <private/gtksymbols_p.h> +#include <qgtkstyle.h> #include "qstyle.h" #include "qmetaobject.h" #include "qtimer.h" @@ -2299,7 +2299,7 @@ void qt_init(QApplicationPrivate *priv, int, #if !defined(QT_NO_STYLE_GTK) if (X11->desktopEnvironment == DE_GNOME) { - static bool menusHaveIcons = QGtk::getGConfBool(QLatin1String("/desktop/gnome/interface/menus_have_icons"), true); + static bool menusHaveIcons = QGtkStyle::getGConfBool(QLatin1String("/desktop/gnome/interface/menus_have_icons"), true); QApplication::setAttribute(Qt::AA_DontShowIconsInMenus, !menusHaveIcons); } #endif diff --git a/src/gui/kernel/qcocoawindowdelegate_mac.mm b/src/gui/kernel/qcocoawindowdelegate_mac.mm index 95c89e5..803a1b1 100644 --- a/src/gui/kernel/qcocoawindowdelegate_mac.mm +++ b/src/gui/kernel/qcocoawindowdelegate_mac.mm @@ -346,5 +346,28 @@ static void cleanupCocoaWindowDelegate() m_drawerHash->remove(drawer); } +- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu +{ + Q_UNUSED(menu); + QWidget *qwidget = m_windowHash->value(window); + if (qwidget && !qwidget->windowFilePath().isEmpty()) { + return YES; + } + return NO; +} + +- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event + from:(NSPoint)dragImageLocation + withPasteboard:(NSPasteboard *)pasteboard +{ + Q_UNUSED(event); + Q_UNUSED(dragImageLocation); + Q_UNUSED(pasteboard); + QWidget *qwidget = m_windowHash->value(window); + if (qwidget && !qwidget->windowFilePath().isEmpty()) { + return YES; + } + return NO; +} @end #endif// QT_MAC_USE_COCOA diff --git a/src/gui/kernel/qcocoawindowdelegate_mac_p.h b/src/gui/kernel/qcocoawindowdelegate_mac_p.h index a06c516..3728002 100644 --- a/src/gui/kernel/qcocoawindowdelegate_mac_p.h +++ b/src/gui/kernel/qcocoawindowdelegate_mac_p.h @@ -76,6 +76,8 @@ QT_FORWARD_DECLARE_CLASS(QWidgetData) - (void)windowDidResignMain:(NSNotification*)notification; - (void)windowDidBecomeKey:(NSNotification*)notification; - (void)windowDidResignKey:(NSNotification*)notification; +- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu; +- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard; @end @protocol NSDrawerDelegate <NSObject> diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index ac597e4..bcebe06 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -4202,7 +4202,7 @@ QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::T \brief The QGestureEvent class provides the description of triggered gestures. The QGestureEvent class contains a list of gestures, which can be obtained using the - allGestures() function. + gestures() function. The gestures are either active or canceled. A list of those that are currently being executed can be obtained using the activeGestures() function. A list of those which @@ -4211,10 +4211,11 @@ QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::T focus, for example, or because of a timeout, or for other reasons. If the event handler does not accept the event by calling the generic - QEvent::accept() function, all individual QGesture object that were not accepted - will be propagated up the parent widget chain until a widget accepts them - individually, by calling QGestureEvent::accept() for each of them, or an event - filter consumes the event. + QEvent::accept() function, all individual QGesture object that were not + accepted and in the Qt::GestureStarted state will be propagated up the + parent widget chain until a widget accepts them individually, by calling + QGestureEvent::accept() for each of them, or an event filter consumes the + event. \sa QGesture, QGestureRecognizer, QWidget::grabGesture(), QGraphicsObject::grabGesture() @@ -4240,7 +4241,7 @@ QGestureEvent::~QGestureEvent() /*! Returns all gestures that are delivered in the event. */ -QList<QGesture *> QGestureEvent::allGestures() const +QList<QGesture *> QGestureEvent::gestures() const { return d_func()->gestures; } @@ -4344,8 +4345,9 @@ bool QGestureEvent::isAccepted(QGesture *gesture) const Sets the accept flag of the given \a gestureType object to the specified \a value. - Setting the accept flag indicates that the event receiver wants the \a gesture. - Unwanted gestures may be propagated to the parent widget. + Setting the accept flag indicates that the event receiver wants the gesture + of type \a gestureType. Unwanted gestures may be propagated to the parent + widget. By default, gestures in events of type QEvent::Gesture are accepted, and gestures in QEvent::GestureOverride events are ignored. @@ -4400,7 +4402,7 @@ bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const /*! \internal - Sets the widget for this event. + Sets the widget for this event to the \a widget specified. */ void QGestureEvent::setWidget(QWidget *widget) { @@ -4417,11 +4419,16 @@ QWidget *QGestureEvent::widget() const #ifndef QT_NO_GRAPHICSVIEW /*! - Returns the scene-local coordinates if the \a gesturePoint is inside a graphics view. + Returns the scene-local coordinates if the \a gesturePoint is inside a + graphics view. + + This functional might be useful when the gesture event is delivered to a + QGraphicsObject to translate a point in screen coordinates to scene-local + coordinates. \sa QPointF::isNull(). */ -QPointF QGestureEvent::mapToScene(const QPointF &gesturePoint) const +QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const { QWidget *w = widget(); if (w) // we get the viewport as widget, not the graphics view diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 141ccad..b9512fa 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -827,7 +827,7 @@ public: QGestureEvent(const QList<QGesture *> &gestures); ~QGestureEvent(); - QList<QGesture *> allGestures() const; + QList<QGesture *> gestures() const; QGesture *gesture(Qt::GestureType type) const; QList<QGesture *> activeGestures() const; @@ -860,7 +860,7 @@ public: QWidget *widget() const; #ifndef QT_NO_GRAPHICSVIEW - QPointF mapToScene(const QPointF &gesturePoint) const; + QPointF mapToGraphicsScene(const QPointF &gesturePoint) const; #endif private: diff --git a/src/gui/kernel/qgesture.cpp b/src/gui/kernel/qgesture.cpp index 850f22c..e322af2 100644 --- a/src/gui/kernel/qgesture.cpp +++ b/src/gui/kernel/qgesture.cpp @@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE Gesture objects are not constructed directly by developers. They are created by the QGestureRecognizer object that is registered with the application; see - QApplication::registerGestureRecognizer(). + QGestureRecognizer::registerRecognizer(). \section1 Gesture Properties @@ -74,7 +74,7 @@ QT_BEGIN_NAMESPACE destroy particular instances of them and create new ones to replace them. The registered gesture recognizer monitors the input events for the target - object via its \l{QGestureRecognizer::}{filterEvent()} function, updating the + object via its \l{QGestureRecognizer::}{recognize()} function, updating the properties of the gesture object as required. The gesture object may be delivered to the target object in a QGestureEvent if @@ -90,7 +90,7 @@ QT_BEGIN_NAMESPACE Constructs a new gesture object with the given \a parent. QGesture objects are created by gesture recognizers in the - QGestureRecognizer::createGesture() function. + QGestureRecognizer::create() function. */ QGesture::QGesture(QObject *parent) : QObject(*new QGesturePrivate, parent) @@ -129,7 +129,7 @@ QGesture::~QGesture() \brief The point that is used to find the receiver for the gesture event. The hot-spot is a point in the global coordinate system, use - QWidget::mapFromGlobal() or QGestureEvent::mapToScene() to get a + QWidget::mapFromGlobal() or QGestureEvent::mapToGraphicsScene() to get a local hot-spot. The hot-spot should be set by the gesture recognizer to allow gesture event @@ -180,8 +180,10 @@ void QGesture::unsetHotSpot() automatically. \value CancelNone On accepting this gesture no other gestures will be affected. - \value CancelAllInContext On accepting this gesture all gestures that are active - in the context (Qt::GestureContext) will be cancelled. + + \value CancelAllInContext On accepting this gesture all gestures that are + active in the context (respecting the Qt::GestureFlag that were specified + when subscribed to the gesture) will be cancelled. */ void QGesture::setGestureCancelPolicy(GestureCancelPolicy policy) @@ -208,16 +210,7 @@ QGesture::GestureCancelPolicy QGesture::gestureCancelPolicy() const */ /*! - \property QPanGesture::totalOffset - \brief the total offset from the first input position to the current input - position - - The total offset measures the total change in position of the user's input - covered by the gesture on the input device. -*/ - -/*! - \property QGesture::GestureCancelPolicy + \property QGesture::gestureCancelPolicy \brief the policy for deciding what happens on accepting a gesture On accepting one gesture Qt can automatically cancel other gestures @@ -241,11 +234,19 @@ QGesture::GestureCancelPolicy QGesture::gestureCancelPolicy() const /*! \property QPanGesture::offset - \brief the offset from the previous input position to the current input + \brief the total offset from the first input position to the current input position - The offset measures the change in position of the user's input on the - input device. + The offset measures the total change in position of the user's input + covered by the gesture on the input device. +*/ + +/*! + \property QPanGesture::delta + \brief the offset from the previous input position to the current input + + This is essentially the same as the difference between offset() and + lastOffset(). */ /*! @@ -261,10 +262,6 @@ QPanGesture::QPanGesture(QObject *parent) d_func()->gestureType = Qt::PanGesture; } -QPointF QPanGesture::totalOffset() const -{ - return d_func()->totalOffset; -} QPointF QPanGesture::lastOffset() const { @@ -276,15 +273,15 @@ QPointF QPanGesture::offset() const return d_func()->offset; } -qreal QPanGesture::acceleration() const +QPointF QPanGesture::delta() const { - return d_func()->acceleration; + Q_D(const QPanGesture); + return d->offset - d->lastOffset; } - -void QPanGesture::setTotalOffset(const QPointF &value) +qreal QPanGesture::acceleration() const { - d_func()->totalOffset = value; + return d_func()->acceleration; } void QPanGesture::setLastOffset(const QPointF &value) @@ -326,7 +323,7 @@ void QPanGesture::setAcceleration(qreal value) */ /*! - \enum QPinchGesture::WhatChange + \enum QPinchGesture::ChangeFlag This enum describes the changes that can occur to the properties of the gesture object. @@ -335,19 +332,30 @@ void QPanGesture::setAcceleration(qreal value) \value RotationAngleChanged The rotation angle held by rotationAngle changed. \value CenterPointChanged The center point held by centerPoint changed. - \sa whatChanged + \sa changeFlags, totalChangeFlags +*/ + +/*! + \property QPinchGesture::totalChangeFlags + \brief the property of the gesture that has change + + This property indicates which of the other properties has changed since the + gesture has started. You can use this information to determine which aspect + of your user interface needs to be updated. + + \sa changeFlags, scaleFactor, rotationAngle, centerPoint */ /*! - \property QPinchGesture::whatChanged - \brief the property of the gesture that has changed + \property QPinchGesture::changeFlags + \brief the property of the gesture that has changed in the current step This property indicates which of the other properties has changed since the previous gesture event included information about this gesture. You can use this information to determine which aspect of your user interface needs to be updated. - \sa scaleFactor, rotationAngle, centerPoint + \sa totalChangeFlags, scaleFactor, rotationAngle, centerPoint */ /*! @@ -441,16 +449,25 @@ QPinchGesture::QPinchGesture(QObject *parent) d_func()->gestureType = Qt::PinchGesture; } -QPinchGesture::WhatChanged QPinchGesture::whatChanged() const +QPinchGesture::ChangeFlags QPinchGesture::totalChangeFlags() const +{ + return d_func()->totalChangeFlags; +} + +void QPinchGesture::setTotalChangeFlags(QPinchGesture::ChangeFlags value) { - return d_func()->whatChanged; + d_func()->totalChangeFlags = value; } -void QPinchGesture::setWhatChanged(QPinchGesture::WhatChanged value) +QPinchGesture::ChangeFlags QPinchGesture::changeFlags() const { - d_func()->whatChanged = value; + return d_func()->changeFlags; } +void QPinchGesture::setChangeFlags(QPinchGesture::ChangeFlags value) +{ + d_func()->changeFlags = value; +} QPointF QPinchGesture::startCenterPoint() const { diff --git a/src/gui/kernel/qgesture.h b/src/gui/kernel/qgesture.h index 524d26e..dd322ad 100644 --- a/src/gui/kernel/qgesture.h +++ b/src/gui/kernel/qgesture.h @@ -97,6 +97,7 @@ private: friend class QGestureEvent; friend class QGestureRecognizer; friend class QGestureManager; + friend class QGraphicsScenePrivate; }; class QPanGesturePrivate; @@ -105,20 +106,19 @@ class Q_GUI_EXPORT QPanGesture : public QGesture Q_OBJECT Q_DECLARE_PRIVATE(QPanGesture) - Q_PROPERTY(QPointF totalOffset READ totalOffset WRITE setTotalOffset) Q_PROPERTY(QPointF lastOffset READ lastOffset WRITE setLastOffset) Q_PROPERTY(QPointF offset READ offset WRITE setOffset) + Q_PROPERTY(QPointF delta READ delta STORED false) Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration) public: QPanGesture(QObject *parent = 0); - QPointF totalOffset() const; QPointF lastOffset() const; QPointF offset() const; + QPointF delta() const; qreal acceleration() const; - void setTotalOffset(const QPointF &value); void setLastOffset(const QPointF &value); void setOffset(const QPointF &value); void setAcceleration(qreal value); @@ -134,14 +134,15 @@ class Q_GUI_EXPORT QPinchGesture : public QGesture Q_DECLARE_PRIVATE(QPinchGesture) public: - enum WhatChange { + enum ChangeFlag { ScaleFactorChanged = 0x1, RotationAngleChanged = 0x2, CenterPointChanged = 0x4 }; - Q_DECLARE_FLAGS(WhatChanged, WhatChange) + Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag) - Q_PROPERTY(WhatChanged whatChanged READ whatChanged WRITE setWhatChanged) + Q_PROPERTY(ChangeFlags totalChangeFlags READ totalChangeFlags WRITE setTotalChangeFlags) + Q_PROPERTY(ChangeFlags changeFlags READ changeFlags WRITE setChangeFlags) Q_PROPERTY(qreal totalScaleFactor READ totalScaleFactor WRITE setTotalScaleFactor) Q_PROPERTY(qreal lastScaleFactor READ lastScaleFactor WRITE setLastScaleFactor) @@ -158,8 +159,11 @@ public: public: QPinchGesture(QObject *parent = 0); - WhatChanged whatChanged() const; - void setWhatChanged(WhatChanged value); + ChangeFlags totalChangeFlags() const; + void setTotalChangeFlags(ChangeFlags value); + + ChangeFlags changeFlags() const; + void setChangeFlags(ChangeFlags value); QPointF startCenterPoint() const; QPointF lastCenterPoint() const; @@ -187,7 +191,7 @@ public: QT_END_NAMESPACE -Q_DECLARE_METATYPE(QPinchGesture::WhatChanged) +Q_DECLARE_METATYPE(QPinchGesture::ChangeFlags) QT_BEGIN_NAMESPACE diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h index 34fbb26..ae2e287 100644 --- a/src/gui/kernel/qgesture_p.h +++ b/src/gui/kernel/qgesture_p.h @@ -90,10 +90,9 @@ public: { } - QPointF totalOffset; QPointF lastOffset; QPointF offset; - QPoint lastPosition; + QPoint startPosition; qreal acceleration; }; @@ -103,12 +102,15 @@ class QPinchGesturePrivate : public QGesturePrivate public: QPinchGesturePrivate() - : whatChanged(0), totalScaleFactor(0), lastScaleFactor(0), scaleFactor(0), - totalRotationAngle(0), lastRotationAngle(0), rotationAngle(0) + : totalChangeFlags(0), changeFlags(0), + totalScaleFactor(0), lastScaleFactor(0), scaleFactor(0), + totalRotationAngle(0), lastRotationAngle(0), rotationAngle(0), + isNewSequence(true) { } - QPinchGesture::WhatChanged whatChanged; + QPinchGesture::ChangeFlags totalChangeFlags; + QPinchGesture::ChangeFlags changeFlags; QPointF startCenterPoint; QPointF lastCenterPoint; @@ -121,6 +123,9 @@ public: qreal totalRotationAngle; qreal lastRotationAngle; qreal rotationAngle; + + bool isNewSequence; + QPointF startPosition[2]; }; class QSwipeGesturePrivate : public QGesturePrivate diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index 0a88a24..628892d 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -52,6 +52,9 @@ #ifdef Q_WS_MAC #include "qmacgesturerecognizer_mac_p.h" #endif +#if defined(Q_OS_WIN) +#include "qwinnativepangesturerecognizer_win_p.h" +#endif #include "qdebug.h" @@ -64,6 +67,15 @@ QT_BEGIN_NAMESPACE +QGestureManager *qt_gestureManager = 0; + +QGestureManager* QGestureManager::instance() +{ + if (!qt_gestureManager) + qt_gestureManager = new QGestureManager(qApp); + return qt_gestureManager; +} + QGestureManager::QGestureManager(QObject *parent) : QObject(parent), state(NotGesture), m_lastCustomGestureId(0) { @@ -77,6 +89,10 @@ QGestureManager::QGestureManager(QObject *parent) #endif #else registerGestureRecognizer(new QPanGestureRecognizer); + registerGestureRecognizer(new QPinchGestureRecognizer); +#if defined(Q_OS_WIN) + registerGestureRecognizer(new QWinNativePanGestureRecognizer); +#endif #endif } @@ -92,7 +108,7 @@ QGestureManager::~QGestureManager() Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *recognizer) { - QGesture *dummy = recognizer->createGesture(0); + QGesture *dummy = recognizer->create(0); if (!dummy) { qWarning("QGestureManager::registerGestureRecognizer: " "the recognizer fails to create a gesture object, skipping registration."); @@ -172,7 +188,7 @@ QGesture *QGestureManager::getState(QObject *object, QGestureRecognizer *recogni } Q_ASSERT(recognizer); - QGesture *state = recognizer->createGesture(object); + QGesture *state = recognizer->create(object); if (!state) return 0; state->setParent(this); @@ -219,18 +235,19 @@ bool QGestureManager::filterEventThroughContexts(const QMultiHash<QObject *, QGesture *state = getState(target, recognizer, gestureType); if (!state) continue; - QGestureRecognizer::Result result = recognizer->filterEvent(state, target, event); + QGestureRecognizer::Result result = recognizer->recognize(state, target, event); QGestureRecognizer::Result type = result & QGestureRecognizer::ResultState_Mask; - if (type == QGestureRecognizer::GestureTriggered) { + result &= QGestureRecognizer::ResultHint_Mask; + if (type == QGestureRecognizer::TriggerGesture) { DEBUG() << "QGestureManager:Recognizer: gesture triggered: " << state; triggeredGestures << state; - } else if (type == QGestureRecognizer::GestureFinished) { + } else if (type == QGestureRecognizer::FinishGesture) { DEBUG() << "QGestureManager:Recognizer: gesture finished: " << state; finishedGestures << state; - } else if (type == QGestureRecognizer::MaybeGesture) { + } else if (type == QGestureRecognizer::MayBeGesture) { DEBUG() << "QGestureManager:Recognizer: maybe gesture: " << state; newMaybeGestures << state; - } else if (type == QGestureRecognizer::NotGesture) { + } else if (type == QGestureRecognizer::CancelGesture) { DEBUG() << "QGestureManager:Recognizer: not gesture: " << state; notGestures << state; } else if (type == QGestureRecognizer::Ignore) { @@ -346,12 +363,7 @@ bool QGestureManager::filterEventThroughContexts(const QMultiHash<QObject *, QSet<QGesture *> endedGestures = finishedGestures + canceledGestures + undeliveredGestures; foreach (QGesture *gesture, endedGestures) { - if (QGestureRecognizer *recognizer = m_gestureToRecognizer.value(gesture, 0)) { - gesture->setGestureCancelPolicy(QGesture::CancelNone); - recognizer->reset(gesture); - } else { - cleanupGesturesForRemovedRecognizer(gesture); - } + recycle(gesture); m_gestureTargets.remove(gesture); } return ret; @@ -409,15 +421,8 @@ void QGestureManager::cancelGesturesForChildren(QGesture *original) deliverEvents(gestures, &undeliveredGestures); } - for (iter = cancelledGestures.begin(); iter != cancelledGestures.end(); ++iter) { - QGestureRecognizer *recognizer = m_gestureToRecognizer.value(*iter, 0); - if (recognizer) { - (*iter)->setGestureCancelPolicy(QGesture::CancelNone); - recognizer->reset(*iter); - } else { - cleanupGesturesForRemovedRecognizer(*iter); - } - } + for (iter = cancelledGestures.begin(); iter != cancelledGestures.end(); ++iter) + recycle(*iter); } void QGestureManager::cleanupGesturesForRemovedRecognizer(QGesture *gesture) @@ -439,7 +444,7 @@ bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event) QSet<Qt::GestureType> types; QMultiHash<QObject *, Qt::GestureType> contexts; QWidget *w = receiver; - typedef QMap<Qt::GestureType, Qt::GestureContext>::const_iterator ContextIterator; + typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator; if (!w->d_func()->gestureContext.isEmpty()) { for(ContextIterator it = w->d_func()->gestureContext.begin(), e = w->d_func()->gestureContext.end(); it != e; ++it) { @@ -453,7 +458,7 @@ bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event) { for (ContextIterator it = w->d_func()->gestureContext.begin(), e = w->d_func()->gestureContext.end(); it != e; ++it) { - if (it.value() == Qt::WidgetWithChildrenGesture) { + if (!(it.value() & Qt::DontStartGestureOnChildren)) { if (!types.contains(it.key())) { types.insert(it.key()); contexts.insertMulti(w, it.key()); @@ -474,7 +479,7 @@ bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event) QMultiHash<QObject *, Qt::GestureType> contexts; QGraphicsObject *item = receiver; if (!item->QGraphicsItem::d_func()->gestureContext.isEmpty()) { - typedef QMap<Qt::GestureType, Qt::GestureContext>::const_iterator ContextIterator; + typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator; for(ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.begin(), e = item->QGraphicsItem::d_func()->gestureContext.end(); it != e; ++it) { types.insert(it.key()); @@ -485,10 +490,10 @@ bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event) item = item->parentObject(); while (item) { - typedef QMap<Qt::GestureType, Qt::GestureContext>::const_iterator ContextIterator; + typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator; for (ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.begin(), e = item->QGraphicsItem::d_func()->gestureContext.end(); it != e; ++it) { - if (it.value() == Qt::ItemWithChildrenGesture) { + if (!(it.value() & Qt::DontStartGestureOnChildren)) { if (!types.contains(it.key())) { types.insert(it.key()); contexts.insertMulti(item, it.key()); @@ -528,12 +533,12 @@ void QGestureManager::getGestureTargets(const QSet<QGesture*> &gestures, foreach (QWidget *widget, gestures.keys()) { QWidget *w = widget->parentWidget(); while (w) { - QMap<Qt::GestureType, Qt::GestureContext>::const_iterator it + QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator it = w->d_func()->gestureContext.find(type); if (it != w->d_func()->gestureContext.end()) { // i.e. 'w' listens to gesture 'type' - Qt::GestureContext context = it.value(); - if (context == Qt::WidgetWithChildrenGesture && w != widget) { + Qt::GestureFlags flags = it.value(); + if (!(it.value() & Qt::DontStartGestureOnChildren) && w != widget) { // conflicting gesture! (*conflicts)[widget].append(gestures[widget]); break; @@ -627,7 +632,7 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures, QApplication::sendEvent(receiver, &event); bool eventAccepted = event.isAccepted(); - foreach(QGesture *gesture, event.allGestures()) { + foreach(QGesture *gesture, event.gestures()) { if (eventAccepted || event.isAccepted(gesture)) { QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); Q_ASSERT(w); @@ -652,6 +657,16 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures, << "gestures:" << it.value(); QGestureEvent event(it.value()); QApplication::sendEvent(it.key(), &event); + bool eventAccepted = event.isAccepted(); + foreach (QGesture *gesture, event.gestures()) { + if (gesture->state() == Qt::GestureStarted && + (eventAccepted || event.isAccepted(gesture))) { + QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); + Q_ASSERT(w); + DEBUG() << "started gesture was delivered and accepted by" << w; + m_gestureTargets[gesture] = w; + } + } } } } @@ -669,19 +684,24 @@ void QGestureManager::timerEvent(QTimerEvent *event) it = m_maybeGestures.erase(it); DEBUG() << "QGestureManager::timerEvent: gesture stopped due to timeout:" << gesture; - QGestureRecognizer *recognizer = m_gestureToRecognizer.value(gesture, 0); - if (recognizer) { - gesture->setGestureCancelPolicy(QGesture::CancelNone); - recognizer->reset(gesture); - } else { - cleanupGesturesForRemovedRecognizer(gesture); - } + recycle(gesture); } else { ++it; } } } +void QGestureManager::recycle(QGesture *gesture) +{ + QGestureRecognizer *recognizer = m_gestureToRecognizer.value(gesture, 0); + if (recognizer) { + gesture->setGestureCancelPolicy(QGesture::CancelNone); + recognizer->reset(gesture); + } else { + cleanupGesturesForRemovedRecognizer(gesture); + } +} + QT_END_NAMESPACE #include "moc_qgesturemanager_p.cpp" diff --git a/src/gui/kernel/qgesturemanager_p.h b/src/gui/kernel/qgesturemanager_p.h index 1e0734b..4efa10b 100644 --- a/src/gui/kernel/qgesturemanager_p.h +++ b/src/gui/kernel/qgesturemanager_p.h @@ -78,11 +78,12 @@ public: bool filterEvent(QGraphicsObject *receiver, QEvent *event); #endif //QT_NO_GRAPHICSVIEW - // declared in qapplication.cpp static QGestureManager* instance(); void cleanupCachedGestures(QObject *target, Qt::GestureType type); + void recycle(QGesture *gesture); + protected: void timerEvent(QTimerEvent *event); bool filterEventThroughContexts(const QMultiHash<QObject *, Qt::GestureType> &contexts, @@ -141,6 +142,8 @@ private: void cancelGesturesForChildren(QGesture *originatingGesture); }; +extern QGestureManager *qt_gestureManager; + QT_END_NAMESPACE #endif // QGESTUREMANAGER_P_H diff --git a/src/gui/kernel/qgesturerecognizer.cpp b/src/gui/kernel/qgesturerecognizer.cpp index 2673be3..ed0bdcc 100644 --- a/src/gui/kernel/qgesturerecognizer.cpp +++ b/src/gui/kernel/qgesturerecognizer.cpp @@ -42,6 +42,7 @@ #include "qgesturerecognizer.h" #include "private/qgesture_p.h" +#include "private/qgesturemanager_p.h" QT_BEGIN_NAMESPACE @@ -65,12 +66,12 @@ QT_BEGIN_NAMESPACE objects, and modifying the associated QGesture objects to include relevant information about the user's input. - Gestures are created when the framework calls createGesture() to handle user input + Gestures are created when the framework calls create() to handle user input for a particular instance of a QWidget or QGraphicsObject subclass. A QGesture object is created for each widget or item that is configured to use gestures. Once a QGesture has been created for a target object, the gesture recognizer will - receive events for it in its filterEvent() handler function. + receive events for it in its recognize() handler function. When a gesture is canceled, the reset() function is called, giving the recognizer the chance to update the appropriate properties in the corresponding QGesture object. @@ -79,20 +80,22 @@ QT_BEGIN_NAMESPACE To add support for new gestures, you need to derive from QGestureRecognizer to create a custom recognizer class, construct an instance of this class, and register it with - the application by calling QApplication::registerGestureRecognizer(). You can also + the application by calling QGestureRecognizer::registerRecognizer(). You can also subclass QGesture to create a custom gesture class, or rely on dynamic properties to express specific details of the gesture you want to handle. - Your custom QGestureRecognizer subclass needs to reimplement the filterEvent() function - to handle and filter the incoming input events for QWidget and QGraphicsObject subclasses. - Although the logic for gesture recognition is implemented in this function, you can - store persistent information about the state of the recognition process in the QGesture - object supplied. The filterEvent() function must return a value of Qt::GestureState that - indicates the state of recognition for a given gesture and target object. This determines - whether or not a gesture event will be delivered to a target object. + Your custom QGestureRecognizer subclass needs to reimplement the recognize() + function to handle and filter the incoming input events for QWidget and + QGraphicsObject subclasses. Although the logic for gesture recognition is + implemented in this function, you can store persistent information about the + state of the recognition process in the QGesture object supplied. The + recognize() function must return a value of QGestureRecognizer::Result that + indicates the state of recognition for a given gesture and target object. + This determines whether or not a gesture event will be delivered to a target + object. If you choose to represent a gesture by a custom QGesture subclass, you will need to - reimplement the createGesture() function to construct instances of your gesture class. + reimplement the create() function to construct instances of your gesture class. Similarly, you may need to reimplement the reset() function if your custom gesture objects need to be specially handled when a gesture is canceled. @@ -105,37 +108,37 @@ QT_BEGIN_NAMESPACE This enum describes the result of the current event filtering step in a gesture recognizer state machine. - The result consists of a state value (one of Ignore, NotGesture, - MaybeGesture, GestureTriggered, GestureFinished) and an optional hint + The result consists of a state value (one of Ignore, MayBeGesture, + TriggerGesture, FinishGesture, CancelGesture) and an optional hint (ConsumeEventHint). \value Ignore The event does not change the state of the recognizer. - \value NotGesture The event made it clear that it is not a gesture. If the - gesture recognizer was in GestureTriggered state before, then the gesture - is canceled and the appropriate QGesture object will be delivered to the - target as a part of a QGestureEvent. - - \value MaybeGesture The event changed the internal state of the recognizer, + \value MayBeGesture The event changed the internal state of the recognizer, but it isn't clear yet if it is a gesture or not. The recognizer needs to - filter more events to decide. Gesture recognizers in the MaybeGesture state + filter more events to decide. Gesture recognizers in the MayBeGesture state may be reset automatically if they take too long to recognize gestures. - \value GestureTriggered The gesture has been triggered and the appropriate + \value TriggerGesture The gesture has been triggered and the appropriate QGesture object will be delivered to the target as a part of a QGestureEvent. - \value GestureFinished The gesture has been finished successfully and the + \value FinishGesture The gesture has been finished successfully and the appropriate QGesture object will be delivered to the target as a part of a QGestureEvent. - \value ConsumeEventHint This hint specifies that the gesture framework should - consume the filtered event and not deliver it to the receiver. + \value CancelGesture The event made it clear that it is not a gesture. If + the gesture recognizer was in GestureTriggered state before, then the + gesture is canceled and the appropriate QGesture object will be delivered + to the target as a part of a QGestureEvent. + + \value ConsumeEventHint This hint specifies that the gesture framework + should consume the filtered event and not deliver it to the receiver. \omitvalue ResultState_Mask \omitvalue ResultHint_Mask - \sa QGestureRecognizer::filterEvent() + \sa QGestureRecognizer::recognize() */ /*! @@ -159,7 +162,7 @@ QGestureRecognizer::~QGestureRecognizer() Reimplement this function to create a custom QGesture-derived gesture object if necessary. */ -QGesture *QGestureRecognizer::createGesture(QObject *target) +QGesture *QGestureRecognizer::create(QObject *target) { Q_UNUSED(target); return new QGesture; @@ -183,7 +186,7 @@ void QGestureRecognizer::reset(QGesture *gesture) } /*! - \fn QGestureRecognizer::filterEvent(QGesture *gesture, QObject *watched, QEvent *event) + \fn QGestureRecognizer::recognize(QGesture *gesture, QObject *watched, QEvent *event) Handles the given \a event for the \a watched object, updating the state of the \a gesture object as required, and returns a suitable result for the current recognition step. @@ -194,7 +197,34 @@ void QGestureRecognizer::reset(QGesture *gesture) The result reflects how much of the gesture has been recognized. The state of the \a gesture object is set depending on the result. - \sa Qt::GestureState + \sa QGestureRecognizer::Result +*/ + +/*! + Registers the given \a recognizer in the gesture framework and returns a gesture ID + for it. + + The application takes ownership of the \a recognizer and returns the gesture type + ID associated with it. For gesture recognizers which handle custom QGesture + objects (i.e., those which return Qt::CustomGesture in a QGesture::gestureType() + function) the return value is a generated gesture ID with the Qt::CustomGesture + flag set. + + \sa unregisterRecognizer(), QGestureRecognizer::create(), QGesture */ +Qt::GestureType QGestureRecognizer::registerRecognizer(QGestureRecognizer *recognizer) +{ + return QGestureManager::instance()->registerGestureRecognizer(recognizer); +} + +/*! + Unregisters all gesture recognizers of the specified \a type. + + \sa registerRecognizer() +*/ +void QGestureRecognizer::unregisterRecognizer(Qt::GestureType type) +{ + QGestureManager::instance()->unregisterGestureRecognizer(type); +} QT_END_NAMESPACE diff --git a/src/gui/kernel/qgesturerecognizer.h b/src/gui/kernel/qgesturerecognizer.h index a3c990d..4eebf7c 100644 --- a/src/gui/kernel/qgesturerecognizer.h +++ b/src/gui/kernel/qgesturerecognizer.h @@ -43,6 +43,7 @@ #define QGESTURERECOGNIZER_H #include <QtCore/qglobal.h> +#include <QtCore/qnamespace.h> QT_BEGIN_HEADER @@ -58,30 +59,34 @@ class Q_GUI_EXPORT QGestureRecognizer public: enum ResultFlag { - Ignore = 0x0001, - NotGesture = 0x0002, - MaybeGesture = 0x0004, - GestureTriggered = 0x0008, // Gesture started or updated - GestureFinished = 0x0010, + Ignore = 0x0001, - ResultState_Mask = 0x00ff, + MayBeGesture = 0x0002, + TriggerGesture = 0x0004, + FinishGesture = 0x0008, + CancelGesture = 0x0010, + + ResultState_Mask = 0x00ff, ConsumeEventHint = 0x0100, // StoreEventHint = 0x0200, // ReplayStoredEventsHint = 0x0400, // DiscardStoredEventsHint = 0x0800, - ResultHint_Mask = 0xff00 + ResultHint_Mask = 0xff00 }; Q_DECLARE_FLAGS(Result, ResultFlag) QGestureRecognizer(); virtual ~QGestureRecognizer(); - virtual QGesture *createGesture(QObject *target); - virtual QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event) = 0; - + virtual QGesture *create(QObject *target); + virtual Result recognize(QGesture *state, QObject *watched, + QEvent *event) = 0; virtual void reset(QGesture *state); + + static Qt::GestureType registerRecognizer(QGestureRecognizer *recognizer); + static void unregisterRecognizer(Qt::GestureType type); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QGestureRecognizer::Result) diff --git a/src/gui/kernel/qguiplatformplugin.cpp b/src/gui/kernel/qguiplatformplugin.cpp index b01d40f..e6efec1 100644 --- a/src/gui/kernel/qguiplatformplugin.cpp +++ b/src/gui/kernel/qguiplatformplugin.cpp @@ -59,9 +59,9 @@ extern bool qt_wince_is_pocket_pc(); //qguifunctions_wince.cpp #if defined(Q_WS_X11) -#include "qkde_p.h" -#include "qt_x11_p.h" -#include <private/gtksymbols_p.h> +#include <private/qkde_p.h> +#include <private/qgtkstyle_p.h> +#include <private/qt_x11_p.h> #endif @@ -206,7 +206,7 @@ QString QGuiPlatformPlugin::systemIconThemeName() if (X11->desktopEnvironment == DE_GNOME) { result = QString::fromLatin1("gnome"); #ifndef QT_NO_STYLE_GTK - result = QGtk::getGConfString(QLatin1String("/desktop/gnome/interface/icon_theme"), result); + result = QGtkStylePrivate::getGConfString(QLatin1String("/desktop/gnome/interface/icon_theme"), result); #endif } else if (X11->desktopEnvironment == DE_KDE) { result = X11->desktopVersion >= 4 ? QString::fromLatin1("oxygen") : QString::fromLatin1("crystalsvg"); diff --git a/src/gui/kernel/qmacgesturerecognizer_mac.mm b/src/gui/kernel/qmacgesturerecognizer_mac.mm index 7019580..d842322 100644 --- a/src/gui/kernel/qmacgesturerecognizer_mac.mm +++ b/src/gui/kernel/qmacgesturerecognizer_mac.mm @@ -53,13 +53,13 @@ QMacSwipeGestureRecognizer::QMacSwipeGestureRecognizer() { } -QGesture *QMacSwipeGestureRecognizer::createGesture(QObject * /*target*/) +QGesture *QMacSwipeGestureRecognizer::create(QObject * /*target*/) { return new QSwipeGesture; } QGestureRecognizer::Result -QMacSwipeGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent *event) +QMacSwipeGestureRecognizer::recognize(QGesture *gesture, QObject *obj, QEvent *event) { if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) { QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event); @@ -67,7 +67,7 @@ QMacSwipeGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent case QNativeGestureEvent::Swipe: { QSwipeGesture *g = static_cast<QSwipeGesture *>(gesture); g->setSwipeAngle(ev->angle); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; break; } default: break; @@ -90,13 +90,13 @@ QMacPinchGestureRecognizer::QMacPinchGestureRecognizer() { } -QGesture *QMacPinchGestureRecognizer::createGesture(QObject * /*target*/) +QGesture *QMacPinchGestureRecognizer::create(QObject * /*target*/) { return new QPinchGesture; } QGestureRecognizer::Result -QMacPinchGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent *event) +QMacPinchGestureRecognizer::recognize(QGesture *gesture, QObject *obj, QEvent *event) { if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) { QPinchGesture *g = static_cast<QPinchGesture *>(gesture); @@ -106,26 +106,26 @@ QMacPinchGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent reset(gesture); g->setStartCenterPoint(static_cast<QWidget*>(obj)->mapFromGlobal(ev->position)); g->setCenterPoint(g->startCenterPoint()); - g->setWhatChanged(QPinchGesture::CenterPointChanged); - return QGestureRecognizer::MaybeGesture | QGestureRecognizer::ConsumeEventHint; + g->setChangeFlags(QPinchGesture::CenterPointChanged); + g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); + return QGestureRecognizer::MayBeGesture | QGestureRecognizer::ConsumeEventHint; case QNativeGestureEvent::Rotate: { g->setLastScaleFactor(g->scaleFactor()); g->setLastRotationAngle(g->rotationAngle()); g->setRotationAngle(g->rotationAngle() + ev->percentage); - g->setWhatChanged(QPinchGesture::RotationAngleChanged); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; - break; + g->setChangeFlags(QPinchGesture::RotationAngleChanged); + g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } case QNativeGestureEvent::Zoom: g->setLastScaleFactor(g->scaleFactor()); g->setLastRotationAngle(g->rotationAngle()); g->setScaleFactor(g->scaleFactor() + ev->percentage); - g->setWhatChanged(QPinchGesture::ScaleFactorChanged); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; - break; + g->setChangeFlags(QPinchGesture::ScaleFactorChanged); + g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; case QNativeGestureEvent::GestureEnd: - return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint; - break; + return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; default: break; } @@ -137,7 +137,8 @@ QMacPinchGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent void QMacPinchGestureRecognizer::reset(QGesture *gesture) { QPinchGesture *g = static_cast<QPinchGesture *>(gesture); - g->setWhatChanged(0); + g->setChangeFlags(0); + g->setTotalChangeFlags(0); g->setScaleFactor(1.0f); g->setTotalScaleFactor(1.0f); g->setLastScaleFactor(1.0f); @@ -158,7 +159,7 @@ QMacPanGestureRecognizer::QMacPanGestureRecognizer() : _panCanceled(true) { } -QGesture *QMacPanGestureRecognizer::createGesture(QObject *target) +QGesture *QMacPanGestureRecognizer::create(QObject *target) { if (!target) return new QPanGesture; @@ -172,7 +173,7 @@ QGesture *QMacPanGestureRecognizer::createGesture(QObject *target) } QGestureRecognizer::Result -QMacPanGestureRecognizer::filterEvent(QGesture *gesture, QObject *target, QEvent *event) +QMacPanGestureRecognizer::recognize(QGesture *gesture, QObject *target, QEvent *event) { const int panBeginDelay = 300; const int panBeginRadius = 3; @@ -185,10 +186,9 @@ QMacPanGestureRecognizer::filterEvent(QGesture *gesture, QObject *target, QEvent if (ev->touchPoints().size() == 1) { reset(gesture); _startPos = QCursor::pos(); - _lastPos = _startPos; _panTimer.start(panBeginDelay, target); _panCanceled = false; - return QGestureRecognizer::MaybeGesture; + return QGestureRecognizer::MayBeGesture; } break;} case QEvent::TouchEnd: { @@ -197,7 +197,7 @@ QMacPanGestureRecognizer::filterEvent(QGesture *gesture, QObject *target, QEvent const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); if (ev->touchPoints().size() == 1) - return QGestureRecognizer::GestureFinished; + return QGestureRecognizer::FinishGesture; break;} case QEvent::TouchUpdate: { if (_panCanceled) @@ -212,23 +212,21 @@ QMacPanGestureRecognizer::filterEvent(QGesture *gesture, QObject *target, QEvent if ((p - _startPos).manhattanLength() > panBeginRadius) { _panCanceled = true; _panTimer.stop(); - return QGestureRecognizer::NotGesture; + return QGestureRecognizer::CancelGesture; } } else { const QPointF p = QCursor::pos(); - const QPointF posOffset = p - _lastPos; + const QPointF posOffset = p - _startPos; g->setLastOffset(g->offset()); g->setOffset(QPointF(posOffset.x(), posOffset.y())); - g->setTotalOffset(g->lastOffset() + g->offset()); - _lastPos = p; - return QGestureRecognizer::GestureTriggered; + return QGestureRecognizer::TriggerGesture; } } else if (_panTimer.isActive()) { // I only want to cancel the pan if the user is pressing // more than one finger, and the pan hasn't started yet: _panCanceled = true; _panTimer.stop(); - return QGestureRecognizer::NotGesture; + return QGestureRecognizer::CancelGesture; } break;} case QEvent::Timer: { @@ -239,8 +237,7 @@ QMacPanGestureRecognizer::filterEvent(QGesture *gesture, QObject *target, QEvent break; // Begin new pan session! _startPos = QCursor::pos(); - _lastPos = _startPos; - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } break; } default: @@ -254,11 +251,9 @@ void QMacPanGestureRecognizer::reset(QGesture *gesture) { QPanGesture *g = static_cast<QPanGesture *>(gesture); _startPos = QPointF(); - _lastPos = QPointF(); _panCanceled = true; g->setOffset(QPointF(0, 0)); g->setLastOffset(QPointF(0, 0)); - g->setTotalOffset(QPointF(0, 0)); g->setAcceleration(qreal(1)); QGestureRecognizer::reset(gesture); } diff --git a/src/gui/kernel/qmacgesturerecognizer_mac_p.h b/src/gui/kernel/qmacgesturerecognizer_mac_p.h index bdc2e08..2dac56a 100644 --- a/src/gui/kernel/qmacgesturerecognizer_mac_p.h +++ b/src/gui/kernel/qmacgesturerecognizer_mac_p.h @@ -64,8 +64,8 @@ class QMacSwipeGestureRecognizer : public QGestureRecognizer public: QMacSwipeGestureRecognizer(); - QGesture *createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *gesture, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event); void reset(QGesture *gesture); }; @@ -74,8 +74,8 @@ class QMacPinchGestureRecognizer : public QGestureRecognizer public: QMacPinchGestureRecognizer(); - QGesture *createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *gesture, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event); void reset(QGesture *gesture); }; @@ -86,12 +86,11 @@ class QMacPanGestureRecognizer : public QObject, public QGestureRecognizer public: QMacPanGestureRecognizer(); - QGesture *createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *gesture, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event); void reset(QGesture *gesture); private: QPointF _startPos; - QPointF _lastPos; QBasicTimer _panTimer; bool _panCanceled; }; diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index dec2311..dfd49eb 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -44,6 +44,7 @@ #include "qgesture_p.h" #include "qevent.h" #include "qwidget.h" +#include "qabstractscrollarea.h" QT_BEGIN_NAMESPACE @@ -51,29 +52,34 @@ QPanGestureRecognizer::QPanGestureRecognizer() { } -QGesture *QPanGestureRecognizer::createGesture(QObject *target) +QGesture *QPanGestureRecognizer::create(QObject *target) { if (target && target->isWidgetType()) { +#if defined(Q_OS_WIN) + // for scroll areas on Windows we want to use native gestures instead + if (!qobject_cast<QAbstractScrollArea *>(target->parent())) + static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents); +#else static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents); +#endif } return new QPanGesture; } -QGestureRecognizer::Result QPanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) { - QPanGesture *q = static_cast<QPanGesture*>(state); + QPanGesture *q = static_cast<QPanGesture *>(state); QPanGesturePrivate *d = q->d_func(); - const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); + const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); QGestureRecognizer::Result result; switch (event->type()) { case QEvent::TouchBegin: { - result = QGestureRecognizer::MaybeGesture; + result = QGestureRecognizer::MayBeGesture; QTouchEvent::TouchPoint p = ev->touchPoints().at(0); - d->lastPosition = p.pos().toPoint(); - d->lastOffset = d->totalOffset = d->offset = QPointF(); + d->lastOffset = d->offset = QPointF(); break; } case QEvent::TouchEnd: { @@ -83,13 +89,12 @@ QGestureRecognizer::Result QPanGestureRecognizer::filterEvent(QGesture *state, Q QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); d->lastOffset = d->offset; d->offset = - QPointF(p1.pos().x() - p1.lastPos().x() + p2.pos().x() - p2.lastPos().x(), - p1.pos().y() - p1.lastPos().y() + p2.pos().y() - p2.lastPos().y()) / 2; - d->totalOffset += d->offset; + QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(), + p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2; } - result = QGestureRecognizer::GestureFinished; + result = QGestureRecognizer::FinishGesture; } else { - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; } break; } @@ -99,14 +104,13 @@ QGestureRecognizer::Result QPanGestureRecognizer::filterEvent(QGesture *state, Q QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); d->lastOffset = d->offset; d->offset = - QPointF(p1.pos().x() - p1.lastPos().x() + p2.pos().x() - p2.lastPos().x(), - p1.pos().y() - p1.lastPos().y() + p2.pos().y() - p2.lastPos().y()) / 2; - d->totalOffset += d->offset; - if (d->totalOffset.x() > 10 || d->totalOffset.y() > 10 || - d->totalOffset.x() < -10 || d->totalOffset.y() < -10) { - result = QGestureRecognizer::GestureTriggered; + QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(), + p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2; + if (d->offset.x() > 10 || d->offset.y() > 10 || + d->offset.x() < -10 || d->offset.y() < -10) { + result = QGestureRecognizer::TriggerGesture; } else { - result = QGestureRecognizer::MaybeGesture; + result = QGestureRecognizer::MayBeGesture; } } break; @@ -128,108 +132,128 @@ void QPanGestureRecognizer::reset(QGesture *state) QPanGesture *pan = static_cast<QPanGesture*>(state); QPanGesturePrivate *d = pan->d_func(); - d->totalOffset = d->lastOffset = d->offset = QPointF(); - d->lastPosition = QPoint(); + d->lastOffset = d->offset = QPointF(); d->acceleration = 0; -//#if defined(QT_MAC_USE_COCOA) -// d->singleTouchPanTimer.stop(); -// d->prevMousePos = QPointF(0, 0); -//#endif - QGestureRecognizer::reset(state); } -/* -bool QPanGestureRecognizer::event(QEvent *event) + +// +// QPinchGestureRecognizer +// + +QPinchGestureRecognizer::QPinchGestureRecognizer() { -#if defined(QT_MAC_USE_COCOA) - Q_D(QPanGesture); - if (event->type() == QEvent::Timer) { - const QTimerEvent *te = static_cast<QTimerEvent *>(event); - if (te->timerId() == d->singleTouchPanTimer.timerId()) { - d->singleTouchPanTimer.stop(); - updateState(Qt::GestureStarted); - } +} + +QGesture *QPinchGestureRecognizer::create(QObject *target) +{ + if (target && target->isWidgetType()) { + static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents); } -#endif + return new QPinchGesture; +} - bool consume = false; +QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) +{ + QPinchGesture *q = static_cast<QPinchGesture *>(state); + QPinchGesturePrivate *d = q->d_func(); + + const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); -#if defined(Q_WS_WIN) -#elif defined(QT_MAC_USE_COCOA) - // The following implements single touch - // panning on Mac: - const int panBeginDelay = 300; - const int panBeginRadius = 3; - const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); + QGestureRecognizer::Result result; switch (event->type()) { case QEvent::TouchBegin: { - if (ev->touchPoints().size() == 1) { - d->delayManager->setEnabled(true); - consume = d->delayManager->append(d->gestureTarget, *event); - d->lastPosition = QCursor::pos(); - d->singleTouchPanTimer.start(panBeginDelay, this); - } - break;} + result = QGestureRecognizer::MayBeGesture; + break; + } case QEvent::TouchEnd: { - d->delayManager->setEnabled(false); - if (state() != Qt::NoGesture) { - updateState(Qt::GestureFinished); - consume = true; - d->delayManager->clear(); + if (q->state() != Qt::NoGesture) { + result = QGestureRecognizer::FinishGesture; } else { - d->delayManager->replay(); + result = QGestureRecognizer::CancelGesture; } - reset(); - break;} + break; + } case QEvent::TouchUpdate: { - consume = d->delayManager->append(d->gestureTarget, *event); - if (ev->touchPoints().size() == 1) { - if (state() == Qt::NoGesture) { - // INVARIANT: The singleTouchTimer has still not fired. - // Lets check if the user moved his finger so much from - // the starting point that it makes sense to cancel: - const QPointF startPos = ev->touchPoints().at(0).startPos().toPoint(); - const QPointF p = ev->touchPoints().at(0).pos().toPoint(); - if ((startPos - p).manhattanLength() > panBeginRadius) { - d->delayManager->replay(); - consume = false; - reset(); - } else { - d->lastPosition = QCursor::pos(); - } + d->changeFlags = 0; + if (ev->touchPoints().size() == 2) { + QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); + QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); + + d->hotSpot = p1.screenPos(); + d->isHotSpotSet = true; + + if (d->isNewSequence) { + d->startPosition[0] = p1.screenPos(); + d->startPosition[1] = p2.screenPos(); + } + QLineF line(p1.screenPos(), p2.screenPos()); + QLineF tmp(line); + tmp.setLength(line.length() / 2.); + QPointF centerPoint = tmp.p2(); + + d->lastCenterPoint = d->centerPoint; + d->centerPoint = centerPoint; + d->changeFlags |= QPinchGesture::CenterPointChanged; + + const qreal scaleFactor = QLineF(p1.pos(), p2.pos()).length() + / QLineF(d->startPosition[0], d->startPosition[1]).length(); + if (d->isNewSequence) { + d->lastScaleFactor = scaleFactor; } else { - d->delayManager->clear(); - QPointF mousePos = QCursor::pos(); - QPointF dist = mousePos - d->lastPosition; - d->lastPosition = mousePos; - d->lastOffset = d->offset; - d->offset = QSizeF(dist.x(), dist.y()); - d->totalOffset += d->offset; - updateState(Qt::GestureUpdated); + d->lastScaleFactor = d->scaleFactor; } - } else if (state() == Qt::NoGesture) { - d->delayManager->replay(); - consume = false; - reset(); + d->scaleFactor = scaleFactor; + d->totalScaleFactor += d->scaleFactor - d->lastScaleFactor; + d->changeFlags |= QPinchGesture::ScaleFactorChanged; + + const qreal rotationAngle = -line.angle(); + if (d->isNewSequence) + d->lastRotationAngle = rotationAngle; + else + d->lastRotationAngle = d->rotationAngle; + d->rotationAngle = rotationAngle; + d->totalRotationAngle += d->rotationAngle - d->lastRotationAngle; + d->changeFlags |= QPinchGesture::RotationAngleChanged; + + d->totalChangeFlags |= d->changeFlags; + d->isNewSequence = false; + result = QGestureRecognizer::TriggerGesture; + } else { + d->isNewSequence = true; + result = QGestureRecognizer::MayBeGesture; } - break;} + break; + } case QEvent::MouseButtonPress: case QEvent::MouseMove: case QEvent::MouseButtonRelease: - if (d->delayManager->isEnabled()) - consume = d->delayManager->append(d->gestureTarget, *event); + result = QGestureRecognizer::Ignore; break; default: - return false; + result = QGestureRecognizer::Ignore; + break; } -#else - Q_UNUSED(event); -#endif - return QGestureRecognizer::Ignore; + return result; +} + +void QPinchGestureRecognizer::reset(QGesture *state) +{ + QPinchGesture *pinch = static_cast<QPinchGesture *>(state); + QPinchGesturePrivate *d = pinch->d_func(); + + d->totalChangeFlags = d->changeFlags = 0; + + d->startCenterPoint = d->lastCenterPoint = d->centerPoint = QPointF(); + d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 0; + d->totalRotationAngle = d->lastRotationAngle = d->rotationAngle = 0; + + d->isNewSequence = true; + + QGestureRecognizer::reset(state); } - */ QT_END_NAMESPACE diff --git a/src/gui/kernel/qstandardgestures_p.h b/src/gui/kernel/qstandardgestures_p.h index fec5c2f..e6f346c 100644 --- a/src/gui/kernel/qstandardgestures_p.h +++ b/src/gui/kernel/qstandardgestures_p.h @@ -63,9 +63,19 @@ class QPanGestureRecognizer : public QGestureRecognizer public: QPanGestureRecognizer(); - QGesture *createGesture(QObject *target); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); + void reset(QGesture *state); +}; + +class QPinchGestureRecognizer : public QGestureRecognizer +{ +public: + QPinchGestureRecognizer(); + + QGesture *create(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 9165515..6a72cfa 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -197,6 +197,7 @@ QWidgetPrivate::QWidgetPrivate(int version) , picture(0) #elif defined(Q_WS_WIN) , noPaintOnScreen(0) + , nativeGesturePanEnabled(0) #elif defined(Q_WS_MAC) , needWindowChange(0) , isGLWidget(0) @@ -11736,22 +11737,22 @@ QGraphicsProxyWidget *QWidget::graphicsProxyWidget() const */ /*! - Subscribes the widget to a given \a gesture with a \a context. + Subscribes the widget to a given \a gesture with specific \a flags. - \sa QGestureEvent + \sa ungrabGesture(), QGestureEvent \since 4.6 */ -void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureContext context) +void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags) { Q_D(QWidget); - d->gestureContext.insert(gesture, context); + d->gestureContext.insert(gesture, flags); (void)QGestureManager::instance(); // create a gesture manager } /*! - Unsubscribes the widget to a given \a gesture type + Unsubscribes the widget from a given \a gesture type - \sa QGestureEvent + \sa grabGesture(), QGestureEvent \since 4.6 */ void QWidget::ungrabGesture(Qt::GestureType gesture) diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index fce3f09..05f0069 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -354,7 +354,7 @@ public: QGraphicsEffect *graphicsEffect() const; void setGraphicsEffect(QGraphicsEffect *effect); - void grabGesture(Qt::GestureType type, Qt::GestureContext context = Qt::WidgetWithChildrenGesture); + void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags()); void ungrabGesture(Qt::GestureType type); public Q_SLOTS: diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 58252ca..9270220 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -3017,10 +3017,17 @@ void QWidgetPrivate::setWindowIcon_sys(bool forceReset) #else QMacCocoaAutoReleasePool pool; NSButton *iconButton = [qt_mac_window_for(q) standardWindowButton:NSWindowDocumentIconButton]; + if (iconButton == nil) { + QCFString string(q->windowTitle()); + const NSString *tmpString = reinterpret_cast<const NSString *>((CFStringRef)string); + [qt_mac_window_for(q) setRepresentedURL:[NSURL fileURLWithPath:tmpString]]; + iconButton = [qt_mac_window_for(q) standardWindowButton:NSWindowDocumentIconButton]; + } if (icon.isNull()) { [iconButton setImage:nil]; } else { - NSImage *image = static_cast<NSImage *>(qt_mac_create_nsimage(*pm)); + QPixmap scaled = pm->scaled(QSize(16,16), Qt::KeepAspectRatio, Qt::SmoothTransformation); + NSImage *image = static_cast<NSImage *>(qt_mac_create_nsimage(scaled)); [iconButton setImage:image]; [image release]; } diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 73a7d68..8b03a85 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -630,7 +630,7 @@ public: #ifndef QT_NO_ACTION QList<QAction*> actions; #endif - QMap<Qt::GestureType, Qt::GestureContext> gestureContext; + QMap<Qt::GestureType, Qt::GestureFlags> gestureContext; // Bit fields. uint high_attributes[3]; // the low ones are in QWidget::widget_attributes diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp index 5bf7649..22a94b9 100644 --- a/src/gui/kernel/qwidget_win.cpp +++ b/src/gui/kernel/qwidget_win.cpp @@ -2036,7 +2036,7 @@ void QWidgetPrivate::winSetupGestures() if (!q || !q->isVisible()) return; QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); - WId winid = q->effectiveWinId(); + WId winid = q->internalWinId(); bool needh = false; bool needv = false; @@ -2052,6 +2052,8 @@ void QWidgetPrivate::winSetupGestures() needv = (vbarpolicy == Qt::ScrollBarAlwaysOn || (vbarpolicy == Qt::ScrollBarAsNeeded && vbar->minimum() < vbar->maximum())); singleFingerPanEnabled = asa->d_func()->singleFingerPanEnabled; + if (!winid) + winid = q->winId(); // enforces the native winid on the viewport } if (winid && qAppPriv->SetGestureConfig) { GESTURECONFIG gc[1]; @@ -2071,17 +2073,6 @@ void QWidgetPrivate::winSetupGestures() gc[0].dwBlock = GC_PAN; } -// gc[1].dwID = GID_ZOOM; -// if (gestures.pinch) -// gc[1].dwWant = GC_ZOOM; -// else -// gc[1].dwBlock = GC_ZOOM; -// gc[2].dwID = GID_ROTATE; -// if (gestures.pinch) -// gc[2].dwWant = GC_ROTATE; -// else -// gc[2].dwBlock = GC_ROTATE; - qAppPriv->SetGestureConfig(winid, 0, sizeof(gc)/sizeof(gc[0]), gc, sizeof(gc[0])); } } diff --git a/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp b/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp index 12d3058..5fceb13 100644 --- a/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp +++ b/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp @@ -56,16 +56,16 @@ QWinNativePanGestureRecognizer::QWinNativePanGestureRecognizer() { } -QGesture* QWinNativePanGestureRecognizer::createGesture(QObject *target) const +QGesture *QWinNativePanGestureRecognizer::create(QObject *target) { if (!target) return new QPanGesture; // a special case - if (qobject_cast<QGraphicsObject*>(target)) - return 0; if (!target->isWidgetType()) return 0; + if (qobject_cast<QGraphicsObject *>(target)) + return 0; - QWidget *q = static_cast<QWidget*>(target); + QWidget *q = static_cast<QWidget *>(target); QWidgetPrivate *d = q->d_func(); d->nativeGesturePanEnabled = true; d->winSetupGestures(); @@ -73,7 +73,9 @@ QGesture* QWinNativePanGestureRecognizer::createGesture(QObject *target) const return new QPanGesture; } -QGestureRecognizer::Result QWinNativePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +QGestureRecognizer::Result QWinNativePanGestureRecognizer::recognize(QGesture *state, + QObject *, + QEvent *event) { QPanGesture *q = static_cast<QPanGesture*>(state); QPanGesturePrivate *d = q->d_func(); @@ -85,26 +87,25 @@ QGestureRecognizer::Result QWinNativePanGestureRecognizer::filterEvent(QGesture case QNativeGestureEvent::GestureBegin: break; case QNativeGestureEvent::Pan: - result = QGestureRecognizer::GestureTriggered; + result = QGestureRecognizer::TriggerGesture; event->accept(); break; case QNativeGestureEvent::GestureEnd: if (q->state() == Qt::NoGesture) return QGestureRecognizer::Ignore; // some other gesture has ended - result = QGestureRecognizer::GestureFinished; + result = QGestureRecognizer::FinishGesture; break; default: return QGestureRecognizer::Ignore; } if (q->state() == Qt::NoGesture) { - d->lastOffset = d->totalOffset = d->offset = QPointF(); + d->lastOffset = d->offset = QPointF(); + d->startPosition = ev->position; } else { d->lastOffset = d->offset; - d->offset = QPointF(ev->position.x() - d->lastPosition.x(), - ev->position.y() - d->lastPosition.y()); - d->totalOffset += d->offset; + d->offset = QPointF(ev->position.x() - d->startPosition.x(), + ev->position.y() - d->startPosition.y()); } - d->lastPosition = ev->position; } return result; } @@ -114,8 +115,8 @@ void QWinNativePanGestureRecognizer::reset(QGesture *state) QPanGesture *pan = static_cast<QPanGesture*>(state); QPanGesturePrivate *d = pan->d_func(); - d->totalOffset = d->lastOffset = d->offset = QPointF(); - d->lastPosition = QPoint(); + d->lastOffset = d->offset = QPointF(); + d->startPosition = QPoint(); d->acceleration = 0; QGestureRecognizer::reset(state); diff --git a/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h b/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h index a1e8511..8fb0d50 100644 --- a/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h +++ b/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h @@ -62,9 +62,8 @@ class QWinNativePanGestureRecognizer : public QGestureRecognizer public: QWinNativePanGestureRecognizer(); - QGesture* createGesture(QObject *target) const; - - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; diff --git a/src/gui/math3d/qgenericmatrix.cpp b/src/gui/math3d/qgenericmatrix.cpp index d211229..aa98536 100644 --- a/src/gui/math3d/qgenericmatrix.cpp +++ b/src/gui/math3d/qgenericmatrix.cpp @@ -80,7 +80,7 @@ QT_BEGIN_NAMESPACE The contents of the array \a values is assumed to be in row-major order. - \sa toValueArray() + \sa copyDataTo() */ /*! @@ -102,11 +102,11 @@ QT_BEGIN_NAMESPACE Returns true if this matrix is the identity; false otherwise. - \sa setIdentity() + \sa setToIdentity() */ /*! - \fn void QGenericMatrix::setIdentity() + \fn void QGenericMatrix::setToIdentity() Sets this matrix to the identity. @@ -213,9 +213,9 @@ QT_BEGIN_NAMESPACE */ /*! - \fn void QGenericMatrix::toValueArray(T *values) + \fn void QGenericMatrix::copyDataTo(T *values) const - Retrieves the N * M items in this matrix and writes them to \a values + Retrieves the N * M items in this matrix and copies them to \a values in row-major order. */ @@ -243,4 +243,100 @@ QT_BEGIN_NAMESPACE \sa data() */ +#ifndef QT_NO_DATASTREAM + +/*! + \fn QDataStream &operator<<(QDataStream &stream, const QGenericMatrix<N, M, T> &matrix) + \relates QGenericMatrix + + Writes the given \a matrix to the given \a stream and returns a + reference to the stream. + + \sa {Format of the QDataStream Operators} +*/ + +/*! + \fn QDataStream &operator>>(QDataStream &stream, QGenericMatrix<N, M, T> &matrix) + \relates QGenericMatrix + + Reads a NxM matrix from the given \a stream into the given \a matrix + and returns a reference to the stream. + + \sa {Format of the QDataStream Operators} +*/ + +#endif + +/*! + \typedef QMatrix2x2 + \relates QGenericMatrix + + The QMatrix2x2 type defines a convenient instantiation of the + QGenericMatrix template for 2 columns, 2 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix2x3 + \relates QGenericMatrix + + The QMatrix2x3 type defines a convenient instantiation of the + QGenericMatrix template for 2 columns, 3 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix2x4 + \relates QGenericMatrix + + The QMatrix2x4 type defines a convenient instantiation of the + QGenericMatrix template for 2 columns, 4 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix3x2 + \relates QGenericMatrix + + The QMatrix3x2 type defines a convenient instantiation of the + QGenericMatrix template for 3 columns, 2 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix3x3 + \relates QGenericMatrix + + The QMatrix3x3 type defines a convenient instantiation of the + QGenericMatrix template for 3 columns, 3 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix3x4 + \relates QGenericMatrix + + The QMatrix3x4 type defines a convenient instantiation of the + QGenericMatrix template for 3 columns, 4 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix4x2 + \relates QGenericMatrix + + The QMatrix4x2 type defines a convenient instantiation of the + QGenericMatrix template for 4 columns, 2 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix4x3 + \relates QGenericMatrix + + The QMatrix4x3 type defines a convenient instantiation of the + QGenericMatrix template for 4 columns, 3 rows, and qreal as + the element type. +*/ + QT_END_NAMESPACE diff --git a/src/gui/math3d/qgenericmatrix.h b/src/gui/math3d/qgenericmatrix.h index f178d02..3871754 100644 --- a/src/gui/math3d/qgenericmatrix.h +++ b/src/gui/math3d/qgenericmatrix.h @@ -44,6 +44,7 @@ #include <QtCore/qmetatype.h> #include <QtCore/qdebug.h> +#include <QtCore/qdatastream.h> QT_BEGIN_HEADER @@ -63,7 +64,7 @@ public: T& operator()(int row, int column); bool isIdentity() const; - void setIdentity(); + void setToIdentity(); void fill(T value); @@ -76,7 +77,7 @@ public: bool operator==(const QGenericMatrix<N, M, T>& other) const; bool operator!=(const QGenericMatrix<N, M, T>& other) const; - void toValueArray(T *values); + void copyDataTo(T *values) const; T *data() { return m[0]; } const T *data() const { return m[0]; } @@ -113,7 +114,7 @@ private: template <int N, int M, typename T> Q_INLINE_TEMPLATE QGenericMatrix<N, M, T>::QGenericMatrix() { - setIdentity(); + setToIdentity(); } template <int N, int M, typename T> @@ -164,7 +165,7 @@ Q_OUTOFLINE_TEMPLATE bool QGenericMatrix<N, M, T>::isIdentity() const } template <int N, int M, typename T> -Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T>::setIdentity() +Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T>::setToIdentity() { for (int col = 0; col < N; ++col) { for (int row = 0; row < M; ++row) { @@ -316,7 +317,7 @@ Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T> operator/(const QGenericMatrix<N, M } template <int N, int M, typename T> -Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T>::toValueArray(T *values) +Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T>::copyDataTo(T *values) const { for (int col = 0; col < N; ++col) for (int row = 0; row < M; ++row) @@ -352,6 +353,32 @@ QDebug operator<<(QDebug dbg, const QGenericMatrix<N, M, T> &m) #endif +#ifndef QT_NO_DATASTREAM + +template <int N, int M, typename T> +QDataStream &operator<<(QDataStream &stream, const QGenericMatrix<N, M, T> &matrix) +{ + for (int row = 0; row < M; ++row) + for (int col = 0; col < N; ++col) + stream << double(matrix(row, col)); + return stream; +} + +template <int N, int M, typename T> +QDataStream &operator>>(QDataStream &stream, QGenericMatrix<N, M, T> &matrix) +{ + double x; + for (int row = 0; row < M; ++row) { + for (int col = 0; col < N; ++col) { + stream >> x; + matrix(row, col) = T(x); + } + } + return stream; +} + +#endif + QT_END_NAMESPACE Q_DECLARE_METATYPE(QMatrix2x2) diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index 5d624d8..2c3d616 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -73,10 +73,10 @@ static const qreal inv_dist_to_plane = 1. / 1024.; If the matrix has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to - inferSpecialType() if they wish QMatrix4x4 to optimize further + optimize() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc. - \sa toValueArray(), inferSpecialType() + \sa copyDataTo(), optimize() */ QMatrix4x4::QMatrix4x4(const qreal *values) { @@ -96,10 +96,10 @@ QMatrix4x4::QMatrix4x4(const qreal *values) If the matrix has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to - inferSpecialType() if they wish QMatrix4x4 to optimize further + optimize() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc. - \sa inferSpecialType() + \sa optimize() */ #if !defined(QT_NO_MEMBER_TEMPLATES) || defined(Q_QDOC) @@ -176,10 +176,10 @@ QMatrix4x4::QMatrix4x4(const qreal *values, int cols, int rows) If \a matrix has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to - inferSpecialType() if they wish QMatrix4x4 to optimize further + optimize() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc. - \sa toAffine(), inferSpecialType() + \sa toAffine(), optimize() */ QMatrix4x4::QMatrix4x4(const QMatrix& matrix) { @@ -208,10 +208,10 @@ QMatrix4x4::QMatrix4x4(const QMatrix& matrix) If \a transform has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to - inferSpecialType() if they wish QMatrix4x4 to optimize further + optimize() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc. - \sa toTransform(), inferSpecialType() + \sa toTransform(), optimize() */ QMatrix4x4::QMatrix4x4(const QTransform& transform) { @@ -249,7 +249,7 @@ QMatrix4x4::QMatrix4x4(const QTransform& transform) Returns a reference to the element at position (\a row, \a column) in this matrix so that the element can be assigned to. - \sa inferSpecialType(), setColumn(), setRow() + \sa optimize(), setColumn(), setRow() */ /*! @@ -289,11 +289,11 @@ QMatrix4x4::QMatrix4x4(const QTransform& transform) Returns true if this matrix is the identity; false otherwise. - \sa setIdentity() + \sa setToIdentity() */ /*! - \fn void QMatrix4x4::setIdentity() + \fn void QMatrix4x4::setToIdentity() Sets this matrix to the identity. @@ -694,11 +694,11 @@ QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor) /*! Multiplies this matrix by another that scales coordinates by - the components of \a vector. Returns this matrix. + the components of \a vector. \sa translate(), rotate() */ -QMatrix4x4& QMatrix4x4::scale(const QVector3D& vector) +void QMatrix4x4::scale(const QVector3D& vector) { qreal vx = vector.x(); qreal vy = vector.y(); @@ -732,7 +732,6 @@ QMatrix4x4& QMatrix4x4::scale(const QVector3D& vector) m[2][3] *= vz; flagBits = General; } - return *this; } #endif @@ -740,11 +739,11 @@ QMatrix4x4& QMatrix4x4::scale(const QVector3D& vector) \overload Multiplies this matrix by another that scales coordinates by the - components \a x, and \a y. Returns this matrix. + components \a x, and \a y. \sa translate(), rotate() */ -QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y) +void QMatrix4x4::scale(qreal x, qreal y) { if (flagBits == Identity) { m[0][0] = x; @@ -768,18 +767,17 @@ QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y) m[1][3] *= y; flagBits = General; } - return *this; } /*! \overload Multiplies this matrix by another that scales coordinates by the - components \a x, \a y, and \a z. Returns this matrix. + components \a x, \a y, and \a z. \sa translate(), rotate() */ -QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y, qreal z) +void QMatrix4x4::scale(qreal x, qreal y, qreal z) { if (flagBits == Identity) { m[0][0] = x; @@ -810,18 +808,17 @@ QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y, qreal z) m[2][3] *= z; flagBits = General; } - return *this; } /*! \overload Multiplies this matrix by another that scales coordinates by the - given \a factor. Returns this matrix. + given \a factor. \sa translate(), rotate() */ -QMatrix4x4& QMatrix4x4::scale(qreal factor) +void QMatrix4x4::scale(qreal factor) { if (flagBits == Identity) { m[0][0] = factor; @@ -852,17 +849,16 @@ QMatrix4x4& QMatrix4x4::scale(qreal factor) m[2][3] *= factor; flagBits = General; } - return *this; } #ifndef QT_NO_VECTOR3D /*! Multiplies this matrix by another that translates coordinates by - the components of \a vector. Returns this matrix. + the components of \a vector. \sa scale(), rotate() */ -QMatrix4x4& QMatrix4x4::translate(const QVector3D& vector) +void QMatrix4x4::translate(const QVector3D& vector) { qreal vx = vector.x(); qreal vy = vector.y(); @@ -895,7 +891,6 @@ QMatrix4x4& QMatrix4x4::translate(const QVector3D& vector) else if (flagBits != (Rotation | Translation)) flagBits = General; } - return *this; } #endif @@ -904,11 +899,11 @@ QMatrix4x4& QMatrix4x4::translate(const QVector3D& vector) \overload Multiplies this matrix by another that translates coordinates - by the components \a x, and \a y. Returns this matrix. + by the components \a x, and \a y. \sa scale(), rotate() */ -QMatrix4x4& QMatrix4x4::translate(qreal x, qreal y) +void QMatrix4x4::translate(qreal x, qreal y) { if (flagBits == Identity) { m[3][0] = x; @@ -935,18 +930,17 @@ QMatrix4x4& QMatrix4x4::translate(qreal x, qreal y) else if (flagBits != (Rotation | Translation)) flagBits = General; } - return *this; } /*! \overload Multiplies this matrix by another that translates coordinates - by the components \a x, \a y, and \a z. Returns this matrix. + by the components \a x, \a y, and \a z. \sa scale(), rotate() */ -QMatrix4x4& QMatrix4x4::translate(qreal x, qreal y, qreal z) +void QMatrix4x4::translate(qreal x, qreal y, qreal z) { if (flagBits == Identity) { m[3][0] = x; @@ -976,20 +970,19 @@ QMatrix4x4& QMatrix4x4::translate(qreal x, qreal y, qreal z) else if (flagBits != (Rotation | Translation)) flagBits = General; } - return *this; } #ifndef QT_NO_VECTOR3D /*! Multiples this matrix by another that rotates coordinates through - \a angle degrees about \a vector. Returns this matrix. + \a angle degrees about \a vector. \sa scale(), translate() */ -QMatrix4x4& QMatrix4x4::rotate(qreal angle, const QVector3D& vector) +void QMatrix4x4::rotate(qreal angle, const QVector3D& vector) { - return rotate(angle, vector.x(), vector.y(), vector.z()); + rotate(angle, vector.x(), vector.y(), vector.z()); } #endif @@ -998,14 +991,14 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, const QVector3D& vector) \overload Multiplies this matrix by another that rotates coordinates through - \a angle degrees about the vector (\a x, \a y, \a z). Returns this matrix. + \a angle degrees about the vector (\a x, \a y, \a z). \sa scale(), translate() */ -QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) +void QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) { if (angle == 0.0f) - return *this; + return; QMatrix4x4 m(1); // The "1" says to not load the identity. qreal c, s, ic; if (angle == 90.0f || angle == -270.0f) { @@ -1027,7 +1020,7 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) if (y == 0.0f) { if (z != 0.0f) { // Rotate around the Z axis. - m.setIdentity(); + m.setToIdentity(); m.m[0][0] = c; m.m[1][1] = c; if (z < 0.0f) { @@ -1042,7 +1035,7 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) } } else if (z == 0.0f) { // Rotate around the Y axis. - m.setIdentity(); + m.setToIdentity(); m.m[0][0] = c; m.m[2][2] = c; if (y < 0.0f) { @@ -1057,7 +1050,7 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) } } else if (y == 0.0f && z == 0.0f) { // Rotate around the X axis. - m.setIdentity(); + m.setToIdentity(); m.m[1][1] = c; m.m[2][2] = c; if (x < 0.0f) { @@ -1102,18 +1095,17 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) flagBits = flags | Rotation; else flagBits = Rotation; - return *this; } /*! \internal */ -QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) +void QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) { // Used by QGraphicsRotation::applyTo() to perform a rotation // and projection back to 2D in a single step. if (angle == 0.0f) - return *this; + return; QMatrix4x4 m(1); // The "1" says to not load the identity. qreal c, s, ic; if (angle == 90.0f || angle == -270.0f) { @@ -1135,7 +1127,7 @@ QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) if (y == 0.0f) { if (z != 0.0f) { // Rotate around the Z axis. - m.setIdentity(); + m.setToIdentity(); m.m[0][0] = c; m.m[1][1] = c; if (z < 0.0f) { @@ -1150,7 +1142,7 @@ QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) } } else if (z == 0.0f) { // Rotate around the Y axis. - m.setIdentity(); + m.setToIdentity(); m.m[0][0] = c; m.m[2][2] = 1.0f; if (y < 0.0f) { @@ -1163,7 +1155,7 @@ QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) } } else if (y == 0.0f && z == 0.0f) { // Rotate around the X axis. - m.setIdentity(); + m.setToIdentity(); m.m[1][1] = c; m.m[2][2] = 1.0f; if (x < 0.0f) { @@ -1206,7 +1198,6 @@ QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) flagBits = flags | Rotation; else flagBits = Rotation; - return *this; } #ifndef QT_NO_QUATERNION @@ -1214,11 +1205,11 @@ QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) /*! Multiples this matrix by another that rotates coordinates according to a specified \a quaternion. The \a quaternion is assumed to have - been normalized. Returns this matrix. + been normalized. \sa scale(), translate(), QQuaternion */ -QMatrix4x4& QMatrix4x4::rotate(const QQuaternion& quaternion) +void QMatrix4x4::rotate(const QQuaternion& quaternion) { // Algorithm from: // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q54 @@ -1254,7 +1245,6 @@ QMatrix4x4& QMatrix4x4::rotate(const QQuaternion& quaternion) flagBits = flags | Rotation; else flagBits = Rotation; - return *this; } #endif @@ -1265,17 +1255,16 @@ QMatrix4x4& QMatrix4x4::rotate(const QQuaternion& quaternion) Multiplies this matrix by another that applies an orthographic projection for a window with boundaries specified by \a rect. The near and far clipping planes will be -1 and 1 respectively. - Returns this matrix. \sa frustum(), perspective() */ -QMatrix4x4& QMatrix4x4::ortho(const QRect& rect) +void QMatrix4x4::ortho(const QRect& rect) { // Note: rect.right() and rect.bottom() subtract 1 in QRect, // which gives the location of a pixel within the rectangle, // instead of the extent of the rectangle. We want the extent. // QRectF expresses the extent properly. - return ortho(rect.x(), rect.x() + rect.width(), rect.y() + rect.height(), rect.y(), -1.0f, 1.0f); + ortho(rect.x(), rect.x() + rect.width(), rect.y() + rect.height(), rect.y(), -1.0f, 1.0f); } /*! @@ -1284,28 +1273,27 @@ QMatrix4x4& QMatrix4x4::ortho(const QRect& rect) Multiplies this matrix by another that applies an orthographic projection for a window with boundaries specified by \a rect. The near and far clipping planes will be -1 and 1 respectively. - Returns this matrix. \sa frustum(), perspective() */ -QMatrix4x4& QMatrix4x4::ortho(const QRectF& rect) +void QMatrix4x4::ortho(const QRectF& rect) { - return ortho(rect.left(), rect.right(), rect.bottom(), rect.top(), -1.0f, 1.0f); + ortho(rect.left(), rect.right(), rect.bottom(), rect.top(), -1.0f, 1.0f); } /*! Multiplies this matrix by another that applies an orthographic projection for a window with lower-left corner (\a left, \a bottom), upper-right corner (\a right, \a top), and the specified \a nearPlane - and \a farPlane clipping planes. Returns this matrix. + and \a farPlane clipping planes. \sa frustum(), perspective() */ -QMatrix4x4& QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane) +void QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane) { // Bail out if the projection volume is zero-sized. if (left == right || bottom == top || nearPlane == farPlane) - return *this; + return; // Construct the projection. qreal width = right - left; @@ -1324,7 +1312,7 @@ QMatrix4x4& QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, (2.0f / width, 2.0f / invheight, -1.0f)); - return *this; + return; } #endif QMatrix4x4 m(1); @@ -1347,22 +1335,22 @@ QMatrix4x4& QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, // Apply the projection. *this *= m; - return *this; + return; } /*! Multiplies this matrix by another that applies a perspective frustum projection for a window with lower-left corner (\a left, \a bottom), upper-right corner (\a right, \a top), and the specified \a nearPlane - and \a farPlane clipping planes. Returns this matrix. + and \a farPlane clipping planes. \sa ortho(), perspective() */ -QMatrix4x4& QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane) +void QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane) { // Bail out if the projection volume is zero-sized. if (left == right || bottom == top || nearPlane == farPlane) - return *this; + return; // Construct the projection. QMatrix4x4 m(1); @@ -1388,7 +1376,6 @@ QMatrix4x4& QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top // Apply the projection. *this *= m; - return *this; } /*! @@ -1396,22 +1383,21 @@ QMatrix4x4& QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top projection. The field of view will be \a angle degrees within a window with a given \a aspect ratio. The projection will have the specified \a nearPlane and \a farPlane clipping planes. - Returns this matrix. \sa ortho(), frustum() */ -QMatrix4x4& QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane) +void QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane) { // Bail out if the projection volume is zero-sized. if (nearPlane == farPlane || aspect == 0.0f) - return *this; + return; // Construct the projection. QMatrix4x4 m(1); qreal radians = (angle / 2.0f) * M_PI / 180.0f; qreal sine = qSin(radians); if (sine == 0.0f) - return *this; + return; qreal cotan = qCos(radians) / sine; qreal clip = farPlane - nearPlane; m.m[0][0] = cotan / aspect; @@ -1433,7 +1419,6 @@ QMatrix4x4& QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, // Apply the projection. *this *= m; - return *this; } #ifndef QT_NO_VECTOR3D @@ -1443,9 +1428,8 @@ QMatrix4x4& QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, transformation. The \a center value indicates the center of the view that the \a eye is looking at. The \a up value indicates which direction should be considered up with respect to the \a eye. - Returns this matrix. */ -QMatrix4x4& QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up) +void QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up) { QVector3D forward = (center - eye).normalized(); QVector3D side = QVector3D::crossProduct(forward, up).normalized(); @@ -1471,7 +1455,7 @@ QMatrix4x4& QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, co m.m[3][3] = 1.0f; *this *= m; - return translate(-eye); + translate(-eye); } #endif @@ -1480,11 +1464,11 @@ QMatrix4x4& QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, co Flips between right-handed and left-handed coordinate systems by multiplying the y and z co-ordinates by -1. This is normally used to create a left-handed orthographic view without scaling - the viewport as ortho() does. Returns this matrix. + the viewport as ortho() does. \sa ortho() */ -QMatrix4x4& QMatrix4x4::flipCoordinates() +void QMatrix4x4::flipCoordinates() { if (flagBits == Scale || flagBits == (Scale | Translation)) { m[1][1] = -m[1][1]; @@ -1508,14 +1492,13 @@ QMatrix4x4& QMatrix4x4::flipCoordinates() m[2][3] = -m[2][3]; flagBits = General; } - return *this; } /*! - Retrieves the 16 items in this matrix and writes them to \a values + Retrieves the 16 items in this matrix and copies them to \a values in row-major order. */ -void QMatrix4x4::toValueArray(qreal *values) const +void QMatrix4x4::copyDataTo(qreal *values) const { for (int row = 0; row < 4; ++row) for (int col = 0; col < 4; ++col) @@ -1739,7 +1722,7 @@ QRectF QMatrix4x4::mapRect(const QRectF& rect) const Returns a pointer to the raw data of this matrix. - \sa constData(), inferSpecialType() + \sa constData(), optimize() */ /*! @@ -1788,94 +1771,8 @@ QMatrix4x4 QMatrix4x4::orthonormalInverse() const return result; } -#ifndef QT_NO_VECTOR3D -/*! - Decomposes the current rotation matrix into an \a axis of rotation plus - an \a angle. The result can be used to construct an equivalent rotation - matrix using glRotate(). It is assumed that the homogenous coordinate - is 1.0. The returned vector is guaranteed to be normalized. - - \code - qreal angle; - QVector3D axis; - - matrix.extractAxisAngle(angle, axis); - glRotate(angle, axis[0], axis[1], axis[2]); - \endcode - - \sa rotate() -*/ -void QMatrix4x4::extractAxisRotation(qreal &angle, QVector3D &axis) const -{ - // Orientation is dependent on the upper 3x3 matrix; subtract the - // homogeneous scaling element from the trace of the 4x4 matrix - qreal tr = m[0][0] + m[1][1] + m[2][2]; - qreal cosa = qreal(0.5f * (tr - 1.0f)); - angle = acos(cosa) * 180.0f / M_PI; - - // Any axis will work if r is zero (means no rotation) - if (qFuzzyIsNull(angle)) { - axis.setX(1.0f); - axis.setY(0.0f); - axis.setZ(0.0f); - return; - } - - if (angle < 180.0f) { - axis.setX(m[1][2] - m[2][1]); - axis.setY(m[2][0] - m[0][2]); - axis.setZ(m[0][1] - m[1][0]); - axis.normalize(); - return; - } - - // rads == PI - qreal tmp; - - // r00 is maximum - if ((m[0][0] >= m[2][2]) && (m[0][0] >= m[1][1])) { - axis.setX(0.5f * qSqrt(m[0][0] - m[1][1] - m[2][2] + 1.0f)); - tmp = 0.5f / axis.x(); - axis.setY(m[1][0] * tmp); - axis.setZ(m[2][0] * tmp); - } - - // r11 is maximum - if ((m[1][1] >= m[2][2]) && (m[1][1] >= m[0][0])) { - axis.setY(0.5f * qSqrt(m[1][1] - m[0][0] - m[2][2] + 1.0f)); - tmp = 0.5f / axis.y(); - axis.setX(tmp * m[1][0]); - axis.setZ(tmp * m[2][1]); - } - - // r22 is maximum - if ((m[2][2] >= m[1][1]) && (m[2][2] >= m[0][0])) { - axis.setZ(0.5f * qSqrt(m[2][2] - m[0][0] - m[1][1] + 1.0f)); - tmp = 0.5f / axis.z(); - axis.setX(m[2][0]*tmp); - axis.setY(m[2][1]*tmp); - } -} - -/*! - If this is an orthonormal transformation matrix (e.g. only rotations and - translations have been applied to the matrix, no scaling, or shearing) - then the world translational component can be obtained by calling this function. - - This is most useful for camera matrices, where the negation of this vector - is effectively the camera world coordinates. -*/ -QVector3D QMatrix4x4::extractTranslation() const -{ - return QVector3D - (m[0][0] * m[3][0] + m[0][1] * m[3][1] + m[0][2] * m[3][2], - m[1][0] * m[3][0] + m[1][1] * m[3][1] + m[1][2] * m[3][2], - m[2][0] * m[3][0] + m[2][1] * m[3][1] + m[2][2] * m[3][2]); -} -#endif - /*! - Infers the special type of this matrix from its current elements. + Optimize the usage of this matrix from its current elements. Some operations such as translate(), scale(), and rotate() can be performed more efficiently if the matrix being modified is already @@ -1888,13 +1785,13 @@ QVector3D QMatrix4x4::extractTranslation() const the special type and will revert to the safest but least efficient operations thereafter. - By calling inferSpecialType() after directly modifying the matrix, + By calling optimize() after directly modifying the matrix, the programmer can force QMatrix4x4 to recover the special type if the elements appear to conform to one of the known optimized types. \sa operator()(), data(), translate() */ -void QMatrix4x4::inferSpecialType() +void QMatrix4x4::optimize() { // If the last element is not 1, then it can never be special. if (m[3][3] != 1.0f) { @@ -2011,7 +1908,7 @@ QDataStream &operator>>(QDataStream &stream, QMatrix4x4 &matrix) matrix(row, col) = qreal(x); } } - matrix.inferSpecialType(); + matrix.optimize(); return stream; } diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index ba74b89..4193bdc 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -63,7 +63,7 @@ class QVariant; class Q_GUI_EXPORT QMatrix4x4 { public: - inline QMatrix4x4() { setIdentity(); } + inline QMatrix4x4() { setToIdentity(); } explicit QMatrix4x4(const qreal *values); inline QMatrix4x4(qreal m11, qreal m12, qreal m13, qreal m14, qreal m21, qreal m22, qreal m23, qreal m24, @@ -87,7 +87,7 @@ public: inline void setRow(int index, const QVector4D& value); inline bool isIdentity() const; - inline void setIdentity(); + inline void setToIdentity(); inline void fill(qreal value); @@ -127,36 +127,31 @@ public: friend inline bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2); #ifndef QT_NO_VECTOR3D - QMatrix4x4& scale(const QVector3D& vector); - QMatrix4x4& translate(const QVector3D& vector); - QMatrix4x4& rotate(qreal angle, const QVector3D& vector); + void scale(const QVector3D& vector); + void translate(const QVector3D& vector); + void rotate(qreal angle, const QVector3D& vector); #endif - QMatrix4x4& scale(qreal x, qreal y); - QMatrix4x4& scale(qreal x, qreal y, qreal z); - QMatrix4x4& scale(qreal factor); - QMatrix4x4& translate(qreal x, qreal y); - QMatrix4x4& translate(qreal x, qreal y, qreal z); - QMatrix4x4& rotate(qreal angle, qreal x, qreal y, qreal z = 0.0f); + void scale(qreal x, qreal y); + void scale(qreal x, qreal y, qreal z); + void scale(qreal factor); + void translate(qreal x, qreal y); + void translate(qreal x, qreal y, qreal z); + void rotate(qreal angle, qreal x, qreal y, qreal z = 0.0f); #ifndef QT_NO_QUATERNION - QMatrix4x4& rotate(const QQuaternion& quaternion); + void rotate(const QQuaternion& quaternion); #endif + void ortho(const QRect& rect); + void ortho(const QRectF& rect); + void ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane); + void frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane); + void perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane); #ifndef QT_NO_VECTOR3D - void extractAxisRotation(qreal &angle, QVector3D &axis) const; - QVector3D extractTranslation() const; + void lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up); #endif + void flipCoordinates(); - QMatrix4x4& ortho(const QRect& rect); - QMatrix4x4& ortho(const QRectF& rect); - QMatrix4x4& ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane); - QMatrix4x4& frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane); - QMatrix4x4& perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane); -#ifndef QT_NO_VECTOR3D - QMatrix4x4& lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up); -#endif - QMatrix4x4& flipCoordinates(); - - void toValueArray(qreal *values) const; + void copyDataTo(qreal *values) const; QMatrix toAffine() const; QTransform toTransform() const; @@ -183,7 +178,7 @@ public: inline const qreal *data() const { return m[0]; } inline const qreal *constData() const { return m[0]; } - void inferSpecialType(); + void optimize(); operator QVariant() const; @@ -208,7 +203,7 @@ private: QMatrix4x4 orthonormalInverse() const; - QMatrix4x4& projectedRotate(qreal angle, qreal x, qreal y, qreal z); + void projectedRotate(qreal angle, qreal x, qreal y, qreal z); friend class QGraphicsRotation; }; @@ -330,7 +325,7 @@ inline bool QMatrix4x4::isIdentity() const return (m[3][3] == 1.0f); } -inline void QMatrix4x4::setIdentity() +inline void QMatrix4x4::setToIdentity() { m[0][0] = 1.0f; m[0][1] = 0.0f; diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp index d5ec054..626cb3c 100644 --- a/src/gui/math3d/qquaternion.cpp +++ b/src/gui/math3d/qquaternion.cpp @@ -288,7 +288,7 @@ void QQuaternion::normalize() in 3D space. The following code: \code - QVector3D result = q.rotateVector(vector); + QVector3D result = q.rotatedVector(vector); \endcode is equivalent to the following: @@ -297,7 +297,7 @@ void QQuaternion::normalize() QVector3D result = (q * QQuaternion(0, vector) * q.conjugate()).vector(); \endcode */ -QVector3D QQuaternion::rotateVector(const QVector3D& vector) const +QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const { return (*this * QQuaternion(0, vector) * conjugate()).vector(); } diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h index 7480a5c..5b2454f 100644 --- a/src/gui/math3d/qquaternion.h +++ b/src/gui/math3d/qquaternion.h @@ -95,7 +95,7 @@ public: QQuaternion conjugate() const; - QVector3D rotateVector(const QVector3D& vector) const; + QVector3D rotatedVector(const QVector3D& vector) const; QQuaternion &operator+=(const QQuaternion &quaternion); QQuaternion &operator-=(const QQuaternion &quaternion); diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index 53edbb0..41602a1 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -7424,6 +7424,14 @@ QT_RECTFILL(qrgb444) QT_RECTFILL(qargb4444) #undef QT_RECTFILL +inline static void qt_rectfill_nonpremul_quint32(QRasterBuffer *rasterBuffer, + int x, int y, int width, int height, + quint32 color) +{ + qt_rectfill<quint32>(reinterpret_cast<quint32 *>(rasterBuffer->buffer()), + INV_PREMUL(color), x, y, width, height, rasterBuffer->bytesPerLine()); +} + // Map table for destination image format. Contains function pointers // for blends of various types unto the destination @@ -7466,7 +7474,7 @@ DrawHelper qDrawHelper[QImage::NImageFormats] = qt_bitmapblit_quint32, qt_alphamapblit_quint32, qt_alphargbblit_quint32, - qt_rectfill_quint32 + qt_rectfill_nonpremul_quint32 }, // Format_ARGB32_Premultiplied { diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index cddad7d..09a4563 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -2275,8 +2275,9 @@ void QPainter::setBrushOrigin(const QPointF &p) /*! Sets the composition mode to the given \a mode. - \warning You can only set the composition mode for QPainter - objects that operates on a QImage. + \warning Only a QPainter operating on a QImage fully supports all + composition modes. The RasterOp modes are supported for X11 as + described in compositionMode(). \sa compositionMode() */ @@ -5163,7 +5164,7 @@ void QPainter::drawPixmap(const QPointF &p, const QPixmap &pm) Q_D(QPainter); - if (!d->engine) + if (!d->engine || pm.isNull()) return; #ifndef QT_NO_DEBUG @@ -7603,7 +7604,7 @@ start_lengthVariant: l.setPosition(QPointF(0., height)); height += l.height(); width = qMax(width, l.naturalTextWidth()); - if (!brect && height >= r.height()) + if (!dontclip && !brect && height >= r.height()) break; } textLayout.endLayout(); diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index c40bcee..8133793 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -3037,11 +3037,11 @@ void QPainterPath::addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadi bool first = d_func()->elements.size() < 2; - arcMoveTo(x, y, rxx2, ryy2, 90); - arcTo(x, y, rxx2, ryy2, 90, 90); - arcTo(x, y+h-ryy2, rxx2, ryy2, 2*90, 90); - arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*90, 90); - arcTo(x+w-rxx2, y, rxx2, ryy2, 0, 90); + arcMoveTo(x, y, rxx2, ryy2, 180); + arcTo(x, y, rxx2, ryy2, 180, -90); + arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90); + arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90); + arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90); closeSubpath(); d_func()->require_moveTo = true; @@ -3094,11 +3094,11 @@ void QPainterPath::addRoundRect(const QRectF &r, int xRnd, int yRnd) bool first = d_func()->elements.size() < 2; - arcMoveTo(x, y, rxx2, ryy2, 90); - arcTo(x, y, rxx2, ryy2, 90, 90); - arcTo(x, y+h-ryy2, rxx2, ryy2, 2*90, 90); - arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*90, 90); - arcTo(x+w-rxx2, y, rxx2, ryy2, 0, 90); + arcMoveTo(x, y, rxx2, ryy2, 180); + arcTo(x, y, rxx2, ryy2, 180, -90); + arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90); + arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90); + arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90); closeSubpath(); d_func()->require_moveTo = true; diff --git a/src/gui/painting/qpainterpath_p.h b/src/gui/painting/qpainterpath_p.h index 112c2bd..54b9392 100644 --- a/src/gui/painting/qpainterpath_p.h +++ b/src/gui/painting/qpainterpath_p.h @@ -132,10 +132,9 @@ public: QPainterPathData() : cStart(0), fillRule(Qt::OddEvenFill), - pathConverter(0), dirtyBounds(false), - dirtyControlBounds(false) - + dirtyControlBounds(false), + pathConverter(0) { ref = 1; require_moveTo = false; @@ -146,10 +145,10 @@ public: QPainterPathPrivate(), cStart(other.cStart), fillRule(other.fillRule), bounds(other.bounds), controlBounds(other.controlBounds), - pathConverter(0), dirtyBounds(other.dirtyBounds), dirtyControlBounds(other.dirtyControlBounds), - convex(other.convex) + convex(other.convex), + pathConverter(0) { ref = 1; require_moveTo = false; diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp index c57b3c1..228a6b1 100644 --- a/src/gui/painting/qstroker.cpp +++ b/src/gui/painting/qstroker.cpp @@ -452,6 +452,17 @@ void QStroker::joinPoints(qfixed focal_x, qfixed focal_y, const QLineF &nextLine #endif if (join == FlatJoin) { + QLineF prevLine(qt_fixed_to_real(m_back2X), qt_fixed_to_real(m_back2Y), + qt_fixed_to_real(m_back1X), qt_fixed_to_real(m_back1Y)); + QPointF isect; + QLineF::IntersectType type = prevLine.intersect(nextLine, &isect); + QLineF shortCut(prevLine.p2(), nextLine.p1()); + qreal angle = shortCut.angleTo(prevLine); + if (type == QLineF::BoundedIntersection || (angle > 90 && !qFuzzyCompare(angle, (qreal)90))) { + emitLineTo(focal_x, focal_y); + emitLineTo(qt_real_to_fixed(nextLine.x1()), qt_real_to_fixed(nextLine.y1())); + return; + } emitLineTo(qt_real_to_fixed(nextLine.x1()), qt_real_to_fixed(nextLine.y1())); @@ -468,8 +479,8 @@ void QStroker::joinPoints(qfixed focal_x, qfixed focal_y, const QLineF &nextLine // If we are on the inside, do the short cut... QLineF shortCut(prevLine.p2(), nextLine.p1()); qreal angle = shortCut.angleTo(prevLine); - if (type == QLineF::BoundedIntersection || (angle > 90 && !qFuzzyCompare(angle, (qreal)90))) { + emitLineTo(focal_x, focal_y); emitLineTo(qt_real_to_fixed(nextLine.x1()), qt_real_to_fixed(nextLine.y1())); return; } @@ -509,8 +520,9 @@ void QStroker::joinPoints(qfixed focal_x, qfixed focal_y, const QLineF &nextLine qfixed offset = m_strokeWidth / 2; QLineF shortCut(prevLine.p2(), nextLine.p1()); - qreal angle = prevLine.angle(shortCut); + qreal angle = shortCut.angleTo(prevLine); if (type == QLineF::BoundedIntersection || (angle > 90 && !qFuzzyCompare(angle, (qreal)90))) { + emitLineTo(focal_x, focal_y); emitLineTo(qt_real_to_fixed(nextLine.x1()), qt_real_to_fixed(nextLine.y1())); return; } @@ -581,6 +593,13 @@ void QStroker::joinPoints(qfixed focal_x, qfixed focal_y, const QLineF &nextLine qt_real_to_fixed(l1.x1()), qt_real_to_fixed(l1.y1())); } else if (join == SvgMiterJoin) { + QLineF shortCut(prevLine.p2(), nextLine.p1()); + qreal angle = shortCut.angleTo(prevLine); + if (type == QLineF::BoundedIntersection || (angle > 90 && !qFuzzyCompare(angle, (qreal)90))) { + emitLineTo(focal_x, focal_y); + emitLineTo(qt_real_to_fixed(nextLine.x1()), qt_real_to_fixed(nextLine.y1())); + return; + } QLineF miterLine(QPointF(qt_fixed_to_real(focal_x), qt_fixed_to_real(focal_y)), isect); if (miterLine.length() > qt_fixed_to_real(m_strokeWidth * m_miterLimit) / 2) { diff --git a/src/gui/painting/qwindowsurface_x11.cpp b/src/gui/painting/qwindowsurface_x11.cpp index 46c4c42..77e019c 100644 --- a/src/gui/painting/qwindowsurface_x11.cpp +++ b/src/gui/painting/qwindowsurface_x11.cpp @@ -94,6 +94,8 @@ QPaintDevice *QX11WindowSurface::paintDevice() void QX11WindowSurface::beginPaint(const QRegion &rgn) { #ifndef QT_NO_XRENDER + Q_ASSERT(!d_ptr->device.isNull()); + if (d_ptr->translucentBackground) { if (d_ptr->device.depth() != 32) static_cast<QX11PixmapData *>(d_ptr->device.data_ptr().data())->convertToARGB32(); @@ -157,8 +159,8 @@ void QX11WindowSurface::setGeometry(const QRect &rect) QPixmap::x11SetDefaultScreen(d_ptr->widget->x11Info().screen()); QX11PixmapData *oldData = static_cast<QX11PixmapData *>(d_ptr->device.pixmapData()); - Q_ASSERT(oldData); - if (!(oldData->flags & QX11PixmapData::Uninitialized) && hasStaticContents()) { + + if (oldData && !(oldData->flags & QX11PixmapData::Uninitialized) && hasStaticContents()) { // Copy the content of the old pixmap into the new one. QX11PixmapData *newData = new QX11PixmapData(QPixmapData::PixmapType); newData->resize(size.width(), size.height()); diff --git a/src/gui/s60framework/qs60mainappui.cpp b/src/gui/s60framework/qs60mainappui.cpp index 4ad78f9..4c4c994 100644 --- a/src/gui/s60framework/qs60mainappui.cpp +++ b/src/gui/s60framework/qs60mainappui.cpp @@ -163,7 +163,7 @@ void QS60MainAppUi::HandleResourceChangeL(TInt type) /*! * \brief Handles raw window server events. * - * The event type and information is passed in \a event, while the receiving control is passed in + * The event type and information is passed in \a wsEvent, while the receiving control is passed in * \a destination. * * If you override this function, you should call the base class implementation if you do not diff --git a/src/gui/statemachine/qbasickeyeventtransition.cpp b/src/gui/statemachine/qbasickeyeventtransition.cpp index 445a253..bf10e3d 100644 --- a/src/gui/statemachine/qbasickeyeventtransition.cpp +++ b/src/gui/statemachine/qbasickeyeventtransition.cpp @@ -68,14 +68,14 @@ public: QEvent::Type eventType; int key; - Qt::KeyboardModifiers modifiersMask; + Qt::KeyboardModifiers modifierMask; }; QBasicKeyEventTransitionPrivate::QBasicKeyEventTransitionPrivate() { eventType = QEvent::None; key = 0; - modifiersMask = Qt::NoModifier; + modifierMask = Qt::NoModifier; } QBasicKeyEventTransitionPrivate *QBasicKeyEventTransitionPrivate::get(QBasicKeyEventTransition *q) @@ -106,17 +106,17 @@ QBasicKeyEventTransition::QBasicKeyEventTransition(QEvent::Type type, int key, /*! Constructs a new event transition for events of the given \a type for the - given \a key, with the given \a modifiersMask and \a sourceState. + given \a key, with the given \a modifierMask and \a sourceState. */ QBasicKeyEventTransition::QBasicKeyEventTransition(QEvent::Type type, int key, - Qt::KeyboardModifiers modifiersMask, + Qt::KeyboardModifiers modifierMask, QState *sourceState) : QAbstractTransition(*new QBasicKeyEventTransitionPrivate, sourceState) { Q_D(QBasicKeyEventTransition); d->eventType = type; d->key = key; - d->modifiersMask = modifiersMask; + d->modifierMask = modifierMask; } /*! @@ -163,23 +163,23 @@ void QBasicKeyEventTransition::setKey(int key) } /*! - Returns the keyboard modifiers mask that this key event transition checks + Returns the keyboard modifier mask that this key event transition checks for. */ -Qt::KeyboardModifiers QBasicKeyEventTransition::modifiersMask() const +Qt::KeyboardModifiers QBasicKeyEventTransition::modifierMask() const { Q_D(const QBasicKeyEventTransition); - return d->modifiersMask; + return d->modifierMask; } /*! - Sets the keyboard modifiers mask that this key event transition will check + Sets the keyboard modifier mask that this key event transition will check for. */ -void QBasicKeyEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) +void QBasicKeyEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask) { Q_D(QBasicKeyEventTransition); - d->modifiersMask = modifiersMask; + d->modifierMask = modifierMask; } /*! @@ -191,7 +191,7 @@ bool QBasicKeyEventTransition::eventTest(QEvent *event) if (event->type() == d->eventType) { QKeyEvent *ke = static_cast<QKeyEvent*>(event); return (ke->key() == d->key) - && ((ke->modifiers() & d->modifiersMask) == d->modifiersMask); + && ((ke->modifiers() & d->modifierMask) == d->modifierMask); } return false; } diff --git a/src/gui/statemachine/qbasickeyeventtransition_p.h b/src/gui/statemachine/qbasickeyeventtransition_p.h index 3c2ec7d..87d3dc7 100644 --- a/src/gui/statemachine/qbasickeyeventtransition_p.h +++ b/src/gui/statemachine/qbasickeyeventtransition_p.h @@ -69,7 +69,7 @@ public: QBasicKeyEventTransition(QState *sourceState = 0); QBasicKeyEventTransition(QEvent::Type type, int key, QState *sourceState = 0); QBasicKeyEventTransition(QEvent::Type type, int key, - Qt::KeyboardModifiers modifiersMask, + Qt::KeyboardModifiers modifierMask, QState *sourceState = 0); ~QBasicKeyEventTransition(); @@ -79,8 +79,8 @@ public: int key() const; void setKey(int key); - Qt::KeyboardModifiers modifiersMask() const; - void setModifiersMask(Qt::KeyboardModifiers modifiers); + Qt::KeyboardModifiers modifierMask() const; + void setModifierMask(Qt::KeyboardModifiers modifiers); protected: bool eventTest(QEvent *event); diff --git a/src/gui/statemachine/qbasicmouseeventtransition.cpp b/src/gui/statemachine/qbasicmouseeventtransition.cpp index 694c319..fe0dea9 100644 --- a/src/gui/statemachine/qbasicmouseeventtransition.cpp +++ b/src/gui/statemachine/qbasicmouseeventtransition.cpp @@ -69,7 +69,7 @@ public: QEvent::Type eventType; Qt::MouseButton button; - Qt::KeyboardModifiers modifiersMask; + Qt::KeyboardModifiers modifierMask; QPainterPath path; }; @@ -149,38 +149,38 @@ void QBasicMouseEventTransition::setButton(Qt::MouseButton button) } /*! - Returns the keyboard modifiers mask that this mouse event transition checks + Returns the keyboard modifier mask that this mouse event transition checks for. */ -Qt::KeyboardModifiers QBasicMouseEventTransition::modifiersMask() const +Qt::KeyboardModifiers QBasicMouseEventTransition::modifierMask() const { Q_D(const QBasicMouseEventTransition); - return d->modifiersMask; + return d->modifierMask; } /*! - Sets the keyboard modifiers mask that this mouse event transition will check + Sets the keyboard modifier mask that this mouse event transition will check for. */ -void QBasicMouseEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) +void QBasicMouseEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask) { Q_D(QBasicMouseEventTransition); - d->modifiersMask = modifiersMask; + d->modifierMask = modifierMask; } /*! - Returns the path for this mouse event transition. + Returns the hit test path for this mouse event transition. */ -QPainterPath QBasicMouseEventTransition::path() const +QPainterPath QBasicMouseEventTransition::hitTestPath() const { Q_D(const QBasicMouseEventTransition); return d->path; } /*! - Sets the path for this mouse event transition. + Sets the hit test path for this mouse event transition. */ -void QBasicMouseEventTransition::setPath(const QPainterPath &path) +void QBasicMouseEventTransition::setHitTestPath(const QPainterPath &path) { Q_D(QBasicMouseEventTransition); d->path = path; @@ -195,7 +195,7 @@ bool QBasicMouseEventTransition::eventTest(QEvent *event) if (event->type() == d->eventType) { QMouseEvent *me = static_cast<QMouseEvent*>(event); return (me->button() == d->button) - && ((me->modifiers() & d->modifiersMask) == d->modifiersMask) + && ((me->modifiers() & d->modifierMask) == d->modifierMask) && (d->path.isEmpty() || d->path.contains(me->pos())); } return false; diff --git a/src/gui/statemachine/qbasicmouseeventtransition_p.h b/src/gui/statemachine/qbasicmouseeventtransition_p.h index 512e0f8..6754c55 100644 --- a/src/gui/statemachine/qbasicmouseeventtransition_p.h +++ b/src/gui/statemachine/qbasicmouseeventtransition_p.h @@ -79,11 +79,11 @@ public: Qt::MouseButton button() const; void setButton(Qt::MouseButton button); - Qt::KeyboardModifiers modifiersMask() const; - void setModifiersMask(Qt::KeyboardModifiers modifiers); + Qt::KeyboardModifiers modifierMask() const; + void setModifierMask(Qt::KeyboardModifiers modifiers); - QPainterPath path() const; - void setPath(const QPainterPath &path); + QPainterPath hitTestPath() const; + void setHitTestPath(const QPainterPath &path); protected: bool eventTest(QEvent *event); diff --git a/src/gui/statemachine/qkeyeventtransition.cpp b/src/gui/statemachine/qkeyeventtransition.cpp index dee3168..a15e671 100644 --- a/src/gui/statemachine/qkeyeventtransition.cpp +++ b/src/gui/statemachine/qkeyeventtransition.cpp @@ -69,9 +69,9 @@ QT_BEGIN_NAMESPACE */ /*! - \property QKeyEventTransition::modifiersMask + \property QKeyEventTransition::modifierMask - \brief the keyboard modifiers mask that this key event transition checks for + \brief the keyboard modifier mask that this key event transition checks for */ class QKeyEventTransitionPrivate : public QEventTransitionPrivate @@ -133,23 +133,23 @@ void QKeyEventTransition::setKey(int key) } /*! - Returns the keyboard modifiers mask that this key event transition checks + Returns the keyboard modifier mask that this key event transition checks for. */ -Qt::KeyboardModifiers QKeyEventTransition::modifiersMask() const +Qt::KeyboardModifiers QKeyEventTransition::modifierMask() const { Q_D(const QKeyEventTransition); - return d->transition->modifiersMask(); + return d->transition->modifierMask(); } /*! - Sets the keyboard \a modifiers mask that this key event transition will - check for. + Sets the keyboard modifier mask that this key event transition will + check for to \a modifierMask. */ -void QKeyEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) +void QKeyEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask) { Q_D(QKeyEventTransition); - d->transition->setModifiersMask(modifiersMask); + d->transition->setModifierMask(modifierMask); } /*! diff --git a/src/gui/statemachine/qkeyeventtransition.h b/src/gui/statemachine/qkeyeventtransition.h index 8df8138..ab1c155 100644 --- a/src/gui/statemachine/qkeyeventtransition.h +++ b/src/gui/statemachine/qkeyeventtransition.h @@ -57,7 +57,7 @@ class Q_GUI_EXPORT QKeyEventTransition : public QEventTransition { Q_OBJECT Q_PROPERTY(int key READ key WRITE setKey) - Q_PROPERTY(Qt::KeyboardModifiers modifiersMask READ modifiersMask WRITE setModifiersMask) + Q_PROPERTY(Qt::KeyboardModifiers modifierMask READ modifierMask WRITE setModifierMask) public: QKeyEventTransition(QState *sourceState = 0); QKeyEventTransition(QObject *object, QEvent::Type type, int key, @@ -67,8 +67,8 @@ public: int key() const; void setKey(int key); - Qt::KeyboardModifiers modifiersMask() const; - void setModifiersMask(Qt::KeyboardModifiers modifiers); + Qt::KeyboardModifiers modifierMask() const; + void setModifierMask(Qt::KeyboardModifiers modifiers); protected: void onTransition(QEvent *event); diff --git a/src/gui/statemachine/qmouseeventtransition.cpp b/src/gui/statemachine/qmouseeventtransition.cpp index 86cacf7..f5c0cb1 100644 --- a/src/gui/statemachine/qmouseeventtransition.cpp +++ b/src/gui/statemachine/qmouseeventtransition.cpp @@ -70,9 +70,9 @@ QT_BEGIN_NAMESPACE */ /*! - \property QMouseEventTransition::modifiersMask + \property QMouseEventTransition::modifierMask - \brief the keyboard modifiers mask that this mouse event transition checks for + \brief the keyboard modifier mask that this mouse event transition checks for */ class QMouseEventTransitionPrivate : public QEventTransitionPrivate @@ -139,45 +139,45 @@ void QMouseEventTransition::setButton(Qt::MouseButton button) } /*! - Returns the keyboard modifiers mask that this mouse event transition checks + Returns the keyboard modifier mask that this mouse event transition checks for. */ -Qt::KeyboardModifiers QMouseEventTransition::modifiersMask() const +Qt::KeyboardModifiers QMouseEventTransition::modifierMask() const { Q_D(const QMouseEventTransition); - return d->transition->modifiersMask(); + return d->transition->modifierMask(); } /*! - Sets the keyboard \a modifiers mask that this mouse event transition will - check for. + Sets the keyboard modifier mask that this mouse event transition will + check for to \a modifierMask. */ -void QMouseEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) +void QMouseEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask) { Q_D(QMouseEventTransition); - d->transition->setModifiersMask(modifiersMask); + d->transition->setModifierMask(modifierMask); } /*! - Returns the path for this mouse event transition. + Returns the hit test path for this mouse event transition. */ -QPainterPath QMouseEventTransition::path() const +QPainterPath QMouseEventTransition::hitTestPath() const { Q_D(const QMouseEventTransition); - return d->transition->path(); + return d->transition->hitTestPath(); } /*! - Sets the \a path for this mouse event transition. + Sets the hit test path for this mouse event transition to \a path. If a valid path has been set, the transition will only trigger if the mouse event position (QMouseEvent::pos()) is inside the path. \sa QPainterPath::contains() */ -void QMouseEventTransition::setPath(const QPainterPath &path) +void QMouseEventTransition::setHitTestPath(const QPainterPath &path) { Q_D(QMouseEventTransition); - d->transition->setPath(path); + d->transition->setHitTestPath(path); } /*! diff --git a/src/gui/statemachine/qmouseeventtransition.h b/src/gui/statemachine/qmouseeventtransition.h index 4e324ec..e7f6a45 100644 --- a/src/gui/statemachine/qmouseeventtransition.h +++ b/src/gui/statemachine/qmouseeventtransition.h @@ -58,7 +58,7 @@ class Q_GUI_EXPORT QMouseEventTransition : public QEventTransition { Q_OBJECT Q_PROPERTY(Qt::MouseButton button READ button WRITE setButton) - Q_PROPERTY(Qt::KeyboardModifiers modifiersMask READ modifiersMask WRITE setModifiersMask) + Q_PROPERTY(Qt::KeyboardModifiers modifierMask READ modifierMask WRITE setModifierMask) public: QMouseEventTransition(QState *sourceState = 0); QMouseEventTransition(QObject *object, QEvent::Type type, @@ -68,11 +68,11 @@ public: Qt::MouseButton button() const; void setButton(Qt::MouseButton button); - Qt::KeyboardModifiers modifiersMask() const; - void setModifiersMask(Qt::KeyboardModifiers modifiers); + Qt::KeyboardModifiers modifierMask() const; + void setModifierMask(Qt::KeyboardModifiers modifiers); - QPainterPath path() const; - void setPath(const QPainterPath &path); + QPainterPath hitTestPath() const; + void setHitTestPath(const QPainterPath &path); protected: void onTransition(QEvent *event); diff --git a/src/gui/styles/gtksymbols.cpp b/src/gui/styles/gtksymbols.cpp deleted file mode 100644 index 32fde62..0000000 --- a/src/gui/styles/gtksymbols.cpp +++ /dev/null @@ -1,1008 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "gtksymbols_p.h" - -// This file is responsible for resolving all GTK functions we use -// dynamically. This is done to avoid link-time dependancy on GTK -// as well as crashes occurring due to usage of the GTK_QT engines -// -// Additionally we create a map of common GTK widgets that we can pass -// to the GTK theme engine as many engines resort to querying the -// actual widget pointers for details that are not covered by the -// state flags - -#include <QtCore/qglobal.h> -#if !defined(QT_NO_STYLE_GTK) - -#include <QtCore/QEvent> -#include <QtCore/QFile> -#include <QtCore/QStringList> -#include <QtCore/QTextStream> -#include <QtCore/QHash> -#include <QtCore/QUrl> - -#include <private/qapplication_p.h> -#include <private/qiconloader_p.h> - -#include <QtGui/QMenu> -#include <QtGui/QStyle> -#include <QtGui/QApplication> -#include <QtGui/QPixmapCache> -#include <QtGui/QStatusBar> -#include <QtGui/QMenuBar> -#include <QtGui/QToolBar> -#include <QtGui/QToolButton> -#include <QtGui/QX11Info> - -#include <X11/Xlib.h> - -QT_BEGIN_NAMESPACE - -static bool displayDepth = -1; -Q_GLOBAL_STATIC(QGtkStyleUpdateScheduler, styleScheduler) - -typedef QHash<QString, GtkWidget*> WidgetMap; -Q_GLOBAL_STATIC(WidgetMap, gtkWidgetMap) - -Ptr_gtk_container_forall QGtk::gtk_container_forall = 0; -Ptr_gtk_init QGtk::gtk_init = 0; -Ptr_gtk_style_attach QGtk::gtk_style_attach = 0; -Ptr_gtk_window_new QGtk::gtk_window_new = 0; -Ptr_gtk_widget_destroy QGtk::gtk_widget_destroy = 0; -Ptr_gtk_widget_realize QGtk::gtk_widget_realize = 0; -Ptr_gtk_widget_set_default_direction QGtk::gtk_widget_set_default_direction = 0; -Ptr_gtk_widget_modify_color QGtk::gtk_widget_modify_fg = 0; -Ptr_gtk_widget_modify_color QGtk::gtk_widget_modify_bg = 0; -Ptr_gtk_arrow_new QGtk::gtk_arrow_new = 0; -Ptr_gtk_menu_item_new QGtk::gtk_menu_item_new = 0; -Ptr_gtk_check_menu_item_new QGtk::gtk_check_menu_item_new = 0; -Ptr_gtk_menu_bar_new QGtk::gtk_menu_bar_new = 0; -Ptr_gtk_menu_new QGtk::gtk_menu_new = 0; -Ptr_gtk_button_new QGtk::gtk_button_new = 0; -Ptr_gtk_tool_button_new QGtk::gtk_tool_button_new = 0; -Ptr_gtk_hbutton_box_new QGtk::gtk_hbutton_box_new = 0; -Ptr_gtk_check_button_new QGtk::gtk_check_button_new = 0; -Ptr_gtk_radio_button_new QGtk::gtk_radio_button_new = 0; -Ptr_gtk_spin_button_new QGtk::gtk_spin_button_new = 0; -Ptr_gtk_frame_new QGtk::gtk_frame_new = 0; -Ptr_gtk_expander_new QGtk::gtk_expander_new = 0; -Ptr_gtk_statusbar_new QGtk::gtk_statusbar_new = 0; -Ptr_gtk_entry_new QGtk::gtk_entry_new = 0; -Ptr_gtk_hscale_new QGtk::gtk_hscale_new = 0; -Ptr_gtk_vscale_new QGtk::gtk_vscale_new = 0; -Ptr_gtk_hscrollbar_new QGtk::gtk_hscrollbar_new = 0; -Ptr_gtk_vscrollbar_new QGtk::gtk_vscrollbar_new = 0; -Ptr_gtk_scrolled_window_new QGtk::gtk_scrolled_window_new = 0; -Ptr_gtk_notebook_new QGtk::gtk_notebook_new = 0; -Ptr_gtk_toolbar_new QGtk::gtk_toolbar_new = 0; -Ptr_gtk_toolbar_insert QGtk::gtk_toolbar_insert = 0; -Ptr_gtk_separator_tool_item_new QGtk::gtk_separator_tool_item_new = 0; -Ptr_gtk_tree_view_new QGtk::gtk_tree_view_new = 0; -Ptr_gtk_combo_box_new QGtk::gtk_combo_box_new = 0; -Ptr_gtk_combo_box_entry_new QGtk::gtk_combo_box_entry_new = 0; -Ptr_gtk_progress_bar_new QGtk::gtk_progress_bar_new = 0; -Ptr_gtk_container_add QGtk::gtk_container_add = 0; -Ptr_gtk_menu_shell_append QGtk::gtk_menu_shell_append = 0; -Ptr_gtk_progress_set_adjustment QGtk::gtk_progress_set_adjustment = 0; -Ptr_gtk_range_set_adjustment QGtk::gtk_range_set_adjustment = 0; -Ptr_gtk_range_set_inverted QGtk::gtk_range_set_inverted = 0; -Ptr_gtk_icon_factory_lookup_default QGtk::gtk_icon_factory_lookup_default = 0; -Ptr_gtk_icon_theme_get_default QGtk::gtk_icon_theme_get_default = 0; -Ptr_gtk_widget_style_get QGtk::gtk_widget_style_get = 0; -Ptr_gtk_icon_set_render_icon QGtk::gtk_icon_set_render_icon = 0; -Ptr_gtk_fixed_new QGtk::gtk_fixed_new = 0; -Ptr_gtk_tree_view_column_new QGtk::gtk_tree_view_column_new = 0; -Ptr_gtk_tree_view_get_column QGtk::gtk_tree_view_get_column = 0; -Ptr_gtk_tree_view_append_column QGtk::gtk_tree_view_append_column = 0; -Ptr_gtk_paint_check QGtk::gtk_paint_check = 0; -Ptr_gtk_paint_box QGtk::gtk_paint_box = 0; -Ptr_gtk_paint_box_gap QGtk::gtk_paint_box_gap = 0; -Ptr_gtk_paint_flat_box QGtk::gtk_paint_flat_box = 0; -Ptr_gtk_paint_option QGtk::gtk_paint_option = 0; -Ptr_gtk_paint_extension QGtk::gtk_paint_extension = 0; -Ptr_gtk_paint_slider QGtk::gtk_paint_slider = 0; -Ptr_gtk_paint_shadow QGtk::gtk_paint_shadow = 0; -Ptr_gtk_paint_resize_grip QGtk::gtk_paint_resize_grip = 0; -Ptr_gtk_paint_focus QGtk::gtk_paint_focus = 0; -Ptr_gtk_paint_arrow QGtk::gtk_paint_arrow = 0; -Ptr_gtk_paint_handle QGtk::gtk_paint_handle = 0; -Ptr_gtk_paint_expander QGtk::gtk_paint_expander = 0; -Ptr_gtk_adjustment_new QGtk::gtk_adjustment_new = 0; -Ptr_gtk_paint_hline QGtk::gtk_paint_hline = 0; -Ptr_gtk_paint_vline QGtk::gtk_paint_vline = 0; -Ptr_gtk_menu_item_set_submenu QGtk::gtk_menu_item_set_submenu = 0; -Ptr_gtk_settings_get_default QGtk::gtk_settings_get_default = 0; -Ptr_gtk_separator_menu_item_new QGtk::gtk_separator_menu_item_new = 0; -Ptr_gtk_widget_size_allocate QGtk::gtk_widget_size_allocate = 0; -Ptr_gtk_widget_set_direction QGtk::gtk_widget_set_direction = 0; -Ptr_gtk_widget_path QGtk::gtk_widget_path = 0; -Ptr_gtk_container_get_type QGtk::gtk_container_get_type = 0; -Ptr_gtk_window_get_type QGtk::gtk_window_get_type = 0; -Ptr_gtk_widget_get_type QGtk::gtk_widget_get_type = 0; -Ptr_gtk_rc_get_style_by_paths QGtk::gtk_rc_get_style_by_paths = 0; -Ptr_gtk_check_version QGtk::gtk_check_version = 0; - -Ptr_pango_font_description_get_size QGtk::pango_font_description_get_size = 0; -Ptr_pango_font_description_get_weight QGtk::pango_font_description_get_weight = 0; -Ptr_pango_font_description_get_family QGtk::pango_font_description_get_family = 0; -Ptr_pango_font_description_get_style QGtk::pango_font_description_get_style = 0; - -Ptr_gtk_file_filter_new QGtk::gtk_file_filter_new = 0; -Ptr_gtk_file_filter_set_name QGtk::gtk_file_filter_set_name = 0; -Ptr_gtk_file_filter_add_pattern QGtk::gtk_file_filter_add_pattern = 0; -Ptr_gtk_file_chooser_add_filter QGtk::gtk_file_chooser_add_filter = 0; -Ptr_gtk_file_chooser_set_filter QGtk::gtk_file_chooser_set_filter = 0; -Ptr_gtk_file_chooser_get_filter QGtk::gtk_file_chooser_get_filter = 0; -Ptr_gtk_file_chooser_dialog_new QGtk::gtk_file_chooser_dialog_new = 0; -Ptr_gtk_file_chooser_set_current_folder QGtk::gtk_file_chooser_set_current_folder = 0; -Ptr_gtk_file_chooser_get_filename QGtk::gtk_file_chooser_get_filename = 0; -Ptr_gtk_file_chooser_get_filenames QGtk::gtk_file_chooser_get_filenames = 0; -Ptr_gtk_file_chooser_set_current_name QGtk::gtk_file_chooser_set_current_name = 0; -Ptr_gtk_dialog_run QGtk::gtk_dialog_run = 0; -Ptr_gtk_file_chooser_set_filename QGtk::gtk_file_chooser_set_filename = 0; - -Ptr_gdk_pixbuf_get_pixels QGtk::gdk_pixbuf_get_pixels = 0; -Ptr_gdk_pixbuf_get_width QGtk::gdk_pixbuf_get_width = 0; -Ptr_gdk_pixbuf_get_height QGtk::gdk_pixbuf_get_height = 0; -Ptr_gdk_pixmap_new QGtk::gdk_pixmap_new = 0; -Ptr_gdk_pixbuf_new QGtk::gdk_pixbuf_new = 0; -Ptr_gdk_pixbuf_get_from_drawable QGtk::gdk_pixbuf_get_from_drawable = 0; -Ptr_gdk_draw_rectangle QGtk::gdk_draw_rectangle = 0; -Ptr_gdk_pixbuf_unref QGtk::gdk_pixbuf_unref = 0; -Ptr_gdk_drawable_unref QGtk::gdk_drawable_unref = 0; -Ptr_gdk_drawable_get_depth QGtk::gdk_drawable_get_depth = 0; -Ptr_gdk_color_free QGtk::gdk_color_free = 0; -Ptr_gdk_x11_window_set_user_time QGtk::gdk_x11_window_set_user_time = 0; -Ptr_gdk_x11_drawable_get_xid QGtk::gdk_x11_drawable_get_xid = 0; -Ptr_gdk_x11_drawable_get_xdisplay QGtk::gdk_x11_drawable_get_xdisplay = 0; - -Ptr_gconf_client_get_default QGtk::gconf_client_get_default = 0; -Ptr_gconf_client_get_string QGtk::gconf_client_get_string = 0; -Ptr_gconf_client_get_bool QGtk::gconf_client_get_bool = 0; - -Ptr_gnome_icon_lookup_sync QGtk::gnome_icon_lookup_sync = 0; -Ptr_gnome_vfs_init QGtk::gnome_vfs_init = 0; - -static QString classPath(GtkWidget *widget) -{ - char* class_path; - QGtk::gtk_widget_path (widget, NULL, &class_path, NULL); - QString path = QLS(class_path); - g_free(class_path); - - // Remove the prefixes - path.remove(QLS("GtkWindow.")); - path.remove(QLS("GtkFixed.")); - return path; -} - -static void resolveGtk() -{ - // enforce the "0" suffix, so we'll open libgtk-x11-2.0.so.0 - QLibrary libgtk(QLS("gtk-x11-2.0"), 0, 0); - QGtk::gtk_init = (Ptr_gtk_init)libgtk.resolve("gtk_init"); - QGtk::gtk_window_new = (Ptr_gtk_window_new)libgtk.resolve("gtk_window_new"); - QGtk::gtk_style_attach = (Ptr_gtk_style_attach)libgtk.resolve("gtk_style_attach"); - QGtk::gtk_widget_destroy = (Ptr_gtk_widget_destroy)libgtk.resolve("gtk_widget_destroy"); - QGtk::gtk_widget_realize = (Ptr_gtk_widget_realize)libgtk.resolve("gtk_widget_realize"); - - QGtk::gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)libgtk.resolve("gtk_file_chooser_set_current_folder"); - QGtk::gtk_file_filter_new = (Ptr_gtk_file_filter_new)libgtk.resolve("gtk_file_filter_new"); - QGtk::gtk_file_filter_set_name = (Ptr_gtk_file_filter_set_name)libgtk.resolve("gtk_file_filter_set_name"); - QGtk::gtk_file_filter_add_pattern = (Ptr_gtk_file_filter_add_pattern)libgtk.resolve("gtk_file_filter_add_pattern"); - QGtk::gtk_file_chooser_add_filter = (Ptr_gtk_file_chooser_add_filter)libgtk.resolve("gtk_file_chooser_add_filter"); - QGtk::gtk_file_chooser_set_filter = (Ptr_gtk_file_chooser_set_filter)libgtk.resolve("gtk_file_chooser_set_filter"); - QGtk::gtk_file_chooser_get_filter = (Ptr_gtk_file_chooser_get_filter)libgtk.resolve("gtk_file_chooser_get_filter"); - QGtk::gtk_file_chooser_dialog_new = (Ptr_gtk_file_chooser_dialog_new)libgtk.resolve("gtk_file_chooser_dialog_new"); - QGtk::gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)libgtk.resolve("gtk_file_chooser_set_current_folder"); - QGtk::gtk_file_chooser_get_filename = (Ptr_gtk_file_chooser_get_filename)libgtk.resolve("gtk_file_chooser_get_filename"); - QGtk::gtk_file_chooser_get_filenames = (Ptr_gtk_file_chooser_get_filenames)libgtk.resolve("gtk_file_chooser_get_filenames"); - QGtk::gtk_file_chooser_set_current_name = (Ptr_gtk_file_chooser_set_current_name)libgtk.resolve("gtk_file_chooser_set_current_name"); - QGtk::gtk_dialog_run = (Ptr_gtk_dialog_run)libgtk.resolve("gtk_dialog_run"); - QGtk::gtk_file_chooser_set_filename = (Ptr_gtk_file_chooser_set_filename)libgtk.resolve("gtk_file_chooser_set_filename"); - - QGtk::gdk_pixbuf_get_pixels = (Ptr_gdk_pixbuf_get_pixels)libgtk.resolve("gdk_pixbuf_get_pixels"); - QGtk::gdk_pixbuf_get_width = (Ptr_gdk_pixbuf_get_width)libgtk.resolve("gdk_pixbuf_get_width"); - QGtk::gdk_pixbuf_get_height = (Ptr_gdk_pixbuf_get_height)libgtk.resolve("gdk_pixbuf_get_height"); - QGtk::gdk_pixmap_new = (Ptr_gdk_pixmap_new)libgtk.resolve("gdk_pixmap_new"); - QGtk::gdk_pixbuf_new = (Ptr_gdk_pixbuf_new)libgtk.resolve("gdk_pixbuf_new"); - QGtk::gdk_pixbuf_get_from_drawable = (Ptr_gdk_pixbuf_get_from_drawable)libgtk.resolve("gdk_pixbuf_get_from_drawable"); - QGtk::gdk_draw_rectangle = (Ptr_gdk_draw_rectangle)libgtk.resolve("gdk_draw_rectangle"); - QGtk::gdk_pixbuf_unref = (Ptr_gdk_pixbuf_unref)libgtk.resolve("gdk_pixbuf_unref"); - QGtk::gdk_drawable_unref = (Ptr_gdk_drawable_unref)libgtk.resolve("gdk_drawable_unref"); - QGtk::gdk_drawable_get_depth = (Ptr_gdk_drawable_get_depth)libgtk.resolve("gdk_drawable_get_depth"); - QGtk::gdk_color_free = (Ptr_gdk_color_free)libgtk.resolve("gdk_color_free"); - QGtk::gdk_x11_window_set_user_time = (Ptr_gdk_x11_window_set_user_time)libgtk.resolve("gdk_x11_window_set_user_time"); - QGtk::gdk_x11_drawable_get_xid = (Ptr_gdk_x11_drawable_get_xid)libgtk.resolve("gdk_x11_drawable_get_xid"); - QGtk::gdk_x11_drawable_get_xdisplay = (Ptr_gdk_x11_drawable_get_xdisplay)libgtk.resolve("gdk_x11_drawable_get_xdisplay"); - - QGtk::gtk_widget_set_default_direction = (Ptr_gtk_widget_set_default_direction)libgtk.resolve("gtk_widget_set_default_direction"); - QGtk::gtk_widget_modify_fg = (Ptr_gtk_widget_modify_color)libgtk.resolve("gtk_widget_modify_fg"); - QGtk::gtk_widget_modify_bg = (Ptr_gtk_widget_modify_color)libgtk.resolve("gtk_widget_modify_bg"); - QGtk::gtk_arrow_new = (Ptr_gtk_arrow_new)libgtk.resolve("gtk_arrow_new"); - QGtk::gtk_menu_item_new = (Ptr_gtk_menu_item_new)libgtk.resolve("gtk_menu_item_new"); - QGtk::gtk_check_menu_item_new = (Ptr_gtk_check_menu_item_new)libgtk.resolve("gtk_check_menu_item_new"); - QGtk::gtk_menu_bar_new = (Ptr_gtk_menu_bar_new)libgtk.resolve("gtk_menu_bar_new"); - QGtk::gtk_menu_new = (Ptr_gtk_menu_new)libgtk.resolve("gtk_menu_new"); - QGtk::gtk_toolbar_new = (Ptr_gtk_toolbar_new)libgtk.resolve("gtk_toolbar_new"); - QGtk::gtk_separator_tool_item_new = (Ptr_gtk_separator_tool_item_new)libgtk.resolve("gtk_separator_tool_item_new"); - QGtk::gtk_toolbar_insert = (Ptr_gtk_toolbar_insert)libgtk.resolve("gtk_toolbar_insert"); - QGtk::gtk_button_new = (Ptr_gtk_button_new)libgtk.resolve("gtk_button_new"); - QGtk::gtk_tool_button_new = (Ptr_gtk_tool_button_new)libgtk.resolve("gtk_tool_button_new"); - QGtk::gtk_hbutton_box_new = (Ptr_gtk_hbutton_box_new)libgtk.resolve("gtk_hbutton_box_new"); - QGtk::gtk_check_button_new = (Ptr_gtk_check_button_new)libgtk.resolve("gtk_check_button_new"); - QGtk::gtk_radio_button_new = (Ptr_gtk_radio_button_new)libgtk.resolve("gtk_radio_button_new"); - QGtk::gtk_notebook_new = (Ptr_gtk_notebook_new)libgtk.resolve("gtk_notebook_new"); - QGtk::gtk_progress_bar_new = (Ptr_gtk_progress_bar_new)libgtk.resolve("gtk_progress_bar_new"); - QGtk::gtk_spin_button_new = (Ptr_gtk_spin_button_new)libgtk.resolve("gtk_spin_button_new"); - QGtk::gtk_hscale_new = (Ptr_gtk_hscale_new)libgtk.resolve("gtk_hscale_new"); - QGtk::gtk_vscale_new = (Ptr_gtk_vscale_new)libgtk.resolve("gtk_vscale_new"); - QGtk::gtk_hscrollbar_new = (Ptr_gtk_hscrollbar_new)libgtk.resolve("gtk_hscrollbar_new"); - QGtk::gtk_vscrollbar_new = (Ptr_gtk_vscrollbar_new)libgtk.resolve("gtk_vscrollbar_new"); - QGtk::gtk_scrolled_window_new = (Ptr_gtk_scrolled_window_new)libgtk.resolve("gtk_scrolled_window_new"); - QGtk::gtk_menu_shell_append = (Ptr_gtk_menu_shell_append)libgtk.resolve("gtk_menu_shell_append"); - QGtk::gtk_entry_new = (Ptr_gtk_entry_new)libgtk.resolve("gtk_entry_new"); - QGtk::gtk_tree_view_new = (Ptr_gtk_tree_view_new)libgtk.resolve("gtk_tree_view_new"); - QGtk::gtk_combo_box_new = (Ptr_gtk_combo_box_new)libgtk.resolve("gtk_combo_box_new"); - QGtk::gtk_progress_set_adjustment = (Ptr_gtk_progress_set_adjustment)libgtk.resolve("gtk_progress_set_adjustment"); - QGtk::gtk_range_set_adjustment = (Ptr_gtk_range_set_adjustment)libgtk.resolve("gtk_range_set_adjustment"); - QGtk::gtk_range_set_inverted = (Ptr_gtk_range_set_inverted)libgtk.resolve("gtk_range_set_inverted"); - QGtk::gtk_container_add = (Ptr_gtk_container_add)libgtk.resolve("gtk_container_add"); - QGtk::gtk_icon_factory_lookup_default = (Ptr_gtk_icon_factory_lookup_default)libgtk.resolve("gtk_icon_factory_lookup_default"); - QGtk::gtk_icon_theme_get_default = (Ptr_gtk_icon_theme_get_default)libgtk.resolve("gtk_icon_theme_get_default"); - QGtk::gtk_widget_style_get = (Ptr_gtk_widget_style_get)libgtk.resolve("gtk_widget_style_get"); - QGtk::gtk_icon_set_render_icon = (Ptr_gtk_icon_set_render_icon)libgtk.resolve("gtk_icon_set_render_icon"); - QGtk::gtk_fixed_new = (Ptr_gtk_fixed_new)libgtk.resolve("gtk_fixed_new"); - QGtk::gtk_tree_view_column_new = (Ptr_gtk_tree_view_column_new)libgtk.resolve("gtk_tree_view_column_new"); - QGtk::gtk_tree_view_append_column= (Ptr_gtk_tree_view_append_column )libgtk.resolve("gtk_tree_view_append_column"); - QGtk::gtk_tree_view_get_column = (Ptr_gtk_tree_view_get_column )libgtk.resolve("gtk_tree_view_get_column"); - QGtk::gtk_paint_check = (Ptr_gtk_paint_check)libgtk.resolve("gtk_paint_check"); - QGtk::gtk_paint_box = (Ptr_gtk_paint_box)libgtk.resolve("gtk_paint_box"); - QGtk::gtk_paint_flat_box = (Ptr_gtk_paint_flat_box)libgtk.resolve("gtk_paint_flat_box"); - QGtk::gtk_paint_check = (Ptr_gtk_paint_check)libgtk.resolve("gtk_paint_check"); - QGtk::gtk_paint_box = (Ptr_gtk_paint_box)libgtk.resolve("gtk_paint_box"); - QGtk::gtk_paint_resize_grip = (Ptr_gtk_paint_resize_grip)libgtk.resolve("gtk_paint_resize_grip"); - QGtk::gtk_paint_focus = (Ptr_gtk_paint_focus)libgtk.resolve("gtk_paint_focus"); - QGtk::gtk_paint_shadow = (Ptr_gtk_paint_shadow)libgtk.resolve("gtk_paint_shadow"); - QGtk::gtk_paint_slider = (Ptr_gtk_paint_slider)libgtk.resolve("gtk_paint_slider"); - QGtk::gtk_paint_expander = (Ptr_gtk_paint_expander)libgtk.resolve("gtk_paint_expander"); - QGtk::gtk_paint_handle = (Ptr_gtk_paint_handle)libgtk.resolve("gtk_paint_handle"); - QGtk::gtk_paint_option = (Ptr_gtk_paint_option)libgtk.resolve("gtk_paint_option"); - QGtk::gtk_paint_arrow = (Ptr_gtk_paint_arrow)libgtk.resolve("gtk_paint_arrow"); - QGtk::gtk_paint_box_gap = (Ptr_gtk_paint_box_gap)libgtk.resolve("gtk_paint_box_gap"); - QGtk::gtk_paint_extension = (Ptr_gtk_paint_extension)libgtk.resolve("gtk_paint_extension"); - QGtk::gtk_paint_hline = (Ptr_gtk_paint_hline)libgtk.resolve("gtk_paint_hline"); - QGtk::gtk_paint_vline = (Ptr_gtk_paint_vline)libgtk.resolve("gtk_paint_vline"); - QGtk::gtk_adjustment_new = (Ptr_gtk_adjustment_new)libgtk.resolve("gtk_adjustment_new"); - QGtk::gtk_menu_item_set_submenu = (Ptr_gtk_menu_item_set_submenu)libgtk.resolve("gtk_menu_item_set_submenu"); - QGtk::gtk_settings_get_default = (Ptr_gtk_settings_get_default)libgtk.resolve("gtk_settings_get_default"); - QGtk::gtk_separator_menu_item_new = (Ptr_gtk_separator_menu_item_new)libgtk.resolve("gtk_separator_menu_item_new"); - QGtk::gtk_frame_new = (Ptr_gtk_frame_new)libgtk.resolve("gtk_frame_new"); - QGtk::gtk_expander_new = (Ptr_gtk_expander_new)libgtk.resolve("gtk_expander_new"); - QGtk::gtk_statusbar_new = (Ptr_gtk_statusbar_new)libgtk.resolve("gtk_statusbar_new"); - QGtk::gtk_combo_box_entry_new = (Ptr_gtk_combo_box_entry_new)libgtk.resolve("gtk_combo_box_entry_new"); - QGtk::gtk_container_forall = (Ptr_gtk_container_forall)libgtk.resolve("gtk_container_forall"); - QGtk::gtk_widget_size_allocate =(Ptr_gtk_widget_size_allocate)libgtk.resolve("gtk_widget_size_allocate"); - QGtk::gtk_widget_set_direction =(Ptr_gtk_widget_set_direction)libgtk.resolve("gtk_widget_set_direction"); - QGtk::gtk_widget_path =(Ptr_gtk_widget_path)libgtk.resolve("gtk_widget_path"); - QGtk::gtk_container_get_type =(Ptr_gtk_container_get_type)libgtk.resolve("gtk_container_get_type"); - QGtk::gtk_window_get_type =(Ptr_gtk_window_get_type)libgtk.resolve("gtk_window_get_type"); - QGtk::gtk_widget_get_type =(Ptr_gtk_widget_get_type)libgtk.resolve("gtk_widget_get_type"); - QGtk::gtk_rc_get_style_by_paths =(Ptr_gtk_rc_get_style_by_paths)libgtk.resolve("gtk_rc_get_style_by_paths"); - QGtk::gtk_check_version =(Ptr_gtk_check_version)libgtk.resolve("gtk_check_version"); - QGtk::pango_font_description_get_size = (Ptr_pango_font_description_get_size)libgtk.resolve("pango_font_description_get_size"); - QGtk::pango_font_description_get_weight = (Ptr_pango_font_description_get_weight)libgtk.resolve("pango_font_description_get_weight"); - QGtk::pango_font_description_get_family = (Ptr_pango_font_description_get_family)libgtk.resolve("pango_font_description_get_family"); - QGtk::pango_font_description_get_style = (Ptr_pango_font_description_get_style)libgtk.resolve("pango_font_description_get_style"); - - QGtk::gnome_icon_lookup_sync = (Ptr_gnome_icon_lookup_sync)QLibrary::resolve( QLS("gnomeui-2"), 0, "gnome_icon_lookup_sync"); - QGtk::gnome_vfs_init= (Ptr_gnome_vfs_init)QLibrary::resolve( QLS("gnomevfs-2"), 0, "gnome_vfs_init"); -} - -void QGtk::cleanup_gtk_widgets() -{ - if (gtkWidgetMap()->contains(QLS("GtkWindow"))) // Gtk will destroy all children - QGtk::gtk_widget_destroy(gtkWidgetMap()->value(QLS("GtkWindow"))); -} - -static bool resolveGConf() -{ - if (!QGtk::gconf_client_get_default) { - QGtk::gconf_client_get_default = (Ptr_gconf_client_get_default)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_default"); - QGtk::gconf_client_get_string = (Ptr_gconf_client_get_string)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_string"); - QGtk::gconf_client_get_bool = (Ptr_gconf_client_get_bool)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_bool"); - } - return (QGtk::gconf_client_get_default !=0); -} - -typedef int (*x11ErrorHandler)(Display*, XErrorEvent*); - -QString QGtk::getGConfString(const QString &value, const QString &fallback) -{ - QString retVal = fallback; - if (resolveGConf()) { - g_type_init(); - GConfClient* client = QGtk::gconf_client_get_default(); - GError *err = 0; - char *str = QGtk::gconf_client_get_string(client, qPrintable(value), &err); - if (!err) { - retVal = QString::fromUtf8(str); - g_free(str); - } - g_object_unref(client); - if (err) - g_error_free (err); - } - return retVal; -} - -bool QGtk::getGConfBool(const QString &key, bool fallback) -{ - bool retVal = fallback; - if (resolveGConf()) { - g_type_init(); - GConfClient* client = QGtk::gconf_client_get_default(); - GError *err = 0; - bool result = QGtk::gconf_client_get_bool(client, qPrintable(key), &err); - g_object_unref(client); - if (!err) - retVal = result; - else - g_error_free (err); - } - return retVal; -} - -static QString getThemeName() -{ - QString themeName; - // We try to parse the gtkrc file first - // primarily to avoid resolving Gtk functions if - // the KDE 3 "Qt" style is currently in use - QString rcPaths = QString::fromLocal8Bit(qgetenv("GTK2_RC_FILES")); - if (!rcPaths.isEmpty()) { - QStringList paths = rcPaths.split(QLS(":")); - foreach (const QString &rcPath, paths) { - if (!rcPath.isEmpty()) { - QFile rcFile(rcPath); - if (rcFile.exists() && rcFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&rcFile); - while(!in.atEnd()) { - QString line = in.readLine(); - if (line.contains(QLS("gtk-theme-name"))) { - line = line.right(line.length() - line.indexOf(QLatin1Char('=')) - 1); - line.remove(QLatin1Char('\"')); - line = line.trimmed(); - themeName = line; - break; - } - } - } - } - if (!themeName.isEmpty()) - break; - } - } - - // Fall back to gconf - if (themeName.isEmpty() && resolveGConf()) - themeName = QGtk::getGConfString(QLS("/desktop/gnome/interface/gtk_theme")); - - return themeName; -} - -static void init_gtk_window() -{ - static QString themeName; - if (!gtkWidgetMap()->contains(QLS("GtkWindow")) && themeName.isEmpty()) { - themeName = getThemeName(); - - if (themeName.isEmpty()) { - qWarning("QGtkStyle was unable to detect the current GTK+ theme."); - return; - } else if (themeName == QLS("Qt") || themeName == QLS("Qt4")) { - // Due to namespace conflicts with Qt3 and obvious recursion with Qt4, - // we cannot support the GTK_Qt Gtk engine - qWarning("QGtkStyle cannot be used together with the GTK_Qt engine."); - return; - } - - resolveGtk(); - - if (QGtk::gtk_init) { - // Gtk will set the Qt error handler so we have to reset it afterwards - x11ErrorHandler qt_x_errhandler = XSetErrorHandler(0); - QGtk::gtk_init (NULL, NULL); - XSetErrorHandler(qt_x_errhandler); - - GtkWidget* gtkWindow = QGtk::gtk_window_new(GTK_WINDOW_POPUP); - QGtk::gtk_widget_realize(gtkWindow); - if (displayDepth == -1) - displayDepth = QGtk::gdk_drawable_get_depth(gtkWindow->window); - gtkWidgetMap()->insert(QLS("GtkWindow"), gtkWindow); - } else { - qWarning("QGtkStyle could not resolve GTK. Make sure you have installed the proper libraries."); - } - } -} - -static void setup_gtk_widget(GtkWidget* widget) -{ - if (Q_GTK_IS_WIDGET(widget)) { - static GtkWidget* protoLayout = 0; - if (!protoLayout) { - protoLayout = QGtk::gtk_fixed_new(); - QGtk::gtk_container_add((GtkContainer*)(gtkWidgetMap()->value(QLS("GtkWindow"))), protoLayout); - } - Q_ASSERT(protoLayout); - - QGtk::gtk_container_add((GtkContainer*)(protoLayout), widget); - QGtk::gtk_widget_realize(widget); - } -} - -static void add_widget_to_map(GtkWidget *widget) -{ - if (Q_GTK_IS_WIDGET(widget)) { - QGtk::gtk_widget_realize(widget); - gtkWidgetMap()->insert(classPath(widget), widget); - } - } - -static void add_all_sub_widgets(GtkWidget *widget, gpointer v = 0) -{ - Q_UNUSED(v); - add_widget_to_map(widget); - if (GTK_CHECK_TYPE ((widget), Q_GTK_TYPE_CONTAINER)) - QGtk::gtk_container_forall((GtkContainer*)widget, add_all_sub_widgets, NULL); -} - -static void init_gtk_menu() -{ - // Create menubar - GtkWidget *gtkMenuBar = QGtk::gtk_menu_bar_new(); - setup_gtk_widget(gtkMenuBar); - - GtkWidget *gtkMenuBarItem = QGtk::gtk_menu_item_new(); - QGtk::gtk_menu_shell_append((GtkMenuShell*)(gtkMenuBar), gtkMenuBarItem); - QGtk::gtk_widget_realize(gtkMenuBarItem); - - // Create menu - GtkWidget *gtkMenu = QGtk::gtk_menu_new(); - QGtk::gtk_menu_item_set_submenu((GtkMenuItem*)(gtkMenuBarItem), gtkMenu); - QGtk::gtk_widget_realize(gtkMenu); - - GtkWidget *gtkMenuItem = QGtk::gtk_menu_item_new(); - QGtk::gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkMenuItem); - QGtk::gtk_widget_realize(gtkMenuItem); - - GtkWidget *gtkCheckMenuItem = QGtk::gtk_check_menu_item_new(); - QGtk::gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkCheckMenuItem); - QGtk::gtk_widget_realize(gtkCheckMenuItem); - - GtkWidget *gtkMenuSeparator = QGtk::gtk_separator_menu_item_new(); - QGtk::gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkMenuSeparator); - - add_all_sub_widgets(gtkMenuBar); - add_all_sub_widgets(gtkMenu); -} - -// Updates window/windowtext palette based on the indicated gtk widget -static QPalette gtkWidgetPalette(const QString >kWidgetName) -{ - GtkWidget *gtkWidget = QGtk::gtkWidget(gtkWidgetName); - Q_ASSERT(gtkWidget); - QPalette pal = QApplication::palette(); - GdkColor gdkBg = gtkWidget->style->bg[GTK_STATE_NORMAL]; - GdkColor gdkText = gtkWidget->style->fg[GTK_STATE_NORMAL]; - GdkColor gdkDisabledText = gtkWidget->style->fg[GTK_STATE_INSENSITIVE]; - QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8); - QColor textColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8); - QColor disabledTextColor(gdkDisabledText.red>>8, gdkDisabledText.green>>8, gdkDisabledText.blue>>8); - pal.setBrush(QPalette::Window, bgColor); - pal.setBrush(QPalette::Button, bgColor); - pal.setBrush(QPalette::All, QPalette::WindowText, textColor); - pal.setBrush(QPalette::Disabled, QPalette::WindowText, disabledTextColor); - pal.setBrush(QPalette::All, QPalette::ButtonText, textColor); - pal.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledTextColor); - return pal; -} - -bool QGtk::isKDE4Session() -{ - static int version = -1; - if (version == -1) - version = qgetenv("KDE_SESSION_VERSION").toInt(); - return (version == 4); -} - -void QGtk::applyCustomPaletteHash() -{ - QPalette menuPal = gtkWidgetPalette(QLS("GtkMenu")); - GdkColor gdkBg = QGtk::gtkWidget(QLS("GtkMenu"))->style->bg[GTK_STATE_NORMAL]; - QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8); - menuPal.setBrush(QPalette::Base, bgColor); - menuPal.setBrush(QPalette::Window, bgColor); - qApp->setPalette(menuPal, "QMenu"); - - QPalette toolbarPal = gtkWidgetPalette(QLS("GtkToolbar")); - qApp->setPalette(toolbarPal, "QToolBar"); - - QPalette menuBarPal = gtkWidgetPalette(QLS("GtkMenuBar")); - qApp->setPalette(menuBarPal, "QMenuBar"); -} - -static void gtkStyleSetCallback(GtkWidget*, GtkStyle*, void*) -{ - // We have to let this function return and complete the event - // loop to ensure that all gtk widgets have been styled before - // updating - QMetaObject::invokeMethod(styleScheduler(), "updateTheme", Qt::QueuedConnection); -} - -void QGtkStyleUpdateScheduler::updateTheme() -{ - static QString oldTheme(QLS("qt_not_set")); - QPixmapCache::clear(); - - QFont font = QGtk::getThemeFont(); - if (QApplication::font() != font) - qApp->setFont(font); - - if (oldTheme != getThemeName()) { - oldTheme = getThemeName(); - QPalette newPalette = qApp->style()->standardPalette(); - QApplicationPrivate::setSystemPalette(newPalette); - QApplication::setPalette(newPalette); - QGtk::initGtkWidgets(); - QGtk::applyCustomPaletteHash(); - QList<QWidget*> widgets = QApplication::allWidgets(); - // Notify all widgets that size metrics might have changed - foreach (QWidget *widget, widgets) { - QEvent e(QEvent::StyleChange); - QApplication::sendEvent(widget, &e); - } - } - QIconLoader::instance()->updateSystemTheme(); -} - -static void add_widget(GtkWidget *widget) -{ - if (widget) { - setup_gtk_widget(widget); - add_all_sub_widgets(widget); - } -} - -static void init_gtk_treeview() -{ - GtkWidget *gtkTreeView = QGtk::gtk_tree_view_new(); - QGtk::gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, QGtk::gtk_tree_view_column_new()); - QGtk::gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, QGtk::gtk_tree_view_column_new()); - QGtk::gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, QGtk::gtk_tree_view_column_new()); - add_widget(gtkTreeView); -} - - -// Fetch the application font from the pango font description -// contained in the theme. -QFont QGtk::getThemeFont() -{ - QFont font; - GtkStyle *style = gtkStyle(); - if (style && qApp->desktopSettingsAware()) - { - PangoFontDescription *gtk_font = style->font_desc; - font.setPointSizeF((float)(pango_font_description_get_size(gtk_font))/PANGO_SCALE); - - QString family = QString::fromLatin1(pango_font_description_get_family(gtk_font)); - if (!family.isEmpty()) - font.setFamily(family); - - int weight = pango_font_description_get_weight(gtk_font); - if (weight >= PANGO_WEIGHT_HEAVY) - font.setWeight(QFont::Black); - else if (weight >= PANGO_WEIGHT_BOLD) - font.setWeight(QFont::Bold); - else if (weight >= PANGO_WEIGHT_SEMIBOLD) - font.setWeight(QFont::DemiBold); - else if (weight >= PANGO_WEIGHT_NORMAL) - font.setWeight(QFont::Normal); - else - font.setWeight(QFont::Light); - - PangoStyle fontstyle = pango_font_description_get_style(gtk_font); - if (fontstyle == PANGO_STYLE_ITALIC) - font.setStyle(QFont::StyleItalic); - else if (fontstyle == PANGO_STYLE_OBLIQUE) - font.setStyle(QFont::StyleOblique); - else - font.setStyle(QFont::StyleNormal); - } - return font; -} - -GtkWidget* QGtk::gtkWidget(const QString &path) -{ - GtkWidget *widget = gtkWidgetMap()->value(path); - if (!widget) { - // Theme might have rearranged widget internals - widget = gtkWidgetMap()->value(path); - } - return widget; -} - -GtkStyle* QGtk::gtkStyle(const QString &path) -{ - if (gtkWidgetMap()->contains(path)) - return gtkWidgetMap()->value(path)->style; - return 0; -} - -static void update_toolbar_style(GtkWidget *gtkToolBar, GParamSpec *, gpointer) -{ - GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS; - g_object_get(gtkToolBar, "toolbar-style", &toolbar_style, NULL); - QWidgetList widgets = QApplication::allWidgets(); - for (int i = 0; i < widgets.size(); ++i) { - QWidget *widget = widgets.at(i); - if (qobject_cast<QToolButton*>(widget)) { - QEvent event(QEvent::StyleChange); - QApplication::sendEvent(widget, &event); - } - } -} - -void QGtk::initGtkWidgets() -{ - // From gtkmain.c - uid_t ruid = getuid (); - uid_t rgid = getgid (); - uid_t euid = geteuid (); - uid_t egid = getegid (); - if (ruid != euid || rgid != egid) { - qWarning("\nThis process is currently running setuid or setgid.\nGTK+ does not allow this " - "therefore Qt cannot use the GTK+ integration.\nTry launching your app using \'gksudo\', " - "\'kdesudo\' or a similar tool.\n\n" - "See http://www.gtk.org/setuid.html for more information.\n"); - return; - } - - init_gtk_window(); - - if (QGtk::gtk_init) { - - // Make all widgets respect the text direction - if (qApp->layoutDirection() == Qt::RightToLeft) - QGtk::gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL); - - if (!gtkWidgetMap()->contains(QLS("GtkButton"))) { - GtkWidget *gtkButton = QGtk::gtk_button_new(); - add_widget(gtkButton); - g_signal_connect(gtkButton, "style-set", G_CALLBACK(gtkStyleSetCallback), NULL); - add_widget(QGtk::gtk_tool_button_new(NULL, NULL)); - add_widget(QGtk::gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE)); - add_widget(QGtk::gtk_hbutton_box_new()); - add_widget(QGtk::gtk_check_button_new()); - add_widget(QGtk::gtk_radio_button_new(NULL)); - add_widget(QGtk::gtk_combo_box_new()); - add_widget(QGtk::gtk_combo_box_entry_new()); - add_widget(QGtk::gtk_entry_new()); - add_widget(QGtk::gtk_frame_new(NULL)); - add_widget(QGtk::gtk_expander_new("")); - add_widget(QGtk::gtk_statusbar_new()); - add_widget(QGtk::gtk_hscale_new((GtkAdjustment*)(QGtk::gtk_adjustment_new(1, 0, 1, 0, 0, 0)))); - add_widget(QGtk::gtk_hscrollbar_new(NULL)); - add_widget(QGtk::gtk_scrolled_window_new(NULL, NULL)); - init_gtk_menu(); - add_widget(QGtk::gtk_notebook_new()); - add_widget(QGtk::gtk_progress_bar_new()); - add_widget(QGtk::gtk_spin_button_new((GtkAdjustment*) - (QGtk::gtk_adjustment_new(1, 0, 1, 0, 0, 0)), 0.1, 3)); - GtkWidget *toolbar = QGtk::gtk_toolbar_new(); - g_signal_connect (toolbar, "notify::toolbar-style", G_CALLBACK (update_toolbar_style), toolbar); - QGtk::gtk_toolbar_insert((GtkToolbar*)toolbar, QGtk::gtk_separator_tool_item_new(), -1); - add_widget(toolbar); - init_gtk_treeview(); - add_widget(QGtk::gtk_vscale_new((GtkAdjustment*)(QGtk::gtk_adjustment_new(1, 0, 1, 0, 0, 0)))); - add_widget(QGtk::gtk_vscrollbar_new(NULL)); - } - else // Rebuild map - { - // When styles change subwidgets can get rearranged - // as with the combo box. We need to update the widget map - // to reflect this; - QHash<QString, GtkWidget*> oldMap = *gtkWidgetMap(); - gtkWidgetMap()->clear(); - QHashIterator<QString, GtkWidget*> it(oldMap); - while (it.hasNext()) { - it.next(); - if (!it.key().contains(QLatin1Char('.'))) { - add_all_sub_widgets(it.value()); - } - } - } - } -} - -// ----------- Native file dialogs ----------- - -// Extract filter list from expressions of type: foo (*.a *.b *.c)" -static QStringList extract_filter(const QString &rawFilter) -{ - QString result = rawFilter; - QRegExp r(QString::fromLatin1("^([^()]*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$")); - int index = r.indexIn(result); - if (index >= 0) - result = r.cap(2); - return result.split(QLatin1Char(' ')); -} - -extern QStringList qt_make_filter_list(const QString &filter); - -static void setupGtkFileChooser(GtkWidget* gtkFileChooser, QWidget *parent, - const QString &dir, const QString &filter, QString *selectedFilter, - QFileDialog::Options options, bool isSaveDialog = false, - QMap<GtkFileFilter *, QString> *filterMap = 0) -{ - g_object_set(gtkFileChooser, "do-overwrite-confirmation", gboolean(!(options & QFileDialog::DontConfirmOverwrite)), NULL); - g_object_set(gtkFileChooser, "local_only", gboolean(true), NULL); - if (!filter.isEmpty()) { - QStringList filters = qt_make_filter_list(filter); - foreach (const QString &rawfilter, filters) { - GtkFileFilter *gtkFilter = QGtk::gtk_file_filter_new (); - QString name = rawfilter.left(rawfilter.indexOf(QLatin1Char('('))); - QStringList extensions = extract_filter(rawfilter); - QGtk::gtk_file_filter_set_name(gtkFilter, qPrintable(name.isEmpty() ? extensions.join(QLS(", ")) : name)); - - foreach (const QString &fileExtension, extensions) { - // Note Gtk file dialogs are by default case sensitive - // and only supports basic glob syntax so we - // rewrite .xyz to .[xX][yY][zZ] - QString caseInsensitive; - for (int i = 0 ; i < fileExtension.length() ; ++i) { - QChar ch = fileExtension.at(i); - if (ch.isLetter()) { - caseInsensitive.append( - QLatin1Char('[') + - ch.toLower() + - ch.toUpper() + - QLatin1Char(']')); - } else { - caseInsensitive.append(ch); - } - } - QGtk::gtk_file_filter_add_pattern (gtkFilter, qPrintable(caseInsensitive)); - - } - if (filterMap) - filterMap->insert(gtkFilter, rawfilter); - QGtk::gtk_file_chooser_add_filter((GtkFileChooser*)gtkFileChooser, gtkFilter); - if (selectedFilter && (rawfilter == *selectedFilter)) - QGtk::gtk_file_chooser_set_filter((GtkFileChooser*)gtkFileChooser, gtkFilter); - } - } - - // Using the currently active window is not entirely correct, however - // it gives more sensible behavior for applications that do not provide a - // parent - QWidget *modalFor = parent ? parent->window() : qApp->activeWindow(); - if (modalFor) { - QGtk::gtk_widget_realize(gtkFileChooser); // Creates X window - XSetTransientForHint(QGtk::gdk_x11_drawable_get_xdisplay(gtkFileChooser->window), - QGtk::gdk_x11_drawable_get_xid(gtkFileChooser->window), - modalFor->winId()); - QGtk::gdk_x11_window_set_user_time (gtkFileChooser->window, QX11Info::appUserTime()); - - } - - QFileInfo fileinfo(dir); - if (dir.isEmpty()) - fileinfo.setFile(QDir::currentPath()); - fileinfo.makeAbsolute(); - if (fileinfo.isDir()) { - QGtk::gtk_file_chooser_set_current_folder((GtkFileChooser*)gtkFileChooser, qPrintable(dir)); - } else if (isSaveDialog) { - QGtk::gtk_file_chooser_set_current_folder((GtkFileChooser*)gtkFileChooser, qPrintable(fileinfo.absolutePath())); - QGtk::gtk_file_chooser_set_current_name((GtkFileChooser*)gtkFileChooser, qPrintable(fileinfo.fileName())); - } else { - QGtk::gtk_file_chooser_set_filename((GtkFileChooser*)gtkFileChooser, qPrintable(dir)); - } -} - -QString QGtk::openFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, - QString *selectedFilter, QFileDialog::Options options) -{ - QMap<GtkFileFilter *, QString> filterMap; - GtkWidget *gtkFileChooser = QGtk::gtk_file_chooser_dialog_new (qPrintable(caption), - NULL, - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - - setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, false, &filterMap); - - QWidget modal_widget; - modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); - modal_widget.setParent(parent, Qt::Window); - QApplicationPrivate::enterModal(&modal_widget); - - QString filename; - if (QGtk::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { - char *gtk_filename = QGtk::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser); - filename = QString::fromUtf8(gtk_filename); - g_free (gtk_filename); - if (selectedFilter) { - GtkFileFilter *gtkFilter = QGtk::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser); - *selectedFilter = filterMap.value(gtkFilter); - } - } - - QApplicationPrivate::leaveModal(&modal_widget); - gtk_widget_destroy (gtkFileChooser); - return filename; -} - - -QString QGtk::openDirectory(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options) -{ - QMap<GtkFileFilter *, QString> filterMap; - GtkWidget *gtkFileChooser = QGtk::gtk_file_chooser_dialog_new (qPrintable(caption), - NULL, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - - setupGtkFileChooser(gtkFileChooser, parent, dir, QString(), 0, options); - QWidget modal_widget; - modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); - modal_widget.setParent(parent, Qt::Window); - QApplicationPrivate::enterModal(&modal_widget); - - QString filename; - if (QGtk::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { - char *gtk_filename = QGtk::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser); - filename = QString::fromUtf8(gtk_filename); - g_free (gtk_filename); - } - - QApplicationPrivate::leaveModal(&modal_widget); - gtk_widget_destroy (gtkFileChooser); - return filename; -} - -QStringList QGtk::openFilenames(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, - QString *selectedFilter, QFileDialog::Options options) -{ - QStringList filenames; - QMap<GtkFileFilter *, QString> filterMap; - GtkWidget *gtkFileChooser = QGtk::gtk_file_chooser_dialog_new (qPrintable(caption), - NULL, - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - - setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, false, &filterMap); - g_object_set(gtkFileChooser, "select-multiple", gboolean(true), NULL); - - QWidget modal_widget; - modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); - modal_widget.setParent(parent, Qt::Window); - QApplicationPrivate::enterModal(&modal_widget); - - if (gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { - GSList *gtk_file_names = QGtk::gtk_file_chooser_get_filenames((GtkFileChooser*)gtkFileChooser); - for (GSList *iterator = gtk_file_names ; iterator; iterator = iterator->next) - filenames << QString::fromUtf8((const char*)iterator->data); - g_slist_free(gtk_file_names); - if (selectedFilter) { - GtkFileFilter *gtkFilter = QGtk::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser); - *selectedFilter = filterMap.value(gtkFilter); - } - } - - QApplicationPrivate::leaveModal(&modal_widget); - gtk_widget_destroy (gtkFileChooser); - return filenames; -} - -QString QGtk::saveFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, - QString *selectedFilter, QFileDialog::Options options) -{ - QMap<GtkFileFilter *, QString> filterMap; - GtkWidget *gtkFileChooser = QGtk::gtk_file_chooser_dialog_new (qPrintable(caption), - NULL, - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, true, &filterMap); - - QWidget modal_widget; - modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); - modal_widget.setParent(parent, Qt::Window); - QApplicationPrivate::enterModal(&modal_widget); - - QString filename; - if (QGtk::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { - char *gtk_filename = QGtk::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser); - filename = QString::fromUtf8(gtk_filename); - g_free (gtk_filename); - if (selectedFilter) { - GtkFileFilter *gtkFilter = QGtk::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser); - *selectedFilter = filterMap.value(gtkFilter); - } - } - - QApplicationPrivate::leaveModal(&modal_widget); - gtk_widget_destroy (gtkFileChooser); - return filename; -} - -QIcon QGtk::getFilesystemIcon(const QFileInfo &info) -{ - QIcon icon; - if (QGtk::gnome_vfs_init && QGtk::gnome_icon_lookup_sync) { - QGtk::gnome_vfs_init(); - GtkIconTheme *theme = QGtk::gtk_icon_theme_get_default(); - QByteArray fileurl = QUrl::fromLocalFile(info.absoluteFilePath()).toEncoded(); - char * icon_name = QGtk::gnome_icon_lookup_sync(theme, - NULL, - fileurl.data(), - NULL, - GNOME_ICON_LOOKUP_FLAGS_NONE, - NULL); - QString iconName = QString::fromUtf8(icon_name); - g_free(icon_name); - if (iconName.startsWith(QLatin1Char('/'))) - return QIcon(iconName); - return QIcon::fromTheme(iconName); - } - return icon; -} - -QT_END_NAMESPACE - -#endif // !defined(QT_NO_STYLE_GTK) diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index bf2f68e..4c9541b 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -5656,102 +5656,103 @@ QIcon QCommonStyle::standardIconImplementation(StandardPixmap standardIcon, cons default: break; } - + } // if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) if (!icon.isNull()) return icon; #if defined(Q_WS_MAC) - OSType iconType = 0; - switch (standardIcon) { - case QStyle::SP_MessageBoxQuestion: - case QStyle::SP_MessageBoxInformation: - case QStyle::SP_MessageBoxWarning: - case QStyle::SP_MessageBoxCritical: - iconType = kGenericApplicationIcon; - break; - case SP_DesktopIcon: - iconType = kDesktopIcon; - break; - case SP_TrashIcon: - iconType = kTrashIcon; - break; - case SP_ComputerIcon: - iconType = kComputerIcon; - break; - case SP_DriveFDIcon: - iconType = kGenericFloppyIcon; - break; - case SP_DriveHDIcon: - iconType = kGenericHardDiskIcon; - break; - case SP_DriveCDIcon: - case SP_DriveDVDIcon: - iconType = kGenericCDROMIcon; - break; - case SP_DriveNetIcon: - iconType = kGenericNetworkIcon; - break; - case SP_DirOpenIcon: - iconType = kOpenFolderIcon; - break; - case SP_DirClosedIcon: - case SP_DirLinkIcon: - iconType = kGenericFolderIcon; - break; - case SP_FileLinkIcon: - case SP_FileIcon: - iconType = kGenericDocumentIcon; - break; - case SP_DirIcon: { - // A rather special case - QIcon closeIcon = QStyle::standardIcon(SP_DirClosedIcon, option, widget); - QIcon openIcon = QStyle::standardIcon(SP_DirOpenIcon, option, widget); - closeIcon.addPixmap(openIcon.pixmap(16, 16), QIcon::Normal, QIcon::On); - closeIcon.addPixmap(openIcon.pixmap(32, 32), QIcon::Normal, QIcon::On); - closeIcon.addPixmap(openIcon.pixmap(64, 64), QIcon::Normal, QIcon::On); - closeIcon.addPixmap(openIcon.pixmap(128, 128), QIcon::Normal, QIcon::On); - return closeIcon; - } - case SP_TitleBarNormalButton: - case SP_TitleBarCloseButton: { - QIcon titleBarIcon; - if (standardIcon == SP_TitleBarCloseButton) { - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-16.png")); - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); - } else { - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-16.png")); - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); + if (QApplication::desktopSettingsAware()) { + OSType iconType = 0; + switch (standardIcon) { + case QStyle::SP_MessageBoxQuestion: + case QStyle::SP_MessageBoxInformation: + case QStyle::SP_MessageBoxWarning: + case QStyle::SP_MessageBoxCritical: + iconType = kGenericApplicationIcon; + break; + case SP_DesktopIcon: + iconType = kDesktopIcon; + break; + case SP_TrashIcon: + iconType = kTrashIcon; + break; + case SP_ComputerIcon: + iconType = kComputerIcon; + break; + case SP_DriveFDIcon: + iconType = kGenericFloppyIcon; + break; + case SP_DriveHDIcon: + iconType = kGenericHardDiskIcon; + break; + case SP_DriveCDIcon: + case SP_DriveDVDIcon: + iconType = kGenericCDROMIcon; + break; + case SP_DriveNetIcon: + iconType = kGenericNetworkIcon; + break; + case SP_DirOpenIcon: + iconType = kOpenFolderIcon; + break; + case SP_DirClosedIcon: + case SP_DirLinkIcon: + iconType = kGenericFolderIcon; + break; + case SP_FileLinkIcon: + case SP_FileIcon: + iconType = kGenericDocumentIcon; + break; + case SP_DirIcon: { + // A rather special case + QIcon closeIcon = QStyle::standardIcon(SP_DirClosedIcon, option, widget); + QIcon openIcon = QStyle::standardIcon(SP_DirOpenIcon, option, widget); + closeIcon.addPixmap(openIcon.pixmap(16, 16), QIcon::Normal, QIcon::On); + closeIcon.addPixmap(openIcon.pixmap(32, 32), QIcon::Normal, QIcon::On); + closeIcon.addPixmap(openIcon.pixmap(64, 64), QIcon::Normal, QIcon::On); + closeIcon.addPixmap(openIcon.pixmap(128, 128), QIcon::Normal, QIcon::On); + return closeIcon; + } + case SP_TitleBarNormalButton: + case SP_TitleBarCloseButton: { + QIcon titleBarIcon; + if (standardIcon == SP_TitleBarCloseButton) { + titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-16.png")); + titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); + } else { + titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-16.png")); + titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); + } + return titleBarIcon; } - return titleBarIcon; - } - default: - break; - } - if (iconType != 0) { - QIcon retIcon; - IconRef icon; - IconRef overlayIcon = 0; - if (iconType != kGenericApplicationIcon) { - GetIconRef(kOnSystemDisk, kSystemIconsCreator, iconType, &icon); - } else { - FSRef fsRef; - ProcessSerialNumber psn = { 0, kCurrentProcess }; - GetProcessBundleLocation(&psn, &fsRef); - GetIconRefFromFileInfo(&fsRef, 0, 0, 0, 0, kIconServicesNormalUsageFlag, &icon, 0); - if (standardIcon == SP_MessageBoxCritical) { - overlayIcon = icon; - GetIconRef(kOnSystemDisk, kSystemIconsCreator, kAlertCautionIcon, &icon); - } - } - if (icon) { - qt_mac_constructQIconFromIconRef(icon, overlayIcon, &retIcon, standardIcon); - ReleaseIconRef(icon); - } - if (overlayIcon) - ReleaseIconRef(overlayIcon); - return retIcon; - } + default: + break; + } + if (iconType != 0) { + QIcon retIcon; + IconRef icon; + IconRef overlayIcon = 0; + if (iconType != kGenericApplicationIcon) { + GetIconRef(kOnSystemDisk, kSystemIconsCreator, iconType, &icon); + } else { + FSRef fsRef; + ProcessSerialNumber psn = { 0, kCurrentProcess }; + GetProcessBundleLocation(&psn, &fsRef); + GetIconRefFromFileInfo(&fsRef, 0, 0, 0, 0, kIconServicesNormalUsageFlag, &icon, 0); + if (standardIcon == SP_MessageBoxCritical) { + overlayIcon = icon; + GetIconRef(kOnSystemDisk, kSystemIconsCreator, kAlertCautionIcon, &icon); + } + } + if (icon) { + qt_mac_constructQIconFromIconRef(icon, overlayIcon, &retIcon, standardIcon); + ReleaseIconRef(icon); + } + if (overlayIcon) + ReleaseIconRef(overlayIcon); + return retIcon; + } + } // if (QApplication::desktopSettingsAware()) #endif // Q_WS_MAC - } switch (standardIcon) { #ifndef QT_NO_IMAGEFORMAT_PNG diff --git a/src/gui/styles/qcommonstyle_p.h b/src/gui/styles/qcommonstyle_p.h index a905601..6122f81 100644 --- a/src/gui/styles/qcommonstyle_p.h +++ b/src/gui/styles/qcommonstyle_p.h @@ -62,25 +62,6 @@ QT_BEGIN_NAMESPACE class QStringList; -#ifdef Q_WS_X11 -class QIconTheme -{ -public: - QIconTheme(QHash <int, QString> dirList, QStringList parents) : - _dirList(dirList), _parents(parents), _valid(true){ } - QIconTheme() : _valid(false){ } - - QHash <int, QString> dirList() {return _dirList;} - QStringList parents() {return _parents;} - bool isValid() {return _valid;} - -private: - QHash <int, QString> _dirList; - QStringList _parents; - bool _valid; -}; -#endif - // Private class class QCommonStylePrivate : public QStylePrivate { diff --git a/src/gui/styles/qgtkpainter.cpp b/src/gui/styles/qgtkpainter.cpp index 05c5804..aaa029a 100644 --- a/src/gui/styles/qgtkpainter.cpp +++ b/src/gui/styles/qgtkpainter.cpp @@ -108,41 +108,41 @@ QPixmap QGtkPainter::renderTheme(uchar *bdata, uchar *wdata, const QRect &rect) return; \ QRect pixmapRect(0, 0, rect.width(), rect.height()); \ { \ - GdkPixmap *pixmap = QGtk::gdk_pixmap_new((GdkDrawable*)(m_window->window), \ + GdkPixmap *pixmap = QGtkStylePrivate::gdk_pixmap_new((GdkDrawable*)(m_window->window), \ rect.width(), rect.height(), -1); \ if (!pixmap) \ return; \ - style = QGtk::gtk_style_attach (style, m_window->window); \ - QGtk::gdk_draw_rectangle(pixmap, m_alpha ? style->black_gc : *style->bg_gc, true, \ + style = QGtkStylePrivate::gtk_style_attach (style, m_window->window); \ + QGtkStylePrivate::gdk_draw_rectangle(pixmap, m_alpha ? style->black_gc : *style->bg_gc, true, \ 0, 0, rect.width(), rect.height()); \ draw_func; \ - GdkPixbuf *imgb = QGtk::gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, rect.width(), rect.height());\ + GdkPixbuf *imgb = QGtkStylePrivate::gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, rect.width(), rect.height());\ if (!imgb) \ return; \ - imgb = QGtk::gdk_pixbuf_get_from_drawable(imgb, pixmap, NULL, 0, 0, 0, 0, \ + imgb = QGtkStylePrivate::gdk_pixbuf_get_from_drawable(imgb, pixmap, NULL, 0, 0, 0, 0, \ rect.width(), rect.height()); \ - uchar* bdata = (uchar*)QGtk::gdk_pixbuf_get_pixels(imgb); \ + uchar* bdata = (uchar*)QGtkStylePrivate::gdk_pixbuf_get_pixels(imgb); \ if (m_alpha) { \ - QGtk::gdk_draw_rectangle(pixmap, style->white_gc, true, 0, 0, rect.width(), rect.height()); \ + QGtkStylePrivate::gdk_draw_rectangle(pixmap, style->white_gc, true, 0, 0, rect.width(), rect.height()); \ draw_func; \ - GdkPixbuf *imgw = QGtk::gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, rect. \ + GdkPixbuf *imgw = QGtkStylePrivate::gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, rect. \ width(), rect.height()); \ if (!imgw) \ return; \ - imgw = QGtk::gdk_pixbuf_get_from_drawable(imgw, pixmap, NULL, 0, 0, 0, 0, \ + imgw = QGtkStylePrivate::gdk_pixbuf_get_from_drawable(imgw, pixmap, NULL, 0, 0, 0, 0, \ rect.width(), rect.height()); \ - uchar* wdata = (uchar*)QGtk::gdk_pixbuf_get_pixels(imgw); \ + uchar* wdata = (uchar*)QGtkStylePrivate::gdk_pixbuf_get_pixels(imgw); \ cache = renderTheme(bdata, wdata, rect); \ - QGtk::gdk_pixbuf_unref(imgw); \ + QGtkStylePrivate::gdk_pixbuf_unref(imgw); \ } else { \ cache = renderTheme(bdata, 0, rect); \ } \ - QGtk::gdk_drawable_unref(pixmap); \ - QGtk::gdk_pixbuf_unref(imgb); \ + QGtkStylePrivate::gdk_drawable_unref(pixmap); \ + QGtkStylePrivate::gdk_pixbuf_unref(imgb); \ } QGtkPainter::QGtkPainter(QPainter *_painter) - : m_window(QGtk::gtkWidget(QLatin1String("GtkWindow"))) + : m_window(QGtkStylePrivate::gtkWidget(QLatin1String("GtkWindow"))) , m_painter(_painter) , m_alpha(true) , m_hflipped(false) @@ -185,18 +185,18 @@ GtkStyle* QGtkPainter::getStyle(GtkWidget *gtkWidget) QPixmap QGtkPainter::getIcon(const char* iconName, GtkIconSize size) { - GtkStyle *style = QGtk::gtkStyle(); - GtkIconSet* iconSet = QGtk::gtk_icon_factory_lookup_default (iconName); - GdkPixbuf* icon = QGtk::gtk_icon_set_render_icon(iconSet, + GtkStyle *style = QGtkStylePrivate::gtkStyle(); + GtkIconSet* iconSet = QGtkStylePrivate::gtk_icon_factory_lookup_default (iconName); + GdkPixbuf* icon = QGtkStylePrivate::gtk_icon_set_render_icon(iconSet, style, GTK_TEXT_DIR_LTR, GTK_STATE_NORMAL, size, NULL, "button"); - uchar* data = (uchar*)QGtk::gdk_pixbuf_get_pixels(icon); - int width = QGtk::gdk_pixbuf_get_width(icon); - int height = QGtk::gdk_pixbuf_get_height(icon); + uchar* data = (uchar*)QGtkStylePrivate::gdk_pixbuf_get_pixels(icon); + int width = QGtkStylePrivate::gdk_pixbuf_get_width(icon); + int height = QGtkStylePrivate::gdk_pixbuf_get_height(icon); QImage converted(width, height, QImage::Format_ARGB32); uchar* tdata = (uchar*)converted.bits(); @@ -208,7 +208,7 @@ QPixmap QGtkPainter::getIcon(const char* iconName, GtkIconSize size) tdata[index + QT_ALPHA] = data[index + GTK_ALPHA]; } - QGtk::gdk_pixbuf_unref(icon); + QGtkStylePrivate::gdk_pixbuf_unref(icon); // should we free iconset? return QPixmap::fromImage(converted); @@ -240,7 +240,7 @@ void QGtkPainter::paintBoxGap(GtkWidget *gtkWidget, const gchar* part, QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) + gapExtras; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_box_gap (style, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_box_gap (style, pixmap, state, shadow, @@ -305,7 +305,7 @@ void QGtkPainter::paintBox(GtkWidget *gtkWidget, const gchar* part, rect.size(), gtkWidget) + pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_box (style, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_box (style, pixmap, state, shadow, @@ -356,7 +356,7 @@ void QGtkPainter::paintHline(GtkWidget *gtkWidget, const gchar* part, QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), gtkWidget) + hLineExtras + pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_hline (style, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_hline (style, pixmap, state, NULL, @@ -383,7 +383,7 @@ void QGtkPainter::paintVline(GtkWidget *gtkWidget, const gchar* part, QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), gtkWidget) + vLineExtras +pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_vline (style, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_vline (style, pixmap, state, NULL, @@ -410,7 +410,7 @@ void QGtkPainter::paintExpander(GtkWidget *gtkWidget, QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), gtkWidget) + QString::number(expander_state) + pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_expander (style, pixmap, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_expander (style, pixmap, state, NULL, gtkWidget, part, rect.width()/2, @@ -433,7 +433,7 @@ void QGtkPainter::paintFocus(GtkWidget *gtkWidget, const gchar* part, QPixmap cache; QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), gtkWidget) + pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_focus (style, pixmap, state, NULL, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_focus (style, pixmap, state, NULL, gtkWidget, part, 0, 0, @@ -458,7 +458,7 @@ void QGtkPainter::paintResizeGrip(GtkWidget *gtkWidget, const gchar* part, QPixmap cache; QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) + pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_resize_grip (style, pixmap, state, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_resize_grip (style, pixmap, state, NULL, gtkWidget, part, edge, 0, 0, rect.width(), @@ -488,7 +488,7 @@ void QGtkPainter::paintArrow(GtkWidget *gtkWidget, const gchar* part, int xOffset = m_cliprect.isValid() ? arrowrect.x() - m_cliprect.x() : 0; int yOffset = m_cliprect.isValid() ? arrowrect.y() - m_cliprect.y() : 0; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_arrow (style, pixmap, state, shadow, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_arrow (style, pixmap, state, shadow, >kCliprect, gtkWidget, part, @@ -515,7 +515,7 @@ void QGtkPainter::paintHandle(GtkWidget *gtkWidget, const gchar* part, const QRe QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) + QString::number(orientation); if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_handle (style, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_handle (style, pixmap, state, shadow, @@ -543,7 +543,7 @@ void QGtkPainter::paintSlider(GtkWidget *gtkWidget, const gchar* part, const QRe QPixmap cache; QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) + pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_slider (style, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_slider (style, pixmap, state, shadow, @@ -574,7 +574,7 @@ void QGtkPainter::paintShadow(GtkWidget *gtkWidget, const gchar* part, QPixmap cache; QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) + pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_shadow(style, pixmap, state, shadow, NULL, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_shadow(style, pixmap, state, shadow, NULL, gtkWidget, part, 0, 0, rect.width(), rect.height())); if (m_usePixmapCache) QPixmapCache::insert(pixmapName, cache); @@ -593,7 +593,7 @@ void QGtkPainter::paintFlatBox(GtkWidget *gtkWidget, const gchar* part, QPixmap cache; QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) + pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_flat_box (style, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_flat_box (style, pixmap, state, shadow, @@ -622,7 +622,7 @@ void QGtkPainter::paintExtention(GtkWidget *gtkWidget, pixmapName += QString::number(gap_pos); if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_extension (style, pixmap, state, shadow, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_extension (style, pixmap, state, shadow, NULL, gtkWidget, (gchar*)part, 0, 0, rect.width(), @@ -651,7 +651,7 @@ void QGtkPainter::paintOption(GtkWidget *gtkWidget, const QRect &radiorect, int xOffset = m_cliprect.isValid() ? radiorect.x() - m_cliprect.x() : 0; int yOffset = m_cliprect.isValid() ? radiorect.y() - m_cliprect.y() : 0; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_option(style, pixmap, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_option(style, pixmap, state, shadow, >kCliprect, gtkWidget, @@ -683,7 +683,7 @@ void QGtkPainter::paintCheckbox(GtkWidget *gtkWidget, const QRect &checkrect, int xOffset = m_cliprect.isValid() ? checkrect.x() - m_cliprect.x() : 0; int yOffset = m_cliprect.isValid() ? checkrect.y() - m_cliprect.y() : 0; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { - DRAW_TO_CACHE(QGtk::gtk_paint_check (style, + DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_check (style, pixmap, state, shadow, diff --git a/src/gui/styles/qgtkpainter_p.h b/src/gui/styles/qgtkpainter_p.h index 0e8ffe2..cbc96c0 100644 --- a/src/gui/styles/qgtkpainter_p.h +++ b/src/gui/styles/qgtkpainter_p.h @@ -56,11 +56,11 @@ #include <QtCore/qglobal.h> #if !defined(QT_NO_STYLE_GTK) -#include "gtksymbols_p.h" #include <QtGui/QCleanlooksStyle> #include <QtGui/QPainter> #include <QtGui/QPalette> #include <QtGui/QFont> +#include <private/qgtkstyle_p.h> QT_BEGIN_NAMESPACE diff --git a/src/gui/styles/qgtkstyle.cpp b/src/gui/styles/qgtkstyle.cpp index ab0ab3a..1c78a47 100644 --- a/src/gui/styles/qgtkstyle.cpp +++ b/src/gui/styles/qgtkstyle.cpp @@ -69,28 +69,14 @@ #include <QtGui/QTreeView> #include <qpixmapcache.h> #undef signals // Collides with GTK stymbols -#include "qgtkpainter_p.h" -#include "qstylehelper_p.h" - +#include <private/qgtkpainter_p.h> +#include <private/qstylehelper_p.h> +#include <private/qgtkstyle_p.h> #include <private/qcleanlooksstyle_p.h> QT_BEGIN_NAMESPACE -typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption, const QString &dir, - const QString &filter, QString *selectedFilter, QFileDialog::Options options); -typedef QString (*_qt_filedialog_open_filename_hook) (QWidget * parent, const QString &caption, const QString &dir, - const QString &filter, QString *selectedFilter, QFileDialog::Options options); -typedef QString (*_qt_filedialog_save_filename_hook) (QWidget * parent, const QString &caption, const QString &dir, - const QString &filter, QString *selectedFilter, QFileDialog::Options options); -typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, const QString &dir, - QFileDialog::Options options); - -extern Q_GUI_EXPORT _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook; -extern Q_GUI_EXPORT _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook; -extern Q_GUI_EXPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook; -extern Q_GUI_EXPORT _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook; - static const char * const dock_widget_close_xpm[] = { "11 13 5 1", @@ -137,57 +123,18 @@ static const char * const dock_widget_restore_xpm[] = " " }; - -class QGtkStyleFilter : public QObject -{ -public: - QGtkStyleFilter() {} -private: - bool eventFilter(QObject *obj, QEvent *e); -}; - -bool QGtkStyleFilter::eventFilter(QObject *obj, QEvent *e) -{ - if (e->type() == QEvent::ApplicationPaletteChange) { - // Only do this the first time since this will also - // generate applicationPaletteChange events - if (!qt_app_palettes_hash() || qt_app_palettes_hash()->isEmpty()) { - QGtk::applyCustomPaletteHash(); - } - } - return QObject::eventFilter(obj, e); -} - -class QGtkStylePrivate : public QCleanlooksStylePrivate -{ - Q_DECLARE_PUBLIC(QGtkStyle) -public: - QGtkStylePrivate() - : QCleanlooksStylePrivate() - { - QGtk::initGtkWidgets(); - if (QGtk::isThemeAvailable()) - qApp->installEventFilter(&filter); - - } - QGtkStyleFilter filter; -}; - static const int groupBoxBottomMargin = 2; // space below the groupbox static const int groupBoxTitleMargin = 6; // space between contents and title static const int groupBoxTopMargin = 2; -// Get size of the arrow controls in a GtkSpinButton -static int spinboxArrowSize() +QString QGtkStyle::getGConfString(const QString &value, const QString &fallback) { - const int MIN_ARROW_WIDTH = 6; - GtkWidget *spinButton = QGtk::gtkWidget(QLS("GtkSpinButton")); - GtkStyle *style = spinButton->style; - gint size = QGtk::pango_font_description_get_size (style->font_desc); - gint arrow_size; - arrow_size = qMax(PANGO_PIXELS (size), MIN_ARROW_WIDTH) + style->xthickness; - arrow_size += arrow_size%2 + 1; - return arrow_size; + return QGtkStylePrivate::getGConfString(value, fallback); +} + +bool QGtkStyle::getGConfBool(const QString &key, bool fallback) +{ + return QGtkStylePrivate::getGConfBool(key, fallback); } static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50) @@ -233,8 +180,23 @@ static GdkColor fromQColor(const QColor &color) QGtkStyle::QGtkStyle() : QCleanlooksStyle(*new QGtkStylePrivate) { + Q_D(QGtkStyle); + d->init(); +} + +/*! + \internal + + Constructs a QGtkStyle object. +*/ +QGtkStyle::QGtkStyle(QGtkStylePrivate &dd) + : QCleanlooksStyle(dd) +{ + Q_D(QGtkStyle); + d->init(); } + /*! Destroys the QGtkStyle object. */ @@ -247,11 +209,13 @@ QGtkStyle::~QGtkStyle() */ QPalette QGtkStyle::standardPalette() const { + Q_D(const QGtkStyle); + QPalette palette = QCleanlooksStyle::standardPalette(); - if (QGtk::isThemeAvailable()) { - GtkStyle *style = QGtk::gtkStyle(); - GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton")); - GtkWidget *gtkEntry = QGtk::gtkWidget(QLS("GtkEntry")); + if (d->isThemeAvailable()) { + GtkStyle *style = d->gtkStyle(); + GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton")); + GtkWidget *gtkEntry = d->getTextColorWidget(); GdkColor gdkBg, gdkBase, gdkText, gdkForeground, gdkSbg, gdkSfg; QColor bg, base, text, fg, highlight, highlightText; @@ -281,12 +245,12 @@ QPalette QGtkStyle::standardPalette() const palette.setColor(QPalette::Base, base); QColor alternateRowColor = palette.base().color().lighter(93); // ref gtkstyle.c draw_flat_box - GtkWidget *gtkTreeView = QGtk::gtkWidget(QLS("GtkTreeView")); + GtkWidget *gtkTreeView = d->gtkWidget(QLS("GtkTreeView")); GdkColor *gtkAltBase = NULL; - QGtk::gtk_widget_style_get(gtkTreeView, "odd-row-color", >kAltBase, NULL); + d->gtk_widget_style_get(gtkTreeView, "odd-row-color", >kAltBase, NULL); if (gtkAltBase) { alternateRowColor = QColor(gtkAltBase->red>>8, gtkAltBase->green>>8, gtkAltBase->blue>>8); - QGtk::gdk_color_free(gtkAltBase); + d->gdk_color_free(gtkAltBase); } palette.setColor(QPalette::AlternateBase, alternateRowColor); @@ -306,7 +270,8 @@ QPalette QGtkStyle::standardPalette() const highlightText.setHsv(highlightText.hue(), 0, highlightText.value(), highlightText.alpha()); palette.setColor(QPalette::Disabled, QPalette::Highlight, highlight); palette.setColor(QPalette::Disabled, QPalette::HighlightedText, highlightText); - style = QGtk::gtk_rc_get_style_by_paths(QGtk::gtk_settings_get_default(), "gtk-tooltips", "GtkWindow", Q_GTK_TYPE_WINDOW); + style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow", + d->gtk_window_get_type()); if (style) { gdkText = style->fg[GTK_STATE_NORMAL]; text = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8); @@ -321,10 +286,12 @@ QPalette QGtkStyle::standardPalette() const */ void QGtkStyle::polish(QPalette &palette) { + Q_D(QGtkStyle); + // QCleanlooksStyle will alter the palette, hence we do // not want to polish the palette unless we are using it as // the fallback - if (!QGtk::isThemeAvailable()) + if (!d->isThemeAvailable()) QCleanlooksStyle::polish(palette); else palette = palette.resolve(standardPalette()); @@ -335,19 +302,21 @@ void QGtkStyle::polish(QPalette &palette) */ void QGtkStyle::polish(QApplication *app) { + Q_D(QGtkStyle); + QCleanlooksStyle::polish(app); // Custom fonts and palettes with QtConfig are intentionally // not supported as these should be entirely determined by // current Gtk settings - if (app->desktopSettingsAware() && QGtk::isThemeAvailable()) { + if (app->desktopSettingsAware() && d->isThemeAvailable()) { QApplicationPrivate::setSystemPalette(standardPalette()); - QApplicationPrivate::setSystemFont(QGtk::getThemeFont()); - QGtk::applyCustomPaletteHash(); - if (!QGtk::isKDE4Session()) { - qt_filedialog_open_filename_hook = &QGtk::openFilename; - qt_filedialog_save_filename_hook = &QGtk::saveFilename; - qt_filedialog_open_filenames_hook = &QGtk::openFilenames; - qt_filedialog_existing_directory_hook = &QGtk::openDirectory; + QApplicationPrivate::setSystemFont(d->getThemeFont()); + d->applyCustomPaletteHash(); + if (!d->isKDE4Session()) { + qt_filedialog_open_filename_hook = &QGtkStylePrivate::openFilename; + qt_filedialog_save_filename_hook = &QGtkStylePrivate::saveFilename; + qt_filedialog_open_filenames_hook = &QGtkStylePrivate::openFilenames; + qt_filedialog_existing_directory_hook = &QGtkStylePrivate::openDirectory; } } } @@ -357,11 +326,13 @@ void QGtkStyle::polish(QApplication *app) */ void QGtkStyle::unpolish(QApplication *app) { + Q_D(QGtkStyle); + QCleanlooksStyle::unpolish(app); QPixmapCache::clear(); - if (app->desktopSettingsAware() && QGtk::isThemeAvailable() - && !QGtk::isKDE4Session()) { + if (app->desktopSettingsAware() && d->isThemeAvailable() + && !d->isKDE4Session()) { qt_filedialog_open_filename_hook = 0; qt_filedialog_save_filename_hook = 0; qt_filedialog_open_filenames_hook = 0; @@ -375,8 +346,10 @@ void QGtkStyle::unpolish(QApplication *app) void QGtkStyle::polish(QWidget *widget) { + Q_D(QGtkStyle); + QCleanlooksStyle::polish(widget); - if (!QGtk::isThemeAvailable()) + if (!d->isThemeAvailable()) return; if (qobject_cast<QAbstractButton*>(widget) || qobject_cast<QToolButton*>(widget) @@ -404,21 +377,22 @@ void QGtkStyle::unpolish(QWidget *widget) \reimp */ int QGtkStyle::pixelMetric(PixelMetric metric, - const QStyleOption *option, const QWidget *widget) const { - if (!QGtk::isThemeAvailable()) + Q_D(const QGtkStyle); + + if (!d->isThemeAvailable()) return QCleanlooksStyle::pixelMetric(metric, option, widget); switch (metric) { case PM_DefaultFrameWidth: if (qobject_cast<const QFrame*>(widget)) { if (GtkStyle *style = - QGtk::gtk_rc_get_style_by_paths(QGtk::gtk_settings_get_default(), + d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "*.GtkScrolledWindow", "*.GtkScrolledWindow", - Q_GTK_TYPE_WINDOW)) + d->gtk_window_get_type())) return qMax(style->xthickness, style->ythickness); } return 2; @@ -439,16 +413,16 @@ int QGtkStyle::pixelMetric(PixelMetric metric, return 0; case PM_ButtonShiftHorizontal: { - GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton")); + GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton")); guint horizontal_shift; - QGtk::gtk_widget_style_get(gtkButton, "child-displacement-x", &horizontal_shift, NULL); + d->gtk_widget_style_get(gtkButton, "child-displacement-x", &horizontal_shift, NULL); return horizontal_shift; } case PM_ButtonShiftVertical: { - GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton")); + GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton")); guint vertical_shift; - QGtk::gtk_widget_style_get(gtkButton, "child-displacement-y", &vertical_shift, NULL); + d->gtk_widget_style_get(gtkButton, "child-displacement-y", &vertical_shift, NULL); return vertical_shift; } @@ -456,18 +430,18 @@ int QGtkStyle::pixelMetric(PixelMetric metric, return 0; case PM_MenuPanelWidth: { - GtkWidget *gtkMenu = QGtk::gtkWidget(QLS("GtkMenu")); + GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu")); guint horizontal_padding = 0; // horizontal-padding is used by Maemo to get thicker borders - if (!QGtk::gtk_check_version(2, 10, 0)) - QGtk::gtk_widget_style_get(gtkMenu, "horizontal-padding", &horizontal_padding, NULL); + if (!d->gtk_check_version(2, 10, 0)) + d->gtk_widget_style_get(gtkMenu, "horizontal-padding", &horizontal_padding, NULL); int padding = qMax<int>(gtkMenu->style->xthickness, horizontal_padding); return padding; } case PM_ButtonIconSize: { int retVal = 24; - GtkSettings *settings = QGtk::gtk_settings_get_default(); + GtkSettings *settings = d->gtk_settings_get_default(); gchararray icon_sizes; g_object_get(settings, "gtk-icon-sizes", &icon_sizes, NULL); QStringList values = QString(QLS(icon_sizes)).split(QLatin1Char(':')); @@ -513,9 +487,9 @@ int QGtkStyle::pixelMetric(PixelMetric metric, case PM_SliderThickness: case PM_SliderControlThickness: { - GtkWidget *gtkScale = QGtk::gtkWidget(QLS("GtkHScale")); + GtkWidget *gtkScale = d->gtkWidget(QLS("GtkHScale")); gint val; - QGtk::gtk_widget_style_get(gtkScale, "slider-width", &val, NULL); + d->gtk_widget_style_get(gtkScale, "slider-width", &val, NULL); if (metric == PM_SliderControlThickness) return val + 2*gtkScale->style->ythickness; return val; @@ -524,8 +498,8 @@ int QGtkStyle::pixelMetric(PixelMetric metric, case PM_ScrollBarExtent: { gint sliderLength; gint trough_border; - GtkWidget *hScrollbar = QGtk::gtkWidget(QLS("GtkHScrollbar")); - QGtk::gtk_widget_style_get(hScrollbar, + GtkWidget *hScrollbar = d->gtkWidget(QLS("GtkHScrollbar")); + d->gtk_widget_style_get(hScrollbar, "trough-border", &trough_border, "slider-width", &sliderLength, NULL); @@ -537,35 +511,35 @@ int QGtkStyle::pixelMetric(PixelMetric metric, case PM_SliderLength: gint val; - QGtk::gtk_widget_style_get(QGtk::gtkWidget(QLS("GtkHScale")), "slider-length", &val, NULL); + d->gtk_widget_style_get(d->gtkWidget(QLS("GtkHScale")), "slider-length", &val, NULL); return val; case PM_ExclusiveIndicatorWidth: case PM_ExclusiveIndicatorHeight: case PM_IndicatorWidth: case PM_IndicatorHeight: { - GtkWidget *gtkCheckButton = QGtk::gtkWidget(QLS("GtkCheckButton")); + GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton")); gint size, spacing; - QGtk::gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, "indicator-size", &size, NULL); + d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, "indicator-size", &size, NULL); return size + 2 * spacing; } case PM_MenuBarVMargin: { - GtkWidget *gtkMenubar = QGtk::gtkWidget(QLS("GtkMenuBar")); + GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar")); return qMax(0, gtkMenubar->style->ythickness); } case PM_ScrollView_ScrollBarSpacing: { gint spacing = 3; - GtkWidget *gtkScrollWindow = QGtk::gtkWidget(QLS("GtkScrolledWindow")); + GtkWidget *gtkScrollWindow = d->gtkWidget(QLS("GtkScrolledWindow")); Q_ASSERT(gtkScrollWindow); - QGtk::gtk_widget_style_get(gtkScrollWindow, "scrollbar-spacing", &spacing, NULL); + d->gtk_widget_style_get(gtkScrollWindow, "scrollbar-spacing", &spacing, NULL); return spacing; } case PM_SubMenuOverlap: { gint offset = 0; - GtkWidget *gtkMenu = QGtk::gtkWidget(QLS("GtkMenu")); - QGtk::gtk_widget_style_get(gtkMenu, "horizontal-offset", &offset, NULL); + GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu")); + d->gtk_widget_style_get(gtkMenu, "horizontal-offset", &offset, NULL); return offset; } default: @@ -580,7 +554,9 @@ int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidg QStyleHintReturn *returnData = 0) const { - if (!QGtk::isThemeAvailable()) + Q_D(const QGtkStyle); + + if (!d->isThemeAvailable()) return QCleanlooksStyle::styleHint(hint, option, widget, returnData); switch (hint) { @@ -588,7 +564,7 @@ int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidg case SH_DialogButtonLayout: { int ret = QDialogButtonBox::GnomeLayout; gboolean alternateOrder = 0; - GtkSettings *settings = QGtk::gtk_settings_get_default(); + GtkSettings *settings = d->gtk_settings_get_default(); g_object_get(settings, "gtk-alternative-button-order", &alternateOrder, NULL); if (alternateOrder) @@ -601,9 +577,9 @@ int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidg case SH_ToolButtonStyle: { - if (QGtk::isKDE4Session()) + if (d->isKDE4Session()) return QCleanlooksStyle::styleHint(hint, option, widget, returnData); - GtkWidget *gtkToolbar = QGtk::gtkWidget(QLS("GtkToolbar")); + GtkWidget *gtkToolbar = d->gtkWidget(QLS("GtkToolbar")); GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS; g_object_get(gtkToolbar, "toolbar-style", &toolbar_style, NULL); switch (toolbar_style) { @@ -626,9 +602,9 @@ int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidg return int(false); case SH_ComboBox_Popup: { - GtkWidget *gtkComboBox = QGtk::gtkWidget(QLS("GtkComboBox")); + GtkWidget *gtkComboBox = d->gtkWidget(QLS("GtkComboBox")); gboolean appears_as_list; - QGtk::gtk_widget_style_get((GtkWidget*)gtkComboBox, "appears-as-list", &appears_as_list, NULL); + d->gtk_widget_style_get((GtkWidget*)gtkComboBox, "appears-as-list", &appears_as_list, NULL); return appears_as_list ? 0 : 1; } @@ -640,7 +616,7 @@ int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidg case SH_Menu_SubMenuPopupDelay: { gint delay = 225; - GtkSettings *settings = QGtk::gtk_settings_get_default(); + GtkSettings *settings = d->gtk_settings_get_default(); g_object_get(settings, "gtk-menu-popup-delay", &delay, NULL); return delay; } @@ -649,15 +625,15 @@ int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidg gboolean scrollbars_within_bevel = false; if (widget && widget->isWindow()) scrollbars_within_bevel = true; - else if (!QGtk::gtk_check_version(2, 12, 0)) { - GtkWidget *gtkScrollWindow = QGtk::gtkWidget(QLS("GtkScrolledWindow")); - QGtk::gtk_widget_style_get(gtkScrollWindow, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL); + else if (!d->gtk_check_version(2, 12, 0)) { + GtkWidget *gtkScrollWindow = d->gtkWidget(QLS("GtkScrolledWindow")); + d->gtk_widget_style_get(gtkScrollWindow, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL); } return !scrollbars_within_bevel; } case SH_DialogButtonBox_ButtonsHaveIcons: { - static bool buttonsHaveIcons = QGtk::getGConfBool(QLS("/desktop/gnome/interface/buttons_have_icons")); + static bool buttonsHaveIcons = d->getGConfBool(QLS("/desktop/gnome/interface/buttons_have_icons")); return buttonsHaveIcons; } @@ -670,17 +646,18 @@ int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidg \reimp */ void QGtkStyle::drawPrimitive(PrimitiveElement element, - const QStyleOption *option, QPainter *painter, const QWidget *widget) const { - if (!QGtk::isThemeAvailable()) { + Q_D(const QGtkStyle); + + if (!d->isThemeAvailable()) { QCleanlooksStyle::drawPrimitive(element, option, painter, widget); return; } - GtkStyle* style = QGtk::gtkStyle(); + GtkStyle* style = d->gtkStyle(); QGtkPainter gtkPainter(painter); switch (element) { @@ -715,10 +692,10 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, else if (option->state & State_Raised) shadow_type = GTK_SHADOW_OUT; - GtkStyle *style = QGtk::gtk_rc_get_style_by_paths(QGtk::gtk_settings_get_default(), - "*.GtkScrolledWindow", "*.GtkScrolledWindow", Q_GTK_TYPE_WINDOW); + GtkStyle *style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), + "*.GtkScrolledWindow", "*.GtkScrolledWindow", d->gtk_window_get_type()); if (style) - gtkFramePainter.paintShadow(QGtk::gtkWidget(QLS("GtkFrame")), "viewport", pmRect, + gtkFramePainter.paintShadow(d->gtkWidget(QLS("GtkFrame")), "viewport", pmRect, option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, shadow_type, style); QPixmapCache::insert(pmKey, pixmap); @@ -745,8 +722,9 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, break; case PE_PanelTipLabel: { - GtkWidget *gtkWindow = QGtk::gtkWidget(QLS("GtkWindow")); // The Murrine Engine currently assumes a widget is passed - style = QGtk::gtk_rc_get_style_by_paths(QGtk::gtk_settings_get_default(), "gtk-tooltips", "GtkWindow", Q_GTK_TYPE_WINDOW); + GtkWidget *gtkWindow = d->gtkWidget(QLS("GtkWindow")); // The Murrine Engine currently assumes a widget is passed + style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow", + d->gtk_window_get_type()); gtkPainter.paintFlatBox(gtkWindow, "tooltip", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, style); } break; @@ -759,8 +737,8 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, break; } GtkShadowType shadow_type; - GtkWidget *gtkStatusbarFrame = QGtk::gtkWidget(QLS("GtkStatusbar.GtkFrame")); - QGtk::gtk_widget_style_get(gtkStatusbarFrame->parent, "shadow-type", &shadow_type, NULL); + GtkWidget *gtkStatusbarFrame = d->gtkWidget(QLS("GtkStatusbar.GtkFrame")); + d->gtk_widget_style_get(gtkStatusbarFrame->parent, "shadow-type", &shadow_type, NULL); gtkPainter.paintShadow(gtkStatusbarFrame, "frame", option->rect, GTK_STATE_NORMAL, shadow_type, gtkStatusbarFrame->style); } @@ -768,7 +746,7 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, case PE_IndicatorHeaderArrow: if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) { - GtkWidget *gtkTreeHeader = QGtk::gtkWidget(QLS("GtkTreeView.GtkButton")); + GtkWidget *gtkTreeHeader = d->gtkWidget(QLS("GtkTreeView.GtkButton")); GtkStateType state = gtkPainter.gtkState(option); style = gtkTreeHeader->style; GtkArrowType type = GTK_ARROW_UP; @@ -806,7 +784,7 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, rect.translate(2, 0); GtkExpanderStyle openState = GTK_EXPANDER_EXPANDED; GtkExpanderStyle closedState = GTK_EXPANDER_COLLAPSED; - GtkWidget *gtkTreeView = QGtk::gtkWidget(QLS("GtkTreeView")); + GtkWidget *gtkTreeView = d->gtkWidget(QLS("GtkTreeView")); GtkStateType state = GTK_STATE_NORMAL; if (!(option->state & State_Enabled)) @@ -842,7 +820,7 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, case PE_IndicatorToolBarSeparator: { const int margin = 6; - GtkWidget *gtkSeparator = QGtk::gtkWidget(QLS("GtkToolbar.GtkSeparatorToolItem")); + GtkWidget *gtkSeparator = d->gtkWidget(QLS("GtkToolbar.GtkSeparatorToolItem")); if (option->state & State_Horizontal) { const int offset = option->rect.width()/2; QRect rect = option->rect.adjusted(offset, margin, 0, -margin); @@ -862,9 +840,9 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, break; case PE_IndicatorToolBarHandle: { - GtkWidget *gtkToolbar = QGtk::gtkWidget(QLS("GtkToolbar")); + GtkWidget *gtkToolbar = d->gtkWidget(QLS("GtkToolbar")); GtkShadowType shadow_type; - QGtk::gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL); + d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL); //Note when the toolbar is horizontal, the handle is vertical painter->setClipRect(option->rect); gtkPainter.paintHandle(gtkToolbar, "toolbar", option->rect.adjusted(-1, -1 ,0 ,1), @@ -910,14 +888,14 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, GtkStateType state = gtkPainter.gtkState(option); QColor arrowColor = option->palette.buttonText().color(); - GtkWidget *gtkArrow = QGtk::gtkWidget(QLS("GtkArrow")); + GtkWidget *gtkArrow = d->gtkWidget(QLS("GtkArrow")); GdkColor color = fromQColor(arrowColor); - QGtk::gtk_widget_modify_fg (gtkArrow, state, &color); + d->gtk_widget_modify_fg (gtkArrow, state, &color); gtkPainter.paintArrow(gtkArrow, "button", arrowRect, type, state, shadow, FALSE, gtkArrow->style, QString::number(arrowColor.rgba(), 16)); // Passing NULL will revert the color change - QGtk::gtk_widget_modify_fg (gtkArrow, state, NULL); + d->gtk_widget_modify_fg (gtkArrow, state, NULL); } break; @@ -926,7 +904,7 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, break; case PE_PanelMenu: { - GtkWidget *gtkMenu = QGtk::gtkWidget(QLS("GtkMenu")); + GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu")); gtkPainter.setAlphaSupport(false); // Note, alpha disabled for performance reasons gtkPainter.paintBox(gtkMenu, "menu", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, gtkMenu->style, QString()); } @@ -938,7 +916,7 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, // This is only used by floating tool bars if (qobject_cast<const QToolBar *>(widget)) { - GtkWidget *gtkMenubar = QGtk::gtkWidget(QLS("GtkMenuBar")); + GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar")); gtkPainter.paintBox( gtkMenubar, "toolbar", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, style); gtkPainter.paintBox( gtkMenubar, "menu", option->rect, @@ -947,13 +925,13 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, break; case PE_FrameLineEdit: { - GtkWidget *gtkEntry = QGtk::gtkWidget(QLS("GtkEntry")); + GtkWidget *gtkEntry = d->gtkWidget(QLS("GtkEntry")); gboolean interior_focus; gint focus_line_width; QRect rect = option->rect; - QGtk::gtk_widget_style_get(gtkEntry, + d->gtk_widget_style_get(gtkEntry, "interior-focus", &interior_focus, "focus-line-width", &focus_line_width, NULL); @@ -981,7 +959,7 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, case PE_PanelLineEdit: if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(option)) { - GtkWidget *gtkEntry = QGtk::gtkWidget(QLS("GtkEntry")); + GtkWidget *gtkEntry = d->gtkWidget(QLS("GtkEntry")); if (panel->lineWidth > 0) proxy()->drawPrimitive(PE_FrameLineEdit, option, painter, widget); uint resolve_mask = option->palette.resolve(); @@ -999,13 +977,13 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, case PE_FrameTabWidget: if (const QStyleOptionTabWidgetFrame *frame = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option)) { - GtkWidget *gtkNotebook = QGtk::gtkWidget(QLS("GtkNotebook")); + GtkWidget *gtkNotebook = d->gtkWidget(QLS("GtkNotebook")); style = gtkPainter.getStyle(gtkNotebook); gtkPainter.setAlphaSupport(false); GtkShadowType shadow = GTK_SHADOW_OUT; GtkStateType state = GTK_STATE_NORMAL; // Only state supported by gtknotebook bool reverse = (option->direction == Qt::RightToLeft); - QGtk::gtk_widget_set_direction(gtkNotebook, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); + QGtkStylePrivate::gtk_widget_set_direction(gtkNotebook, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); if (const QStyleOptionTabWidgetFrameV2 *tabframe = qstyleoption_cast<const QStyleOptionTabWidgetFrameV2*>(option)) { GtkPositionType frameType = GTK_POS_TOP; QTabBar::Shape shape = frame->shape; @@ -1047,10 +1025,10 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, GtkStateType state = gtkPainter.gtkState(option); if (option->state & State_On || option->state & State_Sunken) state = GTK_STATE_ACTIVE; - GtkWidget *gtkButton = QGtk::gtkWidget(isTool ? QLS("GtkToolButton.GtkButton") : QLS("GtkButton")); + GtkWidget *gtkButton = d->gtkWidget(isTool ? QLS("GtkToolButton.GtkButton") : QLS("GtkButton")); gint focusWidth, focusPad; gboolean interiorFocus = false; - QGtk::gtk_widget_style_get (gtkButton, + d->gtk_widget_style_get (gtkButton, "focus-line-width", &focusWidth, "focus-padding", &focusPad, "interior-focus", &interiorFocus, NULL); @@ -1103,14 +1081,14 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, else shadow = GTK_SHADOW_OUT; - GtkWidget *gtkRadioButton = QGtk::gtkWidget(QLS("GtkRadioButton")); + GtkWidget *gtkRadioButton = d->gtkWidget(QLS("GtkRadioButton")); gint spacing; - QGtk::gtk_widget_style_get(gtkRadioButton, "indicator-spacing", &spacing, NULL); + d->gtk_widget_style_get(gtkRadioButton, "indicator-spacing", &spacing, NULL); QRect buttonRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing); gtkPainter.setClipRect(option->rect); // ### Note: Ubuntulooks breaks when the proper widget is passed // Murrine engine requires a widget not to get RGBA check - warnings - GtkWidget *gtkCheckButton = QGtk::gtkWidget(QLS("GtkCheckButton")); + GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton")); gtkPainter.paintOption(gtkCheckButton , buttonRect, state, shadow, gtkRadioButton->style, QLS("radiobutton")); } @@ -1132,12 +1110,12 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, int spacing; - GtkWidget *gtkCheckButton = QGtk::gtkWidget(QLS("GtkCheckButton")); + GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton")); // Some styles such as aero-clone assume they can paint in the spacing area gtkPainter.setClipRect(option->rect); - QGtk::gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, NULL); + d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, NULL); QRect checkRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing); @@ -1204,12 +1182,14 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom QPainter *painter, const QWidget *widget) const { - if (!QGtk::isThemeAvailable()) { + Q_D(const QGtkStyle); + + if (!d->isThemeAvailable()) { QCleanlooksStyle::drawComplexControl(control, option, painter, widget); return; } - GtkStyle* style = QGtk::gtkStyle(); + GtkStyle* style = d->gtkStyle(); QGtkPainter gtkPainter(painter); QColor button = option->palette.button().color(); QColor dark; @@ -1264,7 +1244,7 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) { // Draw prelight background - GtkWidget *gtkCheckButton = QGtk::gtkWidget(QLS("GtkCheckButton")); + GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton")); if (option->state & State_MouseOver) { QRect bgRect = textRect | checkBoxRect; @@ -1340,14 +1320,14 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom QString comboBoxPath = QLS(comboBox->editable ? "GtkComboBoxEntry" : "GtkComboBox"); // We use the gtk widget to position arrows and separators for us - GtkWidget *gtkCombo = QGtk::gtkWidget(comboBoxPath); + GtkWidget *gtkCombo = d->gtkWidget(comboBoxPath); GtkAllocation geometry = {0, 0, option->rect.width(), option->rect.height()}; - QGtk::gtk_widget_set_direction(gtkCombo, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); - QGtk::gtk_widget_size_allocate(gtkCombo, &geometry); + d->gtk_widget_set_direction(gtkCombo, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); + d->gtk_widget_size_allocate(gtkCombo, &geometry); QString buttonPath = comboBoxPath + QLS(".GtkToggleButton"); - GtkWidget *gtkToggleButton = QGtk::gtkWidget(buttonPath); - QGtk::gtk_widget_set_direction(gtkToggleButton, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); + GtkWidget *gtkToggleButton = d->gtkWidget(buttonPath); + d->gtk_widget_set_direction(gtkToggleButton, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); if (gtkToggleButton && (appears_as_list || comboBox->editable)) { if (focus) GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS); @@ -1355,8 +1335,8 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom if (comboBox->editable || appears_as_list) { GtkStateType frameState = (state == GTK_STATE_PRELIGHT) ? GTK_STATE_NORMAL : state; QString entryPath = QLS(comboBox->editable ? "GtkComboBoxEntry.GtkEntry" : "GtkComboBox.GtkFrame"); - GtkWidget *gtkEntry = QGtk::gtkWidget(entryPath); - QGtk::gtk_widget_set_direction(gtkEntry, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); + GtkWidget *gtkEntry = d->gtkWidget(entryPath); + d->gtk_widget_set_direction(gtkEntry, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); QRect frameRect = option->rect; if (reverse) @@ -1425,7 +1405,7 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom // Draw the separator between label and arrows QString vSeparatorPath = buttonPath + QLS(".GtkHBox.GtkVSeparator"); - if (GtkWidget *gtkVSeparator = QGtk::gtkWidget(vSeparatorPath)) { + if (GtkWidget *gtkVSeparator = d->gtkWidget(vSeparatorPath)) { QRect vLineRect(gtkVSeparator->allocation.x, gtkVSeparator->allocation.y, gtkVSeparator->allocation.width, @@ -1437,7 +1417,7 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom gint interiorFocus = true; - QGtk::gtk_widget_style_get(gtkToggleButton, "interior-focus", &interiorFocus, NULL); + d->gtk_widget_style_get(gtkToggleButton, "interior-focus", &interiorFocus, NULL); int xt = interiorFocus ? gtkToggleButton->style->xthickness : 0; int yt = interiorFocus ? gtkToggleButton->style->ythickness : 0; if (focus && ((option->state & State_KeyboardFocusChange) || styleHint(SH_UnderlineShortcut, option, widget))) @@ -1461,14 +1441,14 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom QString arrowPath = comboBoxPath + QLS(appears_as_list ? ".GtkToggleButton.GtkArrow" : ".GtkToggleButton.GtkHBox.GtkArrow"); - GtkWidget *gtkArrow = QGtk::gtkWidget(arrowPath); + GtkWidget *gtkArrow = d->gtkWidget(arrowPath); gfloat scale = 0.7; gint minSize = 15; QRect arrowWidgetRect; - if (gtkArrow && !QGtk::gtk_check_version(2, 12, 0)) { - QGtk::gtk_widget_style_get(gtkArrow, "arrow-scaling", &scale, NULL); - QGtk::gtk_widget_style_get(gtkCombo, "arrow-size", &minSize, NULL); + if (gtkArrow && !d->gtk_check_version(2, 12, 0)) { + d->gtk_widget_style_get(gtkArrow, "arrow-scaling", &scale, NULL); + d->gtk_widget_style_get(gtkCombo, "arrow-size", &minSize, NULL); } if (gtkArrow) { arrowWidgetRect = QRect(gtkArrow->allocation.x, gtkArrow->allocation.y, @@ -1486,9 +1466,9 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom if (sunken) { int xoff, yoff; - GtkWidget *gtkButton = QGtk::gtkWidget(comboBoxPath + QLS(".GtkToggleButton")); - QGtk::gtk_widget_style_get(gtkButton, "child-displacement-x", &xoff, NULL); - QGtk::gtk_widget_style_get(gtkButton, "child-displacement-y", &yoff, NULL); + GtkWidget *gtkButton = d->gtkWidget(comboBoxPath + QLS(".GtkToggleButton")); + d->gtk_widget_style_get(gtkButton, "child-displacement-x", &xoff, NULL); + d->gtk_widget_style_get(gtkButton, "child-displacement-y", &yoff, NULL); arrowRect = arrowRect.adjusted(xoff, yoff, xoff, yoff); } @@ -1559,7 +1539,7 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom QStyleOptionToolButton label = *toolbutton; label.state = bflags; - GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkToolButton.GtkButton")); + GtkWidget *gtkButton = d->gtkWidget(QLS("GtkToolButton.GtkButton")); QPalette pal = toolbutton->palette; if (option->state & State_Enabled && option->state & State_MouseOver && !(widget && widget->testAttribute(Qt::WA_SetPalette))) { @@ -1594,8 +1574,8 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom case CC_ScrollBar: if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) { - GtkWidget *gtkHScrollBar = QGtk::gtkWidget(QLS("GtkHScrollbar")); - GtkWidget *gtkVScrollBar = QGtk::gtkWidget(QLS("GtkVScrollbar")); + GtkWidget *gtkHScrollBar = d->gtkWidget(QLS("GtkHScrollbar")); + GtkWidget *gtkVScrollBar = d->gtkWidget(QLS("GtkVScrollbar")); // Fill background in case the scrollbar is partially transparent painter->fillRect(option->rect, option->palette.background()); @@ -1612,8 +1592,8 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom gboolean trough_side_details = false; gboolean stepper_size = 14; gint trough_border = 1; - if (!QGtk::gtk_check_version(2, 10, 0)) { - QGtk::gtk_widget_style_get((GtkWidget*)(scrollbarWidget), + if (!d->gtk_check_version(2, 10, 0)) { + d->gtk_widget_style_get((GtkWidget*)(scrollbarWidget), "trough-border", &trough_border, "trough-side-details", &trough_side_details, "trough-under-steppers", &trough_under_steppers, @@ -1637,12 +1617,12 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom fakePos = maximum; else if (scrollBar->sliderPosition > scrollBar->minimum) fakePos = maximum - 1; - GtkObject *adjustment = QGtk::gtk_adjustment_new(fakePos, 0, maximum, 0, 0, 0); + GtkObject *adjustment = d->gtk_adjustment_new(fakePos, 0, maximum, 0, 0, 0); if (horizontal) - QGtk::gtk_range_set_adjustment((GtkRange*)(gtkHScrollBar), (GtkAdjustment*)(adjustment)); + d->gtk_range_set_adjustment((GtkRange*)(gtkHScrollBar), (GtkAdjustment*)(adjustment)); else - QGtk::gtk_range_set_adjustment((GtkRange*)(gtkVScrollBar), (GtkAdjustment*)(adjustment)); + d->gtk_range_set_adjustment((GtkRange*)(gtkVScrollBar), (GtkAdjustment*)(adjustment)); if (scrollBar->subControls & SC_ScrollBarGroove) { GtkStateType state = GTK_STATE_ACTIVE; @@ -1739,7 +1719,7 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom case CC_SpinBox: if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { - GtkWidget *gtkSpinButton = QGtk::gtkWidget(QLS("GtkSpinButton")); + GtkWidget *gtkSpinButton = d->gtkWidget(QLS("GtkSpinButton")); bool isEnabled = (spinBox->state & State_Enabled); bool hover = isEnabled && (spinBox->state & State_MouseOver); bool sunken = (spinBox->state & State_Sunken); @@ -1854,7 +1834,7 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom } } else { - int size = spinboxArrowSize(); + int size = d->getSpinboxArrowSize(); int w = size / 2 - 1; w -= w % 2 - 1; // force odd int h = (w + 1)/2; @@ -1886,8 +1866,8 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom case CC_Slider: if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) { - GtkWidget *hScaleWidget = QGtk::gtkWidget(QLS("GtkHScale")); - GtkWidget *vScaleWidget = QGtk::gtkWidget(QLS("GtkVScale")); + GtkWidget *hScaleWidget = d->gtkWidget(QLS("GtkHScale")); + GtkWidget *vScaleWidget = d->gtkWidget(QLS("GtkVScale")); QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget); QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget); @@ -1911,16 +1891,16 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom style = scaleWidget->style; if ((option->subControls & SC_SliderGroove) && groove.isValid()) { - GtkObject *adjustment = QGtk::gtk_adjustment_new(slider->sliderPosition, + GtkObject *adjustment = d->gtk_adjustment_new(slider->sliderPosition, slider->minimum, slider->maximum, slider->singleStep, slider->singleStep, slider->pageStep); int outerSize; - QGtk::gtk_range_set_adjustment ((GtkRange*)(scaleWidget), (GtkAdjustment*)(adjustment)); - QGtk::gtk_range_set_inverted((GtkRange*)(scaleWidget), !horizontal); - QGtk::gtk_widget_style_get(scaleWidget, "trough-border", &outerSize, NULL); + d->gtk_range_set_adjustment ((GtkRange*)(scaleWidget), (GtkAdjustment*)(adjustment)); + d->gtk_range_set_inverted((GtkRange*)(scaleWidget), !horizontal); + d->gtk_widget_style_get(scaleWidget, "trough-border", &outerSize, NULL); outerSize++; GtkStateType state = gtkPainter.gtkState(option); @@ -1929,8 +1909,8 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom -focusFrameMargin, -outerSize - focusFrameMargin); gboolean trough_side_details = false; // Indicates if the upper or lower scale background differs - if (!QGtk::gtk_check_version(2, 10, 0)) - QGtk::gtk_widget_style_get((GtkWidget*)(scaleWidget), "trough-side-details", &trough_side_details, NULL); + if (!d->gtk_check_version(2, 10, 0)) + d->gtk_widget_style_get((GtkWidget*)(scaleWidget), "trough-side-details", &trough_side_details, NULL); if (!trough_side_details) { gtkPainter.paintBox( scaleWidget, "trough", grooveRect, state, @@ -2064,18 +2044,20 @@ void QGtkStyle::drawControl(ControlElement element, QPainter *painter, const QWidget *widget) const { - if (!QGtk::isThemeAvailable()) { + Q_D(const QGtkStyle); + + if (!d->isThemeAvailable()) { QCleanlooksStyle::drawControl(element, option, painter, widget); return; } - GtkStyle* style = QGtk::gtkStyle(); + GtkStyle* style = d->gtkStyle(); QGtkPainter gtkPainter(painter); switch (element) { case CE_ProgressBarLabel: if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { - GtkWidget *gtkProgressBar = QGtk::gtkWidget(QLS("GtkProgressBar")); + GtkWidget *gtkProgressBar = d->gtkWidget(QLS("GtkProgressBar")); if (!gtkProgressBar) return; @@ -2178,7 +2160,7 @@ void QGtkStyle::drawControl(ControlElement element, if (button->features & QStyleOptionButton::HasMenu) ir = ir.adjusted(0, 0, -pixelMetric(PM_MenuButtonIndicator, button, widget), 0); - GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton")); + GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton")); QPalette pal = button->palette; int labelState = GTK_STATE_INSENSITIVE; if (option->state & State_Enabled) @@ -2199,7 +2181,7 @@ void QGtkStyle::drawControl(ControlElement element, bool isRadio = (element == CE_RadioButton); // Draw prelight background - GtkWidget *gtkRadioButton = QGtk::gtkWidget(QLS("GtkRadioButton")); + GtkWidget *gtkRadioButton = d->gtkWidget(QLS("GtkRadioButton")); if (option->state & State_MouseOver) { gtkPainter.paintFlatBox(gtkRadioButton, "checkbutton", option->rect, @@ -2267,7 +2249,7 @@ void QGtkStyle::drawControl(ControlElement element, } if (!cb->currentText.isEmpty() && !cb->editable) { - GtkWidget *gtkCombo = QGtk::gtkWidget(QLS("GtkComboBox")); + GtkWidget *gtkCombo = d->gtkWidget(QLS("GtkComboBox")); QPalette pal = cb->palette; int labelState = GTK_STATE_INSENSITIVE; @@ -2344,9 +2326,9 @@ void QGtkStyle::drawControl(ControlElement element, // Draws the header in tables. if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) { Q_UNUSED(header); - GtkWidget *gtkTreeView = QGtk::gtkWidget(QLS("GtkTreeView")); + GtkWidget *gtkTreeView = d->gtkWidget(QLS("GtkTreeView")); // Get the middle column - GtkTreeViewColumn *column = QGtk::gtk_tree_view_get_column((GtkTreeView*)gtkTreeView, 1); + GtkTreeViewColumn *column = d->gtk_tree_view_get_column((GtkTreeView*)gtkTreeView, 1); Q_ASSERT(column); GtkWidget *gtkTreeHeader = column->button; @@ -2365,7 +2347,7 @@ void QGtkStyle::drawControl(ControlElement element, #ifndef QT_NO_SIZEGRIP case CE_SizeGrip: { - GtkWidget *gtkStatusbar = QGtk::gtkWidget(QLS("GtkStatusbar.GtkFrame")); + GtkWidget *gtkStatusbar = d->gtkWidget(QLS("GtkStatusbar.GtkFrame")); QRect gripRect = option->rect.adjusted(0, 0, -gtkStatusbar->style->xthickness, -gtkStatusbar->style->ythickness); gtkPainter.paintResizeGrip( gtkStatusbar, "statusbar", gripRect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, QApplication::isRightToLeft() ? @@ -2377,7 +2359,7 @@ void QGtkStyle::drawControl(ControlElement element, #endif // QT_NO_SIZEGRIP case CE_MenuBarEmptyArea: { - GtkWidget *gtkMenubar = QGtk::gtkWidget(QLS("GtkMenuBar")); + GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar")); GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8)); if (widget) { // See CE_MenuBarItem @@ -2387,7 +2369,7 @@ void QGtkStyle::drawControl(ControlElement element, QPainter pmPainter(&pixmap); QGtkPainter gtkMenuBarPainter(&pmPainter); GtkShadowType shadow_type; - QGtk::gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL); + d->gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL); gtkMenuBarPainter.paintBox( gtkMenubar, "menubar", menuBarRect, GTK_STATE_NORMAL, shadow_type, gtkMenubar->style); pmPainter.end(); @@ -2400,8 +2382,8 @@ void QGtkStyle::drawControl(ControlElement element, painter->save(); if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { - GtkWidget *gtkMenubarItem = QGtk::gtkWidget(QLS("GtkMenuBar.GtkMenuItem")); - GtkWidget *gtkMenubar = QGtk::gtkWidget(QLS("GtkMenuBar")); + GtkWidget *gtkMenubarItem = d->gtkWidget(QLS("GtkMenuBar.GtkMenuItem")); + GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar")); style = gtkMenubarItem->style; @@ -2416,7 +2398,7 @@ void QGtkStyle::drawControl(ControlElement element, QPainter pmPainter(&pixmap); QGtkPainter menubarPainter(&pmPainter); GtkShadowType shadow_type; - QGtk::gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL); + d->gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL); GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8)); menubarPainter.paintBox(gtkMenubar, "menubar", menuBarRect, @@ -2440,7 +2422,7 @@ void QGtkStyle::drawControl(ControlElement element, if (act) { GtkShadowType shadowType = GTK_SHADOW_NONE; - QGtk::gtk_widget_style_get (gtkMenubarItem, "selected-shadow-type", &shadowType, NULL); + d->gtk_widget_style_get (gtkMenubarItem, "selected-shadow-type", &shadowType, NULL); gtkPainter.paintBox(gtkMenubarItem, "menuitem", option->rect.adjusted(0, 0, 0, 3), GTK_STATE_PRELIGHT, shadowType, gtkMenubarItem->style); //draw text @@ -2457,7 +2439,7 @@ void QGtkStyle::drawControl(ControlElement element, break; case CE_Splitter: { - GtkWidget *gtkWindow = QGtk::gtkWidget(QLS("GtkWindow")); // The Murrine Engine currently assumes a widget is passed + GtkWidget *gtkWindow = d->gtkWidget(QLS("GtkWindow")); // The Murrine Engine currently assumes a widget is passed gtkPainter.paintHandle(gtkWindow, "splitter", option->rect, gtkPainter.gtkState(option), GTK_SHADOW_NONE, !(option->state & State_Horizontal) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, style); @@ -2477,9 +2459,9 @@ void QGtkStyle::drawControl(ControlElement element, if (toolbar->positionWithinLine != QStyleOptionToolBar::End) rect.adjust(0, 0, 1, 0); - GtkWidget *gtkToolbar = QGtk::gtkWidget(QLS("GtkToolbar")); + GtkWidget *gtkToolbar = d->gtkWidget(QLS("GtkToolbar")); GtkShadowType shadow_type = GTK_SHADOW_NONE; - QGtk::gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL); + d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL); gtkPainter.paintBox( gtkToolbar, "toolbar", rect, GTK_STATE_NORMAL, shadow_type, gtkToolbar->style); } @@ -2496,22 +2478,22 @@ void QGtkStyle::drawControl(ControlElement element, const int windowsItemHMargin = 3; // menu item hor text margin const int windowsItemVMargin = 26; // menu item ver text margin const int windowsRightBorder = 15; // right border on windows - GtkWidget *gtkMenu = QGtk::gtkWidget(QLS("GtkMenu")); - GtkWidget *gtkMenuItem = menuItem->checked ? QGtk::gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")) : - QGtk::gtkWidget(QLS("GtkMenu.GtkMenuItem")); + GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu")); + GtkWidget *gtkMenuItem = menuItem->checked ? d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")) : + d->gtkWidget(QLS("GtkMenu.GtkMenuItem")); style = gtkPainter.getStyle(gtkMenuItem); QColor borderColor = option->palette.background().color().darker(160); QColor shadow = option->palette.dark().color(); if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) { - GtkWidget *gtkMenuSeparator = QGtk::gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem")); + GtkWidget *gtkMenuSeparator = d->gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem")); painter->setPen(shadow.lighter(106)); gboolean wide_separators = 0; gint separator_height = 0; guint horizontal_padding = 3; - if (!QGtk::gtk_check_version(2, 10, 0)) { - QGtk::gtk_widget_style_get(gtkMenuSeparator, + if (!d->gtk_check_version(2, 10, 0)) { + d->gtk_widget_style_get(gtkMenuSeparator, "wide-separators", &wide_separators, "separator-height", &separator_height, "horizontal-padding", &horizontal_padding, @@ -2545,7 +2527,7 @@ void QGtkStyle::drawControl(ControlElement element, bool ignoreCheckMark = false; gint checkSize; - QGtk::gtk_widget_style_get(QGtk::gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")), "indicator-size", &checkSize, NULL); + d->gtk_widget_style_get(d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")), "indicator-size", &checkSize, NULL); int checkcol = qMax(menuItem->maxIconWidth, qMax(20, checkSize)); @@ -2732,7 +2714,7 @@ void QGtkStyle::drawControl(ControlElement element, // "arrow-scaling" is actually hardcoded and fails on hardy (see gtk+-2.12/gtkmenuitem.c) // though the current documentation states otherwise int horizontal_padding; - QGtk::gtk_widget_style_get(gtkMenuItem, "horizontal-padding", &horizontal_padding, NULL); + d->gtk_widget_style_get(gtkMenuItem, "horizontal-padding", &horizontal_padding, NULL); const int dim = static_cast<int>(arrow_size * arrow_scaling); int xpos = menuItem->rect.left() + menuItem->rect.width() - horizontal_padding - dim; @@ -2750,12 +2732,12 @@ void QGtkStyle::drawControl(ControlElement element, case CE_PushButton: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) { - GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton")); + GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton")); proxy()->drawControl(CE_PushButtonBevel, btn, painter, widget); QStyleOptionButton subopt = *btn; subopt.rect = subElementRect(SE_PushButtonContents, btn, widget); gint interiorFocus = true; - QGtk::gtk_widget_style_get(gtkButton, "interior-focus", &interiorFocus, NULL); + d->gtk_widget_style_get(gtkButton, "interior-focus", &interiorFocus, NULL); int xt = interiorFocus ? gtkButton->style->xthickness : 0; int yt = interiorFocus ? gtkButton->style->ythickness : 0; @@ -2776,7 +2758,7 @@ void QGtkStyle::drawControl(ControlElement element, case CE_TabBarTabShape: if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) { - GtkWidget *gtkNotebook = QGtk::gtkWidget(QLS("GtkNotebook")); + GtkWidget *gtkNotebook = d->gtkWidget(QLS("GtkNotebook")); style = gtkPainter.getStyle(gtkNotebook); QRect rect = option->rect; @@ -2843,7 +2825,7 @@ void QGtkStyle::drawControl(ControlElement element, case CE_ProgressBarGroove: if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { Q_UNUSED(bar); - GtkWidget *gtkProgressBar = QGtk::gtkWidget(QLS("GtkProgressBar")); + GtkWidget *gtkProgressBar = d->gtkWidget(QLS("GtkProgressBar")); GtkStateType state = gtkPainter.gtkState(option); gtkPainter.paintBox( gtkProgressBar, "trough", option->rect, state, GTK_SHADOW_IN, gtkProgressBar->style); } @@ -2853,7 +2835,7 @@ void QGtkStyle::drawControl(ControlElement element, case CE_ProgressBarContents: if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { GtkStateType state = option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE; - GtkWidget *gtkProgressBar = QGtk::gtkWidget(QLS("GtkProgressBar")); + GtkWidget *gtkProgressBar = d->gtkWidget(QLS("GtkProgressBar")); style = gtkProgressBar->style; gtkPainter.paintBox( gtkProgressBar, "trough", option->rect, state, GTK_SHADOW_IN, style); int xt = style->xthickness; @@ -2901,8 +2883,8 @@ void QGtkStyle::drawControl(ControlElement element, else if (bar->progress > bar->minimum) fakePos = maximum - 1; - GtkObject *adjustment = QGtk::gtk_adjustment_new(fakePos, 0, maximum, 0, 0, 0); - QGtk::gtk_progress_set_adjustment((GtkProgress*)(gtkProgressBar), (GtkAdjustment*)(adjustment)); + GtkObject *adjustment = d->gtk_adjustment_new(fakePos, 0, maximum, 0, 0, 0); + d->gtk_progress_set_adjustment((GtkProgress*)(gtkProgressBar), (GtkAdjustment*)(adjustment)); QRect progressBar; @@ -2942,8 +2924,10 @@ void QGtkStyle::drawControl(ControlElement element, QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option, SubControl subControl, const QWidget *widget) const { + Q_D(const QGtkStyle); + QRect rect = QWindowsStyle::subControlRect(control, option, subControl, widget); - if (!QGtk::isThemeAvailable()) + if (!d->isThemeAvailable()) return QCleanlooksStyle::subControlRect(control, option, subControl, widget); switch (control) { @@ -3009,7 +2993,7 @@ QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComple case CC_SpinBox: if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { - GtkWidget *gtkSpinButton = QGtk::gtkWidget(QLS("GtkSpinButton")); + GtkWidget *gtkSpinButton = d->gtkWidget(QLS("GtkSpinButton")); int center = spinbox->rect.height() / 2; int xt = spinbox->frame ? gtkSpinButton->style->xthickness : 0; int yt = spinbox->frame ? gtkSpinButton->style->ythickness : 0; @@ -3017,7 +3001,7 @@ QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComple QSize bs; bs.setHeight(qMax(8, spinbox->rect.height()/2 - y)); - bs.setWidth(spinboxArrowSize()); + bs.setWidth(d->getSpinboxArrowSize()); int x, lx, rx; x = spinbox->rect.width() - y - bs.width() + 2; lx = xt; @@ -3063,17 +3047,17 @@ QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComple if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { // We employ the gtk widget to position arrows and separators for us QString comboBoxPath = box->editable ? QLS("GtkComboBoxEntry") : QLS("GtkComboBox"); - GtkWidget *gtkCombo = QGtk::gtkWidget(comboBoxPath); - QGtk::gtk_widget_set_direction(gtkCombo, (option->direction == Qt::RightToLeft) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); + GtkWidget *gtkCombo = d->gtkWidget(comboBoxPath); + d->gtk_widget_set_direction(gtkCombo, (option->direction == Qt::RightToLeft) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); GtkAllocation geometry = {0, 0, qMax(0, option->rect.width()), qMax(0, option->rect.height())}; - QGtk::gtk_widget_size_allocate(gtkCombo, &geometry); + d->gtk_widget_size_allocate(gtkCombo, &geometry); int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, option, widget); QString arrowPath = comboBoxPath + QLS(".GtkToggleButton"); if (!box->editable && !appears_as_list) arrowPath += QLS(".GtkHBox.GtkArrow"); - GtkWidget *arrowWidget = QGtk::gtkWidget(arrowPath); + GtkWidget *arrowWidget = d->gtkWidget(arrowPath); if (!arrowWidget) return QCleanlooksStyle::subControlRect(control, option, subControl, widget); @@ -3118,19 +3102,19 @@ QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComple \reimp */ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option, - const QSize &size, const QWidget *widget) const { + Q_D(const QGtkStyle); QSize newSize = QCleanlooksStyle::sizeFromContents(type, option, size, widget); - if (!QGtk::isThemeAvailable()) + if (!d->isThemeAvailable()) return newSize; switch (type) { case CT_ToolButton: if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { - GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkToolButton.GtkButton")); + GtkWidget *gtkButton = d->gtkWidget(QLS("GtkToolButton.GtkButton")); newSize = size + QSize(2 * gtkButton->style->xthickness, 1 + 2 * gtkButton->style->ythickness); if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) { QSize minSize(0, 25); @@ -3138,7 +3122,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option, minSize = toolbutton->iconSize + QSize(12, 12); newSize = newSize.expandedTo(minSize); } - + if (toolbutton->features & QStyleOptionToolButton::HasMenu) newSize += QSize(6, 0); } @@ -3149,10 +3133,10 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option, int textMargin = 8; if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) { - GtkWidget *gtkMenuSeparator = QGtk::gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem")); + GtkWidget *gtkMenuSeparator = d->gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem")); gboolean wide_separators; gint separator_height; - QGtk::gtk_widget_style_get(gtkMenuSeparator, + d->gtk_widget_style_get(gtkMenuSeparator, "wide-separators", &wide_separators, "separator-height", &separator_height, NULL); @@ -3161,14 +3145,14 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option, break; } - GtkWidget *gtkMenuItem = QGtk::gtkWidget(QLS("GtkMenu.GtkMenuItem")); + GtkWidget *gtkMenuItem = d->gtkWidget(QLS("GtkMenu.GtkMenuItem")); GtkStyle* style = gtkMenuItem->style; newSize += QSize(textMargin + style->xthickness - 2, style->ythickness - 4); // Cleanlooks assumes a check column of 20 pixels so we need to // expand it a bit gint checkSize; - QGtk::gtk_widget_style_get(QGtk::gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")), "indicator-size", &checkSize, NULL); + d->gtk_widget_style_get(d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")), "indicator-size", &checkSize, NULL); newSize.setHeight(qMax(newSize.height(), checkSize + 2)); newSize.setWidth(newSize.width() + qMax(0, checkSize - 20)); } @@ -3183,22 +3167,22 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option, case CT_SpinBox: // QSpinBox does some nasty things that depends on CT_LineEdit - newSize = size + QSize(0, -QGtk::gtkWidget(QLS("GtkSpinButton"))->style->ythickness * 2 + 2); + newSize = size + QSize(0, -d->gtkWidget(QLS("GtkSpinButton"))->style->ythickness * 2 + 2); break; case CT_PushButton: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) { - GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton")); + GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton")); gint focusPadding, focusWidth; - QGtk::gtk_widget_style_get(gtkButton, "focus-padding", &focusPadding, NULL); - QGtk::gtk_widget_style_get(gtkButton, "focus-line-width", &focusWidth, NULL); + d->gtk_widget_style_get(gtkButton, "focus-padding", &focusPadding, NULL); + d->gtk_widget_style_get(gtkButton, "focus-line-width", &focusWidth, NULL); newSize = size; newSize += QSize(2*gtkButton->style->xthickness + 4, 2*gtkButton->style->ythickness); newSize += QSize(2*(focusWidth + focusPadding + 2), 2*(focusWidth + focusPadding)); - GtkWidget *gtkButtonBox = QGtk::gtkWidget(QLS("GtkHButtonBox")); + GtkWidget *gtkButtonBox = d->gtkWidget(QLS("GtkHButtonBox")); gint minWidth = 85, minHeight = 0; - QGtk::gtk_widget_style_get(gtkButtonBox, "child-min-width", &minWidth, + d->gtk_widget_style_get(gtkButtonBox, "child-min-width", &minWidth, "child-min-height", &minHeight, NULL); if (!btn->text.isEmpty() && newSize.width() < minWidth) newSize.setWidth(minWidth); @@ -3209,7 +3193,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option, break; case CT_Slider: { - GtkWidget *gtkSlider = QGtk::gtkWidget(QLS("GtkHScale")); + GtkWidget *gtkSlider = d->gtkWidget(QLS("GtkHScale")); newSize = size + QSize(2*gtkSlider->style->xthickness, 2*gtkSlider->style->ythickness); } break; @@ -3219,7 +3203,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option, break; case CT_LineEdit: { - GtkWidget *gtkEntry = QGtk::gtkWidget(QLS("GtkEntry")); + GtkWidget *gtkEntry = d->gtkWidget(QLS("GtkEntry")); newSize = size + QSize(2*gtkEntry->style->xthickness, 2*gtkEntry->style->ythickness); } break; @@ -3230,7 +3214,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option, case CT_ComboBox: if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { - GtkWidget *gtkCombo = QGtk::gtkWidget(QLS("GtkComboBox")); + GtkWidget *gtkCombo = d->gtkWidget(QLS("GtkComboBox")); QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, combo, SC_ComboBoxArrow, widget); newSize = size + QSize(12 + arrowButtonRect.width() + 2*gtkCombo->style->xthickness, 4 + 2*gtkCombo->style->ythickness); @@ -3263,7 +3247,9 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option, QPixmap QGtkStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option, const QWidget *widget) const { - if (!QGtk::isThemeAvailable()) + Q_D(const QGtkStyle); + + if (!d->isThemeAvailable()) return QCleanlooksStyle::standardPixmap(sp, option, widget); QPixmap pixmap; @@ -3330,7 +3316,9 @@ QIcon QGtkStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const { - if (!QGtk::isThemeAvailable()) + Q_D(const QGtkStyle); + + if (!d->isThemeAvailable()) return QCleanlooksStyle::standardIconImplementation(standardIcon, option, widget); switch (standardIcon) { case SP_DialogDiscardButton: diff --git a/src/gui/styles/qgtkstyle.h b/src/gui/styles/qgtkstyle.h index 20c2b52..5c3bad1 100644 --- a/src/gui/styles/qgtkstyle.h +++ b/src/gui/styles/qgtkstyle.h @@ -45,6 +45,7 @@ #include <QtGui/QCleanlooksStyle> #include <QtGui/QPalette> #include <QtGui/QFont> +#include <QtGui/QFileDialog> QT_BEGIN_HEADER @@ -64,6 +65,8 @@ class Q_GUI_EXPORT QGtkStyle : public QCleanlooksStyle public: QGtkStyle(); + QGtkStyle(QGtkStylePrivate &dd); + ~QGtkStyle(); QPalette standardPalette() const; @@ -107,12 +110,15 @@ public: void unpolish(QWidget *widget); void unpolish(QApplication *app); + static bool getGConfBool(const QString &key, bool fallback = 0); + static QString getGConfString(const QString &key, const QString &fallback = QString()); + + protected Q_SLOTS: QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget = 0) const; }; - #endif //!defined(QT_NO_STYLE_QGTK) QT_END_NAMESPACE diff --git a/src/gui/styles/qgtkstyle_p.cpp b/src/gui/styles/qgtkstyle_p.cpp new file mode 100644 index 0000000..7119a4f --- /dev/null +++ b/src/gui/styles/qgtkstyle_p.cpp @@ -0,0 +1,1069 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgtkstyle_p.h" + +// This file is responsible for resolving all GTK functions we use +// dynamically. This is done to avoid link-time dependancy on GTK +// as well as crashes occurring due to usage of the GTK_QT engines +// +// Additionally we create a map of common GTK widgets that we can pass +// to the GTK theme engine as many engines resort to querying the +// actual widget pointers for details that are not covered by the +// state flags + +#include <QtCore/qglobal.h> +#if !defined(QT_NO_STYLE_GTK) + +#include <QtCore/QEvent> +#include <QtCore/QFile> +#include <QtCore/QStringList> +#include <QtCore/QTextStream> +#include <QtCore/QHash> +#include <QtCore/QUrl> +#include <QtCore/QLibrary> + +#include <private/qapplication_p.h> +#include <private/qiconloader_p.h> + +#include <QtGui/QMenu> +#include <QtGui/QStyle> +#include <QtGui/QApplication> +#include <QtGui/QPixmapCache> +#include <QtGui/QStatusBar> +#include <QtGui/QMenuBar> +#include <QtGui/QToolBar> +#include <QtGui/QToolButton> +#include <QtGui/QX11Info> + +#include <private/qt_x11_p.h> + +QT_BEGIN_NAMESPACE + +static bool displayDepth = -1; +Q_GLOBAL_STATIC(QGtkStyleUpdateScheduler, styleScheduler) + +Ptr_gtk_container_forall QGtkStylePrivate::gtk_container_forall = 0; +Ptr_gtk_init QGtkStylePrivate::gtk_init = 0; +Ptr_gtk_style_attach QGtkStylePrivate::gtk_style_attach = 0; +Ptr_gtk_window_new QGtkStylePrivate::gtk_window_new = 0; +Ptr_gtk_widget_destroy QGtkStylePrivate::gtk_widget_destroy = 0; +Ptr_gtk_widget_realize QGtkStylePrivate::gtk_widget_realize = 0; +Ptr_gtk_widget_set_default_direction QGtkStylePrivate::gtk_widget_set_default_direction = 0; +Ptr_gtk_widget_modify_color QGtkStylePrivate::gtk_widget_modify_fg = 0; +Ptr_gtk_widget_modify_color QGtkStylePrivate::gtk_widget_modify_bg = 0; +Ptr_gtk_arrow_new QGtkStylePrivate::gtk_arrow_new = 0; +Ptr_gtk_menu_item_new QGtkStylePrivate::gtk_menu_item_new = 0; +Ptr_gtk_check_menu_item_new QGtkStylePrivate::gtk_check_menu_item_new = 0; +Ptr_gtk_menu_bar_new QGtkStylePrivate::gtk_menu_bar_new = 0; +Ptr_gtk_menu_new QGtkStylePrivate::gtk_menu_new = 0; +Ptr_gtk_button_new QGtkStylePrivate::gtk_button_new = 0; +Ptr_gtk_tool_button_new QGtkStylePrivate::gtk_tool_button_new = 0; +Ptr_gtk_hbutton_box_new QGtkStylePrivate::gtk_hbutton_box_new = 0; +Ptr_gtk_check_button_new QGtkStylePrivate::gtk_check_button_new = 0; +Ptr_gtk_radio_button_new QGtkStylePrivate::gtk_radio_button_new = 0; +Ptr_gtk_spin_button_new QGtkStylePrivate::gtk_spin_button_new = 0; +Ptr_gtk_frame_new QGtkStylePrivate::gtk_frame_new = 0; +Ptr_gtk_expander_new QGtkStylePrivate::gtk_expander_new = 0; +Ptr_gtk_statusbar_new QGtkStylePrivate::gtk_statusbar_new = 0; +Ptr_gtk_entry_new QGtkStylePrivate::gtk_entry_new = 0; +Ptr_gtk_hscale_new QGtkStylePrivate::gtk_hscale_new = 0; +Ptr_gtk_vscale_new QGtkStylePrivate::gtk_vscale_new = 0; +Ptr_gtk_hscrollbar_new QGtkStylePrivate::gtk_hscrollbar_new = 0; +Ptr_gtk_vscrollbar_new QGtkStylePrivate::gtk_vscrollbar_new = 0; +Ptr_gtk_scrolled_window_new QGtkStylePrivate::gtk_scrolled_window_new = 0; +Ptr_gtk_notebook_new QGtkStylePrivate::gtk_notebook_new = 0; +Ptr_gtk_toolbar_new QGtkStylePrivate::gtk_toolbar_new = 0; +Ptr_gtk_toolbar_insert QGtkStylePrivate::gtk_toolbar_insert = 0; +Ptr_gtk_separator_tool_item_new QGtkStylePrivate::gtk_separator_tool_item_new = 0; +Ptr_gtk_tree_view_new QGtkStylePrivate::gtk_tree_view_new = 0; +Ptr_gtk_combo_box_new QGtkStylePrivate::gtk_combo_box_new = 0; +Ptr_gtk_combo_box_entry_new QGtkStylePrivate::gtk_combo_box_entry_new = 0; +Ptr_gtk_progress_bar_new QGtkStylePrivate::gtk_progress_bar_new = 0; +Ptr_gtk_container_add QGtkStylePrivate::gtk_container_add = 0; +Ptr_gtk_menu_shell_append QGtkStylePrivate::gtk_menu_shell_append = 0; +Ptr_gtk_progress_set_adjustment QGtkStylePrivate::gtk_progress_set_adjustment = 0; +Ptr_gtk_range_set_adjustment QGtkStylePrivate::gtk_range_set_adjustment = 0; +Ptr_gtk_range_set_inverted QGtkStylePrivate::gtk_range_set_inverted = 0; +Ptr_gtk_icon_factory_lookup_default QGtkStylePrivate::gtk_icon_factory_lookup_default = 0; +Ptr_gtk_icon_theme_get_default QGtkStylePrivate::gtk_icon_theme_get_default = 0; +Ptr_gtk_widget_style_get QGtkStylePrivate::gtk_widget_style_get = 0; +Ptr_gtk_icon_set_render_icon QGtkStylePrivate::gtk_icon_set_render_icon = 0; +Ptr_gtk_fixed_new QGtkStylePrivate::gtk_fixed_new = 0; +Ptr_gtk_tree_view_column_new QGtkStylePrivate::gtk_tree_view_column_new = 0; +Ptr_gtk_tree_view_get_column QGtkStylePrivate::gtk_tree_view_get_column = 0; +Ptr_gtk_tree_view_append_column QGtkStylePrivate::gtk_tree_view_append_column = 0; +Ptr_gtk_paint_check QGtkStylePrivate::gtk_paint_check = 0; +Ptr_gtk_paint_box QGtkStylePrivate::gtk_paint_box = 0; +Ptr_gtk_paint_box_gap QGtkStylePrivate::gtk_paint_box_gap = 0; +Ptr_gtk_paint_flat_box QGtkStylePrivate::gtk_paint_flat_box = 0; +Ptr_gtk_paint_option QGtkStylePrivate::gtk_paint_option = 0; +Ptr_gtk_paint_extension QGtkStylePrivate::gtk_paint_extension = 0; +Ptr_gtk_paint_slider QGtkStylePrivate::gtk_paint_slider = 0; +Ptr_gtk_paint_shadow QGtkStylePrivate::gtk_paint_shadow = 0; +Ptr_gtk_paint_resize_grip QGtkStylePrivate::gtk_paint_resize_grip = 0; +Ptr_gtk_paint_focus QGtkStylePrivate::gtk_paint_focus = 0; +Ptr_gtk_paint_arrow QGtkStylePrivate::gtk_paint_arrow = 0; +Ptr_gtk_paint_handle QGtkStylePrivate::gtk_paint_handle = 0; +Ptr_gtk_paint_expander QGtkStylePrivate::gtk_paint_expander = 0; +Ptr_gtk_adjustment_new QGtkStylePrivate::gtk_adjustment_new = 0; +Ptr_gtk_paint_hline QGtkStylePrivate::gtk_paint_hline = 0; +Ptr_gtk_paint_vline QGtkStylePrivate::gtk_paint_vline = 0; +Ptr_gtk_menu_item_set_submenu QGtkStylePrivate::gtk_menu_item_set_submenu = 0; +Ptr_gtk_settings_get_default QGtkStylePrivate::gtk_settings_get_default = 0; +Ptr_gtk_separator_menu_item_new QGtkStylePrivate::gtk_separator_menu_item_new = 0; +Ptr_gtk_widget_size_allocate QGtkStylePrivate::gtk_widget_size_allocate = 0; +Ptr_gtk_widget_set_direction QGtkStylePrivate::gtk_widget_set_direction = 0; +Ptr_gtk_widget_path QGtkStylePrivate::gtk_widget_path = 0; +Ptr_gtk_container_get_type QGtkStylePrivate::gtk_container_get_type = 0; +Ptr_gtk_window_get_type QGtkStylePrivate::gtk_window_get_type = 0; +Ptr_gtk_widget_get_type QGtkStylePrivate::gtk_widget_get_type = 0; +Ptr_gtk_rc_get_style_by_paths QGtkStylePrivate::gtk_rc_get_style_by_paths = 0; +Ptr_gtk_check_version QGtkStylePrivate::gtk_check_version = 0; + +Ptr_pango_font_description_get_size QGtkStylePrivate::pango_font_description_get_size = 0; +Ptr_pango_font_description_get_weight QGtkStylePrivate::pango_font_description_get_weight = 0; +Ptr_pango_font_description_get_family QGtkStylePrivate::pango_font_description_get_family = 0; +Ptr_pango_font_description_get_style QGtkStylePrivate::pango_font_description_get_style = 0; + +Ptr_gtk_file_filter_new QGtkStylePrivate::gtk_file_filter_new = 0; +Ptr_gtk_file_filter_set_name QGtkStylePrivate::gtk_file_filter_set_name = 0; +Ptr_gtk_file_filter_add_pattern QGtkStylePrivate::gtk_file_filter_add_pattern = 0; +Ptr_gtk_file_chooser_add_filter QGtkStylePrivate::gtk_file_chooser_add_filter = 0; +Ptr_gtk_file_chooser_set_filter QGtkStylePrivate::gtk_file_chooser_set_filter = 0; +Ptr_gtk_file_chooser_get_filter QGtkStylePrivate::gtk_file_chooser_get_filter = 0; +Ptr_gtk_file_chooser_dialog_new QGtkStylePrivate::gtk_file_chooser_dialog_new = 0; +Ptr_gtk_file_chooser_set_current_folder QGtkStylePrivate::gtk_file_chooser_set_current_folder = 0; +Ptr_gtk_file_chooser_get_filename QGtkStylePrivate::gtk_file_chooser_get_filename = 0; +Ptr_gtk_file_chooser_get_filenames QGtkStylePrivate::gtk_file_chooser_get_filenames = 0; +Ptr_gtk_file_chooser_set_current_name QGtkStylePrivate::gtk_file_chooser_set_current_name = 0; +Ptr_gtk_dialog_run QGtkStylePrivate::gtk_dialog_run = 0; +Ptr_gtk_file_chooser_set_filename QGtkStylePrivate::gtk_file_chooser_set_filename = 0; + +Ptr_gdk_pixbuf_get_pixels QGtkStylePrivate::gdk_pixbuf_get_pixels = 0; +Ptr_gdk_pixbuf_get_width QGtkStylePrivate::gdk_pixbuf_get_width = 0; +Ptr_gdk_pixbuf_get_height QGtkStylePrivate::gdk_pixbuf_get_height = 0; +Ptr_gdk_pixmap_new QGtkStylePrivate::gdk_pixmap_new = 0; +Ptr_gdk_pixbuf_new QGtkStylePrivate::gdk_pixbuf_new = 0; +Ptr_gdk_pixbuf_get_from_drawable QGtkStylePrivate::gdk_pixbuf_get_from_drawable = 0; +Ptr_gdk_draw_rectangle QGtkStylePrivate::gdk_draw_rectangle = 0; +Ptr_gdk_pixbuf_unref QGtkStylePrivate::gdk_pixbuf_unref = 0; +Ptr_gdk_drawable_unref QGtkStylePrivate::gdk_drawable_unref = 0; +Ptr_gdk_drawable_get_depth QGtkStylePrivate::gdk_drawable_get_depth = 0; +Ptr_gdk_color_free QGtkStylePrivate::gdk_color_free = 0; +Ptr_gdk_x11_window_set_user_time QGtkStylePrivate::gdk_x11_window_set_user_time = 0; +Ptr_gdk_x11_drawable_get_xid QGtkStylePrivate::gdk_x11_drawable_get_xid = 0; +Ptr_gdk_x11_drawable_get_xdisplay QGtkStylePrivate::gdk_x11_drawable_get_xdisplay = 0; + +Ptr_gconf_client_get_default QGtkStylePrivate::gconf_client_get_default = 0; +Ptr_gconf_client_get_string QGtkStylePrivate::gconf_client_get_string = 0; +Ptr_gconf_client_get_bool QGtkStylePrivate::gconf_client_get_bool = 0; + +Ptr_gnome_icon_lookup_sync QGtkStylePrivate::gnome_icon_lookup_sync = 0; +Ptr_gnome_vfs_init QGtkStylePrivate::gnome_vfs_init = 0; + +typedef int (*x11ErrorHandler)(Display*, XErrorEvent*); + +static void gtkStyleSetCallback(GtkWidget*, QGtkStylePrivate* stylePrivate) +{ + // We have to let this function return and complete the event + // loop to ensure that all gtk widgets have been styled before + // updating + QMetaObject::invokeMethod(styleScheduler(), "updateTheme", Qt::QueuedConnection, Q_ARG(QGtkStylePrivate*, stylePrivate)); +} + +static void update_toolbar_style(GtkWidget *gtkToolBar, GParamSpec *, gpointer) +{ + GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS; + g_object_get(gtkToolBar, "toolbar-style", &toolbar_style, NULL); + QWidgetList widgets = QApplication::allWidgets(); + for (int i = 0; i < widgets.size(); ++i) { + QWidget *widget = widgets.at(i); + if (qobject_cast<QToolButton*>(widget)) { + QEvent event(QEvent::StyleChange); + QApplication::sendEvent(widget, &event); + } + } +} + +static QString classPath(GtkWidget *widget) +{ + char* class_path; + QGtkStylePrivate::gtk_widget_path (widget, NULL, &class_path, NULL); + QString path = QLS(class_path); + g_free(class_path); + + // Remove the prefixes + path.remove(QLS("GtkWindow.")); + path.remove(QLS("GtkFixed.")); + return path; +} + + + +bool QGtkStyleFilter::eventFilter(QObject *obj, QEvent *e) +{ + if (e->type() == QEvent::ApplicationPaletteChange) { + // Only do this the first time since this will also + // generate applicationPaletteChange events + if (!qt_app_palettes_hash() || qt_app_palettes_hash()->isEmpty()) { + stylePrivate->applyCustomPaletteHash(); + } + } + return QObject::eventFilter(obj, e); +} + +QGtkStylePrivate::QGtkStylePrivate() + : QCleanlooksStylePrivate() + , filter(this) +{ +} + +void QGtkStylePrivate::init() +{ + resolveGtk(); + initGtkWidgets(); + if (isThemeAvailable()) + qApp->installEventFilter(&filter); +} + +GtkWidget* QGtkStylePrivate::gtkWidget(const QString &path) +{ + GtkWidget *widget = gtkWidgetMap()->value(path); + if (!widget) { + // Theme might have rearranged widget internals + widget = gtkWidgetMap()->value(path); + } + return widget; +} + +GtkStyle* QGtkStylePrivate::gtkStyle(const QString &path) +{ + if (gtkWidgetMap()->contains(path)) + return gtkWidgetMap()->value(path)->style; + return 0; +} + +/*! \internal + * Get references to gtk functions after we dynamically load the library. + */ +void QGtkStylePrivate::resolveGtk() +{ + // enforce the "0" suffix, so we'll open libgtk-x11-2.0.so.0 + QLibrary libgtk(QLS("gtk-x11-2.0"), 0, 0); + + gtk_init = (Ptr_gtk_init)libgtk.resolve("gtk_init"); + gtk_window_new = (Ptr_gtk_window_new)libgtk.resolve("gtk_window_new"); + gtk_style_attach = (Ptr_gtk_style_attach)libgtk.resolve("gtk_style_attach"); + gtk_widget_destroy = (Ptr_gtk_widget_destroy)libgtk.resolve("gtk_widget_destroy"); + gtk_widget_realize = (Ptr_gtk_widget_realize)libgtk.resolve("gtk_widget_realize"); + + gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)libgtk.resolve("gtk_file_chooser_set_current_folder"); + gtk_file_filter_new = (Ptr_gtk_file_filter_new)libgtk.resolve("gtk_file_filter_new"); + gtk_file_filter_set_name = (Ptr_gtk_file_filter_set_name)libgtk.resolve("gtk_file_filter_set_name"); + gtk_file_filter_add_pattern = (Ptr_gtk_file_filter_add_pattern)libgtk.resolve("gtk_file_filter_add_pattern"); + gtk_file_chooser_add_filter = (Ptr_gtk_file_chooser_add_filter)libgtk.resolve("gtk_file_chooser_add_filter"); + gtk_file_chooser_set_filter = (Ptr_gtk_file_chooser_set_filter)libgtk.resolve("gtk_file_chooser_set_filter"); + gtk_file_chooser_get_filter = (Ptr_gtk_file_chooser_get_filter)libgtk.resolve("gtk_file_chooser_get_filter"); + gtk_file_chooser_dialog_new = (Ptr_gtk_file_chooser_dialog_new)libgtk.resolve("gtk_file_chooser_dialog_new"); + gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)libgtk.resolve("gtk_file_chooser_set_current_folder"); + gtk_file_chooser_get_filename = (Ptr_gtk_file_chooser_get_filename)libgtk.resolve("gtk_file_chooser_get_filename"); + gtk_file_chooser_get_filenames = (Ptr_gtk_file_chooser_get_filenames)libgtk.resolve("gtk_file_chooser_get_filenames"); + gtk_file_chooser_set_current_name = (Ptr_gtk_file_chooser_set_current_name)libgtk.resolve("gtk_file_chooser_set_current_name"); + gtk_dialog_run = (Ptr_gtk_dialog_run)libgtk.resolve("gtk_dialog_run"); + gtk_file_chooser_set_filename = (Ptr_gtk_file_chooser_set_filename)libgtk.resolve("gtk_file_chooser_set_filename"); + + gdk_pixbuf_get_pixels = (Ptr_gdk_pixbuf_get_pixels)libgtk.resolve("gdk_pixbuf_get_pixels"); + gdk_pixbuf_get_width = (Ptr_gdk_pixbuf_get_width)libgtk.resolve("gdk_pixbuf_get_width"); + gdk_pixbuf_get_height = (Ptr_gdk_pixbuf_get_height)libgtk.resolve("gdk_pixbuf_get_height"); + gdk_pixmap_new = (Ptr_gdk_pixmap_new)libgtk.resolve("gdk_pixmap_new"); + gdk_pixbuf_new = (Ptr_gdk_pixbuf_new)libgtk.resolve("gdk_pixbuf_new"); + gdk_pixbuf_get_from_drawable = (Ptr_gdk_pixbuf_get_from_drawable)libgtk.resolve("gdk_pixbuf_get_from_drawable"); + gdk_draw_rectangle = (Ptr_gdk_draw_rectangle)libgtk.resolve("gdk_draw_rectangle"); + gdk_pixbuf_unref = (Ptr_gdk_pixbuf_unref)libgtk.resolve("gdk_pixbuf_unref"); + gdk_drawable_unref = (Ptr_gdk_drawable_unref)libgtk.resolve("gdk_drawable_unref"); + gdk_drawable_get_depth = (Ptr_gdk_drawable_get_depth)libgtk.resolve("gdk_drawable_get_depth"); + gdk_color_free = (Ptr_gdk_color_free)libgtk.resolve("gdk_color_free"); + gdk_x11_window_set_user_time = (Ptr_gdk_x11_window_set_user_time)libgtk.resolve("gdk_x11_window_set_user_time"); + gdk_x11_drawable_get_xid = (Ptr_gdk_x11_drawable_get_xid)libgtk.resolve("gdk_x11_drawable_get_xid"); + gdk_x11_drawable_get_xdisplay = (Ptr_gdk_x11_drawable_get_xdisplay)libgtk.resolve("gdk_x11_drawable_get_xdisplay"); + + gtk_widget_set_default_direction = (Ptr_gtk_widget_set_default_direction)libgtk.resolve("gtk_widget_set_default_direction"); + gtk_widget_modify_fg = (Ptr_gtk_widget_modify_color)libgtk.resolve("gtk_widget_modify_fg"); + gtk_widget_modify_bg = (Ptr_gtk_widget_modify_color)libgtk.resolve("gtk_widget_modify_bg"); + gtk_arrow_new = (Ptr_gtk_arrow_new)libgtk.resolve("gtk_arrow_new"); + gtk_menu_item_new = (Ptr_gtk_menu_item_new)libgtk.resolve("gtk_menu_item_new"); + gtk_check_menu_item_new = (Ptr_gtk_check_menu_item_new)libgtk.resolve("gtk_check_menu_item_new"); + gtk_menu_bar_new = (Ptr_gtk_menu_bar_new)libgtk.resolve("gtk_menu_bar_new"); + gtk_menu_new = (Ptr_gtk_menu_new)libgtk.resolve("gtk_menu_new"); + gtk_toolbar_new = (Ptr_gtk_toolbar_new)libgtk.resolve("gtk_toolbar_new"); + gtk_separator_tool_item_new = (Ptr_gtk_separator_tool_item_new)libgtk.resolve("gtk_separator_tool_item_new"); + gtk_toolbar_insert = (Ptr_gtk_toolbar_insert)libgtk.resolve("gtk_toolbar_insert"); + gtk_button_new = (Ptr_gtk_button_new)libgtk.resolve("gtk_button_new"); + gtk_tool_button_new = (Ptr_gtk_tool_button_new)libgtk.resolve("gtk_tool_button_new"); + gtk_hbutton_box_new = (Ptr_gtk_hbutton_box_new)libgtk.resolve("gtk_hbutton_box_new"); + gtk_check_button_new = (Ptr_gtk_check_button_new)libgtk.resolve("gtk_check_button_new"); + gtk_radio_button_new = (Ptr_gtk_radio_button_new)libgtk.resolve("gtk_radio_button_new"); + gtk_notebook_new = (Ptr_gtk_notebook_new)libgtk.resolve("gtk_notebook_new"); + gtk_progress_bar_new = (Ptr_gtk_progress_bar_new)libgtk.resolve("gtk_progress_bar_new"); + gtk_spin_button_new = (Ptr_gtk_spin_button_new)libgtk.resolve("gtk_spin_button_new"); + gtk_hscale_new = (Ptr_gtk_hscale_new)libgtk.resolve("gtk_hscale_new"); + gtk_vscale_new = (Ptr_gtk_vscale_new)libgtk.resolve("gtk_vscale_new"); + gtk_hscrollbar_new = (Ptr_gtk_hscrollbar_new)libgtk.resolve("gtk_hscrollbar_new"); + gtk_vscrollbar_new = (Ptr_gtk_vscrollbar_new)libgtk.resolve("gtk_vscrollbar_new"); + gtk_scrolled_window_new = (Ptr_gtk_scrolled_window_new)libgtk.resolve("gtk_scrolled_window_new"); + gtk_menu_shell_append = (Ptr_gtk_menu_shell_append)libgtk.resolve("gtk_menu_shell_append"); + gtk_entry_new = (Ptr_gtk_entry_new)libgtk.resolve("gtk_entry_new"); + gtk_tree_view_new = (Ptr_gtk_tree_view_new)libgtk.resolve("gtk_tree_view_new"); + gtk_combo_box_new = (Ptr_gtk_combo_box_new)libgtk.resolve("gtk_combo_box_new"); + gtk_progress_set_adjustment = (Ptr_gtk_progress_set_adjustment)libgtk.resolve("gtk_progress_set_adjustment"); + gtk_range_set_adjustment = (Ptr_gtk_range_set_adjustment)libgtk.resolve("gtk_range_set_adjustment"); + gtk_range_set_inverted = (Ptr_gtk_range_set_inverted)libgtk.resolve("gtk_range_set_inverted"); + gtk_container_add = (Ptr_gtk_container_add)libgtk.resolve("gtk_container_add"); + gtk_icon_factory_lookup_default = (Ptr_gtk_icon_factory_lookup_default)libgtk.resolve("gtk_icon_factory_lookup_default"); + gtk_icon_theme_get_default = (Ptr_gtk_icon_theme_get_default)libgtk.resolve("gtk_icon_theme_get_default"); + gtk_widget_style_get = (Ptr_gtk_widget_style_get)libgtk.resolve("gtk_widget_style_get"); + gtk_icon_set_render_icon = (Ptr_gtk_icon_set_render_icon)libgtk.resolve("gtk_icon_set_render_icon"); + gtk_fixed_new = (Ptr_gtk_fixed_new)libgtk.resolve("gtk_fixed_new"); + gtk_tree_view_column_new = (Ptr_gtk_tree_view_column_new)libgtk.resolve("gtk_tree_view_column_new"); + gtk_tree_view_append_column= (Ptr_gtk_tree_view_append_column )libgtk.resolve("gtk_tree_view_append_column"); + gtk_tree_view_get_column = (Ptr_gtk_tree_view_get_column )libgtk.resolve("gtk_tree_view_get_column"); + gtk_paint_check = (Ptr_gtk_paint_check)libgtk.resolve("gtk_paint_check"); + gtk_paint_box = (Ptr_gtk_paint_box)libgtk.resolve("gtk_paint_box"); + gtk_paint_flat_box = (Ptr_gtk_paint_flat_box)libgtk.resolve("gtk_paint_flat_box"); + gtk_paint_check = (Ptr_gtk_paint_check)libgtk.resolve("gtk_paint_check"); + gtk_paint_box = (Ptr_gtk_paint_box)libgtk.resolve("gtk_paint_box"); + gtk_paint_resize_grip = (Ptr_gtk_paint_resize_grip)libgtk.resolve("gtk_paint_resize_grip"); + gtk_paint_focus = (Ptr_gtk_paint_focus)libgtk.resolve("gtk_paint_focus"); + gtk_paint_shadow = (Ptr_gtk_paint_shadow)libgtk.resolve("gtk_paint_shadow"); + gtk_paint_slider = (Ptr_gtk_paint_slider)libgtk.resolve("gtk_paint_slider"); + gtk_paint_expander = (Ptr_gtk_paint_expander)libgtk.resolve("gtk_paint_expander"); + gtk_paint_handle = (Ptr_gtk_paint_handle)libgtk.resolve("gtk_paint_handle"); + gtk_paint_option = (Ptr_gtk_paint_option)libgtk.resolve("gtk_paint_option"); + gtk_paint_arrow = (Ptr_gtk_paint_arrow)libgtk.resolve("gtk_paint_arrow"); + gtk_paint_box_gap = (Ptr_gtk_paint_box_gap)libgtk.resolve("gtk_paint_box_gap"); + gtk_paint_extension = (Ptr_gtk_paint_extension)libgtk.resolve("gtk_paint_extension"); + gtk_paint_hline = (Ptr_gtk_paint_hline)libgtk.resolve("gtk_paint_hline"); + gtk_paint_vline = (Ptr_gtk_paint_vline)libgtk.resolve("gtk_paint_vline"); + gtk_adjustment_new = (Ptr_gtk_adjustment_new)libgtk.resolve("gtk_adjustment_new"); + gtk_menu_item_set_submenu = (Ptr_gtk_menu_item_set_submenu)libgtk.resolve("gtk_menu_item_set_submenu"); + gtk_settings_get_default = (Ptr_gtk_settings_get_default)libgtk.resolve("gtk_settings_get_default"); + gtk_separator_menu_item_new = (Ptr_gtk_separator_menu_item_new)libgtk.resolve("gtk_separator_menu_item_new"); + gtk_frame_new = (Ptr_gtk_frame_new)libgtk.resolve("gtk_frame_new"); + gtk_expander_new = (Ptr_gtk_expander_new)libgtk.resolve("gtk_expander_new"); + gtk_statusbar_new = (Ptr_gtk_statusbar_new)libgtk.resolve("gtk_statusbar_new"); + gtk_combo_box_entry_new = (Ptr_gtk_combo_box_entry_new)libgtk.resolve("gtk_combo_box_entry_new"); + gtk_container_forall = (Ptr_gtk_container_forall)libgtk.resolve("gtk_container_forall"); + gtk_widget_size_allocate =(Ptr_gtk_widget_size_allocate)libgtk.resolve("gtk_widget_size_allocate"); + gtk_widget_set_direction =(Ptr_gtk_widget_set_direction)libgtk.resolve("gtk_widget_set_direction"); + gtk_widget_path =(Ptr_gtk_widget_path)libgtk.resolve("gtk_widget_path"); + gtk_container_get_type =(Ptr_gtk_container_get_type)libgtk.resolve("gtk_container_get_type"); + gtk_window_get_type =(Ptr_gtk_window_get_type)libgtk.resolve("gtk_window_get_type"); + gtk_widget_get_type =(Ptr_gtk_widget_get_type)libgtk.resolve("gtk_widget_get_type"); + gtk_rc_get_style_by_paths =(Ptr_gtk_rc_get_style_by_paths)libgtk.resolve("gtk_rc_get_style_by_paths"); + gtk_check_version =(Ptr_gtk_check_version)libgtk.resolve("gtk_check_version"); + pango_font_description_get_size = (Ptr_pango_font_description_get_size)libgtk.resolve("pango_font_description_get_size"); + pango_font_description_get_weight = (Ptr_pango_font_description_get_weight)libgtk.resolve("pango_font_description_get_weight"); + pango_font_description_get_family = (Ptr_pango_font_description_get_family)libgtk.resolve("pango_font_description_get_family"); + pango_font_description_get_style = (Ptr_pango_font_description_get_style)libgtk.resolve("pango_font_description_get_style"); + + gnome_icon_lookup_sync = (Ptr_gnome_icon_lookup_sync)QLibrary::resolve(QLS("gnomeui-2"), 0, "gnome_icon_lookup_sync"); + gnome_vfs_init= (Ptr_gnome_vfs_init)QLibrary::resolve(QLS("gnomevfs-2"), 0, "gnome_vfs_init"); +} + +/* \internal + * Initializes a number of gtk menu widgets. + * The widgets are cached. + */ +void QGtkStylePrivate::initGtkMenu() +{ + // Create menubar + GtkWidget *gtkMenuBar = QGtkStylePrivate::gtk_menu_bar_new(); + setupGtkWidget(gtkMenuBar); + + GtkWidget *gtkMenuBarItem = QGtkStylePrivate::gtk_menu_item_new(); + gtk_menu_shell_append((GtkMenuShell*)(gtkMenuBar), gtkMenuBarItem); + gtk_widget_realize(gtkMenuBarItem); + + // Create menu + GtkWidget *gtkMenu = QGtkStylePrivate::gtk_menu_new(); + gtk_menu_item_set_submenu((GtkMenuItem*)(gtkMenuBarItem), gtkMenu); + gtk_widget_realize(gtkMenu); + + GtkWidget *gtkMenuItem = QGtkStylePrivate::gtk_menu_item_new(); + gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkMenuItem); + gtk_widget_realize(gtkMenuItem); + + GtkWidget *gtkCheckMenuItem = QGtkStylePrivate::gtk_check_menu_item_new(); + gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkCheckMenuItem); + gtk_widget_realize(gtkCheckMenuItem); + + GtkWidget *gtkMenuSeparator = QGtkStylePrivate::gtk_separator_menu_item_new(); + gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkMenuSeparator); + + addAllSubWidgets(gtkMenuBar); + addAllSubWidgets(gtkMenu); +} + + +void QGtkStylePrivate::initGtkTreeview() +{ + GtkWidget *gtkTreeView = gtk_tree_view_new(); + gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, gtk_tree_view_column_new()); + gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, gtk_tree_view_column_new()); + gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, gtk_tree_view_column_new()); + addWidget(gtkTreeView); +} + + +/* \internal + * Initializes a number of gtk widgets that we can later on use to determine some of our styles. + * The widgets are cached. + */ +void QGtkStylePrivate::initGtkWidgets() +{ + // From gtkmain.c + uid_t ruid = getuid (); + uid_t rgid = getgid (); + uid_t euid = geteuid (); + uid_t egid = getegid (); + if (ruid != euid || rgid != egid) { + qWarning("\nThis process is currently running setuid or setgid.\nGTK+ does not allow this " + "therefore Qt cannot use the GTK+ integration.\nTry launching your app using \'gksudo\', " + "\'kdesudo\' or a similar tool.\n\n" + "See http://www.gtk.org/setuid.html for more information.\n"); + return; + } + + static QString themeName; + if (!gtkWidgetMap()->contains(QLS("GtkWindow")) && themeName.isEmpty()) { + themeName = getThemeName(); + + if (themeName.isEmpty()) { + qWarning("QGtkStyle was unable to detect the current GTK+ theme."); + return; + } else if (themeName == QLS("Qt") || themeName == QLS("Qt4")) { + // Due to namespace conflicts with Qt3 and obvious recursion with Qt4, + // we cannot support the GTK_Qt Gtk engine + qWarning("QGtkStyle cannot be used together with the GTK_Qt engine."); + return; + } + } + + if (QGtkStylePrivate::gtk_init) { + // Gtk will set the Qt error handler so we have to reset it afterwards + x11ErrorHandler qt_x_errhandler = XSetErrorHandler(0); + QGtkStylePrivate::gtk_init (NULL, NULL); + XSetErrorHandler(qt_x_errhandler); + + // make a window + GtkWidget* gtkWindow = QGtkStylePrivate::gtk_window_new(GTK_WINDOW_POPUP); + QGtkStylePrivate::gtk_widget_realize(gtkWindow); + if (displayDepth == -1) + displayDepth = QGtkStylePrivate::gdk_drawable_get_depth(gtkWindow->window); + gtkWidgetMap()->insert(QLS("GtkWindow"), gtkWindow); + + + // Make all other widgets. respect the text direction + if (qApp->layoutDirection() == Qt::RightToLeft) + QGtkStylePrivate::gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL); + + if (!gtkWidgetMap()->contains(QLS("GtkButton"))) { + GtkWidget *gtkButton = QGtkStylePrivate::gtk_button_new(); + addWidget(gtkButton); + g_signal_connect(gtkButton, "style-set", G_CALLBACK(gtkStyleSetCallback), this); + addWidget(QGtkStylePrivate::gtk_tool_button_new(NULL, NULL)); + addWidget(QGtkStylePrivate::gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE)); + addWidget(QGtkStylePrivate::gtk_hbutton_box_new()); + addWidget(QGtkStylePrivate::gtk_check_button_new()); + addWidget(QGtkStylePrivate::gtk_radio_button_new(NULL)); + addWidget(QGtkStylePrivate::gtk_combo_box_new()); + addWidget(QGtkStylePrivate::gtk_combo_box_entry_new()); + addWidget(QGtkStylePrivate::gtk_entry_new()); + addWidget(QGtkStylePrivate::gtk_frame_new(NULL)); + addWidget(QGtkStylePrivate::gtk_expander_new("")); + addWidget(QGtkStylePrivate::gtk_statusbar_new()); + addWidget(QGtkStylePrivate::gtk_hscale_new((GtkAdjustment*)(QGtkStylePrivate::gtk_adjustment_new(1, 0, 1, 0, 0, 0)))); + addWidget(QGtkStylePrivate::gtk_hscrollbar_new(NULL)); + addWidget(QGtkStylePrivate::gtk_scrolled_window_new(NULL, NULL)); + + initGtkMenu(); + addWidget(QGtkStylePrivate::gtk_notebook_new()); + addWidget(QGtkStylePrivate::gtk_progress_bar_new()); + addWidget(QGtkStylePrivate::gtk_spin_button_new((GtkAdjustment*) + (QGtkStylePrivate::gtk_adjustment_new(1, 0, 1, 0, 0, 0)), 0.1, 3)); + GtkWidget *toolbar = gtk_toolbar_new(); + g_signal_connect (toolbar, "notify::toolbar-style", G_CALLBACK (update_toolbar_style), toolbar); + gtk_toolbar_insert((GtkToolbar*)toolbar, gtk_separator_tool_item_new(), -1); + addWidget(toolbar); + initGtkTreeview(); + addWidget(gtk_vscale_new((GtkAdjustment*)(QGtkStylePrivate::gtk_adjustment_new(1, 0, 1, 0, 0, 0)))); + addWidget(gtk_vscrollbar_new(NULL)); + } + else // Rebuild map + { + // When styles change subwidgets can get rearranged + // as with the combo box. We need to update the widget map + // to reflect this; + QHash<QString, GtkWidget*> oldMap = *gtkWidgetMap(); + gtkWidgetMap()->clear(); + QHashIterator<QString, GtkWidget*> it(oldMap); + while (it.hasNext()) { + it.next(); + if (!it.key().contains(QLatin1Char('.'))) { + addAllSubWidgets(it.value()); + } + } + } + } else { + qWarning("QGtkStyle could not resolve GTK. Make sure you have installed the proper libraries."); + } +} + +/*! \internal + * destroys all previously buffered widgets. + */ +void QGtkStylePrivate::cleanupGtkWidgets() +{ + if (gtkWidgetMap()->contains(QLS("GtkWindow"))) // Gtk will destroy all children + gtk_widget_destroy(gtkWidgetMap()->value(QLS("GtkWindow"))); +} + +static bool resolveGConf() +{ + if (!QGtkStylePrivate::gconf_client_get_default) { + QGtkStylePrivate::gconf_client_get_default = (Ptr_gconf_client_get_default)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_default"); + QGtkStylePrivate::gconf_client_get_string = (Ptr_gconf_client_get_string)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_string"); + QGtkStylePrivate::gconf_client_get_bool = (Ptr_gconf_client_get_bool)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_bool"); + } + return (QGtkStylePrivate::gconf_client_get_default !=0); +} + +QString QGtkStylePrivate::getGConfString(const QString &value, const QString &fallback) +{ + QString retVal = fallback; + if (resolveGConf()) { + g_type_init(); + GConfClient* client = gconf_client_get_default(); + GError *err = 0; + char *str = gconf_client_get_string(client, qPrintable(value), &err); + if (!err) { + retVal = QString::fromUtf8(str); + g_free(str); + } + g_object_unref(client); + if (err) + g_error_free (err); + } + return retVal; +} + +bool QGtkStylePrivate::getGConfBool(const QString &key, bool fallback) +{ + bool retVal = fallback; + if (resolveGConf()) { + g_type_init(); + GConfClient* client = gconf_client_get_default(); + GError *err = 0; + bool result = gconf_client_get_bool(client, qPrintable(key), &err); + g_object_unref(client); + if (!err) + retVal = result; + else + g_error_free (err); + } + return retVal; +} + +QString QGtkStylePrivate::getThemeName() const +{ + QString themeName; + // We try to parse the gtkrc file first + // primarily to avoid resolving Gtk functions if + // the KDE 3 "Qt" style is currently in use + QString rcPaths = QString::fromLocal8Bit(qgetenv("GTK2_RC_FILES")); + if (!rcPaths.isEmpty()) { + QStringList paths = rcPaths.split(QLS(":")); + foreach (const QString &rcPath, paths) { + if (!rcPath.isEmpty()) { + QFile rcFile(rcPath); + if (rcFile.exists() && rcFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&rcFile); + while(!in.atEnd()) { + QString line = in.readLine(); + if (line.contains(QLS("gtk-theme-name"))) { + line = line.right(line.length() - line.indexOf(QLatin1Char('=')) - 1); + line.remove(QLatin1Char('\"')); + line = line.trimmed(); + themeName = line; + break; + } + } + } + } + if (!themeName.isEmpty()) + break; + } + } + + // Fall back to gconf + if (themeName.isEmpty() && resolveGConf()) + themeName = getGConfString(QLS("/desktop/gnome/interface/gtk_theme")); + + return themeName; +} + +// Get size of the arrow controls in a GtkSpinButton +int QGtkStylePrivate::getSpinboxArrowSize() const +{ + const int MIN_ARROW_WIDTH = 6; + GtkWidget *spinButton = gtkWidget(QLS("GtkSpinButton")); + GtkStyle *style = spinButton->style; + gint size = pango_font_description_get_size (style->font_desc); + gint arrow_size; + arrow_size = qMax(PANGO_PIXELS (size), MIN_ARROW_WIDTH) + style->xthickness; + arrow_size += arrow_size%2 + 1; + return arrow_size; +} + + +bool QGtkStylePrivate::isKDE4Session() +{ + static int version = -1; + if (version == -1) + version = qgetenv("KDE_SESSION_VERSION").toInt(); + return (version == 4); +} + +void QGtkStylePrivate::applyCustomPaletteHash() +{ + QPalette menuPal = gtkWidgetPalette(QLS("GtkMenu")); + GdkColor gdkBg = gtkWidget(QLS("GtkMenu"))->style->bg[GTK_STATE_NORMAL]; + QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8); + menuPal.setBrush(QPalette::Base, bgColor); + menuPal.setBrush(QPalette::Window, bgColor); + qApp->setPalette(menuPal, "QMenu"); + + QPalette toolbarPal = gtkWidgetPalette(QLS("GtkToolbar")); + qApp->setPalette(toolbarPal, "QToolBar"); + + QPalette menuBarPal = gtkWidgetPalette(QLS("GtkMenuBar")); + qApp->setPalette(menuBarPal, "QMenuBar"); +} + +/*! \internal + * Returns the gtk Widget that should be used to determine text foreground and background colors. +*/ +GtkWidget* QGtkStylePrivate::getTextColorWidget() const +{ + return gtkWidget(QLS("GtkEntry")); +} + +void QGtkStylePrivate::setupGtkWidget(GtkWidget* widget) +{ + if (Q_GTK_IS_WIDGET(widget)) { + static GtkWidget* protoLayout = 0; + if (!protoLayout) { + protoLayout = QGtkStylePrivate::gtk_fixed_new(); + QGtkStylePrivate::gtk_container_add((GtkContainer*)(gtkWidgetMap()->value(QLS("GtkWindow"))), protoLayout); + } + Q_ASSERT(protoLayout); + + if (!widget->parent && !GTK_WIDGET_TOPLEVEL(widget)) + QGtkStylePrivate::gtk_container_add((GtkContainer*)(protoLayout), widget); + QGtkStylePrivate::gtk_widget_realize(widget); + } +} + +void QGtkStylePrivate::addWidgetToMap(GtkWidget *widget) +{ + if (Q_GTK_IS_WIDGET(widget)) { + gtk_widget_realize(widget); + gtkWidgetMap()->insert(classPath(widget), widget); + } + } + +void QGtkStylePrivate::addAllSubWidgets(GtkWidget *widget, gpointer v) +{ + Q_UNUSED(v); + addWidgetToMap(widget); + if (GTK_CHECK_TYPE ((widget), gtk_container_get_type())) + gtk_container_forall((GtkContainer*)widget, addAllSubWidgets, NULL); +} + +// Updates window/windowtext palette based on the indicated gtk widget +QPalette QGtkStylePrivate::gtkWidgetPalette(const QString >kWidgetName) +{ + GtkWidget *gtkWidget = QGtkStylePrivate::gtkWidget(gtkWidgetName); + Q_ASSERT(gtkWidget); + QPalette pal = QApplication::palette(); + GdkColor gdkBg = gtkWidget->style->bg[GTK_STATE_NORMAL]; + GdkColor gdkText = gtkWidget->style->fg[GTK_STATE_NORMAL]; + GdkColor gdkDisabledText = gtkWidget->style->fg[GTK_STATE_INSENSITIVE]; + QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8); + QColor textColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8); + QColor disabledTextColor(gdkDisabledText.red>>8, gdkDisabledText.green>>8, gdkDisabledText.blue>>8); + pal.setBrush(QPalette::Window, bgColor); + pal.setBrush(QPalette::Button, bgColor); + pal.setBrush(QPalette::All, QPalette::WindowText, textColor); + pal.setBrush(QPalette::Disabled, QPalette::WindowText, disabledTextColor); + pal.setBrush(QPalette::All, QPalette::ButtonText, textColor); + pal.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledTextColor); + return pal; +} + + +void QGtkStyleUpdateScheduler::updateTheme( QGtkStylePrivate* stylePrivate ) +{ + static QString oldTheme(QLS("qt_not_set")); + QPixmapCache::clear(); + + QFont font = QGtkStylePrivate::getThemeFont(); + if (QApplication::font() != font) + qApp->setFont(font); + + if (oldTheme != stylePrivate->getThemeName()) { + oldTheme = stylePrivate->getThemeName(); + QPalette newPalette = qApp->style()->standardPalette(); + QApplicationPrivate::setSystemPalette(newPalette); + QApplication::setPalette(newPalette); + stylePrivate->initGtkWidgets(); + stylePrivate->applyCustomPaletteHash(); + QList<QWidget*> widgets = QApplication::allWidgets(); + // Notify all widgets that size metrics might have changed + foreach (QWidget *widget, widgets) { + QEvent e(QEvent::StyleChange); + QApplication::sendEvent(widget, &e); + } + } + QIconLoader::instance()->updateSystemTheme(); +} + +void QGtkStylePrivate::addWidget(GtkWidget *widget) +{ + if (widget) { + setupGtkWidget(widget); + addAllSubWidgets(widget); + } +} + + +// Fetch the application font from the pango font description +// contained in the theme. +QFont QGtkStylePrivate::getThemeFont() +{ + QFont font; + GtkStyle *style = gtkStyle(); + if (style && qApp->desktopSettingsAware()) + { + PangoFontDescription *gtk_font = style->font_desc; + font.setPointSizeF((float)(pango_font_description_get_size(gtk_font))/PANGO_SCALE); + + QString family = QString::fromLatin1(pango_font_description_get_family(gtk_font)); + if (!family.isEmpty()) + font.setFamily(family); + + int weight = pango_font_description_get_weight(gtk_font); + if (weight >= PANGO_WEIGHT_HEAVY) + font.setWeight(QFont::Black); + else if (weight >= PANGO_WEIGHT_BOLD) + font.setWeight(QFont::Bold); + else if (weight >= PANGO_WEIGHT_SEMIBOLD) + font.setWeight(QFont::DemiBold); + else if (weight >= PANGO_WEIGHT_NORMAL) + font.setWeight(QFont::Normal); + else + font.setWeight(QFont::Light); + + PangoStyle fontstyle = pango_font_description_get_style(gtk_font); + if (fontstyle == PANGO_STYLE_ITALIC) + font.setStyle(QFont::StyleItalic); + else if (fontstyle == PANGO_STYLE_OBLIQUE) + font.setStyle(QFont::StyleOblique); + else + font.setStyle(QFont::StyleNormal); + } + return font; +} + + +// ----------- Native file dialogs ----------- + +// Extract filter list from expressions of type: foo (*.a *.b *.c)" +QStringList QGtkStylePrivate::extract_filter(const QString &rawFilter) +{ + QString result = rawFilter; + QRegExp r(QString::fromLatin1("^([^()]*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$")); + int index = r.indexIn(result); + if (index >= 0) + result = r.cap(2); + return result.split(QLatin1Char(' ')); +} + +extern QStringList qt_make_filter_list(const QString &filter); + +void QGtkStylePrivate::setupGtkFileChooser(GtkWidget* gtkFileChooser, QWidget *parent, + const QString &dir, const QString &filter, QString *selectedFilter, + QFileDialog::Options options, bool isSaveDialog, + QMap<GtkFileFilter *, QString> *filterMap) +{ + g_object_set(gtkFileChooser, "do-overwrite-confirmation", gboolean(!(options & QFileDialog::DontConfirmOverwrite)), NULL); + g_object_set(gtkFileChooser, "local_only", gboolean(true), NULL); + if (!filter.isEmpty()) { + QStringList filters = qt_make_filter_list(filter); + foreach (const QString &rawfilter, filters) { + GtkFileFilter *gtkFilter = QGtkStylePrivate::gtk_file_filter_new (); + QString name = rawfilter.left(rawfilter.indexOf(QLatin1Char('('))); + QStringList extensions = extract_filter(rawfilter); + QGtkStylePrivate::gtk_file_filter_set_name(gtkFilter, qPrintable(name.isEmpty() ? extensions.join(QLS(", ")) : name)); + + foreach (const QString &fileExtension, extensions) { + // Note Gtk file dialogs are by default case sensitive + // and only supports basic glob syntax so we + // rewrite .xyz to .[xX][yY][zZ] + QString caseInsensitive; + for (int i = 0 ; i < fileExtension.length() ; ++i) { + QChar ch = fileExtension.at(i); + if (ch.isLetter()) { + caseInsensitive.append( + QLatin1Char('[') + + ch.toLower() + + ch.toUpper() + + QLatin1Char(']')); + } else { + caseInsensitive.append(ch); + } + } + QGtkStylePrivate::gtk_file_filter_add_pattern (gtkFilter, qPrintable(caseInsensitive)); + + } + if (filterMap) + filterMap->insert(gtkFilter, rawfilter); + QGtkStylePrivate::gtk_file_chooser_add_filter((GtkFileChooser*)gtkFileChooser, gtkFilter); + if (selectedFilter && (rawfilter == *selectedFilter)) + QGtkStylePrivate::gtk_file_chooser_set_filter((GtkFileChooser*)gtkFileChooser, gtkFilter); + } + } + + // Using the currently active window is not entirely correct, however + // it gives more sensible behavior for applications that do not provide a + // parent + QWidget *modalFor = parent ? parent->window() : qApp->activeWindow(); + if (modalFor) { + QGtkStylePrivate::gtk_widget_realize(gtkFileChooser); // Creates X window + XSetTransientForHint(QGtkStylePrivate::gdk_x11_drawable_get_xdisplay(gtkFileChooser->window), + QGtkStylePrivate::gdk_x11_drawable_get_xid(gtkFileChooser->window), + modalFor->winId()); + QGtkStylePrivate::gdk_x11_window_set_user_time (gtkFileChooser->window, QX11Info::appUserTime()); + + } + + QFileInfo fileinfo(dir); + if (dir.isEmpty()) + fileinfo.setFile(QDir::currentPath()); + fileinfo.makeAbsolute(); + if (fileinfo.isDir()) { + QGtkStylePrivate::gtk_file_chooser_set_current_folder((GtkFileChooser*)gtkFileChooser, qPrintable(dir)); + } else if (isSaveDialog) { + QGtkStylePrivate::gtk_file_chooser_set_current_folder((GtkFileChooser*)gtkFileChooser, qPrintable(fileinfo.absolutePath())); + QGtkStylePrivate::gtk_file_chooser_set_current_name((GtkFileChooser*)gtkFileChooser, qPrintable(fileinfo.fileName())); + } else { + QGtkStylePrivate::gtk_file_chooser_set_filename((GtkFileChooser*)gtkFileChooser, qPrintable(dir)); + } +} + +QString QGtkStylePrivate::openFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, + QString *selectedFilter, QFileDialog::Options options) +{ + QMap<GtkFileFilter *, QString> filterMap; + GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption), + NULL, + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, false, &filterMap); + + QWidget modal_widget; + modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); + modal_widget.setParent(parent, Qt::Window); + QApplicationPrivate::enterModal(&modal_widget); + + QString filename; + if (QGtkStylePrivate::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { + char *gtk_filename = QGtkStylePrivate::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser); + filename = QString::fromUtf8(gtk_filename); + g_free (gtk_filename); + if (selectedFilter) { + GtkFileFilter *gtkFilter = QGtkStylePrivate::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser); + *selectedFilter = filterMap.value(gtkFilter); + } + } + + QApplicationPrivate::leaveModal(&modal_widget); + gtk_widget_destroy (gtkFileChooser); + return filename; +} + + +QString QGtkStylePrivate::openDirectory(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options) +{ + QMap<GtkFileFilter *, QString> filterMap; + GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption), + NULL, + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + setupGtkFileChooser(gtkFileChooser, parent, dir, QString(), 0, options); + QWidget modal_widget; + modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); + modal_widget.setParent(parent, Qt::Window); + QApplicationPrivate::enterModal(&modal_widget); + + QString filename; + if (QGtkStylePrivate::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { + char *gtk_filename = QGtkStylePrivate::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser); + filename = QString::fromUtf8(gtk_filename); + g_free (gtk_filename); + } + + QApplicationPrivate::leaveModal(&modal_widget); + gtk_widget_destroy (gtkFileChooser); + return filename; +} + +QStringList QGtkStylePrivate::openFilenames(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, + QString *selectedFilter, QFileDialog::Options options) +{ + QStringList filenames; + QMap<GtkFileFilter *, QString> filterMap; + GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption), + NULL, + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, false, &filterMap); + g_object_set(gtkFileChooser, "select-multiple", gboolean(true), NULL); + + QWidget modal_widget; + modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); + modal_widget.setParent(parent, Qt::Window); + QApplicationPrivate::enterModal(&modal_widget); + + if (gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { + GSList *gtk_file_names = QGtkStylePrivate::gtk_file_chooser_get_filenames((GtkFileChooser*)gtkFileChooser); + for (GSList *iterator = gtk_file_names ; iterator; iterator = iterator->next) + filenames << QString::fromUtf8((const char*)iterator->data); + g_slist_free(gtk_file_names); + if (selectedFilter) { + GtkFileFilter *gtkFilter = QGtkStylePrivate::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser); + *selectedFilter = filterMap.value(gtkFilter); + } + } + + QApplicationPrivate::leaveModal(&modal_widget); + gtk_widget_destroy (gtkFileChooser); + return filenames; +} + +QString QGtkStylePrivate::saveFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, + QString *selectedFilter, QFileDialog::Options options) +{ + QMap<GtkFileFilter *, QString> filterMap; + GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption), + NULL, + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, true, &filterMap); + + QWidget modal_widget; + modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); + modal_widget.setParent(parent, Qt::Window); + QApplicationPrivate::enterModal(&modal_widget); + + QString filename; + if (QGtkStylePrivate::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { + char *gtk_filename = QGtkStylePrivate::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser); + filename = QString::fromUtf8(gtk_filename); + g_free (gtk_filename); + if (selectedFilter) { + GtkFileFilter *gtkFilter = QGtkStylePrivate::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser); + *selectedFilter = filterMap.value(gtkFilter); + } + } + + QApplicationPrivate::leaveModal(&modal_widget); + gtk_widget_destroy (gtkFileChooser); + return filename; +} + +QIcon QGtkStylePrivate::getFilesystemIcon(const QFileInfo &info) +{ + QIcon icon; + if (gnome_vfs_init && gnome_icon_lookup_sync) { + gnome_vfs_init(); + GtkIconTheme *theme = gtk_icon_theme_get_default(); + QByteArray fileurl = QUrl::fromLocalFile(info.absoluteFilePath()).toEncoded(); + char * icon_name = gnome_icon_lookup_sync(theme, + NULL, + fileurl.data(), + NULL, + GNOME_ICON_LOOKUP_FLAGS_NONE, + NULL); + QString iconName = QString::fromUtf8(icon_name); + g_free(icon_name); + if (iconName.startsWith(QLatin1Char('/'))) + return QIcon(iconName); + return QIcon::fromTheme(iconName); + } + return icon; +} + +QT_END_NAMESPACE + +#endif // !defined(QT_NO_STYLE_GTK) diff --git a/src/gui/styles/gtksymbols_p.h b/src/gui/styles/qgtkstyle_p.h index 2cf21ce..fa16769 100644 --- a/src/gui/styles/gtksymbols_p.h +++ b/src/gui/styles/qgtkstyle_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef GTKSYMBOLS_H -#define GTKSYMBOLS_H +#ifndef QGTKSTYLE_P_H +#define QGTKSTYLE_P_H // // W A R N I N G @@ -56,19 +56,19 @@ #include <QtCore/qglobal.h> #if !defined(QT_NO_STYLE_GTK) +#include <QtGui/QFileDialog> + +#include <QtGui/QGtkStyle> +#include <private/qcleanlooksstyle_p.h> + #undef signals // Collides with GTK stymbols #include <gtk/gtk.h> -#include <QtCore/QLibrary> -#include <QtGui/QFont> -#include <QtGui/QFileDialog> + typedef unsigned long XID; #undef GTK_OBJECT_FLAGS #define GTK_OBJECT_FLAGS(obj)(((GtkObject*)(obj))->flags) -#define Q_GTK_TYPE_WIDGET QGtk::gtk_widget_get_type() -#define Q_GTK_IS_WIDGET(widget) widget && GTK_CHECK_TYPE ((widget), Q_GTK_TYPE_WIDGET) -#define Q_GTK_TYPE_WINDOW QGtk::gtk_window_get_type() -#define Q_GTK_TYPE_CONTAINER QGtk::gtk_container_get_type() +#define Q_GTK_IS_WIDGET(widget) widget && GTK_CHECK_TYPE ((widget), QGtkStylePrivate::gtk_widget_get_type()) #define QLS(x) QLatin1String(x) @@ -198,6 +198,35 @@ typedef XID (*Ptr_gdk_x11_drawable_get_xid) (GdkDrawable *); typedef Display* (*Ptr_gdk_x11_drawable_get_xdisplay) ( GdkDrawable *); +QT_BEGIN_NAMESPACE + +typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption, const QString &dir, + const QString &filter, QString *selectedFilter, QFileDialog::Options options); +typedef QString (*_qt_filedialog_open_filename_hook) (QWidget * parent, const QString &caption, const QString &dir, + const QString &filter, QString *selectedFilter, QFileDialog::Options options); +typedef QString (*_qt_filedialog_save_filename_hook) (QWidget * parent, const QString &caption, const QString &dir, + const QString &filter, QString *selectedFilter, QFileDialog::Options options); +typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, const QString &dir, + QFileDialog::Options options); + +extern Q_GUI_EXPORT _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook; +extern Q_GUI_EXPORT _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook; +extern Q_GUI_EXPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook; +extern Q_GUI_EXPORT _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook; + +class QGtkStylePrivate; + +class QGtkStyleFilter : public QObject +{ +public: + QGtkStyleFilter(QGtkStylePrivate* sp) + : stylePrivate(sp) + {} +private: + QGtkStylePrivate* stylePrivate; + bool eventFilter(QObject *obj, QEvent *e); +}; + typedef enum { GNOME_ICON_LOOKUP_FLAGS_NONE = 0, GNOME_ICON_LOOKUP_FLAGS_EMBEDDING_TEXT = 1<<0, @@ -220,21 +249,41 @@ typedef char* (*Ptr_gnome_icon_lookup_sync) ( GnomeIconLookupFlags flags, GnomeIconLookupResultFlags *result); -QT_BEGIN_NAMESPACE -class QGtk +class QGtkStylePrivate : public QCleanlooksStylePrivate { + Q_DECLARE_PUBLIC(QGtkStyle) public: + QGtkStylePrivate(); + + QGtkStyleFilter filter; + static GtkWidget* gtkWidget(const QString &path); static GtkStyle* gtkStyle(const QString &path = QLatin1String("GtkWindow")); - static void cleanup_gtk_widgets(); - static void initGtkWidgets(); + virtual void resolveGtk(); + virtual void initGtkMenu(); + virtual void initGtkTreeview(); + virtual void initGtkWidgets(); + + static void cleanupGtkWidgets(); + static bool isKDE4Session(); - static void applyCustomPaletteHash(); + void applyCustomPaletteHash(); static QFont getThemeFont(); static bool isThemeAvailable() { return gtkStyle() != 0; } + static bool getGConfBool(const QString &key, bool fallback = 0); + static QString getGConfString(const QString &key, const QString &fallback = QString()); + + virtual QString getThemeName() const; + virtual int getSpinboxArrowSize() const; + + static void setupGtkFileChooser(GtkWidget* gtkFileChooser, QWidget *parent, + const QString &dir, const QString &filter, QString *selectedFilter, + QFileDialog::Options options, bool isSaveDialog = false, + QMap<GtkFileFilter *, QString> *filterMap = 0); + static QString openFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); static QString saveFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, @@ -242,8 +291,6 @@ public: static QString openDirectory(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options); static QStringList openFilenames(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); - static QString getGConfString(const QString &key, const QString &fallback = QString()); - static bool getGConfBool(const QString &key, bool fallback = 0); static QIcon getFilesystemIcon(const QFileInfo &); static Ptr_gtk_container_forall gtk_container_forall; @@ -364,6 +411,29 @@ public: static Ptr_gnome_icon_lookup_sync gnome_icon_lookup_sync; static Ptr_gnome_vfs_init gnome_vfs_init; + + virtual QPalette gtkWidgetPalette(const QString >kWidgetName); + +protected: + typedef QHash<QString, GtkWidget*> WidgetMap; + + static inline WidgetMap *gtkWidgetMap() + { + static WidgetMap *map = 0; + if (!map) + map = new WidgetMap(); + return map; + } + + static QStringList extract_filter(const QString &rawFilter); + + virtual GtkWidget* getTextColorWidget() const; + static void setupGtkWidget(GtkWidget* widget); + static void addWidgetToMap(GtkWidget* widget); + static void addAllSubWidgets(GtkWidget *widget, gpointer v = 0); + static void addWidget(GtkWidget *widget); + + virtual void init(); }; // Helper to ensure that we have polished all our gtk widgets @@ -372,10 +442,10 @@ class QGtkStyleUpdateScheduler : public QObject { Q_OBJECT public slots: - void updateTheme(); + void updateTheme( QGtkStylePrivate* stylePrivate ); }; QT_END_NAMESPACE #endif // !QT_NO_STYLE_GTK -#endif // GTKSYMBOLS_H +#endif // QGTKSTYLE_P_H diff --git a/src/gui/styles/qwindowsxpstyle.cpp b/src/gui/styles/qwindowsxpstyle.cpp index 9fd9ce9..fe7f5d7 100644 --- a/src/gui/styles/qwindowsxpstyle.cpp +++ b/src/gui/styles/qwindowsxpstyle.cpp @@ -2926,10 +2926,10 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo } // Draw arrow p->save(); - p->setPen(option->palette.dark()); + p->setPen(option->palette.dark().color()); p->drawLine(menuarea.left(), menuarea.top() + 3, menuarea.left(), menuarea.bottom() - 3); - p->setPen(option->palette.light()); + p->setPen(option->palette.light().color()); p->drawLine(menuarea.left() - 1, menuarea.top() + 3, menuarea.left() - 1, menuarea.bottom() - 3); diff --git a/src/gui/styles/styles.pri b/src/gui/styles/styles.pri index 767ade0..88a2cce 100644 --- a/src/gui/styles/styles.pri +++ b/src/gui/styles/styles.pri @@ -109,10 +109,10 @@ contains( styles, plastique ) { contains( styles, gtk ) { HEADERS += styles/qgtkstyle.h HEADERS += styles/qgtkpainter_p.h - HEADERS += styles/gtksymbols_p.h + HEADERS += styles/qgtkstyle_p.h SOURCES += styles/qgtkstyle.cpp SOURCES += styles/qgtkpainter.cpp - SOURCES += styles/gtksymbols.cpp + SOURCES += styles/qgtkstyle_p.cpp !contains( styles, cleanlooks ) { styles += cleanlooks DEFINES+= QT_STYLE_CLEANLOOKS diff --git a/src/gui/symbian/qsymbianevent.cpp b/src/gui/symbian/qsymbianevent.cpp index af2c861..2799e6f 100644 --- a/src/gui/symbian/qsymbianevent.cpp +++ b/src/gui/symbian/qsymbianevent.cpp @@ -66,13 +66,13 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QSymbianEvent::type() + \fn QSymbianEvent::type() const Returns the event type contained in the QSymbianEvent instance. */ /*! - \fn QSymbianEvent::isValid() + \fn QSymbianEvent::isValid() const Returns whether this QSymbianEvent instance contains a valid event. */ diff --git a/src/gui/text/qtextengine_mac.cpp b/src/gui/text/qtextengine_mac.cpp index eeccc72..54be53b 100644 --- a/src/gui/text/qtextengine_mac.cpp +++ b/src/gui/text/qtextengine_mac.cpp @@ -594,53 +594,50 @@ void QTextEngine::shapeTextMac(int item) const str = reinterpret_cast<const QChar *>(uc); } - while (true) { - ensureSpace(num_glyphs); - num_glyphs = layoutData->glyphLayout.numGlyphs - layoutData->used; - - QGlyphLayout g = availableGlyphs(&si); - g.numGlyphs = num_glyphs; - unsigned short *log_clusters = logClusters(&si); + ensureSpace(num_glyphs); + num_glyphs = layoutData->glyphLayout.numGlyphs - layoutData->used; - if (fe->stringToCMap(str, - len, - &g, - &num_glyphs, - flags, - log_clusters, - attributes())) { + QGlyphLayout g = availableGlyphs(&si); + g.numGlyphs = num_glyphs; + unsigned short *log_clusters = logClusters(&si); - heuristicSetGlyphAttributes(str, len, &g, log_clusters, num_glyphs); - break; - } + bool stringToCMapFailed = false; + if (!fe->stringToCMap(str, len, &g, &num_glyphs, flags, log_clusters, attributes())) { + ensureSpace(num_glyphs); + stringToCMapFailed = fe->stringToCMap(str, len, &g, &num_glyphs, flags, log_clusters, + attributes()); } - si.num_glyphs = num_glyphs; + if (!stringToCMapFailed) { + heuristicSetGlyphAttributes(str, len, &g, log_clusters, num_glyphs); - layoutData->used += si.num_glyphs; + si.num_glyphs = num_glyphs; - QGlyphLayout g = shapedGlyphs(&si); + layoutData->used += si.num_glyphs; - if (si.analysis.script == QUnicodeTables::Arabic) { - QVarLengthArray<QArabicProperties> props(len + 2); - QArabicProperties *properties = props.data(); - int f = si.position; - int l = len; - if (f > 0) { - --f; - ++l; - ++properties; - } - if (f + l < layoutData->string.length()) { - ++l; - } - qt_getArabicProperties((const unsigned short *)(layoutData->string.unicode()+f), l, props.data()); + QGlyphLayout g = shapedGlyphs(&si); - unsigned short *log_clusters = logClusters(&si); + if (si.analysis.script == QUnicodeTables::Arabic) { + QVarLengthArray<QArabicProperties> props(len + 2); + QArabicProperties *properties = props.data(); + int f = si.position; + int l = len; + if (f > 0) { + --f; + ++l; + ++properties; + } + if (f + l < layoutData->string.length()) { + ++l; + } + qt_getArabicProperties((const unsigned short *)(layoutData->string.unicode()+f), l, props.data()); - for (int i = 0; i < len; ++i) { - int gpos = log_clusters[i]; - g.attributes[gpos].justification = properties[i].justification; + unsigned short *log_clusters = logClusters(&si); + + for (int i = 0; i < len; ++i) { + int gpos = log_clusters[i]; + g.attributes[gpos].justification = properties[i].justification; + } } } diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp index 1690d87..85b539f 100644 --- a/src/gui/util/qdesktopservices.cpp +++ b/src/gui/util/qdesktopservices.cpp @@ -294,15 +294,6 @@ void QDesktopServices::unsetUrlHandler(const QString &scheme) Rest of the standard locations point to folder on same drive with executable, except that if executable is in ROM the folder from C drive is returned. - \note On Mac OS X, DataLocation does not include QCoreApplication::organizationName. - Use code like this to add it: - - \code - QString location = QDesktopServices::storageLocation(QDesktopServices::DataLocation); - #ifdef Q_WS_MAC - location.insert(location.count() - QCoreApplication::applicationName().count(), - QCoreApplication::organizationName() + "/"); - #endif \endcode */ diff --git a/src/gui/util/qdesktopservices_mac.cpp b/src/gui/util/qdesktopservices_mac.cpp index 0626e0a..23f9e60 100644 --- a/src/gui/util/qdesktopservices_mac.cpp +++ b/src/gui/util/qdesktopservices_mac.cpp @@ -153,9 +153,12 @@ QString QDesktopServices::storageLocation(StandardLocation type) QString path = getFullPath(ref); - QString appName = QCoreApplication::applicationName(); - if (!appName.isEmpty() && (type == DataLocation || type == CacheLocation)) - path += QLatin1Char('/') + appName; + if (type == DataLocation || type == CacheLocation) { + if (QCoreApplication::organizationName().isEmpty() == false) + path += QLatin1Char('/') + QCoreApplication::organizationName(); + if (QCoreApplication::applicationName().isEmpty() == false) + path += QLatin1Char('/') + QCoreApplication::applicationName(); + } return path; } diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index 0896256..7d81d5a 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -293,13 +293,16 @@ void QAbstractScrollAreaPrivate::init() q->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); layoutChildren(); + viewport->grabGesture(Qt::PanGesture); } #ifdef Q_WS_WIN void QAbstractScrollAreaPrivate::setSingleFingerPanEnabled(bool on) { singleFingerPanEnabled = on; - winSetupGestures(); + QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport)); + if (dd) + dd->winSetupGestures(); } #endif // Q_WS_WIN @@ -539,6 +542,7 @@ void QAbstractScrollArea::setViewport(QWidget *widget) d->viewport->setParent(this); d->viewport->setFocusProxy(this); d->viewport->installEventFilter(d->viewportFilter.data()); + d->viewport->grabGesture(Qt::PanGesture); d->layoutChildren(); if (isVisible()) d->viewport->show(); @@ -935,6 +939,26 @@ bool QAbstractScrollArea::event(QEvent *e) case QEvent::TouchUpdate: case QEvent::TouchEnd: return false; + case QEvent::Gesture: + { + QGestureEvent *ge = static_cast<QGestureEvent *>(e); + QPanGesture *g = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture)); + if (g) { + QScrollBar *hBar = horizontalScrollBar(); + QScrollBar *vBar = verticalScrollBar(); + QPointF delta = g->lastOffset(); + if (!delta.isNull()) { + if (QApplication::isRightToLeft()) + delta.rx() *= -1; + int newX = hBar->value() - delta.x(); + int newY = vBar->value() - delta.y(); + hBar->setValue(newX); + vBar->setValue(newY); + } + return true; + } + return false; + } case QEvent::StyleChange: case QEvent::LayoutDirectionChange: case QEvent::ApplicationLayoutDirectionChange: @@ -990,6 +1014,8 @@ bool QAbstractScrollArea::viewportEvent(QEvent *e) #endif return QFrame::event(e); case QEvent::LayoutRequest: + case QEvent::Gesture: + case QEvent::GestureOverride: return event(e); default: break; @@ -1266,11 +1292,13 @@ void QAbstractScrollAreaPrivate::_q_vslide(int y) void QAbstractScrollAreaPrivate::_q_showOrHideScrollBars() { layoutChildren(); -#ifdef Q_OS_WIN +#ifdef Q_WS_WIN // Need to re-subscribe to gestures as the content changes to make sure we // enable/disable panning when needed. - winSetupGestures(); -#endif // Q_OS_WIN + QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport)); + if (dd) + dd->winSetupGestures(); +#endif // Q_WS_WIN } QPoint QAbstractScrollAreaPrivate::contentsOffset() const @@ -1335,25 +1363,6 @@ void QAbstractScrollArea::setupViewport(QWidget *viewport) Q_UNUSED(viewport); } -//void QAbstractScrollAreaPrivate::_q_gestureTriggered() -//{ -// Q_Q(QAbstractScrollArea); -// QPanGesture *g = qobject_cast<QPanGesture*>(q->sender()); -// if (!g) -// return; -// QScrollBar *hBar = q->horizontalScrollBar(); -// QScrollBar *vBar = q->verticalScrollBar(); -// QSizeF delta = g->lastOffset(); -// if (!delta.isNull()) { -// if (QApplication::isRightToLeft()) -// delta.rwidth() *= -1; -// int newX = hBar->value() - delta.width(); -// int newY = vBar->value() - delta.height(); -// hbar->setValue(newX); -// vbar->setValue(newY); -// } -//} - QT_END_NAMESPACE #include "moc_qabstractscrollarea.cpp" diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp index bb93546..0de7421 100644 --- a/src/gui/widgets/qplaintextedit.cpp +++ b/src/gui/widgets/qplaintextedit.cpp @@ -730,9 +730,6 @@ QPlainTextEditPrivate::QPlainTextEditPrivate() backgroundVisible = false; centerOnScroll = false; inDrag = false; -#ifdef Q_WS_WIN - singleFingerPanEnabled = true; -#endif } @@ -789,6 +786,9 @@ void QPlainTextEditPrivate::init(const QString &txt) viewport->setCursor(Qt::IBeamCursor); #endif originalOffsetY = 0; +#ifdef Q_WS_WIN + setSingleFingerPanEnabled(true); +#endif } void QPlainTextEditPrivate::_q_repaintContents(const QRectF &contentsRect) @@ -1450,6 +1450,29 @@ bool QPlainTextEdit::event(QEvent *e) d->sendControlEvent(e); } #endif + else if (e->type() == QEvent::Gesture) { + QGestureEvent *ge = static_cast<QGestureEvent *>(e); + QPanGesture *g = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture)); + if (g) { + QScrollBar *hBar = horizontalScrollBar(); + QScrollBar *vBar = verticalScrollBar(); + if (g->state() == Qt::GestureStarted) + d->originalOffsetY = vBar->value(); + QPointF offset = g->offset(); + if (!offset.isNull()) { + if (QApplication::isRightToLeft()) + offset.rx() *= -1; + // QPlainTextEdit scrolls by lines only in vertical direction + QFontMetrics fm(document()->defaultFont()); + int lineHeight = fm.height(); + int newX = hBar->value() - g->lastOffset().x(); + int newY = d->originalOffsetY - offset.y()/lineHeight; + hBar->setValue(newX); + vBar->setValue(newY); + } + } + return true; + } return QAbstractScrollArea::event(e); } @@ -2929,30 +2952,6 @@ QAbstractTextDocumentLayout::PaintContext QPlainTextEdit::getPaintContext() cons (\a available is true) or unavailable (\a available is false). */ -//void QPlainTextEditPrivate::_q_gestureTriggered() -//{ -// Q_Q(QPlainTextEdit); -// QPanGesture *g = qobject_cast<QPanGesture*>(q->sender()); -// if (!g) -// return; -// QScrollBar *hBar = q->horizontalScrollBar(); -// QScrollBar *vBar = q->verticalScrollBar(); -// if (g->state() == Qt::GestureStarted) -// originalOffsetY = vBar->value(); -// QSizeF totalOffset = g->totalOffset(); -// if (!totalOffset.isNull()) { -// if (QApplication::isRightToLeft()) -// totalOffset.rwidth() *= -1; -// // QPlainTextEdit scrolls by lines only in vertical direction -// QFontMetrics fm(q->document()->defaultFont()); -// int lineHeight = fm.height(); -// int newX = hBar->value() - g->lastOffset().width(); -// int newY = originalOffsetY - totalOffset.height()/lineHeight; -// hbar->setValue(newX); -// vbar->setValue(newY); -// } -//} - QT_END_NAMESPACE #include "moc_qplaintextedit.cpp" diff --git a/src/gui/widgets/qtextedit.cpp b/src/gui/widgets/qtextedit.cpp index d995e0f..88502e3 100644 --- a/src/gui/widgets/qtextedit.cpp +++ b/src/gui/widgets/qtextedit.cpp @@ -116,9 +116,6 @@ QTextEditPrivate::QTextEditPrivate() preferRichText = false; showCursorOnInitialShow = true; inDrag = false; -#ifdef Q_WS_WIN - setSingleFingerPanEnabled(true); -#endif } void QTextEditPrivate::createAutoBulletList() @@ -186,6 +183,9 @@ void QTextEditPrivate::init(const QString &html) #ifndef QT_NO_CURSOR viewport->setCursor(Qt::IBeamCursor); #endif +#ifdef Q_WS_WIN + setSingleFingerPanEnabled(true); +#endif } void QTextEditPrivate::_q_repaintContents(const QRectF &contentsRect) |