homescreenapp/examples/localisedhellowidgetplugin/src/localisedhellowidget.cpp
changeset 51 4785f57bf3d4
child 61 2b1b11a301d2
equal deleted inserted replaced
46:23b5d6a29cce 51:4785f57bf3d4
       
     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_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     QString testing = hbTrId("txt_localisedhellowidgetplugin_button_hello_world2"); 
       
    82     testing = hbTrId("txt_localisedhellowidgetplugin_button_hello_world1"); 
       
    83     testing = hbTrId("txt_localisedhellowidgetplugin_dblist_hello_world_title"); 
       
    84     testing = hbTrId("txt_localisedhellowidgetplugin_dblist_hello_world_desc"); 
       
    85     mButton->setText(hbTrId("txt_localisedhellowidgetplugin_button_hello_world1"));
       
    86     // roothPath is set thus we can use it
       
    87     QString iconPath = QDir::toNativeSeparators(mRootPath + "/localisedhellowidgetplugin.png"); 
       
    88     mIcon = new HbIconItem(iconPath);
       
    89     static_cast<QGraphicsLinearLayout*>(layout())->addItem(mIcon);
       
    90 }
       
    91 
       
    92 /*!
       
    93     Called when widget is shown in the home screen
       
    94 */
       
    95 void LocalisedHelloWidget::onShow()
       
    96 {
       
    97 }
       
    98 
       
    99 /*!
       
   100     Called when widget is hidden from the home screen
       
   101 */
       
   102 void LocalisedHelloWidget::onHide()
       
   103 {
       
   104 }
       
   105 
       
   106 /*!
       
   107     Called when button is pressed, toggles between two localised strings.
       
   108 */
       
   109 void LocalisedHelloWidget::onButtonPressed()
       
   110 {
       
   111     QString tmp = mButton->text();
       
   112     mButton->setText(mText);
       
   113     mText = tmp;
       
   114 }
       
   115