diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-18 03:43:35 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-18 03:43:35 (GMT) |
commit | 19bf1fec0ec3341fae97e27d3cb0baf8fb27b9f3 (patch) | |
tree | 16d04a9a1d3f87f6e42d94c8ea85875dfa2b5809 /src | |
parent | 379b4dc81177b95c15de30c5925efca1136e4041 (diff) | |
parent | 91a1f7a1c408052b1d284d6b901819964e338fe5 (diff) | |
download | Qt-19bf1fec0ec3341fae97e27d3cb0baf8fb27b9f3.zip Qt-19bf1fec0ec3341fae97e27d3cb0baf8fb27b9f3.tar.gz Qt-19bf1fec0ec3341fae97e27d3cb0baf8fb27b9f3.tar.bz2 |
Merge branch 'qt-4.7-from-4.6' of scm.dev.nokia.troll.no:qt/qt-integration into 4.7-integration
* 'qt-4.7-from-4.6' of scm.dev.nokia.troll.no:qt/qt-integration: (69 commits)
re-add overriding of tool paths to configure
fix regexp
Support linked fonts (.ltt) from standard font locations.
fix path separators in install targets for MinGW+sh
fix QMAKE_QMAKE path separator under mingw+sh in the qmake spec
define qtPrepareTool() function and use it throughout
QS60Style: In S60 3.x and 5.0 Qt itemviews behaviour is not nativelike
QNAM HTTP: And one more testcase
QNetworkAccessManager: Backends were tried in wrong order
Fix QUrl::isValid if the host contains invalid caracter.
Fix anomaly demo control strip icon placement
QUrl: parsing of host name with an undercore.
Fixed race condition compiling xmlpatterns tests.
Remove qdbusserver from tests/auto/dbus.pro
QNAM HTTP: Preemptive anti crash if() statement
QNAM HTTP: More testcases
Fixing compiling issues.
Remove garbage test.
OpenVG blending modes from VG_KHR_advanced_blending extension
Fix spurious mouse click when dismissing a native menu
...
Diffstat (limited to 'src')
54 files changed, 1400 insertions, 710 deletions
diff --git a/src/3rdparty/phonon/qt7/audiodevice.mm b/src/3rdparty/phonon/qt7/audiodevice.mm index 6bec62d..3aae0ee4 100644 --- a/src/3rdparty/phonon/qt7/audiodevice.mm +++ b/src/3rdparty/phonon/qt7/audiodevice.mm @@ -149,7 +149,6 @@ QString AudioDevice::deviceSourceName(AudioDeviceID deviceID) size = sizeof(translation); err = AudioDeviceGetProperty(deviceID, 0, 0, kAudioDevicePropertyDataSourceNameForIDCFString, &size, &translation); if (err != noErr){ - CFRelease(cfName); return QString(); } QString name = PhononCFString::toQString(cfName); diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index d4b8b5f..79a8ce4 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -345,6 +345,7 @@ public: bool hasQuery; bool hasFragment; bool isValid; + bool isHostValid; char valueDelimiter; char pairDelimiter; @@ -3138,10 +3139,11 @@ static void toPunycodeHelper(const QChar *s, int ucLength, QString *output) static const char * const idn_whitelist[] = { - "ac", "at", - "br", + "ac", "ar", "at", + "biz", "br", "cat", "ch", "cl", "cn", "de", "dk", + "es", "fi", "gr", "hu", @@ -3155,6 +3157,9 @@ static const char * const idn_whitelist[] = { "se", "sh", "th", "tm", "tw", "vn", + "xn--mgbaam7a8h", // UAE + "xn--mgberp4a5d4ar", // Saudi Arabia + "xn--wgbh1c" // Egypt }; static QStringList *user_idn_whitelist = 0; @@ -3313,6 +3318,7 @@ static QString qt_ACE_do(const QString &domain, AceOperation op) qt_nameprep(&result, prevLen); labelLength = result.length() - prevLen; register int toReserve = labelLength + 4 + 6; // "xn--" plus some extra bytes + aceForm.resize(0); if (toReserve > aceForm.capacity()) aceForm.reserve(toReserve); toPunycodeHelper(result.constData() + prevLen, result.size() - prevLen, &aceForm); @@ -3349,6 +3355,7 @@ QUrlPrivate::QUrlPrivate() ref = 1; port = -1; isValid = false; + isHostValid = true; parsingMode = QUrl::TolerantMode; valueDelimiter = '='; pairDelimiter = '&'; @@ -3375,6 +3382,7 @@ QUrlPrivate::QUrlPrivate(const QUrlPrivate ©) hasQuery(copy.hasQuery), hasFragment(copy.hasFragment), isValid(copy.isValid), + isHostValid(copy.isHostValid), valueDelimiter(copy.valueDelimiter), pairDelimiter(copy.pairDelimiter), stateFlags(copy.stateFlags), @@ -3405,6 +3413,8 @@ QString QUrlPrivate::canonicalHost() const that->host = host.toLower(); } else { that->host = qt_ACE_do(host, NormalizeAce); + if (that->host.isNull()) + that->isHostValid = false; } return that->host; } @@ -3481,6 +3491,7 @@ QString QUrlPrivate::authority(QUrl::FormattingOptions options) const void QUrlPrivate::setAuthority(const QString &auth) { + isHostValid = true; if (auth.isEmpty()) { setUserInfo(QString()); host.clear(); @@ -4175,7 +4186,7 @@ bool QUrl::isValid() const if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse(); if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Validated)) d->validate(); - return d->isValid; + return d->isValid && d->isHostValid; } /*! @@ -4427,7 +4438,6 @@ void QUrl::setAuthority(const QString &authority) if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse(); detach(); QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized); - d->setAuthority(authority); } @@ -4648,6 +4658,7 @@ void QUrl::setHost(const QString &host) if (!d) d = new QUrlPrivate; if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse(); detach(); + d->isHostValid = true; QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized | QUrlPrivate::HostCanonicalized); d->host = host; diff --git a/src/corelib/kernel/qeventdispatcher_symbian.cpp b/src/corelib/kernel/qeventdispatcher_symbian.cpp index 687a6d9..33775d2 100644 --- a/src/corelib/kernel/qeventdispatcher_symbian.cpp +++ b/src/corelib/kernel/qeventdispatcher_symbian.cpp @@ -47,6 +47,8 @@ #include <unistd.h> #include <errno.h> +#include <net/if.h> + QT_BEGIN_NAMESPACE #ifdef SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS @@ -569,13 +571,17 @@ void QSelectThread::updateActivatedNotifiers(QSocketNotifier::Type type, fd_set * check if socket is in exception set * then signal RequestComplete for it */ - qWarning("exception on %d [will close the socket handle - hack]", i.key()->socket()); + qWarning("exception on %d [will do setdefaultif(0) - hack]", i.key()->socket()); // quick fix; there is a bug // when doing read on socket // errors not preoperly mapped // after offline-ing the device // on some devices we do get exception - ::close(i.key()->socket()); + // close all exiting sockets + // and reset default IAP + if(::setdefaultif(0) != KErrNone) // well we can't do much about it + qWarning("setdefaultif(0) failed"); + toRemove.append(i.key()); TRequestStatus *status = i.value(); QEventDispatcherSymbian::RequestComplete(d->threadData->symbian_thread_handle, status, KErrNone); diff --git a/src/corelib/kernel/qfunctions_wince.cpp b/src/corelib/kernel/qfunctions_wince.cpp index 8ad6126..e58feb3 100644 --- a/src/corelib/kernel/qfunctions_wince.cpp +++ b/src/corelib/kernel/qfunctions_wince.cpp @@ -352,16 +352,18 @@ void *qt_wince_bsearch(const void *key, size_t low = 0; size_t high = num - 1; while (low <= high) { - unsigned int mid = ((unsigned) (low + high)) >> 1; + size_t mid = (low + high) >> 1; int c = compare(key, (char*)base + mid * size); - if (c < 0) + if (c < 0) { + if (!mid) + break; high = mid - 1; - else if (c > 0) + } else if (c > 0) low = mid + 1; else return (char*) base + mid * size; } - return (NULL); + return 0; } void *lfind(const void* key, const void* base, size_t* elements, size_t size, diff --git a/src/corelib/tools/qlocale_symbian.cpp b/src/corelib/tools/qlocale_symbian.cpp index 6e36dcd..1777ba9 100644 --- a/src/corelib/tools/qlocale_symbian.cpp +++ b/src/corelib/tools/qlocale_symbian.cpp @@ -140,7 +140,7 @@ static const symbianToISO symbian_to_iso_list[] = { { ELangBrazilianPortuguese, "pt_BR" }, { ELangRomanian, "ro_RO" }, { ELangSerbian, "sr_RS" }, - { ELangLatinAmericanSpanish, "es" }, + { ELangLatinAmericanSpanish,"es_MX" }, // TODO: should be es_419 { ELangUkrainian, "uk_UA" }, { ELangUrdu, "ur_PK" }, // India/Pakistan { ELangVietnamese, "vi_VN" }, diff --git a/src/dbus/qdbusmacros.h b/src/dbus/qdbusmacros.h index 77122fc..693a350 100644 --- a/src/dbus/qdbusmacros.h +++ b/src/dbus/qdbusmacros.h @@ -48,8 +48,10 @@ #if defined(QDBUS_MAKEDLL) # define QDBUS_EXPORT Q_DECL_EXPORT -#else +#elif defined(QT_SHARED) # define QDBUS_EXPORT Q_DECL_IMPORT +#else +# define QDBUS_EXPORT #endif #ifndef Q_MOC_RUN diff --git a/src/gui/dialogs/qprintdialog_unix.cpp b/src/gui/dialogs/qprintdialog_unix.cpp index e3c62be..5d0bcac 100644 --- a/src/gui/dialogs/qprintdialog_unix.cpp +++ b/src/gui/dialogs/qprintdialog_unix.cpp @@ -973,7 +973,7 @@ void QUnixPrintWidgetPrivate::_q_btnPropertiesClicked() #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) void QUnixPrintWidgetPrivate::setCupsProperties() { - if (cups && QCUPSSupport::isAvailable()) { + if (cups && QCUPSSupport::isAvailable() && cups->pageSizes()) { QPrintEngine *engine = printer->printEngine(); const ppd_option_t* pageSizes = cups->pageSizes(); QByteArray cupsPageSize; diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 5e0d46f..fd128b8 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -3656,6 +3656,8 @@ void QGraphicsItem::setPos(const QPointF &pos) // Update and repositition. if (!(d_ptr->flags & (ItemSendsGeometryChanges | ItemSendsScenePositionChanges))) { d_ptr->setPosHelper(pos); + if (d_ptr->isWidget) + static_cast<QGraphicsWidget *>(this)->d_func()->setGeometryFromSetPos(); return; } diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 478c0c3..c486c45 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -1096,13 +1096,7 @@ QVariant QGraphicsWidget::itemChange(GraphicsItemChange change, const QVariant & } break; case ItemPositionHasChanged: - if (!d->inSetGeometry) { - d->inSetPos = 1; - // Ensure setGeometry is called (avoid recursion when setPos is - // called from within setGeometry). - setGeometry(QRectF(pos(), size())); - d->inSetPos = 0 ; - } + d->setGeometryFromSetPos(); break; case ItemParentChange: { // Deliver ParentAboutToChange. diff --git a/src/gui/graphicsview/qgraphicswidget_p.cpp b/src/gui/graphicsview/qgraphicswidget_p.cpp index 50b315a..076e8626 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.cpp +++ b/src/gui/graphicsview/qgraphicswidget_p.cpp @@ -879,6 +879,18 @@ void QGraphicsWidgetPrivate::resetHeight() q->setGeometry(QRectF(q->x(), q->y(), width(), 0)); } +void QGraphicsWidgetPrivate::setGeometryFromSetPos() +{ + if (inSetGeometry) + return; + Q_Q(QGraphicsWidget); + inSetPos = 1; + // Ensure setGeometry is called (avoid recursion when setPos is + // called from within setGeometry). + q->setGeometry(QRectF(pos, q->size())); + inSetPos = 0 ; +} + QT_END_NAMESPACE #endif //QT_NO_GRAPHICSVIEW diff --git a/src/gui/graphicsview/qgraphicswidget_p.h b/src/gui/graphicsview/qgraphicswidget_p.h index 7116a23..e9e6fc2 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.h +++ b/src/gui/graphicsview/qgraphicswidget_p.h @@ -139,6 +139,7 @@ public: qreal height() const; void setHeight(qreal); void resetHeight(); + void setGeometryFromSetPos(); // State inline int attributeToBitIndex(Qt::WidgetAttribute att) const diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index 610ac3c..d081cfd 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -484,9 +484,10 @@ void QCoeFepInputContext::applyHints(Qt::InputMethodHints hints) void QCoeFepInputContext::applyFormat(QList<QInputMethodEvent::Attribute> *attributes) { TCharFormat cFormat; - QColor styleTextColor = QApplication::palette("QLineEdit").text().color(); - TLogicalRgb tontColor(TRgb(styleTextColor.red(), styleTextColor.green(), styleTextColor.blue(), styleTextColor.alpha())); - cFormat.iFontPresentation.iTextColor = tontColor; + const QColor styleTextColor = focusWidget() ? focusWidget()->palette().text().color() : + QApplication::palette("QLineEdit").text().color(); + const TLogicalRgb fontColor(TRgb(styleTextColor.red(), styleTextColor.green(), styleTextColor.blue(), styleTextColor.alpha())); + cFormat.iFontPresentation.iTextColor = fontColor; TInt numChars = 0; TInt charPos = 0; diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 97fd6e1..6d4562a 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -1785,7 +1785,10 @@ void QAbstractItemView::mouseReleaseEvent(QMouseEvent *event) emit clicked(index); if (edited) return; - if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this)) + QStyleOptionViewItemV4 option = d->viewOptionsV4(); + if (d->pressedAlreadySelected) + option.state |= QStyle::State_Selected; + if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this)) emit activated(index); } } diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index f4c7304..3213f66 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -642,10 +642,12 @@ TKeyResponse QSymbianControl::OfferKeyEvent(const TKeyEvent& keyEvent, TEventCod QPoint pos = QCursor::pos(); TPointerEvent fakeEvent; + fakeEvent.iType = (TPointerEvent::TType)(-1); TInt x = pos.x(); TInt y = pos.y(); if (type == EEventKeyUp) { - if (keyCode == Qt::Key_Select) + if (keyCode == Qt::Key_Select && + (S60->virtualMousePressedKeys & QS60Data::Select)) fakeEvent.iType = TPointerEvent::EButton1Up; S60->virtualMouseAccel = 1; S60->virtualMouseLastKey = 0; @@ -694,8 +696,7 @@ TKeyResponse QSymbianControl::OfferKeyEvent(const TKeyEvent& keyEvent, TEventCod // example for drag'n'drop), Symbian starts producing spurious up and // down messages for some keys. Therefore, make sure we have a clean slate // of pressed keys before starting a new button press. - if (S60->virtualMousePressedKeys != 0) { - S60->virtualMousePressedKeys |= QS60Data::Select; + if (S60->virtualMousePressedKeys & QS60Data::Select) { return EKeyWasConsumed; } else { S60->virtualMousePressedKeys |= QS60Data::Select; @@ -718,7 +719,8 @@ TKeyResponse QSymbianControl::OfferKeyEvent(const TKeyEvent& keyEvent, TEventCod fakeEvent.iModifiers = keyEvent.iModifiers; fakeEvent.iPosition = cpos; fakeEvent.iParentPosition = epos; - HandlePointerEvent(fakeEvent); + if(fakeEvent.iType != -1) + HandlePointerEvent(fakeEvent); return EKeyWasConsumed; } else { diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index 50b9759..60fc5e1 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -2477,7 +2477,7 @@ extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wPa QApplication::postEvent(widget, new QEvent(QEvent::Close)); else #ifndef QT_NO_MENUBAR - QMenuBar::wceCommands(LOWORD(wParam), (HWND) lParam); + QMenuBar::wceCommands(LOWORD(wParam)); #endif result = true; } diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index a0429d3..02e7cb8 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -387,7 +387,6 @@ void QWidgetPrivate::create_sys(WId window, bool /* initializeWindow */, bool de | EPointerFilterMove | EPointerFilterDrag, 0); drawableWindow->EnableVisibilityChangeEvents(); - s60UpdateIsOpaque(); } q->setAttribute(Qt::WA_WState_Created); @@ -400,6 +399,9 @@ void QWidgetPrivate::create_sys(WId window, bool /* initializeWindow */, bool de // this generates a WinIdChanged event. setWinId(control.take()); + if (!desktop) + s60UpdateIsOpaque(); // must be called after setWinId() + } else if (q->testAttribute(Qt::WA_NativeWindow) || paintOnScreen()) { // create native child widget QScopedPointer<QSymbianControl> control( q_check_ptr(new QSymbianControl(q)) ); diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 898a996..596649e 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5977,12 +5977,17 @@ void QPainter::drawText(const QPointF &p, const QString &str, int tf, int justif gf.glyphs = engine.shapedGlyphs(&si); gf.chars = engine.layoutData->string.unicode() + si.position; gf.num_chars = engine.length(item); - gf.width = si.width; + if (engine.forceJustification) { + for (int j=0; j<gf.glyphs.numGlyphs; ++j) + gf.width += gf.glyphs.effectiveAdvance(j); + } else { + gf.width = si.width; + } gf.logClusters = engine.logClusters(&si); drawTextItem(QPointF(x.toReal(), p.y()), gf); - x += si.width; + x += gf.width; } } diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 44049c0..6e02435 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -971,12 +971,17 @@ void QPdfBaseEngine::drawPoints (const QPointF *points, int pointCount) if (!points) return; + Q_D(QPdfBaseEngine); QPainterPath p; for (int i=0; i!=pointCount;++i) { p.moveTo(points[i]); p.lineTo(points[i] + QPointF(0, 0.001)); } + + bool hadBrush = d->hasBrush; + d->hasBrush = false; drawPath(p); + d->hasBrush = hadBrush; } void QPdfBaseEngine::drawLines (const QLineF *lines, int lineCount) @@ -984,12 +989,16 @@ void QPdfBaseEngine::drawLines (const QLineF *lines, int lineCount) if (!lines) return; + Q_D(QPdfBaseEngine); QPainterPath p; for (int i=0; i!=lineCount;++i) { p.moveTo(lines[i].p1()); p.lineTo(lines[i].p2()); } + bool hadBrush = d->hasBrush; + d->hasBrush = false; drawPath(p); + d->hasBrush = hadBrush; } void QPdfBaseEngine::drawRects (const QRectF *rects, int rectCount) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 20297ae..d28e1d9 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -92,10 +92,10 @@ static const qreal goldenRatio = 1.618; const layoutHeader QS60StylePrivate::m_layoutHeaders[] = { // *** generated layout data *** -{240,320,1,18,"QVGA Landscape"}, -{320,240,1,18,"QVGA Portrait"}, -{360,640,1,18,"NHD Landscape"}, -{640,360,1,18,"NHD Portrait"}, +{240,320,1,19,"QVGA Landscape"}, +{320,240,1,19,"QVGA Portrait"}, +{360,640,1,19,"NHD Landscape"}, +{640,360,1,19,"NHD Portrait"}, {352,800,1,12,"E90 Landscape"} // *** End of generated data *** }; @@ -104,11 +104,11 @@ const int QS60StylePrivate::m_numberOfLayouts = const short QS60StylePrivate::data[][MAX_PIXELMETRICS] = { // *** generated pixel metrics *** -{5,0,-909,0,0,2,0,0,-1,7,12,19,13,13,6,200,-909,-909,-909,20,13,2,0,0,21,7,18,30,3,3,1,-909,-909,0,1,0,0,12,20,15,15,18,18,1,115,18,0,-909,-909,-909,-909,0,0,16,2,-909,0,0,-909,16,-909,-909,-909,-909,32,18,55,24,55,4,4,4,9,13,-909,5,51,11,5,0,3,3,6,8,3,3,-909,2,-909,-909,-909,-909,5,5,3,1, 106}, -{5,0,-909,0,0,1,0,0,-1,8,14,22,15,15,7,164,-909,-909,-909,19,15,2,0,0,21,8,27,28,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,65,27,65,3,3,5,10,15,-909,5,58,13,5,0,4,4,7,9,4,4,-909,2,-909,-909,-909,-909,6,6,3,1, 106}, -{7,0,-909,0,0,2,0,0,-1,25,69,28,19,19,9,258,-909,-909,-909,23,19,26,0,0,32,25,72,44,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,2,-909,0,0,-909,25,-909,-909,-909,-909,87,27,77,35,77,13,13,6,8,19,-909,7,74,19,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1, 135}, -{7,0,-909,0,0,2,0,0,-1,25,68,28,19,19,9,258,-909,-909,-909,31,19,6,0,0,32,25,60,52,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,2,-909,0,0,-909,26,-909,-909,-909,-909,87,27,96,35,96,12,12,6,8,19,-909,7,74,22,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1, 135}, -{7,0,-909,0,0,2,0,0,-1,10,20,27,18,18,9,301,-909,-909,-909,29,18,5,0,0,35,7,32,30,5,5,2,-909,-909,0,2,8,0,16,28,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,6,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,19,7,0,5,6,8,11,6,5,-909,2,-909,-909,-909,-909,5,5,3,1, 106} +{5,0,-909,0,0,2,0,0,-1,7,12,22,15,15,7,198,-909,-909,-909,20,13,2,0,0,21,7,18,30,3,3,1,-909,-909,0,1,0,0,12,20,15,15,18,18,1,115,18,0,-909,-909,-909,-909,0,0,16,2,-909,0,0,-909,16,-909,-909,-909,-909,32,18,55,24,55,4,4,4,9,13,-909,5,51,11,5,0,3,3,6,8,3,3,-909,2,-909,-909,-909,-909,5,5,3,1,106}, +{5,0,-909,0,0,1,0,0,-1,8,14,22,15,15,7,164,-909,-909,-909,19,15,2,0,0,21,8,27,28,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,65,27,65,3,3,5,10,15,-909,5,58,13,5,0,4,4,7,9,4,4,-909,2,-909,-909,-909,-909,6,6,3,1,106}, +{7,0,-909,0,0,2,0,0,-1,25,69,46,37,37,9,258,-909,-909,-909,23,19,26,0,0,32,25,72,44,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,2,-909,0,0,-909,25,-909,-909,-909,-909,87,27,77,35,77,13,13,6,8,19,-909,7,74,19,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1,135}, +{7,0,-909,0,0,2,0,0,-1,25,68,46,37,37,9,258,-909,-909,-909,31,19,6,0,0,32,25,60,52,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,2,-909,0,0,-909,26,-909,-909,-909,-909,87,27,96,35,96,12,12,6,8,19,-909,7,74,22,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1,135}, +{7,0,-909,0,0,2,0,0,-1,10,20,27,18,18,9,301,-909,-909,-909,29,18,5,0,0,35,7,32,30,5,5,2,-909,-909,0,2,8,0,16,28,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,6,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,19,7,0,5,6,8,11,6,5,-909,2,-909,-909,-909,-909,5,5,3,1,106} // *** End of generated data *** }; @@ -653,6 +653,8 @@ void QS60StylePrivate::setFont(QWidget *widget) const fontCategory = QS60StyleEnums::FC_Primary; } else if (qobject_cast<QMenu *>(widget)){ fontCategory = QS60StyleEnums::FC_Primary; + } else if (qobject_cast<QCalendarWidget *>(widget)){ + fontCategory = QS60StyleEnums::FC_Secondary; } if (fontCategory != QS60StyleEnums::FC_Undefined) { const bool resolveFontSize = widget->testAttribute(Qt::WA_SetFont) @@ -813,12 +815,6 @@ void QS60StylePrivate::setThemePaletteHash(QPalette *palette) const widgetPalette.setColor(QPalette::HighlightedText, s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0)); QApplication::setPalette(widgetPalette, "QLineEdit"); - widgetPalette = *palette; - - widgetPalette.setColor(QPalette::Text, - s60Color(QS60StyleEnums::CL_QsnTextColors, 27, 0)); - widgetPalette.setColor(QPalette::HighlightedText, - s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0)); QApplication::setPalette(widgetPalette, "QTextEdit"); widgetPalette = *palette; @@ -880,7 +876,6 @@ QSize QS60StylePrivate::partSize(QS60StyleEnums::SkinParts part, SkinElementFlag case QS60StyleEnums::SP_QgnGrafNsliderEndLeft: case QS60StyleEnums::SP_QgnGrafNsliderEndRight: case QS60StyleEnums::SP_QgnGrafNsliderMiddle: - result.setWidth(result.height() >> 1); break; case QS60StyleEnums::SP_QgnGrafNsliderMarker: @@ -1120,11 +1115,9 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom tool.rect = button.unite(menuRect); tool.state = bflags; const QToolButton *toolButtonWidget = qobject_cast<const QToolButton *>(widget); - QS60StylePrivate::SkinElements element; - if (toolButtonWidget) - element = (toolButtonWidget->isDown()) ? QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton; - else - element = (option->state & State_Sunken) ? QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton; + const QS60StylePrivate::SkinElements element = + ((toolButtonWidget && toolButtonWidget->isDown()) || (option->state & State_Sunken)) ? + QS60StylePrivate::SE_ToolBarButtonPressed : QS60StylePrivate::SE_ToolBarButton; QS60StylePrivate::drawSkinElement(element, painter, tool.rect, flags); drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); } @@ -1534,13 +1527,13 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, QS60StylePrivate::SE_TabBarTabNorthInactive; break; } - if (skinElement==QS60StylePrivate::SE_TabBarTabEastInactive|| - skinElement==QS60StylePrivate::SE_TabBarTabNorthInactive|| - skinElement==QS60StylePrivate::SE_TabBarTabSouthInactive|| - skinElement==QS60StylePrivate::SE_TabBarTabWestInactive|| - skinElement==QS60StylePrivate::SE_TabBarTabEastActive|| - skinElement==QS60StylePrivate::SE_TabBarTabNorthActive|| - skinElement==QS60StylePrivate::SE_TabBarTabSouthActive|| + if (skinElement == QS60StylePrivate::SE_TabBarTabEastInactive || + skinElement == QS60StylePrivate::SE_TabBarTabNorthInactive || + skinElement == QS60StylePrivate::SE_TabBarTabSouthInactive || + skinElement == QS60StylePrivate::SE_TabBarTabWestInactive || + skinElement == QS60StylePrivate::SE_TabBarTabEastActive || + skinElement == QS60StylePrivate::SE_TabBarTabNorthActive || + skinElement == QS60StylePrivate::SE_TabBarTabSouthActive || skinElement==QS60StylePrivate::SE_TabBarTabWestActive) { const int borderThickness = QS60StylePrivate::pixelMetric(PM_DefaultFrameWidth); @@ -2052,16 +2045,17 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti case PE_FrameFocusRect: { //Draw themed highlight to radiobuttons and checkboxes. //For other widgets skip, unless palette has been modified. In that case, draw with commonstyle. - if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color()) + if (option->palette.highlight().color() == QS60StylePrivate::themePalette()->highlight().color()) { if ((qstyleoption_cast<const QStyleOptionFocusRect *>(option) && (qobject_cast<const QRadioButton *>(widget) || qobject_cast<const QCheckBox *>(widget)))) QS60StylePrivate::drawSkinElement( QS60StylePrivate::isWidgetPressed(widget) ? QS60StylePrivate::SE_ListItemPressed : QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags); - else + } else { commonStyleDraws = true; } + } break; #ifndef QT_NO_LINEEDIT case PE_PanelLineEdit: @@ -2361,41 +2355,43 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti #endif QCommonStyle::drawPrimitive(element, option, painter, widget); } else { - const bool rightLine = option->state & State_Item; - const bool downLine = option->state & State_Sibling; - const bool upLine = option->state & (State_Open | State_Children | State_Item | State_Sibling); - - QS60StyleEnums::SkinParts skinPart; - bool drawSkinPart = false; - if (rightLine && downLine && upLine) { - skinPart = QS60StyleEnums::SP_QgnIndiHlLineBranch; - drawSkinPart = true; - } else if (rightLine && upLine) { - skinPart = QS60StyleEnums::SP_QgnIndiHlLineEnd; - drawSkinPart = true; - } else if (upLine && downLine) { - skinPart = QS60StyleEnums::SP_QgnIndiHlLineStraight; - drawSkinPart = true; - } - - if (drawSkinPart) - QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, flags); + if (const QStyleOptionViewItemV2 *vopt = qstyleoption_cast<const QStyleOptionViewItemV2 *>(option)) { + const bool rightLine = option->state & State_Item; + const bool downLine = option->state & State_Sibling; + const bool upLine = option->state & (State_Open | State_Children | State_Item | State_Sibling); + QS60StylePrivate::SkinElementFlags adjustedFlags = flags; + + QS60StyleEnums::SkinParts skinPart; + bool drawSkinPart = false; + if (rightLine && downLine && upLine) { + skinPart = QS60StyleEnums::SP_QgnIndiHlLineBranch; + drawSkinPart = true; + } else if (rightLine && upLine) { + skinPart = QS60StyleEnums::SP_QgnIndiHlLineEnd; + drawSkinPart = true; + } else if (upLine && downLine) { + skinPart = QS60StyleEnums::SP_QgnIndiHlLineStraight; + drawSkinPart = true; + } - if (option->state & State_Children) { - QS60StyleEnums::SkinParts skinPart = - (option->state & State_Open) ? QS60StyleEnums::SP_QgnIndiHlColSuper : QS60StyleEnums::SP_QgnIndiHlExpSuper; - int minDimension = qMin(option->rect.width(), option->rect.height()); - QRect iconRect(option->rect.topLeft(), QSize(minDimension, minDimension)); - const int magicTweak = 3; - int resizeValue = minDimension >> 1; - if (!QS60StylePrivate::isTouchSupported()) { - minDimension += resizeValue; // Adjust the icon bigger because of empty space in svg icon. - iconRect.setSize(QSize(minDimension, minDimension)); - const int verticalMagic = (option->rect.width() <= option->rect.height()) ? magicTweak : 0; - resizeValue = verticalMagic - resizeValue; + if (option->direction == Qt::RightToLeft) + adjustedFlags |= QS60StylePrivate::SF_Mirrored_X_Axis; + + if (drawSkinPart) + QS60StylePrivate::drawSkinPart(skinPart, painter, option->rect, adjustedFlags); + + if (option->state & State_Children) { + QS60StyleEnums::SkinParts skinPart = + (option->state & State_Open) ? QS60StyleEnums::SP_QgnIndiHlColSuper : QS60StyleEnums::SP_QgnIndiHlExpSuper; + const QRect selectionRect = subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget); + const int minDimension = qMin(option->rect.width(), option->rect.height()); + const int magicTweak = (option->direction == Qt::RightToLeft) ? -3 : 3; //@todo: magic + //The branch indicator icon in S60 is supposed to be superimposed on top of branch lines. + QRect iconRect(QPoint(option->rect.left() + magicTweak, selectionRect.top() + 1), QSize(minDimension, minDimension)); + if (!QS60StylePrivate::isTouchSupported()) + iconRect.translate(0, -4); //@todo: magic + QS60StylePrivate::drawSkinPart(skinPart, painter, iconRect, adjustedFlags); } - iconRect.translate(magicTweak, resizeValue); - QS60StylePrivate::drawSkinPart(skinPart, painter, iconRect, flags); } } break; @@ -2478,6 +2474,12 @@ int QS60Style::pixelMetric(PixelMetric metric, const QStyleOption *option, const //double the top layout margin for dialogs, it is very close to real value //without having to define custom pixel metric metricValue *= 2; + + if (widget && (metric == PM_FocusFrameHMargin)) + if (qobject_cast<const QTableView *>(widget)) + //Halve the focus frame margin for table items + metricValue /= 2; + return metricValue; } @@ -2503,7 +2505,7 @@ QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt, sz += QSize(pixelMetric(PM_IndicatorWidth) + pixelMetric(PM_CheckBoxLabelSpacing), 0); const int iconHeight = (!buttonWidget->icon().isNull()) ? buttonWidget->iconSize().height() : 0; const int textHeight = (buttonWidget->text().length() > 0) ? - buttonWidget->fontMetrics().size(Qt::TextSingleLine, buttonWidget->text()).height() : 0; + buttonWidget->fontMetrics().size(Qt::TextSingleLine, buttonWidget->text()).height() : opt->fontMetrics.height(); const int decoratorHeight = (buttonWidget->isCheckable()) ? pixelMetric(PM_IndicatorHeight) : 0; const int contentHeight = @@ -2573,7 +2575,7 @@ QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt, int QS60Style::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *hret) const { - int retValue = -1; + int retValue = 0; switch (sh) { case SH_RequestSoftwareInputPanel: if (QS60StylePrivate::isSingleClickUi()) @@ -2608,9 +2610,13 @@ int QS60Style::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w case SH_Dial_BackgroundRole: retValue = QPalette::Base; break; - case SH_ItemView_ActivateItemOnSingleClick: - retValue = QS60StylePrivate::isSingleClickUi(); + case SH_ItemView_ActivateItemOnSingleClick: { + if (QS60StylePrivate::isSingleClickUi()) + retValue = true; + else if (opt && opt->state & QStyle::State_Selected) + retValue = true; break; + } case SH_ProgressDialog_TextLabelAlignment: retValue = (QApplication::layoutDirection() == Qt::LeftToRight) ? Qt::AlignLeft : @@ -3002,7 +3008,7 @@ QRect QS60Style::subElementRect(SubElement element, const QStyleOption *opt, con } break; case SE_ItemViewItemCheckIndicator: - if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { + if (const QStyleOptionViewItemV2 *vopt = qstyleoption_cast<const QStyleOptionViewItemV2 *>(opt)) { const QListWidget *listItem = qobject_cast<const QListWidget *>(widget); const bool singleSelection = listItem && diff --git a/src/gui/styles/qs60style_p.h b/src/gui/styles/qs60style_p.h index 9dd3810..d8c31f8 100644 --- a/src/gui/styles/qs60style_p.h +++ b/src/gui/styles/qs60style_p.h @@ -476,6 +476,8 @@ public: SF_StateDisabled = 0x0020, SF_ColorSkinned = 0x0040, // pixmap is colored with foreground pen color SF_Animation = 0x0080, + SF_Mirrored_X_Axis = 0x0100, + SF_Mirrored_Y_Axis = 0x0200 }; enum CacheClearReason { diff --git a/src/gui/styles/qs60style_s60.cpp b/src/gui/styles/qs60style_s60.cpp index 46de9ef..c1223af 100644 --- a/src/gui/styles/qs60style_s60.cpp +++ b/src/gui/styles/qs60style_s60.cpp @@ -654,6 +654,14 @@ QPixmap QS60StyleModeSpecifics::fromFbsBitmap(CFbsBitmap *icon, CFbsBitmap *mask pixmap = QPixmap::fromImage(iconImage); } + if ((flags & QS60StylePrivate::SF_Mirrored_X_Axis) || + (flags & QS60StylePrivate::SF_Mirrored_Y_Axis)) { + QImage iconImage = pixmap.toImage().mirrored( + flags & QS60StylePrivate::SF_Mirrored_X_Axis, + flags & QS60StylePrivate::SF_Mirrored_Y_Axis); + pixmap = QPixmap::fromImage(iconImage); + } + return pixmap; } @@ -969,7 +977,7 @@ void QS60StyleModeSpecifics::frameIdAndCenterId(QS60StylePrivate::SkinFrameEleme switch(frameElement) { case QS60StylePrivate::SF_ToolTip: - if (QSysInfo::s60Version()!=QSysInfo::SV_S60_3_1) { + if (QSysInfo::s60Version() != QSysInfo::SV_S60_3_1) { centerId.Set(EAknsMajorGeneric, 0x19c2); frameId.Set(EAknsMajorSkin, 0x5300); } else { @@ -978,7 +986,8 @@ void QS60StyleModeSpecifics::frameIdAndCenterId(QS60StylePrivate::SkinFrameEleme } break; case QS60StylePrivate::SF_ToolBar: - if (QSysInfo::s60Version()==QSysInfo::SV_S60_3_1 || QSysInfo::s60Version()==QSysInfo::SV_S60_3_2) { + if (QSysInfo::s60Version() == QSysInfo::SV_S60_3_1 || + QSysInfo::s60Version() == QSysInfo::SV_S60_3_2) { centerId.Set(KAknsIIDQsnFrPopupCenterSubmenu); frameId.Set(KAknsIIDQsnFrPopupSub); } diff --git a/src/gui/styles/qwindowsmobilestyle.cpp b/src/gui/styles/qwindowsmobilestyle.cpp index 5f939d0..67eb1ef 100644 --- a/src/gui/styles/qwindowsmobilestyle.cpp +++ b/src/gui/styles/qwindowsmobilestyle.cpp @@ -5356,6 +5356,50 @@ void QWindowsMobileStyle::drawPrimitive(PrimitiveElement element, const QStyleOp painter->setPen(option->palette.text().color()); painter->drawLines(a); break; } + case PE_IndicatorBranch: { + // Copied from the Windows style. + static const int decoration_size = d->doubleControls ? 18 : 9; + static const int ofsA = d->doubleControls ? 4 : 2; + static const int ofsB = d->doubleControls ? 8 : 4; + static const int ofsC = d->doubleControls ? 12 : 6; + static const int ofsD = d->doubleControls ? 1 : 0; + int mid_h = option->rect.x() + option->rect.width() / 2; + int mid_v = option->rect.y() + option->rect.height() / 2; + int bef_h = mid_h; + int bef_v = mid_v; + int aft_h = mid_h; + int aft_v = mid_v; + if (option->state & State_Children) { + int delta = decoration_size / 2; + bef_h -= delta; + bef_v -= delta; + aft_h += delta; + aft_v += delta; + QPen oldPen = painter->pen(); + QPen crossPen = oldPen; + crossPen.setWidth(2); + painter->setPen(crossPen); + painter->drawLine(bef_h + ofsA + ofsD, bef_v + ofsB + ofsD, bef_h + ofsC + ofsD, bef_v + ofsB + ofsD); + if (!(option->state & State_Open)) + painter->drawLine(bef_h + ofsB + ofsD, bef_v + ofsA + ofsD, bef_h + ofsB + ofsD, bef_v + ofsC + ofsD); + painter->setPen(option->palette.dark().color()); + painter->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1); + if (d->doubleControls) + painter->drawRect(bef_h + 1, bef_v + 1, decoration_size - 3, decoration_size - 3); + painter->setPen(oldPen); + } + QBrush brush(option->palette.dark().color(), Qt::Dense4Pattern); + if (option->state & State_Item) { + if (option->direction == Qt::RightToLeft) + painter->fillRect(option->rect.left(), mid_v, bef_h - option->rect.left(), 1, brush); + else + painter->fillRect(aft_h, mid_v, option->rect.right() - aft_h + 1, 1, brush); + } + if (option->state & State_Sibling) + painter->fillRect(mid_h, aft_v, 1, option->rect.bottom() - aft_v + 1, brush); + if (option->state & (State_Open | State_Children | State_Item | State_Sibling)) + painter->fillRect(mid_h, option->rect.y(), 1, bef_v - option->rect.y(), brush); + break; } case PE_Frame: qDrawPlainRect(painter, option->rect, option->palette.shadow().color(), d->doubleControls ? 2 : 1, &option->palette.background()); diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 21a31a3..c229242 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -805,6 +805,9 @@ QFont::QFont(const QString &family, int pointSize, int weight, bool italic) resolve_mask |= QFont::WeightResolved | QFont::StyleResolved; } + if (italic) + resolve_mask |= QFont::StyleResolved; + d->request.family = family; d->request.pointSize = qreal(pointSize); d->request.pixelSize = -1; diff --git a/src/gui/text/qfontdatabase_s60.cpp b/src/gui/text/qfontdatabase_s60.cpp index 95774f9..489b70b 100644 --- a/src/gui/text/qfontdatabase_s60.cpp +++ b/src/gui/text/qfontdatabase_s60.cpp @@ -113,6 +113,7 @@ QSymbianFontDatabaseExtrasImplementation::QSymbianFontDatabaseExtrasImplementati QStringList filters; filters.append(QLatin1String("*.ttf")); filters.append(QLatin1String("*.ccc")); + filters.append(QLatin1String("*.ltt")); const QFileInfoList fontFiles = alternativeFilePaths(QLatin1String("resource\\Fonts"), filters); const TInt heapMinLength = 0x1000; diff --git a/src/gui/util/qsystemtrayicon_win.cpp b/src/gui/util/qsystemtrayicon_win.cpp index 8e482e0..c89fbae 100644 --- a/src/gui/util/qsystemtrayicon_win.cpp +++ b/src/gui/util/qsystemtrayicon_win.cpp @@ -60,17 +60,9 @@ #include <QDesktopWidget> #include <QSettings> -#if defined(Q_WS_WINCE) && !defined(STANDARDSHELL_UI_MODEL) -# include <streams.h> -#endif - QT_BEGIN_NAMESPACE -#if defined(Q_WS_WINCE) -static const UINT q_uNOTIFYICONID = 13; // IDs from 0 to 12 are reserved on WinCE. -#else static const UINT q_uNOTIFYICONID = 0; -#endif static uint MYWM_TASKBARCREATED = 0; #define MYWM_NOTIFYICON (WM_APP+101) @@ -124,23 +116,15 @@ bool QSystemTrayIconSys::allowsMessages() bool QSystemTrayIconSys::supportsMessages() { -#ifndef Q_OS_WINCE return allowsMessages(); -#endif - return false; } QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object) : hIcon(0), q(object), ignoreNextMouseRelease(false) { -#ifndef Q_OS_WINCE notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, guidItem); // NOTIFYICONDATAW_V2_SIZE; maxTipLength = 128; -#else - notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, szTip[64]); // NOTIFYICONDATAW_V1_SIZE; - maxTipLength = 64; -#endif // For restoring the tray icon after explorer crashes if (!MYWM_TASKBARCREATED) { @@ -316,24 +300,13 @@ bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) case WM_RBUTTONUP: if (q->contextMenu()) { q->contextMenu()->popup(gpos); -#if defined(Q_WS_WINCE) - // We must ensure that the popup menu doesn't show up behind the task bar. - QRect desktopRect = qApp->desktop()->availableGeometry(); - int maxY = desktopRect.y() + desktopRect.height() - q->contextMenu()->height(); - if (gpos.y() > maxY) { - gpos.ry() = maxY; - q->contextMenu()->move(gpos); - } -#endif } emit q->activated(QSystemTrayIcon::Context); break; -#if !defined(Q_WS_WINCE) case NIN_BALLOONUSERCLICK: emit q->messageClicked(); break; -#endif case WM_MBUTTONUP: emit q->activated(QSystemTrayIcon::MiddleClick); @@ -400,23 +373,11 @@ QRect QSystemTrayIconSys::findIconGeometry(const int iconId) //find the toolbar used in the notification area if (trayHandle) { -#if defined(Q_OS_WINCE) - trayHandle = FindWindow(L"TrayNotifyWnd", NULL); -#else trayHandle = FindWindowEx(trayHandle, NULL, L"TrayNotifyWnd", NULL); -#endif if (trayHandle) { -#if defined(Q_OS_WINCE) - HWND hwnd = FindWindow(L"SysPager", NULL); -#else HWND hwnd = FindWindowEx(trayHandle, NULL, L"SysPager", NULL); -#endif if (hwnd) { -#if defined(Q_OS_WINCE) - hwnd = FindWindow(L"ToolbarWindow32", NULL); -#else hwnd = FindWindowEx(hwnd, NULL, L"ToolbarWindow32", NULL); -#endif if (hwnd) trayHandle = hwnd; } @@ -435,11 +396,7 @@ QRect QSystemTrayIconSys::findIconGeometry(const int iconId) return ret; int buttonCount = SendMessage(trayHandle, TB_BUTTONCOUNT, 0, 0); -#if defined(Q_OS_WINCE) - LPVOID data = VirtualAlloc(NULL, sizeof(TBBUTTON), MEM_COMMIT, PAGE_READWRITE); -#else LPVOID data = VirtualAllocEx(trayProcess, NULL, sizeof(TBBUTTON), MEM_COMMIT, PAGE_READWRITE); -#endif if ( buttonCount < 1 || !data ) { CloseHandle(trayProcess); @@ -477,11 +434,7 @@ QRect QSystemTrayIconSys::findIconGeometry(const int iconId) } } } -#if defined(Q_OS_WINCE) - VirtualFree(data, 0, MEM_RELEASE); -#else VirtualFreeEx(trayProcess, data, 0, MEM_RELEASE); -#endif CloseHandle(trayProcess); return ret; } @@ -555,16 +508,10 @@ void QSystemTrayIconPrivate::updateMenu_sys() void QSystemTrayIconPrivate::updateToolTip_sys() { -#ifdef Q_WS_WINCE - // Calling sys->trayMessage(NIM_MODIFY) on an existing icon is broken on Windows CE. - // So we need to call updateIcon_sys() which creates a new icon handle. - updateIcon_sys(); -#else if (!sys) return; sys->trayMessage(NIM_MODIFY); -#endif } bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() diff --git a/src/gui/util/qsystemtrayicon_wince.cpp b/src/gui/util/qsystemtrayicon_wince.cpp new file mode 100644 index 0000000..0a0d340 --- /dev/null +++ b/src/gui/util/qsystemtrayicon_wince.cpp @@ -0,0 +1,296 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "qsystemtrayicon_p.h" +#ifndef QT_NO_SYSTEMTRAYICON +#define _WIN32_IE 0x0600 //required for NOTIFYICONDATA_V2_SIZE + +#include <qt_windows.h> +#include <shlwapi.h> +#include <QApplication> + +QT_BEGIN_NAMESPACE + +static const UINT q_uNOTIFYICONID = 13; // IDs from 0 to 12 are reserved on WinCE. +#define MYWM_NOTIFYICON (WM_APP+101) + +struct Q_NOTIFYICONIDENTIFIER { + DWORD cbSize; + HWND hWnd; + UINT uID; + GUID guidItem; +}; + +class QSystemTrayIconSys : QWidget +{ +public: + QSystemTrayIconSys(QSystemTrayIcon *object); + ~QSystemTrayIconSys(); + bool winEvent( MSG *m, long *result ); + bool trayMessage(DWORD msg); + void setIconContents(NOTIFYICONDATA &data); + void createIcon(); + QRect findTrayGeometry(); + HICON hIcon; + QPoint globalPos; + QSystemTrayIcon *q; +private: + uint notifyIconSize; + int maxTipLength; + bool ignoreNextMouseRelease; +}; + +QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object) + : hIcon(0), q(object), ignoreNextMouseRelease(false) + +{ + notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, szTip[64]); // NOTIFYICONDATAW_V1_SIZE; + maxTipLength = 64; +} + +QSystemTrayIconSys::~QSystemTrayIconSys() +{ + if (hIcon) + DestroyIcon(hIcon); +} + +QRect QSystemTrayIconSys::findTrayGeometry() +{ + // Use lower right corner as fallback + QPoint brCorner = qApp->desktop()->screenGeometry().bottomRight(); + QRect ret(brCorner.x() - 10, brCorner.y() - 10, 10, 10); + return ret; +} + +void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd) +{ + tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; + tnd.uCallbackMessage = MYWM_NOTIFYICON; + tnd.hIcon = hIcon; + QString tip = q->toolTip(); + + if (!tip.isNull()) { + tip = tip.left(maxTipLength - 1) + QChar(); + memcpy(tnd.szTip, tip.utf16(), qMin(tip.length() + 1, maxTipLength) * sizeof(wchar_t)); + } +} + +bool QSystemTrayIconSys::trayMessage(DWORD msg) +{ + NOTIFYICONDATA tnd; + memset(&tnd, 0, notifyIconSize); + tnd.uID = q_uNOTIFYICONID; + tnd.cbSize = notifyIconSize; + tnd.hWnd = winId(); + + Q_ASSERT(testAttribute(Qt::WA_WState_Created)); + + if (msg != NIM_DELETE) { + setIconContents(tnd); + } + + return Shell_NotifyIcon(msg, &tnd); +} + +void QSystemTrayIconSys::createIcon() +{ + hIcon = 0; + QIcon icon = q->icon(); + if (icon.isNull()) + return; + + //const QSize preferredSize(GetSystemMetrics(SM_CXSMICON) * 2, GetSystemMetrics(SM_CYSMICON) * 2); + const QSize preferredSize(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); + QPixmap pm = icon.pixmap(preferredSize); + if (pm.isNull()) + return; + + hIcon = pm.toWinHICON(); +} + +bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) +{ + switch(m->message) { + case WM_CREATE: + SetWindowLong(winId(), GWL_USERDATA, (LONG)((CREATESTRUCTW*)m->lParam)->lpCreateParams); + break; + + case MYWM_NOTIFYICON: + { + RECT r; + GetWindowRect(winId(), &r); + QEvent *e = 0; + Qt::KeyboardModifiers keys = QApplication::keyboardModifiers(); + QPoint gpos = QCursor::pos(); + + switch (m->lParam) { + case WM_LBUTTONUP: + if (ignoreNextMouseRelease) + ignoreNextMouseRelease = false; + else + emit q->activated(QSystemTrayIcon::Trigger); + break; + + case WM_LBUTTONDBLCLK: + ignoreNextMouseRelease = true; // Since DBLCLICK Generates a second mouse + // release we must ignore it + emit q->activated(QSystemTrayIcon::DoubleClick); + break; + + case WM_RBUTTONUP: + if (q->contextMenu()) { + q->contextMenu()->popup(gpos); + + // We must ensure that the popup menu doesn't show up behind the task bar. + QRect desktopRect = qApp->desktop()->availableGeometry(); + int maxY = desktopRect.y() + desktopRect.height() - q->contextMenu()->height(); + if (gpos.y() > maxY) { + gpos.ry() = maxY; + q->contextMenu()->move(gpos); + } + } + emit q->activated(QSystemTrayIcon::Context); + break; + + case WM_MBUTTONUP: + emit q->activated(QSystemTrayIcon::MiddleClick); + break; + default: + break; + } + if (e) { + bool res = QApplication::sendEvent(q, e); + delete e; + return res; + } + break; + } + default: + return QWidget::winEvent(m, result); + } + return 0; +} + +void QSystemTrayIconPrivate::install_sys() +{ + Q_Q(QSystemTrayIcon); + if (!sys) { + sys = new QSystemTrayIconSys(q); + sys->createIcon(); + sys->trayMessage(NIM_ADD); + } +} + +void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, int timeOut) +{ + if (!sys) + return; + + uint uSecs = 0; + if ( timeOut < 0) + uSecs = 10000; //10 sec default + else uSecs = (int)timeOut; + + //message is limited to 255 chars + NULL + QString messageString; + if (message.isEmpty() && !title.isEmpty()) + messageString = QLatin1Char(' '); //ensures that the message shows when only title is set + else + messageString = message.left(255) + QChar(); + + //title is limited to 63 chars + NULL + QString titleString = title.left(63) + QChar(); + + //show QBalloonTip + QRect trayRect = sys->findTrayGeometry(); + QBalloonTip::showBalloon(type, title, message, sys->q, QPoint(trayRect.left(), + trayRect.center().y()), uSecs, false); +} + +QRect QSystemTrayIconPrivate::geometry_sys() const +{ + return QRect(); +} + +void QSystemTrayIconPrivate::remove_sys() +{ + if (!sys) + return; + + sys->trayMessage(NIM_DELETE); + delete sys; + sys = 0; +} + +void QSystemTrayIconPrivate::updateIcon_sys() +{ + if (!sys) + return; + + HICON hIconToDestroy = sys->hIcon; + + sys->createIcon(); + sys->trayMessage(NIM_MODIFY); + + if (hIconToDestroy) + DestroyIcon(hIconToDestroy); +} + +void QSystemTrayIconPrivate::updateMenu_sys() +{ + +} + +void QSystemTrayIconPrivate::updateToolTip_sys() +{ + // Calling sys->trayMessage(NIM_MODIFY) on an existing icon is broken on Windows CE. + // So we need to call updateIcon_sys() which creates a new icon handle. + updateIcon_sys(); +} + +bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() +{ + return true; +} + +QT_END_NAMESPACE + +#endif diff --git a/src/gui/util/util.pri b/src/gui/util/util.pri index bd2af85..be8db93 100644 --- a/src/gui/util/util.pri +++ b/src/gui/util/util.pri @@ -20,7 +20,10 @@ SOURCES += \ util/qundoview.cpp -win32 { +wince* { + SOURCES += \ + util/qsystemtrayicon_wince.cpp +} else:win32 { SOURCES += \ util/qsystemtrayicon_win.cpp } diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index e0b09aa..1504066 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -152,7 +152,10 @@ QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewIt menuOption.icon = qvariant_cast<QPixmap>(variant); break; } - + if (qVariantCanConvert<QBrush>(index.data(Qt::BackgroundRole))) { + menuOption.palette.setBrush(QPalette::All, QPalette::Background, + qvariant_cast<QBrush>(index.data(Qt::BackgroundRole))); + } menuOption.text = index.model()->data(index, Qt::DisplayRole).toString() .replace(QLatin1Char('&'), QLatin1String("&&")); menuOption.tabWidth = 0; diff --git a/src/gui/widgets/qmenu.h b/src/gui/widgets/qmenu.h index a040afa..7708e05 100644 --- a/src/gui/widgets/qmenu.h +++ b/src/gui/widgets/qmenu.h @@ -142,7 +142,7 @@ public: #endif #ifdef Q_WS_WINCE - HMENU wceMenu(bool create = false); + HMENU wceMenu(); #endif bool separatorsCollapsible() const; diff --git a/src/gui/widgets/qmenu_p.h b/src/gui/widgets/qmenu_p.h index 39cbbd8..33283fd 100644 --- a/src/gui/widgets/qmenu_p.h +++ b/src/gui/widgets/qmenu_p.h @@ -358,7 +358,7 @@ public: return 0; } } *wce_menu; - HMENU wceMenu(bool create = false); + HMENU wceMenu(); QAction* wceCommands(uint command); #endif #if defined(Q_WS_S60) diff --git a/src/gui/widgets/qmenu_wince.cpp b/src/gui/widgets/qmenu_wince.cpp index 1577f0a..e088db6 100644 --- a/src/gui/widgets/qmenu_wince.cpp +++ b/src/gui/widgets/qmenu_wince.cpp @@ -126,6 +126,7 @@ static void qt_wce_enable_soft_key(HWND handle, uint command) if (ptrEnableSoftKey) ptrEnableSoftKey(handle, command, false, true); } + static void qt_wce_disable_soft_key(HWND handle, uint command) { resolveAygLibs(); @@ -133,7 +134,8 @@ static void qt_wce_disable_soft_key(HWND handle, uint command) ptrEnableSoftKey(handle, command, false, false); } -static void qt_wce_delete_action_list(QList<QWceMenuAction*> *list) { +static void qt_wce_delete_action_list(QList<QWceMenuAction*> *list) +{ for(QList<QWceMenuAction*>::Iterator it = list->begin(); it != list->end(); ++it) { QWceMenuAction *action = (*it); delete action; @@ -143,7 +145,8 @@ static void qt_wce_delete_action_list(QList<QWceMenuAction*> *list) { } //search for first QuitRole in QMenuBar -static QAction* qt_wce_get_quit_action(QList<QAction *> actionItems) { +static QAction* qt_wce_get_quit_action(QList<QAction *> actionItems) +{ QAction *returnAction = 0; for (int i = 0; i < actionItems.size(); ++i) { QAction *action = actionItems.at(i); @@ -158,7 +161,8 @@ static QAction* qt_wce_get_quit_action(QList<QAction *> actionItems) { return 0; //nothing found; } -static QAction* qt_wce_get_quit_action(QList<QWceMenuAction*> actionItems) { +static QAction* qt_wce_get_quit_action(QList<QWceMenuAction*> actionItems) +{ for (int i = 0; i < actionItems.size(); ++i) { if (actionItems.at(i)->action->menuRole() == QAction::QuitRole) return actionItems.at(i)->action; @@ -171,7 +175,8 @@ static QAction* qt_wce_get_quit_action(QList<QWceMenuAction*> actionItems) { return 0; } -static HMODULE qt_wce_get_module_handle() { +static HMODULE qt_wce_get_module_handle() +{ HMODULE module = 0; //handle to resources if (!(module = GetModuleHandle(L"QtGui4"))) //release dynamic if (!(module = GetModuleHandle(L"QtGuid4"))) //debug dynamic @@ -180,7 +185,8 @@ static HMODULE qt_wce_get_module_handle() { return module; } -static void qt_wce_change_command(HWND menuHandle, int item, int command) { +static void qt_wce_change_command(HWND menuHandle, int item, int command) +{ TBBUTTONINFOA tbbi; memset(&tbbi,0,sizeof(tbbi)); tbbi.cbSize = sizeof(tbbi); @@ -189,7 +195,8 @@ TBBUTTONINFOA tbbi; SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi); } -static void qt_wce_rename_menu_item(HWND menuHandle, int item, const QString &newText) { +static void qt_wce_rename_menu_item(HWND menuHandle, int item, const QString &newText) +{ TBBUTTONINFOA tbbi; memset(&tbbi,0,sizeof(tbbi)); tbbi.cbSize = sizeof(tbbi); @@ -200,7 +207,8 @@ static void qt_wce_rename_menu_item(HWND menuHandle, int item, const QString &ne SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi); } -static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, int toolbarID, int flags = 0) { +static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, int toolbarID, int flags = 0) +{ resolveAygLibs(); if (ptrCreateMenuBar) { @@ -225,8 +233,8 @@ static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, i return 0; } -static void qt_wce_insert_action(HMENU menu, QWceMenuAction *action, bool created) { - +static void qt_wce_insert_action(HMENU menu, QWceMenuAction *action) +{ Q_ASSERT_X(menu, "AppendMenu", "menu is 0"); if (action->action->isVisible()) { int flags; @@ -240,7 +248,7 @@ static void qt_wce_insert_action(HMENU menu, QWceMenuAction *action, bool create else if (action->action->menu()) { text.remove(QChar::fromLatin1('&')); AppendMenu (menu, MF_STRING | flags | MF_POPUP, - (UINT) action->action->menu()->wceMenu(created), reinterpret_cast<const wchar_t *> (text.utf16())); + (UINT) action->action->menu()->wceMenu(), reinterpret_cast<const wchar_t *> (text.utf16())); } else { AppendMenu (menu, MF_STRING | flags, action->command, reinterpret_cast<const wchar_t *> (text.utf16())); @@ -265,12 +273,14 @@ static void qt_wce_clear_menu(HMENU hMenu) This function refreshes the native Windows CE menu. */ -void QMenuBar::wceRefresh() { +void QMenuBar::wceRefresh() +{ for (int i = 0; i < nativeMenuBars.size(); ++i) nativeMenuBars.at(i)->d_func()->wceRefresh(); } -void QMenuBarPrivate::wceRefresh() { +void QMenuBarPrivate::wceRefresh() +{ DrawMenuBar(wce_menubar->menubarHandle); } @@ -280,7 +290,8 @@ void QMenuBarPrivate::wceRefresh() { This function sends native Windows CE commands to Qt menus. */ -QAction* QMenu::wceCommands(uint command) { +QAction* QMenu::wceCommands(uint command) +{ Q_D(QMenu); return d->wceCommands(command); } @@ -292,22 +303,27 @@ QAction* QMenu::wceCommands(uint command) { and all their child menus. */ -void QMenuBar::wceCommands(uint command, HWND) { - for (int i = 0; i < nativeMenuBars.size(); ++i) - nativeMenuBars.at(i)->d_func()->wceCommands(command); +void QMenuBar::wceCommands(uint command) +{ + const HWND hwndActiveWindow = GetActiveWindow(); + for (int i = 0; i < nativeMenuBars.size(); ++i) { + QMenuBarPrivate* nativeMenuBar = nativeMenuBars.at(i)->d_func(); + if (hwndActiveWindow == nativeMenuBar->wce_menubar->parentWindowHandle) + nativeMenuBar->wceCommands(command); + } } -bool QMenuBarPrivate::wceEmitSignals(QList<QWceMenuAction*> actions, uint command) { +bool QMenuBarPrivate::wceEmitSignals(QList<QWceMenuAction*> actions, uint command) +{ QAction *foundAction = 0; for (int i = 0; i < actions.size(); ++i) { - if (foundAction) - break; QWceMenuAction *action = actions.at(i); if (action->action->menu()) { foundAction = action->action->menu()->wceCommands(command); + if (foundAction) + break; } else if (action->command == command) { - emit q_func()->triggered(action->action); action->action->activate(QAction::Trigger); return true; } @@ -319,13 +335,14 @@ bool QMenuBarPrivate::wceEmitSignals(QList<QWceMenuAction*> actions, uint comman return false; } -void QMenuBarPrivate::wceCommands(uint command) { +void QMenuBarPrivate::wceCommands(uint command) +{ if (wceClassicMenu) { for (int i = 0; i < wce_menubar->actionItemsClassic.size(); ++i) wceEmitSignals(wce_menubar->actionItemsClassic.at(i), command); } else { if (wceEmitSignals(wce_menubar->actionItems, command)) { - return ; + return; } else if (wce_menubar->leftButtonIsMenu) {//check if command is on the left quick button wceEmitSignals(wce_menubar->actionItemsLeftButton, command); @@ -337,7 +354,8 @@ void QMenuBarPrivate::wceCommands(uint command) { } } -QAction *QMenuPrivate::wceCommands(uint command) { +QAction *QMenuPrivate::wceCommands(uint command) +{ QAction *foundAction = 0; for (int i = 0; i < wce_menu->actionItems.size(); ++i) { if (foundAction) @@ -347,7 +365,7 @@ QAction *QMenuPrivate::wceCommands(uint command) { foundAction = action->action->menu()->d_func()->wceCommands(command); } else if (action->command == command) { - action->action->activate(QAction::Trigger); + activateAction(action->action, QAction::Trigger); return action->action; } } @@ -356,8 +374,8 @@ QAction *QMenuPrivate::wceCommands(uint command) { return foundAction; } -void QMenuBarPrivate::wceCreateMenuBar(QWidget *parent) { - +void QMenuBarPrivate::wceCreateMenuBar(QWidget *parent) +{ Q_Q(QMenuBar); wce_menubar = new QWceMenuBarPrivate(this); @@ -371,21 +389,25 @@ void QMenuBarPrivate::wceCreateMenuBar(QWidget *parent) { wceClassicMenu = (!qt_wince_is_smartphone() && !qt_wince_is_pocket_pc()); } -void QMenuBarPrivate::wceDestroyMenuBar() { +void QMenuBarPrivate::wceDestroyMenuBar() +{ Q_Q(QMenuBar); int index = nativeMenuBars.indexOf(q); nativeMenuBars.removeAt(index); - if (wce_menubar) - delete wce_menubar; - wce_menubar = 0; + if (wce_menubar) { + delete wce_menubar; + wce_menubar = 0; + } } -QMenuBarPrivate::QWceMenuBarPrivate::QWceMenuBarPrivate(QMenuBarPrivate *menubar) : - menubarHandle(0), menuHandle(0),leftButtonMenuHandle(0) , - leftButtonAction(0), leftButtonIsMenu(false), d(menubar) { +QMenuBarPrivate::QWceMenuBarPrivate::QWceMenuBarPrivate(QMenuBarPrivate *menubar) +: menubarHandle(0), menuHandle(0), leftButtonMenuHandle(0), + leftButtonAction(0), leftButtonIsMenu(false), d(menubar) +{ } -QMenuBarPrivate::QWceMenuBarPrivate::~QWceMenuBarPrivate() { +QMenuBarPrivate::QWceMenuBarPrivate::~QWceMenuBarPrivate() +{ if (menubarHandle) DestroyWindow(menubarHandle); qt_wce_delete_action_list(&actionItems); @@ -403,24 +425,28 @@ QMenuBarPrivate::QWceMenuBarPrivate::~QWceMenuBarPrivate() { QMenuBar::wceRefresh(); } -QMenuPrivate::QWceMenuPrivate::QWceMenuPrivate() { - menuHandle = 0; +QMenuPrivate::QWceMenuPrivate::QWceMenuPrivate() +: menuHandle(0) +{ } -QMenuPrivate::QWceMenuPrivate::~QWceMenuPrivate() { +QMenuPrivate::QWceMenuPrivate::~QWceMenuPrivate() +{ qt_wce_delete_action_list(&actionItems); if (menuHandle) DestroyMenu(menuHandle); } -void QMenuPrivate::QWceMenuPrivate::addAction(QAction *a, QWceMenuAction *before) { +void QMenuPrivate::QWceMenuPrivate::addAction(QAction *a, QWceMenuAction *before) +{ QWceMenuAction *action = new QWceMenuAction; action->action = a; action->command = qt_wce_menu_static_cmd_id++; addAction(action, before); } -void QMenuPrivate::QWceMenuPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) { +void QMenuPrivate::QWceMenuPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) +{ if (!action) return; int before_index = actionItems.indexOf(before); @@ -439,12 +465,16 @@ void QMenuPrivate::QWceMenuPrivate::addAction(QWceMenuAction *action, QWceMenuAc Windows CE menu bar bindings. */ -HMENU QMenu::wceMenu(bool create) { return d_func()->wceMenu(create); } +HMENU QMenu::wceMenu() +{ + return d_func()->wceMenu(); +} -HMENU QMenuPrivate::wceMenu(bool create) { +HMENU QMenuPrivate::wceMenu() +{ if (!wce_menu) wce_menu = new QWceMenuPrivate; - if (!wce_menu->menuHandle || create) + if (!wce_menu->menuHandle) wce_menu->rebuild(); return wce_menu->menuHandle; } @@ -459,30 +489,33 @@ void QMenuPrivate::QWceMenuPrivate::rebuild() for (int i = 0; i < actionItems.size(); ++i) { QWceMenuAction *action = actionItems.at(i); action->menuHandle = menuHandle; - qt_wce_insert_action(menuHandle, action, true); + qt_wce_insert_action(menuHandle, action); } QMenuBar::wceRefresh(); } -void QMenuPrivate::QWceMenuPrivate::syncAction(QWceMenuAction *) { +void QMenuPrivate::QWceMenuPrivate::syncAction(QWceMenuAction *) +{ rebuild(); } -void QMenuPrivate::QWceMenuPrivate::removeAction(QWceMenuAction *action) { - actionItems.removeAll(action); - delete action; - action = 0; - rebuild(); +void QMenuPrivate::QWceMenuPrivate::removeAction(QWceMenuAction *action) +{ + actionItems.removeAll(action); + delete action; + rebuild(); } -void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QAction *a, QWceMenuAction *before) { +void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QAction *a, QWceMenuAction *before) +{ QWceMenuAction *action = new QWceMenuAction; action->action = a; action->command = qt_wce_menu_static_cmd_id++; addAction(action, before); } -void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) { +void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) +{ if (!action) return; int before_index = actionItems.indexOf(before); @@ -494,25 +527,27 @@ void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QWceMenuAction *action, QWce rebuild(); } -void QMenuBarPrivate::QWceMenuBarPrivate::syncAction(QWceMenuAction*) { +void QMenuBarPrivate::QWceMenuBarPrivate::syncAction(QWceMenuAction*) +{ QMenuBar::wceRefresh(); rebuild(); } -void QMenuBarPrivate::QWceMenuBarPrivate::removeAction(QWceMenuAction *action) { +void QMenuBarPrivate::QWceMenuBarPrivate::removeAction(QWceMenuAction *action) +{ actionItems.removeAll(action); delete action; - action = 0; rebuild(); } -void QMenuBarPrivate::_q_updateDefaultAction() { +void QMenuBarPrivate::_q_updateDefaultAction() +{ if (wce_menubar) wce_menubar->rebuild(); } -void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() { - +void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() +{ d->q_func()->resize(0,0); parentWindowHandle = d->q_func()->parentWidget() ? d->q_func()->parentWidget()->winId() : d->q_func()->winId(); if (d->wceClassicMenu) { @@ -559,7 +594,7 @@ void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() { action->command = qt_wce_menu_static_cmd_id++; action->menuHandle = subMenuHandle; actionItemsClassic.last().append(action); - qt_wce_insert_action(subMenuHandle, action, true); + qt_wce_insert_action(subMenuHandle, action); } } for (int i = actions.size();i<maxEntries;++i) { @@ -602,7 +637,7 @@ void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() { for (int i = 0; i < actionItems.size(); ++i) { QWceMenuAction *action = actionItems.at(i); action->menuHandle = menuHandle; - qt_wce_insert_action(menuHandle, action, true); + qt_wce_insert_action(menuHandle, action); } if (!leftButtonIsMenu) { if (leftButtonAction) { @@ -622,7 +657,7 @@ void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() { action->command = qt_wce_menu_static_cmd_id++; action->menuHandle = leftButtonMenuHandle; actionItemsLeftButton.append(action); - qt_wce_insert_action(leftButtonMenuHandle, action, true); + qt_wce_insert_action(leftButtonMenuHandle, action); } } } diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index ef37fd1..aa4ffce 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -1956,7 +1956,7 @@ bool QMenuBar::isNativeMenuBar() const to the right soft key. Currently there is only support for the default action on Windows - Mobile. All other platforms ignore the default action. + Mobile. On all other platforms this method is not available. \sa defaultAction() */ diff --git a/src/gui/widgets/qmenubar.h b/src/gui/widgets/qmenubar.h index 85c0988..c63a4f5 100644 --- a/src/gui/widgets/qmenubar.h +++ b/src/gui/widgets/qmenubar.h @@ -115,7 +115,7 @@ public: void setDefaultAction(QAction *); QAction *defaultAction() const; - static void wceCommands(uint command, HWND controlHandle); + static void wceCommands(uint command); static void wceRefresh(); #endif diff --git a/src/multimedia/multimedia/audio/qaudio_symbian_p.cpp b/src/multimedia/multimedia/audio/qaudio_symbian_p.cpp index afe98f5..4522c5c 100644 --- a/src/multimedia/multimedia/audio/qaudio_symbian_p.cpp +++ b/src/multimedia/multimedia/audio/qaudio_symbian_p.cpp @@ -45,41 +45,6 @@ QT_BEGIN_NAMESPACE namespace SymbianAudio { - -DevSoundCapabilities::DevSoundCapabilities(CMMFDevSound &devsound, - QAudio::Mode mode) -{ - QT_TRAP_THROWING(constructL(devsound, mode)); -} - -DevSoundCapabilities::~DevSoundCapabilities() -{ - m_fourCC.Close(); -} - -void DevSoundCapabilities::constructL(CMMFDevSound &devsound, - QAudio::Mode mode) -{ - m_caps = devsound.Capabilities(); - - TMMFPrioritySettings settings; - - switch (mode) { - case QAudio::AudioOutput: - settings.iState = EMMFStatePlaying; - devsound.GetSupportedInputDataTypesL(m_fourCC, settings); - break; - - case QAudio::AudioInput: - settings.iState = EMMFStateRecording; - devsound.GetSupportedInputDataTypesL(m_fourCC, settings); - break; - - default: - Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode"); - } -} - namespace Utils { //----------------------------------------------------------------------------- @@ -274,11 +239,8 @@ bool sampleInfoQtToNative(int inputSampleSize, return found; } -//----------------------------------------------------------------------------- -// Public functions -//----------------------------------------------------------------------------- - -void capabilitiesNativeToQt(const DevSoundCapabilities &caps, +void capabilitiesNativeToQt(const TMMFCapabilities &caps, + const TFourCC &fourcc, QList<int> &frequencies, QList<int> &channels, QList<int> &sampleSizes, @@ -292,37 +254,20 @@ void capabilitiesNativeToQt(const DevSoundCapabilities &caps, channels.clear(); for (int i=0; i<SampleRateCount; ++i) - if (caps.caps().iRate & SampleRateListNative[i]) + if (caps.iRate & SampleRateListNative[i]) frequencies += SampleRateListQt[i]; for (int i=0; i<ChannelsCount; ++i) - if (caps.caps().iChannels & ChannelsListNative[i]) + if (caps.iChannels & ChannelsListNative[i]) channels += ChannelsListQt[i]; for (int i=0; i<EncodingCount; ++i) { - if (caps.fourCC().Find(EncodingFourCC[i]) != KErrNotFound) { + if (fourcc == EncodingFourCC[i]) { sampleSizes += EncodingSampleSize[i]; byteOrders += EncodingByteOrder[i]; sampleTypes += EncodingSampleType[i]; } } - -} - -bool isFormatSupported(const QAudioFormat &formatQt, - const DevSoundCapabilities &caps) { - TMMFCapabilities formatNative; - TUint32 fourCC; - - bool result = false; - if (formatQt.codec() == QString::fromAscii("audio/pcm") && - formatQtToNative(formatQt, fourCC, formatNative)) { - result = - (formatNative.iRate & caps.caps().iRate) - && (formatNative.iChannels & caps.caps().iChannels) - && (caps.fourCC().Find(fourCC) != KErrNotFound); - } - return result; } bool formatQtToNative(const QAudioFormat &inputFormat, @@ -337,7 +282,7 @@ bool formatQtToNative(const QAudioFormat &inputFormat, TMMFMonoStereo outputChannels; TMMFSoundEncoding outputEncoding; - if (inputFormat.codec() == QString::fromAscii("audio/pcm")) { + if (inputFormat.codec() == QLatin1String("audio/pcm")) { result = sampleRateQtToNative(inputFormat.frequency(), outputSampleRate) && channelsQtToNative(inputFormat.channels(), outputChannels) @@ -357,14 +302,13 @@ bool formatQtToNative(const QAudioFormat &inputFormat, return result; } -QAudio::State stateNativeToQt(State nativeState, - QAudio::State initializingState) +QAudio::State stateNativeToQt(State nativeState) { switch (nativeState) { case ClosedState: return QAudio::StoppedState; case InitializingState: - return initializingState; + return QAudio::StoppedState; case ActiveState: return QAudio::ActiveState; case IdleState: @@ -388,6 +332,291 @@ qint64 samplesToBytes(const QAudioFormat &format, qint64 samples) } } // namespace Utils + + +//----------------------------------------------------------------------------- +// DevSoundWrapper +//----------------------------------------------------------------------------- + +DevSoundWrapper::DevSoundWrapper(QAudio::Mode mode, QObject *parent) + : QObject(parent) + , m_mode(mode) + , m_state(StateIdle) + , m_devsound(0) + , m_fourcc(0) +{ + QT_TRAP_THROWING(m_devsound = CMMFDevSound::NewL()); + + switch (mode) { + case QAudio::AudioOutput: + m_nativeMode = EMMFStatePlaying; + break; + + case QAudio::AudioInput: + m_nativeMode = EMMFStateRecording; + break; + + default: + Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode"); + } + + getSupportedCodecs(); +} + +DevSoundWrapper::~DevSoundWrapper() +{ + delete m_devsound; +} + +const QList<QString>& DevSoundWrapper::supportedCodecs() const +{ + return m_supportedCodecs; +} + +void DevSoundWrapper::initialize(const QString& codec) +{ + Q_ASSERT(StateInitializing != m_state); + m_state = StateInitializing; + if (QLatin1String("audio/pcm") == codec) { + m_fourcc = KMMFFourCCCodePCM16; + TRAPD(err, m_devsound->InitializeL(*this, m_fourcc, m_nativeMode)); + if (KErrNone != err) { + m_state = StateIdle; + emit initializeComplete(err); + } + } else { + emit initializeComplete(KErrNotSupported); + } +} + +const QList<int>& DevSoundWrapper::supportedFrequencies() const +{ + Q_ASSERT(StateInitialized == m_state); + return m_supportedFrequencies; +} + +const QList<int>& DevSoundWrapper::supportedChannels() const +{ + Q_ASSERT(StateInitialized == m_state); + return m_supportedChannels; +} + +const QList<int>& DevSoundWrapper::supportedSampleSizes() const +{ + Q_ASSERT(StateInitialized == m_state); + return m_supportedSampleSizes; +} + +const QList<QAudioFormat::Endian>& DevSoundWrapper::supportedByteOrders() const +{ + Q_ASSERT(StateInitialized == m_state); + return m_supportedByteOrders; +} + +const QList<QAudioFormat::SampleType>& DevSoundWrapper::supportedSampleTypes() const +{ + Q_ASSERT(StateInitialized == m_state); + return m_supportedSampleTypes; +} + +bool DevSoundWrapper::isFormatSupported(const QAudioFormat &format) const +{ + Q_ASSERT(StateInitialized == m_state); + return m_supportedCodecs.contains(format.codec()) + && m_supportedFrequencies.contains(format.frequency()) + && m_supportedChannels.contains(format.channels()) + && m_supportedSampleSizes.contains(format.sampleSize()) + && m_supportedSampleTypes.contains(format.sampleType()) + && m_supportedByteOrders.contains(format.byteOrder()); +} + +int DevSoundWrapper::samplesProcessed() const +{ + Q_ASSERT(StateInitialized == m_state); + int result = 0; + switch (m_mode) { + case QAudio::AudioInput: + result = m_devsound->SamplesRecorded(); + break; + case QAudio::AudioOutput: + result = m_devsound->SamplesPlayed(); + break; + } + return result; +} + +bool DevSoundWrapper::setFormat(const QAudioFormat &format) +{ + Q_ASSERT(StateInitialized == m_state); + bool result = false; + TUint32 fourcc; + TMMFCapabilities nativeFormat; + if (Utils::formatQtToNative(format, fourcc, nativeFormat)) { + TMMFCapabilities currentNativeFormat = m_devsound->Config(); + nativeFormat.iBufferSize = currentNativeFormat.iBufferSize; + TRAPD(err, m_devsound->SetConfigL(nativeFormat)); + result = (KErrNone == err); + } + return result; +} + +bool DevSoundWrapper::start() +{ + Q_ASSERT(StateInitialized == m_state); + int err = KErrArgument; + switch (m_mode) { + case QAudio::AudioInput: + TRAP(err, m_devsound->RecordInitL()); + break; + case QAudio::AudioOutput: + TRAP(err, m_devsound->PlayInitL()); + break; + } + return (KErrNone == err); +} + +void DevSoundWrapper::pause() +{ + Q_ASSERT(StateInitialized == m_state); + m_devsound->Pause(); +} + +void DevSoundWrapper::stop() +{ + m_devsound->Stop(); +} + +void DevSoundWrapper::bufferProcessed() +{ + Q_ASSERT(StateInitialized == m_state); + switch (m_mode) { + case QAudio::AudioInput: + m_devsound->RecordData(); + break; + case QAudio::AudioOutput: + m_devsound->PlayData(); + break; + } +} + +void DevSoundWrapper::getSupportedCodecs() +{ +/* + * TODO: once we support formats other than PCM, this function should + * convert the array of FourCC codes into MIME types for each codec. + * + RArray<TFourCC> fourcc; + QT_TRAP_THROWING(CleanupClosePushL(&fourcc)); + + TMMFPrioritySettings settings; + switch (mode) { + case QAudio::AudioOutput: + settings.iState = EMMFStatePlaying; + m_devsound->GetSupportedInputDataTypesL(fourcc, settings); + break; + + case QAudio::AudioInput: + settings.iState = EMMFStateRecording; + m_devsound->GetSupportedInputDataTypesL(fourcc, settings); + break; + + default: + Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode"); + } + + CleanupStack::PopAndDestroy(); // fourcc +*/ + + m_supportedCodecs.append(QLatin1String("audio/pcm")); +} + +void DevSoundWrapper::populateCapabilities() +{ + m_supportedFrequencies.clear(); + m_supportedChannels.clear(); + m_supportedSampleSizes.clear(); + m_supportedByteOrders.clear(); + m_supportedSampleTypes.clear(); + + const TMMFCapabilities caps = m_devsound->Capabilities(); + + for (int i=0; i<Utils::SampleRateCount; ++i) + if (caps.iRate & Utils::SampleRateListNative[i]) + m_supportedFrequencies += Utils::SampleRateListQt[i]; + + for (int i=0; i<Utils::ChannelsCount; ++i) + if (caps.iChannels & Utils::ChannelsListNative[i]) + m_supportedChannels += Utils::ChannelsListQt[i]; + + for (int i=0; i<Utils::EncodingCount; ++i) { + if (m_fourcc == Utils::EncodingFourCC[i]) { + m_supportedSampleSizes += Utils::EncodingSampleSize[i]; + m_supportedByteOrders += Utils::EncodingByteOrder[i]; + m_supportedSampleTypes += Utils::EncodingSampleType[i]; + } + } +} + +void DevSoundWrapper::InitializeComplete(TInt aError) +{ + Q_ASSERT(StateInitializing == m_state); + if (KErrNone == aError) { + m_state = StateInitialized; + populateCapabilities(); + } else { + m_state = StateIdle; + } + emit initializeComplete(aError); +} + +void DevSoundWrapper::ToneFinished(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound's tone playback functions, so should + // never receive this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void DevSoundWrapper::BufferToBeFilled(CMMFBuffer *aBuffer) +{ + Q_ASSERT(QAudio::AudioOutput == m_mode); + emit bufferToBeProcessed(aBuffer); +} + +void DevSoundWrapper::PlayError(TInt aError) +{ + Q_ASSERT(QAudio::AudioOutput == m_mode); + emit processingError(aError); +} + +void DevSoundWrapper::BufferToBeEmptied(CMMFBuffer *aBuffer) +{ + Q_ASSERT(QAudio::AudioInput == m_mode); + emit bufferToBeProcessed(aBuffer); +} + +void DevSoundWrapper::RecordError(TInt aError) +{ + Q_ASSERT(QAudio::AudioInput == m_mode); + emit processingError(aError); +} + +void DevSoundWrapper::ConvertError(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound's format conversion functions, so + // should never receive this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void DevSoundWrapper::DeviceMessage(TUid aMessageType, const TDesC8 &aMsg) +{ + Q_UNUSED(aMessageType) + Q_UNUSED(aMsg) + // Ignore this callback. +} + + } // namespace SymbianAudio QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudio_symbian_p.h b/src/multimedia/multimedia/audio/qaudio_symbian_p.h index d5238b4..58ef192 100644 --- a/src/multimedia/multimedia/audio/qaudio_symbian_p.h +++ b/src/multimedia/multimedia/audio/qaudio_symbian_p.h @@ -53,7 +53,8 @@ #ifndef QAUDIO_SYMBIAN_P_H #define QAUDIO_SYMBIAN_P_H -#include <QtCore/qnamespace.h> +#include <QtCore/QList> +#include <QtCore/QString> #include <QtMultimedia/qaudioformat.h> #include <QtMultimedia/qaudio.h> #include <sounddevice.h> @@ -83,60 +84,92 @@ enum State { , SuspendedState }; -/* - * Helper class for querying DevSound codec / format support +/** + * Wrapper around DevSound instance */ -class DevSoundCapabilities { +class DevSoundWrapper + : public QObject + , public MDevSoundObserver +{ + Q_OBJECT + +public: + DevSoundWrapper(QAudio::Mode mode, QObject *parent = 0); + ~DevSoundWrapper(); + public: - DevSoundCapabilities(CMMFDevSound &devsound, QAudio::Mode mode); - ~DevSoundCapabilities(); + // List of supported codecs; can be called once object is constructed + const QList<QString>& supportedCodecs() const; + + // Asynchronous initialization function; emits devsoundInitializeComplete + void initialize(const QString& codec); + + // Capabilities, for selected codec. Can be called once initialize has returned + // successfully. + const QList<int>& supportedFrequencies() const; + const QList<int>& supportedChannels() const; + const QList<int>& supportedSampleSizes() const; + const QList<QAudioFormat::Endian>& supportedByteOrders() const; + const QList<QAudioFormat::SampleType>& supportedSampleTypes() const; - const RArray<TFourCC>& fourCC() const { return m_fourCC; } - const TMMFCapabilities& caps() const { return m_caps; } + bool isFormatSupported(const QAudioFormat &format) const; + + int samplesProcessed() const; + bool setFormat(const QAudioFormat &format); + bool start(); + void pause(); + void stop(); + void bufferProcessed(); + +public: + // MDevSoundObserver + void InitializeComplete(TInt aError); + void ToneFinished(TInt aError); + void BufferToBeFilled(CMMFBuffer *aBuffer); + void PlayError(TInt aError); + void BufferToBeEmptied(CMMFBuffer *aBuffer); + void RecordError(TInt aError); + void ConvertError(TInt aError); + void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); + +signals: + void initializeComplete(int error); + void bufferToBeProcessed(CMMFBuffer *buffer); + void processingError(int error); private: - void constructL(CMMFDevSound &devsound, QAudio::Mode mode); + void getSupportedCodecs(); + void populateCapabilities(); private: - RArray<TFourCC> m_fourCC; - TMMFCapabilities m_caps; -}; + const QAudio::Mode m_mode; + TMMFState m_nativeMode; -namespace Utils { + enum State { + StateIdle, + StateInitializing, + StateInitialized + } m_state; -/** - * Convert native audio capabilities to QAudio lists. - */ -void capabilitiesNativeToQt(const DevSoundCapabilities &caps, - QList<int> &frequencies, - QList<int> &channels, - QList<int> &sampleSizes, - QList<QAudioFormat::Endian> &byteOrders, - QList<QAudioFormat::SampleType> &sampleTypes); + CMMFDevSound* m_devsound; + TFourCC m_fourcc; -/** - * Check whether format is supported. - */ -bool isFormatSupported(const QAudioFormat &format, - const DevSoundCapabilities &caps); + QList<QString> m_supportedCodecs; + QList<int> m_supportedFrequencies; + QList<int> m_supportedChannels; + QList<int> m_supportedSampleSizes; + QList<QAudioFormat::Endian> m_supportedByteOrders; + QList<QAudioFormat::SampleType> m_supportedSampleTypes; -/** - * Convert QAudioFormat to native format types. - * - * Note that, despite the name, DevSound uses TMMFCapabilities to specify - * single formats as well as capabilities. - * - * Note that this function does not modify outputFormat.iBufferSize. - */ -bool formatQtToNative(const QAudioFormat &inputFormat, - TUint32 &outputFourCC, - TMMFCapabilities &outputFormat); +}; + + +namespace Utils { /** * Convert internal states to QAudio states. */ -QAudio::State stateNativeToQt(State nativeState, - QAudio::State initializingState); +QAudio::State stateNativeToQt(State nativeState); /** * Convert data length to number of samples. diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp b/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp index 36284d3..4be116f 100644 --- a/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include <QtCore/QCoreApplication> #include "qaudiodeviceinfo_symbian_p.h" #include "qaudio_symbian_p.h" @@ -50,7 +51,7 @@ QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray device, , m_mode(mode) , m_updated(false) { - QT_TRAP_THROWING(m_devsound.reset(CMMFDevSound::NewL())); + } QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal() @@ -85,16 +86,21 @@ QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const } if (!isFormatSupported(format)) { - if (m_frequencies.size()) - format.setFrequency(m_frequencies[0]); - if (m_channels.size()) - format.setChannels(m_channels[0]); - if (m_sampleSizes.size()) - format.setSampleSize(m_sampleSizes[0]); - if (m_byteOrders.size()) - format.setByteOrder(m_byteOrders[0]); - if (m_sampleTypes.size()) - format.setSampleType(m_sampleTypes[0]); + format = QAudioFormat(); + format.setCodec(QLatin1String("audio/pcm")); + if (m_capabilities.contains(format.codec())) { + const Capabilities &codecCaps = m_capabilities[format.codec()]; + if (codecCaps.m_frequencies.size()) + format.setFrequency(codecCaps.m_frequencies[0]); + if (codecCaps.m_channels.size()) + format.setChannels(codecCaps.m_channels[0]); + if (codecCaps.m_sampleSizes.size()) + format.setSampleSize(codecCaps.m_sampleSizes[0]); + if (codecCaps.m_byteOrders.size()) + format.setByteOrder(codecCaps.m_byteOrders[0]); + if (codecCaps.m_sampleTypes.size()) + format.setSampleType(codecCaps.m_sampleTypes[0]); + } } return format; @@ -104,14 +110,15 @@ bool QAudioDeviceInfoInternal::isFormatSupported( const QAudioFormat &format) const { getSupportedFormats(); - const bool supported = - m_codecs.contains(format.codec()) - && m_frequencies.contains(format.frequency()) - && m_channels.contains(format.channels()) - && m_sampleSizes.contains(format.sampleSize()) - && m_byteOrders.contains(format.byteOrder()) - && m_sampleTypes.contains(format.sampleType()); - + bool supported = false; + if (m_capabilities.contains(format.codec())) { + const Capabilities &codecCaps = m_capabilities[format.codec()]; + supported = codecCaps.m_frequencies.contains(format.frequency()) + && codecCaps.m_channels.contains(format.channels()) + && codecCaps.m_sampleSizes.contains(format.sampleSize()) + && codecCaps.m_byteOrders.contains(format.byteOrder()) + && codecCaps.m_sampleTypes.contains(format.sampleType()); + } return supported; } @@ -131,37 +138,37 @@ QString QAudioDeviceInfoInternal::deviceName() const QStringList QAudioDeviceInfoInternal::codecList() { getSupportedFormats(); - return m_codecs; + return m_capabilities.keys(); } QList<int> QAudioDeviceInfoInternal::frequencyList() { getSupportedFormats(); - return m_frequencies; + return m_unionCapabilities.m_frequencies; } QList<int> QAudioDeviceInfoInternal::channelsList() { getSupportedFormats(); - return m_channels; + return m_unionCapabilities.m_channels; } QList<int> QAudioDeviceInfoInternal::sampleSizeList() { getSupportedFormats(); - return m_sampleSizes; + return m_unionCapabilities.m_sampleSizes; } QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList() { getSupportedFormats(); - return m_byteOrders; + return m_unionCapabilities.m_byteOrders; } QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList() { getSupportedFormats(); - return m_sampleTypes; + return m_unionCapabilities.m_sampleTypes; } QByteArray QAudioDeviceInfoInternal::defaultInputDevice() @@ -181,17 +188,50 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode) return result; } -void QAudioDeviceInfoInternal::getSupportedFormats() const +void QAudioDeviceInfoInternal::devsoundInitializeComplete(int err) { - if (!m_updated) { - QScopedPointer<SymbianAudio::DevSoundCapabilities> caps( - new SymbianAudio::DevSoundCapabilities(*m_devsound, m_mode)); + m_intializationResult = err; + m_initializing = false; +} - SymbianAudio::Utils::capabilitiesNativeToQt(*caps, - m_frequencies, m_channels, m_sampleSizes, - m_byteOrders, m_sampleTypes); +// Helper function +template<typename T> +void appendUnique(QList<T> &left, const QList<T> &right) +{ + foreach (const T &value, right) + if (!left.contains(value)) + left += value; +} - m_codecs.append(QLatin1String("audio/pcm")); +void QAudioDeviceInfoInternal::getSupportedFormats() const +{ + if (!m_updated) { + QScopedPointer<SymbianAudio::DevSoundWrapper> devsound(new SymbianAudio::DevSoundWrapper(m_mode)); + connect(devsound.data(), SIGNAL(initializeComplete(int)), + this, SLOT(devsoundInitializeComplete(int))); + + foreach (const QString& codec, devsound->supportedCodecs()) { + m_initializing = true; + devsound->initialize(codec); + while (m_initializing) + QCoreApplication::instance()->processEvents(QEventLoop::WaitForMoreEvents); + if (KErrNone == m_intializationResult) { + m_capabilities[codec].m_frequencies = devsound->supportedFrequencies(); + appendUnique(m_unionCapabilities.m_frequencies, devsound->supportedFrequencies()); + + m_capabilities[codec].m_channels = devsound->supportedChannels(); + appendUnique(m_unionCapabilities.m_channels, devsound->supportedChannels()); + + m_capabilities[codec].m_sampleSizes = devsound->supportedSampleSizes(); + appendUnique(m_unionCapabilities.m_sampleSizes, devsound->supportedSampleSizes()); + + m_capabilities[codec].m_byteOrders = devsound->supportedByteOrders(); + appendUnique(m_unionCapabilities.m_byteOrders, devsound->supportedByteOrders()); + + m_capabilities[codec].m_sampleTypes = devsound->supportedSampleTypes(); + appendUnique(m_unionCapabilities.m_sampleTypes, devsound->supportedSampleTypes()); + } + } m_updated = true; } diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.h b/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.h index 89e539f..79b23cc 100644 --- a/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.h +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.h @@ -53,11 +53,16 @@ #ifndef QAUDIODEVICEINFO_SYMBIAN_P_H #define QAUDIODEVICEINFO_SYMBIAN_P_H +#include <QtCore/QMap> #include <QtMultimedia/qaudioengine.h> #include <sounddevice.h> QT_BEGIN_NAMESPACE +namespace SymbianAudio { +class DevSoundWrapper; +} + class QAudioDeviceInfoInternal : public QAbstractAudioDeviceInfo { @@ -82,24 +87,33 @@ public: static QByteArray defaultOutputDevice(); static QList<QByteArray> availableDevices(QAudio::Mode); +private slots: + void devsoundInitializeComplete(int err); + private: void getSupportedFormats() const; private: - QScopedPointer<CMMFDevSound> m_devsound; + mutable bool m_initializing; + int m_intializationResult; QString m_deviceName; QAudio::Mode m_mode; + struct Capabilities + { + QList<int> m_frequencies; + QList<int> m_channels; + QList<int> m_sampleSizes; + QList<QAudioFormat::Endian> m_byteOrders; + QList<QAudioFormat::SampleType> m_sampleTypes; + }; + // Mutable to allow lazy initialization when called from const-qualified // public functions (isFormatSupported, nearestFormat) mutable bool m_updated; - mutable QStringList m_codecs; - mutable QList<int> m_frequencies; - mutable QList<int> m_channels; - mutable QList<int> m_sampleSizes; - mutable QList<QAudioFormat::Endian> m_byteOrders; - mutable QList<QAudioFormat::SampleType> m_sampleTypes; + mutable QMap<QString, Capabilities> m_capabilities; + mutable Capabilities m_unionCapabilities; }; QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudioinput_symbian_p.cpp b/src/multimedia/multimedia/audio/qaudioinput_symbian_p.cpp index 52daa88..9d240ca 100644 --- a/src/multimedia/multimedia/audio/qaudioinput_symbian_p.cpp +++ b/src/multimedia/multimedia/audio/qaudioinput_symbian_p.cpp @@ -116,16 +116,16 @@ QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, , m_pullMode(false) , m_sink(0) , m_pullTimer(new QTimer(this)) + , m_devSound(0) , m_devSoundBuffer(0) , m_devSoundBufferSize(0) , m_totalBytesReady(0) , m_devSoundBufferPos(0) , m_totalSamplesRecorded(0) { - connect(m_notifyTimer.data(), SIGNAL(timeout()), this, SIGNAL(notify())); + qRegisterMetaType<CMMFBuffer *>("CMMFBuffer *"); - SymbianAudio::Utils::formatQtToNative(m_format, m_nativeFourCC, - m_nativeFormat); + connect(m_notifyTimer.data(), SIGNAL(timeout()), this, SIGNAL(notify())); m_pullTimer->setInterval(PushInterval); connect(m_pullTimer.data(), SIGNAL(timeout()), this, SLOT(pullData())); @@ -164,7 +164,7 @@ void QAudioInputPrivate::stop() void QAudioInputPrivate::reset() { m_totalSamplesRecorded += getSamplesRecorded(); - m_devSound->Stop(); + m_devSound->stop(); startRecording(); } @@ -174,7 +174,7 @@ void QAudioInputPrivate::suspend() || SymbianAudio::IdleState == m_internalState) { m_notifyTimer->stop(); m_pullTimer->stop(); - m_devSound->Pause(); + m_devSound->pause(); const qint64 samplesRecorded = getSamplesRecorded(); m_totalSamplesRecorded += samplesRecorded; @@ -189,8 +189,11 @@ void QAudioInputPrivate::suspend() void QAudioInputPrivate::resume() { - if (SymbianAudio::SuspendedState == m_internalState) + if (SymbianAudio::SuspendedState == m_internalState) { + if (!m_pullMode && !bytesReady()) + m_devSound->start(); startDataTransfer(); + } } int QAudioInputPrivate::bytesReady() const @@ -224,11 +227,14 @@ int QAudioInputPrivate::bufferSize() const void QAudioInputPrivate::setNotifyInterval(int ms) { - if (ms > 0) { + if (ms >= 0) { const int oldNotifyInterval = m_notifyInterval; m_notifyInterval = ms; - if (m_notifyTimer->isActive() && ms != oldNotifyInterval) + if (m_notifyInterval && (SymbianAudio::ActiveState == m_internalState || + SymbianAudio::IdleState == m_internalState)) m_notifyTimer->start(m_notifyInterval); + else + m_notifyTimer->stop(); } } @@ -275,88 +281,6 @@ QAudioFormat QAudioInputPrivate::format() const return m_format; } -//----------------------------------------------------------------------------- -// MDevSoundObserver implementation -//----------------------------------------------------------------------------- - -void QAudioInputPrivate::InitializeComplete(TInt aError) -{ - Q_ASSERT_X(SymbianAudio::InitializingState == m_internalState, - Q_FUNC_INFO, "Invalid state"); - - if (KErrNone == aError) - startRecording(); -} - -void QAudioInputPrivate::ToneFinished(TInt aError) -{ - Q_UNUSED(aError) - // This class doesn't use DevSound's tone playback functions, so should - // never receive this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioInputPrivate::BufferToBeFilled(CMMFBuffer *aBuffer) -{ - Q_UNUSED(aBuffer) - // This class doesn't use DevSound in play mode, so should never receive - // this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioInputPrivate::PlayError(TInt aError) -{ - Q_UNUSED(aError) - // This class doesn't use DevSound in play mode, so should never receive - // this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioInputPrivate::BufferToBeEmptied(CMMFBuffer *aBuffer) -{ - // Following receipt of this callback, DevSound should not provide another - // buffer until we have returned the current one. - Q_ASSERT_X(!m_devSoundBuffer, Q_FUNC_INFO, "Buffer already held"); - - CMMFDataBuffer *const buffer = static_cast<CMMFDataBuffer*>(aBuffer); - - if (!m_devSoundBufferSize) - m_devSoundBufferSize = buffer->Data().MaxLength(); - - m_totalBytesReady += buffer->Data().Length(); - - if (SymbianAudio::SuspendedState == m_internalState) { - m_devSoundBufferQ.append(buffer); - } else { - // Will be returned to DevSound by bufferEmptied(). - m_devSoundBuffer = buffer; - m_devSoundBufferPos = 0; - - if (bytesReady() && !m_pullMode) - pushData(); - } -} - -void QAudioInputPrivate::RecordError(TInt aError) -{ - Q_UNUSED(aError) - setError(QAudio::IOError); -} - -void QAudioInputPrivate::ConvertError(TInt aError) -{ - Q_UNUSED(aError) - // This class doesn't use DevSound's format conversion functions, so - // should never receive this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioInputPrivate::DeviceMessage(TUid aMessageType, const TDesC8 &aMsg) -{ - Q_UNUSED(aMessageType) - Q_UNUSED(aMsg) - // Ignore this callback. -} //----------------------------------------------------------------------------- // Private functions @@ -367,33 +291,30 @@ void QAudioInputPrivate::open() Q_ASSERT_X(SymbianAudio::ClosedState == m_internalState, Q_FUNC_INFO, "DevSound already opened"); - QT_TRAP_THROWING( m_devSound.reset(CMMFDevSound::NewL()) ) - - QScopedPointer<SymbianAudio::DevSoundCapabilities> caps( - new SymbianAudio::DevSoundCapabilities(*m_devSound, QAudio::AudioInput)); + Q_ASSERT(!m_devSound); + m_devSound = new SymbianAudio::DevSoundWrapper(QAudio::AudioInput, this); - int err = SymbianAudio::Utils::isFormatSupported(m_format, *caps) ? - KErrNone : KErrNotSupported; - - if (KErrNone == err) { - setState(SymbianAudio::InitializingState); - TRAP(err, m_devSound->InitializeL(*this, m_nativeFourCC, - EMMFStateRecording)); - } + connect(m_devSound, SIGNAL(initializeComplete(int)), + this, SLOT(devsoundInitializeComplete(int))); + connect(m_devSound, SIGNAL(bufferToBeProcessed(CMMFBuffer *)), + this, SLOT(devsoundBufferToBeEmptied(CMMFBuffer *))); + connect(m_devSound, SIGNAL(processingError(int)), + this, SLOT(devsoundRecordError(int))); - if (KErrNone != err) { - setError(QAudio::OpenError); - m_devSound.reset(); - } + setState(SymbianAudio::InitializingState); + m_devSound->initialize(m_format.codec()); } void QAudioInputPrivate::startRecording() { - const int samplesRecorded = m_devSound->SamplesRecorded(); + const int samplesRecorded = m_devSound->samplesProcessed(); Q_ASSERT(samplesRecorded == 0); - TRAPD(err, startDevSoundL()); - if (KErrNone == err) { + bool ok = m_devSound->setFormat(m_format); + if (ok) + ok = m_devSound->start(); + + if (ok) { startDataTransfer(); } else { setError(QAudio::OpenError); @@ -401,17 +322,10 @@ void QAudioInputPrivate::startRecording() } } -void QAudioInputPrivate::startDevSoundL() -{ - TMMFCapabilities nativeFormat = m_devSound->Config(); - m_nativeFormat.iBufferSize = nativeFormat.iBufferSize; - m_devSound->SetConfigL(m_nativeFormat); - m_devSound->RecordInitL(); -} - void QAudioInputPrivate::startDataTransfer() { - m_notifyTimer->start(m_notifyInterval); + if (m_notifyInterval) + m_notifyTimer->start(m_notifyInterval); if (m_pullMode) m_pullTimer->start(); @@ -503,6 +417,48 @@ void QAudioInputPrivate::pullData() } } +void QAudioInputPrivate::devsoundInitializeComplete(int err) +{ + Q_ASSERT_X(SymbianAudio::InitializingState == m_internalState, + Q_FUNC_INFO, "Invalid state"); + + if (!err && m_devSound->isFormatSupported(m_format)) + startRecording(); + else + setError(QAudio::OpenError); +} + +void QAudioInputPrivate::devsoundBufferToBeEmptied(CMMFBuffer *baseBuffer) +{ + // Following receipt of this signal, DevSound should not provide another + // buffer until we have returned the current one. + Q_ASSERT_X(!m_devSoundBuffer, Q_FUNC_INFO, "Buffer already held"); + + CMMFDataBuffer *const buffer = static_cast<CMMFDataBuffer*>(baseBuffer); + + if (!m_devSoundBufferSize) + m_devSoundBufferSize = buffer->Data().MaxLength(); + + m_totalBytesReady += buffer->Data().Length(); + + if (SymbianAudio::SuspendedState == m_internalState) { + m_devSoundBufferQ.append(buffer); + } else { + // Will be returned to DevSoundWrapper by bufferProcessed(). + m_devSoundBuffer = buffer; + m_devSoundBufferPos = 0; + + if (bytesReady() && !m_pullMode) + pushData(); + } +} + +void QAudioInputPrivate::devsoundRecordError(int err) +{ + Q_UNUSED(err) + setError(QAudio::IOError); +} + void QAudioInputPrivate::bufferEmptied() { m_devSoundBufferPos = 0; @@ -510,7 +466,7 @@ void QAudioInputPrivate::bufferEmptied() if (m_devSoundBuffer) { m_totalBytesReady -= m_devSoundBuffer->Data().Length(); m_devSoundBuffer = 0; - m_devSound->RecordData(); + m_devSound->bufferProcessed(); } else { Q_ASSERT(!m_devSoundBufferQ.empty()); m_totalBytesReady -= m_devSoundBufferQ.front()->Data().Length(); @@ -518,7 +474,8 @@ void QAudioInputPrivate::bufferEmptied() // If the queue has been emptied, resume transfer from the hardware if (m_devSoundBufferQ.empty()) - m_devSound->RecordInitL(); + if (!m_devSound->start()) + setError(QAudio::IOError); } Q_ASSERT(m_totalBytesReady >= 0); @@ -532,8 +489,10 @@ void QAudioInputPrivate::close() m_error = QAudio::NoError; if (m_devSound) - m_devSound->Stop(); - m_devSound.reset(); + m_devSound->stop(); + delete m_devSound; + m_devSound = 0; + m_devSoundBuffer = 0; m_devSoundBufferSize = 0; m_totalBytesReady = 0; @@ -554,7 +513,7 @@ qint64 QAudioInputPrivate::getSamplesRecorded() const { qint64 result = 0; if (m_devSound) - result = qint64(m_devSound->SamplesRecorded()); + result = qint64(m_devSound->samplesProcessed()); return result; } @@ -565,30 +524,28 @@ void QAudioInputPrivate::setError(QAudio::Error error) // Although no state transition actually occurs here, a stateChanged event // must be emitted to inform the client that the call to start() was // unsuccessful. - if (QAudio::OpenError == error) + if (QAudio::OpenError == error) { emit stateChanged(QAudio::StoppedState); - - // Close the DevSound instance. This causes a transition to StoppedState. - // This must be done asynchronously in case the current function was called - // from a DevSound event handler, in which case deleting the DevSound - // instance may cause an exception. - QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection); + } else { + if (QAudio::UnderrunError == error) + setState(SymbianAudio::IdleState); + else + // Close the DevSound instance. This causes a transition to + // StoppedState. This must be done asynchronously in case the + // current function was called from a DevSound event handler, in which + // case deleting the DevSound instance may cause an exception. + QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection); + } } void QAudioInputPrivate::setState(SymbianAudio::State newInternalState) { const QAudio::State oldExternalState = m_externalState; m_internalState = newInternalState; - m_externalState = SymbianAudio::Utils::stateNativeToQt( - m_internalState, initializingState()); + m_externalState = SymbianAudio::Utils::stateNativeToQt(m_internalState); if (m_externalState != oldExternalState) emit stateChanged(m_externalState); } -QAudio::State QAudioInputPrivate::initializingState() const -{ - return QAudio::IdleState; -} - QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudioinput_symbian_p.h b/src/multimedia/multimedia/audio/qaudioinput_symbian_p.h index ca3ccf7..7417655 100644 --- a/src/multimedia/multimedia/audio/qaudioinput_symbian_p.h +++ b/src/multimedia/multimedia/audio/qaudioinput_symbian_p.h @@ -56,7 +56,6 @@ #include <QtMultimedia/qaudioengine.h> #include <QTime> #include <QTimer> -#include <sounddevice.h> #include "qaudio_symbian_p.h" QT_BEGIN_NAMESPACE @@ -82,7 +81,6 @@ private: class QAudioInputPrivate : public QAbstractAudioInput - , public MDevSoundObserver { friend class SymbianAudioInputPrivate; Q_OBJECT @@ -109,23 +107,15 @@ public: QAudio::State state() const; QAudioFormat format() const; - // MDevSoundObserver - void InitializeComplete(TInt aError); - void ToneFinished(TInt aError); - void BufferToBeFilled(CMMFBuffer *aBuffer); - void PlayError(TInt aError); - void BufferToBeEmptied(CMMFBuffer *aBuffer); - void RecordError(TInt aError); - void ConvertError(TInt aError); - void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); - private slots: void pullData(); + void devsoundInitializeComplete(int err); + void devsoundBufferToBeEmptied(CMMFBuffer *); + void devsoundRecordError(int err); private: void open(); void startRecording(); - void startDevSoundL(); void startDataTransfer(); CMMFDataBuffer* currentBuffer() const; void pushData(); @@ -138,8 +128,6 @@ private: void setError(QAudio::Error error); void setState(SymbianAudio::State state); - QAudio::State initializingState() const; - private: const QByteArray m_device; const QAudioFormat m_format; @@ -158,9 +146,7 @@ private: QScopedPointer<QTimer> m_pullTimer; - QScopedPointer<CMMFDevSound> m_devSound; - TUint32 m_nativeFourCC; - TMMFCapabilities m_nativeFormat; + SymbianAudio::DevSoundWrapper* m_devSound; // Latest buffer provided by DevSound, to be empied of data. CMMFDataBuffer *m_devSoundBuffer; diff --git a/src/multimedia/multimedia/audio/qaudiooutput.cpp b/src/multimedia/multimedia/audio/qaudiooutput.cpp index b0b5244..371773c 100644 --- a/src/multimedia/multimedia/audio/qaudiooutput.cpp +++ b/src/multimedia/multimedia/audio/qaudiooutput.cpp @@ -209,6 +209,10 @@ QAudioFormat QAudioOutput::format() const If a problem occurs during this process the error() is set to QAudio::OpenError, state() is set to QAudio::StoppedState and stateChanged() signal is emitted. + In either case, the stateChanged() signal may be emitted either synchronously + during execution of the start() function or asynchronously after start() has + returned to the caller. + \sa QIODevice */ @@ -228,6 +232,10 @@ void QAudioOutput::start(QIODevice* device) If a problem occurs during this process the error() is set to QAudio::OpenError, state() is set to QAudio::StoppedState and stateChanged() signal is emitted. + In either case, the stateChanged() signal may be emitted either synchronously + during execution of the start() function or asynchronously after start() has + returned to the caller. + \sa QIODevice */ @@ -276,6 +284,8 @@ void QAudioOutput::suspend() Sets state() to QAudio::ActiveState if you previously called start(QIODevice*). Sets state() to QAudio::IdleState if you previously called start(). emits stateChanged() signal. + + Note: signal will always be emitted during execution of the resume() function. */ void QAudioOutput::resume() diff --git a/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.cpp b/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.cpp index 3f8e933..5098469 100644 --- a/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.cpp +++ b/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.cpp @@ -110,6 +110,7 @@ QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, , m_externalState(QAudio::StoppedState) , m_pullMode(false) , m_source(0) + , m_devSound(0) , m_devSoundBuffer(0) , m_devSoundBufferSize(0) , m_bytesWritten(0) @@ -121,10 +122,9 @@ QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, , m_samplesPlayed(0) , m_totalSamplesPlayed(0) { - connect(m_notifyTimer.data(), SIGNAL(timeout()), this, SIGNAL(notify())); + qRegisterMetaType<CMMFBuffer *>("CMMFBuffer *"); - SymbianAudio::Utils::formatQtToNative(m_format, m_nativeFourCC, - m_nativeFormat); + connect(m_notifyTimer.data(), SIGNAL(timeout()), this, SIGNAL(notify())); m_underflowTimer->setInterval(UnderflowTimerInterval); connect(m_underflowTimer.data(), SIGNAL(timeout()), this, @@ -140,8 +140,6 @@ QIODevice* QAudioOutputPrivate::start(QIODevice *device) { stop(); - // We have to set these before the call to open() because of the - // logic in initializingState() if (device) { m_pullMode = true; m_source = device; @@ -171,7 +169,7 @@ void QAudioOutputPrivate::stop() void QAudioOutputPrivate::reset() { m_totalSamplesPlayed += getSamplesPlayed(); - m_devSound->Stop(); + m_devSound->stop(); m_bytesPadding = 0; startPlayback(); } @@ -196,11 +194,12 @@ void QAudioOutputPrivate::suspend() // Because this causes buffered data to be dropped, we replace the // lost data with silence following a call to resume(), in order to // ensure that processedUSecs() returns the correct value. - m_devSound->Stop(); + m_devSound->stop(); m_totalSamplesPlayed += samplesPlayed; // Calculate the amount of data dropped const qint64 paddingSamples = samplesWritten - samplesPlayed; + Q_ASSERT(paddingSamples >= 0); m_bytesPadding = SymbianAudio::Utils::samplesToBytes(m_format, paddingSamples); @@ -210,8 +209,11 @@ void QAudioOutputPrivate::suspend() void QAudioOutputPrivate::resume() { - if (SymbianAudio::SuspendedState == m_internalState) + if (SymbianAudio::SuspendedState == m_internalState) { + if (!m_pullMode && m_devSoundBuffer && m_devSoundBuffer->Data().Length()) + bufferFilled(); startPlayback(); + } } int QAudioOutputPrivate::bytesFree() const @@ -249,11 +251,14 @@ int QAudioOutputPrivate::bufferSize() const void QAudioOutputPrivate::setNotifyInterval(int ms) { - if (ms > 0) { + if (ms >= 0) { const int oldNotifyInterval = m_notifyInterval; m_notifyInterval = ms; - if (m_notifyTimer->isActive() && ms != oldNotifyInterval) + if (m_notifyInterval && (SymbianAudio::ActiveState == m_internalState || + SymbianAudio::IdleState == m_internalState)) m_notifyTimer->start(m_notifyInterval); + else + m_notifyTimer->stop(); } } @@ -300,35 +305,52 @@ QAudioFormat QAudioOutputPrivate::format() const return m_format; } + //----------------------------------------------------------------------------- -// MDevSoundObserver implementation +// Private functions //----------------------------------------------------------------------------- -void QAudioOutputPrivate::InitializeComplete(TInt aError) +void QAudioOutputPrivate::dataReady() { - Q_ASSERT_X(SymbianAudio::InitializingState == m_internalState, - Q_FUNC_INFO, "Invalid state"); + // Client-provided QIODevice has data ready to read. - if (KErrNone == aError) - startPlayback(); + Q_ASSERT_X(m_source->bytesAvailable(), Q_FUNC_INFO, + "readyRead signal received, but no data available"); + + if (!m_bytesPadding) + pullData(); } -void QAudioOutputPrivate::ToneFinished(TInt aError) +void QAudioOutputPrivate::underflowTimerExpired() { - Q_UNUSED(aError) - // This class doesn't use DevSound's tone playback functions, so should - // never receive this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); + const TInt samplesPlayed = getSamplesPlayed(); + if (m_samplesPlayed && (samplesPlayed == m_samplesPlayed)) { + setError(QAudio::UnderrunError); + } else { + m_samplesPlayed = samplesPlayed; + m_underflowTimer->start(); + } +} + +void QAudioOutputPrivate::devsoundInitializeComplete(int err) +{ + Q_ASSERT_X(SymbianAudio::InitializingState == m_internalState, + Q_FUNC_INFO, "Invalid state"); + + if (!err && m_devSound->isFormatSupported(m_format)) + startPlayback(); + else + setError(QAudio::OpenError); } -void QAudioOutputPrivate::BufferToBeFilled(CMMFBuffer *aBuffer) +void QAudioOutputPrivate::devsoundBufferToBeFilled(CMMFBuffer *bufferBase) { - // Following receipt of this callback, DevSound should not provide another + // Following receipt of this signal, DevSound should not provide another // buffer until we have returned the current one. Q_ASSERT_X(!m_devSoundBuffer, Q_FUNC_INFO, "Buffer already held"); - // Will be returned to DevSound by bufferFilled(). - m_devSoundBuffer = static_cast<CMMFDataBuffer*>(aBuffer); + // Will be returned to DevSoundWrapper by bufferProcessed(). + m_devSoundBuffer = static_cast<CMMFDataBuffer*>(bufferBase); if (!m_devSoundBufferSize) m_devSoundBufferSize = m_devSoundBuffer->Data().MaxLength(); @@ -339,9 +361,9 @@ void QAudioOutputPrivate::BufferToBeFilled(CMMFBuffer *aBuffer) pullData(); } -void QAudioOutputPrivate::PlayError(TInt aError) +void QAudioOutputPrivate::devsoundPlayError(int err) { - switch (aError) { + switch (err) { case KErrUnderflow: m_underflow = true; if (m_pullMode && !m_lastBuffer) @@ -355,102 +377,42 @@ void QAudioOutputPrivate::PlayError(TInt aError) } } -void QAudioOutputPrivate::BufferToBeEmptied(CMMFBuffer *aBuffer) -{ - Q_UNUSED(aBuffer) - // This class doesn't use DevSound in record mode, so should never receive - // this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioOutputPrivate::RecordError(TInt aError) -{ - Q_UNUSED(aError) - // This class doesn't use DevSound in record mode, so should never receive - // this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioOutputPrivate::ConvertError(TInt aError) -{ - Q_UNUSED(aError) - // This class doesn't use DevSound's format conversion functions, so - // should never receive this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioOutputPrivate::DeviceMessage(TUid aMessageType, const TDesC8 &aMsg) -{ - Q_UNUSED(aMessageType) - Q_UNUSED(aMsg) - // Ignore this callback. -} - -//----------------------------------------------------------------------------- -// Private functions -//----------------------------------------------------------------------------- - -void QAudioOutputPrivate::dataReady() -{ - // Client-provided QIODevice has data ready to read. - - Q_ASSERT_X(m_source->bytesAvailable(), Q_FUNC_INFO, - "readyRead signal received, but no data available"); - - if (!m_bytesPadding) - pullData(); -} - -void QAudioOutputPrivate::underflowTimerExpired() -{ - const TInt samplesPlayed = getSamplesPlayed(); - if (m_samplesPlayed && (samplesPlayed == m_samplesPlayed)) { - setError(QAudio::UnderrunError); - } else { - m_samplesPlayed = samplesPlayed; - m_underflowTimer->start(); - } -} - void QAudioOutputPrivate::open() { Q_ASSERT_X(SymbianAudio::ClosedState == m_internalState, Q_FUNC_INFO, "DevSound already opened"); - QT_TRAP_THROWING( m_devSound.reset(CMMFDevSound::NewL()) ) - - QScopedPointer<SymbianAudio::DevSoundCapabilities> caps( - new SymbianAudio::DevSoundCapabilities(*m_devSound, - QAudio::AudioOutput)); + Q_ASSERT(!m_devSound); + m_devSound = new SymbianAudio::DevSoundWrapper(QAudio::AudioOutput, this); - int err = SymbianAudio::Utils::isFormatSupported(m_format, *caps) ? - KErrNone : KErrNotSupported; + connect(m_devSound, SIGNAL(initializeComplete(int)), + this, SLOT(devsoundInitializeComplete(int))); + connect(m_devSound, SIGNAL(bufferToBeProcessed(CMMFBuffer *)), + this, SLOT(devsoundBufferToBeFilled(CMMFBuffer *))); + connect(m_devSound, SIGNAL(processingError(int)), + this, SLOT(devsoundPlayError(int))); - if (KErrNone == err) { - setState(SymbianAudio::InitializingState); - TRAP(err, m_devSound->InitializeL(*this, m_nativeFourCC, - EMMFStatePlaying)); - } - - if (KErrNone != err) { - setError(QAudio::OpenError); - m_devSound.reset(); - } + setState(SymbianAudio::InitializingState); + m_devSound->initialize(m_format.codec()); } void QAudioOutputPrivate::startPlayback() { - TRAPD(err, startDevSoundL()); - if (KErrNone == err) { + bool ok = m_devSound->setFormat(m_format); + if (ok) + ok = m_devSound->start(); + + if (ok) { if (isDataReady()) setState(SymbianAudio::ActiveState); else setState(SymbianAudio::IdleState); - m_notifyTimer->start(m_notifyInterval); + if (m_notifyInterval) + m_notifyTimer->start(m_notifyInterval); m_underflow = false; - Q_ASSERT(m_devSound->SamplesPlayed() == 0); + Q_ASSERT(m_devSound->samplesProcessed() == 0); writePaddingData(); @@ -462,14 +424,6 @@ void QAudioOutputPrivate::startPlayback() } } -void QAudioOutputPrivate::startDevSoundL() -{ - TMMFCapabilities nativeFormat = m_devSound->Config(); - m_nativeFormat.iBufferSize = nativeFormat.iBufferSize; - m_devSound->SetConfigL(m_nativeFormat); - m_devSound->PlayInitL(); -} - void QAudioOutputPrivate::writePaddingData() { // See comments in suspend() @@ -486,10 +440,11 @@ void QAudioOutputPrivate::writePaddingData() Mem::FillZ(ptr, paddingBytes); outputBuffer.SetLength(outputBuffer.Length() + paddingBytes); m_bytesPadding -= paddingBytes; + Q_ASSERT(m_bytesPadding >= 0); if (m_pullMode && m_source->atEnd()) lastBufferFilled(); - if (paddingBytes == outputBytes) + if ((paddingBytes == outputBytes) || !m_bytesPadding) bufferFilled(); } } @@ -543,9 +498,6 @@ void QAudioOutputPrivate::pullData() Q_ASSERT_X(m_pullMode, Q_FUNC_INFO, "pullData called when in push mode"); - if (m_bytesPadding) - m_bytesPadding = 1; - // writePaddingData() is called by BufferToBeFilled() before pullData(), // so we should never have any padding data left at this point. Q_ASSERT_X(0 == m_bytesPadding, Q_FUNC_INFO, @@ -590,7 +542,7 @@ void QAudioOutputPrivate::bufferFilled() if (QAudio::UnderrunError == m_error) m_error = QAudio::NoError; - m_devSound->PlayData(); + m_devSound->bufferProcessed(); } void QAudioOutputPrivate::lastBufferFilled() @@ -610,8 +562,10 @@ void QAudioOutputPrivate::close() m_error = QAudio::NoError; if (m_devSound) - m_devSound->Stop(); - m_devSound.reset(); + m_devSound->stop(); + delete m_devSound; + m_devSound = 0; + m_devSoundBuffer = 0; m_devSoundBufferSize = 0; @@ -644,7 +598,7 @@ qint64 QAudioOutputPrivate::getSamplesPlayed() const // This is necessary because some DevSound implementations report // that they have played more data than has actually been provided to them // by the client. - const qint64 devSoundSamplesPlayed(m_devSound->SamplesPlayed()); + const qint64 devSoundSamplesPlayed(m_devSound->samplesProcessed()); result = qMin(devSoundSamplesPlayed, samplesWritten); } } @@ -658,25 +612,25 @@ void QAudioOutputPrivate::setError(QAudio::Error error) // Although no state transition actually occurs here, a stateChanged event // must be emitted to inform the client that the call to start() was // unsuccessful. - if (QAudio::OpenError == error) + if (QAudio::OpenError == error) { emit stateChanged(QAudio::StoppedState); - - if (QAudio::UnderrunError == error) - setState(SymbianAudio::IdleState); - else - // Close the DevSound instance. This causes a transition to - // StoppedState. This must be done asynchronously in case the - // current function was called from a DevSound event handler, in which - // case deleting the DevSound instance may cause an exception. - QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection); + } else { + if (QAudio::UnderrunError == error) + setState(SymbianAudio::IdleState); + else + // Close the DevSound instance. This causes a transition to + // StoppedState. This must be done asynchronously in case the + // current function was called from a DevSound event handler, in which + // case deleting the DevSound instance may cause an exception. + QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection); + } } void QAudioOutputPrivate::setState(SymbianAudio::State newInternalState) { const QAudio::State oldExternalState = m_externalState; m_internalState = newInternalState; - m_externalState = SymbianAudio::Utils::stateNativeToQt( - m_internalState, initializingState()); + m_externalState = SymbianAudio::Utils::stateNativeToQt(m_internalState); if (m_externalState != oldExternalState) emit stateChanged(m_externalState); @@ -689,9 +643,4 @@ bool QAudioOutputPrivate::isDataReady() const || m_pushDataReady; } -QAudio::State QAudioOutputPrivate::initializingState() const -{ - return isDataReady() ? QAudio::ActiveState : QAudio::IdleState; -} - QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.h b/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.h index 00ccb24..c0acb07 100644 --- a/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.h +++ b/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.h @@ -80,7 +80,6 @@ private: class QAudioOutputPrivate : public QAbstractAudioOutput - , public MDevSoundObserver { friend class SymbianAudioOutputPrivate; Q_OBJECT @@ -107,24 +106,16 @@ public: QAudio::State state() const; QAudioFormat format() const; - // MDevSoundObserver - void InitializeComplete(TInt aError); - void ToneFinished(TInt aError); - void BufferToBeFilled(CMMFBuffer *aBuffer); - void PlayError(TInt aError); - void BufferToBeEmptied(CMMFBuffer *aBuffer); - void RecordError(TInt aError); - void ConvertError(TInt aError); - void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); - private slots: void dataReady(); void underflowTimerExpired(); + void devsoundInitializeComplete(int err); + void devsoundBufferToBeFilled(CMMFBuffer *); + void devsoundPlayError(int err); private: void open(); void startPlayback(); - void startDevSoundL(); void writePaddingData(); qint64 pushData(const char *data, qint64 len); void pullData(); @@ -138,7 +129,6 @@ private: void setState(SymbianAudio::State state); bool isDataReady() const; - QAudio::State initializingState() const; private: const QByteArray m_device; @@ -156,9 +146,7 @@ private: bool m_pullMode; QIODevice *m_source; - QScopedPointer<CMMFDevSound> m_devSound; - TUint32 m_nativeFourCC; - TMMFCapabilities m_nativeFormat; + SymbianAudio::DevSoundWrapper* m_devSound; // Buffer provided by DevSound, to be filled with data. CMMFDataBuffer *m_devSoundBuffer; diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 31c64f0..1afabec 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -723,6 +723,7 @@ void QHttpNetworkConnectionPrivate::removeReply(QHttpNetworkReply *reply) // This function must be called from the event loop. The only // exception is documented in QHttpNetworkConnectionPrivate::queueRequest +// although it is called _q_startNextRequest, it will actually start multiple requests when possible void QHttpNetworkConnectionPrivate::_q_startNextRequest() { //resend the necessary ones. @@ -740,26 +741,23 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest() // dequeue new ones - QAbstractSocket *socket = 0; + // return fast if there is nothing to do + if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty()) + return; + // try to get a free AND connected socket for (int i = 0; i < channelCount; ++i) { - QAbstractSocket *chSocket = channels[i].socket; - // try to get a free AND connected socket if (!channels[i].isSocketBusy() && channels[i].socket->state() == QAbstractSocket::ConnectedState) { - socket = chSocket; - dequeueAndSendRequest(socket); - break; + dequeueAndSendRequest(channels[i].socket); } } - if (!socket) { - for (int i = 0; i < channelCount; ++i) { - QAbstractSocket *chSocket = channels[i].socket; - // try to get a free unconnected socket - if (!channels[i].isSocketBusy()) { - socket = chSocket; - dequeueAndSendRequest(socket); - break; - } + // return fast if there is nothing to do + if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty()) + return; + // try to get a free unconnected socket + for (int i = 0; i < channelCount; ++i) { + if (!channels[i].isSocketBusy()) { + dequeueAndSendRequest(channels[i].socket); } } diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index d24eb1f..d3576dd 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -294,7 +294,8 @@ bool QHttpNetworkConnectionChannel::sendRequest() // ensure we try to receive a reply in all cases, even if _q_readyRead_ hat not been called // this is needed if the sends an reply before we have finished sending the request. In that // case receiveReply had been called before but ignored the server reply - QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection); + if (socket->bytesAvailable()) + QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection); break; } case QHttpNetworkConnectionChannel::ReadingState: diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index 338236e..108ba8a 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -179,6 +179,9 @@ qint64 QHttpNetworkReply::bytesAvailableNextBlock() const QByteArray QHttpNetworkReply::readAny() { Q_D(QHttpNetworkReply); + if (d->responseData.bufferCount() == 0) + return QByteArray(); + // we'll take the last buffer, so schedule another read from http if (d->downstreamLimited && d->responseData.bufferCount() == 1) d->connection->d_func()->readMoreLater(this); diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 2a02c99..60f7dc6 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -74,7 +74,7 @@ Q_GLOBAL_STATIC(QNetworkAccessBackendFactoryData, factoryData) QNetworkAccessBackendFactory::QNetworkAccessBackendFactory() { QMutexLocker locker(&factoryData()->mutex); - factoryData()->prepend(this); + factoryData()->append(this); } QNetworkAccessBackendFactory::~QNetworkAccessBackendFactory() diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index 28a6c84..8ae1305 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -44,14 +44,10 @@ #include "QtCore/qscopedpointer.h" #include <qabstracteventdispatcher.h> -#include <private/qunicodetables_p.h> #include <qcoreapplication.h> #include <qmetaobject.h> -#include <qregexp.h> -#include <private/qnativesocketengine_p.h> #include <qstringlist.h> #include <qthread.h> -#include <qtimer.h> #include <qurl.h> #ifdef Q_OS_UNIX diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp index a186e78..90751f4 100644 --- a/src/network/kernel/qhostinfo_unix.cpp +++ b/src/network/kernel/qhostinfo_unix.cpp @@ -44,6 +44,7 @@ #include "qplatformdefs.h" #include "qhostinfo_p.h" +#include "private/qnativesocketengine_p.h" #include "qiodevice.h" #include <qbytearray.h> #include <qlibrary.h> diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp index 4264f60..b30204b 100644 --- a/src/network/kernel/qhostinfo_win.cpp +++ b/src/network/kernel/qhostinfo_win.cpp @@ -50,7 +50,6 @@ #include "private/qnativesocketengine_p.h" #include <ws2tcpip.h> #include <qlibrary.h> -#include <qtimer.h> #include <qmutex.h> #include <qurl.h> #include <private/qmutexpool_p.h> diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp index ac25597..40b3641 100644 --- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp +++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp @@ -266,10 +266,12 @@ QGLEngineShaderProg *QGLEngineSharedShaders::findProgramInCache(const QGLEngineS do { QByteArray source; - source.append(qShaderSnippets[prog.mainFragShader]); - source.append(qShaderSnippets[prog.srcPixelFragShader]); + // Insert the custom stage before the srcPixel shader to work around an ATI driver bug + // where you cannot forward declare a function that takes a sampler as argument. if (prog.srcPixelFragShader == CustomImageSrcFragmentShader) source.append(prog.customStageSource); + source.append(qShaderSnippets[prog.mainFragShader]); + source.append(qShaderSnippets[prog.srcPixelFragShader]); if (prog.compositionFragShader) source.append(qShaderSnippets[prog.compositionFragShader]); if (prog.maskFragShader) @@ -777,8 +779,8 @@ bool QGLEngineShaderManager::useCorrectShaderProg() // doesn't use are disabled) QGLContextPrivate* ctx_d = ctx->d_func(); ctx_d->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, true); - ctx_d->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, currentShaderProg->useTextureCoords); - ctx_d->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, currentShaderProg->useOpacityAttribute); + ctx_d->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, currentShaderProg && currentShaderProg->useTextureCoords); + ctx_d->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, currentShaderProg && currentShaderProg->useOpacityAttribute); shaderProgNeedsChanging = false; return true; diff --git a/src/opengl/gl2paintengineex/qglengineshadersource_p.h b/src/opengl/gl2paintengineex/qglengineshadersource_p.h index 8dba951..a7ece0f 100644 --- a/src/opengl/gl2paintengineex/qglengineshadersource_p.h +++ b/src/opengl/gl2paintengineex/qglengineshadersource_p.h @@ -351,7 +351,6 @@ static const char* const qglslImageSrcFragmentShader = "\n\ static const char* const qglslCustomSrcFragmentShader = "\n\ varying highp vec2 textureCoords; \n\ uniform lowp sampler2D imageTexture; \n\ - lowp vec4 customShader(lowp sampler2D texture, highp vec2 coords); \n\ lowp vec4 srcPixel() \n\ { \n\ return customShader(imageTexture, textureCoords); \n\ diff --git a/src/opengl/qglpixmapfilter.cpp b/src/opengl/qglpixmapfilter.cpp index d5a11d9..bfa5ef1 100644 --- a/src/opengl/qglpixmapfilter.cpp +++ b/src/opengl/qglpixmapfilter.cpp @@ -591,10 +591,11 @@ bool QGLPixmapDropShadowFilter::processGL(QPainter *painter, const QPointF &pos, qt_blurImage(image, r * qreal(0.5), false, 1); - GLuint texture = generateBlurTexture(image.size(), GL_ALPHA); - - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image.width(), image.height(), GL_ALPHA, - GL_UNSIGNED_BYTE, image.bits()); + GLuint texture; + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, image.width(), image.height(), + 0, GL_ALPHA, GL_UNSIGNED_BYTE, image.bits()); info = new QGLBlurTextureInfo(image, texture, r); } diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp index 08a50cb..28d37bc 100644 --- a/src/opengl/qpaintengine_opengl.cpp +++ b/src/opengl/qpaintengine_opengl.cpp @@ -1451,6 +1451,11 @@ bool QOpenGLPaintEngine::end() d->device->endPaint(); qt_mask_texture_cache()->maintainCache(); +#if defined(Q_WS_X11) + // clear out the references we hold for textures bound with the + // texture_from_pixmap extension + ctx->d_func()->boundPixmaps.clear(); +#endif return true; } diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index f602c73..76a605a 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -119,6 +119,35 @@ private: class QVGPaintEnginePrivate : public QPaintEngineExPrivate { public: + // Extra blending modes from VG_KHR_advanced_blending extension. + // Use the QT_VG prefix to avoid conflicts with any definitions + // that may come in via <VG/vgext.h>. + enum AdvancedBlending { + QT_VG_BLEND_OVERLAY_KHR = 0x2010, + QT_VG_BLEND_HARDLIGHT_KHR = 0x2011, + QT_VG_BLEND_SOFTLIGHT_SVG_KHR = 0x2012, + QT_VG_BLEND_SOFTLIGHT_KHR = 0x2013, + QT_VG_BLEND_COLORDODGE_KHR = 0x2014, + QT_VG_BLEND_COLORBURN_KHR = 0x2015, + QT_VG_BLEND_DIFFERENCE_KHR = 0x2016, + QT_VG_BLEND_SUBTRACT_KHR = 0x2017, + QT_VG_BLEND_INVERT_KHR = 0x2018, + QT_VG_BLEND_EXCLUSION_KHR = 0x2019, + QT_VG_BLEND_LINEARDODGE_KHR = 0x201a, + QT_VG_BLEND_LINEARBURN_KHR = 0x201b, + QT_VG_BLEND_VIVIDLIGHT_KHR = 0x201c, + QT_VG_BLEND_LINEARLIGHT_KHR = 0x201d, + QT_VG_BLEND_PINLIGHT_KHR = 0x201e, + QT_VG_BLEND_HARDMIX_KHR = 0x201f, + QT_VG_BLEND_CLEAR_KHR = 0x2020, + QT_VG_BLEND_DST_KHR = 0x2021, + QT_VG_BLEND_SRC_OUT_KHR = 0x2022, + QT_VG_BLEND_DST_OUT_KHR = 0x2023, + QT_VG_BLEND_SRC_ATOP_KHR = 0x2024, + QT_VG_BLEND_DST_ATOP_KHR = 0x2025, + QT_VG_BLEND_XOR_KHR = 0x2026 + }; + QVGPaintEnginePrivate(); ~QVGPaintEnginePrivate(); @@ -216,6 +245,8 @@ public: QVGFontEngineCleaner *fontEngineCleaner; #endif + bool hasAdvancedBlending; + QScopedPointer<QPixmapFilter> convolutionFilter; QScopedPointer<QPixmapFilter> colorizeFilter; QScopedPointer<QPixmapFilter> dropShadowFilter; @@ -369,6 +400,8 @@ void QVGPaintEnginePrivate::init() fontEngineCleaner = 0; #endif + hasAdvancedBlending = false; + clearModes(); } @@ -445,6 +478,10 @@ void QVGPaintEnginePrivate::initObjects() VG_PATH_CAPABILITY_ALL); vgAppendPathData(linePath, 2, segments, coords); #endif + + const char *extensions = reinterpret_cast<const char *>(vgGetString(VG_EXTENSIONS)); + if (extensions) + hasAdvancedBlending = strstr(extensions, "VG_KHR_advanced_blending") != 0; } void QVGPaintEnginePrivate::destroy() @@ -2288,7 +2325,7 @@ void QVGPaintEngine::compositionModeChanged() Q_D(QVGPaintEngine); d->dirty |= QPaintEngine::DirtyCompositionMode; - VGBlendMode vgMode = VG_BLEND_SRC_OVER; + VGint vgMode = VG_BLEND_SRC_OVER; switch (state()->composition_mode) { case QPainter::CompositionMode_SourceOver: @@ -2322,11 +2359,53 @@ void QVGPaintEngine::compositionModeChanged() vgMode = VG_BLEND_LIGHTEN; break; default: - qWarning() << "QVGPaintEngine::compositionModeChanged unsupported mode" << state()->composition_mode; - break; // Fall back to VG_BLEND_SRC_OVER. + if (d->hasAdvancedBlending) { + switch (state()->composition_mode) { + case QPainter::CompositionMode_Overlay: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_OVERLAY_KHR; + break; + case QPainter::CompositionMode_ColorDodge: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_COLORDODGE_KHR; + break; + case QPainter::CompositionMode_ColorBurn: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_COLORBURN_KHR; + break; + case QPainter::CompositionMode_HardLight: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_HARDLIGHT_KHR; + break; + case QPainter::CompositionMode_SoftLight: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_SOFTLIGHT_KHR; + break; + case QPainter::CompositionMode_Difference: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_DIFFERENCE_KHR; + break; + case QPainter::CompositionMode_Exclusion: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_EXCLUSION_KHR; + break; + case QPainter::CompositionMode_SourceOut: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_SRC_OUT_KHR; + break; + case QPainter::CompositionMode_DestinationOut: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_DST_OUT_KHR; + break; + case QPainter::CompositionMode_SourceAtop: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_SRC_ATOP_KHR; + break; + case QPainter::CompositionMode_DestinationAtop: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_DST_ATOP_KHR; + break; + case QPainter::CompositionMode_Xor: + vgMode = QVGPaintEnginePrivate::QT_VG_BLEND_XOR_KHR; + break; + default: break; // Fall back to VG_BLEND_SRC_OVER. + } + } + if (vgMode == VG_BLEND_SRC_OVER) + qWarning() << "QVGPaintEngine::compositionModeChanged unsupported mode" << state()->composition_mode; + break; } - d->setBlendMode(vgMode); + d->setBlendMode(VGBlendMode(vgMode)); } void QVGPaintEngine::renderHintsChanged() |