summaryrefslogtreecommitdiffabout
path: root/korganizer/journalentry.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (side-by-side diff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /korganizer/journalentry.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'korganizer/journalentry.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/journalentry.cpp170
1 files changed, 170 insertions, 0 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp
new file mode 100644
index 0000000..d1d7946
--- a/dev/null
+++ b/korganizer/journalentry.cpp
@@ -0,0 +1,170 @@
+/*
+ This file is part of KOrganizer.
+ Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+//
+// Journal Entry
+
+#include <qlabel.h>
+#include <qlayout.h>
+
+#include <kdebug.h>
+#include <kglobal.h>
+#include <klocale.h>
+#include <ktextedit.h>
+#include "koprefs.h"
+
+#include <libkcal/journal.h>
+#include <libkcal/calendarresources.h>
+#include <libkcal/resourcecalendar.h>
+#include <kresources/resourceselectdialog.h>
+
+#include "journalentry.h"
+#include "journalentry.moc"
+#ifndef DESKTOP_VERSION
+#include <qpe/qpeapplication.h>
+#endif
+JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
+ QFrame(parent)
+{
+ mCalendar = calendar;
+ mJournal = 0;
+ mDirty = false;
+
+ mTitleLabel = new QLabel(i18n("Title"),this);
+ mTitleLabel->setMargin(2);
+ mTitleLabel->setAlignment(AlignCenter);
+
+ mEditor = new KTextEdit(this);
+ connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty()));
+#ifndef DESKTOP_VERSION
+ QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold );
+#endif
+ mEditor->setWordWrap( KTextEdit::WidgetWidth );
+ QBoxLayout *topLayout = new QVBoxLayout(this);
+ topLayout->addWidget(mTitleLabel);
+ topLayout->addWidget(mEditor);
+ mEditor->installEventFilter(this);
+}
+
+JournalEntry::~JournalEntry()
+{
+}
+
+void JournalEntry::setDate(const QDate &date)
+{
+ writeJournal();
+
+ mTitleLabel->setText(KGlobal::locale()->formatDate(date));
+
+
+ mDate = date;
+}
+
+void JournalEntry::setJournal(Journal *journal)
+{
+ writeJournal();
+
+ mJournal = journal;
+
+ mEditor->setText(mJournal->description());
+
+ mDirty = false;
+}
+
+Journal *JournalEntry::journal() const
+{
+ return mJournal;
+}
+
+void JournalEntry::setDirty()
+{
+ mDirty = true;
+
+// kdDebug() << "JournalEntry::setDirty()" << endl;
+}
+
+void JournalEntry::clear()
+{
+ mJournal = 0;
+ mEditor->setText("");
+}
+
+bool JournalEntry::eventFilter( QObject *o, QEvent *e )
+{
+// kdDebug() << "JournalEntry::event received " << e->type() << endl;
+
+ if ( e->type() == QEvent::FocusOut ) {
+ writeJournal();
+ }
+ if ( e->type() == QEvent::KeyPress ) {
+ QKeyEvent * k = (QKeyEvent *) e;
+ if ( k->state() == Qt::ControlButton ) {
+ k->ignore();
+ //return true;
+ }
+ }
+
+ return QFrame::eventFilter( o, e ); // standard event processing
+}
+
+void JournalEntry::writeJournal()
+{
+// kdDebug() << "JournalEntry::writeJournal()" << endl;
+ if (!mDirty) return;
+
+ if (mEditor->text().isEmpty()) {
+ if ( mJournal ) {
+ mDirty = false;
+ bool conf = KOPrefs::instance()->mConfirm;
+ KOPrefs::instance()->mConfirm = false;
+ emit deleteJournal(mJournal);
+ KOPrefs::instance()->mConfirm = conf;
+ mJournal = 0;
+ }
+ return;
+ }
+
+// kdDebug() << "JournalEntry::writeJournal()..." << endl;
+
+ if (!mJournal) {
+ mJournal = new Journal;
+ mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
+ mCalendar->addJournal(mJournal);
+ }
+
+ mJournal->setDescription(mEditor->text());
+
+ mDirty = false;
+}
+
+void JournalEntry::flushEntry()
+{
+ if (!mDirty) return;
+
+ writeJournal();
+}
+void JournalEntry::keyPressEvent ( QKeyEvent * e )
+{
+ e->ignore();
+
+}