-rw-r--r-- | korganizer/journalentry.cpp | 51 |
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 | |||
@@ -70,44 +70,45 @@ JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | |||
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() ) ); |
@@ -167,27 +168,52 @@ void JournalEntry::slotLoadTemplate() | |||
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 | } |
174 | void JournalEntry::setDate(const QDate &date) | 175 | void 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 +")"); | 182 | void 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 | ||
184 | void JournalEntry::toggleShowJournal() | 210 | void 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 ); |
@@ -197,41 +223,39 @@ void JournalEntry::toggleShowJournal() | |||
197 | void JournalEntry::setVisibleOn() | 223 | void JournalEntry::setVisibleOn() |
198 | { | 224 | { |
199 | visibleMode = true; | 225 | visibleMode = true; |
200 | } | 226 | } |
201 | void JournalEntry::setShowOnly() | 227 | void 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 | } |
209 | void JournalEntry::setJournal(Journal *journal) | 235 | void 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 | ||
228 | Journal *JournalEntry::journal() const | 252 | Journal *JournalEntry::journal() const |
229 | { | 253 | { |
230 | return mJournal; | 254 | return mJournal; |
231 | } | 255 | } |
232 | 256 | ||
233 | 257 | ||
234 | void JournalEntry::clear() | 258 | void JournalEntry::clear() |
235 | { | 259 | { |
236 | mJournal = 0; | 260 | mJournal = 0; |
237 | mEditor->setText(""); | 261 | mEditor->setText(""); |
@@ -251,24 +275,25 @@ bool JournalEntry::eventFilter( QObject *o, QEvent *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 | ||
260 | void JournalEntry::writeJournal() | 284 | void 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 | ||
@@ -277,23 +302,27 @@ void JournalEntry::writeJournal() | |||
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 | ||
291 | void JournalEntry::flushEntry() | 320 | void JournalEntry::flushEntry() |
292 | { | 321 | { |
293 | writeJournal(); | 322 | writeJournal(); |
294 | } | 323 | } |
295 | void JournalEntry::keyPressEvent ( QKeyEvent * e ) | 324 | void JournalEntry::keyPressEvent ( QKeyEvent * e ) |
296 | { | 325 | { |
297 | e->ignore(); | 326 | e->ignore(); |
298 | 327 | ||
299 | } | 328 | } |