Home · All Classes · Main Classes · Deprecated |
There are four steps in the implementation process of this navigation pattern:
1. Set your application to display actions as tabs in the toolbar, in other words, in a tab bar:
setToolbarViewType(MToolBar::tabType);
2. Add actions to the MApplicationWindow and set their locations to MAction::ToolBarLocation so that they appear in the toolbar.
action->setLocation(MAction::ToolBarLocation); applicationWindow->addAction(action);
3. Connect the triggered() signal of the actions to slots that display the corresponding pages.
window->connect(settingsAction, SIGNAL(triggered()), SLOT(showSettingsPage()));
4. Set the MApplicationPage::escapeMode() of your pages to MApplicationPageModel::EscapeCloseWindow, otherwise the Escape button behaves as in a drill-down navigational pattern.
In this example, the actions are grouped in a QActionGroup so that the same method is called whenever any of the actions is triggered.
All files can be found at:
libmeegotouch/examples/pagenavigation_tab
main.cpp:
/*************************************************************************** ** ** Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (directui@nokia.com) ** ** This file is part of libmeegotouch. ** ** If you have questions regarding the use of this file, please contact ** Nokia at directui@nokia.com. ** ** This library is free software; you can redistribute it and/or ** modify it under the terms of the GNU Lesser General Public ** License version 2.1 as published by the Free Software Foundation ** and appearing in the file LICENSE.LGPL included in the packaging ** of this file. ** ****************************************************************************/ #include <MApplication> #include "samplewindow.h" int main(int argc, char **argv) { MApplication app(argc, argv); SampleWindow window; window.show(); return app.exec(); }
samplewindow.cpp:
/*************************************************************************** ** ** Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (directui@nokia.com) ** ** This file is part of libmeegotouch. ** ** If you have questions regarding the use of this file, please contact ** Nokia at directui@nokia.com. ** ** This library is free software; you can redistribute it and/or ** modify it under the terms of the GNU Lesser General Public ** License version 2.1 as published by the Free Software Foundation ** and appearing in the file LICENSE.LGPL included in the packaging ** of this file. ** ****************************************************************************/ #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:
/*************************************************************************** ** ** Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (directui@nokia.com) ** ** This file is part of libmeegotouch. ** ** If you have questions regarding the use of this file, please contact ** Nokia at directui@nokia.com. ** ** This library is free software; you can redistribute it and/or ** modify it under the terms of the GNU Lesser General Public ** License version 2.1 as published by the Free Software Foundation ** and appearing in the file LICENSE.LGPL included in the packaging ** of this file. ** ****************************************************************************/ #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 | MeeGo Touch |