summaryrefslogtreecommitdiffabout
path: root/korganizer/journalentry.cpp
Unidiff
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 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24//
25// Journal Entry
26
27#include <qlabel.h>
28#include <qlayout.h>
29
30#include <kdebug.h>
31#include <kglobal.h>
32#include <klocale.h>
33#include <ktextedit.h>
34#include "koprefs.h"
35
36#include <libkcal/journal.h>
37#include <libkcal/calendarresources.h>
38#include <libkcal/resourcecalendar.h>
39#include <kresources/resourceselectdialog.h>
40
41#include "journalentry.h"
42#include "journalentry.moc"
43#ifndef DESKTOP_VERSION
44#include <qpe/qpeapplication.h>
45#endif
46JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
47 QFrame(parent)
48{
49 mCalendar = calendar;
50 mJournal = 0;
51 mDirty = false;
52
53 mTitleLabel = new QLabel(i18n("Title"),this);
54 mTitleLabel->setMargin(2);
55 mTitleLabel->setAlignment(AlignCenter);
56
57 mEditor = new KTextEdit(this);
58 connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty()));
59#ifndef DESKTOP_VERSION
60 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold );
61#endif
62 mEditor->setWordWrap( KTextEdit::WidgetWidth );
63 QBoxLayout *topLayout = new QVBoxLayout(this);
64 topLayout->addWidget(mTitleLabel);
65 topLayout->addWidget(mEditor);
66 mEditor->installEventFilter(this);
67}
68
69JournalEntry::~JournalEntry()
70{
71}
72
73void JournalEntry::setDate(const QDate &date)
74{
75 writeJournal();
76
77 mTitleLabel->setText(KGlobal::locale()->formatDate(date));
78
79
80 mDate = date;
81}
82
83void JournalEntry::setJournal(Journal *journal)
84{
85 writeJournal();
86
87 mJournal = journal;
88
89 mEditor->setText(mJournal->description());
90
91 mDirty = false;
92}
93
94Journal *JournalEntry::journal() const
95{
96 return mJournal;
97}
98
99void JournalEntry::setDirty()
100{
101 mDirty = true;
102
103// kdDebug() << "JournalEntry::setDirty()" << endl;
104}
105
106void JournalEntry::clear()
107{
108 mJournal = 0;
109 mEditor->setText("");
110}
111
112bool JournalEntry::eventFilter( QObject *o, QEvent *e )
113{
114// kdDebug() << "JournalEntry::event received " << e->type() << endl;
115
116 if ( e->type() == QEvent::FocusOut ) {
117 writeJournal();
118 }
119 if ( e->type() == QEvent::KeyPress ) {
120 QKeyEvent * k = (QKeyEvent *) e;
121 if ( k->state() == Qt::ControlButton ) {
122 k->ignore();
123 //return true;
124 }
125 }
126
127 return QFrame::eventFilter( o, e ); // standard event processing
128}
129
130void JournalEntry::writeJournal()
131{
132// kdDebug() << "JournalEntry::writeJournal()" << endl;
133 if (!mDirty) return;
134
135 if (mEditor->text().isEmpty()) {
136 if ( mJournal ) {
137 mDirty = false;
138 bool conf = KOPrefs::instance()->mConfirm;
139 KOPrefs::instance()->mConfirm = false;
140 emit deleteJournal(mJournal);
141 KOPrefs::instance()->mConfirm = conf;
142 mJournal = 0;
143 }
144 return;
145 }
146
147// kdDebug() << "JournalEntry::writeJournal()..." << endl;
148
149 if (!mJournal) {
150 mJournal = new Journal;
151 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
152 mCalendar->addJournal(mJournal);
153 }
154
155 mJournal->setDescription(mEditor->text());
156
157 mDirty = false;
158}
159
160void JournalEntry::flushEntry()
161{
162 if (!mDirty) return;
163
164 writeJournal();
165}
166void JournalEntry::keyPressEvent ( QKeyEvent * e )
167{
168 e->ignore();
169
170}