diff options
author | Tomas Junnonen <tomas.junnonen@nokia.com> | 2010-05-29 17:18:21 +0300 |
---|---|---|
committer | Tomas Junnonen <tomas.junnonen@nokia.com> | 2010-07-22 10:24:09 +0300 |
commit | eb95f5ee90cdebe4d95e854e18a75b68553e4013 (patch) | |
tree | 13a4c58ae2e676177273af1dee8f95df81af5981 /examples | |
parent | 92e1745f8e8ec364cfc9e0030a4137eddf11e1f3 (diff) |
Fixes: NB#166004 - Unexpected input focus behaviour when focused widget is covered by app menues or app dialogs
Modified by: Dominik Kapusta
RevBy: Tomas Junnonen, Daniel d'Andrada
Details: SceneManager now sends QEvent::WindowBlocked and QEvent::WindowUnBlocked
to the active MApplicationPage. This allows applications to perform actions when
for example the object menu, dialogs or the application menu is opened or closed.
A new example of how to for instance manage application focus in such cases has
been added to the examples directory.
Added examples/focus to demonstrate focus handling with both signals and the event.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/focus/focus.pro | 19 | ||||
-rw-r--r-- | examples/focus/main.cpp | 54 | ||||
-rw-r--r-- | examples/focus/mydialog.cpp | 25 | ||||
-rw-r--r-- | examples/focus/mydialog.h | 21 | ||||
-rw-r--r-- | examples/focus/mypage.cpp | 42 | ||||
-rw-r--r-- | examples/focus/mypage.h | 21 |
6 files changed, 182 insertions, 0 deletions
diff --git a/examples/focus/focus.pro b/examples/focus/focus.pro new file mode 100644 index 00000000..5aefe43c --- /dev/null +++ b/examples/focus/focus.pro @@ -0,0 +1,19 @@ +TEMPLATE = app +TARGET = focus +CONFIG += meegotouch + +# Input +SOURCES += main.cpp \ + mydialog.cpp \ + mypage.cpp + +HEADERS += \ + mydialog.h \ + mypage.h + +# The following lines are only to allow building the +# example inside the source tree without installing +# libmeegotouch first: +INCLUDEPATH += ../../src/include +QMAKE_LIBDIR += ../../lib/ +LIBS += -lmeegotouchcore diff --git a/examples/focus/main.cpp b/examples/focus/main.cpp new file mode 100644 index 00000000..2d489d19 --- /dev/null +++ b/examples/focus/main.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libmeegotouch. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it 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. +** +****************************************************************************/ + +/* + * An example of managing focus. + * + * The example starts out with no widget being focused. + * If the text entry on the page is clicked, it receives focus as expected. + * + * If the application menu or the example dialog is opened, the entry on the + * page loses focus. The entry inside the dialog automatically gains focus when + * it is opened. Closing the dialog or application menu automatically focuses + * the text entry on the page. + * + */ + +#include <MApplication> +#include <MApplicationWindow> +#include <MScene> +#include <MTextEdit> +#include <MButton> +#include <QGraphicsLinearLayout> + +#include "mypage.h" +#include "mydialog.h" + +int main(int argc, char **argv) +{ + MApplication app(argc, argv); + + MApplicationWindow w; + w.show(); + + MyPage p; + p.appear(); + + return app.exec(); +} diff --git a/examples/focus/mydialog.cpp b/examples/focus/mydialog.cpp new file mode 100644 index 00000000..8c05ac64 --- /dev/null +++ b/examples/focus/mydialog.cpp @@ -0,0 +1,25 @@ +#include "mydialog.h" + +#include <QGraphicsLinearLayout> +#include <MTextEdit> +#include <MLabel> + +MyDialog::MyDialog() + : MDialog("Dialogs are neat!", 0) +{ + QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, centralWidget()); + MLabel *label = new MLabel("Don't you agree?"); + textEdit = new MTextEdit(MTextEditModel::SingleLine); + layout->addItem(label); + layout->addItem(textEdit); + + addButton("Undoubtedly!"); + addButton("Meh..."); + + connect(this, SIGNAL(appeared()), this, SLOT(focusTextEntry())); +} + +void MyDialog::focusTextEntry() +{ + textEdit->setFocus(); +} diff --git a/examples/focus/mydialog.h b/examples/focus/mydialog.h new file mode 100644 index 00000000..63625555 --- /dev/null +++ b/examples/focus/mydialog.h @@ -0,0 +1,21 @@ +#ifndef MYDIALOG_H +#define MYDIALOG_H + +#include <MDialog> + +class MTextEdit; + +class MyDialog : public MDialog +{ + Q_OBJECT +public: + MyDialog(); + +private Q_SLOTS: + void focusTextEntry(); + +private: + MTextEdit *textEdit; +}; + +#endif // MYDIALOG_H diff --git a/examples/focus/mypage.cpp b/examples/focus/mypage.cpp new file mode 100644 index 00000000..6c355fd1 --- /dev/null +++ b/examples/focus/mypage.cpp @@ -0,0 +1,42 @@ +#include <QGraphicsLinearLayout> +#include <MTextEdit> +#include <MButton> +#include <MDebug> +#include <MAction> + +#include "mypage.h" +#include "mydialog.h" + +MyPage::MyPage() +{ + setTitle("Focus example"); + + QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(centralWidget()); + + textEdit = new MTextEdit; + textEdit->setPrompt("Click to focus"); + layout->addItem(textEdit); + + MButton *button = new MButton("Open dialog"); + layout->addItem(button); + + MyDialog *dialog = new MyDialog(); + + QObject::connect(button, SIGNAL(clicked()), dialog, SLOT(appear())); + + MAction *action = new MAction("Hello!", this); + action->setLocation(MAction::ApplicationMenuLocation); + addAction(action); +} + +bool MyPage::event(QEvent *e) +{ + if (e->type() == QEvent::WindowBlocked) { + mDebug("MyPage") << "Help! Help! I'm Being Oppressed!"; + } + if (e->type() == QEvent::WindowUnblocked) { + textEdit->setFocus(); + } + + return MApplicationPage::event(e); +} diff --git a/examples/focus/mypage.h b/examples/focus/mypage.h new file mode 100644 index 00000000..f305e6a9 --- /dev/null +++ b/examples/focus/mypage.h @@ -0,0 +1,21 @@ +#ifndef MYPAGE_H +#define MYPAGE_H + +#include <MApplicationPage> + +class MTextEdit; + +class MyPage : public MApplicationPage +{ + Q_OBJECT +public: + MyPage(); + +protected: + virtual bool event(QEvent *e); + +private: + MTextEdit *textEdit; +}; + +#endif // MYPAGE_H |