controlpanelui/src/cpplugins/keytouchfdbkplugin/src/cpkeyscreenview.cpp
changeset 19 36aa4756ee82
child 21 2883a5458389
equal deleted inserted replaced
12:624337f114fe 19:36aa4756ee82
       
     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 
       
    29 
       
    30 CpKeyScreenView::CpKeyScreenView(QGraphicsItem *parent) :
       
    31     CpBaseSettingView(0,parent),
       
    32     mScreenRadioButton(0),
       
    33     mRotateCheckbox(0),
       
    34 	mBrightSliderItem(0),
       
    35 	mCallibItem(0),
       
    36 	mModel(0)
       
    37 {
       
    38     HbDataForm *form = qobject_cast<HbDataForm*> ( widget() );
       
    39     if (form) {
       
    40         form->setHeading(hbTrId("txt_cp_subhead_keys_screen"));
       
    41         mModel = new CpKeyScreenModel();
       
    42         HbDataFormModel *model = new HbDataFormModel;
       
    43 
       
    44         if ( mModel->isKeyguardSupported() ) {
       
    45             makeScreenItem(*model);
       
    46         }
       
    47 
       
    48         if ( mModel->isRotateSupported() ) {
       
    49             makeRotateItem(*model);
       
    50         }
       
    51 
       
    52         makeBrightnessItem(*model);
       
    53 
       
    54         if ( mModel->isCallibrationSupported() ) {
       
    55             makeCallibrationItem(*model);
       
    56         }
       
    57 
       
    58         form->setModel(model);
       
    59     }
       
    60 }
       
    61 
       
    62 void CpKeyScreenView::makeScreenItem(HbDataFormModel& model)
       
    63 {
       
    64     mScreenRadioButton = new CpSettingFormItemData(HbDataFormModelItem::RadioButtonListItem,
       
    65             hbTrId("txt_cp_setlabel_keys_screen_locked_after"));
       
    66     qobject_cast<HbDataForm*> ( widget() )->addConnection(mScreenRadioButton,SIGNAL(itemSelected(int)),this,SLOT(screenValueChanged(int)));
       
    67     model.appendDataFormItem(mScreenRadioButton, model.invisibleRootItem());
       
    68 
       
    69     // Valid range is:
       
    70     // 15 secs, 30 secs, 45 secs, 1 min, 2 mins
       
    71     QStringList sList;
       
    72     sList<< hbTrId("txt_cp_setlabel_keys_screen_val_15_seconds")<< hbTrId("txt_cp_setlabel_keys_screen_val_30_seconds")
       
    73          << hbTrId("txt_cp_setlabel_keys_screen_val_45_seconds")<< hbTrId("txt_cp_setlabel_keys_screen_val_1_minute")
       
    74          << hbTrId("txt_cp_setlabel_keys_screen_val_2_minutes");
       
    75     int period = mModel->keyguard();
       
    76     int selectedIndex = period/KCpKeyscreenTimeCoeff - 1;
       
    77     if ( KCpKeyscreenLock120s == period ){ // 2 minutes
       
    78         selectedIndex = EKeyScreenLockItem5;
       
    79     }
       
    80     if ( (KCpKeyscreenLock15s != period) && (KCpKeyscreenLock30s != period) && 
       
    81             (KCpKeyscreenLock45s != period) && (KCpKeyscreenLock60s != period) && 
       
    82             (KCpKeyscreenLock120s != period) ){
       
    83         mModel->setKeyguard(KCpKeyscreenLockDefault30s);  // Set keyguard and backlight period to default
       
    84         selectedIndex = EKeyScreenLockItem2;
       
    85     }
       
    86     mScreenRadioButton->setContentWidgetData( QString("items"), sList );
       
    87     mScreenRadioButton->setContentWidgetData( QString("selected"), selectedIndex);
       
    88 }
       
    89 
       
    90 void CpKeyScreenView::makeRotateItem(HbDataFormModel& model)
       
    91 {
       
    92     mRotateCheckbox = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, QString());
       
    93     qobject_cast<HbDataForm*> ( widget() )->addConnection(mRotateCheckbox,SIGNAL(stateChanged(int)),this,SLOT(rotateValueChanged(int)));
       
    94     model.appendDataFormItem(mRotateCheckbox, model.invisibleRootItem());
       
    95 
       
    96     mRotateCheckbox->setContentWidgetData( QString("text"), QVariant(hbTrId("txt_cp_list_autorotate_display")) );
       
    97     mRotateCheckbox->setData(HbDataFormModelItem::DescriptionRole, QString( hbTrId("txt_cp_info_rotate_the_display_content_automatical") ));
       
    98     Qt::CheckState state;
       
    99     if ( mModel->rotate() ){
       
   100         state = Qt::Checked;
       
   101     } else {
       
   102         state = Qt::Unchecked;
       
   103     }
       
   104     mRotateCheckbox->setContentWidgetData( QString("checkState"), state );
       
   105 }
       
   106 
       
   107 void CpKeyScreenView::makeBrightnessItem(HbDataFormModel& model)
       
   108 {
       
   109     mBrightSliderItem = new CpSettingFormItemData(HbDataFormModelItem::SliderItem, hbTrId("txt_cp_setlabel_brightness"));
       
   110     qobject_cast<HbDataForm*> ( widget() )->addConnection(mBrightSliderItem,SIGNAL(valueChanged(int)),this,SLOT(brightValueChanged(int)));
       
   111     model.appendDataFormItem(mBrightSliderItem, model.invisibleRootItem());
       
   112 
       
   113     mBrightSliderItem->setContentWidgetData( QString("value"), mModel->brightness() );
       
   114     mBrightSliderItem->setContentWidgetData( QString("minimum"), 1 );
       
   115     mBrightSliderItem->setContentWidgetData( QString("maximum"), 5 );
       
   116 }
       
   117 
       
   118 void CpKeyScreenView::makeCallibrationItem(HbDataFormModel& model)
       
   119 {
       
   120     mCallibItem = new CpSettingFormItemData(HbDataFormModelItem::ToggleValueItem,
       
   121                         QString());
       
   122     qobject_cast<HbDataForm*> ( widget() )->addConnection(mCallibItem,SIGNAL(pressed()),this,SLOT(launchCallib()));
       
   123     model.appendDataFormItem(mCallibItem, model.invisibleRootItem());
       
   124     mCallibItem->setContentWidgetData( QString("text"), hbTrId("txt_cp_button_touch_screen_calibration"));
       
   125 }
       
   126 
       
   127 CpKeyScreenView::~CpKeyScreenView()
       
   128 {
       
   129     delete mModel;
       
   130 	mModel = 0;
       
   131 }
       
   132 
       
   133 void CpKeyScreenView::screenValueChanged(int index)
       
   134 {
       
   135     int period = (index + 1) * KCpKeyscreenTimeCoeff;
       
   136     if (EKeyScreenLockItem5 == index){
       
   137         period = KCpKeyscreenLock120s;
       
   138     }
       
   139     mModel->setKeyguard(period);
       
   140 }
       
   141 
       
   142 void CpKeyScreenView::rotateValueChanged(int value)
       
   143 {
       
   144     mModel->setRotate( value );
       
   145 }
       
   146 
       
   147 void CpKeyScreenView::brightValueChanged(int value)
       
   148 {
       
   149 	mModel->setBrightness(value);
       
   150 }
       
   151 
       
   152 void CpKeyScreenView::launchCallib()
       
   153 {
       
   154 }
       
   155 
       
   156