summaryrefslogtreecommitdiffstats
path: root/examples/widgets/softkeys/softkeys.cpp
blob: b29be2bb1bb2901d66b3a5b6adfbbfb8dcdacd2f (plain)
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
#include "softkeys.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)      
{
    central = new QWidget(this);
    setCentralWidget(central);
    infoLabel = new QLabel(tr("Funky stuff in menu!"));

    layout = new QVBoxLayout;
    layout->addWidget(infoLabel);
    central->setLayout(layout);
    central->setFocusPolicy(Qt::TabFocus);
    
    fileMenu = menuBar()->addMenu(tr("&File"));
    openDialogAct = new QAction(tr("&Open Dialog"), this);
    addSoftKeysAct = new QAction(tr("&Add Softkeys"), this);
    clearSoftKeysAct = new QAction(tr("&Clear Softkeys"), this);
    fileMenu->addAction(openDialogAct);
    fileMenu->addAction(addSoftKeysAct);
    fileMenu->addAction(clearSoftKeysAct);
    connect(openDialogAct, SIGNAL(triggered()), this, SLOT(openDialog()));    
    connect(addSoftKeysAct, SIGNAL(triggered()), this, SLOT(addSoftKeys()));    
    connect(clearSoftKeysAct, SIGNAL(triggered()), this, SLOT(clearSoftKeys()));    
}

MainWindow::~MainWindow()
{
}

void MainWindow::openDialog()
{
    QFileDialog::getOpenFileName(this);
}

void MainWindow::addSoftKeys()
{
    ok = new QAction(tr("Ok"), this);
    ok->setSoftKeyRole(QAction::OkSoftKey);
    connect(ok, SIGNAL(triggered()), this, SLOT(okPressed()));  
    
    cancel = new QAction(tr("Cancel"), this);
    cancel->setSoftKeyRole(QAction::OkSoftKey);
    connect(cancel, SIGNAL(triggered()), this, SLOT(cancelPressed()));  

    QList<QAction*> softkeys;
    softkeys.append(ok);
    softkeys.append(cancel);
    central->setSoftKeys(softkeys);
    central->setFocus();
    
}

void MainWindow::clearSoftKeys()
{
    central->setSoftKey(0);
}

void MainWindow::okPressed()
{
    infoLabel->setText(tr("OK pressed"));
    central->setSoftKey(0);
}

void MainWindow::cancelPressed()
{
    infoLabel->setText(tr("Cancel pressed"));
    central->setSoftKey(0);
}