Home · All Classes · Main Classes · Deprecated

mscene.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 <QList>
00021 #include <QGraphicsItem>
00022 #include <QPainter>
00023 #include <QTime>
00024 #include <QTimer>
00025 #include <QFileInfo>
00026 #include <QGesture>
00027 #include <QGestureEvent>
00028 
00029 #include "mdebug.h"
00030 #include <mondisplaychangeevent.h>
00031 #include "mapplication.h"
00032 #include "mapplicationwindow.h"
00033 #include "mscene.h"
00034 #include "mscenemanager.h"
00035 #include "mwidget.h"
00036 #include "mapplicationpage.h"
00037 #include "mscene_p.h"
00038 #include "mdeviceprofile.h"
00039 #include "mcancelevent.h"
00040 
00041 const QFont     TextFont                = QFont("Sans", 10);
00042 const QSize     FpsBoxSize              = QSize(100, 40);
00043 const QColor    FpsTextColor            = QColor(0xFFFF00);
00044 const QFont     FpsFont                 = QFont("Sans", 15);
00045 const int       FpsRefreshInterval      = 1000;
00046 const QString   FpsBackgroundColor      = "#000000";
00047 const qreal     FpsBackgroundOpacity    = 0.35;
00048 const QString   BoundingRectLineColor   = "#00F000";
00049 const QString   BoundingRectFillColor   = "#00F000";
00050 const qreal     BoundingRectOpacity     = 0.1;
00051 const qreal     MarginBackgroundOpacity = 0.4;
00052 const QColor    MarginColor             = QColor(Qt::red);
00053 const int       MarginBorderWidth       = 2;
00054 
00055 
00056 MScenePrivate::MScenePrivate() :
00057         q_ptr(0),
00058         manager(0),
00059         emuPoint1(1),
00060         emuPoint2(2),
00061         pinchEmulationEnabled(false)
00062 {
00063 }
00064 
00065 MScenePrivate::~MScenePrivate()
00066 {
00067 }
00068 
00069 void MScenePrivate::setSceneManager(MSceneManager *sceneManager)
00070 {
00071     manager = sceneManager;
00072 }
00073 
00074 void MScenePrivate::onDisplayChangeEvent(MOnDisplayChangeEvent *event)
00075 {
00076     Q_Q(MScene);
00077 
00078     if (event->state() == MOnDisplayChangeEvent::FullyOnDisplay ||
00079             event->state() == MOnDisplayChangeEvent::FullyOffDisplay) {
00080         // Simple cases. Just forward the event as it is.
00081         sendEventToMWidgets(filterMWidgets(q->items()), event);
00082         return;
00083     }
00084 
00085     QList<MWidget *> fullyOnWidgets;
00086     QList<MWidget *> partiallyOnWidgets;
00087     QList<MWidget *> fullyOffWidgets;
00088 
00089     QList<MWidget *> intersectingWidgets = filterMWidgets(q->items(event->viewRect(),
00090             Qt::IntersectsItemBoundingRect));
00091 
00092     QList<MWidget *> allWidgets = filterMWidgets(q->items());
00093 
00094     // Find who is fully on, partially on and fully off
00095 
00096     QSet<MWidget *> fullyOffWidgetsSet = allWidgets.toSet().subtract(intersectingWidgets.toSet());
00097     fullyOffWidgets = fullyOffWidgetsSet.toList();
00098 
00099     int intersectingWidgetsCount = intersectingWidgets.count();
00100     MWidget *widget;
00101     for (int i = 0; i < intersectingWidgetsCount; i++) {
00102         widget = intersectingWidgets.at(i);
00103         if (event->viewRect().contains(widget->sceneBoundingRect())) {
00104             fullyOnWidgets << widget;
00105         } else {
00106             partiallyOnWidgets << widget;
00107         }
00108     }
00109 
00110     // Send the events to the corresponding MWidgets
00111 
00112     if (fullyOnWidgets.count() > 0) {
00113         MOnDisplayChangeEvent fullyOnEvent(MOnDisplayChangeEvent::FullyOnDisplay,
00114                                              event->viewRect());
00115 
00116         sendEventToMWidgets(fullyOnWidgets, &fullyOnEvent);
00117     }
00118 
00119     if (fullyOffWidgets.count() > 0) {
00120         MOnDisplayChangeEvent fullyOffEvent(MOnDisplayChangeEvent::FullyOffDisplay,
00121                                               event->viewRect());
00122 
00123         sendEventToMWidgets(fullyOffWidgets, &fullyOffEvent);
00124     }
00125 
00126     if (partiallyOnWidgets.count() > 0) {
00127         MOnDisplayChangeEvent partiallyOnEvent(MOnDisplayChangeEvent::PartiallyOnDisplay,
00128                 event->viewRect());
00129 
00130         sendEventToMWidgets(partiallyOnWidgets, &partiallyOnEvent);
00131     }
00132 
00133 }
00134 
00135 QList<MWidget *> MScenePrivate::filterMWidgets(QList<QGraphicsItem *> itemsList)
00136 {
00137     QGraphicsItem *item;
00138     MWidget *mWidget;
00139     QList<MWidget *> widgetsList;
00140 
00141     int itemsCount = itemsList.count();
00142     for (int i = 0; i < itemsCount; i++) {
00143         item = itemsList.at(i);
00144         if (item->isWidget()) {
00145             mWidget = qobject_cast<MWidget *>(static_cast<QGraphicsWidget *>(item));
00146             if (mWidget) {
00147                 widgetsList << mWidget;
00148             }
00149         }
00150     }
00151 
00152     return widgetsList;
00153 }
00154 
00155 void MScenePrivate::sendEventToMWidgets(QList<MWidget *> widgetsList, QEvent *event)
00156 {
00157     Q_Q(MScene);
00158     MWidget *widget;
00159 
00160     foreach(widget, widgetsList) {
00161         //we have to check if any of items was removed from scene or deleted
00162         //while previous ones were handling the event
00163         if(q->items().contains(widget)){
00164             q->sendEvent(widget, event);
00165         }
00166     }
00167 }
00168 
00169 void MScenePrivate::touchPointCopyPosToLastPos(QTouchEvent::TouchPoint &point)
00170 {
00171     point.setLastPos(point.pos());
00172     point.setLastScenePos(point.scenePos());
00173     point.setLastScreenPos(point.screenPos());
00174 }
00175 
00176 void MScenePrivate::touchPointCopyMousePosToPointPos(QTouchEvent::TouchPoint &point, const QGraphicsSceneMouseEvent *event)
00177 {
00178     point.setPos(event->scenePos());
00179     point.setScenePos(event->scenePos());
00180     point.setScreenPos(event->scenePos());
00181 }
00182 
00183 void MScenePrivate::touchPointCopyMousePosToPointStartPos(QTouchEvent::TouchPoint &point, const QGraphicsSceneMouseEvent *event)
00184 {
00185     point.setStartPos(event->scenePos());
00186     point.setStartScenePos(event->scenePos());
00187     point.setStartScreenPos(event->scenePos());
00188 }
00189 
00190 void MScenePrivate::touchPointMirrorMousePosToPointPos(QTouchEvent::TouchPoint &point, const QGraphicsSceneMouseEvent *event)
00191 {
00192     QSize resolution = MDeviceProfile::instance()->resolution();
00193     QPointF centerPoint(resolution.width() / 2, resolution.height() / 2);
00194     QPointF mirrorPoint = centerPoint + (centerPoint - event->scenePos());
00195 
00196     point.setPos(mirrorPoint);
00197     point.setScenePos(mirrorPoint);
00198     point.setScreenPos(mirrorPoint);
00199 }
00200 
00201 void MScenePrivate::touchPointMirrorMousePosToPointStartPos(QTouchEvent::TouchPoint &point, const QGraphicsSceneMouseEvent *event)
00202 {
00203     QSize resolution = MDeviceProfile::instance()->resolution();
00204     QPointF centerPoint(resolution.width() / 2, resolution.height() / 2);
00205     QPointF mirrorPoint = centerPoint + (centerPoint - event->scenePos());
00206 
00207     point.setStartPos(mirrorPoint);
00208     point.setStartScenePos(mirrorPoint);
00209     point.setStartScreenPos(mirrorPoint);
00210 }
00211 
00212 bool MScenePrivate::eventEmulateTwoFingerGestures(QEvent *event)
00213 {
00214     if (MApplication::emulateTwoFingerGestures() &&
00215         eventEmulatePinch(event)) {
00216         return true;
00217     }
00218 
00219     return false;
00220 }
00221 
00222 bool MScenePrivate::eventEmulatePinch(QEvent *event)
00223 {
00224     Q_Q(MScene);
00225 
00226     bool sendTouchEvent = false;
00227     QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent*>(event);
00228 
00229     QEvent::Type touchEventType;
00230     Qt::TouchPointState touchPointState;
00231 
00232     if (QEvent::GraphicsSceneMousePress == event->type()) {
00233         if (Qt::LeftButton == e->button() && Qt::ControlModifier == e->modifiers()) {
00234             pinchEmulationEnabled = true;
00235 
00236             touchPointMirrorMousePosToPointPos(emuPoint1,e);
00237             touchPointMirrorMousePosToPointStartPos(emuPoint1,e);
00238             emuPoint1.setState(Qt::TouchPointPressed);
00239 
00240             touchPointCopyMousePosToPointPos(emuPoint2,e);
00241             touchPointCopyMousePosToPointStartPos(emuPoint2,e);
00242             emuPoint2.setState(Qt::TouchPointPressed);
00243 
00244             touchEventType = QEvent::TouchBegin;
00245             touchPointState = Qt::TouchPointPressed;
00246             sendTouchEvent = true;
00247         }
00248     }
00249 
00250     if (pinchEmulationEnabled && QEvent::GraphicsSceneMouseMove == event->type()) {
00251 
00252         touchPointCopyPosToLastPos(emuPoint1);
00253         touchPointMirrorMousePosToPointPos(emuPoint1,e);
00254         emuPoint1.setState(Qt::TouchPointMoved);
00255 
00256         touchPointCopyPosToLastPos(emuPoint2);
00257         touchPointCopyMousePosToPointPos(emuPoint2,e);
00258         emuPoint2.setState(Qt::TouchPointMoved);
00259 
00260         touchEventType = QEvent::TouchUpdate;
00261         touchPointState = Qt::TouchPointMoved;
00262         sendTouchEvent = true;
00263     }
00264 
00265     if (pinchEmulationEnabled && QEvent::GraphicsSceneMouseRelease == event->type()) {
00266         if (Qt::LeftButton == e->button()) {
00267 
00268             touchPointCopyPosToLastPos(emuPoint1);
00269             emuPoint1.setState(Qt::TouchPointReleased);
00270 
00271             touchPointCopyPosToLastPos(emuPoint2);
00272             touchPointCopyMousePosToPointPos(emuPoint2,e);
00273             emuPoint2.setState(Qt::TouchPointReleased);
00274 
00275             touchEventType = QEvent::TouchEnd;
00276             touchPointState = Qt::TouchPointReleased;
00277             pinchEmulationEnabled = false;
00278             sendTouchEvent = true;
00279         }
00280     }
00281 
00282     if (sendTouchEvent) {
00283         QList<QTouchEvent::TouchPoint> touchList;
00284         touchList.append(emuPoint1);
00285         touchList.append(emuPoint2);
00286 
00287         QTouchEvent touchEvent(touchEventType, QTouchEvent::TouchPad, Qt::NoModifier, touchPointState, touchList);
00288         QApplication::sendEvent(q, &touchEvent);
00289         q->update();
00290         return true;
00291     }
00292 
00293     return false;
00294 }
00295 
00296 
00297 void MScenePrivate::showFpsCounter(QPainter *painter, float fps)
00298 {
00299     Q_Q(MScene);
00300 
00301     QString display = QString("FPS: %1").arg((int)(fps + 0.5f));
00302     /* Draw a simple FPS counter in the lower right corner */
00303     static QRectF fpsRect(0, 0, FpsBoxSize.width(), FpsBoxSize.height());
00304     if (!q->views().isEmpty()) {
00305         MApplicationWindow *window = qobject_cast<MApplicationWindow *>(q->views().at(0));
00306         if (window) {
00307             if (manager && manager->orientation() == M::Portrait)
00308                 fpsRect.moveTo(QPointF(window->visibleSceneSize().height() - FpsBoxSize.width(),
00309                                        window->visibleSceneSize().width() - FpsBoxSize.height()));
00310             else
00311                 fpsRect.moveTo(QPointF(window->visibleSceneSize().width() - FpsBoxSize.width(),
00312                                        window->visibleSceneSize().height() - FpsBoxSize.height()));
00313         }
00314     }
00315 
00316     painter->fillRect(fpsRect, fpsBackgroundBrush);
00317 
00318     painter->setPen(FpsTextColor);
00319     painter->setFont(FpsFont);
00320     painter->drawText(fpsRect,
00321                       Qt::AlignCenter,
00322                       display);
00323 }
00324 
00325 void MScenePrivate::logFpsCounter(const QTime *timeStamp, float fps)
00326 {
00327     /* Open fps log-file, if needed */
00328     if (!fpsLog.output.isOpen()) {
00329         QFileInfo fi(qApp->arguments().at(0));
00330         QString appName = fi.baseName();
00331         QString pid("0");
00332 #ifdef Q_OS_UNIX
00333         pid = QString().setNum(getpid());
00334 #endif //Q_OS_UNIX
00335 
00336         QString fileName = QString("%1-%2.fps").arg(appName, pid);
00337         fpsLog.output.setFileName(fileName);
00338         if (!fpsLog.output.open(QIODevice::WriteOnly | QIODevice::Text)) {
00339             mWarning("MScene::logFpsCounter") << "Could not open fps log file " << fileName;
00340             MApplication::setLogFps(false);
00341             return;
00342         } else {
00343             fpsLog.stream.setDevice(&fpsLog.output);
00344         }
00345     }
00346     fpsLog.stream << timeStamp->toString();
00347     fpsLog.stream << " " << QString("%1").arg(fps, 0, 'f', 1) << endl;
00348 }
00349 
00350 void MScenePrivate::fillMarginRectWithPattern(QPainter *painter, const QRectF& rect, int thickness)
00351 {
00352     if(thickness == 0)
00353         return;
00354 
00355     QColor fillColor;
00356 
00357     switch(thickness)
00358     {
00359     case 24:
00360         fillColor = QColor(122, 24, 127);
00361         break;
00362     case 16:
00363         fillColor = QColor(250, 25, 0);
00364         break;
00365     case 12:
00366         fillColor = QColor(100, 190, 69);
00367         break;
00368     case 8:
00369         fillColor = QColor(0, 51, 250);
00370         break;
00371     case 6:
00372         fillColor = QColor(138, 93, 59);
00373         break;
00374     case 4:
00375         fillColor = QColor(255, 171, 0);
00376         break;
00377     case 2:
00378         fillColor = QColor(250, 250, 2);
00379         break;
00380 
00381     default:
00382         fillColor = QColor(2, 254, 255);
00383     }
00384 
00385     painter->fillRect(rect, QBrush(fillColor));
00386     painter->setOpacity(0.6);
00387     painter->fillRect(rect, QBrush(Qt::black, Qt::BDiagPattern));
00388 }
00389 
00390 void MScenePrivate::handleGestureEvent(QEvent* event)
00391 {
00392     Q_Q(MScene);
00393 
00394     QGestureEvent *gestureEvent = static_cast<QGestureEvent*>(event);
00395 
00396     foreach(QGesture* gesture, gestureEvent->gestures()) {
00397 
00398         switch (gesture->state()) {
00399         case Qt::GestureStarted:
00400             if (panelAcceptedGestures.contains(gesture->gestureType()))
00401                 panelAcceptedGestures.removeAt(panelAcceptedGestures.indexOf(gesture->gestureType()));
00402             else if (gestureEvent->isAccepted(gesture))
00403                 childrenAcceptedGestures.append(gesture->gestureType());
00404             break;
00405         case Qt::GestureCanceled:
00406             if (childrenAcceptedGestures.contains(gesture->gestureType()))
00407                 childrenAcceptedGestures.removeAt(childrenAcceptedGestures.indexOf(gesture->gestureType()));
00408             break;
00409         case Qt::GestureFinished:
00410                 if (childrenAcceptedGestures.contains(gesture->gestureType())) {
00411                     if (q->mouseGrabberItem()) {
00412                         MCancelEvent cancelEvent;
00413                         q->sendEvent(q->mouseGrabberItem(),&cancelEvent);
00414                     }
00415                     childrenAcceptedGestures.removeAt(childrenAcceptedGestures.indexOf(gesture->gestureType()));
00416                 }
00417         default:
00418             break;
00419         }
00420     }
00421 }
00422 
00423 void MScenePrivate::notifyGestureCaughtByPanel(Qt::GestureType gestureType)
00424 {
00425     if (!panelAcceptedGestures.contains(gestureType))
00426         panelAcceptedGestures.append(gestureType);
00427 }
00428 
00429 MScene::MScene(QObject *parent)
00430     : QGraphicsScene(parent),
00431       d_ptr(new MScenePrivate)
00432 {
00433     Q_D(MScene);
00434 
00435     d->q_ptr = this;
00436     d->manager = 0;
00437     QColor fpsBackgroundColor(FpsBackgroundColor);
00438     fpsBackgroundColor.setAlphaF(FpsBackgroundOpacity);
00439     d->fpsBackgroundBrush = QBrush(fpsBackgroundColor);
00440 
00441     QColor boundingRectLineColor(BoundingRectLineColor);
00442     d->boundingRectLinePen = QPen(boundingRectLineColor);
00443 
00444     QColor boundingRectFillColor(BoundingRectFillColor);
00445     d->boundingRectFillBrush = QBrush(boundingRectFillColor);
00446 
00447     setItemIndexMethod(QGraphicsScene::NoIndex);
00448 }
00449 
00450 MScene::~MScene()
00451 {
00452     delete d_ptr;
00453 }
00454 
00455 MSceneManager *MScene::sceneManager()
00456 {
00457     Q_D(MScene);
00458 
00459     return d->manager;
00460 }
00461 
00462 bool MScene::event(QEvent *event)
00463 {
00464     Q_D(MScene);
00465 
00466     if (d->eventEmulateTwoFingerGestures(event)) {
00467         return true;
00468     }
00469 
00470     bool retValue = QGraphicsScene::event(event);
00471 
00472     if (event->type() == QEvent::Gesture)
00473         d->handleGestureEvent(event);
00474 
00475     return retValue;
00476 }
00477 
00478 void MScene::drawForeground(QPainter *painter, const QRectF &rect)
00479 {
00480     Q_D(MScene);
00481 
00482     /* Overlay information on the widgets in development mode */
00483     if (MApplication::showBoundingRect() || MApplication::showSize() || MApplication::showPosition() || MApplication::showMargins() || MApplication::showObjectNames() || MApplication::showStyleNames()) {
00484         QList<QGraphicsItem *> itemList = items(rect);
00485         QList<QGraphicsItem *>::iterator item;
00486 
00487         painter->setFont(TextFont);
00488         QFontMetrics metrics(TextFont);
00489         int fontHeight = metrics.height();
00490 
00491         QTransform rotationMatrix;
00492         painter->setTransform(rotationMatrix);
00493 
00494         QList<QGraphicsItem *>::iterator end = itemList.end();
00495         for (item = itemList.begin(); item != end; ++item) {
00496             QRectF br = (*item)->boundingRect();
00497             QPolygonF bp = (*item)->mapToScene(br);
00498 
00499             if (MApplication::showBoundingRect()) {
00500                 if (!dynamic_cast<MApplicationPage *>(*item)) { // filter out page for clarity
00501                     painter->setOpacity(BoundingRectOpacity);
00502                     painter->setPen(d->boundingRectLinePen);
00503                     painter->setBrush(d->boundingRectFillBrush);
00504                     painter->drawPolygon(bp);
00505                 }
00506             }
00507 
00508             if (MApplication::showMargins()) {
00509                 // Draw content margins
00510                 QGraphicsLayoutItem *layoutItem = dynamic_cast<QGraphicsLayoutItem *>(*item);
00511                 if (layoutItem) {
00512                     qreal left, top, right, bottom;
00513                     layoutItem->getContentsMargins(&left, &top, &right, &bottom);
00514 
00515                     QRectF outerRect = (*item)->mapRectToScene(br.x(),br.y(), br.width(), br.height());
00516                     QRectF innerRect = outerRect.adjusted(left, top, -right, -bottom);
00517 
00518                     QRectF leftRect(outerRect.x(), outerRect.y(), innerRect.x() - outerRect.x(), outerRect.height());
00519                     QRectF topRect(innerRect.x(), outerRect.y(), innerRect.width(), innerRect.y() - outerRect.y());
00520                     QRectF rightRect(innerRect.bottomRight().x(), outerRect.y(), outerRect.bottomRight().x() - innerRect.bottomRight().x(), outerRect.height());
00521                     QRectF bottomRect(innerRect.x(), innerRect.bottomRight().y(), innerRect.width(), outerRect.bottomRight().y() - innerRect.bottomRight().y());
00522 
00523                     painter->setOpacity(0.5);
00524 
00525                     d->fillMarginRectWithPattern(painter, leftRect, leftRect.width());
00526                     d->fillMarginRectWithPattern(painter, topRect, topRect.height());
00527                     d->fillMarginRectWithPattern(painter, rightRect, rightRect.width());
00528                     d->fillMarginRectWithPattern(painter, bottomRect, bottomRect.height());
00529 
00530                 }
00531 
00532                 painter->setOpacity(1.0);
00533             }
00534 
00535             if (MApplication::showPosition()) {
00536                 QPointF topLeft = ((*item)->mapToScene(br.topLeft()));
00537                 QString posStr = QString("(%1, %2)").arg(topLeft.x()).arg(topLeft.y());
00538                 painter->setPen(Qt::black);
00539                 painter->drawText(topLeft += QPointF(5, fontHeight), posStr);
00540                 painter->setPen(Qt::white);
00541                 painter->drawText(topLeft -= QPointF(1, 1),  posStr);
00542             }
00543 
00544             if (MApplication::showSize()) {
00545                 QPointF bottomRight = ((*item)->mapToScene(br.bottomRight()));
00546                 QString sizeStr = QString("%1x%2").arg(br.width()).arg(br.height());
00547                 painter->setPen(Qt::black);
00548                 painter->drawText(bottomRight -= QPointF(metrics.width(sizeStr), 2), sizeStr);
00549                 painter->setPen(Qt::white);
00550                 painter->drawText(bottomRight -= QPointF(1, 1), sizeStr);
00551             }
00552 
00553             if (MApplication::showObjectNames()) {
00554                 QGraphicsWidget *widget = dynamic_cast<QGraphicsWidget *>(*item);
00555                 if (widget) {
00556                     QRectF boundingRect = bp.boundingRect();
00557                     QString name = widget->objectName();
00558                     QRect textBoundingRect = metrics.boundingRect(name);
00559                     QPointF center = boundingRect.topLeft();
00560                     center += QPointF((boundingRect.width() - textBoundingRect.width()) / 2, (boundingRect.height() - fontHeight) / 2);
00561                     painter->fillRect(textBoundingRect.translated(center.toPoint()), d->fpsBackgroundBrush);
00562                     painter->setPen(FpsTextColor);
00563                     painter->drawText(center, name);
00564                 }
00565             }
00566 
00567             if (MApplication::showStyleNames()) {
00568                 MWidgetController *widget = dynamic_cast<MWidgetController *>(*item);
00569                 if (widget) {
00570                     QRectF boundingRect = bp.boundingRect();
00571                     QString name = widget->styleName();
00572                     QRect textBoundingRect = metrics.boundingRect(name);
00573                     QPointF center = boundingRect.topLeft();
00574                     center += QPointF((boundingRect.width() - textBoundingRect.width()) / 2, (boundingRect.height() - fontHeight) / 2);
00575                     painter->fillRect(textBoundingRect.translated(center.toPoint()), d->fpsBackgroundBrush);
00576                     painter->setPen(FpsTextColor);
00577                     painter->drawText(center, name);
00578                 }
00579             }
00580         }
00581     }
00582 
00583     bool countingFps = MApplication::logFps() || MApplication::showFps();
00584     if (countingFps) {
00585         if (d->fps.frameCount < 0) {
00586             d->fps.time.restart();
00587             d->fps.frameCount = 0;
00588         }
00589         ++d->fps.frameCount;
00590 
00591         int ms = d->fps.time.elapsed();
00592         if (ms > FpsRefreshInterval) {
00593             float fps = d->fps.frameCount * 1000.0f / ms;
00594             d->fps.time.restart();
00595             d->fps.frameCount = 0;
00596             if (MApplication::logFps()) {
00597                 QTime time = d->fps.time.currentTime();
00598                 d->logFpsCounter(&time, fps);
00599             }
00600             d->fps.fps = fps;
00601         }
00602 
00603         if (MApplication::showFps()) {
00604             d->showFpsCounter(painter, d->fps.fps);
00605         }
00606 
00607         // this update call makes repainting work as fast
00608         // as possible, and by that prints useful fps numbers
00609         QTimer::singleShot(0, this, SLOT(update()));
00610     } else {
00611         d->fps.frameCount = -1;
00612     }
00613 
00614     if (MApplication::emulateTwoFingerGestures() &&
00615         d->pinchEmulationEnabled)
00616     {
00617         static const QPixmap *tapPixmap = MTheme::pixmap("meegotouch-tap");
00618         QPointF pixmapCenterDelta(tapPixmap->width() / 2, tapPixmap->height() / 2);
00619 
00620         painter->drawPixmap(d->emuPoint1.screenPos() - pixmapCenterDelta, *tapPixmap);
00621         painter->drawPixmap(d->emuPoint2.screenPos() - pixmapCenterDelta, *tapPixmap);
00622     }
00623 }

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