journalentry.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <qlabel.h>
00028 #include <qlayout.h>
00029
00030 #include <kdebug.h>
00031 #include <kglobal.h>
00032 #include <klocale.h>
00033 #include <ktextedit.h>
00034
00035 #include <libkcal/journal.h>
00036
00037 #include "journalentry.h"
00038 #include "journalentry.moc"
00039
00040 JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
00041 QFrame(parent)
00042 {
00043 mCalendar = calendar;
00044 mJournal = 0;
00045 mDirty = false;
00046
00047 mTitleLabel = new QLabel(i18n("Title"),this);
00048 mTitleLabel->setMargin(2);
00049 mTitleLabel->setAlignment(AlignCenter);
00050
00051 mEditor = new KTextEdit(this);
00052 connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty()));
00053
00054 QBoxLayout *topLayout = new QVBoxLayout(this);
00055 topLayout->addWidget(mTitleLabel);
00056 topLayout->addWidget(mEditor);
00057
00058 mEditor->installEventFilter(this);
00059 }
00060
00061 JournalEntry::~JournalEntry()
00062 {
00063 }
00064
00065 void JournalEntry::setDate(const QDate &date)
00066 {
00067 writeJournal();
00068
00069 mTitleLabel->setText(KGlobal::locale()->formatDate(date));
00070
00071
00072 mDate = date;
00073 }
00074
00075 void JournalEntry::setJournal(Journal *journal)
00076 {
00077 writeJournal();
00078
00079 mJournal = journal;
00080
00081 mEditor->setText(mJournal->description());
00082
00083 mDirty = false;
00084 }
00085
00086 Journal *JournalEntry::journal() const
00087 {
00088 return mJournal;
00089 }
00090
00091 void JournalEntry::setDirty()
00092 {
00093 mDirty = true;
00094
00095 }
00096
00097 void JournalEntry::clear()
00098 {
00099 mJournal = 0;
00100 mEditor->setText("");
00101 }
00102
00103 bool JournalEntry::eventFilter( QObject *o, QEvent *e )
00104 {
00105
00106
00107 if ( e->type() == QEvent::FocusOut ) {
00108 writeJournal();
00109 }
00110 return QFrame::eventFilter( o, e );
00111 }
00112
00113 void JournalEntry::writeJournal()
00114 {
00115
00116
00117 if (!mDirty) return;
00118
00119 if (mEditor->text().isEmpty()) return;
00120
00121
00122
00123 if (!mJournal) {
00124 mJournal = new Journal;
00125 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
00126 mCalendar->addJournal(mJournal);
00127 }
00128
00129 mJournal->setDescription(mEditor->text());
00130
00131 mDirty = false;
00132 }
00133
00134 void JournalEntry::flushEntry()
00135 {
00136 if (!mDirty) return;
00137
00138 writeJournal();
00139 }
This file is part of the documentation for kdelibs Version 3.1.5.