phonesettings/cpphonesettingsplugins/divertplugin/src/cpdivertselectioncustomitem.cpp
changeset 21 92ab7f8d0eab
child 22 6bb1b21d2484
equal deleted inserted replaced
4:c84cf270c54f 21:92ab7f8d0eab
       
     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 "cpdivertselectioncustomitem.h"
       
    19 #include <hblabel.h>
       
    20 #include <hbcheckbox.h>
       
    21 #include <qgraphicsgridlayout.h>
       
    22 #include <cppluginlogging.h>
       
    23 
       
    24 
       
    25 CpDivertSelectionCustomitem::CpDivertSelectionCustomitem(
       
    26         QGraphicsItem *parent /**=0*/,
       
    27         Qt::WindowFlags wFlags /**=0*/):
       
    28         HbWidget(parent, wFlags),
       
    29         layout(NULL),
       
    30         checkbox(NULL),
       
    31         //numberValueLabel(NULL),
       
    32         timeoutLabel(NULL),
       
    33         timeoutValueLabel(NULL),
       
    34         m_state(Disabled)
       
    35 {
       
    36     DPRINT;
       
    37 
       
    38     layout = new QGraphicsGridLayout(this);
       
    39     layout->setSpacing(0);
       
    40     layout->setContentsMargins(0,0,0,0);
       
    41     layout->setRowMaximumHeight(0,0);
       
    42     layout->setRowMaximumHeight(1,0);
       
    43 
       
    44     checkbox = new HbCheckBox(this);
       
    45     checkbox->setBackgroundItem(HbStyle::P_DataItemContentWidget_background);
       
    46 
       
    47     HbStyle::setItemName(checkbox, "dataItem_ContentWidget");
       
    48 
       
    49     layout->addItem(checkbox, 0, 0, 1, 2);
       
    50 
       
    51     connect(checkbox,SIGNAL(clicked()), this, SIGNAL(clicked()));
       
    52 
       
    53     //numberValueLabel = new HbLabel(this);
       
    54     //layout->addItem(numberValueLabel, 0, 1);
       
    55     //connect(numberValueLabel,SIGNAL(clicked()), this, SIGNAL(clicked()));
       
    56 
       
    57     timeoutLabel = new HbLabel(this);
       
    58     HbStyle::setItemName(timeoutLabel, "dataItem_ContentWidget");
       
    59     timeoutLabel->setAlignment(Qt::AlignRight);
       
    60     layout->addItem(timeoutLabel, 1, 0);
       
    61 
       
    62     timeoutLabel->hide();
       
    63     timeoutValueLabel = new HbLabel(this);
       
    64     timeoutValueLabel->setBackgroundItem(HbStyle::P_DataItemContentWidget_background);
       
    65     HbStyle::setItemName(timeoutValueLabel, "dataItem_ContentWidget");
       
    66     timeoutValueLabel->hide();
       
    67     layout->addItem(timeoutValueLabel, 1, 1);
       
    68 
       
    69     setLayout(layout);
       
    70 }
       
    71 
       
    72 CpDivertSelectionCustomitem::~CpDivertSelectionCustomitem()
       
    73 {
       
    74     DPRINT;
       
    75 }
       
    76 
       
    77 const QString CpDivertSelectionCustomitem::number() const
       
    78 {
       
    79     DPRINT;
       
    80     return checkbox->text();
       
    81 }
       
    82 
       
    83 void CpDivertSelectionCustomitem::setNumber( const QString& number )
       
    84 {
       
    85     DPRINT << number;
       
    86     
       
    87     checkbox->setText(number);
       
    88 }
       
    89 
       
    90 int CpDivertSelectionCustomitem::timeout() const
       
    91 {
       
    92     DPRINT;
       
    93     return timeoutValueLabel->plainText().toInt();
       
    94 }
       
    95 
       
    96 void CpDivertSelectionCustomitem::setTimeout( int timeout)
       
    97 {
       
    98     DPRINT << timeout;
       
    99     timeoutValueLabel->setPlainText(QString::number(timeout));
       
   100 }
       
   101 
       
   102 const QString CpDivertSelectionCustomitem::timeoutText() const
       
   103 {
       
   104     DPRINT;
       
   105     return timeoutLabel->plainText();
       
   106 }
       
   107 
       
   108 void CpDivertSelectionCustomitem::setTimeoutText( const QString& text )
       
   109 {
       
   110     DPRINT << text;
       
   111     timeoutLabel->setPlainText(text);
       
   112 
       
   113     if (text != QString("")) {
       
   114         timeoutLabel->show();
       
   115         timeoutValueLabel->show();
       
   116 
       
   117     } else {
       
   118         timeoutLabel->hide();
       
   119         timeoutValueLabel->hide();
       
   120     }
       
   121 }
       
   122 
       
   123 int CpDivertSelectionCustomitem::state() const
       
   124 {
       
   125     DPRINT << m_state;
       
   126     
       
   127     return m_state;
       
   128 }
       
   129 
       
   130 void CpDivertSelectionCustomitem::setState(int state)
       
   131 {
       
   132     DPRINT << state;
       
   133     
       
   134     m_state = state;
       
   135     
       
   136     updateCheckState();
       
   137 }
       
   138 
       
   139 void CpDivertSelectionCustomitem::updateCheckState()
       
   140 {
       
   141     DPRINT << m_state;
       
   142     
       
   143     switch (m_state) {
       
   144         case Enabled:
       
   145             checkbox->setCheckState(Qt::Checked);
       
   146             break;
       
   147         case Deactivated:
       
   148             setNumber(QString(""));
       
   149             setTimeout(0);
       
   150 			//intended fall-through
       
   151         case Disabled:
       
   152             checkbox->setCheckState(Qt::Unchecked);
       
   153             break;
       
   154         default:
       
   155             break;
       
   156     }
       
   157 }