summaryrefslogtreecommitdiffabout
path: root/korganizer/journalentry.cpp
Unidiff
Diffstat (limited to 'korganizer/journalentry.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/journalentry.cpp53
1 files changed, 21 insertions, 32 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp
index 0b923ad..05bfd31 100644
--- a/korganizer/journalentry.cpp
+++ b/korganizer/journalentry.cpp
@@ -33,66 +33,57 @@
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 46
46#include <libkcal/journal.h> 47#include <libkcal/journal.h>
47#include <libkcal/calendarresources.h> 48#include <libkcal/calendarresources.h>
48#include <libkcal/resourcecalendar.h> 49#include <libkcal/resourcecalendar.h>
49#include <kresources/resourceselectdialog.h> 50#include <kresources/resourceselectdialog.h>
50 51
51#include "journalentry.h" 52#include "journalentry.h"
52//#include "journalentry.moc" 53//#include "journalentry.moc"
53#ifndef DESKTOP_VERSION 54#ifndef DESKTOP_VERSION
54#include <qpe/qpeapplication.h> 55#include <qpe/qpeapplication.h>
55#endif 56#endif
56JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : 57JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
57 QFrame(parent) 58 QFrame(parent)
58{ 59{
59 heiHint = QApplication::desktop()->height() / 5 ; 60 heiHint = QApplication::desktop()->height() / 5 ;
60 showOnlyMode = false; 61 showOnlyMode = false;
61 mCalendar = calendar; 62 mCalendar = calendar;
62 mJournal = 0; 63 mJournal = 0;
63 mDirty = false; 64 mDirty = false;
64 65
65 QHBox * vb = new QHBox ( this ); 66 QHBox * vb = new QHBox ( this );
66 QPushButton * newJournal = new QPushButton( vb );
67 QIconSet icon; 67 QIconSet icon;
68 if ( QApplication::desktop()->width() < 321 )
69 icon = SmallIcon("ko16old");
70 else
71 icon = SmallIcon("ko24old");
72 newJournal->setIconSet (icon ) ;
73 int size = newJournal->sizeHint().height();
74 newJournal->setFixedSize( size, size );
75
76 68
77 QPushButton * toggleJournal = new QPushButton( vb ); 69 QPushButton * toggleJournal = new QPushButton( vb );
78 icon = SmallIcon("1updownarrow"); 70 icon = SmallIcon("1updownarrow");
79 toggleJournal->setIconSet (icon ) ; 71 toggleJournal->setIconSet (icon ) ;
80 //int size = toggleJournal->sizeHint().height(); 72 int size = toggleJournal->sizeHint().height();
81 toggleJournal->setFixedSize( size * 2 /3 , size ); 73 toggleJournal->setFixedSize( size * 2 /3 , size );
82 74 new QLabel(i18n(" Title: "),vb);
83 75 mTitle = new KLineEdit ( vb );
84
85 mTitleLabel = new QLabel(i18n("Title"),vb); 76 mTitleLabel = new QLabel(i18n("Title"),vb);
86 mTitleLabel->setMargin(2); 77 mTitleLabel->setMargin(0);
87 mTitleLabel->setAlignment(AlignCenter); 78 mTitleLabel->setAlignment(AlignCenter);
88 QPushButton * loadTemplate = new QPushButton( vb ); 79 QPushButton * loadTemplate = new QPushButton( vb );
89 QPushButton * saveTemplate = new QPushButton( vb ); 80 QPushButton * saveTemplate = new QPushButton( vb );
90 if ( QApplication::desktop()->width() < 321 ) 81 if ( QApplication::desktop()->width() < 321 )
91 icon = SmallIcon("fileexport16"); 82 icon = SmallIcon("fileexport16");
92 else 83 else
93 icon = SmallIcon("fileexport"); 84 icon = SmallIcon("fileexport");
94 saveTemplate->setIconSet (icon ) ; 85 saveTemplate->setIconSet (icon ) ;
95 //size = saveTemplate->sizeHint().height(); 86 //size = saveTemplate->sizeHint().height();
96 saveTemplate->setFixedSize( size, size ); 87 saveTemplate->setFixedSize( size, size );
97 if ( QApplication::desktop()->width() < 321 ) 88 if ( QApplication::desktop()->width() < 321 )
98 icon = SmallIcon("fileimport16"); 89 icon = SmallIcon("fileimport16");
@@ -102,32 +93,32 @@ JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
102 loadTemplate->setFixedSize( size, size ); 93 loadTemplate->setFixedSize( size, size );
103 mEditor = new KTextEdit(this); 94 mEditor = new KTextEdit(this);
104 connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty())); 95 connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty()));
105#ifndef DESKTOP_VERSION 96#ifndef DESKTOP_VERSION
106 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); 97 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold );
107#endif 98#endif
108 mEditor->setWordWrap( KTextEdit::WidgetWidth ); 99 mEditor->setWordWrap( KTextEdit::WidgetWidth );
109 QBoxLayout *topLayout = new QVBoxLayout(this); 100 QBoxLayout *topLayout = new QVBoxLayout(this);
110 topLayout->addWidget(vb); 101 topLayout->addWidget(vb);
111 topLayout->addWidget(mEditor); 102 topLayout->addWidget(mEditor);
112 mEditor->installEventFilter(this); 103 mEditor->installEventFilter(this);
113 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 104 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
105 connect( mTitle, SIGNAL( textChanged ( const QString & ) ), this , SLOT( setDirty() ) );
114 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 106 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
115 connect( newJournal, SIGNAL( clicked() ), this , SIGNAL( newJournal() ) );
116 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); 107 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) );
117} 108}
118 109
119JournalEntry::~JournalEntry() 110JournalEntry::~JournalEntry()
120{ 111{
121 qDebug("JournalEntry::~JournalEntry() "); 112 //qDebug("JournalEntry::~JournalEntry() ");
122} 113}
123QSize JournalEntry::sizeHint() const 114QSize JournalEntry::sizeHint() const
124{ 115{
125 return QSize ( 240, heiHint ); 116 return QSize ( 240, heiHint );
126} 117}
127void JournalEntry::slotSaveTemplate() 118void JournalEntry::slotSaveTemplate()
128{ 119{
129 QString fileName =locateLocal( "templates", "journals" ); 120 QString fileName =locateLocal( "templates", "journals" );
130 QDir t_dir; 121 QDir t_dir;
131 if ( !t_dir.exists(fileName) ) 122 if ( !t_dir.exists(fileName) )
132 t_dir.mkdir ( fileName ); 123 t_dir.mkdir ( fileName );
133 fileName += "/journal"; 124 fileName += "/journal";
@@ -170,54 +161,53 @@ void JournalEntry::slotLoadTemplate()
170 int line, col; 161 int line, col;
171 mEditor->getCursorPosition (& line, & col ); 162 mEditor->getCursorPosition (& line, & col );
172 mEditor-> insertAt ( text, line, col, true ); 163 mEditor-> insertAt ( text, line, col, true );
173 //mEditor->setIgnoreMark( true ); 164 //mEditor->setIgnoreMark( true );
174 setDirty(); 165 setDirty();
175} 166}
176void JournalEntry::setDate(const QDate &date) 167void JournalEntry::setDate(const QDate &date)
177{ 168{
178 showOnlyMode = false; 169 showOnlyMode = false;
179 mDate = date; 170 mDate = date;
180 writeJournal(); 171 writeJournal();
181 int id = mCalendar->defaultCalendar(); 172 int id = mCalendar->defaultCalendar();
182 if ( id == 1 ) { 173 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
183 mTitleLabel->setText(KGlobal::locale()->formatDate(date)); 174 mTitleLabel->setText( " (" + calname +")");
184 } else {
185 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
186 mTitleLabel->setText( KGlobal::locale()->formatDate(mDate,true) + " (" + calname +")");
187 }
188} 175}
189 176
190void JournalEntry::toggleShowJournal() 177void JournalEntry::toggleShowJournal()
191{ 178{
179 flushEntry();
192 if ( showOnlyMode ) 180 if ( showOnlyMode )
193 emit showJournalOnly( 0 ); 181 emit showJournalOnly( 0 );
194 else 182 else
195 emit showJournalOnly( mJournal ); 183 emit showJournalOnly( mJournal );
196} 184}
197 185void JournalEntry::setShowOnly()
186{
187 showOnlyMode = true;
188 mEditor->setFocus();
189}
198void JournalEntry::setJournal(Journal *journal) 190void JournalEntry::setJournal(Journal *journal)
199{ 191{
200 writeJournal(); 192 writeJournal();
201 193
202 mJournal = journal; 194 mJournal = journal;
203 195 mTitle->setText(mJournal->summary());
204 mEditor->setText(mJournal->description()); 196 mEditor->setText(mJournal->description());
205 int id = mJournal->calID(); 197 int id = mJournal->calID();
206 if ( id > 1 ) { 198
207 QString calname = KOPrefs::instance()->getCalendar( id )->mName; 199 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
208 mTitleLabel->setText( KGlobal::locale()->formatDate(mDate,true) + " (" + calname +")"); 200 mTitleLabel->setText( " (" + calname +")");
209 } else { 201
210 mTitleLabel->setText(KGlobal::locale()->formatDate(mDate));
211 }
212 mDirty = false; 202 mDirty = false;
213} 203}
214 204
215Journal *JournalEntry::journal() const 205Journal *JournalEntry::journal() const
216{ 206{
217 return mJournal; 207 return mJournal;
218} 208}
219 209
220void JournalEntry::setDirty() 210void JournalEntry::setDirty()
221{ 211{
222 mDirty = true; 212 mDirty = true;
223 213
@@ -265,26 +255,25 @@ void JournalEntry::writeJournal()
265 return; 255 return;
266 } 256 }
267 257
268// kdDebug() << "JournalEntry::writeJournal()..." << endl; 258// kdDebug() << "JournalEntry::writeJournal()..." << endl;
269 259
270 if (!mJournal) { 260 if (!mJournal) {
271 mJournal = new Journal; 261 mJournal = new Journal;
272 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); 262 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
273 mCalendar->addJournal(mJournal); 263 mCalendar->addJournal(mJournal);
274 } 264 }
275 265
276 mJournal->setDescription(mEditor->text()); 266 mJournal->setDescription(mEditor->text());
277 //qDebug("tttt%s ", mEditor->text().latin1()); 267 mJournal->setSummary(mTitle->text());
278
279 mDirty = false; 268 mDirty = false;
280} 269}
281 270
282void JournalEntry::flushEntry() 271void JournalEntry::flushEntry()
283{ 272{
284 if (!mDirty) return; 273 if (!mDirty) return;
285 274
286 writeJournal(); 275 writeJournal();
287} 276}
288void JournalEntry::keyPressEvent ( QKeyEvent * e ) 277void JournalEntry::keyPressEvent ( QKeyEvent * e )
289{ 278{
290 e->ignore(); 279 e->ignore();