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#include "eventoccurrenceeditpage.h"
41
42#include <QtWidgets>
43#include <QtOrganizer/qorganizer.h>
44
45QTORGANIZER_USE_NAMESPACE
46
47EventOccurrenceEditPage::EventOccurrenceEditPage(QWidget *parent)
48 :QWidget(parent),
49 m_manager(0),
50 scrollAreaLayout(0),
51 m_typeComboBox(0),
52 m_subjectEdit(0),
53 m_countSpinBox(0),
54 m_repeatUntilDate(0)
55{
56 //create asynch request to save an item
57 m_saveItemRequest = new QOrganizerItemSaveRequest(this);
58 // Create widgets
59 QLabel *subjectLabel = new QLabel("Subject:", this);
60 m_subjectEdit = new QLineEdit(this);
61 QLabel *startTimeLabel = new QLabel("Start time:", this);
62 m_startTimeEdit = new QDateTimeEdit(this);
63 m_startTimeEdit->setDisplayFormat(QString("yyyy-MM-dd hh:mm:ss AP"));
64 QLabel *endTimeLabel = new QLabel("End time:", this);
65 m_endTimeEdit = new QDateTimeEdit(this);
66 m_endTimeEdit->setDisplayFormat(QString("yyyy-MM-dd hh:mm:ss AP"));
67
68 // Add push buttons
69 QHBoxLayout* hbLayout = new QHBoxLayout();
70 QPushButton *okButton = new QPushButton("Ok", this);
71 connect(sender: okButton,SIGNAL(clicked()),receiver: this,SLOT(saveOrNextClicked()));
72 hbLayout->addWidget(okButton);
73 QPushButton *cancelButton = new QPushButton("Cancel", this);
74 connect(sender: cancelButton,SIGNAL(clicked()),receiver: this,SLOT(cancelClicked()));
75 hbLayout->addWidget(cancelButton);
76
77 scrollAreaLayout = new QVBoxLayout();
78 scrollAreaLayout->addWidget(subjectLabel);
79 scrollAreaLayout->addWidget(m_subjectEdit);
80 scrollAreaLayout->addWidget(startTimeLabel);
81 scrollAreaLayout->addWidget(m_startTimeEdit);
82 scrollAreaLayout->addWidget(endTimeLabel);
83 scrollAreaLayout->addWidget(m_endTimeEdit);
84 scrollAreaLayout->addStretch();
85 scrollAreaLayout->addLayout(layout: hbLayout);
86
87 QScrollArea *scrollArea = new QScrollArea(this);
88 scrollArea->setWidgetResizable(true);
89 QWidget *formContainer = new QWidget(scrollArea);
90 formContainer->setLayout(scrollAreaLayout);
91 scrollArea->setWidget(formContainer);
92
93 QVBoxLayout *mainLayout = new QVBoxLayout();
94 mainLayout->addWidget(scrollArea);
95 setLayout(mainLayout);
96
97 m_countFieldAdded = false;
98 m_multipleEntries = false;
99 m_listOfEvents.clear();
100}
101
102EventOccurrenceEditPage::~EventOccurrenceEditPage()
103{
104
105}
106
107void EventOccurrenceEditPage::eventOccurrenceChanged(QOrganizerManager *manager, const QOrganizerEventOccurrence &eventOccurrence)
108{
109 m_manager = manager;
110 m_organizerEventOccurrence = eventOccurrence;
111 m_subjectEdit->setText(eventOccurrence.displayLabel());
112 m_startTimeEdit->setDateTime(eventOccurrence.startDateTime());
113 m_endTimeEdit->setDateTime(eventOccurrence.endDateTime());
114}
115
116void EventOccurrenceEditPage::cancelClicked()
117{
118 emit showDayPage();
119}
120
121void EventOccurrenceEditPage::saveOrNextClicked()
122{
123 QDateTime start(m_startTimeEdit->dateTime());
124 QDateTime end(m_endTimeEdit->dateTime());
125 if (start > end) {
126 QMessageBox::warning(parent: this, title: "Failed!", text: "Start date is not before end date");
127 return;
128 }
129
130 m_organizerEventOccurrence.setDisplayLabel(m_subjectEdit->text());
131 m_organizerEventOccurrence.setStartDateTime(start);
132 m_organizerEventOccurrence.setEndDateTime(end);
133 m_listOfEvents.append(t: m_organizerEventOccurrence);
134 if(m_numOfEntiresToBeCreated > 1){
135 m_numOfEntiresToBeCreated--;
136 // Clear subject field indicating its a new editor.
137 m_subjectEdit->clear();
138 } else {
139 if(!m_multipleEntries){
140 // If single entry
141 m_manager->saveItem(item: &m_organizerEventOccurrence);
142 } else {
143 // If multiple entries, save asynchronously.
144 m_saveItemRequest->setItems(m_listOfEvents);
145 m_saveItemRequest->setManager(m_manager);
146 m_saveItemRequest->start();
147 }
148
149 if (m_manager->error())
150 QMessageBox::warning(parent: this, title: "Failed!", text: QString("Failed to save event occurrence!\n(error code %1)").arg(a: m_manager->error()));
151 else
152 emit showDayPage();
153 }
154}
155
156void EventOccurrenceEditPage::showEvent(QShowEvent *event)
157{
158 window()->setWindowTitle("Edit event occurrence");
159 QWidget::showEvent(event);
160}
161
162

source code of qtpim/examples/organizer/calendardemo/src/eventoccurrenceeditpage.cpp