summaryrefslogtreecommitdiffabout
path: root/korganizer/journalentry.cpp
Unidiff
Diffstat (limited to 'korganizer/journalentry.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/journalentry.cpp51
1 files changed, 40 insertions, 11 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp
index 4751d40..56221dc 100644
--- a/korganizer/journalentry.cpp
+++ b/korganizer/journalentry.cpp
@@ -58,68 +58,69 @@
58#endif 58#endif
59JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : 59JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
60 QFrame(parent) 60 QFrame(parent)
61{ 61{
62 62
63 int fac = 5; 63 int fac = 5;
64 heiHint = QApplication::desktop()->height(); 64 heiHint = QApplication::desktop()->height();
65 if ( heiHint > 800 ) 65 if ( heiHint > 800 )
66 fac += 2; 66 fac += 2;
67 heiHint = heiHint / fac; 67 heiHint = heiHint / fac;
68 68
69 showOnlyMode = false; 69 showOnlyMode = false;
70 mCalendar = calendar; 70 mCalendar = calendar;
71 mJournal = 0; 71 mJournal = 0;
72 visibleMode = true; 72 visibleMode = true;
73 QHBox * vb = new QHBox ( this ); 73 QHBox * vb = new QHBox ( this );
74 QPixmap iconp; 74 QPixmap iconp;
75 vb->setMargin ( KDialog::marginHint()-1 ); 75 vb->setMargin ( KDialog::marginHint()-1 );
76 QPushButton * toggleJournal = new QPushButton( vb ); 76 QPushButton * toggleJournal = new QPushButton( vb );
77 iconp = SmallIcon("1updownarrow"); 77 iconp = SmallIcon("1updownarrow");
78 toggleJournal->setPixmap (iconp ) ; 78 toggleJournal->setPixmap (iconp ) ;
79 new QLabel(" "+i18n("Title: "),vb); 79 new QLabel(" "+i18n("Title: "),vb);
80 mTitle = new KOLocationBox(TRUE, vb, 30); 80 mTitle = new KOLocationBox(TRUE, vb, 30);
81 mTitle->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) ); 81 mTitle->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) );
82 mTitleLabel = new QLabel(i18n("Title"),vb); 82 mCalendarBox = new QComboBox(vb);
83 mTitleLabel->setMargin(0); 83 //mTitleLabel->setMargin(0);
84 mTitleLabel->setAlignment(AlignCenter); 84 //mTitleLabel->setAlignment(AlignCenter);
85 QPushButton * loadTemplate = new QPushButton( vb ); 85 QPushButton * loadTemplate = new QPushButton( vb );
86 QPushButton * saveTemplate = new QPushButton( vb ); 86 QPushButton * saveTemplate = new QPushButton( vb );
87 if ( QApplication::desktop()->width() < 321 ) 87 if ( QApplication::desktop()->width() < 321 )
88 iconp = SmallIcon("fileexport16"); 88 iconp = SmallIcon("fileexport16");
89 else 89 else
90 iconp = SmallIcon("fileexport"); 90 iconp = SmallIcon("fileexport");
91 saveTemplate->setPixmap (iconp ) ; 91 saveTemplate->setPixmap (iconp ) ;
92 int size = saveTemplate->sizeHint().height(); 92 int size = saveTemplate->sizeHint().height();
93 if ( QApplication::desktop()->width() < 321 ) 93 if ( QApplication::desktop()->width() < 321 )
94 iconp = SmallIcon("fileimport16"); 94 iconp = SmallIcon("fileimport16");
95 else 95 else
96 iconp = SmallIcon("fileimport"); 96 iconp = SmallIcon("fileimport");
97 loadTemplate->setPixmap (iconp ) ; 97 loadTemplate->setPixmap (iconp ) ;
98 loadTemplate->setFixedSize( size, size ); 98 loadTemplate->setFixedSize( size, size );
99 saveTemplate->setFixedSize( size, size ); 99 saveTemplate->setFixedSize( size, size );
100 toggleJournal->setFixedSize( size , size ); 100 toggleJournal->setFixedSize( size , size );
101 mTitle->setMaximumHeight( size+4); 101 mTitle->setMaximumHeight( size+4);
102 mCalendarBox->setMaximumHeight( size+4);
102 mEditor = new KTextEdit(this); 103 mEditor = new KTextEdit(this);
103#ifndef DESKTOP_VERSION 104#ifndef DESKTOP_VERSION
104 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); 105 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold );
105#endif 106#endif
106 mEditor->setWordWrap( KTextEdit::WidgetWidth ); 107 mEditor->setWordWrap( KTextEdit::WidgetWidth );
107 QBoxLayout *topLayout = new QVBoxLayout(this); 108 QBoxLayout *topLayout = new QVBoxLayout(this);
108 topLayout->addWidget(vb); 109 topLayout->addWidget(vb);
109 topLayout->addWidget(mEditor); 110 topLayout->addWidget(mEditor);
110 mEditor->installEventFilter(this); 111 mEditor->installEventFilter(this);
111 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 112 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
112 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 113 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
113 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); 114 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) );
114 mTitle->load( KOLocationBox::SUMMARYJOURNAL ); 115 mTitle->load( KOLocationBox::SUMMARYJOURNAL );
115 mTitle->lineEdit ()->setText(""); 116 mTitle->lineEdit ()->setText("");
116} 117}
117 118
118JournalEntry::~JournalEntry() 119JournalEntry::~JournalEntry()
119{ 120{
120 //qDebug("JournalEntry::~JournalEntry() "); 121 //qDebug("JournalEntry::~JournalEntry() ");
121} 122}
122QSize JournalEntry::sizeHint() const 123QSize JournalEntry::sizeHint() const
123{ 124{
124 return QSize ( 240, heiHint ); 125 return QSize ( 240, heiHint );
125} 126}
@@ -155,145 +156,173 @@ void JournalEntry::slotLoadTemplate()
155 fileName += "/journal"; 156 fileName += "/journal";
156 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); 157 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this );
157 if ( fileName.length() == 0 ) 158 if ( fileName.length() == 0 )
158 return; 159 return;
159 QFile fileIn( fileName ); 160 QFile fileIn( fileName );
160 if (!fileIn.open( IO_ReadOnly ) ) { 161 if (!fileIn.open( IO_ReadOnly ) ) {
161 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 162 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
162 .arg( fileName ) ); 163 .arg( fileName ) );
163 return; 164 return;
164 } 165 }
165 QTextStream tsIn( &fileIn ); 166 QTextStream tsIn( &fileIn );
166 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 167 tsIn.setCodec( QTextCodec::codecForName("utf8") );
167 QString text = tsIn.read(); 168 QString text = tsIn.read();
168 fileIn.close(); 169 fileIn.close();
169 int line, col; 170 int line, col;
170 mEditor->getCursorPosition (& line, & col ); 171 mEditor->getCursorPosition (& line, & col );
171 mEditor-> insertAt ( text, line, col, true ); 172 mEditor-> insertAt ( text, line, col, true );
172 //mEditor->setIgnoreMark( true ); 173 //mEditor->setIgnoreMark( true );
173} 174}
174void JournalEntry::setDate(const QDate &date) 175void JournalEntry::setDate(const QDate &date)
175{ 176{
176 showOnlyMode = false; 177 showOnlyMode = false;
177 writeJournal(); 178 writeJournal();
178 mDate = date; 179 mDate = date;
179 int id = mCalendar->defaultCalendar(); 180 fillCalendar( mCalendar->defaultCalendar() );
180 QString calname = KOPrefs::instance()->getCalendar( id )->mName; 181}
181 mTitleLabel->setText( " (" + calname +")"); 182void JournalEntry::fillCalendar( int setToID )
183{
184 mCalendarBox->clear();
185 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first();
186 int std = 0;
187 int count = 0;
188 while ( kkf ) {
189 if ( (!kkf->mErrorOnLoad &&! kkf->isReadOnly) || setToID == kkf->mCalNumber ) {
190 if ( setToID ) {
191 if ( kkf->mCalNumber == setToID )
192 std = count;
193 } else {
194 if ( kkf->isStandard ) {
195 std = count;
196 }
197 }
198 ++count;
199 mCalendarBox->insertItem( kkf->mName );
200 }
201 kkf = KOPrefs::instance()->mCalendars.next();
202 }
203 mCalendarBox->setCurrentItem( std );
204 if ( KOPrefs::instance()->mCalendars.count() == 1 )
205 mCalendarBox->hide();
206 else
207 mCalendarBox->show();
182} 208}
183 209
184void JournalEntry::toggleShowJournal() 210void JournalEntry::toggleShowJournal()
185{ 211{
186 if (!mEditor->text().isEmpty() || !mTitle->currentText ().isEmpty()) 212 if (!mEditor->text().isEmpty() || !mTitle->currentText ().isEmpty())
187 flushEntry(); 213 flushEntry();
188 if ( showOnlyMode ) 214 if ( showOnlyMode )
189 emit showJournalOnly( 0 ); 215 emit showJournalOnly( 0 );
190 else { 216 else {
191 // we have to protect mJournal from deleting if mJournal has empty text 217 // we have to protect mJournal from deleting if mJournal has empty text
192 visibleMode = false; // set to true via :setShowOnly() 218 visibleMode = false; // set to true via :setShowOnly()
193 emit showJournalOnly( mJournal ); 219 emit showJournalOnly( mJournal );
194 //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) ); 220 //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) );
195 } 221 }
196} 222}
197void JournalEntry::setVisibleOn() 223void JournalEntry::setVisibleOn()
198{ 224{
199 visibleMode = true; 225 visibleMode = true;
200} 226}
201void JournalEntry::setShowOnly() 227void JournalEntry::setShowOnly()
202{ 228{
203 showOnlyMode = true; 229 showOnlyMode = true;
204 if ( mTitle->currentText().isEmpty() ) 230 if ( mTitle->currentText().isEmpty() )
205 mTitle->setFocus(); 231 mTitle->setFocus();
206 else 232 else
207 mEditor->setFocus(); 233 mEditor->setFocus();
208} 234}
209void JournalEntry::setJournal(Journal *journal) 235void JournalEntry::setJournal(Journal *journal, bool saveJournal )
210{ 236{
237 if ( saveJournal )
211 writeJournal(); 238 writeJournal();
212 mTitle->load( KOLocationBox::SUMMARYJOURNAL ); 239 mTitle->load( KOLocationBox::SUMMARYJOURNAL );
213 240
214 mJournal = journal; 241 mJournal = journal;
215 if ( journal->isReadOnly() ) 242 if ( journal->isReadOnly() )
216 mTitle->lineEdit ()->setText(mJournal->summary()+" ("+i18n("readonly")+")"); 243 mTitle->lineEdit ()->setText(mJournal->summary()+" ("+i18n("readonly")+")");
217 else 244 else
218 mTitle->lineEdit ()->setText(mJournal->summary()); 245 mTitle->lineEdit ()->setText(mJournal->summary());
219 mEditor->setText(mJournal->description()); 246 mEditor->setText(mJournal->description());
220 mTitle->setEnabled (!journal->isReadOnly() ); 247 mTitle->setEnabled (!journal->isReadOnly() );
221 mEditor->setReadOnly ( journal->isReadOnly() ); 248 mEditor->setReadOnly ( journal->isReadOnly() );
222 int id = mJournal->calID(); 249 fillCalendar( mJournal->calID() );
223
224 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
225 mTitleLabel->setText( " (" + calname +")");
226} 250}
227 251
228Journal *JournalEntry::journal() const 252Journal *JournalEntry::journal() const
229{ 253{
230 return mJournal; 254 return mJournal;
231} 255}
232 256
233 257
234void JournalEntry::clear() 258void JournalEntry::clear()
235{ 259{
236 mJournal = 0; 260 mJournal = 0;
237 mEditor->setText(""); 261 mEditor->setText("");
238 mTitle->load( KOLocationBox::SUMMARYJOURNAL ); 262 mTitle->load( KOLocationBox::SUMMARYJOURNAL );
239 mTitle->lineEdit ()->setText(""); 263 mTitle->lineEdit ()->setText("");
240} 264}
241 265
242bool JournalEntry::eventFilter( QObject *o, QEvent *e ) 266bool JournalEntry::eventFilter( QObject *o, QEvent *e )
243{ 267{
244// kdDebug() << "JournalEntry::event received " << e->type() << endl; 268// kdDebug() << "JournalEntry::event received " << e->type() << endl;
245 269
246 if ( e->type() == QEvent::FocusOut ) { 270 if ( e->type() == QEvent::FocusOut ) {
247 writeJournal(); 271 writeJournal();
248 } 272 }
249 if ( e->type() == QEvent::KeyPress ) { 273 if ( e->type() == QEvent::KeyPress ) {
250 QKeyEvent * k = (QKeyEvent *) e; 274 QKeyEvent * k = (QKeyEvent *) e;
251 if ( k->state() == Qt::ControlButton ) { 275 if ( k->state() == Qt::ControlButton ) {
252 k->ignore(); 276 k->ignore();
253 //return true; 277 //return true;
254 } 278 }
255 } 279 }
256 280
257 return QFrame::eventFilter( o, e ); // standard event processing 281 return QFrame::eventFilter( o, e ); // standard event processing
258} 282}
259 283
260void JournalEntry::writeJournal() 284void JournalEntry::writeJournal()
261{ 285{
262 if ( !visibleMode ) return; 286 if ( !visibleMode ) return;
287 if ( !mTitle->isEnabled() ) return;
263 if (mEditor->text().isEmpty() && mTitle->currentText().isEmpty()) { 288 if (mEditor->text().isEmpty() && mTitle->currentText().isEmpty()) {
264 if ( mJournal ) { 289 if ( mJournal ) {
265 Journal* j = mJournal; 290 Journal* j = mJournal;
266 mJournal = 0; 291 mJournal = 0;
267 bool conf = KOPrefs::instance()->mConfirm; 292 bool conf = KOPrefs::instance()->mConfirm;
268 KOPrefs::instance()->mConfirm = false; 293 KOPrefs::instance()->mConfirm = false;
269 emit deleteJournal(j); 294 emit deleteJournal(j);
270 KOPrefs::instance()->mConfirm = conf; 295 KOPrefs::instance()->mConfirm = conf;
271 } 296 }
272 return; 297 return;
273 } 298 }
274 299
275// kdDebug() << "JournalEntry::writeJournal()..." << endl; 300// kdDebug() << "JournalEntry::writeJournal()..." << endl;
276 301
277 if (!mJournal) { 302 if (!mJournal) {
278 mJournal = new Journal; 303 mJournal = new Journal;
279 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); 304 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
280 mCalendar->addJournal(mJournal); 305 mCalendar->addJournal(mJournal);
281 } 306 }
282 if ( mJournal->description() != mEditor->text() ) { 307 if ( mJournal->description() != mEditor->text() ) {
283 mJournal->setDescription(mEditor->text()); 308 mJournal->setDescription(mEditor->text());
284 } 309 }
285 if ( mJournal->summary() != mTitle->currentText() ) { 310 if ( mJournal->summary() != mTitle->currentText() ) {
286 mJournal->setSummary(mTitle->currentText()); 311 mJournal->setSummary(mTitle->currentText());
287 mTitle->save(KOLocationBox::SUMMARYJOURNAL); 312 mTitle->save(KOLocationBox::SUMMARYJOURNAL);
288 } 313 }
314 int id = KOPrefs::instance()->getCalendarID( mCalendarBox->currentText() );
315 if ( mJournal->calID() != id ) {
316 mJournal->setCalID( id );
317 }
289} 318}
290 319
291void JournalEntry::flushEntry() 320void JournalEntry::flushEntry()
292{ 321{
293 writeJournal(); 322 writeJournal();
294} 323}
295void JournalEntry::keyPressEvent ( QKeyEvent * e ) 324void JournalEntry::keyPressEvent ( QKeyEvent * e )
296{ 325{
297 e->ignore(); 326 e->ignore();
298 327
299} 328}