summaryrefslogtreecommitdiffstats
path: root/examples/widgets/softkeys
diff options
context:
space:
mode:
authorMarkku Luukkainen <markku.luukkainen@digia.com>2009-06-15 12:41:16 (GMT)
committerMarkku Luukkainen <markku.luukkainen@digia.com>2009-06-15 12:41:16 (GMT)
commit2b630bd12b9e944707d8e52c1135e88750323ed0 (patch)
treeae611fe6538da24112d2047519674e1b7e0eba34 /examples/widgets/softkeys
parent5b418dd900b9455dadfeeda23e5478fb575f5e3f (diff)
downloadQt-2b630bd12b9e944707d8e52c1135e88750323ed0.zip
Qt-2b630bd12b9e944707d8e52c1135e88750323ed0.tar.gz
Qt-2b630bd12b9e944707d8e52c1135e88750323ed0.tar.bz2
Updated softkey example to be more complete
Diffstat (limited to 'examples/widgets/softkeys')
-rw-r--r--examples/widgets/softkeys/softkeys.cpp83
-rw-r--r--examples/widgets/softkeys/softkeys.h13
2 files changed, 70 insertions, 26 deletions
diff --git a/examples/widgets/softkeys/softkeys.cpp b/examples/widgets/softkeys/softkeys.cpp
index 083d05c..9672aee 100644
--- a/examples/widgets/softkeys/softkeys.cpp
+++ b/examples/widgets/softkeys/softkeys.cpp
@@ -42,33 +42,73 @@
#include "softkeys.h"
MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
+ : QMainWindow(parent)
{
central = new QWidget(this);
+ central->setContextMenuPolicy(Qt::NoContextMenu); // explicitly forbid usage of context menu so actions item is not shown menu
setCentralWidget(central);
- infoLabel = new QLabel(tr("Open menu to start!"));
+
+ // Create text editor and set softkeys to it
+ textEditor= new QTextEdit(tr("Choose items from menu or navigate around with tab+selection to see what softkeys can do"), this);
+ QAction* fill = new QAction(tr("Fill"), this);
+ fill->setSoftKeyRole(QAction::OkSoftKey);
+ QAction* clear = new QAction(tr("Clear"), this);
+ clear->setSoftKeyRole(QAction::CancelSoftKey);
+
+ QList<QAction*> textEditorSoftKeys;
+ textEditorSoftKeys.append(fill);
+ textEditorSoftKeys.append(clear);
+ textEditor->setSoftKeys(textEditorSoftKeys);
+
+ infoLabel = new QLabel(tr(""), this);
+ infoLabel->setContextMenuPolicy(Qt::NoContextMenu);
+
+ pushButton = new QPushButton(tr("Open File Dialog"), this);
+ pushButton->setContextMenuPolicy(Qt::NoContextMenu);
+
+ QComboBox* comboBox = new QComboBox(this);
+ comboBox->setContextMenuPolicy(Qt::NoContextMenu);
+ comboBox->insertItems(0, QStringList()
+ << QApplication::translate("MainWindow", "Selection1", 0, QApplication::UnicodeUTF8)
+ << QApplication::translate("MainWindow", "Selection2", 0, QApplication::UnicodeUTF8)
+ << QApplication::translate("MainWindow", "Selection3", 0, QApplication::UnicodeUTF8)
+ );
layout = new QVBoxLayout;
+ layout->addWidget(textEditor);
layout->addWidget(infoLabel);
+ layout->addWidget(pushButton);
+ layout->addWidget(comboBox);
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()));
+ exit = new QAction(tr("&Exit"), this);
+ fileMenu->addAction(exit);
+
+ connect(fill, SIGNAL(triggered()), this, SLOT(fillTextEditor()));
+ connect(clear, SIGNAL(triggered()), this, SLOT(clearTextEditor()));
+ connect(pushButton, SIGNAL(clicked()), this, SLOT(openDialog()));
+ connect(addSoftKeysAct, SIGNAL(triggered()), this, SLOT(addSoftKeys()));
+ connect(exit, SIGNAL(triggered()), this, SLOT(exitApplication()));
+ pushButton->setFocus();
}
MainWindow::~MainWindow()
{
}
+void MainWindow::fillTextEditor()
+{
+ textEditor->setText(tr("The fill softkey was pressed and here is some text to fill the editor"));
+}
+
+void MainWindow::clearTextEditor()
+{
+ textEditor->setText(tr(""));
+}
+
void MainWindow::openDialog()
{
QFileDialog::getOpenFileName(this);
@@ -78,33 +118,34 @@ void MainWindow::addSoftKeys()
{
ok = new QAction(tr("Ok"), this);
ok->setSoftKeyRole(QAction::OkSoftKey);
- connect(ok, SIGNAL(triggered()), this, SLOT(okPressed()));
-
+ connect(ok, SIGNAL(triggered()), this, SLOT(okPressed()));
+
cancel = new QAction(tr("Cancel"), this);
cancel->setSoftKeyRole(QAction::OkSoftKey);
- connect(cancel, SIGNAL(triggered()), this, SLOT(cancelPressed()));
+ connect(cancel, SIGNAL(triggered()), this, SLOT(cancelPressed()));
QList<QAction*> softkeys;
softkeys.append(ok);
softkeys.append(cancel);
- central->setSoftKeys(softkeys);
- central->setFocus();
-
+ pushButton->setSoftKeys(softkeys);
}
-void MainWindow::clearSoftKeys()
+void MainWindow::exitApplication()
{
- central->setSoftKey(0);
+ qApp->exit();
}
void MainWindow::okPressed()
{
infoLabel->setText(tr("OK pressed"));
- central->setSoftKey(0);
+ pushButton->setSoftKey(0);
}
void MainWindow::cancelPressed()
{
infoLabel->setText(tr("Cancel pressed"));
- central->setSoftKey(0);
+ pushButton->setSoftKey(0);
}
+
+
+
diff --git a/examples/widgets/softkeys/softkeys.h b/examples/widgets/softkeys/softkeys.h
index 11db419..bd75473 100644
--- a/examples/widgets/softkeys/softkeys.h
+++ b/examples/widgets/softkeys/softkeys.h
@@ -48,24 +48,27 @@ class MainWindow : public QMainWindow
{
Q_OBJECT
public:
-
+
private slots:
+ void fillTextEditor();
+ void clearTextEditor();
void openDialog();
void addSoftKeys();
- void clearSoftKeys();
+ void exitApplication();
void okPressed();
void cancelPressed();
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QVBoxLayout *layout;
QWidget *central;
+ QTextEdit* textEditor;
QLabel *infoLabel;
+ QPushButton* pushButton;
QMenu* fileMenu;
- QAction* openDialogAct;
QAction* addSoftKeysAct;
- QAction* clearSoftKeysAct;
+ QAction* exit;
QAction* ok;
QAction* cancel;
};