diff options
author | Markku Luukkainen <markku.luukkainen@digia.com> | 2009-05-26 12:32:50 (GMT) |
---|---|---|
committer | Markku Luukkainen <markku.luukkainen@digia.com> | 2009-05-26 12:32:50 (GMT) |
commit | 62743959699d78a63057e98b43fe3c79ace87234 (patch) | |
tree | 7f729ad04fc41ff3011b8385553cefdb0a868a2b /src | |
parent | 09bdf0224aec37678d4aac0c4b83af4ad272828f (diff) | |
download | Qt-62743959699d78a63057e98b43fe3c79ace87234.zip Qt-62743959699d78a63057e98b43fe3c79ace87234.tar.gz Qt-62743959699d78a63057e98b43fe3c79ace87234.tar.bz2 |
Implemented popandPush method. This is needed to optimize popping
and pushing. This avoid unnecessary screen redraw and setting of
native softkeys. One such case occurs when focused widge changes.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/qsoftkeystack.cpp | 54 | ||||
-rw-r--r-- | src/gui/widgets/qsoftkeystack.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/qsoftkeystack_p.h | 2 |
3 files changed, 55 insertions, 3 deletions
diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 05fe397..a7fa3f1 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -44,6 +44,22 @@ #include "qapplication.h" #include "qmainwindow.h" +static bool isSame(const QSoftkeySet& a, const QSoftkeySet& b) +{ + bool isSame=true; + if ( a.count() != b.count()) + return false; + int index=0; + while (index<a.count()) { + if (a.at(index)->role() != b.at(index)->role()) + return false; + if (a.at(index)->text().compare(b.at(index)->text())!=0) + return false; + index++; + } + return true; +} + QSoftKeyStackPrivate::QSoftKeyStackPrivate() { @@ -75,6 +91,25 @@ void QSoftKeyStackPrivate::pop() setNativeSoftKeys(); } +void QSoftKeyStackPrivate::popandPush(QSoftKeyAction *softKey) +{ + QSoftkeySet oldSoftKeySet = softKeyStack.pop(); + QSoftkeySet newSoftKeySet; + newSoftKeySet.append(newSoftKeySet); + softKeyStack.push(newSoftKeySet); + if( !isSame(oldSoftKeySet, newSoftKeySet)) + setNativeSoftKeys(); +} + +void QSoftKeyStackPrivate::popandPush(const QList<QSoftKeyAction*> &softkeys) +{ + QSoftkeySet oldSoftKeySet = softKeyStack.pop(); + QSoftkeySet newSoftKeySet(softkeys); + softKeyStack.push(newSoftKeySet); + if( !isSame(oldSoftKeySet, newSoftKeySet)) + setNativeSoftKeys(); +} + const QSoftkeySet& QSoftKeyStackPrivate::top() { return softKeyStack.top(); @@ -108,6 +143,18 @@ void QSoftKeyStack::pop() d->pop(); } +void QSoftKeyStack::popandPush(QSoftKeyAction *softKey) +{ + Q_D(QSoftKeyStack); + d->popandPush(softKey); +} + +void QSoftKeyStack::popandPush(const QList<QSoftKeyAction*> &softkeys) +{ + Q_D(QSoftKeyStack); + d->popandPush(softkeys); +} + const QSoftkeySet& QSoftKeyStack::top() { Q_D(QSoftKeyStack); @@ -123,8 +170,6 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) if( !mainWindow) return; QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); - if (old) - softKeyStack->pop(); Qt::ContextMenuPolicy policy = now->contextMenuPolicy(); if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { @@ -133,7 +178,10 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) QSoftKeyAction* contextMenu = new QSoftKeyAction(QSoftKeyAction::ContextMenu, QString::fromLatin1("ContextMenu"), now); actionList.append(menu); actionList.append(contextMenu); - softKeyStack->push(actionList); + if (old) + softKeyStack->popandPush(actionList); + else + softKeyStack->push(actionList); } } diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h index 2a63ab8..10d9153 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -66,6 +66,8 @@ public: void push(QSoftKeyAction *softKey); void push(const QList<QSoftKeyAction*> &softkeys); void pop(); + void popandPush(QSoftKeyAction *softKey); + void popandPush(const QList<QSoftKeyAction*> &softkeys); const QSoftkeySet& top(); void handleSoftKeyPress(int command); diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index 2469648..57475bd 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -77,6 +77,8 @@ public: void push(QSoftKeyAction *softKey); void push(const QList<QSoftKeyAction*> &softKeys); void pop(); + void popandPush(QSoftKeyAction *softKey); + void popandPush(const QList<QSoftKeyAction*> &softkeys); const QSoftkeySet& top(); void handleSoftKeyPress(int command); |