author | zautrix <zautrix> | 2005-06-29 12:29:53 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-29 12:29:53 (UTC) |
commit | 0d4d5898a32f162dca010db329e02310a14629d5 (patch) (unidiff) | |
tree | 2d6e758a8a5ec64995de79a4cd1c02c89f509190 /korganizer/journalentry.cpp | |
parent | 435e68d6ace30fb2121b718226e00be44971c617 (diff) | |
download | kdepimpi-0d4d5898a32f162dca010db329e02310a14629d5.zip kdepimpi-0d4d5898a32f162dca010db329e02310a14629d5.tar.gz kdepimpi-0d4d5898a32f162dca010db329e02310a14629d5.tar.bz2 |
j fixes
-rw-r--r-- | korganizer/journalentry.cpp | 53 |
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 | |||
@@ -21,125 +21,116 @@ | |||
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 | 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 |
56 | JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | 57 | JournalEntry::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"); |
99 | else | 90 | else |
100 | icon = SmallIcon("fileimport"); | 91 | icon = SmallIcon("fileimport"); |
101 | loadTemplate->setIconSet (icon ) ; | 92 | loadTemplate->setIconSet (icon ) ; |
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 | ||
119 | JournalEntry::~JournalEntry() | 110 | JournalEntry::~JournalEntry() |
120 | { | 111 | { |
121 | qDebug("JournalEntry::~JournalEntry() "); | 112 | //qDebug("JournalEntry::~JournalEntry() "); |
122 | } | 113 | } |
123 | QSize JournalEntry::sizeHint() const | 114 | QSize JournalEntry::sizeHint() const |
124 | { | 115 | { |
125 | return QSize ( 240, heiHint ); | 116 | return QSize ( 240, heiHint ); |
126 | } | 117 | } |
127 | void JournalEntry::slotSaveTemplate() | 118 | void 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"; |
134 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); | 125 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); |
135 | if ( fileName.length() == 0 ) | 126 | if ( fileName.length() == 0 ) |
136 | return; | 127 | return; |
137 | 128 | ||
138 | QFile fileIn( fileName ); | 129 | QFile fileIn( fileName ); |
139 | if (!fileIn.open( IO_WriteOnly ) ) { | 130 | if (!fileIn.open( IO_WriteOnly ) ) { |
140 | KMessageBox::error( this, i18n("Error saving template file\n '%1'.") | 131 | KMessageBox::error( this, i18n("Error saving template file\n '%1'.") |
141 | .arg( fileName ) ); | 132 | .arg( fileName ) ); |
142 | return; | 133 | return; |
143 | } | 134 | } |
144 | // QString text; | 135 | // QString text; |
145 | QTextStream tsIn( &fileIn ); | 136 | QTextStream tsIn( &fileIn ); |
@@ -158,78 +149,77 @@ void JournalEntry::slotLoadTemplate() | |||
158 | if ( fileName.length() == 0 ) | 149 | if ( fileName.length() == 0 ) |
159 | return; | 150 | return; |
160 | QFile fileIn( fileName ); | 151 | QFile fileIn( fileName ); |
161 | if (!fileIn.open( IO_ReadOnly ) ) { | 152 | if (!fileIn.open( IO_ReadOnly ) ) { |
162 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") | 153 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") |
163 | .arg( fileName ) ); | 154 | .arg( fileName ) ); |
164 | return; | 155 | return; |
165 | } | 156 | } |
166 | QTextStream tsIn( &fileIn ); | 157 | QTextStream tsIn( &fileIn ); |
167 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 158 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
168 | QString text = tsIn.read(); | 159 | QString text = tsIn.read(); |
169 | fileIn.close(); | 160 | fileIn.close(); |
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 | } |
176 | void JournalEntry::setDate(const QDate &date) | 167 | void 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 | ||
190 | void JournalEntry::toggleShowJournal() | 177 | void 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 | 185 | void JournalEntry::setShowOnly() | |
186 | { | ||
187 | showOnlyMode = true; | ||
188 | mEditor->setFocus(); | ||
189 | } | ||
198 | void JournalEntry::setJournal(Journal *journal) | 190 | void 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 | ||
215 | Journal *JournalEntry::journal() const | 205 | Journal *JournalEntry::journal() const |
216 | { | 206 | { |
217 | return mJournal; | 207 | return mJournal; |
218 | } | 208 | } |
219 | 209 | ||
220 | void JournalEntry::setDirty() | 210 | void JournalEntry::setDirty() |
221 | { | 211 | { |
222 | mDirty = true; | 212 | mDirty = true; |
223 | 213 | ||
224 | // kdDebug() << "JournalEntry::setDirty()" << endl; | 214 | // kdDebug() << "JournalEntry::setDirty()" << endl; |
225 | } | 215 | } |
226 | 216 | ||
227 | void JournalEntry::clear() | 217 | void JournalEntry::clear() |
228 | { | 218 | { |
229 | mJournal = 0; | 219 | mJournal = 0; |
230 | mEditor->setText(""); | 220 | mEditor->setText(""); |
231 | } | 221 | } |
232 | 222 | ||
233 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) | 223 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) |
234 | { | 224 | { |
235 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; | 225 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; |
@@ -253,40 +243,39 @@ void JournalEntry::writeJournal() | |||
253 | // kdDebug() << "JournalEntry::writeJournal()" << endl; | 243 | // kdDebug() << "JournalEntry::writeJournal()" << endl; |
254 | if (!mDirty) return; | 244 | if (!mDirty) return; |
255 | 245 | ||
256 | if (mEditor->text().isEmpty()) { | 246 | if (mEditor->text().isEmpty()) { |
257 | if ( mJournal ) { | 247 | if ( mJournal ) { |
258 | mDirty = false; | 248 | mDirty = false; |
259 | bool conf = KOPrefs::instance()->mConfirm; | 249 | bool conf = KOPrefs::instance()->mConfirm; |
260 | KOPrefs::instance()->mConfirm = false; | 250 | KOPrefs::instance()->mConfirm = false; |
261 | emit deleteJournal(mJournal); | 251 | emit deleteJournal(mJournal); |
262 | KOPrefs::instance()->mConfirm = conf; | 252 | KOPrefs::instance()->mConfirm = conf; |
263 | mJournal = 0; | 253 | mJournal = 0; |
264 | } | 254 | } |
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 | ||
282 | void JournalEntry::flushEntry() | 271 | void JournalEntry::flushEntry() |
283 | { | 272 | { |
284 | if (!mDirty) return; | 273 | if (!mDirty) return; |
285 | 274 | ||
286 | writeJournal(); | 275 | writeJournal(); |
287 | } | 276 | } |
288 | void JournalEntry::keyPressEvent ( QKeyEvent * e ) | 277 | void JournalEntry::keyPressEvent ( QKeyEvent * e ) |
289 | { | 278 | { |
290 | e->ignore(); | 279 | e->ignore(); |
291 | 280 | ||
292 | } | 281 | } |