homescreenapp/examples/localisedhellowidgetplugin/src/localisedhellowidget.cpp
branchRCL_3
changeset 82 5f0182e07bfb
equal deleted inserted replaced
79:f00a6757af32 82:5f0182e07bfb
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Example of home screen widget
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QGraphicsLinearLayout>
       
    19 #include <HbLabel>
       
    20 #include <HbPushButton> 
       
    21 #include <QDir>
       
    22 #include <QPainter>
       
    23 #include <HbIconItem>
       
    24 #include "localisedhellowidget.h"
       
    25 
       
    26 /*!
       
    27     \ingroup group_localised_helloworld_widget
       
    28     \class LocalisedHelloWidget
       
    29     \brief Example implementation for home screen widget.
       
    30 
       
    31     LocalisedHelloWidget derived from the HbWidget and implements 
       
    32     needed functions for the home screen widget to demonstrate widget localisation.
       
    33 */
       
    34 
       
    35 /*!
       
    36     Constructs a widget which is a child of \a parent, with widget flags set to \a flags.
       
    37 */
       
    38 LocalisedHelloWidget::LocalisedHelloWidget(QGraphicsItem* parent, Qt::WindowFlags flags)
       
    39     : HbWidget(parent, flags),mIcon(0)
       
    40 {
       
    41     QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical);
       
    42     setPreferredSize(200,100);
       
    43     setLayout(layout);
       
    44     mButton = new HbPushButton();
       
    45     layout->addItem(mButton);
       
    46    
       
    47     connect(mButton,SIGNAL(pressed()),SLOT(onButtonPressed()));
       
    48 }
       
    49 
       
    50 /*!
       
    51     Destructor
       
    52 */
       
    53 LocalisedHelloWidget::~LocalisedHelloWidget()
       
    54 {
       
    55 
       
    56 }
       
    57 
       
    58 /*!
       
    59     Root path for widget's resources
       
    60 */
       
    61 QString LocalisedHelloWidget::rootPath()const
       
    62 {
       
    63     return mRootPath;
       
    64 }
       
    65 
       
    66 /*!
       
    67     Set's widget root path as \a rootPath
       
    68 */
       
    69 void LocalisedHelloWidget::setRootPath(const QString &rootPath)
       
    70 {
       
    71     mRootPath = rootPath;
       
    72 }
       
    73 
       
    74 /*!
       
    75     Called when widget is initialized 
       
    76 */
       
    77 void LocalisedHelloWidget::onInitialize()
       
    78 {
       
    79     // localisation can be used now
       
    80     mText = hbTrId("txt_localisedhellowidgetplugin_button_hello_world2");
       
    81     mButton->setText(hbTrId("txt_localisedhellowidgetplugin_button_hello_world1"));
       
    82     // roothPath is set thus we can use it
       
    83     QString iconPath = QDir::toNativeSeparators(mRootPath + "/localisedhellowidgetplugin.png"); 
       
    84     mIcon = new HbIconItem(iconPath);
       
    85     static_cast<QGraphicsLinearLayout*>(layout())->addItem(mIcon);
       
    86 }
       
    87 
       
    88 /*!
       
    89     Called when widget is shown in the home screen
       
    90 */
       
    91 void LocalisedHelloWidget::onShow()
       
    92 {
       
    93 }
       
    94 
       
    95 /*!
       
    96     Called when widget is hidden from the home screen
       
    97 */
       
    98 void LocalisedHelloWidget::onHide()
       
    99 {
       
   100 }
       
   101 
       
   102 /*!
       
   103     Called when button is pressed, toggles between two localised strings.
       
   104 */
       
   105 void LocalisedHelloWidget::onButtonPressed()
       
   106 {
       
   107     QString tmp = mButton->text();
       
   108     mButton->setText(mText);
       
   109     mText = tmp;
       
   110 }
       
   111