korganizer Library API Documentation

journalentry.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 //
00025 // Journal Entry
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 //  kdDebug() << "JournalEntry::setDirty()" << endl;
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 //  kdDebug() << "JournalEntry::event received " << e->type() << endl;
00106 
00107   if ( e->type() == QEvent::FocusOut ) {
00108     writeJournal();
00109   }
00110   return QFrame::eventFilter( o, e );    // standard event processing
00111 }
00112 
00113 void JournalEntry::writeJournal()
00114 {
00115 //  kdDebug() << "JournalEntry::writeJournal()" << endl;
00116 
00117   if (!mDirty) return;
00118  
00119   if (mEditor->text().isEmpty()) return;
00120  
00121 //  kdDebug() << "JournalEntry::writeJournal()..." << endl;
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 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:08 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001