source: trunk/examples/widgets/softkeys/softkeys.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: 5.0 KB
Line 
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** 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 qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "softkeys.h"
43
44MainWindow::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"), this);
70 toggleButton->setContextMenuPolicy(Qt::NoContextMenu);
71 toggleButton->setCheckable(true);
72
73 pushButton = new QPushButton(tr("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 QGridLayout;
85 layout->addWidget(textEditor, 0, 0, 1, 2);
86 layout->addWidget(infoLabel, 1, 0, 1, 2);
87 layout->addWidget(toggleButton, 2, 0);
88 layout->addWidget(pushButton, 2, 1);
89 layout->addWidget(comboBox, 3, 0, 1, 2);
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
103MainWindow::~MainWindow()
104{
105}
106
107void MainWindow::clearTextEditor()
108{
109 textEditor->setText(tr(""));
110}
111
112void MainWindow::openDialog()
113{
114 QFileDialog::getOpenFileName(this);
115}
116
117void MainWindow::addSoftKeys()
118{
119 addAction(ok);
120 addAction(cancel);
121}
122
123void 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
136void MainWindow::exitApplication()
137{
138 qApp->exit();
139}
140
141void MainWindow::okPressed()
142{
143 infoLabel->setText(tr("OK pressed"));
144}
145
146void MainWindow::cancelPressed()
147{
148 infoLabel->setText(tr("Cancel pressed"));
149}
150
151
Note: See TracBrowser for help on using the repository browser.