controlpanelui/src/cpplugins/volumeplugin/src/cppersonalizationcustomviewitem.cpp
branchRCL_3
changeset 13 90fe62538f66
equal deleted inserted replaced
12:3fec62e6e7fc 13:90fe62538f66
       
     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 "cppersonalizationcustomviewitem.h"
       
    19 #include <hbdataformmodelitem.h>
       
    20 #include <hbdataformmodel.h>
       
    21 #include <hbabstractitemview.h>
       
    22 #include <QMetaProperty>
       
    23 #include <hbpushbutton.h>
       
    24 
       
    25 CpPersonalizationCustomViewItem::CpPersonalizationCustomViewItem(QGraphicsItem *parent )
       
    26 																: HbDataFormViewItem(parent),
       
    27 																  mWidget(0)
       
    28 {
       
    29 }
       
    30 CpPersonalizationCustomViewItem::~CpPersonalizationCustomViewItem()
       
    31 {
       
    32 }
       
    33 HbAbstractViewItem* CpPersonalizationCustomViewItem::createItem()
       
    34 {
       
    35 	return new CpPersonalizationCustomViewItem(*this);
       
    36 }
       
    37 bool CpPersonalizationCustomViewItem::canSetModelIndex(const QModelIndex &index) const
       
    38 {
       
    39     CpVolumeCustomItemType type = static_cast<CpVolumeCustomItemType>(index.data(HbDataFormModelItem::ItemTypeRole).toInt());
       
    40 	/*if (type == MasterVolumeSliderItem) {
       
    41 		return true;
       
    42 	}
       
    43 	else*/ if (type == SilenceIndicatorItem) {
       
    44         return true;
       
    45 	} 
       
    46 	else {
       
    47 		return false;
       
    48 	}
       
    49 }
       
    50 
       
    51 HbWidget *CpPersonalizationCustomViewItem::createCustomWidget()
       
    52 {
       
    53     CpVolumeCustomItemType type = static_cast<CpVolumeCustomItemType>
       
    54                 (modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
    55 	/*if (type == MasterVolumeSliderItem) {
       
    56 		CpMasterVolumeSlider *masterVolumeSlider = new CpMasterVolumeSlider();
       
    57 		connect(masterVolumeSlider, SIGNAL(valueChanged(int)), this, SLOT(store()));
       
    58 		mWidgetMap.insert(type,masterVolumeSlider);
       
    59 		return masterVolumeSlider;
       
    60 	} else*/ if (type == SilenceIndicatorItem ) {
       
    61         HbPushButton *slienceIndicator = new HbPushButton();
       
    62         slienceIndicator->setCheckable(true);
       
    63         connect(slienceIndicator, SIGNAL(toggled(bool)),this,SLOT(store()));
       
    64         mWidget = slienceIndicator;
       
    65         return slienceIndicator;
       
    66 	}
       
    67 	else {
       
    68 		return 0;
       
    69 	}
       
    70 }
       
    71 
       
    72 void CpPersonalizationCustomViewItem::load()
       
    73 {
       
    74 	//HbDataFormViewItem::load();
       
    75 	
       
    76     CpVolumeCustomItemType itemType = static_cast<CpVolumeCustomItemType>(
       
    77         modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
    78 
       
    79     if(itemType == SilenceIndicatorItem) {
       
    80         
       
    81         QModelIndex itemIndex = modelIndex();
       
    82         HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());;
       
    83         HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>(
       
    84             model->itemFromIndex(itemIndex));
       
    85         
       
    86        
       
    87         if (mWidget != 0) {
       
    88             const QMetaObject *metaObj = mWidget->metaObject();
       
    89             int count = metaObj->propertyCount();
       
    90             for (int i = 0; i < count; i++) {
       
    91                 QMetaProperty metaProperty = metaObj->property(i);
       
    92                 if (metaProperty.isValid() && metaProperty.isWritable()) {
       
    93                     metaProperty.write(mWidget,modelItem->contentWidgetData(metaProperty.name()));
       
    94                 }
       
    95             }
       
    96         }
       
    97     }	
       
    98 }
       
    99 
       
   100 void CpPersonalizationCustomViewItem::restore()
       
   101 {
       
   102     HbDataFormViewItem::restore();
       
   103     
       
   104     CpVolumeCustomItemType itemType = static_cast<CpVolumeCustomItemType>(
       
   105         modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
   106 
       
   107     if(itemType == SilenceIndicatorItem) {
       
   108         
       
   109         QModelIndex itemIndex = modelIndex();
       
   110         HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());;
       
   111         HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>(
       
   112             model->itemFromIndex(itemIndex));
       
   113         
       
   114        
       
   115         if (mWidget != 0) {
       
   116             const QMetaObject *metaObj = mWidget->metaObject();
       
   117             int count = metaObj->propertyCount();
       
   118             for (int i = 0; i < count; i++) {
       
   119                 QMetaProperty metaProperty = metaObj->property(i);
       
   120                 if (metaProperty.isValid() && metaProperty.isWritable()) {
       
   121                     metaProperty.write(mWidget,modelItem->contentWidgetData(metaProperty.name()));
       
   122                 }
       
   123             }
       
   124         }
       
   125     }   
       
   126 }
       
   127 
       
   128 
       
   129 void CpPersonalizationCustomViewItem::store()
       
   130 {
       
   131 	//HbDataFormViewItem::store();
       
   132 
       
   133     CpVolumeCustomItemType itemType = static_cast<CpVolumeCustomItemType>(
       
   134         modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
   135 
       
   136     if(itemType == SilenceIndicatorItem) {
       
   137 
       
   138         QModelIndex itemIndex = modelIndex();
       
   139         HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());
       
   140         HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>(
       
   141             model->itemFromIndex(itemIndex));
       
   142         
       
   143         
       
   144         /*if (CpMasterVolumeSlider *slider = qobject_cast<CpMasterVolumeSlider *>(widget)) {
       
   145             modelItem->setContentWidgetData("value",slider->value());
       
   146         }*/
       
   147         if (HbPushButton *silenceIndicator = qobject_cast<HbPushButton *>(mWidget)) {
       
   148             modelItem->setContentWidgetData("checked",silenceIndicator->isChecked());
       
   149         }                
       
   150     }
       
   151 }
       
   152 
       
   153 /*void CpPersonalizationCustomViewItem::onValueChanged(int value)
       
   154 {
       
   155 	HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>(
       
   156 									modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
   157 
       
   158 	if(itemType == MasterVolumeSliderItem) {
       
   159 
       
   160 		QModelIndex itemIndex = modelIndex();
       
   161 		HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());;
       
   162 		HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>(
       
   163 			model->itemFromIndex(itemIndex));
       
   164 		modelItem->setContentWidgetData("value",value);
       
   165 	}
       
   166 }*/