|
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 "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 |
|
69 toggleButton = new QPushButton(tr("Custom softkeys"), this); |
|
70 toggleButton->setContextMenuPolicy(Qt::NoContextMenu); |
|
71 toggleButton->setCheckable(true); |
|
72 |
|
73 pushButton = new QPushButton(tr("Open File Dialog"), this); |
|
74 pushButton->setContextMenuPolicy(Qt::NoContextMenu); |
|
75 |
|
76 QComboBox* comboBox = new QComboBox(this); |
|
77 comboBox->setContextMenuPolicy(Qt::NoContextMenu); |
|
78 comboBox->insertItems(0, QStringList() |
|
79 << QApplication::translate("MainWindow", "Selection1", 0, QApplication::UnicodeUTF8) |
|
80 << QApplication::translate("MainWindow", "Selection2", 0, QApplication::UnicodeUTF8) |
|
81 << QApplication::translate("MainWindow", "Selection3", 0, QApplication::UnicodeUTF8) |
|
82 ); |
|
83 |
|
84 layout = new QVBoxLayout; |
|
85 layout->addWidget(textEditor); |
|
86 layout->addWidget(infoLabel); |
|
87 layout->addWidget(toggleButton); |
|
88 layout->addWidget(pushButton); |
|
89 layout->addWidget(comboBox); |
|
90 central->setLayout(layout); |
|
91 |
|
92 fileMenu = menuBar()->addMenu(tr("&File")); |
|
93 exit = new QAction(tr("&Exit"), this); |
|
94 fileMenu->addAction(exit); |
|
95 |
|
96 connect(clear, SIGNAL(triggered()), this, SLOT(clearTextEditor())); |
|
97 connect(pushButton, SIGNAL(clicked()), this, SLOT(openDialog())); |
|
98 connect(exit, SIGNAL(triggered()), this, SLOT(exitApplication())); |
|
99 connect(toggleButton, SIGNAL(clicked()), this, SLOT(setCustomSoftKeys())); |
|
100 pushButton->setFocus(); |
|
101 } |
|
102 |
|
103 MainWindow::~MainWindow() |
|
104 { |
|
105 } |
|
106 |
|
107 void MainWindow::clearTextEditor() |
|
108 { |
|
109 textEditor->setText(tr("")); |
|
110 } |
|
111 |
|
112 void MainWindow::openDialog() |
|
113 { |
|
114 QFileDialog::getOpenFileName(this); |
|
115 } |
|
116 |
|
117 void MainWindow::addSoftKeys() |
|
118 { |
|
119 addAction(ok); |
|
120 addAction(cancel); |
|
121 } |
|
122 |
|
123 void MainWindow::setCustomSoftKeys() |
|
124 { |
|
125 if (toggleButton->isChecked()) { |
|
126 infoLabel->setText(tr("Custom softkeys set")); |
|
127 addSoftKeys(); |
|
128 } |
|
129 else { |
|
130 infoLabel->setText(tr("Custom softkeys removed")); |
|
131 removeAction(ok); |
|
132 removeAction(cancel); |
|
133 } |
|
134 } |
|
135 |
|
136 void MainWindow::exitApplication() |
|
137 { |
|
138 qApp->exit(); |
|
139 } |
|
140 |
|
141 void MainWindow::okPressed() |
|
142 { |
|
143 infoLabel->setText(tr("OK pressed")); |
|
144 } |
|
145 |
|
146 void MainWindow::cancelPressed() |
|
147 { |
|
148 infoLabel->setText(tr("Cancel pressed")); |
|
149 } |
|
150 |
|
151 |