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 /*! |
|
26 CpDivertSelectionCustomitem::CpDivertSelectionCustomitem. |
|
27 */ |
|
28 CpDivertSelectionCustomitem::CpDivertSelectionCustomitem( |
|
29 QGraphicsItem *parent /**=0*/, |
|
30 Qt::WindowFlags wFlags /**=0*/): |
|
31 HbWidget(parent, wFlags), |
|
32 layout(NULL), |
|
33 checkbox(NULL), |
|
34 timeoutLabel(NULL), |
|
35 timeoutValueLabel(NULL), |
|
36 m_state(Disabled) |
|
37 { |
|
38 DPRINT; |
|
39 |
|
40 layout = new QGraphicsGridLayout(this); |
|
41 layout->setSpacing(0); |
|
42 layout->setContentsMargins(0,0,0,0); |
|
43 layout->setRowMaximumHeight(0,0); |
|
44 layout->setRowMaximumHeight(1,0); |
|
45 |
|
46 checkbox = new HbCheckBox(this); |
|
47 HbStyle::setItemName(checkbox, "dataItem_ContentWidget"); |
|
48 |
|
49 layout->addItem(checkbox, 0, 0, 1, 2); |
|
50 connect(checkbox,SIGNAL(clicked()), this, SIGNAL(clicked())); |
|
51 |
|
52 timeoutLabel = new HbLabel(this); |
|
53 HbStyle::setItemName(timeoutLabel, "dataItem_ContentWidget"); |
|
54 timeoutLabel->setAlignment(Qt::AlignRight); |
|
55 layout->addItem(timeoutLabel, 1, 0); |
|
56 |
|
57 timeoutLabel->hide(); |
|
58 timeoutValueLabel = new HbLabel(this); |
|
59 HbStyle::setItemName(timeoutValueLabel, "dataItem_ContentWidget"); |
|
60 timeoutValueLabel->hide(); |
|
61 layout->addItem(timeoutValueLabel, 1, 1); |
|
62 |
|
63 setLayout(layout); |
|
64 } |
|
65 |
|
66 |
|
67 /*! |
|
68 CpDivertSelectionCustomitem::~CpDivertSelectionCustomitem. |
|
69 */ |
|
70 CpDivertSelectionCustomitem::~CpDivertSelectionCustomitem() |
|
71 { |
|
72 DPRINT; |
|
73 } |
|
74 |
|
75 |
|
76 /*! |
|
77 CpDivertSelectionCustomitem::number. |
|
78 */ |
|
79 const QString CpDivertSelectionCustomitem::number() const |
|
80 { |
|
81 DPRINT; |
|
82 return checkbox->text(); |
|
83 } |
|
84 |
|
85 |
|
86 /*! |
|
87 CpDivertSelectionCustomitem::setNumber. |
|
88 */ |
|
89 void CpDivertSelectionCustomitem::setNumber(const QString& number) |
|
90 { |
|
91 DPRINT << number; |
|
92 checkbox->setText(number); |
|
93 } |
|
94 |
|
95 |
|
96 /*! |
|
97 CpDivertSelectionCustomitem::timeout. |
|
98 */ |
|
99 int CpDivertSelectionCustomitem::timeout() const |
|
100 { |
|
101 DPRINT; |
|
102 return timeoutValueLabel->plainText().toInt(); |
|
103 } |
|
104 |
|
105 |
|
106 /*! |
|
107 CpDivertSelectionCustomitem::setTimeout. |
|
108 */ |
|
109 void CpDivertSelectionCustomitem::setTimeout(int timeout) |
|
110 { |
|
111 DPRINT << timeout; |
|
112 timeoutValueLabel->setPlainText(QString::number(timeout)); |
|
113 } |
|
114 |
|
115 |
|
116 /*! |
|
117 CpDivertSelectionCustomitem::timeoutText. |
|
118 */ |
|
119 const QString CpDivertSelectionCustomitem::timeoutText() const |
|
120 { |
|
121 DPRINT; |
|
122 return timeoutLabel->plainText(); |
|
123 } |
|
124 |
|
125 |
|
126 /*! |
|
127 CpDivertSelectionCustomitem::setTimeoutText. |
|
128 */ |
|
129 void CpDivertSelectionCustomitem::setTimeoutText( const QString& text ) |
|
130 { |
|
131 DPRINT << text; |
|
132 timeoutLabel->setPlainText(text); |
|
133 |
|
134 if (text != QString("")) { |
|
135 timeoutLabel->show(); |
|
136 timeoutValueLabel->show(); |
|
137 |
|
138 } else { |
|
139 timeoutLabel->hide(); |
|
140 timeoutValueLabel->hide(); |
|
141 } |
|
142 } |
|
143 |
|
144 |
|
145 /*! |
|
146 CpDivertSelectionCustomitem::state. |
|
147 */ |
|
148 int CpDivertSelectionCustomitem::state() const |
|
149 { |
|
150 DPRINT << m_state; |
|
151 return m_state; |
|
152 } |
|
153 |
|
154 |
|
155 /*! |
|
156 CpDivertSelectionCustomitem::setState. |
|
157 */ |
|
158 void CpDivertSelectionCustomitem::setState(int state) |
|
159 { |
|
160 DPRINT << state; |
|
161 m_state = state; |
|
162 updateCheckState(); |
|
163 } |
|
164 |
|
165 |
|
166 /*! |
|
167 CpDivertSelectionCustomitem::updateCheckState. |
|
168 */ |
|
169 void CpDivertSelectionCustomitem::updateCheckState() |
|
170 { |
|
171 DPRINT << m_state; |
|
172 |
|
173 switch (m_state) { |
|
174 case Enabled: |
|
175 checkbox->setCheckState(Qt::Checked); |
|
176 break; |
|
177 case Deactivated: |
|
178 setNumber(QString("")); |
|
179 setTimeout(0); |
|
180 //intended fall-through |
|
181 case Disabled: |
|
182 checkbox->setCheckState(Qt::Unchecked); |
|
183 break; |
|
184 default: |
|
185 break; |
|
186 } |
|
187 } |
|
188 |
|
189 // End of File. |
|