author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 13 | c0432d11811c |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 "softkeys.h" |
|
43 |
||
44 |
MainWindow::MainWindow(QWidget *parent) |
|
45 |
: QMainWindow(parent) |
|
46 |
{ |
|
47 |
central = new QWidget(this); |
|
48 |
central->setContextMenuPolicy(Qt::NoContextMenu); // explicitly forbid usage of context menu so actions item is not shown menu |
|
49 |
setCentralWidget(central); |
|
50 |
||
51 |
// Create text editor and set softkeys to it |
|
52 |
textEditor= new QTextEdit(tr("Navigate in UI to see context sensitive softkeys in action"), this); |
|
53 |
QAction* clear = new QAction(tr("Clear"), this); |
|
54 |
clear->setSoftKeyRole(QAction::NegativeSoftKey); |
|
55 |
||
56 |
textEditor->addAction(clear); |
|
57 |
||
58 |
ok = new QAction(tr("Ok"), this); |
|
59 |
ok->setSoftKeyRole(QAction::PositiveSoftKey); |
|
60 |
connect(ok, SIGNAL(triggered()), this, SLOT(okPressed())); |
|
61 |
||
62 |
cancel = new QAction(tr("Cancel"), this); |
|
63 |
cancel->setSoftKeyRole(QAction::NegativeSoftKey); |
|
64 |
connect(cancel, SIGNAL(triggered()), this, SLOT(cancelPressed())); |
|
65 |
||
66 |
infoLabel = new QLabel(tr(""), this); |
|
67 |
infoLabel->setContextMenuPolicy(Qt::NoContextMenu); |
|
68 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
toggleButton = new QPushButton(tr("Custom"), this); |
0 | 70 |
toggleButton->setContextMenuPolicy(Qt::NoContextMenu); |
71 |
toggleButton->setCheckable(true); |
|
72 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
73 |
modeButton = new QPushButton(tr("Loop SK window type"), this); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
74 |
modeButton->setContextMenuPolicy(Qt::NoContextMenu); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
75 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
76 |
modeLabel = new QLabel(tr("Normal maximized"), this); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
77 |
modeLabel->setContextMenuPolicy(Qt::NoContextMenu); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
78 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
pushButton = new QPushButton(tr("File Dialog"), this); |
0 | 80 |
pushButton->setContextMenuPolicy(Qt::NoContextMenu); |
81 |
||
82 |
QComboBox* comboBox = new QComboBox(this); |
|
83 |
comboBox->setContextMenuPolicy(Qt::NoContextMenu); |
|
84 |
comboBox->insertItems(0, QStringList() |
|
85 |
<< QApplication::translate("MainWindow", "Selection1", 0, QApplication::UnicodeUTF8) |
|
86 |
<< QApplication::translate("MainWindow", "Selection2", 0, QApplication::UnicodeUTF8) |
|
87 |
<< QApplication::translate("MainWindow", "Selection3", 0, QApplication::UnicodeUTF8) |
|
88 |
); |
|
89 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
layout = new QGridLayout; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
layout->addWidget(textEditor, 0, 0, 1, 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
layout->addWidget(infoLabel, 1, 0, 1, 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
layout->addWidget(toggleButton, 2, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
layout->addWidget(pushButton, 2, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
layout->addWidget(comboBox, 3, 0, 1, 2); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
96 |
layout->addWidget(modeButton, 4, 0, 1, 2); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
97 |
layout->addWidget(modeLabel, 5, 0, 1, 2); |
0 | 98 |
central->setLayout(layout); |
99 |
||
100 |
fileMenu = menuBar()->addMenu(tr("&File")); |
|
101 |
exit = new QAction(tr("&Exit"), this); |
|
102 |
fileMenu->addAction(exit); |
|
103 |
||
104 |
connect(clear, SIGNAL(triggered()), this, SLOT(clearTextEditor())); |
|
105 |
connect(pushButton, SIGNAL(clicked()), this, SLOT(openDialog())); |
|
106 |
connect(exit, SIGNAL(triggered()), this, SLOT(exitApplication())); |
|
107 |
connect(toggleButton, SIGNAL(clicked()), this, SLOT(setCustomSoftKeys())); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
108 |
connect(modeButton, SIGNAL(clicked()), this, SLOT(setMode())); |
0 | 109 |
pushButton->setFocus(); |
110 |
} |
|
111 |
||
112 |
MainWindow::~MainWindow() |
|
113 |
{ |
|
114 |
} |
|
115 |
||
116 |
void MainWindow::clearTextEditor() |
|
117 |
{ |
|
118 |
textEditor->setText(tr("")); |
|
119 |
} |
|
120 |
||
121 |
void MainWindow::openDialog() |
|
122 |
{ |
|
123 |
QFileDialog::getOpenFileName(this); |
|
124 |
} |
|
125 |
||
126 |
void MainWindow::addSoftKeys() |
|
127 |
{ |
|
128 |
addAction(ok); |
|
129 |
addAction(cancel); |
|
130 |
} |
|
131 |
||
132 |
void MainWindow::setCustomSoftKeys() |
|
133 |
{ |
|
134 |
if (toggleButton->isChecked()) { |
|
135 |
infoLabel->setText(tr("Custom softkeys set")); |
|
136 |
addSoftKeys(); |
|
137 |
} |
|
138 |
else { |
|
139 |
infoLabel->setText(tr("Custom softkeys removed")); |
|
140 |
removeAction(ok); |
|
141 |
removeAction(cancel); |
|
142 |
} |
|
143 |
} |
|
144 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
145 |
void MainWindow::setMode() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
146 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
147 |
if(isMaximized()) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
148 |
showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
149 |
modeLabel->setText(tr("Normal Fullscreen")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
150 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
151 |
Qt::WindowFlags flags = windowFlags(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
152 |
if(flags & Qt::WindowSoftkeysRespondHint) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
153 |
flags |= Qt::WindowSoftkeysVisibleHint; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
154 |
flags &= ~Qt::WindowSoftkeysRespondHint; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
155 |
setWindowFlags(flags); // Hides visible window |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
156 |
showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
157 |
modeLabel->setText(tr("Fullscreen with softkeys")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
158 |
} else if(flags & Qt::WindowSoftkeysVisibleHint) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
159 |
flags &= ~Qt::WindowSoftkeysVisibleHint; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
160 |
flags &= ~Qt::WindowSoftkeysRespondHint; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
161 |
setWindowFlags(flags); // Hides visible window |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
162 |
showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
163 |
modeLabel->setText(tr("Normal Maximized")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
164 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
165 |
flags &= ~Qt::WindowSoftkeysVisibleHint; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
166 |
flags |= Qt::WindowSoftkeysRespondHint; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
167 |
setWindowFlags(flags); // Hides visible window |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
168 |
showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
169 |
modeLabel->setText(tr("Fullscreen with SK respond")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
170 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
171 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
172 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
173 |
|
0 | 174 |
void MainWindow::exitApplication() |
175 |
{ |
|
176 |
qApp->exit(); |
|
177 |
} |
|
178 |
||
179 |
void MainWindow::okPressed() |
|
180 |
{ |
|
181 |
infoLabel->setText(tr("OK pressed")); |
|
182 |
} |
|
183 |
||
184 |
void MainWindow::cancelPressed() |
|
185 |
{ |
|
186 |
infoLabel->setText(tr("Cancel pressed")); |
|
187 |
} |
|
188 |
||
189 |