| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the examples of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:BSD$ | 
|---|
| 10 | ** You may use this file under the terms of the BSD license as follows: | 
|---|
| 11 | ** | 
|---|
| 12 | ** "Redistribution and use in source and binary forms, with or without | 
|---|
| 13 | ** modification, are permitted provided that the following conditions are | 
|---|
| 14 | ** met: | 
|---|
| 15 | **   * Redistributions of source code must retain the above copyright | 
|---|
| 16 | **     notice, this list of conditions and the following disclaimer. | 
|---|
| 17 | **   * Redistributions in binary form must reproduce the above copyright | 
|---|
| 18 | **     notice, this list of conditions and the following disclaimer in | 
|---|
| 19 | **     the documentation and/or other materials provided with the | 
|---|
| 20 | **     distribution. | 
|---|
| 21 | **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor | 
|---|
| 22 | **     the names of its contributors may be used to endorse or promote | 
|---|
| 23 | **     products derived from this software without specific prior written | 
|---|
| 24 | **     permission. | 
|---|
| 25 | ** | 
|---|
| 26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
|---|
| 27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
|---|
| 28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
|---|
| 29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
|---|
| 30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
|---|
| 31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
|---|
| 32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
|---|
| 33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|---|
| 34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|---|
| 35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
|---|
| 36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." | 
|---|
| 37 | ** $QT_END_LICENSE$ | 
|---|
| 38 | ** | 
|---|
| 39 | ****************************************************************************/ | 
|---|
| 40 |  | 
|---|
| 41 | #include "myinputpanel.h" | 
|---|
| 42 |  | 
|---|
| 43 | //! [0] | 
|---|
| 44 |  | 
|---|
| 45 | MyInputPanel::MyInputPanel() | 
|---|
| 46 | : QWidget(0, Qt::Tool | Qt::WindowStaysOnTopHint), | 
|---|
| 47 | lastFocusedWidget(0) | 
|---|
| 48 | { | 
|---|
| 49 | form.setupUi(this); | 
|---|
| 50 |  | 
|---|
| 51 | connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), | 
|---|
| 52 | this, SLOT(saveFocusWidget(QWidget*,QWidget*))); | 
|---|
| 53 |  | 
|---|
| 54 | signalMapper.setMapping(form.panelButton_1, form.panelButton_1); | 
|---|
| 55 | signalMapper.setMapping(form.panelButton_2, form.panelButton_2); | 
|---|
| 56 | signalMapper.setMapping(form.panelButton_3, form.panelButton_3); | 
|---|
| 57 | signalMapper.setMapping(form.panelButton_4, form.panelButton_4); | 
|---|
| 58 | signalMapper.setMapping(form.panelButton_5, form.panelButton_5); | 
|---|
| 59 | signalMapper.setMapping(form.panelButton_6, form.panelButton_6); | 
|---|
| 60 | signalMapper.setMapping(form.panelButton_7, form.panelButton_7); | 
|---|
| 61 | signalMapper.setMapping(form.panelButton_8, form.panelButton_8); | 
|---|
| 62 | signalMapper.setMapping(form.panelButton_9, form.panelButton_9); | 
|---|
| 63 | signalMapper.setMapping(form.panelButton_star, form.panelButton_star); | 
|---|
| 64 | signalMapper.setMapping(form.panelButton_0, form.panelButton_0); | 
|---|
| 65 | signalMapper.setMapping(form.panelButton_hash, form.panelButton_hash); | 
|---|
| 66 |  | 
|---|
| 67 | connect(form.panelButton_1, SIGNAL(clicked()), | 
|---|
| 68 | &signalMapper, SLOT(map())); | 
|---|
| 69 | connect(form.panelButton_2, SIGNAL(clicked()), | 
|---|
| 70 | &signalMapper, SLOT(map())); | 
|---|
| 71 | connect(form.panelButton_3, SIGNAL(clicked()), | 
|---|
| 72 | &signalMapper, SLOT(map())); | 
|---|
| 73 | connect(form.panelButton_4, SIGNAL(clicked()), | 
|---|
| 74 | &signalMapper, SLOT(map())); | 
|---|
| 75 | connect(form.panelButton_5, SIGNAL(clicked()), | 
|---|
| 76 | &signalMapper, SLOT(map())); | 
|---|
| 77 | connect(form.panelButton_6, SIGNAL(clicked()), | 
|---|
| 78 | &signalMapper, SLOT(map())); | 
|---|
| 79 | connect(form.panelButton_7, SIGNAL(clicked()), | 
|---|
| 80 | &signalMapper, SLOT(map())); | 
|---|
| 81 | connect(form.panelButton_8, SIGNAL(clicked()), | 
|---|
| 82 | &signalMapper, SLOT(map())); | 
|---|
| 83 | connect(form.panelButton_9, SIGNAL(clicked()), | 
|---|
| 84 | &signalMapper, SLOT(map())); | 
|---|
| 85 | connect(form.panelButton_star, SIGNAL(clicked()), | 
|---|
| 86 | &signalMapper, SLOT(map())); | 
|---|
| 87 | connect(form.panelButton_0, SIGNAL(clicked()), | 
|---|
| 88 | &signalMapper, SLOT(map())); | 
|---|
| 89 | connect(form.panelButton_hash, SIGNAL(clicked()), | 
|---|
| 90 | &signalMapper, SLOT(map())); | 
|---|
| 91 |  | 
|---|
| 92 | connect(&signalMapper, SIGNAL(mapped(QWidget*)), | 
|---|
| 93 | this, SLOT(buttonClicked(QWidget*))); | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 | //! [0] | 
|---|
| 97 |  | 
|---|
| 98 | bool MyInputPanel::event(QEvent *e) | 
|---|
| 99 | { | 
|---|
| 100 | switch (e->type()) { | 
|---|
| 101 | //! [1] | 
|---|
| 102 | case QEvent::WindowActivate: | 
|---|
| 103 | if (lastFocusedWidget) | 
|---|
| 104 | lastFocusedWidget->activateWindow(); | 
|---|
| 105 | break; | 
|---|
| 106 | //! [1] | 
|---|
| 107 | default: | 
|---|
| 108 | break; | 
|---|
| 109 | } | 
|---|
| 110 |  | 
|---|
| 111 | return QWidget::event(e); | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | //! [2] | 
|---|
| 115 |  | 
|---|
| 116 | void MyInputPanel::saveFocusWidget(QWidget * /*oldFocus*/, QWidget *newFocus) | 
|---|
| 117 | { | 
|---|
| 118 | if (newFocus != 0 && !this->isAncestorOf(newFocus)) { | 
|---|
| 119 | lastFocusedWidget = newFocus; | 
|---|
| 120 | } | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | //! [2] | 
|---|
| 124 |  | 
|---|
| 125 | //! [3] | 
|---|
| 126 |  | 
|---|
| 127 | void MyInputPanel::buttonClicked(QWidget *w) | 
|---|
| 128 | { | 
|---|
| 129 | QChar chr = qvariant_cast<QChar>(w->property("buttonValue")); | 
|---|
| 130 | emit characterGenerated(chr); | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 133 | //! [3] | 
|---|