×
Namespaces

Variants
Actions
(Difference between revisions)

HttpRemote

From Nokia Developer Wiki
Jump to: navigation, search
axeljaeger (Talk | contribs)
(Add screenshots. How to make thumbnails?)
axeljaeger (Talk | contribs)
(Add code example for UI)
Line 17: Line 17:
  
 
To be able to draw the three channels above each other and mix the colors, a special composition mode has to be set in QPainter: QPainter::CompositionMode_Plus.  
 
To be able to draw the three channels above each other and mix the colors, a special composition mode has to be set in QPainter: QPainter::CompositionMode_Plus.  
 +
<code cpp>
 +
void ChannelButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 +
{
 +
    // Store current composition mode, brush and pen to be able to restore them. QPainter's native save/restore seem not to work for composition mode.
 +
    QPainter::CompositionMode old_mode(painter->compositionMode());
 +
    QPen old_pen(painter->pen());
 +
    QBrush old_brush(painter->brush());
 +
 +
    // Set special composition mode
 +
    painter->setCompositionMode(QPainter::CompositionMode_Plus);
 +
 +
    double offset(m_phase * 5);
 +
 +
    painter->setPen(QPen(Qt::NoPen));
 +
   
 +
    // Draw red channel
 +
    painter->save();
 +
    painter->setBrush(Qt::red);
 +
    painter->translate(QPointF(cos(M_PI * (m_angle + 15.0) / 180.0),
 +
                              sin(M_PI * (m_angle + 15.0) / 180.0)) * offset);
 +
    painter->drawPath(m_path);
 +
    painter->restore();
 +
 +
    // Draw green channel
 +
    painter->save();
 +
    painter->setBrush(Qt::green);
 +
    painter->translate(QPointF(cos(M_PI * (m_angle + 135.0) / 180.0),
 +
                              sin(M_PI * (m_angle + 135.0) / 180.0)) * offset);
 +
    painter->drawPath(m_path);
 +
    painter->restore();
 +
 +
    // Draw blue channel
 +
    painter->save();
 +
    painter->setBrush(Qt::blue);
 +
    painter->translate(QPointF(cos(M_PI * (m_angle + 285.0) / 180.0),
 +
                              sin(M_PI * (m_angle + 285.0) / 180.0)) * offset);
 +
    painter->drawPath(m_path);
 +
    painter->restore();
 +
 +
    // Restore previos painter configuration
 +
    painter->setPen(old_pen);
 +
    painter->setBrush(old_brush);
 +
    painter->setCompositionMode(old_mode);
 +
}
 +
</code>
 +
 
==Network handling==
 
==Network handling==
 
Originally developed to showcase the Qt Bearer Management Library, the example is meant to connect to a local network. To my surprise, I did not had to do anything but my phone automatically connected to the local network. Now the only thing that was needed was to issue QNetworkManager for the http-requests.  
 
Originally developed to showcase the Qt Bearer Management Library, the example is meant to connect to a local network. To my surprise, I did not had to do anything but my phone automatically connected to the local network. Now the only thing that was needed was to issue QNetworkManager for the http-requests.  

Revision as of 11:01, 1 April 2010

Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic, Nokia N97 mini
Compatibility
Platform(s): S60 5th Edition
Symbian
Article
Keywords: QPainter
Created: (30 Mar 2010)
Last edited: axeljaeger (01 Apr 2010)

Underconstruction.pngUnder Construction: This article is under construction and it may have outstanding issues. If you have any comments please use the comments tab.

Contents

Overview

This example show how to implement a custom QGraphicsWidget that uses not so common graphics operations. This widget is then used to trigger custom http-get-requests. Such GET-requests are commonly used by cheap embedded hardware to trigger a certain action. The usecase for this example is to remote control a media player by sending those requests when pressing on of the buttons.

Graphics

The idea behind the graphics is to show a remote that reminds the user of a situation related to media playback. Digital pictures are usually composed of three color channels: Red, Blue and Green. Other colors are mixed from these channels. If these channels are shifted in position, the user will see the three seperate channels. This UI is composed of white controlls on a dark background. But whenever the user presses a control, the color channels seperate, orbit around the center of the control and the vibra goes on to simulate the effect of a motor or other device.

To be able to draw the three channels above each other and mix the colors, a special composition mode has to be set in QPainter: QPainter::CompositionMode_Plus.

void ChannelButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// Store current composition mode, brush and pen to be able to restore them. QPainter's native save/restore seem not to work for composition mode.
QPainter::CompositionMode old_mode(painter->compositionMode());
QPen old_pen(painter->pen());
QBrush old_brush(painter->brush());
 
// Set special composition mode
painter->setCompositionMode(QPainter::CompositionMode_Plus);
 
double offset(m_phase * 5);
 
painter->setPen(QPen(Qt::NoPen));
 
// Draw red channel
painter->save();
painter->setBrush(Qt::red);
painter->translate(QPointF(cos(M_PI * (m_angle + 15.0) / 180.0),
sin(M_PI * (m_angle + 15.0) / 180.0)) * offset);
painter->drawPath(m_path);
painter->restore();
 
// Draw green channel
painter->save();
painter->setBrush(Qt::green);
painter->translate(QPointF(cos(M_PI * (m_angle + 135.0) / 180.0),
sin(M_PI * (m_angle + 135.0) / 180.0)) * offset);
painter->drawPath(m_path);
painter->restore();
 
// Draw blue channel
painter->save();
painter->setBrush(Qt::blue);
painter->translate(QPointF(cos(M_PI * (m_angle + 285.0) / 180.0),
sin(M_PI * (m_angle + 285.0) / 180.0)) * offset);
painter->drawPath(m_path);
painter->restore();
 
// Restore previos painter configuration
painter->setPen(old_pen);
painter->setBrush(old_brush);
painter->setCompositionMode(old_mode);
}

Network handling

Originally developed to showcase the Qt Bearer Management Library, the example is meant to connect to a local network. To my surprise, I did not had to do anything but my phone automatically connected to the local network. Now the only thing that was needed was to issue QNetworkManager for the http-requests.

Screenshots

Idle
Button pressed

Keep in mind that the screenshot shows only one frame of the animation of the actual running application.

Testing the application

The example is either be meant to be compiled directly for the device or as a desktop application.

Download Code Example

102 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×