0
|
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 <QtGui>
|
|
43 |
#include "ui_keypadnavigation.h"
|
|
44 |
|
|
45 |
class KeypadNavigation : public QMainWindow
|
|
46 |
{
|
|
47 |
Q_OBJECT
|
|
48 |
|
|
49 |
public:
|
|
50 |
KeypadNavigation(QWidget *parent = 0)
|
|
51 |
: QMainWindow(parent)
|
|
52 |
, ui(new Ui_KeypadNavigation)
|
|
53 |
{
|
|
54 |
ui->setupUi(this);
|
|
55 |
|
|
56 |
const struct {
|
|
57 |
QObject *action;
|
|
58 |
QWidget *page;
|
|
59 |
} layoutMappings[] = {
|
|
60 |
{ui->m_actionLayoutVerticalSimple, ui->m_pageVerticalSimple},
|
|
61 |
{ui->m_actionLayoutVerticalComplex, ui->m_pageVerticalComplex},
|
|
62 |
{ui->m_actionLayoutTwoDimensional, ui->m_pageTwoDimensional},
|
|
63 |
{ui->m_actionLayoutSliderMagic, ui->m_pageSliderMagic},
|
|
64 |
{ui->m_actionLayoutChaos, ui->m_pageChaos},
|
|
65 |
{ui->m_actionLayoutDialogs, ui->m_pageDialogs}
|
|
66 |
};
|
|
67 |
for (int i = 0; i < int(sizeof layoutMappings / sizeof layoutMappings[0]); ++i) {
|
|
68 |
connect(layoutMappings[i].action, SIGNAL(triggered()), &m_layoutSignalMapper, SLOT(map()));
|
|
69 |
m_layoutSignalMapper.setMapping(layoutMappings[i].action, layoutMappings[i].page);
|
|
70 |
}
|
|
71 |
connect(&m_layoutSignalMapper, SIGNAL(mapped(QWidget*)), ui->m_stackWidget, SLOT(setCurrentWidget(QWidget*)));
|
|
72 |
|
|
73 |
const struct {
|
|
74 |
QObject *action;
|
|
75 |
Qt::NavigationMode mode;
|
|
76 |
} modeMappings[] = {
|
|
77 |
{ui->m_actionModeNone, Qt::NavigationModeNone},
|
|
78 |
{ui->m_actionModeKeypadTabOrder, Qt::NavigationModeKeypadTabOrder},
|
|
79 |
{ui->m_actionModeKeypadDirectional, Qt::NavigationModeKeypadDirectional},
|
|
80 |
{ui->m_actionModeCursorAuto, Qt::NavigationModeCursorAuto},
|
|
81 |
{ui->m_actionModeCursorForceVisible, Qt::NavigationModeCursorForceVisible}
|
|
82 |
};
|
|
83 |
for (int i = 0; i < int(sizeof modeMappings / sizeof modeMappings[0]); ++i) {
|
|
84 |
connect(modeMappings[i].action, SIGNAL(triggered()), &m_modeSignalMapper, SLOT(map()));
|
|
85 |
m_modeSignalMapper.setMapping(modeMappings[i].action, int(modeMappings[i].mode));
|
|
86 |
}
|
|
87 |
connect(&m_modeSignalMapper, SIGNAL(mapped(int)), SLOT(setNavigationMode(int)));
|
|
88 |
|
|
89 |
const struct {
|
|
90 |
QObject *button;
|
|
91 |
Dialog dialog;
|
|
92 |
} openDialogMappings[] = {
|
|
93 |
{ui->m_buttonGetOpenFileName, DialogGetOpenFileName},
|
|
94 |
{ui->m_buttonGetSaveFileName, DialogGetSaveFileName},
|
|
95 |
{ui->m_buttonGetExistingDirectory, DialogGetExistingDirectory},
|
|
96 |
{ui->m_buttonGetColor, DialogGetColor},
|
|
97 |
{ui->m_buttonGetFont, DialogGetFont},
|
|
98 |
{ui->m_buttonQuestion, DialogQuestion},
|
|
99 |
{ui->m_buttonAboutQt, DialogAboutQt},
|
|
100 |
{ui->m_buttonGetItem, DialogGetItem}
|
|
101 |
};
|
|
102 |
for (int i = 0; i < int(sizeof openDialogMappings / sizeof openDialogMappings[0]); ++i) {
|
|
103 |
connect(openDialogMappings[i].button, SIGNAL(clicked()), &m_dialogSignalMapper, SLOT(map()));
|
|
104 |
m_dialogSignalMapper.setMapping(openDialogMappings[i].button, int(openDialogMappings[i].dialog));
|
|
105 |
}
|
|
106 |
connect(&m_dialogSignalMapper, SIGNAL(mapped(int)), SLOT(openDialog(int)));
|
|
107 |
}
|
|
108 |
|
|
109 |
~KeypadNavigation()
|
|
110 |
{
|
|
111 |
delete ui;
|
|
112 |
}
|
|
113 |
|
|
114 |
protected slots:
|
|
115 |
void setNavigationMode(int mode)
|
|
116 |
{
|
|
117 |
QApplication::setNavigationMode(Qt::NavigationMode(mode));
|
|
118 |
}
|
|
119 |
|
|
120 |
void openDialog(int dialog)
|
|
121 |
{
|
|
122 |
switch (Dialog(dialog)) {
|
|
123 |
case DialogGetOpenFileName:
|
|
124 |
QFileDialog::getOpenFileName(this, QLatin1String("getOpenFileName"));
|
|
125 |
break;
|
|
126 |
case DialogGetSaveFileName:
|
|
127 |
QFileDialog::getSaveFileName(this, QLatin1String("getSaveFileName"));
|
|
128 |
break;
|
|
129 |
case DialogGetExistingDirectory:
|
|
130 |
QFileDialog::getExistingDirectory(this, QLatin1String("getExistingDirectory"));
|
|
131 |
break;
|
|
132 |
case DialogGetColor:
|
|
133 |
QColorDialog::getColor(QColor(Qt::green), this, QLatin1String("getColor"));
|
|
134 |
break;
|
|
135 |
case DialogGetFont:
|
|
136 |
QFontDialog::getFont(0, this);
|
|
137 |
break;
|
|
138 |
case DialogQuestion:
|
|
139 |
QMessageBox::question(this, QLatin1String("question"), QLatin1String("¿Hola, que tal?"));
|
|
140 |
break;
|
|
141 |
case DialogAboutQt:
|
|
142 |
QMessageBox::aboutQt(this);
|
|
143 |
break;
|
|
144 |
case DialogGetItem:
|
|
145 |
QInputDialog::getItem(this, QLatin1String("getItem"), QLatin1String("Choose a color"), QColor::colorNames());
|
|
146 |
break;
|
|
147 |
default:
|
|
148 |
break;
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
private:
|
|
153 |
enum Dialog {
|
|
154 |
DialogGetOpenFileName,
|
|
155 |
DialogGetSaveFileName,
|
|
156 |
DialogGetExistingDirectory,
|
|
157 |
DialogGetColor,
|
|
158 |
DialogGetFont,
|
|
159 |
DialogQuestion,
|
|
160 |
DialogAboutQt,
|
|
161 |
DialogGetItem
|
|
162 |
};
|
|
163 |
|
|
164 |
Ui_KeypadNavigation *ui;
|
|
165 |
QSignalMapper m_layoutSignalMapper;
|
|
166 |
QSignalMapper m_modeSignalMapper;
|
|
167 |
QSignalMapper m_dialogSignalMapper;
|
|
168 |
};
|
|
169 |
|
|
170 |
int main(int argc, char *argv[])
|
|
171 |
{
|
|
172 |
QApplication a(argc, argv);
|
|
173 |
KeypadNavigation w;
|
|
174 |
#ifdef Q_WS_S60
|
|
175 |
w.showMaximized();
|
|
176 |
#else
|
|
177 |
w.show();
|
|
178 |
#endif
|
|
179 |
return a.exec();
|
|
180 |
}
|
|
181 |
|
|
182 |
#include "main.moc"
|