1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:BSD$
9** You may use this file under the terms of the BSD license as follows:
10**
11** "Redistribution and use in source and binary forms, with or without
12** modification, are permitted provided that the following conditions are
13** met:
14** * Redistributions of source code must retain the above copyright
15** notice, this list of conditions and the following disclaimer.
16** * Redistributions in binary form must reproduce the above copyright
17** notice, this list of conditions and the following disclaimer in
18** the documentation and/or other materials provided with the
19** distribution.
20** * Neither the name of The Qt Company Ltd nor the names of its
21** contributors may be used to endorse or promote products derived
22** from this software without specific prior written permission.
23**
24**
25** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include <QtWidgets>
42
43#include <QtOrganizer/qorganizer.h>
44
45#include "todoeditor.h"
46
47QTORGANIZER_USE_NAMESPACE
48
49TodoEditor::TodoEditor()
50{
51 setupGui();
52}
53
54//! [1]
55void TodoEditor::editTodo(const QOrganizerTodo &newTodo)
56{
57 todo = newTodo;
58
59 subjectLineEdit->setText(todo.displayLabel());
60 startDateEdit->setDateTime(todo.startDateTime());
61 dueDateEdit->setDateTime(todo.dueDateTime());
62 priorityCombo->setCurrentIndex(
63 priorityCombo->findData(data: QVariant(todo.priority())));
64 statusCombo->setCurrentIndex(
65 statusCombo->findData(data: QVariant(todo.status())));
66 descriptionTextEdit->setText(todo.description());
67//! [1]
68
69//! [2]
70 if (!todo.details(detailType: QOrganizerItemDetail::TypeVisualReminder).isEmpty()){
71 QOrganizerItemVisualReminder reminder =
72 todo.detail(detailType: QOrganizerItemDetail::TypeVisualReminder);
73 int seconds = reminder.secondsBeforeStart();
74 alarmCombo->setCurrentIndex(seconds/(15*60));
75 } else
76 alarmCombo->setCurrentIndex(0);
77}
78//! [2]
79
80//! [3]
81void TodoEditor::updateSubject()
82{
83 todo.setDisplayLabel(subjectLineEdit->text());
84}
85
86void TodoEditor::updateDescription()
87{
88 todo.setDescription(descriptionTextEdit->toPlainText());
89}
90//! [3]
91
92//! [4]
93void TodoEditor::updateDates()
94{
95 QDateTime startTime = startDateEdit->dateTime();
96 QDateTime dueDateTime = dueDateEdit->dateTime();
97
98 todo.setStartDateTime(startTime);
99 todo.setDueDateTime(dueDateTime);
100
101 updateAlarm(index: alarmCombo->currentIndex());
102}
103//! [4]
104
105//! [5]
106void TodoEditor::updateStatus(int index)
107{
108 QOrganizerTodoProgress::Status status =
109 (QOrganizerTodoProgress::Status) statusCombo->itemData(index).toInt();
110 todo.setStatus(status);
111}
112
113void TodoEditor::updatePriority(int index)
114{
115 QOrganizerItemPriority::Priority priority =
116 (QOrganizerItemPriority::Priority)
117 priorityCombo->itemData(index).toInt();
118 todo.setPriority(priority);
119}
120//! [5]
121
122//! [6]
123void TodoEditor::updateAlarm(int index)
124{
125 int seconds = index * (15*60);
126 QDateTime dueDate = todo.dueDateTime();
127
128 QOrganizerItemVisualReminder oldReminder =
129 todo.detail(detailType: QOrganizerItemDetail::TypeVisualReminder);
130 todo.removeDetail(detail: &oldReminder);
131
132 if (seconds == 0)
133 return;
134
135 QOrganizerItemVisualReminder reminder;
136 reminder.setSecondsBeforeStart(seconds);
137
138 todo.saveDetail(detail: &reminder);
139}
140//! [6]
141
142void TodoEditor::finishEditing()
143{
144 emit editingFinished(todo);
145}
146
147void TodoEditor::setupGui()
148{
149 startDateEdit = new QDateTimeEdit;
150 dueDateEdit = new QDateTimeEdit;
151 subjectLineEdit = new QLineEdit;
152 descriptionTextEdit = new QTextEdit;
153 doneButton = new QPushButton(tr(s: "Done"));
154
155 setupCombos();
156
157 connect(sender: startDateEdit, SIGNAL(editingFinished()),
158 receiver: this, SLOT(updateDates()));
159 connect(sender: dueDateEdit, SIGNAL(editingFinished()), receiver: this, SLOT(updateDates()));
160 connect(sender: subjectLineEdit, SIGNAL(editingFinished()),
161 receiver: this, SLOT(updateSubject()));
162 connect(sender: descriptionTextEdit, SIGNAL(textChanged()),
163 receiver: this, SLOT(updateDescription()));
164 connect(sender: statusCombo, SIGNAL(activated(int)), receiver: this, SLOT(updateStatus(int)));
165 connect(sender: priorityCombo, SIGNAL(activated(int)),
166 receiver: this, SLOT(updatePriority(int)));
167 connect(sender: alarmCombo, SIGNAL(activated(int)), receiver: this, SLOT(updateAlarm(int)));
168 connect(sender: doneButton, SIGNAL(clicked()), receiver: this, SLOT(finishEditing()));
169
170 QVBoxLayout *layout = new QVBoxLayout;
171 layout->addWidget(new QLabel(tr(s: "Subject:")));
172 layout->addWidget(subjectLineEdit);
173 layout->addWidget(new QLabel(tr(s: "Start Date:")));
174 layout->addWidget(startDateEdit);
175 layout->addWidget(new QLabel(tr(s: "Due Date:")));
176 layout->addWidget(dueDateEdit);
177 layout->addWidget(new QLabel(tr(s: "Status:")));
178 layout->addWidget(statusCombo);
179 layout->addWidget(new QLabel(tr(s: "Priority:")));
180 layout->addWidget(priorityCombo);
181 layout->addWidget(new QLabel(tr(s: "Alarm:")));
182 layout->addWidget(alarmCombo);
183 layout->addWidget(new QLabel(tr(s: "Description")));
184 layout->addWidget(descriptionTextEdit);
185 layout->addWidget(doneButton);
186
187 setLayout(layout);
188}
189
190//! [0]
191void TodoEditor::setupCombos()
192{
193 priorityCombo = new QComboBox;
194 priorityCombo->addItem(atext: "Unknown", auserData: QOrganizerItemPriority::UnknownPriority);
195 priorityCombo->addItem(atext: "Highest", auserData: QOrganizerItemPriority::HighestPriority);
196 priorityCombo->addItem(atext: "Extremely high",
197 auserData: QOrganizerItemPriority::ExtremelyHighPriority);
198 priorityCombo->addItem(atext: "Very high",
199 auserData: QOrganizerItemPriority::VeryHighPriority);
200 priorityCombo->addItem(atext: "High", auserData: QOrganizerItemPriority::HighPriority);
201 priorityCombo->addItem(atext: "Medium", auserData: QOrganizerItemPriority::MediumPriority);
202 priorityCombo->addItem(atext: "Low", auserData: QOrganizerItemPriority::LowPriority);
203 priorityCombo->addItem(atext: "Very low", auserData: QOrganizerItemPriority::VeryLowPriority);
204 priorityCombo->addItem(atext: "Extremely low",
205 auserData: QOrganizerItemPriority::ExtremelyLowPriority);
206 priorityCombo->addItem(atext: "Lowest", auserData: QOrganizerItemPriority::LowestPriority);
207
208 statusCombo = new QComboBox;
209 statusCombo->addItem(atext: "Not started",
210 auserData: QOrganizerTodoProgress::StatusNotStarted);
211 statusCombo->addItem(atext: "In progress", auserData: QOrganizerTodoProgress::StatusInProgress);
212 statusCombo->addItem(atext: "Complete",
213 auserData: QOrganizerTodoProgress::StatusComplete);
214
215 alarmCombo = new QComboBox;
216 QStringList alarmList;
217 alarmList << "None" << "15 minutes" << "30 minutes" << "45 minutes"
218 << "1 hour";
219 alarmCombo->addItems(texts: alarmList);
220}
221//! [0]
222
223

source code of qtpim/examples/organizer/todo/todoeditor.cpp