summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/journalentry.cpp19
-rw-r--r--korganizer/journalentry.h2
-rw-r--r--korganizer/kojournalview.cpp19
3 files changed, 31 insertions, 9 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp
index add874f..395392c 100644
--- a/korganizer/journalentry.cpp
+++ b/korganizer/journalentry.cpp
@@ -1,268 +1,275 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 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 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. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24// 24//
25// Journal Entry 25// Journal Entry
26 26
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qvbox.h> 29#include <qvbox.h>
30#include <qfile.h> 30#include <qfile.h>
31#include <qdir.h> 31#include <qdir.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qtextcodec.h> 33#include <qtextcodec.h>
34#include <qpixmap.h> 34#include <qpixmap.h>
35#include <qpushbutton.h> 35#include <qpushbutton.h>
36#include <qapplication.h> 36#include <qapplication.h>
37 37
38#include <kdebug.h> 38#include <kdebug.h>
39#include <kglobal.h> 39#include <kglobal.h>
40#include <klocale.h> 40#include <klocale.h>
41#include <ktextedit.h> 41#include <ktextedit.h>
42#include <kfiledialog.h> 42#include <kfiledialog.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44#include "koprefs.h" 44#include "koprefs.h"
45#include <klineedit.h> 45#include <klineedit.h>
46 46
47#include <libkcal/journal.h> 47#include <libkcal/journal.h>
48#include <libkcal/calendarresources.h> 48#include <libkcal/calendarresources.h>
49#include <libkcal/resourcecalendar.h> 49#include <libkcal/resourcecalendar.h>
50#include <kresources/resourceselectdialog.h> 50#include <kresources/resourceselectdialog.h>
51 51
52#include "journalentry.h" 52#include "journalentry.h"
53//#include "journalentry.moc" 53//#include "journalentry.moc"
54#ifndef DESKTOP_VERSION 54#ifndef DESKTOP_VERSION
55#include <qpe/qpeapplication.h> 55#include <qpe/qpeapplication.h>
56#endif 56#endif
57JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : 57JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
58 QFrame(parent) 58 QFrame(parent)
59{ 59{
60 heiHint = QApplication::desktop()->height() / 5 ; 60 heiHint = QApplication::desktop()->height() / 5 ;
61 showOnlyMode = false; 61 showOnlyMode = false;
62 mCalendar = calendar; 62 mCalendar = calendar;
63 mJournal = 0; 63 mJournal = 0;
64 64 visibleMode = true;
65 QHBox * vb = new QHBox ( this ); 65 QHBox * vb = new QHBox ( this );
66 QPixmap iconp; 66 QPixmap iconp;
67 67
68 QPushButton * toggleJournal = new QPushButton( vb ); 68 QPushButton * toggleJournal = new QPushButton( vb );
69 iconp = SmallIcon("1updownarrow"); 69 iconp = SmallIcon("1updownarrow");
70 toggleJournal->setPixmap (iconp ) ; 70 toggleJournal->setPixmap (iconp ) ;
71 new QLabel(i18n(" Title: "),vb); 71 new QLabel(i18n(" Title: "),vb);
72 mTitle = new KLineEdit ( vb ); 72 mTitle = new KLineEdit ( vb );
73 mTitleLabel = new QLabel(i18n("Title"),vb); 73 mTitleLabel = new QLabel(i18n("Title"),vb);
74 mTitleLabel->setMargin(0); 74 mTitleLabel->setMargin(0);
75 mTitleLabel->setAlignment(AlignCenter); 75 mTitleLabel->setAlignment(AlignCenter);
76 QPushButton * loadTemplate = new QPushButton( vb ); 76 QPushButton * loadTemplate = new QPushButton( vb );
77 QPushButton * saveTemplate = new QPushButton( vb ); 77 QPushButton * saveTemplate = new QPushButton( vb );
78 if ( QApplication::desktop()->width() < 321 ) 78 if ( QApplication::desktop()->width() < 321 )
79 iconp = SmallIcon("fileexport16"); 79 iconp = SmallIcon("fileexport16");
80 else 80 else
81 iconp = SmallIcon("fileexport"); 81 iconp = SmallIcon("fileexport");
82 saveTemplate->setPixmap (iconp ) ; 82 saveTemplate->setPixmap (iconp ) ;
83 int size = saveTemplate->sizeHint().height(); 83 int size = saveTemplate->sizeHint().height();
84 if ( QApplication::desktop()->width() < 321 ) 84 if ( QApplication::desktop()->width() < 321 )
85 iconp = SmallIcon("fileimport16"); 85 iconp = SmallIcon("fileimport16");
86 else 86 else
87 iconp = SmallIcon("fileimport"); 87 iconp = SmallIcon("fileimport");
88 loadTemplate->setPixmap (iconp ) ; 88 loadTemplate->setPixmap (iconp ) ;
89 loadTemplate->setFixedSize( size, size ); 89 loadTemplate->setFixedSize( size, size );
90 saveTemplate->setFixedSize( size, size ); 90 saveTemplate->setFixedSize( size, size );
91 toggleJournal->setFixedSize( size , size ); 91 toggleJournal->setFixedSize( size , size );
92 mEditor = new KTextEdit(this); 92 mEditor = new KTextEdit(this);
93#ifndef DESKTOP_VERSION 93#ifndef DESKTOP_VERSION
94 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); 94 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold );
95#endif 95#endif
96 mEditor->setWordWrap( KTextEdit::WidgetWidth ); 96 mEditor->setWordWrap( KTextEdit::WidgetWidth );
97 QBoxLayout *topLayout = new QVBoxLayout(this); 97 QBoxLayout *topLayout = new QVBoxLayout(this);
98 topLayout->addWidget(vb); 98 topLayout->addWidget(vb);
99 topLayout->addWidget(mEditor); 99 topLayout->addWidget(mEditor);
100 mEditor->installEventFilter(this); 100 mEditor->installEventFilter(this);
101 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 101 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
102 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 102 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
103 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); 103 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) );
104} 104}
105 105
106JournalEntry::~JournalEntry() 106JournalEntry::~JournalEntry()
107{ 107{
108 //qDebug("JournalEntry::~JournalEntry() "); 108 //qDebug("JournalEntry::~JournalEntry() ");
109} 109}
110QSize JournalEntry::sizeHint() const 110QSize JournalEntry::sizeHint() const
111{ 111{
112 return QSize ( 240, heiHint ); 112 return QSize ( 240, heiHint );
113} 113}
114void JournalEntry::slotSaveTemplate() 114void JournalEntry::slotSaveTemplate()
115{ 115{
116 QString fileName =locateLocal( "templates", "journals" ); 116 QString fileName =locateLocal( "templates", "journals" );
117 QDir t_dir; 117 QDir t_dir;
118 if ( !t_dir.exists(fileName) ) 118 if ( !t_dir.exists(fileName) )
119 t_dir.mkdir ( fileName ); 119 t_dir.mkdir ( fileName );
120 fileName += "/journal"; 120 fileName += "/journal";
121 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); 121 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this );
122 if ( fileName.length() == 0 ) 122 if ( fileName.length() == 0 )
123 return; 123 return;
124 124
125 QFile fileIn( fileName ); 125 QFile fileIn( fileName );
126 if (!fileIn.open( IO_WriteOnly ) ) { 126 if (!fileIn.open( IO_WriteOnly ) ) {
127 KMessageBox::error( this, i18n("Error saving template file\n '%1'.") 127 KMessageBox::error( this, i18n("Error saving template file\n '%1'.")
128 .arg( fileName ) ); 128 .arg( fileName ) );
129 return; 129 return;
130 } 130 }
131 // QString text; 131 // QString text;
132 QTextStream tsIn( &fileIn ); 132 QTextStream tsIn( &fileIn );
133 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 133 tsIn.setCodec( QTextCodec::codecForName("utf8") );
134 tsIn << mEditor->text(); 134 tsIn << mEditor->text();
135 fileIn.close(); 135 fileIn.close();
136} 136}
137void JournalEntry::slotLoadTemplate() 137void JournalEntry::slotLoadTemplate()
138{ 138{
139 QString fileName =locateLocal( "templates", "journals" ); 139 QString fileName =locateLocal( "templates", "journals" );
140 QDir t_dir; 140 QDir t_dir;
141 if ( !t_dir.exists(fileName) ) 141 if ( !t_dir.exists(fileName) )
142 t_dir.mkdir ( fileName ); 142 t_dir.mkdir ( fileName );
143 fileName += "/journal"; 143 fileName += "/journal";
144 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); 144 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this );
145 if ( fileName.length() == 0 ) 145 if ( fileName.length() == 0 )
146 return; 146 return;
147 QFile fileIn( fileName ); 147 QFile fileIn( fileName );
148 if (!fileIn.open( IO_ReadOnly ) ) { 148 if (!fileIn.open( IO_ReadOnly ) ) {
149 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 149 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
150 .arg( fileName ) ); 150 .arg( fileName ) );
151 return; 151 return;
152 } 152 }
153 QTextStream tsIn( &fileIn ); 153 QTextStream tsIn( &fileIn );
154 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 154 tsIn.setCodec( QTextCodec::codecForName("utf8") );
155 QString text = tsIn.read(); 155 QString text = tsIn.read();
156 fileIn.close(); 156 fileIn.close();
157 int line, col; 157 int line, col;
158 mEditor->getCursorPosition (& line, & col ); 158 mEditor->getCursorPosition (& line, & col );
159 mEditor-> insertAt ( text, line, col, true ); 159 mEditor-> insertAt ( text, line, col, true );
160 //mEditor->setIgnoreMark( true ); 160 //mEditor->setIgnoreMark( true );
161} 161}
162void JournalEntry::setDate(const QDate &date) 162void JournalEntry::setDate(const QDate &date)
163{ 163{
164 showOnlyMode = false; 164 showOnlyMode = false;
165 mDate = date; 165 mDate = date;
166 writeJournal(); 166 writeJournal();
167 int id = mCalendar->defaultCalendar(); 167 int id = mCalendar->defaultCalendar();
168 QString calname = KOPrefs::instance()->getCalendar( id )->mName; 168 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
169 mTitleLabel->setText( " (" + calname +")"); 169 mTitleLabel->setText( " (" + calname +")");
170} 170}
171 171
172void JournalEntry::toggleShowJournal() 172void JournalEntry::toggleShowJournal()
173{ 173{
174 flushEntry(); 174 if (!mEditor->text().isEmpty() || !mTitle->text().isEmpty())
175 flushEntry();
175 if ( showOnlyMode ) 176 if ( showOnlyMode )
176 emit showJournalOnly( 0 ); 177 emit showJournalOnly( 0 );
177 else 178 else {
179 // we have to protect mJournal from deleting if mJournal has empty text
180 visibleMode = false; // set to true via :setShowOnly()
178 emit showJournalOnly( mJournal ); 181 emit showJournalOnly( mJournal );
182 }
179} 183}
180void JournalEntry::setShowOnly() 184void JournalEntry::setShowOnly()
181{ 185{
182 showOnlyMode = true; 186 showOnlyMode = true;
183 mEditor->setFocus(); 187 mEditor->setFocus();
188 visibleMode = true;
184} 189}
185void JournalEntry::setJournal(Journal *journal) 190void JournalEntry::setJournal(Journal *journal)
186{ 191{
187 writeJournal(); 192 writeJournal();
188 193
189 mJournal = journal; 194 mJournal = journal;
190 if ( journal->isReadOnly() ) 195 if ( journal->isReadOnly() )
191 mTitle->setText(mJournal->summary()+" ("+i18n("readonly")+")"); 196 mTitle->setText(mJournal->summary()+" ("+i18n("readonly")+")");
192 else 197 else
193 mTitle->setText(mJournal->summary()); 198 mTitle->setText(mJournal->summary());
194 mEditor->setText(mJournal->description()); 199 mEditor->setText(mJournal->description());
195 mTitle->setReadOnly (journal->isReadOnly() ); 200 mTitle->setReadOnly (journal->isReadOnly() );
196 mEditor->setReadOnly ( journal->isReadOnly() ); 201 mEditor->setReadOnly ( journal->isReadOnly() );
197 int id = mJournal->calID(); 202 int id = mJournal->calID();
198 203
199 QString calname = KOPrefs::instance()->getCalendar( id )->mName; 204 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
200 mTitleLabel->setText( " (" + calname +")"); 205 mTitleLabel->setText( " (" + calname +")");
201 206
202} 207}
203 208
204Journal *JournalEntry::journal() const 209Journal *JournalEntry::journal() const
205{ 210{
206 return mJournal; 211 return mJournal;
207} 212}
208 213
209 214
210void JournalEntry::clear() 215void JournalEntry::clear()
211{ 216{
212 mJournal = 0; 217 mJournal = 0;
213 mEditor->setText(""); 218 mEditor->setText("");
219 mTitle->setText("");
214} 220}
215 221
216bool JournalEntry::eventFilter( QObject *o, QEvent *e ) 222bool JournalEntry::eventFilter( QObject *o, QEvent *e )
217{ 223{
218// kdDebug() << "JournalEntry::event received " << e->type() << endl; 224// kdDebug() << "JournalEntry::event received " << e->type() << endl;
219 225
220 if ( e->type() == QEvent::FocusOut ) { 226 if ( e->type() == QEvent::FocusOut ) {
221 writeJournal(); 227 writeJournal();
222 } 228 }
223 if ( e->type() == QEvent::KeyPress ) { 229 if ( e->type() == QEvent::KeyPress ) {
224 QKeyEvent * k = (QKeyEvent *) e; 230 QKeyEvent * k = (QKeyEvent *) e;
225 if ( k->state() == Qt::ControlButton ) { 231 if ( k->state() == Qt::ControlButton ) {
226 k->ignore(); 232 k->ignore();
227 //return true; 233 //return true;
228 } 234 }
229 } 235 }
230 236
231 return QFrame::eventFilter( o, e ); // standard event processing 237 return QFrame::eventFilter( o, e ); // standard event processing
232} 238}
233 239
234void JournalEntry::writeJournal() 240void JournalEntry::writeJournal()
235{ 241{
236 242 if ( !visibleMode ) return;
237 if (mEditor->text().isEmpty() && mTitle->text().isEmpty()) { 243 if (mEditor->text().isEmpty() && mTitle->text().isEmpty()) {
238 if ( mJournal ) { 244 if ( mJournal ) {
245 Journal* j = mJournal;
246 mJournal = 0;
239 bool conf = KOPrefs::instance()->mConfirm; 247 bool conf = KOPrefs::instance()->mConfirm;
240 KOPrefs::instance()->mConfirm = false; 248 KOPrefs::instance()->mConfirm = false;
241 emit deleteJournal(mJournal); 249 emit deleteJournal(j);
242 KOPrefs::instance()->mConfirm = conf; 250 KOPrefs::instance()->mConfirm = conf;
243 mJournal = 0;
244 } 251 }
245 return; 252 return;
246 } 253 }
247 254
248// kdDebug() << "JournalEntry::writeJournal()..." << endl; 255// kdDebug() << "JournalEntry::writeJournal()..." << endl;
249 256
250 if (!mJournal) { 257 if (!mJournal) {
251 mJournal = new Journal; 258 mJournal = new Journal;
252 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); 259 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
253 mCalendar->addJournal(mJournal); 260 mCalendar->addJournal(mJournal);
254 } 261 }
255 262
256 mJournal->setDescription(mEditor->text()); 263 mJournal->setDescription(mEditor->text());
257 mJournal->setSummary(mTitle->text()); 264 mJournal->setSummary(mTitle->text());
258} 265}
259 266
260void JournalEntry::flushEntry() 267void JournalEntry::flushEntry()
261{ 268{
262 writeJournal(); 269 writeJournal();
263} 270}
264void JournalEntry::keyPressEvent ( QKeyEvent * e ) 271void JournalEntry::keyPressEvent ( QKeyEvent * e )
265{ 272{
266 e->ignore(); 273 e->ignore();
267 274
268} 275}
diff --git a/korganizer/journalentry.h b/korganizer/journalentry.h
index f2db785..e98d018 100644
--- a/korganizer/journalentry.h
+++ b/korganizer/journalentry.h
@@ -1,81 +1,83 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 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 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. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef JOURNALENTRY_H 23#ifndef JOURNALENTRY_H
24#define JOURNALENTRY_H 24#define JOURNALENTRY_H
25// 25//
26// Widget showing one Journal entry 26// Widget showing one Journal entry
27 27
28#include <qframe.h> 28#include <qframe.h>
29 29
30#include <libkcal/calendar.h> 30#include <libkcal/calendar.h>
31 31
32class QLabel; 32class QLabel;
33class KTextEdit; 33class KTextEdit;
34class KLineEdit; 34class KLineEdit;
35 35
36using namespace KCal; 36using namespace KCal;
37 37
38class JournalEntry : public QFrame { 38class JournalEntry : public QFrame {
39 Q_OBJECT 39 Q_OBJECT
40 public: 40 public:
41 JournalEntry(Calendar *,QWidget *parent); 41 JournalEntry(Calendar *,QWidget *parent);
42 virtual ~JournalEntry(); 42 virtual ~JournalEntry();
43 43
44 void setJournal(Journal *); 44 void setJournal(Journal *);
45 Journal *journal() const; 45 Journal *journal() const;
46 46
47 void setDate(const QDate &); 47 void setDate(const QDate &);
48 48
49 void clear(); 49 void clear();
50 50
51 void flushEntry(); 51 void flushEntry();
52 void setShowOnly(); 52 void setShowOnly();
53 QSize sizeHint() const; 53 QSize sizeHint() const;
54 void setVisibleMode( bool b ) { visibleMode = b;}
54 55
55 protected slots: 56 protected slots:
56 void slotSaveTemplate(); 57 void slotSaveTemplate();
57 void slotLoadTemplate(); 58 void slotLoadTemplate();
58 void toggleShowJournal(); 59 void toggleShowJournal();
59 signals: 60 signals:
60 void deleteJournal(Journal *); 61 void deleteJournal(Journal *);
61 void newJournal(); 62 void newJournal();
62 void showJournalOnly( Journal * ); 63 void showJournalOnly( Journal * );
63 64
64 protected: 65 protected:
65 bool eventFilter( QObject *o, QEvent *e ); 66 bool eventFilter( QObject *o, QEvent *e );
66 67
67 void writeJournal(); 68 void writeJournal();
68 69
69 private: 70 private:
71 bool visibleMode;
70 bool showOnlyMode; 72 bool showOnlyMode;
71 Calendar *mCalendar; 73 Calendar *mCalendar;
72 Journal *mJournal; 74 Journal *mJournal;
73 QDate mDate; 75 QDate mDate;
74 void keyPressEvent ( QKeyEvent * ) ; 76 void keyPressEvent ( QKeyEvent * ) ;
75 QLabel *mTitleLabel; 77 QLabel *mTitleLabel;
76 KLineEdit * mTitle; 78 KLineEdit * mTitle;
77 KTextEdit *mEditor; 79 KTextEdit *mEditor;
78 int heiHint; 80 int heiHint;
79}; 81};
80 82
81#endif 83#endif
diff --git a/korganizer/kojournalview.cpp b/korganizer/kojournalview.cpp
index cb9a2c0..b659d53 100644
--- a/korganizer/kojournalview.cpp
+++ b/korganizer/kojournalview.cpp
@@ -1,219 +1,232 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 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 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. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24// 24//
25// View of Journal entries 25// View of Journal entries
26 26
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qscrollview.h> 28#include <qscrollview.h>
29#include <qpopupmenu.h> 29#include <qpopupmenu.h>
30#include <qhbox.h> 30#include <qhbox.h>
31#include <qpushbutton.h> 31#include <qpushbutton.h>
32#include <qlabel.h> 32#include <qlabel.h>
33#include <qpushbutton.h> 33#include <qpushbutton.h>
34#include <qapplication.h> 34#include <qapplication.h>
35 35
36#include <klocale.h> 36#include <klocale.h>
37#include <kdebug.h> 37#include <kdebug.h>
38#include "koprefs.h" 38#include "koprefs.h"
39#include <kglobal.h> 39#include <kglobal.h>
40 40
41#include <libkcal/calendar.h> 41#include <libkcal/calendar.h>
42 42
43#include "journalentry.h" 43#include "journalentry.h"
44 44
45#include "kojournalview.h" 45#include "kojournalview.h"
46using namespace KOrg; 46using namespace KOrg;
47 47
48KOJournalView::KOJournalView(Calendar *calendar, QWidget *parent, 48KOJournalView::KOJournalView(Calendar *calendar, QWidget *parent,
49 const char *name) 49 const char *name)
50 : KOrg::BaseView(calendar, parent, name) 50 : KOrg::BaseView(calendar, parent, name)
51{ 51{
52 mCalendar = calendar; 52 mCalendar = calendar;
53 QScrollView * sv = new QScrollView( this ); 53 QScrollView * sv = new QScrollView( this );
54 QHBoxLayout * hbl = new QHBoxLayout( this ); 54 QHBoxLayout * hbl = new QHBoxLayout( this );
55 hbl->addWidget( sv ); 55 hbl->addWidget( sv );
56 parWid = new QWidget( sv->viewport() ); 56 parWid = new QWidget( sv->viewport() );
57 sv->addChild(parWid); 57 sv->addChild(parWid);
58 sv->setResizePolicy( QScrollView:: AutoOneFit ); 58 sv->setResizePolicy( QScrollView:: AutoOneFit );
59 mTopLayout = new QVBoxLayout(parWid); 59 mTopLayout = new QVBoxLayout(parWid);
60 QHBox * vb = new QHBox ( parWid ); 60 QHBox * vb = new QHBox ( parWid );
61 QPushButton * newJournal = new QPushButton( vb ); 61 QPushButton * newJournal = new QPushButton( vb );
62 QPixmap icon; 62 QPixmap icon;
63 if ( QApplication::desktop()->width() < 321 ) 63 if ( QApplication::desktop()->width() < 321 )
64 icon = SmallIcon("ko16old"); 64 icon = SmallIcon("ko16old");
65 else 65 else
66 icon = SmallIcon("ko24old"); 66 icon = SmallIcon("ko24old");
67 newJournal->setPixmap (icon ) ; 67 newJournal->setPixmap (icon ) ;
68 int size = newJournal->sizeHint().height(); 68 int size = newJournal->sizeHint().height();
69 newJournal->setFixedSize( size, size ); 69 newJournal->setFixedSize( size, size );
70 mDateLabel = new QLabel ( vb ); 70 mDateLabel = new QLabel ( vb );
71 mTopLayout->addWidget( vb ); 71 mTopLayout->addWidget( vb );
72 mDateLabel->setMargin(1); 72 mDateLabel->setMargin(1);
73 mDateLabel->setAlignment(AlignCenter); 73 mDateLabel->setAlignment(AlignCenter);
74 connect( newJournal, SIGNAL( clicked() ), this , SLOT( newJournal() ) ); 74 connect( newJournal, SIGNAL( clicked() ), this , SLOT( newJournal() ) );
75 getNewEntry(); 75 getNewEntry();
76} 76}
77 77
78KOJournalView::~KOJournalView() 78KOJournalView::~KOJournalView()
79{ 79{
80} 80}
81 81
82int KOJournalView::currentDateCount() 82int KOJournalView::currentDateCount()
83{ 83{
84 return 0; 84 return 0;
85} 85}
86JournalEntry* KOJournalView::getNewEntry() 86JournalEntry* KOJournalView::getNewEntry()
87{ 87{
88 JournalEntry* Entry = new JournalEntry(mCalendar,parWid); 88 JournalEntry* Entry = new JournalEntry(mCalendar,parWid);
89 jEntries.append( Entry ); 89 jEntries.append( Entry );
90 mTopLayout->addWidget(Entry); 90 mTopLayout->addWidget(Entry);
91 Entry->setFont ( KOPrefs::instance()->mJornalViewFont ); 91 Entry->setFont ( KOPrefs::instance()->mJornalViewFont );
92 connect ( Entry,SIGNAL(deleteJournal(Journal *) ),this ,SIGNAL(deleteJournal(Journal *) ) ) ; 92 connect ( Entry,SIGNAL(deleteJournal(Journal *) ),this ,SIGNAL(deleteJournal(Journal *) ) ) ;
93 connect ( Entry,SIGNAL(newJournal() ),this ,SLOT(newJournal() ) ) ; 93 connect ( Entry,SIGNAL(newJournal() ),this ,SLOT(newJournal() ) ) ;
94 connect ( Entry,SIGNAL(showJournalOnly( Journal * ) ),this ,SLOT(showOnly ( Journal* ) ) ) ; 94 connect ( Entry,SIGNAL(showJournalOnly( Journal * ) ),this ,SLOT(showOnly ( Journal* ) ) ) ;
95 return Entry; 95 return Entry;
96} 96}
97 97
98QPtrList<Incidence> KOJournalView::selectedIncidences() 98QPtrList<Incidence> KOJournalView::selectedIncidences()
99{ 99{
100 QPtrList<Incidence> eventList; 100 QPtrList<Incidence> eventList;
101 101
102 return eventList; 102 return eventList;
103} 103}
104void KOJournalView::updateConfig() 104void KOJournalView::updateConfig()
105{ 105{
106 JournalEntry* mEntry = jEntries.first(); 106 JournalEntry* mEntry = jEntries.first();
107 while ( mEntry ) { 107 while ( mEntry ) {
108 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont ); 108 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont );
109 mEntry = jEntries.next(); 109 mEntry = jEntries.next();
110 } 110 }
111} 111}
112void KOJournalView::updateView() 112void KOJournalView::updateView()
113{ 113{
114 JournalEntry* mEntry = jEntries.first(); 114 JournalEntry* mEntry = jEntries.first();
115 while ( mEntry ) { 115 while ( mEntry ) {
116 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont ); 116 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont );
117 mEntry = jEntries.next(); 117 mEntry = jEntries.next();
118 } 118 }
119 showDates( mDate, QDate() ); 119 showDates( mDate, QDate() );
120} 120}
121 121
122void KOJournalView::flushView() 122void KOJournalView::flushView()
123{ 123{
124 static bool ff = false;
125 if ( ff ) return;
126 ff = true;
124 JournalEntry* mEntry = jEntries.first(); 127 JournalEntry* mEntry = jEntries.first();
125 while ( mEntry ) { 128 while ( mEntry ) {
126 mEntry->flushEntry(); 129 mEntry->flushEntry();
127 mEntry = jEntries.next(); 130 mEntry = jEntries.next();
128 } 131 }
132 ff = false;
129} 133}
130 134
131void KOJournalView::clearList() 135void KOJournalView::clearList()
132{ 136{
133 JournalEntry* mEntry = jEntries.first(); 137 JournalEntry* mEntry = jEntries.first();
134 while ( mEntry ) { 138 while ( mEntry ) {
135 mEntry->clear(); 139 mEntry->clear();
136 mEntry = jEntries.next(); 140 mEntry = jEntries.next();
137 } 141 }
138} 142}
139void KOJournalView::newJournal() 143void KOJournalView::newJournal()
140{ 144{
145 //qDebug(" KOJournalView::newJournal()");
141 flushView(); 146 flushView();
142 Journal* mJournal = new Journal; 147 Journal* mJournal = new Journal;
143 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); 148 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
144 mCalendar->addJournal(mJournal); 149 mCalendar->addJournal(mJournal);
145 showDates( mDate, QDate() ); 150 showDates( mDate, QDate() );
146} 151}
147 152
148void KOJournalView::showOnly ( Journal* j ) 153void KOJournalView::showOnly ( Journal* j )
149{ 154{
155 //qDebug("showOnly %x ", j);
150 flushView(); 156 flushView();
151 if ( j == 0 ) { 157 if ( j == 0 ) {
152 showDates( mDate, QDate() ); 158 showDates( mDate, QDate() );
153 return; 159 return;
154 } 160 }
155 QPtrList<Journal> jl; 161 QPtrList<Journal> jl;
156 jl.append ( j ); 162 jl.append ( j );
157 showList( jl ); 163 showList( jl );
158 JournalEntry* mEntry = jEntries.first(); 164 JournalEntry* mEntry = jEntries.first();
159 mEntry->setShowOnly(); 165 mEntry->setShowOnly();
160} 166}
161void KOJournalView::showList(QPtrList<Journal> jl) 167void KOJournalView::showList(QPtrList<Journal> jl)
162{ 168{
169 //qDebug("KOJournalView::showList %d",jl.count() );
163 JournalEntry* mEntry = jEntries.first(); 170 JournalEntry* mEntry = jEntries.first();
164 JournalEntry* firstEntry = mEntry; 171 JournalEntry* firstEntry = mEntry;
165 int count = jl.count(); 172 int count = jl.count();
166 int iii = 0; 173 int iii = 0;
167 while ( iii < count ) { 174 while ( iii < count ) {
168 if ( !mEntry ) { 175 if ( !mEntry ) {
169 mEntry = getNewEntry(); 176 mEntry = getNewEntry();
170 mEntry->show(); 177 mEntry->show();
178 mEntry->setVisibleMode( true );
171 mEntry->setDate(mDate); 179 mEntry->setDate(mDate);
172 mEntry->setJournal(jl.at(iii)); 180 mEntry->setJournal(jl.at(iii));
173 mEntry = 0; 181 mEntry = 0;
174 } else { 182 } else {
175 mEntry->setDate(mDate); 183 mEntry->setDate(mDate);
176 mEntry->setJournal(jl.at(iii)); 184 mEntry->setJournal(jl.at(iii));
177 mEntry->show(); 185 mEntry->show();
186 mEntry->setVisibleMode( true );
178 mEntry = jEntries.next(); 187 mEntry = jEntries.next();
179 } 188 }
180 ++iii; 189 ++iii;
181 } 190 }
182 while ( mEntry ) { 191 while ( mEntry ) {
183 mEntry->setDate(mDate); 192 mEntry->setDate(mDate);
184 mEntry->clear(); 193 mEntry->clear();
185 if ( mEntry != firstEntry ) 194 if ( mEntry != firstEntry ) {
186 mEntry->hide(); 195 mEntry->hide();
187 else 196 mEntry->setVisibleMode( false );
197 }
198 else {
199 mEntry->setVisibleMode( true );
188 mEntry->show(); 200 mEntry->show();
201 }
189 mEntry = jEntries.next(); 202 mEntry = jEntries.next();
190 } 203 }
191} 204}
192 205
193void KOJournalView::showDates(const QDate &start, const QDate &) 206void KOJournalView::showDates(const QDate &start, const QDate &)
194{ 207{
195 mDate = start; 208 mDate = start;
196 mDateLabel-> setText(KGlobal::locale()->formatDate(mDate)); 209 mDateLabel-> setText(KGlobal::locale()->formatDate(mDate));
197 QPtrList<Journal> jl = calendar()->journals4Date( start ); 210 QPtrList<Journal> jl = calendar()->journals4Date( start );
198 showList( jl ); 211 showList( jl );
199} 212}
200 213
201void KOJournalView::showEvents(QPtrList<Event>) 214void KOJournalView::showEvents(QPtrList<Event>)
202{ 215{
203 // After new creation of list view no events are selected. 216 // After new creation of list view no events are selected.
204// emit incidenceSelected( 0 ); 217// emit incidenceSelected( 0 );
205} 218}
206 219
207void KOJournalView::changeEventDisplay(Event *, int /*action*/) 220void KOJournalView::changeEventDisplay(Event *, int /*action*/)
208{ 221{
209 updateView(); 222 updateView();
210} 223}
211 224
212void KOJournalView::keyPressEvent ( QKeyEvent * e ) 225void KOJournalView::keyPressEvent ( QKeyEvent * e )
213{ 226{
214 //qDebug("keyPressEven "); 227 //qDebug("keyPressEven ");
215 if ( e->state() == Qt::ControlButton ) { 228 if ( e->state() == Qt::ControlButton ) {
216 if ( e->key () == Qt::Key_Right || e->key () == Qt::Key_Left ) 229 if ( e->key () == Qt::Key_Right || e->key () == Qt::Key_Left )
217 e->ignore(); 230 e->ignore();
218 } 231 }
219} 232}