SlideShare a Scribd company logo
1 of 83
Download to read offline
Copy Your Favorite Nokia Apps
                                09/25/09
Ariya Hidayat
Agenda

• Mobile platform challenges:
  – differences vs desktop
  – things to keep in mind
• Examples which demonstrate:
  – Low-level painting
  – Graphics View
  – Network and web stack




                                2
Spread the Love

        All examples are available from...




             labs.qt.nokia.com


            bit.ly/graphicsdojo




                                             3
Desktop vs Mobile Platforms

• Hardware power
• Screen size and resolutions
• Input method
• Network access




                                4
Nokia N95

• CPU: 332 MHz ARM11
• RAM: 128 MB
• Screen: 240 x 320 (QVGA)
• 9-Button keypad




                             5
Nokia E71

• CPU: 369 MHz ARM11
• RAM: 128 MB
• Screen: 320x240 (QVGA)
• Full QWERTY Keypad




                           6
Nokia 5800 XpressMusic

• CPU: 434 MHz ARM11
• RAM: 128 MB
• Screen: 360 x 640 (nHD)
• Touch interface




                            7
Processing Power

• ARM architecture
   – Different than x86
• Limited memory




                          8
Graphics Power

• Lower resolution
• Software rendering
   – hardware acceleration with OpenGL ES
• Font metrics




                                            9
Input Methods

• Keypad, not keyboard
  – often not full QWERTY
• No mouse
   – don't bother with mouse move event
• Touch interface
   – single vs multitouch
   – stylus vs finger
• Sensors: accelerometer, GPS, compass, ...


                                              10
Network Access

• Wireless LAN
  – sometimes not available
• Other data access
  – slower data rate




                              11
Development Flow

• Device emulator
• Remote debugging
• Performance test
• Profiling tools




                     12
Example #1
Digital Clock
Digital (Vintage) Clock




                          14
Framed Digits

      plain digits   with frame




                          gradient




                                     15
Gradient is Expensive, so...
QLinearGradient gr(QPoint(0, 0), QPoint(0, height));
gr.setColorAt(0.00, QColor(128, 128, 128));
gr.setColorAt(0.49, QColor(64, 64, 64));
gr.setColorAt(0.51, QColor(128, 128, 128));
gr.setColorAt(1.00, QColor(16, 16, 16));

QPainter p;                  Cache to a
p.begin(&pixmap);
                              pixmap
p.setFont(font);
QPen pen;
pen.setBrush(QBrush(gr));
p.setPen(pen);
p.drawText(pixmap.rect(), Qt::AlignCenter, str);
p.end();




                                                       16
Sliding Effect




            translating both pixmaps



                                       17
Sliding Effect: The Code
QPainter p(this);
int y = height() * currentFrame / 100;
p.drawPixmap(0, y, m_lastPixmap);
p.drawPixmap(0, y - height(), m_pixmap);
p.end();




                                           18
Rotation

           transform.rotate(30, Qt::ZAxis)




                                             19
Perspective Transformation



transform.rotate
(60, Qt::XAxis)




                   transform.rotate(60, Qt::YAxis)


                                                     20
Rotating Effect




              rotating pixmaps



                                 21
Rotating Effect: The Code
QTransform transform;
transform.translate(width() / 2, height() / 2);
transform.rotate(angle, Qt::XAxis);

QPainter p(this);
p.setTransform(transform);
p.drawPixmap(-width() / 2, -height() / 2, pixmap);
p.end();




                                                     22
Flipping Effect




            rotating and interleaving
                  two pixmaps

                                        23
A Trick with QBasicTimer
QBasicTimer ticker;
ticker.start(1000, this);

void timerEvent(QTimerEvent*)
{
  // update the clock
}




             No need for QTimer, a slot, and
            periodic triggering of signal/slot !



                                                   24
QTimeLine for Frame-based Animation
QTimeLine animator;
animator.setFrameRange(0, 100);
animator.setDuration(600);
animator.setCurveShape(QTimeLine::EaseInOutCurve);

int progress = animator.currentFrame();


            Linear        EaseInOut
                                                 deacceleration




                                      acceleration

                                                              25
Sacrifice Quality for Speed

       Beauty is in the eye of the beholder.




                                               26
Aliasing during Animation
QPainter p(this);
p.setRenderHint(QPainter::SmoothPixmapTransform, false);
p.setRenderHint(QPainter::Antialiasing, false);




                                                           27
Example #2
Weather Info
Weather Info




               29
Screen Orientation




       requires different layout strategy




                                            30
Lock the Orientation

                           S60-specific, usually you do
                              NOT need to do this!
#include   <eikenv.h>
#include   <eikappui.h>
#include   <aknenv.h>
#include   <aknappui.h>

CAknAppUi* appUi = dynamic_cast<CAknAppUi*>
  (CEikonEnv::Static()->AppUi());
appUi->SetOrientationL
  (CAknAppUi::EAppUiOrientationPortrait);




                                                          31
Animation with Graphics View


                          item movement &
                               opacity




                                            32
Using Web Service
<weather>
<forecast_information>
  <city data="Oslo, Oslo"/>
  <postal_code data="Oslo"/>
  <latitude_e6 data=""/><longitude_e6 data=""/>
  <forecast_date data="2009-09-15"/>
  <current_date_time data="2009-09-15 13:40:00 +0000"/>
  <unit_system data="US"/>
</forecast_information>
<current_conditions>
  <condition data="Clear"/>
  <temp_f data="61"/><temp_c data="16"/>
  <humidity data="Humidity: 55%"/>
  <icon data="/ig/images/weather/sunny.gif"/>
  <wind_condition data="Wind: S at 12 mph"/>
</current_conditions>
<forecast_conditions>
...



                                                          33
Create the Network Request
     http://www.google.com/ig/api?hl=en&weather=oslo

QUrl url("http://www.google.com/ig/api");
url.addEncodedQueryItem("hl", "en");
url.addEncodedQueryItem("weather",
  QUrl::toPercentEncoding(location));

QNetworkAccessManager *manager;
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
  this,SLOT(handleNetworkData(QNetworkReply*)));

manager->get(QNetworkRequest(url));




                                                       34
Handle the Network Reply
     http://www.google.com/ig/api?hl=en&weather=oslo

QUrl url = networkReply->url();
data = QString::fromUtf8(networkReply->readAll());
networkReply->deleteLater();
networkReply->manager()->deleteLater();




                                                       35
XML Stream Reader for Parsing


QXmlStreamReader xml(data);
while (!xml.atEnd()) {
  xml.readNext();
  if (xml.tokenType() == QXmlStreamReader::StartElement)
    if (xml.name() == "city")
      city = xml.attributes().value("data").toString()
}




        faster and requires less memory than
                    using QDom!


                                                           36
Scalable Icons with SVG

             bitmap vs vector




                                37
Optimize Your SVG
<g>
      <ellipse cx="10" cy="10" rx=2" ry="2"/>
</g>




<ellipse cx="10" cy="10" rx=2" ry="2"/>



           Because one element in a group often
                  does not make sense!



                                                  38
SVG Loading Time Comparison




             Use tools like:
           codedread.com/scour
          svgmin.googlecode.com


                                  39
Example #3
Flight Tracking
Flight Tracking




                  41
No Web Service?
      Use “mobile” version of the web site.




                                              42
Web Scraping

• Grab the HTML contents
• Scrap it
   – remove unnecessary clutters
   – parse and extract the interesting bits
• Legal aspect
   – some sites explicitly prohibit the use other than
     in a web browser




                                                         43
Parsing HTML with XML Stream Reader

• HTML != XML
• Potentially provoke the parser (→ errors)
  – Solution: “scrub it”, i.e. clean up the raw HTML


// remove all inline frames
while (true) {
    i = data.indexOf("<iframe");
    if (i < 0)
        break;
    data.remove(i, data.indexOf("</iframe>") - i + 8);
}




                                                         44
The Usual Tricks

• Use network request and reply
• Contents
   – Construct the request
   – Get the HTML data
   – Clean it up and then parse it
• Flight map
   – Construct the request
   – Get data and feed it to a QPixmap
   – Display the pixmap, e.g. with QLabel


                                            45
Beware of Different Font Metrics




                                   46
Example #4
Magnifying Glass
Image Zoom




             48
Shadow with Radial Gradient




                              magnifier




                                          49
Shadow with Radial Gradient
 Prepare the gradient brush
QRadialGradient g;
g.setCenter(radius, radius);
g.setFocalPoint(radius, radius);
g.setRadius(radius);
g.setColorAt(1.0, QColor(255, 255, 255, 0));
g.setColorAt(0.5, QColor(128, 128, 128, 255));

 Draw the shadow
p.setCompositionMode (QPainter::CompositionMode_Source);
p.setBrush(g);
p.drawRect(maskPixmap.rect());
 Carve the “hole”
p.setBrush(QColor(Qt::transparent));
p.drawEllipse(g.center(), radius-15, radius-15);




                                                           50
Panning with Mouse/Finger/Stylus
                 Record the tap position
void mousePressEvent(QMouseEvent *event) {
    if (event->buttons() != Qt::LeftButton)
        return;
    pressed = true;
    pressPos = dragPos = event->pos();
}


          Pan the map based on the movement
void mouseMoveEvent(QMouseEvent *event) {
    if (!event->buttons())
        return;
    QPoint delta = event->pos() - pressPos;
    pressPos = event->pos();
    pan(delta);
}



                                              51
Avoid Accidental Panning




   panning is not started   past the threshold




                                                 52
Turbo Downscaling (We're Cheating!)




     With filtering



                        Fast, no filtering



                      Up to 200x faster,
        see http://bit.ly/cheatscale for details!
                                                    53
Example #5
  Maps
Maps (with OpenStreetMap)




                            55
OpenStreetMap vs [Google,Yahoo]Maps

• Free content
   – Creative Commons Attribution-ShareAlike 2.0
• API does not require the license key
• Available in
   – rendered images
   – vector data



More info at www.openstreetmap.org !


                                                   56
Getting the Rendered Tiles

• Each tile is 256 x 256 pixels
• Zoom level of 0 → the whole world
• Zoom level of 17 → most detailed

QPointF tileForCoordinate(qreal lat, qreal lng, int zoom)
{
    qreal zn = static_cast<qreal>(1 << zoom);
    qreal tx = (lng + 180.0) / 360.0;
    qreal ty = (1.0 - log(tan(lat * M_PI / 180.0) +
               1.0 / cos(lat * M_PI / 180.0)) / M_PI)
               / 2.0;
    return QPointF(tx * zn, ty * zn);
}



                                                            57
Rendering and Caching Strategy




          cached tiles   application window
                                              58
Avoid Accidental Panning




   panning is not started   past the threshold




                                                 59
Night Mode




             60
Night Mode: The Code
                 Color channel inversion

QPainter p(this);
p.setCompositionMode
  (QPainter::CompositionMode_Difference);
p.fillRect(event->rect(), Qt::white);
p.end();


                     red = 255 – red
                  green = 255 – green
                    blue = 255 - blue




                                            61
Example #6
Kinetic Scrolling
Kinetic Scrolling




                    63
State Machine for Scrolling

                                              Mouse move
 Mouse press             Pressed

                                              Manual Scroll
                Mouse release
  Steady                                  Mouse release

                     Mouse
                     move                      Auto Scroll
Mouse release                   Mouse press
                     Stop
                                                   Timer tick


                                                                64
Example #7
Parallax Sliding
Parallax Sliding




                   66
Slow-moving Background




         1               5
             2       4
                 3
                             67
Example #8
Web Technologies
Web Browser

• QtWebKit:
  – Standard compliant, fast rendering engine
  – Used in Apple Safari, Google Chrome, …
  – S60 Browser, Apple iPhone, Google Android,
    Palm WebOS, …
• Use QWebView and you are done!
• Add flick support for kinetic scrolling




                                                 69
Google Chat Client




                     70
We Cheat (Again)!

• Use QWebView from QtWebKit
• Show the “mobile” version
• Add custom login page




                               71
Example #9
Unfinished Mini-game
Ray Casting




              73
Made Popular in (DOS) Wolfenstein 3-D

• A single ray is traced for every column
• Grid-based world, uniform height → fast




                                            74
Shading Trick




                75
Direct Screen Blit

          Don't bother “clearing” the widget!
setAttribute(Qt::WA_OpaquePaintEvent, true);




          Faster direct screen access using
              CDirectScreenBitmap or
                  Anti-Tearing API




                                                76
Bypass Alpha-Blending
       Since we handle each and every pixel, ...

QPainter p(this);
p.setCompositionMode(QPainter::Composition_Source)
p.drawImage(0, 0, buffer);




                                                     77
Storing Pixels in Image




                          78
Memory Access Optimization
        Minimize location (in memory) between
            two vertically separated pixels




     Jump several                    Jump few
    hundreds bytes                   bytes only

                                                  79
Inner Loop Approach
      Use only simple, 12-bits fixed-point arithmetics

while (y1 >= 0 && y2 < bufh && p1 >= 0) {
    *pixel1 = tex[p1 >> 12];
    *pixel2 = tex[p2 >> 12];
    p1 -= dy;
    p2 += dy;
    --y1;
    ++y2;
    pixel1 -= stride;
    pixel2 += stride;
}




                                                         80
Conclusion



      Mobile application development
              with Qt is FUN




                                       81
That's all, folks...




        Thank You!


                       82
Bleeding-Edge




           labs.qt.nokia.com


           bit.ly/graphicsdojo




                                 83

More Related Content

What's hot

Using Multi-Touch and Gestures with Qt
Using Multi-Touch and Gestures with QtUsing Multi-Touch and Gestures with Qt
Using Multi-Touch and Gestures with Qtaccount inactive
 
Qt State Machine Framework
Qt State Machine FrameworkQt State Machine Framework
Qt State Machine Frameworkaccount inactive
 
Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)vitalipe
 
Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1NokiaAppForum
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and GraphicsAndreas Jakl
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2NokiaAppForum
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentICS
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? ICS
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threadsYnon Perek
 
The Next Generation Qt Item Views
The Next Generation Qt Item ViewsThe Next Generation Qt Item Views
The Next Generation Qt Item Viewsaccount inactive
 
Best Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IBest Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IICS
 
Advanced Scenegraph Rendering Pipeline
Advanced Scenegraph Rendering PipelineAdvanced Scenegraph Rendering Pipeline
Advanced Scenegraph Rendering PipelineNarann29
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickICS
 
Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well Mark Kilgard
 
A Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkA Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkZachary Blair
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Johan Thelin
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016Mark Kilgard
 

What's hot (20)

Using Multi-Touch and Gestures with Qt
Using Multi-Touch and Gestures with QtUsing Multi-Touch and Gestures with Qt
Using Multi-Touch and Gestures with Qt
 
Qt Widget In-Depth
Qt Widget In-DepthQt Widget In-Depth
Qt Widget In-Depth
 
Qt State Machine Framework
Qt State Machine FrameworkQt State Machine Framework
Qt State Machine Framework
 
Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)
 
Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI development
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
 
The Next Generation Qt Item Views
The Next Generation Qt Item ViewsThe Next Generation Qt Item Views
The Next Generation Qt Item Views
 
Best Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IBest Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part I
 
Advanced Scenegraph Rendering Pipeline
Advanced Scenegraph Rendering PipelineAdvanced Scenegraph Rendering Pipeline
Advanced Scenegraph Rendering Pipeline
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt Quick
 
Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well
 
OpenGL for 2015
OpenGL for 2015OpenGL for 2015
OpenGL for 2015
 
A Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkA Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application Framework
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016
 
Qt Workshop
Qt WorkshopQt Workshop
Qt Workshop
 

Similar to Copy Your Favourite Nokia App with Qt

Snake Game on FPGA in Verilog
Snake Game on FPGA in VerilogSnake Game on FPGA in Verilog
Snake Game on FPGA in VerilogKrishnajith S S
 
Drawing with Quartz on iOS
Drawing with Quartz on iOSDrawing with Quartz on iOS
Drawing with Quartz on iOSBob McCune
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billynimbleltd
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicsamitsarda3
 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Chris Ramsdale
 
INAC Online Hazards Database App
INAC Online Hazards Database AppINAC Online Hazards Database App
INAC Online Hazards Database AppGerry James
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer GraphicsAdri Jovin
 
Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphicsLOKESH KUMAR
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer ToolsMark Billinghurst
 
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG
JavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVGJavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVG
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVGPatrick Chanezon
 
Google Developer Fest 2010
Google Developer Fest 2010Google Developer Fest 2010
Google Developer Fest 2010Chris Ramsdale
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35Bilal Ahmed
 
Witekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio
 
Android RenderScript on LLVM
Android RenderScript on LLVMAndroid RenderScript on LLVM
Android RenderScript on LLVMJohn Lee
 
Megamodeling of Complex, Distributed, Heterogeneous CPS Systems
Megamodeling of Complex, Distributed, Heterogeneous CPS SystemsMegamodeling of Complex, Distributed, Heterogeneous CPS Systems
Megamodeling of Complex, Distributed, Heterogeneous CPS SystemsEugenio Villar
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Patrick Chanezon
 

Similar to Copy Your Favourite Nokia App with Qt (20)

Snake Game on FPGA in Verilog
Snake Game on FPGA in VerilogSnake Game on FPGA in Verilog
Snake Game on FPGA in Verilog
 
Drawing with Quartz on iOS
Drawing with Quartz on iOSDrawing with Quartz on iOS
Drawing with Quartz on iOS
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billy
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010
 
Qt Programming on TI Processors
Qt Programming on TI ProcessorsQt Programming on TI Processors
Qt Programming on TI Processors
 
INAC Online Hazards Database App
INAC Online Hazards Database AppINAC Online Hazards Database App
INAC Online Hazards Database App
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphics
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools
 
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG
JavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVGJavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVG
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG
 
Google Developer Fest 2010
Google Developer Fest 2010Google Developer Fest 2010
Google Developer Fest 2010
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35
 
Witekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio custom modern qt quick components
Witekio custom modern qt quick components
 
The Future of Qt Widgets
The Future of Qt WidgetsThe Future of Qt Widgets
The Future of Qt Widgets
 
Android RenderScript on LLVM
Android RenderScript on LLVMAndroid RenderScript on LLVM
Android RenderScript on LLVM
 
Chapter-3.pdf
Chapter-3.pdfChapter-3.pdf
Chapter-3.pdf
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Megamodeling of Complex, Distributed, Heterogeneous CPS Systems
Megamodeling of Complex, Distributed, Heterogeneous CPS SystemsMegamodeling of Complex, Distributed, Heterogeneous CPS Systems
Megamodeling of Complex, Distributed, Heterogeneous CPS Systems
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
 

More from account inactive

KDE Plasma for Mobile Phones
KDE Plasma for Mobile PhonesKDE Plasma for Mobile Phones
KDE Plasma for Mobile Phonesaccount inactive
 
Shipping Mobile Applications Using Qt for Symbian
Shipping Mobile Applications Using Qt for SymbianShipping Mobile Applications Using Qt for Symbian
Shipping Mobile Applications Using Qt for Symbianaccount inactive
 
Developments in The Qt WebKit Integration
Developments in The Qt WebKit IntegrationDevelopments in The Qt WebKit Integration
Developments in The Qt WebKit Integrationaccount inactive
 
Development with Qt for Windows CE
Development with Qt for Windows CEDevelopment with Qt for Windows CE
Development with Qt for Windows CEaccount inactive
 
Translating Qt Applications
Translating Qt ApplicationsTranslating Qt Applications
Translating Qt Applicationsaccount inactive
 
Mobile Development with Qt for Symbian
Mobile Development with Qt for SymbianMobile Development with Qt for Symbian
Mobile Development with Qt for Symbianaccount inactive
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Nativeaccount inactive
 
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)account inactive
 
Optimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based ApplicationsOptimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based Applicationsaccount inactive
 
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization SoftwareCase Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Softwareaccount inactive
 
Case Study: Porting Qt for Embedded Linux on Embedded Processors
Case Study: Porting Qt for Embedded Linux on Embedded ProcessorsCase Study: Porting Qt for Embedded Linux on Embedded Processors
Case Study: Porting Qt for Embedded Linux on Embedded Processorsaccount inactive
 
OGRE: Qt & OGRE for Multimedia Creation
OGRE: Qt & OGRE for Multimedia CreationOGRE: Qt & OGRE for Multimedia Creation
OGRE: Qt & OGRE for Multimedia Creationaccount inactive
 
HGZ Kaffeemaschinen & Qt Speak Coffee
HGZ Kaffeemaschinen & Qt Speak CoffeeHGZ Kaffeemaschinen & Qt Speak Coffee
HGZ Kaffeemaschinen & Qt Speak Coffeeaccount inactive
 
Discover Qt Learning and Certification
Discover Qt Learning and CertificationDiscover Qt Learning and Certification
Discover Qt Learning and Certificationaccount inactive
 
Accelerating performance on Qt and WebKit for the MIPS architecture
Accelerating performance on Qt and WebKit for the MIPS architectureAccelerating performance on Qt and WebKit for the MIPS architecture
Accelerating performance on Qt and WebKit for the MIPS architectureaccount inactive
 

More from account inactive (20)

Meet Qt
Meet QtMeet Qt
Meet Qt
 
KDE Plasma for Mobile Phones
KDE Plasma for Mobile PhonesKDE Plasma for Mobile Phones
KDE Plasma for Mobile Phones
 
Shipping Mobile Applications Using Qt for Symbian
Shipping Mobile Applications Using Qt for SymbianShipping Mobile Applications Using Qt for Symbian
Shipping Mobile Applications Using Qt for Symbian
 
Developments in The Qt WebKit Integration
Developments in The Qt WebKit IntegrationDevelopments in The Qt WebKit Integration
Developments in The Qt WebKit Integration
 
Qt Kwan-Do
Qt Kwan-DoQt Kwan-Do
Qt Kwan-Do
 
Development with Qt for Windows CE
Development with Qt for Windows CEDevelopment with Qt for Windows CE
Development with Qt for Windows CE
 
Translating Qt Applications
Translating Qt ApplicationsTranslating Qt Applications
Translating Qt Applications
 
Qt Creator Bootcamp
Qt Creator BootcampQt Creator Bootcamp
Qt Creator Bootcamp
 
Mobile Development with Qt for Symbian
Mobile Development with Qt for SymbianMobile Development with Qt for Symbian
Mobile Development with Qt for Symbian
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Native
 
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
 
The Mobility Project
The Mobility ProjectThe Mobility Project
The Mobility Project
 
Optimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based ApplicationsOptimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based Applications
 
Qt Licensing Explained
Qt Licensing ExplainedQt Licensing Explained
Qt Licensing Explained
 
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization SoftwareCase Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
 
Case Study: Porting Qt for Embedded Linux on Embedded Processors
Case Study: Porting Qt for Embedded Linux on Embedded ProcessorsCase Study: Porting Qt for Embedded Linux on Embedded Processors
Case Study: Porting Qt for Embedded Linux on Embedded Processors
 
OGRE: Qt & OGRE for Multimedia Creation
OGRE: Qt & OGRE for Multimedia CreationOGRE: Qt & OGRE for Multimedia Creation
OGRE: Qt & OGRE for Multimedia Creation
 
HGZ Kaffeemaschinen & Qt Speak Coffee
HGZ Kaffeemaschinen & Qt Speak CoffeeHGZ Kaffeemaschinen & Qt Speak Coffee
HGZ Kaffeemaschinen & Qt Speak Coffee
 
Discover Qt Learning and Certification
Discover Qt Learning and CertificationDiscover Qt Learning and Certification
Discover Qt Learning and Certification
 
Accelerating performance on Qt and WebKit for the MIPS architecture
Accelerating performance on Qt and WebKit for the MIPS architectureAccelerating performance on Qt and WebKit for the MIPS architecture
Accelerating performance on Qt and WebKit for the MIPS architecture
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Copy Your Favourite Nokia App with Qt

  • 1. Copy Your Favorite Nokia Apps 09/25/09 Ariya Hidayat
  • 2. Agenda • Mobile platform challenges: – differences vs desktop – things to keep in mind • Examples which demonstrate: – Low-level painting – Graphics View – Network and web stack 2
  • 3. Spread the Love All examples are available from... labs.qt.nokia.com bit.ly/graphicsdojo 3
  • 4. Desktop vs Mobile Platforms • Hardware power • Screen size and resolutions • Input method • Network access 4
  • 5. Nokia N95 • CPU: 332 MHz ARM11 • RAM: 128 MB • Screen: 240 x 320 (QVGA) • 9-Button keypad 5
  • 6. Nokia E71 • CPU: 369 MHz ARM11 • RAM: 128 MB • Screen: 320x240 (QVGA) • Full QWERTY Keypad 6
  • 7. Nokia 5800 XpressMusic • CPU: 434 MHz ARM11 • RAM: 128 MB • Screen: 360 x 640 (nHD) • Touch interface 7
  • 8. Processing Power • ARM architecture – Different than x86 • Limited memory 8
  • 9. Graphics Power • Lower resolution • Software rendering – hardware acceleration with OpenGL ES • Font metrics 9
  • 10. Input Methods • Keypad, not keyboard – often not full QWERTY • No mouse – don't bother with mouse move event • Touch interface – single vs multitouch – stylus vs finger • Sensors: accelerometer, GPS, compass, ... 10
  • 11. Network Access • Wireless LAN – sometimes not available • Other data access – slower data rate 11
  • 12. Development Flow • Device emulator • Remote debugging • Performance test • Profiling tools 12
  • 15. Framed Digits plain digits with frame gradient 15
  • 16. Gradient is Expensive, so... QLinearGradient gr(QPoint(0, 0), QPoint(0, height)); gr.setColorAt(0.00, QColor(128, 128, 128)); gr.setColorAt(0.49, QColor(64, 64, 64)); gr.setColorAt(0.51, QColor(128, 128, 128)); gr.setColorAt(1.00, QColor(16, 16, 16)); QPainter p; Cache to a p.begin(&pixmap); pixmap p.setFont(font); QPen pen; pen.setBrush(QBrush(gr)); p.setPen(pen); p.drawText(pixmap.rect(), Qt::AlignCenter, str); p.end(); 16
  • 17. Sliding Effect translating both pixmaps 17
  • 18. Sliding Effect: The Code QPainter p(this); int y = height() * currentFrame / 100; p.drawPixmap(0, y, m_lastPixmap); p.drawPixmap(0, y - height(), m_pixmap); p.end(); 18
  • 19. Rotation transform.rotate(30, Qt::ZAxis) 19
  • 21. Rotating Effect rotating pixmaps 21
  • 22. Rotating Effect: The Code QTransform transform; transform.translate(width() / 2, height() / 2); transform.rotate(angle, Qt::XAxis); QPainter p(this); p.setTransform(transform); p.drawPixmap(-width() / 2, -height() / 2, pixmap); p.end(); 22
  • 23. Flipping Effect rotating and interleaving two pixmaps 23
  • 24. A Trick with QBasicTimer QBasicTimer ticker; ticker.start(1000, this); void timerEvent(QTimerEvent*) { // update the clock } No need for QTimer, a slot, and periodic triggering of signal/slot ! 24
  • 25. QTimeLine for Frame-based Animation QTimeLine animator; animator.setFrameRange(0, 100); animator.setDuration(600); animator.setCurveShape(QTimeLine::EaseInOutCurve); int progress = animator.currentFrame(); Linear EaseInOut deacceleration acceleration 25
  • 26. Sacrifice Quality for Speed Beauty is in the eye of the beholder. 26
  • 27. Aliasing during Animation QPainter p(this); p.setRenderHint(QPainter::SmoothPixmapTransform, false); p.setRenderHint(QPainter::Antialiasing, false); 27
  • 30. Screen Orientation requires different layout strategy 30
  • 31. Lock the Orientation S60-specific, usually you do NOT need to do this! #include <eikenv.h> #include <eikappui.h> #include <aknenv.h> #include <aknappui.h> CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi()); appUi->SetOrientationL (CAknAppUi::EAppUiOrientationPortrait); 31
  • 32. Animation with Graphics View item movement & opacity 32
  • 33. Using Web Service <weather> <forecast_information> <city data="Oslo, Oslo"/> <postal_code data="Oslo"/> <latitude_e6 data=""/><longitude_e6 data=""/> <forecast_date data="2009-09-15"/> <current_date_time data="2009-09-15 13:40:00 +0000"/> <unit_system data="US"/> </forecast_information> <current_conditions> <condition data="Clear"/> <temp_f data="61"/><temp_c data="16"/> <humidity data="Humidity: 55%"/> <icon data="/ig/images/weather/sunny.gif"/> <wind_condition data="Wind: S at 12 mph"/> </current_conditions> <forecast_conditions> ... 33
  • 34. Create the Network Request http://www.google.com/ig/api?hl=en&weather=oslo QUrl url("http://www.google.com/ig/api"); url.addEncodedQueryItem("hl", "en"); url.addEncodedQueryItem("weather", QUrl::toPercentEncoding(location)); QNetworkAccessManager *manager; manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)), this,SLOT(handleNetworkData(QNetworkReply*))); manager->get(QNetworkRequest(url)); 34
  • 35. Handle the Network Reply http://www.google.com/ig/api?hl=en&weather=oslo QUrl url = networkReply->url(); data = QString::fromUtf8(networkReply->readAll()); networkReply->deleteLater(); networkReply->manager()->deleteLater(); 35
  • 36. XML Stream Reader for Parsing QXmlStreamReader xml(data); while (!xml.atEnd()) { xml.readNext(); if (xml.tokenType() == QXmlStreamReader::StartElement) if (xml.name() == "city") city = xml.attributes().value("data").toString() } faster and requires less memory than using QDom! 36
  • 37. Scalable Icons with SVG bitmap vs vector 37
  • 38. Optimize Your SVG <g> <ellipse cx="10" cy="10" rx=2" ry="2"/> </g> <ellipse cx="10" cy="10" rx=2" ry="2"/> Because one element in a group often does not make sense! 38
  • 39. SVG Loading Time Comparison Use tools like: codedread.com/scour svgmin.googlecode.com 39
  • 42. No Web Service? Use “mobile” version of the web site. 42
  • 43. Web Scraping • Grab the HTML contents • Scrap it – remove unnecessary clutters – parse and extract the interesting bits • Legal aspect – some sites explicitly prohibit the use other than in a web browser 43
  • 44. Parsing HTML with XML Stream Reader • HTML != XML • Potentially provoke the parser (→ errors) – Solution: “scrub it”, i.e. clean up the raw HTML // remove all inline frames while (true) { i = data.indexOf("<iframe"); if (i < 0) break; data.remove(i, data.indexOf("</iframe>") - i + 8); } 44
  • 45. The Usual Tricks • Use network request and reply • Contents – Construct the request – Get the HTML data – Clean it up and then parse it • Flight map – Construct the request – Get data and feed it to a QPixmap – Display the pixmap, e.g. with QLabel 45
  • 46. Beware of Different Font Metrics 46
  • 49. Shadow with Radial Gradient magnifier 49
  • 50. Shadow with Radial Gradient Prepare the gradient brush QRadialGradient g; g.setCenter(radius, radius); g.setFocalPoint(radius, radius); g.setRadius(radius); g.setColorAt(1.0, QColor(255, 255, 255, 0)); g.setColorAt(0.5, QColor(128, 128, 128, 255)); Draw the shadow p.setCompositionMode (QPainter::CompositionMode_Source); p.setBrush(g); p.drawRect(maskPixmap.rect()); Carve the “hole” p.setBrush(QColor(Qt::transparent)); p.drawEllipse(g.center(), radius-15, radius-15); 50
  • 51. Panning with Mouse/Finger/Stylus Record the tap position void mousePressEvent(QMouseEvent *event) { if (event->buttons() != Qt::LeftButton) return; pressed = true; pressPos = dragPos = event->pos(); } Pan the map based on the movement void mouseMoveEvent(QMouseEvent *event) { if (!event->buttons()) return; QPoint delta = event->pos() - pressPos; pressPos = event->pos(); pan(delta); } 51
  • 52. Avoid Accidental Panning panning is not started past the threshold 52
  • 53. Turbo Downscaling (We're Cheating!) With filtering Fast, no filtering Up to 200x faster, see http://bit.ly/cheatscale for details! 53
  • 54. Example #5 Maps
  • 56. OpenStreetMap vs [Google,Yahoo]Maps • Free content – Creative Commons Attribution-ShareAlike 2.0 • API does not require the license key • Available in – rendered images – vector data More info at www.openstreetmap.org ! 56
  • 57. Getting the Rendered Tiles • Each tile is 256 x 256 pixels • Zoom level of 0 → the whole world • Zoom level of 17 → most detailed QPointF tileForCoordinate(qreal lat, qreal lng, int zoom) { qreal zn = static_cast<qreal>(1 << zoom); qreal tx = (lng + 180.0) / 360.0; qreal ty = (1.0 - log(tan(lat * M_PI / 180.0) + 1.0 / cos(lat * M_PI / 180.0)) / M_PI) / 2.0; return QPointF(tx * zn, ty * zn); } 57
  • 58. Rendering and Caching Strategy cached tiles application window 58
  • 59. Avoid Accidental Panning panning is not started past the threshold 59
  • 61. Night Mode: The Code Color channel inversion QPainter p(this); p.setCompositionMode (QPainter::CompositionMode_Difference); p.fillRect(event->rect(), Qt::white); p.end(); red = 255 – red green = 255 – green blue = 255 - blue 61
  • 64. State Machine for Scrolling Mouse move Mouse press Pressed Manual Scroll Mouse release Steady Mouse release Mouse move Auto Scroll Mouse release Mouse press Stop Timer tick 64
  • 67. Slow-moving Background 1 5 2 4 3 67
  • 69. Web Browser • QtWebKit: – Standard compliant, fast rendering engine – Used in Apple Safari, Google Chrome, … – S60 Browser, Apple iPhone, Google Android, Palm WebOS, … • Use QWebView and you are done! • Add flick support for kinetic scrolling 69
  • 71. We Cheat (Again)! • Use QWebView from QtWebKit • Show the “mobile” version • Add custom login page 71
  • 74. Made Popular in (DOS) Wolfenstein 3-D • A single ray is traced for every column • Grid-based world, uniform height → fast 74
  • 76. Direct Screen Blit Don't bother “clearing” the widget! setAttribute(Qt::WA_OpaquePaintEvent, true); Faster direct screen access using CDirectScreenBitmap or Anti-Tearing API 76
  • 77. Bypass Alpha-Blending Since we handle each and every pixel, ... QPainter p(this); p.setCompositionMode(QPainter::Composition_Source) p.drawImage(0, 0, buffer); 77
  • 78. Storing Pixels in Image 78
  • 79. Memory Access Optimization Minimize location (in memory) between two vertically separated pixels Jump several Jump few hundreds bytes bytes only 79
  • 80. Inner Loop Approach Use only simple, 12-bits fixed-point arithmetics while (y1 >= 0 && y2 < bufh && p1 >= 0) { *pixel1 = tex[p1 >> 12]; *pixel2 = tex[p2 >> 12]; p1 -= dy; p2 += dy; --y1; ++y2; pixel1 -= stride; pixel2 += stride; } 80
  • 81. Conclusion Mobile application development with Qt is FUN 81
  • 82. That's all, folks... Thank You! 82
  • 83. Bleeding-Edge labs.qt.nokia.com bit.ly/graphicsdojo 83