| Home · All Classes · Main Classes · Deprecated |
Those are the four main points for implementing this navigational pattern:
setToolbarViewType(MToolBar::tabType);
action->setLocation(MAction::ToolBarLocation); applicationWindow->addAction(action);
window->connect(settingsAction, SIGNAL(triggered()), SLOT(showSettingsPage()));
In this example the actions were grouped in a QActionGroup only because I wanted the same method to be called whenever any of those actions are triggered.
All files can be found at:
libmeegotouch/examples/pagenavigation_tab
main.cpp:
#include <MApplication> #include "samplewindow.h" int main(int argc, char **argv) { MApplication app(argc, argv); SampleWindow window; window.show(); return app.exec(); }
samplewindow.cpp:
#include "samplewindow.h" #include <MLabel> #include <MToolBar> SampleWindow::SampleWindow(QWidget *parent) : MApplicationWindow(parent) { // We want the toolbar to show actions as tabs. I.e., be a tab bar. setToolbarViewType(MToolBar::tabType); currentAction = 0; actionGroup = new QActionGroup(this); actionGroup->setExclusive(true); QAction *alphaAction = createAction("Alpha", true); createAction("Beta"); createAction("Gamma"); createAction("Delta"); connect(actionGroup, SIGNAL(triggered(QAction*)), SLOT(showPageForAction(QAction*))); showPageForAction(alphaAction); } void SampleWindow::showPageForAction(QAction *action) { if (currentAction == action) return; MApplicationPage *page = createPage(action->text()); page->appear(this, MSceneWindow::DestroyWhenDone); currentAction = action; } MApplicationPage *SampleWindow::createPage(const QString &name) { MApplicationPage *page = new MApplicationPage; page->setTitle(name); QString contentText = QString("%1 Content").arg(name); page->setCentralWidget(new MLabel(contentText)); page->setEscapeMode(MApplicationPageModel::EscapeCloseWindow); return page; } QAction *SampleWindow::createAction(const QString &name, bool checked) { MAction *action = new MAction(name, this); action->setLocation(MAction::ToolBarLocation); action->setCheckable(true); action->setChecked(checked); action->setActionGroup(actionGroup); addAction(action); return action; }
samplewindow.h:
#ifndef SAMPLEWINDOW_H #define SAMPLEWINDOW_H #include <MApplicationWindow> #include <MApplicationPage> #include <MAction> #include <QActionGroup> class SampleWindow : public MApplicationWindow { Q_OBJECT public: SampleWindow(QWidget *parent = 0); private slots: void showPageForAction(QAction *action); private: MApplicationPage *createPage(const QString &name); QAction *createAction(const QString &name, bool checked = false); QAction *currentAction; QActionGroup *actionGroup; }; #endif
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:14:23 (PDT) Doxygen 1.7.1 |
MeeGo Touch |