source: trunk/examples/tools/inputpanel/myinputpanel.cpp@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

  • Property svn:eol-style set to native
File size: 4.8 KB
RevLine 
[556]1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the examples of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "myinputpanel.h"
43
44//! [0]
45
46MyInputPanel::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
99bool 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
117void 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
128void MyInputPanel::buttonClicked(QWidget *w)
129{
130 QChar chr = qvariant_cast<QChar>(w->property("buttonValue"));
131 emit characterGenerated(chr);
132}
133
134//! [3]
Note: See TracBrowser for help on using the repository browser.