diff options
-rw-r--r-- | src/gui/widgets/qmenu_symbian.cpp | 27 | ||||
-rw-r--r-- | src/gui/widgets/qsoftkeystack.cpp | 65 | ||||
-rw-r--r-- | src/gui/widgets/qsoftkeystack.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/qsoftkeystack_p.h | 3 |
4 files changed, 82 insertions, 16 deletions
diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index 1cff1bf..491c78e 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -185,20 +185,21 @@ static void rebuildMenu() QWidget *w = qApp->activeWindow(); QMainWindow *mainWindow = qobject_cast<QMainWindow*>(w); QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); - const QSoftkeySet& softKeyTop = softKeyStack->top(); - - int index=0; - bool found=false; - while( index<softKeyTop.count() && !found) { - QSoftKeyAction* softAction = softKeyTop.at(index); - QSoftKeyAction::StandardRole role = softAction->role(); - if(softAction->role() == QSoftKeyAction::ContextMenu) { - widgetWithContextMenu = softAction->parentWidget(); - found=true; - } - index++; + if (!softKeyStack->isEmpty()) { + const QSoftkeySet& softKeyTop = softKeyStack->top(); + int index=0; + bool found=false; + while( index<softKeyTop.count() && !found) { + QSoftKeyAction* softAction = softKeyTop.at(index); + QSoftKeyAction::StandardRole role = softAction->role(); + if(softAction->role() == QSoftKeyAction::ContextMenu) { + widgetWithContextMenu = softAction->parentWidget(); + found=true; + } + index++; + } } - + if (w) { mb = menubars()->value(w); qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 05fe397..0054c6b 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,11 +91,35 @@ 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(); } +bool QSoftKeyStackPrivate::isEmpty() +{ + return softKeyStack.isEmpty(); +} + QSoftKeyStack::QSoftKeyStack(QWidget *parent) : QObject(*new QSoftKeyStackPrivate, parent) { @@ -108,12 +148,30 @@ 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); return d->top(); } +bool QSoftKeyStack::isEmpty() +{ + Q_D(QSoftKeyStack); + return d->isEmpty(); +} + void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) { if (!now) @@ -123,8 +181,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 +189,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..2606bd1 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -66,7 +66,10 @@ 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(); + bool isEmpty(); void handleSoftKeyPress(int command); diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h index 2469648..b698178 100644 --- a/src/gui/widgets/qsoftkeystack_p.h +++ b/src/gui/widgets/qsoftkeystack_p.h @@ -77,7 +77,10 @@ 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(); + bool isEmpty(); void handleSoftKeyPress(int command); private: |