|
1 /* |
|
2 * Copyright (c) 2010 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 <QGraphicsLinearLayout> |
|
19 #include <HbPushButton> |
|
20 #include <HbDialog> |
|
21 #include <HbLabel> |
|
22 #include <HbDateTimePicker> |
|
23 #include <HbAction> |
|
24 #include <HbExtendedLocale> |
|
25 |
|
26 #include "nmipssettingstimeeditor.h" |
|
27 |
|
28 /*! |
|
29 \class NmIpsSettingsTimeEditor |
|
30 \brief The class implements a custom HbDataFormViewItem for selecting time with a tumbler. |
|
31 |
|
32 */ |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 /*! |
|
37 Constructor of NmIpsSettingsTimeEditor. |
|
38 */ |
|
39 NmIpsSettingsTimeEditor::NmIpsSettingsTimeEditor(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
40 : HbWidget(parent, wFlags), |
|
41 mButton(0), |
|
42 mTimePickerDialog(0) |
|
43 { |
|
44 // Create widget layout. |
|
45 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical); |
|
46 this->setLayout(layout); // Takes ownership |
|
47 |
|
48 // Create label. |
|
49 mButton = new HbPushButton(); |
|
50 layout->addItem(mButton); // Takes ownership |
|
51 |
|
52 connect( mButton, SIGNAL(clicked()), |
|
53 this, SLOT(launchTimePicker())); |
|
54 } |
|
55 |
|
56 /*! |
|
57 Destructor of NmIpsSettingsTimeEditor. |
|
58 */ |
|
59 NmIpsSettingsTimeEditor::~NmIpsSettingsTimeEditor() |
|
60 { |
|
61 delete mTimePickerDialog; |
|
62 } |
|
63 |
|
64 /*! |
|
65 Returns the currently set time. |
|
66 \return The time. |
|
67 */ |
|
68 QTime NmIpsSettingsTimeEditor::time() const |
|
69 { |
|
70 return mTime; |
|
71 } |
|
72 |
|
73 /*! |
|
74 Sets the current time. |
|
75 \param time The time to set. |
|
76 */ |
|
77 void NmIpsSettingsTimeEditor::setTime(QTime time) |
|
78 { |
|
79 mTime = time; |
|
80 mButton->setText(mTime.toString(timeFormat())); |
|
81 } |
|
82 |
|
83 /*! |
|
84 Returns the selection dialog heading label. |
|
85 \return The heading label. |
|
86 */ |
|
87 QString NmIpsSettingsTimeEditor::heading() const |
|
88 { |
|
89 return mLabel; |
|
90 } |
|
91 |
|
92 /*! |
|
93 Sets the time selection dialog heading label. |
|
94 \param label The label to set. |
|
95 */ |
|
96 void NmIpsSettingsTimeEditor::setHeading(QString label) |
|
97 { |
|
98 mLabel = label; |
|
99 } |
|
100 |
|
101 |
|
102 /*! |
|
103 Launches the time picker dialog. |
|
104 */ |
|
105 void NmIpsSettingsTimeEditor::launchTimePicker() |
|
106 { |
|
107 if (mTimePickerDialog) { |
|
108 delete mTimePickerDialog; |
|
109 mTimePickerDialog = 0; |
|
110 } |
|
111 |
|
112 // Create the dialog. |
|
113 mTimePickerDialog = new HbDialog(); |
|
114 mTimePickerDialog->setTimeout(HbDialog::NoTimeout); |
|
115 mTimePickerDialog->setDismissPolicy(HbDialog::NoDismiss); |
|
116 |
|
117 // Set the heading for the dialog. |
|
118 HbLabel *timeLabel = new HbLabel(mLabel, mTimePickerDialog); |
|
119 mTimePickerDialog->setHeadingWidget(timeLabel); |
|
120 |
|
121 // Create the tumbler. |
|
122 HbDateTimePicker *timePicker = new HbDateTimePicker(mTimePickerDialog); |
|
123 |
|
124 // Set the tumbler as the content widget. |
|
125 mTimePickerDialog->setContentWidget(timePicker); |
|
126 |
|
127 // Set tumbler data. |
|
128 timePicker->setDisplayFormat(timeFormat()); |
|
129 timePicker->setTime(mTime); |
|
130 |
|
131 // Set dialog actions. |
|
132 HbAction *okAction = new HbAction(QString(hbTrId("txt_common_button_ok")), mTimePickerDialog); |
|
133 mTimePickerDialog->setPrimaryAction(okAction); |
|
134 |
|
135 HbAction *cancelAction = new HbAction(QString(hbTrId("txt_common_button_cancel")), |
|
136 mTimePickerDialog); |
|
137 mTimePickerDialog->setSecondaryAction( cancelAction ); |
|
138 |
|
139 // Show the dialog. |
|
140 mTimePickerDialog->open(this, SLOT(handleTimeAction(HbAction *))); |
|
141 } |
|
142 |
|
143 /*! |
|
144 Handles the action from the time picker dialog. |
|
145 */ |
|
146 void NmIpsSettingsTimeEditor::handleTimeAction(HbAction *action) |
|
147 { |
|
148 if (action == mTimePickerDialog->primaryAction()) { |
|
149 // Get the time from the picker. |
|
150 QTime newTime = static_cast<HbDateTimePicker *> (mTimePickerDialog->contentWidget())->time(); |
|
151 |
|
152 // Store the new time. |
|
153 setTime(newTime); |
|
154 |
|
155 // Emit the signal. |
|
156 emit timeChanged(newTime); |
|
157 } |
|
158 } |
|
159 |
|
160 /*! |
|
161 Returns locale specific formatting string for hours and minutes. |
|
162 \return Time format string. |
|
163 */ |
|
164 QString NmIpsSettingsTimeEditor::timeFormat() |
|
165 { |
|
166 // Set the correct time format string based on locale. |
|
167 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
168 QString timeFormat("h:mm ap"); |
|
169 if (HbExtendedLocale::Time24 == locale.timeStyle()) { |
|
170 timeFormat = QString("h:mm"); |
|
171 } |
|
172 // Set the separator between hours and minutes. |
|
173 timeFormat.replace(QString(":"), locale.timeSeparator(1)); |
|
174 |
|
175 return timeFormat; |
|
176 } |