Home · All Classes · Main Classes · Deprecated

mapplicationpage.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (directui@nokia.com)
00006 **
00007 ** This file is part of libmeegotouch.
00008 **
00009 ** If you have questions regarding the use of this file, please contact
00010 ** Nokia at directui@nokia.com.
00011 **
00012 ** This library is free software; you can redistribute it and/or
00013 ** modify it under the terms of the GNU Lesser General Public
00014 ** License version 2.1 as published by the Free Software Foundation
00015 ** and appearing in the file LICENSE.LGPL included in the packaging
00016 ** of this file.
00017 **
00018 ****************************************************************************/
00019 
00020 #include "mapplicationpage.h"
00021 #include "mapplicationpage_p.h"
00022 #include "mapplicationpagemodel.h"
00023 #include "mapplicationwindow.h"
00024 #include "mwidgetview.h"
00025 #include "mondisplaychangeevent.h"
00026 #include "mwidgetcreator.h"
00027 #include "mpannableviewport.h"
00028 
00029 #include <QAction>
00030 #include <QGraphicsLinearLayout>
00031 
00032 M_REGISTER_WIDGET(MApplicationPage)
00033 
00034 MApplicationPagePrivate::MApplicationPagePrivate() :
00035     pannableViewport(0),
00036     panDirection(0),
00037     contentCreated(false)
00038 {}
00039 
00040 void MApplicationPagePrivate::init()
00041 {
00042     Q_Q(MApplicationPage);
00043 
00044     QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
00045     layout->setContentsMargins(0, 0, 0, 0);
00046     layout->setSpacing(0.0);
00047 
00048     pannableViewport = new MPannableViewport;
00049     pannableViewport->setClipping(false);
00050     panDirection = pannableViewport->panDirection();
00051 
00052     layout->addItem(pannableViewport);
00053 
00054     q->setLayout(layout);
00055 
00056     q->connect(q,
00057                SIGNAL(sceneWindowStateChanged(MSceneWindow::SceneWindowState,
00058                                               MSceneWindow::SceneWindowState)),
00059                SLOT(_q_onSceneWindowStateChanged(MSceneWindow::SceneWindowState,
00060                                                  MSceneWindow::SceneWindowState)));
00061 }
00062 
00063 void MApplicationPagePrivate::_q_onSceneWindowStateChanged(
00064         MSceneWindow::SceneWindowState newState, MSceneWindow::SceneWindowState oldState)
00065 {
00066     Q_Q(MApplicationPage);
00067 
00068     if (oldState == MSceneWindow::Disappeared &&
00069             (newState == MSceneWindow::Appearing || newState == MSceneWindow::Appeared)) {
00070 
00071         if (!contentCreated) {
00072             contentCreated = true;
00073             q->createContent();
00074         }
00075     }
00076 }
00077 
00078 MApplicationPage::MApplicationPage(QGraphicsItem *parent)
00079     : MSceneWindow(new MApplicationPagePrivate, new MApplicationPageModel,
00080                      MSceneWindow::ApplicationPage, QString(), parent)
00081 {
00082     Q_D(MApplicationPage);
00083 
00084     d->init();
00085 }
00086 
00087 MApplicationPage::~MApplicationPage()
00088 {
00089     setCentralWidget(0);
00090 }
00091 
00092 void MApplicationPage::setCentralWidget(QGraphicsWidget *centralWidget)
00093 {
00094     if (model()->centralWidget())
00095         delete model()->centralWidget();
00096 
00097     model()->setCentralWidget(centralWidget);
00098 }
00099 
00100 QGraphicsWidget *MApplicationPage::centralWidget()
00101 {
00102     return model()->centralWidget();
00103 }
00104 
00105 MApplicationWindow *MApplicationPage::applicationWindow()
00106 {
00107     MApplicationWindow *applicationWindow = 0;
00108 
00109     if (scene() != 0) {
00110         QList<QGraphicsView *> viewsList = scene()->views();
00111         int i = 0;
00112 
00113         while (applicationWindow == 0 && i < viewsList.count()) {
00114 
00115             applicationWindow = qobject_cast<MApplicationWindow *>(viewsList[i]);
00116             ++i;
00117         }
00118     }
00119 
00120     return applicationWindow;
00121 }
00122 
00123 const QString MApplicationPage::title() const
00124 {
00125     return model()->title();
00126 }
00127 
00128 void MApplicationPage::setTitle(const QString &title)
00129 {
00130     model()->setTitle(title);
00131 }
00132 
00133 void MApplicationPage::createContent()
00134 {
00135     Q_D(MApplicationPage);
00136 
00137     d->contentCreated = true;
00138 }
00139 
00140 bool MApplicationPage::isContentCreated() const
00141 {
00142     Q_D(const MApplicationPage);
00143 
00144     return d->contentCreated;
00145 }
00146 
00147 void MApplicationPage::setRememberPosition(bool remember)
00148 {
00149     model()->setRememberPosition(remember);
00150 }
00151 
00152 bool MApplicationPage::rememberPosition() const
00153 {
00154     return model()->rememberPosition();
00155 }
00156 
00157 void MApplicationPage::setPannable(bool pannable)
00158 {
00159     Q_D(MApplicationPage);
00160 
00161     if (pannable)
00162         d->pannableViewport->setPanDirection(d->panDirection);
00163     else
00164         d->pannableViewport->setPanDirection(0);
00165 }
00166 
00167 bool MApplicationPage::isPannable() const
00168 {
00169     Q_D(const MApplicationPage);
00170 
00171     return d->pannableViewport->panDirection() != 0;
00172 }
00173 
00174 void MApplicationPage::setPanningDirection(Qt::Orientations direction)
00175 {
00176     Q_D(MApplicationPage);
00177 
00178     d->panDirection = direction;
00179     d->pannableViewport->setPanDirection(direction);
00180 }
00181 
00182 Qt::Orientations MApplicationPage::panningDirection() const
00183 {
00184     Q_D(const MApplicationPage);
00185 
00186     return d->pannableViewport->panDirection();
00187 }
00188 
00189 void MApplicationPage::actionEvent(QActionEvent *e)
00190 {
00191     QAction *action = e->action();
00192     switch (e->type()) {
00193     case QEvent::ActionRemoved: {
00194         if (action)
00195             action->disconnect(this);
00196         //fall through is intentional.
00197     }
00198     case QEvent::ActionChanged:
00199     case QEvent::ActionAdded: {
00200         emit actionUpdated(e);
00201         break;
00202     }
00203     default: {
00204         break;
00205     }
00206     }
00207 }
00208 
00209 void MApplicationPage::enterDisplayEvent()
00210 {
00211     MSceneWindow::enterDisplayEvent();
00212 }
00213 
00214 void MApplicationPagePrivate::doEnterDisplayEvent()
00215 {
00216     Q_Q(MApplicationPage);
00217 
00218     if (!contentCreated) {
00219         contentCreated = true;
00220         q->createContent();
00221     }
00222 
00223     MWidgetPrivate::doEnterDisplayEvent();
00224 }
00225 
00226 void MApplicationPagePrivate::setExposedContentRect(const QRectF &exposedContentRect)
00227 {
00228     Q_Q(MApplicationPage);
00229 
00230     if (exposedContentRect != q->model()->exposedContentRect()) {
00231         q->model()->setExposedContentRect(exposedContentRect);
00232         emit q->exposedContentRectChanged();
00233     }
00234 }
00235 
00236 QRectF MApplicationPage::exposedContentRect() const
00237 {
00238     return model()->exposedContentRect();
00239 }
00240 
00241 MApplicationPageModel::ComponentDisplayMode MApplicationPage::componentDisplayMode(
00242     Component component) const
00243 {
00244     MApplicationPageModel::ComponentDisplayMode displayMode;
00245 
00246     switch (component) {
00247     case NavigationBar:
00248         displayMode = model()->navigationBarDisplayMode();
00249         break;
00250 
00251     case HomeButton:
00252         displayMode = model()->homeButtonDisplayMode();
00253         break;
00254 
00255     default:
00256         displayMode = model()->escapeButtonDisplayMode();
00257     };
00258 
00259     return displayMode;
00260 }
00261 
00262 void MApplicationPage::setComponentsDisplayMode(Components components,
00263         MApplicationPageModel::ComponentDisplayMode displayMode)
00264 {
00265     if (components.testFlag(NavigationBar)) {
00266         model()->setNavigationBarDisplayMode(displayMode);
00267     }
00268 
00269     if (components.testFlag(HomeButton)) {
00270         model()->setHomeButtonDisplayMode(displayMode);
00271     }
00272 
00273     if (components.testFlag(EscapeButton)) {
00274         model()->setEscapeButtonDisplayMode(displayMode);
00275     }
00276 }
00277 
00278 bool MApplicationPage::isProgressIndicatorVisible() const
00279 {
00280     return model()->progressIndicatorVisible();
00281 }
00282 
00283 void MApplicationPage::setProgressIndicatorVisible(bool visible)
00284 {
00285     model()->setProgressIndicatorVisible(visible);
00286 }
00287 
00288 void MApplicationPage::setAutoMarginsForComponentsEnabled(bool enabled)
00289 {
00290     model()->setAutoMarginsForComponentsEnabled(enabled);
00291 }
00292 
00293 bool MApplicationPage::autoMarginsForComponentsEnabled() const
00294 {
00295     return model()->autoMarginsForComponentsEnabled();
00296 }
00297 
00298 MApplicationPageModel::PageEscapeMode MApplicationPage::escapeMode() const
00299 {
00300     return model()->escapeMode();
00301 }
00302 
00303 void MApplicationPage::setEscapeMode(MApplicationPageModel::PageEscapeMode mode)
00304 {
00305     model()->setEscapeMode(mode);
00306 }
00307 
00308 MPannableViewport * MApplicationPage::pannableViewport()
00309 {
00310     Q_D(MApplicationPage);
00311 
00312     return d->pannableViewport;
00313 }
00314 
00315 #include "moc_mapplicationpage.cpp"

Copyright © 2010 Nokia Corporation Generated on Thu Nov 4 2010 18:14:20 (PDT)
Doxygen 1.7.1
MeeGo Touch