|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "myinputpanel.h" |
|
43 |
|
44 //! [0] |
|
45 |
|
46 MyInputPanel::MyInputPanel() |
|
47 : QWidget(0, Qt::Tool | Qt::WindowStaysOnTopHint), |
|
48 lastFocusedWidget(0) |
|
49 { |
|
50 form.setupUi(this); |
|
51 |
|
52 connect(qApp, SIGNAL(focusChanged(QWidget *, QWidget *)), |
|
53 this, SLOT(saveFocusWidget(QWidget *, QWidget *))); |
|
54 |
|
55 signalMapper.setMapping(form.panelButton_1, form.panelButton_1); |
|
56 signalMapper.setMapping(form.panelButton_2, form.panelButton_2); |
|
57 signalMapper.setMapping(form.panelButton_3, form.panelButton_3); |
|
58 signalMapper.setMapping(form.panelButton_4, form.panelButton_4); |
|
59 signalMapper.setMapping(form.panelButton_5, form.panelButton_5); |
|
60 signalMapper.setMapping(form.panelButton_6, form.panelButton_6); |
|
61 signalMapper.setMapping(form.panelButton_7, form.panelButton_7); |
|
62 signalMapper.setMapping(form.panelButton_8, form.panelButton_8); |
|
63 signalMapper.setMapping(form.panelButton_9, form.panelButton_9); |
|
64 signalMapper.setMapping(form.panelButton_star, form.panelButton_star); |
|
65 signalMapper.setMapping(form.panelButton_0, form.panelButton_0); |
|
66 signalMapper.setMapping(form.panelButton_hash, form.panelButton_hash); |
|
67 |
|
68 connect(form.panelButton_1, SIGNAL(clicked()), |
|
69 &signalMapper, SLOT(map())); |
|
70 connect(form.panelButton_2, SIGNAL(clicked()), |
|
71 &signalMapper, SLOT(map())); |
|
72 connect(form.panelButton_3, SIGNAL(clicked()), |
|
73 &signalMapper, SLOT(map())); |
|
74 connect(form.panelButton_4, SIGNAL(clicked()), |
|
75 &signalMapper, SLOT(map())); |
|
76 connect(form.panelButton_5, SIGNAL(clicked()), |
|
77 &signalMapper, SLOT(map())); |
|
78 connect(form.panelButton_6, SIGNAL(clicked()), |
|
79 &signalMapper, SLOT(map())); |
|
80 connect(form.panelButton_7, SIGNAL(clicked()), |
|
81 &signalMapper, SLOT(map())); |
|
82 connect(form.panelButton_8, SIGNAL(clicked()), |
|
83 &signalMapper, SLOT(map())); |
|
84 connect(form.panelButton_9, SIGNAL(clicked()), |
|
85 &signalMapper, SLOT(map())); |
|
86 connect(form.panelButton_star, SIGNAL(clicked()), |
|
87 &signalMapper, SLOT(map())); |
|
88 connect(form.panelButton_0, SIGNAL(clicked()), |
|
89 &signalMapper, SLOT(map())); |
|
90 connect(form.panelButton_hash, SIGNAL(clicked()), |
|
91 &signalMapper, SLOT(map())); |
|
92 |
|
93 connect(&signalMapper, SIGNAL(mapped(QWidget *)), |
|
94 this, SLOT(buttonClicked(QWidget *))); |
|
95 } |
|
96 |
|
97 //! [0] |
|
98 |
|
99 bool MyInputPanel::event(QEvent *e) |
|
100 { |
|
101 switch (e->type()) { |
|
102 //! [1] |
|
103 case QEvent::WindowActivate: |
|
104 if (lastFocusedWidget) |
|
105 lastFocusedWidget->activateWindow(); |
|
106 break; |
|
107 //! [1] |
|
108 default: |
|
109 break; |
|
110 } |
|
111 |
|
112 return QWidget::event(e); |
|
113 } |
|
114 |
|
115 //! [2] |
|
116 |
|
117 void MyInputPanel::saveFocusWidget(QWidget * /*oldFocus*/, QWidget *newFocus) |
|
118 { |
|
119 if (newFocus != 0 && !this->isAncestorOf(newFocus)) { |
|
120 lastFocusedWidget = newFocus; |
|
121 } |
|
122 } |
|
123 |
|
124 //! [2] |
|
125 |
|
126 //! [3] |
|
127 |
|
128 void MyInputPanel::buttonClicked(QWidget *w) |
|
129 { |
|
130 QChar chr = qvariant_cast<QChar>(w->property("buttonValue")); |
|
131 emit characterGenerated(chr); |
|
132 } |
|
133 |
|
134 //! [3] |