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 #include <libkcal/calendarresources.h>
00037 #include <libkcal/resourcecalendar.h>
00038
00039 #include "kodialogmanager.h"
00040
00041 #include "journalentry.h"
00042 #include "journalentry.moc"
00043
00044 JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
00045 QFrame(parent)
00046 {
00047 mCalendar = calendar;
00048 mJournal = 0;
00049 mDirty = false;
00050
00051 mTitleLabel = new QLabel(i18n("Title"),this);
00052 mTitleLabel->setMargin(2);
00053 mTitleLabel->setAlignment(AlignCenter);
00054
00055 mEditor = new KTextEdit(this);
00056 connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty()));
00057
00058 QBoxLayout *topLayout = new QVBoxLayout(this);
00059 topLayout->addWidget(mTitleLabel);
00060 topLayout->addWidget(mEditor);
00061
00062 mEditor->installEventFilter(this);
00063 }
00064
00065 JournalEntry::~JournalEntry()
00066 {
00067 }
00068
00069 void JournalEntry::setDate(const QDate &date)
00070 {
00071 writeJournal();
00072
00073 mTitleLabel->setText(KGlobal::locale()->formatDate(date));
00074
00075
00076 mDate = date;
00077 }
00078
00079 void JournalEntry::setJournal(Journal *journal)
00080 {
00081 writeJournal();
00082
00083 mJournal = journal;
00084
00085 mEditor->setText(mJournal->description());
00086
00087 mDirty = false;
00088 }
00089
00090 Journal *JournalEntry::journal() const
00091 {
00092 return mJournal;
00093 }
00094
00095 void JournalEntry::setDirty()
00096 {
00097 mDirty = true;
00098
00099 }
00100
00101 void JournalEntry::clear()
00102 {
00103 mJournal = 0;
00104 mEditor->setText("");
00105 }
00106
00107 bool JournalEntry::eventFilter( QObject *o, QEvent *e )
00108 {
00109
00110
00111 if ( e->type() == QEvent::FocusOut ) {
00112 writeJournal();
00113 }
00114 return QFrame::eventFilter( o, e );
00115 }
00116
00117 void JournalEntry::writeJournal()
00118 {
00119
00120
00121 if (!mDirty) return;
00122
00123 if (mEditor->text().isEmpty()) {
00124 mCalendar->deleteJournal( mJournal );
00125 delete mJournal;
00126 mJournal = 0;
00127 return;
00128 }
00129
00130
00131
00132 if (!mJournal) {
00133 mJournal = new Journal;
00134 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
00135 if ( !mCalendar->addJournal( mJournal ) ) {
00136 KODialogManager::errorSaveJournal( this );
00137 delete mJournal;
00138 mJournal = 0;
00139 return;
00140 }
00141 }
00142
00143 mJournal->setDescription(mEditor->text());
00144
00145 mDirty = false;
00146 }
00147
00148 void JournalEntry::flushEntry()
00149 {
00150 if (!mDirty) return;
00151
00152 writeJournal();
00153 }
This file is part of the documentation for korganizer Library Version 3.2.2.