From 3d19bb6e7572cad3644863f3f89cf67a3b7160d7 Mon Sep 17 00:00:00 2001 From: peknurmi Date: Wed, 3 Jun 2009 08:44:41 +0200 Subject: Now qs60style does not send extra resize event in orientation change. QSymbianControl::HandleResourceChange contained global event handling. So Qt handled same issues unnecessarily (for each shown top level widget). Now this global event handling is encapsulated to s60ResourceChange (new method) called by s60main. In addition, qs60style generated unnecessary resize events. If widget was fullscreen or maximized, then this caused incorrect resize events (old size delivered). With these changes, qs60style just informs widgets of style change (similarly as in qstylesheetstyle). Task-number: 251085 Reviewed-by: Jason Barron Conflicts: src/gui/kernel/qapplication.h src/gui/styles/qs60style.cpp --- src/gui/kernel/qapplication.h | 1 + src/gui/kernel/qapplication_s60.cpp | 56 ++++--- src/gui/styles/qs60style.cpp | 26 +++- src/s60main/qts60mainappui.cpp | 13 ++ src/s60main/qts60mainappui.h | 7 + .../orientationchange/orientationchange.pro | 7 + .../orientationchange/tst_orientationchange.cpp | 165 +++++++++++++++++++++ tests/auto/symbian/qsymbiantests.pro | 2 +- 8 files changed, 247 insertions(+), 30 deletions(-) create mode 100644 tests/auto/symbian/orientationchange/orientationchange.pro create mode 100644 tests/auto/symbian/orientationchange/tst_orientationchange.cpp diff --git a/src/gui/kernel/qapplication.h b/src/gui/kernel/qapplication.h index f9559fa..6088780 100644 --- a/src/gui/kernel/qapplication.h +++ b/src/gui/kernel/qapplication.h @@ -234,6 +234,7 @@ public: int s60ProcessEvent(TWsEvent *event); virtual bool s60EventFilter(TWsEvent *aEvent); void symbianHandleCommand(int command); + void s60ResourceChangeL(int type); #endif #if defined(Q_WS_QWS) virtual bool qwsEventFilter(QWSEvent *); diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 7b1817f..dc2b9d3 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -649,21 +649,7 @@ void QSymbianControl::HandleResourceChange(int resourceType) // font change event break; case KEikDynamicLayoutVariantSwitch: - { -#ifndef QT_NO_STYLE_S60 - QS60Style *s60Style = 0; - -#ifndef QT_NO_STYLE_STYLESHEET - QStyleSheetStyle *proxy = qobject_cast(QApplication::style()); - if (proxy) - s60Style = qobject_cast(proxy->baseStyle()); - else -#endif - s60Style = qobject_cast(QApplication::style()); - - if (s60Style) - s60Style->handleDynamicLayoutVariantSwitch(); -#endif + { if (qwidget->isFullScreen()) { SetExtentToWholeScreen(); } else if (qwidget->isMaximized()) { @@ -672,12 +658,6 @@ void QSymbianControl::HandleResourceChange(int resourceType) } break; } -#ifndef QT_NO_STYLE_S60 - case KAknsMessageSkinChange: - if (QS60Style *s60Style = qobject_cast(QApplication::style())) - s60Style->handleSkinChange(); - break; -#endif default: break; } @@ -1060,6 +1040,40 @@ void QApplication::symbianHandleCommand(int command) } } +void QApplication::s60ResourceChangeL(int type) +{ + switch (type) { + case KEikDynamicLayoutVariantSwitch: + { +#ifndef QT_NO_STYLE_S60 + QS60Style *s60Style = 0; + +#ifndef QT_NO_STYLE_STYLESHEET + QStyleSheetStyle *proxy = qobject_cast(QApplication::style()); + if (proxy) + s60Style = qobject_cast(proxy->baseStyle()); + else +#endif + s60Style = qobject_cast(QApplication::style()); + + if (s60Style) + s60Style->handleDynamicLayoutVariantSwitch(); +#endif + } + break; + +#ifndef QT_NO_STYLE_S60 + case KAknsMessageSkinChange: + if (QS60Style *s60Style = qobject_cast(QApplication::style())) + s60Style->handleSkinChange(); + break; +#endif + + default: + break; + } +} + #ifndef QT_NO_WHEELEVENT int QApplication::wheelScrollLines() { diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index fde1cc6..3aaa839 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -119,6 +119,22 @@ static const int frameElementsCount = const int KNotFound = -1; +static void updateWidgets(const QList& widgets) +{ + // This is based on updateWidgets in qstylesheetstyle.cpp. + + for (int i = 0; i < widgets.size(); ++i) { + QWidget *widget = const_cast(widgets.at(i)); + if (widget == 0) + continue; + widget->style()->polish(widget); + QEvent event(QEvent::StyleChange); + qApp->sendEvent(widget, &event); + widget->update(); + widget->updateGeometry(); + } +} + QS60StylePrivate::~QS60StylePrivate() { clearCaches(); //deletes also background image @@ -584,14 +600,8 @@ QPixmap QS60StylePrivate::cachedFrame(SkinFrameElements frame, const QSize &size } void QS60StylePrivate::refreshUI() -{ - foreach (QWidget *topLevelWidget, QApplication::allWidgets()) { - topLevelWidget->updateGeometry(); - //todo: study how we can get rid of this. Apparently scrollbars cache pixelmetrics values, and we need them to update themselves - // maybe styleChanged event is enough? - //QCoreApplication::postEvent(topLevelWidget, new QEvent(QEvent::StyleChange)); - QCoreApplication::postEvent(topLevelWidget, new QResizeEvent(topLevelWidget->size(), topLevelWidget->size())); - } +{ + updateWidgets(QApplication::allWidgets()); } void QS60StylePrivate::setFont(QWidget *widget) const diff --git a/src/s60main/qts60mainappui.cpp b/src/s60main/qts60mainappui.cpp index 8467aef..f7e570b 100644 --- a/src/s60main/qts60mainappui.cpp +++ b/src/s60main/qts60mainappui.cpp @@ -76,6 +76,19 @@ void CQtS60MainAppUi::HandleCommandL( TInt aCommand ) qApp->symbianHandleCommand(aCommand); } +// ----------------------------------------------------------------------------- +// CQtS60MainAppUi::HandleResourceChangeL() +// Takes care of event handling. +// ----------------------------------------------------------------------------- +// +void CQtS60MainAppUi::HandleResourceChangeL(TInt aType) +{ + CAknAppUi::HandleResourceChangeL(aType); + + if (qApp) + qApp->s60ResourceChangeL(aType); +} + void CQtS60MainAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl *control) { int result = 0; diff --git a/src/s60main/qts60mainappui.h b/src/s60main/qts60mainappui.h index 3addb0c..8124fa3 100644 --- a/src/s60main/qts60mainappui.h +++ b/src/s60main/qts60mainappui.h @@ -61,6 +61,13 @@ class CQtS60MainAppUi : public CAknAppUi void HandleCommandL( TInt aCommand ); /** + * From CAknAppUi, HandleResourceChangeL + * Handles resource change events such as layout switches in global level. + * @param aType event type. + */ + void HandleResourceChangeL(TInt aType); + + /** * HandleStatusPaneSizeChange. * Called by the framework when the application status pane * size is changed. diff --git a/tests/auto/symbian/orientationchange/orientationchange.pro b/tests/auto/symbian/orientationchange/orientationchange.pro new file mode 100644 index 0000000..d240fa1 --- /dev/null +++ b/tests/auto/symbian/orientationchange/orientationchange.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +HEADERS += +SOURCES += tst_orientationchange.cpp + +symbian { + INCLUDEPATH += $$MW_LAYER_SYSTEMINCLUDE +} diff --git a/tests/auto/symbian/orientationchange/tst_orientationchange.cpp b/tests/auto/symbian/orientationchange/tst_orientationchange.cpp new file mode 100644 index 0000000..9d57ae1 --- /dev/null +++ b/tests/auto/symbian/orientationchange/tst_orientationchange.cpp @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#ifdef Q_OS_SYMBIAN + +#include +#include + +class tst_orientationchange : public QObject +{ + Q_OBJECT +public: + tst_orientationchange(){}; + ~tst_orientationchange(){}; + +private slots: + void resizeEventOnOrientationChange(); +}; + +class TestWidget : public QWidget +{ +public: + TestWidget(QWidget *parent = 0); + + void reset(); +public: + void resizeEvent(QResizeEvent *event); + +public: + QSize resizeEventSize; + int resizeEventCount; +}; + +TestWidget::TestWidget(QWidget *parent) +: QWidget(parent) +{ + reset(); +} + +void TestWidget::reset() +{ + resizeEventSize = QSize(); + resizeEventCount = 0; +} + +void TestWidget::resizeEvent(QResizeEvent *event) +{ + QWidget::resizeEvent(event); + + // Size delivered in first resize event is stored. + if (!resizeEventCount) + resizeEventSize = event->size(); + + resizeEventCount++; +} + +void tst_orientationchange::resizeEventOnOrientationChange() +{ + // This will test that when orientation 'changes', then + // at most one resize event is generated. + + TestWidget *normalWidget = new TestWidget(); + TestWidget *fullScreenWidget = new TestWidget(); + TestWidget *maximizedWidget = new TestWidget(); + + fullScreenWidget->showFullScreen(); + maximizedWidget->showMaximized(); + normalWidget->show(); + + QCoreApplication::sendPostedEvents(); + QCoreApplication::sendPostedEvents(); + + QCOMPARE(fullScreenWidget->resizeEventCount, 1); + QCOMPARE(fullScreenWidget->size(), fullScreenWidget->resizeEventSize); + QCOMPARE(maximizedWidget->resizeEventCount, 1); + QCOMPARE(maximizedWidget->size(), maximizedWidget->resizeEventSize); + QCOMPARE(normalWidget->resizeEventCount, 1); + QCOMPARE(normalWidget->size(), normalWidget->resizeEventSize); + + fullScreenWidget->reset(); + maximizedWidget->reset(); + normalWidget->reset(); + + // Assumes that Qt application is AVKON application. + CAknAppUi *appUi = static_cast(CEikonEnv::Static()->EikAppUi()); + + // Determine 'opposite' orientation to the current orientation. + + CAknAppUi::TAppUiOrientation orientation = CAknAppUi::EAppUiOrientationLandscape; + if (fullScreenWidget->size().width() > fullScreenWidget->size().height()) { + orientation = CAknAppUi::EAppUiOrientationPortrait; + } + + TRAPD(err, appUi->SetOrientationL(orientation)); + + QCoreApplication::sendPostedEvents(); + QCoreApplication::sendPostedEvents(); + + // setOrientationL is not guaranteed to change orientation + // (if emulator configured to support just portrait or landscape, then + // setOrientationL call shouldn't do anything). + // So let's ensure that we do not get resize event twice. + + QVERIFY(fullScreenWidget->resizeEventCount <= 1); + if (fullScreenWidget->resizeEventCount) { + QCOMPARE(fullScreenWidget->size(), fullScreenWidget->resizeEventSize); + } + QVERIFY(maximizedWidget->resizeEventCount <= 1); + if (fullScreenWidget->resizeEventCount) { + QCOMPARE(maximizedWidget->size(), maximizedWidget->resizeEventSize); + } + QCOMPARE(normalWidget->resizeEventCount, 0); + + TRAP(err, appUi->SetOrientationL(CAknAppUi::EAppUiOrientationUnspecified)); + + delete normalWidget; + delete fullScreenWidget; + delete maximizedWidget; +} + +QTEST_MAIN(tst_orientationchange) +#include "tst_orientationchange.moc" +#else +QTEST_NOOP_MAIN +#endif diff --git a/tests/auto/symbian/qsymbiantests.pro b/tests/auto/symbian/qsymbiantests.pro index 151d7ec..648335e 100644 --- a/tests/auto/symbian/qsymbiantests.pro +++ b/tests/auto/symbian/qsymbiantests.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = qmainexceptions \ No newline at end of file +SUBDIRS = qmainexceptions orientationchange \ No newline at end of file -- cgit v0.12 From 7a7a73184b5de3be3bb84df3991ca95461a711cc Mon Sep 17 00:00:00 2001 From: peknurmi Date: Wed, 3 Jun 2009 08:51:56 +0200 Subject: Some minor correction to qs60style. Added null check to qs60style::refreshUI method. Reviewed-by: Jason Barron Conflicts: src/gui/styles/qs60style.cpp --- src/gui/styles/qs60style.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 3aaa839..93a3144 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -119,22 +119,6 @@ static const int frameElementsCount = const int KNotFound = -1; -static void updateWidgets(const QList& widgets) -{ - // This is based on updateWidgets in qstylesheetstyle.cpp. - - for (int i = 0; i < widgets.size(); ++i) { - QWidget *widget = const_cast(widgets.at(i)); - if (widget == 0) - continue; - widget->style()->polish(widget); - QEvent event(QEvent::StyleChange); - qApp->sendEvent(widget, &event); - widget->update(); - widget->updateGeometry(); - } -} - QS60StylePrivate::~QS60StylePrivate() { clearCaches(); //deletes also background image @@ -600,8 +584,24 @@ QPixmap QS60StylePrivate::cachedFrame(SkinFrameElements frame, const QSize &size } void QS60StylePrivate::refreshUI() -{ - updateWidgets(QApplication::allWidgets()); +{ + QList widgets = QApplication::allWidgets(); + + // The following is similar to updateWidgets in qstylesheetstyle.cpp. + + for (int i = 0; i < widgets.size(); ++i) { + QWidget *widget = widgets.at(i); + if (widget == 0) + continue; + + if (widget->style()) { + widget->style()->polish(widget); + QEvent event(QEvent::StyleChange); + qApp->sendEvent(widget, &event); + } + widget->update(); + widget->updateGeometry(); + } } void QS60StylePrivate::setFont(QWidget *widget) const -- cgit v0.12 From 6ea9dca71b58c51e8fdb44fdd7d9b2a0381538cb Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Wed, 3 Jun 2009 08:55:35 +0200 Subject: Change function name to match symbianHandleCommand(). These functions are really Symbian functions and not S60 specific so they should be named as such. Also, our public API should use the Qt convention and not the Symbian convention so remove the 'L' even if it is a leaving function at the moment. --- src/gui/kernel/qapplication.h | 2 +- src/gui/kernel/qapplication_s60.cpp | 2 +- src/s60main/qts60mainappui.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/kernel/qapplication.h b/src/gui/kernel/qapplication.h index 6088780..e1b8b26 100644 --- a/src/gui/kernel/qapplication.h +++ b/src/gui/kernel/qapplication.h @@ -234,7 +234,7 @@ public: int s60ProcessEvent(TWsEvent *event); virtual bool s60EventFilter(TWsEvent *aEvent); void symbianHandleCommand(int command); - void s60ResourceChangeL(int type); + void symbianResourceChange(int type); #endif #if defined(Q_WS_QWS) virtual bool qwsEventFilter(QWSEvent *); diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index dc2b9d3..a05e9bd 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -1040,7 +1040,7 @@ void QApplication::symbianHandleCommand(int command) } } -void QApplication::s60ResourceChangeL(int type) +void QApplication::symbianResourceChange(int type) { switch (type) { case KEikDynamicLayoutVariantSwitch: diff --git a/src/s60main/qts60mainappui.cpp b/src/s60main/qts60mainappui.cpp index f7e570b..49a3342 100644 --- a/src/s60main/qts60mainappui.cpp +++ b/src/s60main/qts60mainappui.cpp @@ -86,7 +86,7 @@ void CQtS60MainAppUi::HandleResourceChangeL(TInt aType) CAknAppUi::HandleResourceChangeL(aType); if (qApp) - qApp->s60ResourceChangeL(aType); + qApp->symbianResourceChange(aType); } void CQtS60MainAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl *control) -- cgit v0.12