author | zautrix <zautrix> | 2005-06-30 06:35:25 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-30 06:35:25 (UTC) |
commit | 0fc571a7eadda739fd1a93d627e7129b9956c9f6 (patch) (unidiff) | |
tree | 60336a1e91259ab654e292dbe9938af4ecdf7a72 /korganizer/journalentry.cpp | |
parent | da264cf19c0183d6ea4e8dab6eabd40994e351c8 (diff) | |
download | kdepimpi-0fc571a7eadda739fd1a93d627e7129b9956c9f6.zip kdepimpi-0fc571a7eadda739fd1a93d627e7129b9956c9f6.tar.gz kdepimpi-0fc571a7eadda739fd1a93d627e7129b9956c9f6.tar.bz2 |
fixes
-rw-r--r-- | korganizer/journalentry.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp index add874f..395392c 100644 --- a/korganizer/journalentry.cpp +++ b/korganizer/journalentry.cpp | |||
@@ -40,49 +40,49 @@ | |||
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 |
57 | JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | 57 | JournalEntry::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 ) ; |
@@ -150,118 +150,125 @@ void JournalEntry::slotLoadTemplate() | |||
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 | } |
162 | void JournalEntry::setDate(const QDate &date) | 162 | void 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 | ||
172 | void JournalEntry::toggleShowJournal() | 172 | void JournalEntry::toggleShowJournal() |
173 | { | 173 | { |
174 | if (!mEditor->text().isEmpty() || !mTitle->text().isEmpty()) | ||
174 | flushEntry(); | 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 ); |
179 | } | 182 | } |
183 | } | ||
180 | void JournalEntry::setShowOnly() | 184 | void JournalEntry::setShowOnly() |
181 | { | 185 | { |
182 | showOnlyMode = true; | 186 | showOnlyMode = true; |
183 | mEditor->setFocus(); | 187 | mEditor->setFocus(); |
188 | visibleMode = true; | ||
184 | } | 189 | } |
185 | void JournalEntry::setJournal(Journal *journal) | 190 | void 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 | ||
204 | Journal *JournalEntry::journal() const | 209 | Journal *JournalEntry::journal() const |
205 | { | 210 | { |
206 | return mJournal; | 211 | return mJournal; |
207 | } | 212 | } |
208 | 213 | ||
209 | 214 | ||
210 | void JournalEntry::clear() | 215 | void JournalEntry::clear() |
211 | { | 216 | { |
212 | mJournal = 0; | 217 | mJournal = 0; |
213 | mEditor->setText(""); | 218 | mEditor->setText(""); |
219 | mTitle->setText(""); | ||
214 | } | 220 | } |
215 | 221 | ||
216 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) | 222 | bool 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 | ||
234 | void JournalEntry::writeJournal() | 240 | void 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 | ||
260 | void JournalEntry::flushEntry() | 267 | void JournalEntry::flushEntry() |
261 | { | 268 | { |
262 | writeJournal(); | 269 | writeJournal(); |
263 | } | 270 | } |
264 | void JournalEntry::keyPressEvent ( QKeyEvent * e ) | 271 | void JournalEntry::keyPressEvent ( QKeyEvent * e ) |
265 | { | 272 | { |
266 | e->ignore(); | 273 | e->ignore(); |
267 | 274 | ||