source: trunk/examples/widgets/softkeys/softkeys.cpp@ 1168

Last change on this file since 1168 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 6.6 KB
RevLine 
[556]1/****************************************************************************
2**
[846]3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
[556]4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the examples of the Qt Toolkit.
8**
[846]9** $QT_BEGIN_LICENSE:BSD$
10** You may use this file under the terms of the BSD license as follows:
[556]11**
[846]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.
[556]25**
[846]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."
[556]37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include "softkeys.h"
42
43MainWindow::MainWindow(QWidget *parent)
44 : QMainWindow(parent)
45{
46 central = new QWidget(this);
47 central->setContextMenuPolicy(Qt::NoContextMenu); // explicitly forbid usage of context menu so actions item is not shown menu
48 setCentralWidget(central);
49
50 // Create text editor and set softkeys to it
51 textEditor= new QTextEdit(tr("Navigate in UI to see context sensitive softkeys in action"), this);
52 QAction* clear = new QAction(tr("Clear"), this);
53 clear->setSoftKeyRole(QAction::NegativeSoftKey);
54
55 textEditor->addAction(clear);
56
57 ok = new QAction(tr("Ok"), this);
58 ok->setSoftKeyRole(QAction::PositiveSoftKey);
59 connect(ok, SIGNAL(triggered()), this, SLOT(okPressed()));
60
61 cancel = new QAction(tr("Cancel"), this);
62 cancel->setSoftKeyRole(QAction::NegativeSoftKey);
63 connect(cancel, SIGNAL(triggered()), this, SLOT(cancelPressed()));
64
65 infoLabel = new QLabel(tr(""), this);
66 infoLabel->setContextMenuPolicy(Qt::NoContextMenu);
67
68 toggleButton = new QPushButton(tr("Custom"), this);
69 toggleButton->setContextMenuPolicy(Qt::NoContextMenu);
70 toggleButton->setCheckable(true);
71
[769]72 modeButton = new QPushButton(tr("Loop SK window type"), this);
73 modeButton->setContextMenuPolicy(Qt::NoContextMenu);
74
75 modeLabel = new QLabel(tr("Normal maximized"), this);
76 modeLabel->setContextMenuPolicy(Qt::NoContextMenu);
77
[556]78 pushButton = new QPushButton(tr("File Dialog"), this);
79 pushButton->setContextMenuPolicy(Qt::NoContextMenu);
80
81 QComboBox* comboBox = new QComboBox(this);
82 comboBox->setContextMenuPolicy(Qt::NoContextMenu);
83 comboBox->insertItems(0, QStringList()
84 << QApplication::translate("MainWindow", "Selection1", 0, QApplication::UnicodeUTF8)
85 << QApplication::translate("MainWindow", "Selection2", 0, QApplication::UnicodeUTF8)
86 << QApplication::translate("MainWindow", "Selection3", 0, QApplication::UnicodeUTF8)
87 );
88
89 layout = new QGridLayout;
90 layout->addWidget(textEditor, 0, 0, 1, 2);
91 layout->addWidget(infoLabel, 1, 0, 1, 2);
92 layout->addWidget(toggleButton, 2, 0);
93 layout->addWidget(pushButton, 2, 1);
94 layout->addWidget(comboBox, 3, 0, 1, 2);
[769]95 layout->addWidget(modeButton, 4, 0, 1, 2);
96 layout->addWidget(modeLabel, 5, 0, 1, 2);
[556]97 central->setLayout(layout);
98
99 fileMenu = menuBar()->addMenu(tr("&File"));
100 exit = new QAction(tr("&Exit"), this);
101 fileMenu->addAction(exit);
102
103 connect(clear, SIGNAL(triggered()), this, SLOT(clearTextEditor()));
104 connect(pushButton, SIGNAL(clicked()), this, SLOT(openDialog()));
105 connect(exit, SIGNAL(triggered()), this, SLOT(exitApplication()));
106 connect(toggleButton, SIGNAL(clicked()), this, SLOT(setCustomSoftKeys()));
[769]107 connect(modeButton, SIGNAL(clicked()), this, SLOT(setMode()));
[556]108 pushButton->setFocus();
109}
110
111MainWindow::~MainWindow()
112{
113}
114
115void MainWindow::clearTextEditor()
116{
117 textEditor->setText(tr(""));
118}
119
120void MainWindow::openDialog()
121{
122 QFileDialog::getOpenFileName(this);
123}
124
125void MainWindow::addSoftKeys()
126{
127 addAction(ok);
128 addAction(cancel);
129}
130
131void MainWindow::setCustomSoftKeys()
132{
133 if (toggleButton->isChecked()) {
134 infoLabel->setText(tr("Custom softkeys set"));
135 addSoftKeys();
136 }
137 else {
138 infoLabel->setText(tr("Custom softkeys removed"));
139 removeAction(ok);
140 removeAction(cancel);
141 }
142}
143
[769]144void MainWindow::setMode()
145{
146 if(isMaximized()) {
147 showFullScreen();
148 modeLabel->setText(tr("Normal Fullscreen"));
149 } else {
150 Qt::WindowFlags flags = windowFlags();
151 if(flags & Qt::WindowSoftkeysRespondHint) {
152 flags |= Qt::WindowSoftkeysVisibleHint;
153 flags &= ~Qt::WindowSoftkeysRespondHint;
154 setWindowFlags(flags); // Hides visible window
155 showFullScreen();
156 modeLabel->setText(tr("Fullscreen with softkeys"));
157 } else if(flags & Qt::WindowSoftkeysVisibleHint) {
158 flags &= ~Qt::WindowSoftkeysVisibleHint;
159 flags &= ~Qt::WindowSoftkeysRespondHint;
160 setWindowFlags(flags); // Hides visible window
161 showMaximized();
162 modeLabel->setText(tr("Normal Maximized"));
163 } else {
164 flags &= ~Qt::WindowSoftkeysVisibleHint;
165 flags |= Qt::WindowSoftkeysRespondHint;
166 setWindowFlags(flags); // Hides visible window
167 showFullScreen();
168 modeLabel->setText(tr("Fullscreen with SK respond"));
169 }
170 }
171}
172
[556]173void MainWindow::exitApplication()
174{
175 qApp->exit();
176}
177
178void MainWindow::okPressed()
179{
180 infoLabel->setText(tr("OK pressed"));
181}
182
183void MainWindow::cancelPressed()
184{
185 infoLabel->setText(tr("Cancel pressed"));
186}
187
188
Note: See TracBrowser for help on using the repository browser.