diff options
author | Markku Luukkainen <markku.luukkainen@digia.com> | 2009-06-05 15:02:56 (GMT) |
---|---|---|
committer | Markku Luukkainen <markku.luukkainen@digia.com> | 2009-06-05 15:02:56 (GMT) |
commit | dfffbd4d134f9b8adc75b2c33c31a2ee859903e6 (patch) | |
tree | c705b68fc0ff7ac73d18413cc48eb857cc97015c /src | |
parent | 93ea4a9cd6336de6e2a63b1ca075a7fdb835cfa7 (diff) | |
download | Qt-dfffbd4d134f9b8adc75b2c33c31a2ee859903e6.zip Qt-dfffbd4d134f9b8adc75b2c33c31a2ee859903e6.tar.gz Qt-dfffbd4d134f9b8adc75b2c33c31a2ee859903e6.tar.bz2 |
Initial version of softkey implementation that doesn't use
softkeystack but instead softkeys are stored in QWidgets.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 35 | ||||
-rw-r--r-- | src/gui/kernel/qwidget.h | 4 | ||||
-rw-r--r-- | src/gui/kernel/qwidget_p.h | 4 | ||||
-rw-r--r-- | src/gui/kernel/qwidget_s60.cpp | 91 | ||||
-rw-r--r-- | src/gui/widgets/qmainwindow.cpp | 11 | ||||
-rw-r--r-- | src/gui/widgets/qsoftkeystack.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/qsoftkeystack_s60.cpp | 1 |
7 files changed, 144 insertions, 4 deletions
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 955ac8b..157a18e 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -5715,9 +5715,12 @@ bool QWidget::hasFocus() const void QWidget::setFocus(Qt::FocusReason reason) { + Q_D(QWidget); + d->setNativeSoftKeys(softKeys()); + if (!isEnabled()) return; - + QWidget *f = this; while (f->d_func()->extra && f->d_func()->extra->focus_proxy) f = f->d_func()->extra->focus_proxy; @@ -11509,6 +11512,36 @@ void QWidget::clearMask() setMask(QRegion()); } +const QList<QSoftKeyAction*>& QWidget::softKeys() const +{ + Q_D(const QWidget); + if( d->softKeys.count() > 0) + return d->softKeys; + + if (isWindow() || !parentWidget()) + return d->softKeys; + + return parentWidget()->softKeys(); +} + +void QWidget::setSoftKeys(QSoftKeyAction *softKey) +{ + Q_D(QWidget); + qDeleteAll(d->softKeys); + d->softKeys.append(softKey); +// d->setNativeSoftKeys(softkeys); +} + +void QWidget::setSoftKeys(const QList<QSoftKeyAction*> &softKeys) +{ + Q_D(QWidget); + qDeleteAll(d->softKeys); + for(int i = 0; i < softKeys.count(); i++) + d->softKeys.append(softKeys.at(i)); + + // d->setNativeSoftKeys(softkeys); +} + /*! \fn const QX11Info &QWidget::x11Info() const Returns information about the configuration of the X display used to display the widget. diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index 0dd470d..516d69a 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -70,6 +70,7 @@ class QWSRegionManager; class QStyle; class QAction; class QVariant; +class QSoftKeyAction; class QActionEvent; class QMouseEvent; @@ -554,6 +555,9 @@ public: void removeAction(QAction *action); QList<QAction*> actions() const; #endif + const QList<QSoftKeyAction*>& softKeys() const; + void setSoftKeys(QSoftKeyAction *softKey); + void setSoftKeys(const QList<QSoftKeyAction*> &softKeys); QWidget *parentWidget() const; diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index d5f1b98..90d9c93 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -85,6 +85,7 @@ class CCoeControl; class CAknTitlePane; class CAknContextPane; #endif +class QSoftKeyAction; QT_BEGIN_NAMESPACE @@ -102,6 +103,7 @@ class QPixmap; class QWidgetBackingStore; class QGraphicsProxyWidget; class QWidgetItemV2; +class QSoftKeyAction; class QStyle; @@ -224,6 +226,7 @@ public: explicit QWidgetPrivate(int version = QObjectPrivateVersion); ~QWidgetPrivate(); + void setNativeSoftKeys(const QList<QSoftKeyAction*> &softkeys); QWExtra *extraData() const; QTLWExtra *topData() const; QTLWExtra *maybeTopData() const; @@ -511,6 +514,7 @@ public: #ifndef QT_NO_ACTION QList<QAction*> actions; #endif + QList<QSoftKeyAction*> softKeys; QLayout *layout; QWidgetItemV2 *widgetItem; #if !defined(QT_NO_IM) diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index 11cb974..c39dbf4 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -52,6 +52,9 @@ #include <qinputcontext.h> +#include <aknappui.h> +#include "qsoftkeyaction.h" + QT_BEGIN_NAMESPACE extern bool qt_nograb(); @@ -59,6 +62,83 @@ extern bool qt_nograb(); QWidget *QWidgetPrivate::mouseGrabber = 0; QWidget *QWidgetPrivate::keyboardGrabber = 0; +#define QSoftkeySet QList <QSoftKeyAction*> +// The following 2 defines may only be needed for s60. To be seen. +#define SOFTKEYSTART 5000 +#define SOFTKEYEND (5000 + Qt::Key_Context4-Qt::Key_Context1) + +static void mapSoftKeys(const QSoftkeySet &softkeys) +{ + if (softkeys.count() == 1 && softkeys.at(0)->role()==QSoftKeyAction::Menu) { + softkeys.at(0)->setNativePosition(0); + softkeys.at(0)->setQtContextKey(Qt::Key_Context1); + } + else if(softkeys.count() == 1 && softkeys.at(0)->role()!=QSoftKeyAction::Menu) { + softkeys.at(0)->setNativePosition(2); + softkeys.at(0)->setQtContextKey(Qt::Key_Context1); + } + else { + // FIX THIS + // veryWeirdMagic is needes as s60 5th edition sdk always panics if cba is set with index 1, this hops over it + // This needs further investigation why so that the hack can be removed + int veryWeirdMagic = 0; + for (int index = 0; index < softkeys.count(); index++) { + softkeys.at(index)->setNativePosition(index + veryWeirdMagic); + softkeys.at(index)->setQtContextKey(Qt::Key_Context1 + index); + if (veryWeirdMagic == 0) + veryWeirdMagic = 1; + } + } +} + +static bool isSame(const QList<QSoftKeyAction*>& a, const QList<QSoftKeyAction*>& 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; +} + + +void QWidgetPrivate::setNativeSoftKeys(const QList<QSoftKeyAction*> &softkeys) +{ + if (QApplication::focusWidget()) { + QList<QSoftKeyAction*> old = QApplication::focusWidget()->softKeys(); + if (isSame(old, softkeys )) + return; + } + + CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); + CAknAppUi* aknAppUi = static_cast <CAknAppUi*>(appui); + CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); + nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); + + mapSoftKeys(softkeys); + + for (int index = 0; index < softkeys.count(); index++) { + const QSoftKeyAction* softKeyAction = softkeys.at(index); + if (softKeyAction->role() != QSoftKeyAction::ContextMenu) { + + HBufC* text = qt_QString2HBufCNewL(softKeyAction->text()); + CleanupStack::PushL(text); + if (softKeyAction->role() == QSoftKeyAction::Menu) { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), EAknSoftkeyOptions, *text); + } else { + nativeContainer->SetCommandL(softKeyAction->nativePosition(), SOFTKEYSTART + softKeyAction->qtContextKey()-Qt::Key_Context1, *text); + } + CleanupStack::PopAndDestroy(); + } + } +} + void QWidgetPrivate::setWSGeometry(bool dontShow) { @@ -1003,5 +1083,16 @@ void QWidget::activateWindow() rw->SetOrdinalPosition(0); } } +/* +void QWidget::setSoftKeys(QSoftKeyAction *softKey) +{ + Q_D(QWidget); + d-> +} +void QWidget::setSoftKeys(const QList<QSoftKeyAction*> &softkeys) +{ + Q_D(QWidget); +} +*/ QT_END_NAMESPACE diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 37b1398..20270b4 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -69,6 +69,7 @@ QT_END_NAMESPACE #ifndef QT_NO_SOFTKEYSTACK #include <qsoftkeystack.h> #endif +#include <qsoftkeyaction.h> QT_BEGIN_NAMESPACE @@ -121,9 +122,9 @@ void QMainWindowPrivate::init() explicitIconSize = false; q->setAttribute(Qt::WA_Hover); -#if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SOFTKEYSTACK) - softKeyStack = new QSoftKeyStack(q); -#endif +//#if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SOFTKEYSTACK) +// softKeyStack = new QSoftKeyStack(q); +//#endif } /* @@ -495,6 +496,10 @@ void QMainWindow::setMenuBar(QMenuBar *menuBar) oldMenuBar->deleteLater(); } d->layout->setMenuBar(menuBar); + if (menuBar) { + QSoftKeyAction* menu = new QSoftKeyAction(QSoftKeyAction::Menu, QString::fromLatin1("Menu"), this); + setSoftKeys(menu); + } } /*! diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 9a5a66c..6c00d35 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -196,6 +196,7 @@ QList<QSoftKeyAction*> menuActionList(QWidget *widget) void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) { + return; if (!now) return; QWidget *w = qApp->activeWindow(); @@ -252,6 +253,7 @@ QToolBar* softKeyToolBar(QMainWindow *mainWindow) void QSoftKeyStackPrivate::setNativeSoftKeys() { + return; Q_Q(QSoftKeyStack); QMainWindow *parent = qobject_cast<QMainWindow*>(q->parent()); if (!parent) diff --git a/src/gui/widgets/qsoftkeystack_s60.cpp b/src/gui/widgets/qsoftkeystack_s60.cpp index 8dfd5dd..a315a3b 100644 --- a/src/gui/widgets/qsoftkeystack_s60.cpp +++ b/src/gui/widgets/qsoftkeystack_s60.cpp @@ -73,6 +73,7 @@ void QSoftKeyStackPrivate::mapSoftKeys(const QSoftkeySet &top) void QSoftKeyStackPrivate::setNativeSoftKeys() { + return; CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); CAknAppUi* aknAppUi = static_cast <CAknAppUi*>(appui); CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); |