journaleditpage.cpp Example File
calendardemo/src/journaleditpage.cpp
#include "journaleditpage.h"
#include <QtGui>
#include <QComboBox>
#include <qtorganizer.h>
QTM_USE_NAMESPACE
JournalEditPage::JournalEditPage(QWidget *parent)
:QWidget(parent),
m_manager(0),
m_subjectEdit(0),
m_timeEdit(0),
m_alarmComboBox(0)
{
QLabel *subjectLabel = new QLabel("Subject:", this);
m_subjectEdit = new QLineEdit(this);
QLabel *startTimeLabel = new QLabel("Time:", this);
m_timeEdit = new QDateTimeEdit(this);
QLabel *alarmLabel = new QLabel("Alarm:", this);
m_alarmComboBox = new QComboBox(this);
QStringList alarmList;
alarmList << "None"
<< "0 minutes before"
<< "5 minutes before"
<< "15 minutes before"
<< "30 minutes before"
<< "1 hour before";
m_alarmComboBox->addItems(alarmList);
connect(m_alarmComboBox, SIGNAL(currentIndexChanged(const QString)), this,
SLOT(handleAlarmIndexChanged(const QString)));
#ifndef Q_OS_SYMBIAN
QHBoxLayout* hbLayout = new QHBoxLayout();
QPushButton *okButton = new QPushButton("Ok", this);
connect(okButton,SIGNAL(clicked()),this,SLOT(saveClicked()));
hbLayout->addWidget(okButton);
QPushButton *cancelButton = new QPushButton("Cancel", this);
connect(cancelButton,SIGNAL(clicked()),this,SLOT(cancelClicked()));
hbLayout->addWidget(cancelButton);
#endif
QVBoxLayout *scrollAreaLayout = new QVBoxLayout();
scrollAreaLayout->addWidget(subjectLabel);
scrollAreaLayout->addWidget(m_subjectEdit);
scrollAreaLayout->addWidget(startTimeLabel);
scrollAreaLayout->addWidget(m_timeEdit);
scrollAreaLayout->addWidget(alarmLabel);
scrollAreaLayout->addWidget(m_alarmComboBox);
scrollAreaLayout->addStretch();
#ifndef Q_OS_SYMBIAN
scrollAreaLayout->addLayout(hbLayout);
#endif
QScrollArea *scrollArea = new QScrollArea(this);
scrollArea->setWidgetResizable(true);
QWidget *formContainer = new QWidget(scrollArea);
formContainer->setLayout(scrollAreaLayout);
scrollArea->setWidget(formContainer);
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addWidget(scrollArea);
setLayout(mainLayout);
QAction* cancelSoftKey = new QAction("Cancel", this);
cancelSoftKey->setSoftKeyRole(QAction::NegativeSoftKey);
addAction(cancelSoftKey);
connect(cancelSoftKey, SIGNAL(triggered(bool)), this, SLOT(cancelClicked()));
QAction* saveSoftKey = new QAction("Save", this);
saveSoftKey->setSoftKeyRole(QAction::PositiveSoftKey);
addAction(saveSoftKey);
connect(saveSoftKey, SIGNAL(triggered(bool)), this, SLOT(saveClicked()));
}
JournalEditPage::~JournalEditPage()
{
}
void JournalEditPage::journalChanged(QOrganizerItemManager *manager, const QOrganizerJournal &journal)
{
m_manager = manager;
m_organizerJournal = journal;
m_subjectEdit->setText(journal.displayLabel());
m_timeEdit->setDateTime(journal.dateTime());
}
void JournalEditPage::cancelClicked()
{
emit showDayPage();
}
void JournalEditPage::saveClicked()
{
m_organizerJournal.setDisplayLabel(m_subjectEdit->text());
m_organizerJournal.setDateTime(m_timeEdit->dateTime());
m_manager->saveItem(&m_organizerJournal);
if (m_manager->error())
QMessageBox::warning(this, "Failed!", QString("Failed to save journal!\n(error code %1)").arg(m_manager->error()));
else
emit showDayPage();
}
void JournalEditPage::showEvent(QShowEvent *event)
{
window()->setWindowTitle("Edit journal");
QWidget::showEvent(event);
}
void JournalEditPage::handleAlarmIndexChanged(const QString time)
{
QOrganizerItemVisualReminder reminder;
reminder.setMessage(m_subjectEdit->text());
if (time == "None") {
QOrganizerItemVisualReminder fetchedReminder = m_organizerJournal.detail(QOrganizerItemVisualReminder::DefinitionName);
m_organizerJournal.removeDetail(&fetchedReminder);
return;
} else if (time == "0 minutes before") {
reminder.setDateTime(m_timeEdit->dateTime());
} else if (time == "5 minutes before") {
QDateTime reminderTime = m_timeEdit->dateTime().addSecs(-(5*60));
reminder.setDateTime(reminderTime);
} else if (time == "15 minutes before") {
QDateTime reminderTime = m_timeEdit->dateTime().addSecs(-(15*60));
reminder.setDateTime(reminderTime);
} else if (time == "30 minutes before") {
QDateTime reminderTime = m_timeEdit->dateTime().addSecs(-(30*60));
reminder.setDateTime(reminderTime);
} else if (time == "1 hour before") {
QDateTime reminderTime = m_timeEdit->dateTime().addSecs(-(60*60));
reminder.setDateTime(reminderTime);
}
m_organizerJournal.saveDetail(&reminder);
}