| Home · All Classes · Main Classes · Deprecated |
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 <MDebug> 00021 #include <MDismissEvent> 00022 #include <QChildEvent> 00023 #include <QGestureEvent> 00024 #include <QTapAndHoldGesture> 00025 #include <QGraphicsSceneContextMenuEvent> 00026 #include <QTimer> 00027 #include "mscenewindow.h" 00028 #include "mscenewindowmodel.h" 00029 #include "mscenewindow_p.h" 00030 #include "mscene.h" 00031 #include "mscene_p.h" 00032 #include "mscenemanager.h" 00033 #include "mscenemanager_p.h" 00034 #include "mapplication.h" 00035 #include "mwidgetview.h" 00036 #include "mwindow.h" 00037 #include "mdialog.h" 00038 #include "mcancelevent.h" 00039 00040 #include "mwidgetcreator.h" 00041 M_REGISTER_WIDGET_NO_CREATE(MSceneWindow) 00042 00043 MSceneWindowPrivate::MSceneWindowPrivate() 00044 : windowType(MSceneWindow::PlainSceneWindow), 00045 policy(MSceneWindow::KeepWhenDone), 00046 sceneWindowState(MSceneWindow::Disappeared), 00047 managedManually(false), 00048 dismissed(false), 00049 waitingForContextMenuEvent(false), 00050 effect(0), 00051 displacementItem(0), 00052 appearanceAnimation(0), 00053 disappearanceAnimation(0), 00054 queuedTransition(0), 00055 sceneManager(0) 00056 { 00057 } 00058 00059 void MSceneWindowPrivate::setSceneWindowState(MSceneWindow::SceneWindowState newState) 00060 { 00061 Q_Q(MSceneWindow); 00062 00063 if (newState == sceneWindowState) 00064 return; 00065 00066 MSceneWindow::SceneWindowState oldState = sceneWindowState; 00067 00068 sceneWindowState = newState; 00069 00070 emit q->sceneWindowStateChanged(newState, oldState); 00071 00072 switch (newState) { 00073 case MSceneWindow::Appearing: 00074 emit q->appearing(); 00075 break; 00076 00077 case MSceneWindow::Appeared: 00078 emit q->appeared(); 00079 break; 00080 00081 case MSceneWindow::Disappearing: 00082 emit q->disappearing(); 00083 break; 00084 00085 case MSceneWindow::Disappeared: 00086 emit q->disappeared(); 00087 break; 00088 00089 default: 00090 break; 00091 } 00092 } 00093 00094 MSceneWindow::MSceneWindow(QGraphicsItem *parent) : 00095 MWidgetController(new MSceneWindowPrivate, new MSceneWindowModel, parent) 00096 { 00097 Q_D(MSceneWindow); 00098 00099 d->windowType = PlainSceneWindow; 00100 grabGesture(Qt::PanGesture); 00101 grabGesture(Qt::TapGesture); 00102 grabGesture(Qt::TapAndHoldGesture); 00103 grabGesture(Qt::PinchGesture); 00104 grabGesture(Qt::SwipeGesture); 00105 setFlag(QGraphicsItem::ItemStopsClickFocusPropagation); 00106 } 00107 00108 00109 MSceneWindow::MSceneWindow(MSceneWindowPrivate *dd, MSceneWindowModel *model, MSceneWindow::WindowType windowType, const QString &viewType, QGraphicsItem *parent) : 00110 MWidgetController(dd, model, parent) 00111 { 00112 Q_D(MSceneWindow); 00113 setViewType(viewType); 00114 00115 d->windowType = windowType; 00116 grabGesture(Qt::PanGesture); 00117 grabGesture(Qt::TapGesture); 00118 grabGesture(Qt::TapAndHoldGesture); 00119 grabGesture(Qt::PinchGesture); 00120 grabGesture(Qt::SwipeGesture); 00121 setFlag(QGraphicsItem::ItemStopsClickFocusPropagation); 00122 } 00123 00124 MSceneWindow::~MSceneWindow() 00125 { 00126 if (sceneManager()) 00127 sceneManager()->d_func()->removeSceneWindow(this); 00128 } 00129 00130 MSceneWindow::WindowType MSceneWindow::windowType() const 00131 { 00132 Q_D(const MSceneWindow); 00133 return d->windowType; 00134 } 00135 00136 MSceneWindow::DeletionPolicy MSceneWindow::deletionPolicy() const 00137 { 00138 Q_D(const MSceneWindow); 00139 return d->policy; 00140 } 00141 00142 bool MSceneWindow::isManagedManually() const 00143 { 00144 Q_D(const MSceneWindow); 00145 return d->managedManually; 00146 } 00147 00148 void MSceneWindow::setManagedManually(bool managedManually) 00149 { 00150 Q_D(MSceneWindow); 00151 d->managedManually = managedManually; 00152 } 00153 00154 MSceneWindow::SceneWindowState MSceneWindow::sceneWindowState() const 00155 { 00156 Q_D(const MSceneWindow); 00157 return d->sceneWindowState; 00158 } 00159 00160 void MSceneWindow::appear(QGraphicsScene *scene, MSceneWindow::DeletionPolicy policy) 00161 { 00162 if (!scene) { 00163 mWarning("MSceneWindow") << Q_FUNC_INFO << "NULL scene."; 00164 return; 00165 } 00166 00167 MScene *mScene = qobject_cast<MScene *>(scene); 00168 if (!mScene || !mScene->sceneManager()) { 00169 mWarning("MSceneWindow") << Q_FUNC_INFO << "scene has no scene manager."; 00170 return; 00171 } 00172 00173 if (view()) { 00174 if (model()->disappearTimeout() != 0) { 00175 QTimer::singleShot(model()->disappearTimeout(), this, SLOT(disappear())); 00176 } 00177 } 00178 00179 mScene->sceneManager()->appearSceneWindow(this, policy); 00180 } 00181 00182 void MSceneWindow::appear(MWindow *window, MSceneWindow::DeletionPolicy policy) 00183 { 00184 if (!window) { 00185 // Remove this behavior along with the deprecated 00186 // MSceneWindow::appear(DeletionPolicy); 00187 window = MApplication::activeWindow(); 00188 if (!window) { 00189 mWarning("MSceneWindow") 00190 << "Construct and show MWindow before showing a scene window"; 00191 return; 00192 } 00193 } 00194 00195 // Force the creation of a scene manager (and scene) if none was 00196 // set to this window yet. 00197 // 00198 // Therefore: 00199 // sceneWindow->appear(window); 00200 // Will yield a different result than: 00201 // sceneWindow->appear(window->scene()); 00202 // If window didn't have a scene and scene manager. 00203 window->sceneManager(); 00204 00205 appear(window->scene(), policy); 00206 } 00207 00208 void MSceneWindow::appear(MSceneWindow::DeletionPolicy policy) 00209 { 00210 mWarning("MSceneWindow") << Q_FUNC_INFO << "is deprecated." 00211 "Use appear(QGraphicsScene*) or appear(MWindow*) instead."; 00212 appear((MWindow *)0, policy); 00213 } 00214 00215 void MSceneWindow::disappear() 00216 { 00217 if (sceneManager()) 00218 sceneManager()->disappearSceneWindow(this); 00219 } 00220 00221 Qt::Alignment MSceneWindow::alignment() const 00222 { 00223 Qt::Alignment result = 0; 00224 00225 // There is an implicit property interface between the controller and the views 00226 // The controller expects the view to provide an "alignment" property. 00227 if (view()) { 00228 QVariant v = view()->property("alignment"); 00229 if (v.isValid()) { 00230 result = Qt::Alignment(v.toInt()); 00231 } 00232 else { 00233 } 00234 } 00235 00236 if (layoutDirection() == Qt::RightToLeft) { 00237 if (result.testFlag(Qt::AlignLeft)) { 00238 result &= ~Qt::AlignLeft; 00239 result |= Qt::AlignRight; 00240 } else if (result.testFlag(Qt::AlignRight)) { 00241 result &= ~Qt::AlignRight; 00242 result |= Qt::AlignLeft; 00243 } 00244 } 00245 00246 return result; 00247 } 00248 00249 QPointF MSceneWindow::offset() const 00250 { 00251 QPointF result; 00252 00253 // There is an implicit property interface between the controller and the views 00254 // The controller expects the view to provide an "offset" property. 00255 if (view()) { 00256 QVariant v = view()->property("offset"); 00257 if (v.isValid()) { 00258 result = v.toPointF(); 00259 } 00260 } else { 00261 result = QPointF(0, 0); 00262 } 00263 00264 return result; 00265 } 00266 00267 bool MSceneWindow::dismiss() 00268 { 00269 MDismissEvent dismissEvent; 00270 QApplication::sendEvent(this, &dismissEvent); 00271 00272 if (!dismissEvent.isAccepted()) { 00273 return false; 00274 } 00275 00276 if (sceneManager()) { 00277 sceneManager()->dismissSceneWindow(this); 00278 } 00279 00280 return true; 00281 } 00282 00283 void MSceneWindow::dismissEvent(MDismissEvent *event) 00284 { 00285 event->accept(); 00286 } 00287 00288 void MSceneWindow::closeEvent(QCloseEvent *event) 00289 { 00290 event->ignore(); 00291 dismiss(); 00292 } 00293 00294 void MSceneWindow::tapAndHoldGestureEvent(QGestureEvent *event, QTapAndHoldGesture *gesture) 00295 { 00296 Q_D(MSceneWindow); 00297 00298 if (gesture->state() == Qt::GestureStarted) { 00299 // We will send cancel event on our own, unregistering this gesture from mscene. 00300 MScene *mScene = qobject_cast<MScene *>(scene()); 00301 if (mScene) 00302 mScene->d_func()->notifyGestureCaughtByPanel(gesture->gestureType()); 00303 } else if (gesture->state() == Qt::GestureFinished) { 00304 00305 QGraphicsSceneContextMenuEvent contextEvent(QEvent::GraphicsSceneContextMenu); 00306 contextEvent.setPos(gesture->position()); 00307 contextEvent.setScenePos(gesture->position()); 00308 contextEvent.setScreenPos(gesture->position().toPoint()); 00309 00310 d->waitingForContextMenuEvent = true; 00311 QApplication::sendEvent(scene(), &contextEvent); 00312 00313 if (contextEvent.isAccepted() && d->waitingForContextMenuEvent) { 00314 //Event has been accepted by some widget on top of this scenewindow. 00315 if ((scene() == NULL) || (scene()->views().size() == 0)) { 00316 // If this widget has been removed from the scene and/or there 00317 // is no view, return 00318 return; 00319 } 00320 00321 MCancelEvent cancelEvent; 00322 QList<QGraphicsItem*> affectedItems = scene()->items(gesture->hotSpot()); 00323 QGraphicsItem *item = 0; 00324 00325 foreach(item, affectedItems) { 00326 if (scene()->items().contains(item)) 00327 scene()->sendEvent(item, &cancelEvent); 00328 } 00329 } 00330 d->waitingForContextMenuEvent = false; 00331 00332 } 00333 00334 event->accept(gesture); 00335 } 00336 00337 bool MSceneWindow::event(QEvent *event) 00338 { 00339 Q_D(MSceneWindow); 00340 if (event->type() == MDismissEvent::eventType()) { 00341 dismissEvent(static_cast<MDismissEvent *>(event)); 00342 } else if (event->type() == QEvent::GraphicsSceneContextMenu) { 00343 //Event was not accepted by any of our child widgets. 00344 //We need to accept it so that it doesn't propagate further and 00345 //clear the flag, so that the tap&hold gesture event handler 00346 //will know that the event wasn't delivered. 00347 if (d->waitingForContextMenuEvent) { 00348 event->accept(); 00349 d->waitingForContextMenuEvent = false; 00350 return true; 00351 } 00352 } else if (event->type() == QEvent::ChildAdded) { 00353 QChildEvent *childEvent = static_cast<QChildEvent *>(event); 00354 if (childEvent->child()->objectName() == "_m_testBridge") { 00355 new MSceneWindowTestInterface(d, childEvent->child()); 00356 } 00357 } 00358 00359 return MWidgetController::event(event); 00360 } 00361 00362 void MSceneWindow::gestureEvent(QGestureEvent *event) 00363 { 00364 00365 MWidgetController::gestureEvent(event); 00366 00367 MScene *mScene = qobject_cast<MScene *>(scene()); 00368 if (!mScene) 00369 return; 00370 00371 foreach(QGesture* gesture, event->gestures()) { 00372 if (gesture->state() == Qt::GestureStarted && !event->isAccepted(gesture->gestureType())) { 00373 mScene->d_func()->notifyGestureCaughtByPanel(gesture->gestureType()); 00374 event->accept(gesture); 00375 } 00376 } 00377 } 00378 00379 MSceneWindowTestInterface::MSceneWindowTestInterface(MSceneWindowPrivate *d, QObject *parent) 00380 : QObject(parent), d(d) 00381 { 00382 } 00383 00384 void MSceneWindowTestInterface::setSceneWindowState(MSceneWindow::SceneWindowState newState) 00385 { 00386 d->setSceneWindowState(newState); 00387 }
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:14:21 (PDT) Doxygen 1.7.1 |
MeeGo Touch |