controlpanelui/src/cpplugins/keytouchfdbkplugin/src/cpkeyscreenview.cpp
branchRCL_3
changeset 14 5f281e37a2f5
parent 13 90fe62538f66
equal deleted inserted replaced
13:90fe62538f66 14:5f281e37a2f5
     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 
       
    18 #include "cpkeyscreenview.h"
       
    19 #include "cpkeyscreenmodel.h"
       
    20 #include "cpkeyscreenconstants.h"
       
    21 #include <hbdataform.h>
       
    22 #include <QStringList>
       
    23 #include <QDebug>
       
    24 #include <QtCore/qobject.h>
       
    25 #include <hbdataformmodel.h>
       
    26 #include <cpsettingformitemdata.h>
       
    27 #include <hbmessagebox.h>
       
    28 #include <hbslider.h>
       
    29 
       
    30 
       
    31 CpKeyScreenView::CpKeyScreenView(QGraphicsItem *parent) :
       
    32     CpBaseSettingView(0,parent),
       
    33     mScreenComboButton(0),
       
    34     mRotateCheckbox(0),
       
    35 	mBrightSliderItem(0),
       
    36 	mCallibItem(0),
       
    37 	mModel(0)
       
    38 {   
       
    39     HbDataForm *form = qobject_cast<HbDataForm*> ( widget() );
       
    40     if (form) {
       
    41         // Valid range is:
       
    42         // 15 secs, 30 secs, 45 secs, 1 min, 2 mins
       
    43         mScreenLockValues.insert(KCpKeyscreenLock15s,hbTrId("txt_cp_setlabel_keys_screen_val_15_seconds"));
       
    44         mScreenLockValues.insert(KCpKeyscreenLock30s,hbTrId("txt_cp_setlabel_keys_screen_val_30_seconds"));
       
    45         mScreenLockValues.insert(KCpKeyscreenLock45s,hbTrId("txt_cp_setlabel_keys_screen_val_45_seconds"));
       
    46         mScreenLockValues.insert(KCpKeyscreenLock60s,hbTrId("txt_cp_setlabel_keys_screen_val_1_minute"));
       
    47         mScreenLockValues.insert(KCpKeyscreenLock120s,hbTrId("txt_cp_setlabel_keys_screen_val_2_minutes"));
       
    48         
       
    49         form->setHeading(hbTrId("txt_cp_subhead_keys_screen"));
       
    50         mModel = new CpKeyScreenModel();
       
    51         HbDataFormModel *model = new HbDataFormModel;
       
    52 
       
    53         if ( mModel->isKeyguardSupported() ) {
       
    54             makeScreenItem(*model);
       
    55         }
       
    56 
       
    57         if ( mModel->isRotateSupported() ) {
       
    58             makeRotateItem(*model);
       
    59         }
       
    60 
       
    61         makeBrightnessItem(*model);
       
    62 
       
    63        /* if ( mModel->isCallibrationSupported() ) {
       
    64             makeCallibrationItem(*model);
       
    65         }*/
       
    66 
       
    67         form->setModel(model);
       
    68     }
       
    69 }
       
    70 
       
    71 void CpKeyScreenView::makeScreenItem(HbDataFormModel& model)
       
    72 {
       
    73     mScreenComboButton = new CpSettingFormItemData(HbDataFormModelItem::ComboBoxItem,
       
    74             hbTrId("txt_cp_setlabel_keys_screen_locked_after"));    
       
    75     
       
    76     qobject_cast<HbDataForm*> ( widget() )->addConnection(
       
    77             mScreenComboButton,SIGNAL(currentIndexChanged(QString)),
       
    78             this,SLOT(screenValueChanged(QString)));
       
    79     
       
    80     model.appendDataFormItem(mScreenComboButton, model.invisibleRootItem());
       
    81 
       
    82     int period = mModel->keyguard();
       
    83     
       
    84     int selectedIndex(-1);    
       
    85     
       
    86     QMap<int,QString>::iterator it = mScreenLockValues.find(period);
       
    87     if (it == mScreenLockValues.end()) {
       
    88         mModel->setKeyguard(KCpKeyscreenLockDefault30s); // Set keyguard and backlight period to default
       
    89         selectedIndex = 1;
       
    90     }
       
    91     else {
       
    92         for (it = mScreenLockValues.begin();it != mScreenLockValues.end();++it) {
       
    93             selectedIndex++;
       
    94             if (it.key() == period) {
       
    95                 break;
       
    96             }
       
    97         }
       
    98     }
       
    99     
       
   100     QStringList items = mScreenLockValues.values();
       
   101     mScreenComboButton->setContentWidgetData( QString("items"), items );
       
   102     mScreenComboButton->setContentWidgetData( QString("currentIndex"), selectedIndex);
       
   103     mScreenComboButton->setContentWidgetData("objectName", "screenComboButton");
       
   104 }
       
   105 
       
   106 void CpKeyScreenView::makeRotateItem(HbDataFormModel& model)
       
   107 {
       
   108     mRotateCheckbox = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, QString());
       
   109     qobject_cast<HbDataForm*> ( widget() )->addConnection(mRotateCheckbox,SIGNAL(stateChanged(int)),this,SLOT(rotateValueChanged(int)));
       
   110     model.appendDataFormItem(mRotateCheckbox, model.invisibleRootItem());
       
   111 
       
   112     mRotateCheckbox->setContentWidgetData( QString("text"), QVariant(hbTrId("txt_cp_list_autorotate_display")) );
       
   113     mRotateCheckbox->setData(HbDataFormModelItem::DescriptionRole, QString( hbTrId("txt_cp_info_rotate_the_display_content_automatical") ));
       
   114     Qt::CheckState state;
       
   115     if ( mModel->rotate() ){
       
   116         state = Qt::Checked;
       
   117     } else {
       
   118         state = Qt::Unchecked;
       
   119     }
       
   120     mRotateCheckbox->setContentWidgetData( QString("checkState"), state );
       
   121     mRotateCheckbox->setContentWidgetData("objectName", "rotateCheckbox");
       
   122 }
       
   123 
       
   124 void CpKeyScreenView::makeBrightnessItem(HbDataFormModel& model)
       
   125 {
       
   126     mBrightSliderItem = new CpSettingFormItemData(HbDataFormModelItem::SliderItem, hbTrId("txt_cp_setlabel_brightness"));
       
   127     qobject_cast<HbDataForm*> ( widget() )->addConnection(mBrightSliderItem,SIGNAL(valueChanged(int)),this,SLOT(brightValueChanged(int)));
       
   128     model.appendDataFormItem(mBrightSliderItem, model.invisibleRootItem());
       
   129 
       
   130     QList<QVariant> sliderElements;
       
   131     sliderElements << QVariant(HbSlider::IncreaseElement) << QVariant(HbSlider::TrackElement)
       
   132                    << QVariant(HbSlider::DecreaseElement);
       
   133     mBrightSliderItem->setContentWidgetData("sliderElements",sliderElements);
       
   134     mBrightSliderItem->setContentWidgetData( QString("value"), mModel->brightness() );
       
   135     mBrightSliderItem->setContentWidgetData( QString("minimum"), 1 );
       
   136     mBrightSliderItem->setContentWidgetData( QString("maximum"), 5 );
       
   137     QMap< QString, QVariant > iconElements;
       
   138     iconElements.insert(QString("IncreaseElement") , QVariant(":/icon/hb_vol_slider_increment.svg"));
       
   139     iconElements.insert(QString("DecreaseElement"), QVariant(":/icon/hb_vol_slider_decrement.svg") );
       
   140     mBrightSliderItem->setContentWidgetData( QString( "elementIcons" ), iconElements );
       
   141     mRotateCheckbox->setContentWidgetData("objectName", "brightSliderItem");
       
   142 }
       
   143 
       
   144 void CpKeyScreenView::makeCallibrationItem(HbDataFormModel& model)
       
   145 {
       
   146     mCallibItem = new CpSettingFormItemData(HbDataFormModelItem::ToggleValueItem,
       
   147                         QString());
       
   148     qobject_cast<HbDataForm*> ( widget() )->addConnection(mCallibItem,SIGNAL(pressed()),this,SLOT(launchCallib()));
       
   149     model.appendDataFormItem(mCallibItem, model.invisibleRootItem());
       
   150     mCallibItem->setContentWidgetData( QString("text"), hbTrId("txt_cp_button_touch_screen_calibration"));
       
   151 }
       
   152 
       
   153 CpKeyScreenView::~CpKeyScreenView()
       
   154 {
       
   155     delete mModel;
       
   156 	mModel = 0;
       
   157 }
       
   158 
       
   159 void CpKeyScreenView::screenValueChanged(const QString &value)
       
   160 {    
       
   161     for (QMap<int,QString>::iterator it = mScreenLockValues.begin();
       
   162          it != mScreenLockValues.end();++it) {
       
   163         if (it.value() == value) {
       
   164             mModel->setKeyguard(it.key());
       
   165             break;
       
   166         }
       
   167     }
       
   168 }
       
   169 
       
   170 void CpKeyScreenView::rotateValueChanged(int value)
       
   171 {
       
   172     mModel->setRotate( value );
       
   173 }
       
   174 
       
   175 void CpKeyScreenView::brightValueChanged(int value)
       
   176 {
       
   177 	mModel->setBrightness(value);
       
   178 }
       
   179 
       
   180 void CpKeyScreenView::launchCallib()
       
   181 {
       
   182 }
       
   183 
       
   184