From 9bdd939c508dfe784402c5c3e85e26d135f7643c Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 9 Jun 2009 14:40:56 +0200 Subject: Fixes from code review --- src/gui/itemviews/qabstractitemview.cpp | 6 +- src/gui/kernel/qwidget_s60.cpp | 41 ----------- src/gui/widgets/qactiontokeyeventmapper.cpp | 103 +++++++++++++++++++++++++++ src/gui/widgets/qactiontokeyeventmapper_p.h | 70 +++++++++++++++++++ src/gui/widgets/qcombobox.cpp | 8 +-- src/gui/widgets/qkeyeventsoftkey.cpp | 105 ---------------------------- src/gui/widgets/qkeyeventsoftkey.h | 74 -------------------- src/gui/widgets/qmenu.cpp | 8 +-- src/gui/widgets/widgets.pri | 4 +- 9 files changed, 186 insertions(+), 233 deletions(-) create mode 100644 src/gui/widgets/qactiontokeyeventmapper.cpp create mode 100644 src/gui/widgets/qactiontokeyeventmapper_p.h delete mode 100644 src/gui/widgets/qkeyeventsoftkey.cpp delete mode 100644 src/gui/widgets/qkeyeventsoftkey.h diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 69e630e..af84ea6 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -61,7 +61,7 @@ #ifndef QT_NO_ACCESSIBILITY #include #endif -#include +#include QT_BEGIN_NAMESPACE @@ -2004,14 +2004,14 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event) if (QApplication::keypadNavigationEnabled()) { if (!hasEditFocus()) { setEditFocus(true); - QKeyEventSoftKey::addSoftKey(QAction::BackSoftKey, Qt::Key_Back, this); + QActionToKeyEventMapper::addSoftKey(QAction::BackSoftKey, Qt::Key_Back, this); return; } } break; case Qt::Key_Back: if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { - QKeyEventSoftKey::removeSoftkey(this); + QActionToKeyEventMapper::removeSoftkey(this); setEditFocus(false); } else { event->ignore(); diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index 2a83fc7..cc6f794 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -61,31 +61,6 @@ extern bool qt_nograb(); QWidget *QWidgetPrivate::mouseGrabber = 0; QWidget *QWidgetPrivate::keyboardGrabber = 0; -static void mapSoftKeys(const QList &softkeys) -{ -/* if (softkeys.count() == 1 && softkeys.at(0)->menuRole()==QAction::MenuSoftKey) { - softkeys.at(0)->setNativePosition(0); - softkeys.at(0)->setQtContextKey(Qt::Key_Context1); - } - else if(softkeys.count() == 1 && softkeys.at(0)->menuRole()!=QAction::MenuSoftKey) { - 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 isEqual(const QList& a, const QList& b) { if ( a.count() != b.count()) @@ -110,15 +85,12 @@ void QWidgetPrivate::setSoftKeys_sys(const QList &softkeys) if (isEqual(old, softkeys )) return; } - CCoeAppUi* appui = CEikonEnv::Static()->AppUi(); CAknAppUi* aknAppUi = static_cast (appui); CEikButtonGroupContainer* nativeContainer = aknAppUi->Cba(); nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); - mapSoftKeys(softkeys); int placeInScreen=0; - for (int index = 0; index < softkeys.count(); index++) { const QAction* softKeyAction = softkeys.at(index); if (softKeyAction->softKeyRole() != QAction::ContextMenuSoftKey) { @@ -135,7 +107,6 @@ void QWidgetPrivate::setSoftKeys_sys(const QList &softkeys) } if (placeInScreen==1) placeInScreen=2; - } } @@ -1083,16 +1054,4 @@ void QWidget::activateWindow() rw->SetOrdinalPosition(0); } } -/* -void QWidget::setSoftKeys(QSoftKeyAction *softKey) -{ - Q_D(QWidget); - d-> -} - -void QWidget::setSoftKeys(const QList &softkeys) -{ - Q_D(QWidget); -} -*/ QT_END_NAMESPACE diff --git a/src/gui/widgets/qactiontokeyeventmapper.cpp b/src/gui/widgets/qactiontokeyeventmapper.cpp new file mode 100644 index 0000000..5cce415 --- /dev/null +++ b/src/gui/widgets/qactiontokeyeventmapper.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 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 "qapplication.h" +#include "qevent.h" +#include "QActionToKeyEventMapper_p.h" + +QT_BEGIN_NAMESPACE + +QActionToKeyEventMapper::QActionToKeyEventMapper(QAction *softKeyAction, Qt::Key key, QObject *parent) + : QObject(parent) + , m_softKeyAction(softKeyAction) + , m_key(key) +{ + +} + +QString QActionToKeyEventMapper::roleText(QAction::SoftKeyRole role) +{ + switch (role) { + case QAction::OptionsSoftKey: + return QAction::tr("Options"); + case QAction::SelectSoftKey: + return QAction::tr("Select"); + case QAction::BackSoftKey: + return QAction::tr("Back"); + case QAction::NextSoftKey: + return QAction::tr("Next"); + case QAction::PreviousSoftKey: + return QAction::tr("Previous"); + case QAction::OkSoftKey: + return QAction::tr("Ok"); + case QAction::CancelSoftKey: + return QAction::tr("Cancel"); + case QAction::EditSoftKey: + return QAction::tr("Edit"); + case QAction::ViewSoftKey: + return QAction::tr("View"); + default: + return QString(); + }; +} +void QActionToKeyEventMapper::addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget) +{ + QAction *action = new QAction(actionWidget); + action->setSoftKeyRole(standardRole); + action->setText(roleText(standardRole)); + QActionToKeyEventMapper *softKey = new QActionToKeyEventMapper(action, key, actionWidget); + connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent())); + connect(action, SIGNAL(destroyed()), softKey, SLOT(deleteLater())); + actionWidget->setSoftKey(action); +} + +void QActionToKeyEventMapper::removeSoftkey(QWidget *focussedWidget) +{ + focussedWidget->setSoftKey(0); +} + +void QActionToKeyEventMapper::sendKeyEvent() +{ + QApplication::postEvent(parent(), new QKeyEvent(QEvent::KeyPress, m_key, Qt::NoModifier)); +} + +QT_END_NAMESPACE + diff --git a/src/gui/widgets/qactiontokeyeventmapper_p.h b/src/gui/widgets/qactiontokeyeventmapper_p.h new file mode 100644 index 0000000..da336e8 --- /dev/null +++ b/src/gui/widgets/qactiontokeyeventmapper_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 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$ +** +****************************************************************************/ + +#ifndef QACTIONTOKEYEVENTMAPPER_P_H +#define QACTIONTOKEYEVENTMAPPER_P_H + +#include +#include "QtGui/qaction.h" +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QActionToKeyEventMapper : public QObject +{ + Q_OBJECT +public: + QActionToKeyEventMapper(QAction *softKeyAction, Qt::Key key, QObject *parent); + static QString roleText(QAction::SoftKeyRole role); + static void addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget); + static void removeSoftkey(QWidget *focussedWidget); +private: + QAction *m_softKeyAction; + Qt::Key m_key; +private Q_SLOTS: + void sendKeyEvent(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif //QACTIONTOKEYEVENTMAPPER_H diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 01fcf34..2da5cd0 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -63,7 +63,7 @@ #include #include #include -#include +#include #ifdef Q_WS_X11 #include #endif @@ -629,7 +629,7 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e) #endif if (view->currentIndex().isValid() && (view->currentIndex().flags() & Qt::ItemIsEnabled) ) { #ifdef QT_KEYPAD_NAVIGATION - QKeyEventSoftKey::removeSoftkey(this); + QActionToKeyEventMapper::removeSoftkey(this); #endif combo->hidePopup(); emit itemSelected(view->currentIndex()); @@ -643,7 +643,7 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e) case Qt::Key_Escape: #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Back: - QKeyEventSoftKey::removeSoftkey(this); + QActionToKeyEventMapper::removeSoftkey(this); #endif combo->hidePopup(); return true; @@ -2438,7 +2438,7 @@ void QComboBox::showPopup() #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) view()->setEditFocus(true); - QKeyEventSoftKey::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, view()); + QActionToKeyEventMapper::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, view()); #endif } diff --git a/src/gui/widgets/qkeyeventsoftkey.cpp b/src/gui/widgets/qkeyeventsoftkey.cpp deleted file mode 100644 index f5f10fc..0000000 --- a/src/gui/widgets/qkeyeventsoftkey.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 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 "qapplication.h" -#include "qevent.h" -#include "qkeyeventsoftkey.h" - -QT_BEGIN_NAMESPACE - -QKeyEventSoftKey::QKeyEventSoftKey(QAction *softKeyAction, Qt::Key key, QObject *parent) - : QObject(parent) - , m_softKeyAction(softKeyAction) - , m_key(key) -{ - -} - -QString QKeyEventSoftKey::roleText(QAction::SoftKeyRole role) -{ - switch (role) { - case QAction::OptionsSoftKey: - return QAction::tr("Options"); - case QAction::SelectSoftKey: - return QAction::tr("Select"); - case QAction::BackSoftKey: - return QAction::tr("Back"); - case QAction::NextSoftKey: - return QAction::tr("Next"); - case QAction::PreviousSoftKey: - return QAction::tr("Previous"); - case QAction::OkSoftKey: - return QAction::tr("Ok"); - case QAction::CancelSoftKey: - return QAction::tr("Cancel"); - case QAction::EditSoftKey: - return QAction::tr("Edit"); - case QAction::ViewSoftKey: - return QAction::tr("View"); - default: - return QString(); - }; -} -void QKeyEventSoftKey::addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget) -{ - QAction *action = new QAction(actionWidget); - action->setSoftKeyRole(standardRole); - action->setText(roleText(standardRole)); - QKeyEventSoftKey *softKey = new QKeyEventSoftKey(action, key, actionWidget); - connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent())); - connect(action, SIGNAL(destroyed()), softKey, SLOT(deleteLater())); - actionWidget->setSoftKey(action); -} - -void QKeyEventSoftKey::removeSoftkey(QWidget *focussedWidget) -{ - focussedWidget->setSoftKey(0); -} - -void QKeyEventSoftKey::sendKeyEvent() -{ - QApplication::postEvent(parent(), new QKeyEvent(QEvent::KeyPress, m_key, Qt::NoModifier)); -} - -QT_END_NAMESPACE - -#include "moc_qkeyeventsoftkey.cpp" - diff --git a/src/gui/widgets/qkeyeventsoftkey.h b/src/gui/widgets/qkeyeventsoftkey.h deleted file mode 100644 index 0b95efb..0000000 --- a/src/gui/widgets/qkeyeventsoftkey.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 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$ -** -****************************************************************************/ - -#ifndef QKEYEVENTSOFTKEY_H -#define QKEYEVENTSOFTKEY_H - -#include -#include "QtGui/qaction.h" -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - - - -class Q_GUI_EXPORT QKeyEventSoftKey : QObject -{ - Q_OBJECT -public: - QKeyEventSoftKey(QAction *softKeyAction, Qt::Key key, QObject *parent); - static QString roleText(QAction::SoftKeyRole role); - static void addSoftKey(QAction::SoftKeyRole standardRole, Qt::Key key, QWidget *actionWidget); - static void removeSoftkey(QWidget *focussedWidget); -private: - QAction *m_softKeyAction; - Qt::Key m_key; -private Q_SLOTS: - void sendKeyEvent(); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif //QKEYEVENSOFTKEY_H diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index d713081..3486574 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -60,7 +60,7 @@ #ifndef QT_NO_WHATSTHIS # include #endif -#include +#include #include "qmenu_p.h" #include "qmenubar_p.h" @@ -584,7 +584,7 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason #ifdef QT_KEYPAD_NAVIGATION // TODO: aportale, remove KEYPAD_NAVIGATION_HACK when softkey stack // handles focus related and user related actions separately... - QKeyEventSoftKey::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, q); + QActionToKeyEventMapper::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, q); #endif } } @@ -1945,7 +1945,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) QAccessible::updateAccessibility(this, 0, QAccessible::PopupMenuStart); #endif #ifdef QT_KEYPAD_NAVIGATION - QKeyEventSoftKey::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, this); + QActionToKeyEventMapper::addSoftKey(QAction::CancelSoftKey, Qt::Key_Back, this); #endif } @@ -2597,7 +2597,7 @@ void QMenu::keyPressEvent(QKeyEvent *e) case Qt::Key_Escape: #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Back: - QKeyEventSoftKey::removeSoftkey(this); + QActionToKeyEventMapper::removeSoftkey(this); #endif key_consumed = true; if (d->tornoff) { diff --git a/src/gui/widgets/widgets.pri b/src/gui/widgets/widgets.pri index f395c76..9e226e2 100644 --- a/src/gui/widgets/widgets.pri +++ b/src/gui/widgets/widgets.pri @@ -79,7 +79,7 @@ HEADERS += \ widgets/qplaintextedit.h \ widgets/qplaintextedit_p.h \ widgets/qprintpreviewwidget.h \ - widgets/qkeyeventsoftkey.h + widgets/qactiontokeyeventmapper_p.h SOURCES += \ widgets/qabstractbutton.cpp \ widgets/qabstractslider.cpp \ @@ -139,7 +139,7 @@ SOURCES += \ widgets/qtoolbararealayout.cpp \ widgets/qplaintextedit.cpp \ widgets/qprintpreviewwidget.cpp \ - widgets/qkeyeventsoftkey.cpp + widgets/qactiontokeyeventmapper.cpp !embedded:mac { HEADERS += widgets/qmacnativewidget_mac.h \ -- cgit v0.12