diff options
author | Markku Luukkainen <markku.luukkainen@digia.com> | 2009-06-18 15:24:03 (GMT) |
---|---|---|
committer | Markku Luukkainen <markku.luukkainen@digia.com> | 2009-06-18 15:24:03 (GMT) |
commit | 829307fa214586d40ff13d9e9eb4ece4d1bd4ff1 (patch) | |
tree | 6d39f4fc01e649ea3c87338f5a09038af3f913c8 /examples/widgets | |
parent | 0cbf534a7feba5a0159877d19d15f225e1199fc8 (diff) | |
download | Qt-829307fa214586d40ff13d9e9eb4ece4d1bd4ff1.zip Qt-829307fa214586d40ff13d9e9eb4ece4d1bd4ff1.tar.gz Qt-829307fa214586d40ff13d9e9eb4ece4d1bd4ff1.tar.bz2 |
Updated example to make more sense
Diffstat (limited to 'examples/widgets')
-rw-r--r-- | examples/widgets/softkeys/softkeys.cpp | 46 | ||||
-rw-r--r-- | examples/widgets/softkeys/softkeys.h | 3 |
2 files changed, 27 insertions, 22 deletions
diff --git a/examples/widgets/softkeys/softkeys.cpp b/examples/widgets/softkeys/softkeys.cpp index e717510..110f2e6 100644 --- a/examples/widgets/softkeys/softkeys.cpp +++ b/examples/widgets/softkeys/softkeys.cpp @@ -49,20 +49,24 @@ MainWindow::MainWindow(QWidget *parent) setCentralWidget(central); // 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); + textEditor= new QTextEdit(tr("Navigate in UI to see context sensitive softkeys in action"), this); + QAction* menu = new QAction(tr("Menu"), this); + menu->setSoftKeyRole(QAction::MenuSoftKey); QAction* clear = new QAction(tr("Clear"), this); clear->setSoftKeyRole(QAction::CancelSoftKey); QList<QAction*> textEditorSoftKeys; - textEditorSoftKeys.append(fill); + textEditorSoftKeys.append(menu); textEditorSoftKeys.append(clear); textEditor->setSoftKeys(textEditorSoftKeys); infoLabel = new QLabel(tr(""), this); infoLabel->setContextMenuPolicy(Qt::NoContextMenu); + toggleButton = new QPushButton(tr("Custom softkeys"), this); + toggleButton->setContextMenuPolicy(Qt::NoContextMenu); + toggleButton->setCheckable(true); + pushButton = new QPushButton(tr("Open File Dialog"), this); pushButton->setContextMenuPolicy(Qt::NoContextMenu); @@ -77,21 +81,19 @@ MainWindow::MainWindow(QWidget *parent) layout = new QVBoxLayout; layout->addWidget(textEditor); layout->addWidget(infoLabel); + layout->addWidget(toggleButton); layout->addWidget(pushButton); layout->addWidget(comboBox); central->setLayout(layout); fileMenu = menuBar()->addMenu(tr("&File")); - addSoftKeysAct = new QAction(tr("&Add Softkeys"), this); - fileMenu->addAction(addSoftKeysAct); 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())); + connect(toggleButton, SIGNAL(clicked()), this, SLOT(setCustomSoftKeys())); pushButton->setFocus(); } @@ -99,11 +101,6 @@ 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("")); @@ -121,7 +118,7 @@ void MainWindow::addSoftKeys() connect(ok, SIGNAL(triggered()), this, SLOT(okPressed())); cancel = new QAction(tr("Cancel"), this); - cancel->setSoftKeyRole(QAction::OkSoftKey); + cancel->setSoftKeyRole(QAction::CancelSoftKey); connect(cancel, SIGNAL(triggered()), this, SLOT(cancelPressed())); QList<QAction*> softkeys; @@ -132,6 +129,20 @@ void MainWindow::addSoftKeys() focusWidget->setSoftKeys(softkeys); } +void MainWindow::setCustomSoftKeys() +{ + if (toggleButton->isChecked()) { + infoLabel->setText(tr("Custom softkeys set")); + addSoftKeys(); + } + else { + infoLabel->setText(tr("Custom softkeys removed")); + QWidget* focusWidget = QApplication::focusWidget(); + if (focusWidget) + focusWidget->setSoftKey(0); + } +} + void MainWindow::exitApplication() { qApp->exit(); @@ -140,18 +151,11 @@ void MainWindow::exitApplication() void MainWindow::okPressed() { infoLabel->setText(tr("OK pressed")); - QWidget* focusWidget = QApplication::focusWidget(); - if (focusWidget) - focusWidget->setSoftKey(0); } void MainWindow::cancelPressed() { infoLabel->setText(tr("Cancel pressed")); - QWidget* focusWidget = QApplication::focusWidget(); - if (focusWidget) - focusWidget->setSoftKey(0); } - diff --git a/examples/widgets/softkeys/softkeys.h b/examples/widgets/softkeys/softkeys.h index bd75473..da56eae 100644 --- a/examples/widgets/softkeys/softkeys.h +++ b/examples/widgets/softkeys/softkeys.h @@ -50,13 +50,13 @@ class MainWindow : public QMainWindow public: private slots: - void fillTextEditor(); void clearTextEditor(); void openDialog(); void addSoftKeys(); void exitApplication(); void okPressed(); void cancelPressed(); + void setCustomSoftKeys(); public: MainWindow(QWidget *parent = 0); ~MainWindow(); @@ -65,6 +65,7 @@ private: QWidget *central; QTextEdit* textEditor; QLabel *infoLabel; + QPushButton* toggleButton; QPushButton* pushButton; QMenu* fileMenu; QAction* addSoftKeysAct; |