taskswitcher/testapplications/tstestcatapp/lunchwidget.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 #include "lunchwidget.h"
       
    18 #include <hbapplication>
       
    19 #include <QStringList>
       
    20 #include <HbComboBox>
       
    21 #include <HbIcon>
       
    22 #include <hbMainWindow>
       
    23 #include <hbinstance.h>
       
    24 #include "tstasksettings.h"
       
    25 
       
    26 
       
    27 
       
    28 #define hbApp qobject_cast<HbApplication*>(qApp)
       
    29 
       
    30 lunchwidget::lunchwidget(QGraphicsItem *parent)
       
    31     : HbWidget(parent)
       
    32 {
       
    33     mClient = new TsTaskSettings; 
       
    34 
       
    35     mAnimal1 = new QPixmap(":/images/lion.jpg");
       
    36     mAnimal2 = new QPixmap(":/images/puma.jpg");
       
    37     
       
    38     mResultLabel = new HbLabel;        
       
    39     mPhotoLabel= new HbLabel;        
       
    40    // mPriorityLabel = new HbLabel("Priority");   
       
    41     
       
    42     mRegisterButton = new HbPushButton("Register");
       
    43     mUnregisterButton = new HbPushButton("Unregister");
       
    44     mHideButton = new HbPushButton("Hide me");
       
    45     mShowButton = new HbPushButton("Show me");
       
    46     mAnimal1Button = new HbPushButton("Lion");
       
    47     mAnimal2Button = new HbPushButton("Puma");
       
    48     mClearButton = new HbPushButton("Clear");
       
    49     
       
    50     /*mPriorityCombo = new HbComboBox();
       
    51     mPriorityCombo->addItem("default"); 
       
    52     mPriorityCombo->addItem("low");
       
    53     mPriorityCombo->addItem("medium");
       
    54     mPriorityCombo->addItem("high");*/
       
    55 
       
    56     mGridLayout = new QGraphicsGridLayout();
       
    57     mGridLayout->addItem(mPhotoLabel, 0, 0, 6, 6);
       
    58     mGridLayout->addItem(mResultLabel, 6, 0, 1, 3);
       
    59     mGridLayout->addItem(mClearButton, 6, 4, 1, 3);
       
    60     //mGridLayout->addItem(mPriorityLabel, 7, 0, 1, 3);
       
    61     //mGridLayout->addItem(mPriorityCombo, 7, 4, 1, 3);    
       
    62     mGridLayout->addItem(mRegisterButton, 7, 0, 1, 3);
       
    63     mGridLayout->addItem(mUnregisterButton, 7, 4, 1, 3);    
       
    64     mGridLayout->addItem(mAnimal1Button, 8, 0, 1, 3);
       
    65     mGridLayout->addItem(mAnimal2Button, 8, 4, 1, 3);    
       
    66     mGridLayout->addItem(mHideButton, 9, 0, 1, 3);
       
    67     mGridLayout->addItem(mShowButton, 9, 4, 1, 3);
       
    68     mGridLayout->setRowFixedHeight(0, 300);
       
    69     setLayout(mGridLayout);
       
    70     
       
    71     connect( mRegisterButton, SIGNAL(released()), this, SLOT(regScr()) );
       
    72     connect( mUnregisterButton, SIGNAL(released()), this, SLOT(unregScr()) );
       
    73     connect( mHideButton, SIGNAL(released()), this, SLOT(hideMe()) );
       
    74     connect( mShowButton, SIGNAL(released()), this, SLOT(showMe()) );
       
    75     connect( mAnimal1Button, SIGNAL(released()), this, SLOT(animal1()) );
       
    76     connect( mAnimal2Button, SIGNAL(released()), this, SLOT(animal2()) );
       
    77     connect( mClearButton, SIGNAL(released()), this, SLOT(clear()) );
       
    78 }
       
    79 
       
    80 lunchwidget::~lunchwidget()
       
    81 {
       
    82     delete mClient;
       
    83     delete mAnimal1;
       
    84     delete mAnimal2;
       
    85 }
       
    86 
       
    87 void lunchwidget::regScr() 
       
    88 {
       
    89     HbMainWindow *mainWindow = hbInstance->allMainWindows().first();
       
    90     QPixmap screenshot = QPixmap::grabWidget(mainWindow, mainWindow->rect());
       
    91     
       
    92     Before();
       
    93     bool ok = mClient->registerScreenshot(screenshot);
       
    94     After();
       
    95     Result();
       
    96     setResult(ok);
       
    97 }
       
    98 
       
    99 void lunchwidget::unregScr()
       
   100 {
       
   101     Before();
       
   102     bool ok = mClient->unregisterScreenshot();
       
   103     After();
       
   104     Result();
       
   105     setResult(ok);
       
   106 }
       
   107 
       
   108 void lunchwidget::hideMe() 
       
   109 {
       
   110     Before();
       
   111     bool ok = mClient->setVisibility(false);
       
   112     After();
       
   113     Result();
       
   114     setResult(ok);
       
   115 }
       
   116 
       
   117 void lunchwidget::showMe() 
       
   118 {
       
   119     Before();
       
   120     bool ok = mClient->setVisibility(true);
       
   121     After();
       
   122     Result();
       
   123     setResult(ok);
       
   124 }
       
   125     
       
   126 void lunchwidget::Before()
       
   127 {
       
   128     TTime time;
       
   129     time.HomeTime();
       
   130     iBefore = time.Int64();
       
   131 }
       
   132 
       
   133 void lunchwidget::After()
       
   134 {
       
   135     TTime time;
       
   136     time.HomeTime();
       
   137     iAfter = time.Int64();
       
   138 }
       
   139 
       
   140 void lunchwidget::Result()
       
   141 {
       
   142     TInt64 res(0);
       
   143     res = iAfter-iBefore;
       
   144     res = res/1000;
       
   145     iResult = res;
       
   146 }
       
   147 
       
   148 void lunchwidget::animal1()
       
   149 {
       
   150     mPhotoLabel->setIcon(QIcon(*mAnimal1));
       
   151 }
       
   152 
       
   153 void lunchwidget::animal2()
       
   154 {
       
   155     mPhotoLabel->setIcon(QIcon(*mAnimal2));
       
   156 }
       
   157 
       
   158 void lunchwidget::clear()
       
   159 {
       
   160     mPhotoLabel->setIcon(QIcon());
       
   161     mResultLabel->setPlainText("");
       
   162 }
       
   163 
       
   164 void lunchwidget::setResult(bool ok)
       
   165 {
       
   166     if ( ok ) {        
       
   167         QString msg;
       
   168         msg = tr("%1 ms").arg(iResult);
       
   169         mResultLabel->setPlainText(msg);
       
   170     }
       
   171     else {
       
   172         mResultLabel->setPlainText("Fail");
       
   173     }
       
   174     
       
   175 }