1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/****************************************************************************
**
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the $MODULE$ of the Qt Toolkit.
**
** $TROLLTECH_DUAL_LICENSE$
**
****************************************************************************/
#include <QtGui>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
private slots:
void context1Slot();
void context3Slot();
void softKeySlot();
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
QMenu *contextMenu;
QAction* context1;
QAction* context2;
QAction* context3;
QSoftKeyAction *action1;
QSoftKeyAction *action2;
QSoftKeyAction *action3;
QSoftKeyAction *action4;
QSoftKeyAction *action5;
};
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
contextMenu(0),
context1(0), context2(0), context3(0),
action1(0),action2(0),action3(0),action4(0),action5(0)
{
QWidget *central = new QWidget(this);
contextMenu = new QMenu();
central->setLayout(new QVBoxLayout);
central->layout()->addWidget(new QPushButton);
central->layout()->addWidget(new QPushButton);
central->layout()->addWidget(new QPushButton);
context1 = new QAction(QString("Context1"), central);
context2 = new QAction(QString("Context2"), central);
context3 = new QAction(QString("Context3"), contextMenu);
central->addAction(context1);
central->addAction(context2);
QMenuBar* menuBar = new QMenuBar(this);
menuBar->addAction("MyMenuItem1");
this->setMenuBar(menuBar);
context2->setMenu(contextMenu);
contextMenu->addAction(context3);
connect(context1, SIGNAL(triggered()), this, SLOT(context1Slot()));
connect(context3, SIGNAL(triggered()), this, SLOT(context3Slot()));
action1 = new QSoftKeyAction(QSoftKeyAction::Ok, QString("Ok"), central);
action2 = new QSoftKeyAction(QSoftKeyAction::Back, QString("Back"), central);
action3 = new QSoftKeyAction(QSoftKeyAction::Cancel, QString("Cancel"), central);
action4 = new QSoftKeyAction(QSoftKeyAction::Menu, QString("Menu"), central);
action5 = new QSoftKeyAction(QSoftKeyAction::ContextMenu,QString("ContextMenu"), central);
connect(action2, SIGNAL(triggered()), this, SLOT(softKeySlot()));
QList<QSoftKeyAction*> myActionList;
myActionList.append(action1);
myActionList.append(action2);
myActionList.append(action3);
softKeyStack()->push(myActionList);
softKeyStack()->pop();
softKeyStack()->push(action1);
softKeyStack()->pop();
QList<QSoftKeyAction*> myActionList2;
myActionList2.append(action4);
myActionList2.append(action2);
myActionList2.append(action5);
softKeyStack()->push(myActionList2);
setCentralWidget(central);
}
MainWindow::~MainWindow()
{
delete context1;
delete context2;
delete context3;
delete action1;
delete action2;
delete action3;
delete action4;
delete action5;
delete contextMenu;
}
void MainWindow::context1Slot()
{
}
void MainWindow::context3Slot()
{
}
void MainWindow::softKeySlot()
{
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mw;
mw.show();
return app.exec();
}
#include "main.moc"
|