author | zautrix <zautrix> | 2005-07-09 11:21:22 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-07-09 11:21:22 (UTC) |
commit | e98b8d5a8e01d5dd7cf6b8967d1065d72f61c908 (patch) (unidiff) | |
tree | 0687ea02ba6cd6071cad137593b8d0e0e21e910f | |
parent | b51db424f4b1e558ab8c7c723859bb564c99d83b (diff) | |
download | kdepimpi-e98b8d5a8e01d5dd7cf6b8967d1065d72f61c908.zip kdepimpi-e98b8d5a8e01d5dd7cf6b8967d1065d72f61c908.tar.gz kdepimpi-e98b8d5a8e01d5dd7cf6b8967d1065d72f61c908.tar.bz2 |
fixxx
-rw-r--r-- | korganizer/journalentry.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp index f0e0f86..739949d 100644 --- a/korganizer/journalentry.cpp +++ b/korganizer/journalentry.cpp | |||
@@ -1,353 +1,370 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
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 | #include <klineedit.h> |
46 | #include <kdialog.h> | 46 | #include <kdialog.h> |
47 | #include "kolocationbox.h" | 47 | #include "kolocationbox.h" |
48 | 48 | ||
49 | #include <libkcal/journal.h> | 49 | #include <libkcal/journal.h> |
50 | #include <libkcal/calendarresources.h> | 50 | #include <libkcal/calendarresources.h> |
51 | #include <libkcal/resourcecalendar.h> | 51 | #include <libkcal/resourcecalendar.h> |
52 | #include <kresources/resourceselectdialog.h> | 52 | #include <kresources/resourceselectdialog.h> |
53 | 53 | ||
54 | #include "journalentry.h" | 54 | #include "journalentry.h" |
55 | //#include "journalentry.moc" | 55 | //#include "journalentry.moc" |
56 | #ifndef DESKTOP_VERSION | 56 | #ifndef DESKTOP_VERSION |
57 | #include <qpe/qpeapplication.h> | 57 | #include <qpe/qpeapplication.h> |
58 | #endif | 58 | #endif |
59 | JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | 59 | JournalEntry::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 | QLabel* textLabel = new QLabel(" "+i18n("Title: "),vb); | 79 | QLabel* textLabel = new QLabel(" "+i18n("Title: "),vb); |
80 | vb->setStretchFactor (textLabel,1); | 80 | vb->setStretchFactor (textLabel,1); |
81 | vb->setStretchFactor( toggleJournal, 1 ); | 81 | vb->setStretchFactor( toggleJournal, 1 ); |
82 | mTitle = new KOLocationBox(TRUE, vb, 30); | 82 | mTitle = new KOLocationBox(TRUE, vb, 30); |
83 | mTitle->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) ); | 83 | mTitle->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::Fixed ,FALSE) ); |
84 | mCalendarBox = new QComboBox(vb); | 84 | mCalendarBox = new QComboBox(vb); |
85 | mCalendarBox->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) ); | 85 | mCalendarBox->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::Fixed ,FALSE) ); |
86 | #ifndef DESKTOP_VERSION | 86 | #ifndef DESKTOP_VERSION |
87 | mTitle->setSizeLimit( 8 ); | 87 | mTitle->setSizeLimit( 8 ); |
88 | mCalendarBox->setSizeLimit( 8 ); | 88 | mCalendarBox->setSizeLimit( 8 ); |
89 | #endif | 89 | #endif |
90 | vb->setStretchFactor ( mTitle, 8 ); | 90 | vb->setStretchFactor ( mTitle, 8 ); |
91 | vb->setStretchFactor ( mCalendarBox, 3 ); | 91 | int limit = 3; |
92 | if ( QApplication::desktop()->width() < 640 ) | ||
93 | limit = 6; | ||
94 | vb->setStretchFactor ( mCalendarBox, limit ); | ||
92 | //mTitleLabel->setMargin(0); | 95 | //mTitleLabel->setMargin(0); |
93 | //mTitleLabel->setAlignment(AlignCenter); | 96 | //mTitleLabel->setAlignment(AlignCenter); |
94 | QPushButton * loadTemplate = new QPushButton( vb ); | 97 | QPushButton * loadTemplate = new QPushButton( vb ); |
95 | QPushButton * saveTemplate = new QPushButton( vb ); | 98 | QPushButton * saveTemplate = new QPushButton( vb ); |
96 | if ( QApplication::desktop()->width() < 321 ) | 99 | if ( QApplication::desktop()->width() < 321 ) |
97 | iconp = SmallIcon("fileexport16"); | 100 | iconp = SmallIcon("fileexport16"); |
98 | else | 101 | else |
99 | iconp = SmallIcon("fileexport"); | 102 | iconp = SmallIcon("fileexport"); |
100 | saveTemplate->setPixmap (iconp ) ; | 103 | saveTemplate->setPixmap (iconp ) ; |
101 | int size = saveTemplate->sizeHint().height(); | 104 | int size = saveTemplate->sizeHint().height(); |
102 | if ( QApplication::desktop()->width() < 321 ) | 105 | if ( QApplication::desktop()->width() < 321 ) |
103 | iconp = SmallIcon("fileimport16"); | 106 | iconp = SmallIcon("fileimport16"); |
104 | else | 107 | else |
105 | iconp = SmallIcon("fileimport"); | 108 | iconp = SmallIcon("fileimport"); |
106 | loadTemplate->setPixmap (iconp ) ; | 109 | loadTemplate->setPixmap (iconp ) ; |
107 | loadTemplate->setFixedSize( size, size ); | 110 | loadTemplate->setFixedSize( size, size ); |
108 | saveTemplate->setFixedSize( size, size ); | 111 | saveTemplate->setFixedSize( size, size ); |
109 | toggleJournal->setFixedSize( size , size ); | 112 | toggleJournal->setFixedSize( size , size ); |
110 | mTitle->setFixedHeight( size+4); | 113 | mTitle->setFixedHeight( size+4); |
111 | mCalendarBox->setFixedHeight( size+4); | 114 | mCalendarBox->setFixedHeight( size+4); |
112 | mEditor = new KTextEdit(this); | 115 | mEditor = new KTextEdit(this); |
113 | #ifndef DESKTOP_VERSION | 116 | #ifndef DESKTOP_VERSION |
114 | QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); | 117 | QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); |
115 | #endif | 118 | #endif |
116 | mMaxWidDiff = 3*size - 2*frameWidth() - textLabel->sizeHint().width(); | 119 | mMaxWidDiff = 3*size - 2*frameWidth() - textLabel->sizeHint().width(); |
117 | mDeskWid = QApplication::desktop()->width(); | 120 | mDeskWid = QApplication::desktop()->width(); |
118 | int maxwid = mDeskWid - mMaxWidDiff; | 121 | int maxwid = mDeskWid - mMaxWidDiff; |
119 | mTitle->setMaximumWidth( maxwid/2 +20 ); | 122 | if ( QApplication::desktop()->width() < 640 ) { |
120 | mCalendarBox->setMaximumWidth( maxwid/2 -20 ); | 123 | mTitle->setMaximumWidth( maxwid/2 +20 ); |
124 | mCalendarBox->setMaximumWidth( maxwid/2 -20); | ||
125 | } else { | ||
126 | mTitle->setMaximumWidth( (maxwid/4)*3); | ||
127 | mCalendarBox->setMaximumWidth( maxwid/2 ); | ||
128 | } | ||
129 | //mCalendarBox->setMaximumWidth( maxwid/2 -20 ); | ||
121 | mEditor->setWordWrap( KTextEdit::WidgetWidth ); | 130 | mEditor->setWordWrap( KTextEdit::WidgetWidth ); |
122 | QBoxLayout *topLayout = new QVBoxLayout(this); | 131 | QBoxLayout *topLayout = new QVBoxLayout(this); |
123 | topLayout->addWidget(vb); | 132 | topLayout->addWidget(vb); |
124 | topLayout->addWidget(mEditor); | 133 | topLayout->addWidget(mEditor); |
125 | mEditor->installEventFilter(this); | 134 | mEditor->installEventFilter(this); |
126 | connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); | 135 | connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); |
127 | connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); | 136 | connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); |
128 | connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); | 137 | connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); |
129 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); | 138 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); |
130 | mTitle->lineEdit ()->setText(""); | 139 | mTitle->lineEdit ()->setText(""); |
131 | } | 140 | } |
132 | 141 | ||
133 | JournalEntry::~JournalEntry() | 142 | JournalEntry::~JournalEntry() |
134 | { | 143 | { |
135 | //qDebug("JournalEntry::~JournalEntry() "); | 144 | //qDebug("JournalEntry::~JournalEntry() "); |
136 | } | 145 | } |
137 | void JournalEntry::resizeEvent(QResizeEvent* e ) | 146 | void JournalEntry::resizeEvent(QResizeEvent* e ) |
138 | { | 147 | { |
139 | #ifndef DESKTOP_VERSION | 148 | #ifndef DESKTOP_VERSION |
149 | |||
140 | if ( mDeskWid != QApplication::desktop()->width() ) { | 150 | if ( mDeskWid != QApplication::desktop()->width() ) { |
141 | mDeskWid == QApplication::desktop()->width(); | 151 | mDeskWid == QApplication::desktop()->width(); |
142 | int maxwid = mDeskWid - mMaxWidDiff; | 152 | int maxwid = mDeskWid - mMaxWidDiff; |
143 | mTitle->setMaximumWidth( maxwid/2 +20 ); | 153 | if ( QApplication::desktop()->width() < 640 ) { |
144 | mCalendarBox->setMaximumWidth( maxwid/2 -20 ); | 154 | mTitle->setMaximumWidth( maxwid/2 +20 ); |
155 | mCalendarBox->setMaximumWidth( maxwid/2 -20); | ||
156 | } | ||
157 | else { | ||
158 | mTitle->setMaximumWidth( (maxwid/4)*3); | ||
159 | mCalendarBox->setMaximumWidth( maxwid/2 ); | ||
160 | } | ||
161 | //mCalendarBox->setMaximumWidth( maxwid/2 -20 ); | ||
145 | } | 162 | } |
146 | setMaximumWidth( QApplication::desktop()->width() ); | 163 | //setMaximumWidth( QApplication::desktop()->width() ); |
147 | qDebug("MAXXX %d ", QApplication::desktop()->width()); | 164 | //qDebug("MAXXX %d ", QApplication::desktop()->width()); |
148 | #endif | 165 | #endif |
149 | QFrame::resizeEvent( e ); | 166 | QFrame::resizeEvent( e ); |
150 | } | 167 | } |
151 | QSize JournalEntry::sizeHint() const | 168 | QSize JournalEntry::sizeHint() const |
152 | { | 169 | { |
153 | return QSize ( 240, heiHint ); | 170 | return QSize ( 240, heiHint ); |
154 | } | 171 | } |
155 | void JournalEntry::slotSaveTemplate() | 172 | void JournalEntry::slotSaveTemplate() |
156 | { | 173 | { |
157 | QString fileName =locateLocal( "templates", "journals" ); | 174 | QString fileName =locateLocal( "templates", "journals" ); |
158 | QDir t_dir; | 175 | QDir t_dir; |
159 | if ( !t_dir.exists(fileName) ) | 176 | if ( !t_dir.exists(fileName) ) |
160 | t_dir.mkdir ( fileName ); | 177 | t_dir.mkdir ( fileName ); |
161 | fileName += "/journal"; | 178 | fileName += "/journal"; |
162 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); | 179 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); |
163 | if ( fileName.length() == 0 ) | 180 | if ( fileName.length() == 0 ) |
164 | return; | 181 | return; |
165 | 182 | ||
166 | QFile fileIn( fileName ); | 183 | QFile fileIn( fileName ); |
167 | if (!fileIn.open( IO_WriteOnly ) ) { | 184 | if (!fileIn.open( IO_WriteOnly ) ) { |
168 | KMessageBox::error( this, i18n("Error saving template file\n '%1'.") | 185 | KMessageBox::error( this, i18n("Error saving template file\n '%1'.") |
169 | .arg( fileName ) ); | 186 | .arg( fileName ) ); |
170 | return; | 187 | return; |
171 | } | 188 | } |
172 | // QString text; | 189 | // QString text; |
173 | QTextStream tsIn( &fileIn ); | 190 | QTextStream tsIn( &fileIn ); |
174 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 191 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
175 | tsIn << mEditor->text(); | 192 | tsIn << mEditor->text(); |
176 | fileIn.close(); | 193 | fileIn.close(); |
177 | } | 194 | } |
178 | void JournalEntry::slotLoadTemplate() | 195 | void JournalEntry::slotLoadTemplate() |
179 | { | 196 | { |
180 | QString fileName =locateLocal( "templates", "journals" ); | 197 | QString fileName =locateLocal( "templates", "journals" ); |
181 | QDir t_dir; | 198 | QDir t_dir; |
182 | if ( !t_dir.exists(fileName) ) | 199 | if ( !t_dir.exists(fileName) ) |
183 | t_dir.mkdir ( fileName ); | 200 | t_dir.mkdir ( fileName ); |
184 | fileName += "/journal"; | 201 | fileName += "/journal"; |
185 | fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); | 202 | fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); |
186 | if ( fileName.length() == 0 ) | 203 | if ( fileName.length() == 0 ) |
187 | return; | 204 | return; |
188 | QFile fileIn( fileName ); | 205 | QFile fileIn( fileName ); |
189 | if (!fileIn.open( IO_ReadOnly ) ) { | 206 | if (!fileIn.open( IO_ReadOnly ) ) { |
190 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") | 207 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") |
191 | .arg( fileName ) ); | 208 | .arg( fileName ) ); |
192 | return; | 209 | return; |
193 | } | 210 | } |
194 | QTextStream tsIn( &fileIn ); | 211 | QTextStream tsIn( &fileIn ); |
195 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 212 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
196 | QString text = tsIn.read(); | 213 | QString text = tsIn.read(); |
197 | fileIn.close(); | 214 | fileIn.close(); |
198 | int line, col; | 215 | int line, col; |
199 | mEditor->getCursorPosition (& line, & col ); | 216 | mEditor->getCursorPosition (& line, & col ); |
200 | mEditor-> insertAt ( text, line, col, true ); | 217 | mEditor-> insertAt ( text, line, col, true ); |
201 | //mEditor->setIgnoreMark( true ); | 218 | //mEditor->setIgnoreMark( true ); |
202 | } | 219 | } |
203 | void JournalEntry::setDate(const QDate &date) | 220 | void JournalEntry::setDate(const QDate &date) |
204 | { | 221 | { |
205 | showOnlyMode = false; | 222 | showOnlyMode = false; |
206 | writeJournal(); | 223 | writeJournal(); |
207 | mDate = date; | 224 | mDate = date; |
208 | fillCalendar( mCalendar->defaultCalendar() ); | 225 | fillCalendar( mCalendar->defaultCalendar() ); |
209 | } | 226 | } |
210 | void JournalEntry::fillCalendar( int setToID ) | 227 | void JournalEntry::fillCalendar( int setToID ) |
211 | { | 228 | { |
212 | mCalendarBox->clear(); | 229 | mCalendarBox->clear(); |
213 | KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); | 230 | KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); |
214 | int std = 0; | 231 | int std = 0; |
215 | int count = 0; | 232 | int count = 0; |
216 | while ( kkf ) { | 233 | while ( kkf ) { |
217 | if ( (!kkf->mErrorOnLoad &&! kkf->isReadOnly) || setToID == kkf->mCalNumber ) { | 234 | if ( (!kkf->mErrorOnLoad &&! kkf->isReadOnly) || setToID == kkf->mCalNumber ) { |
218 | if ( setToID ) { | 235 | if ( setToID ) { |
219 | if ( kkf->mCalNumber == setToID ) | 236 | if ( kkf->mCalNumber == setToID ) |
220 | std = count; | 237 | std = count; |
221 | } else { | 238 | } else { |
222 | if ( kkf->isStandard ) { | 239 | if ( kkf->isStandard ) { |
223 | std = count; | 240 | std = count; |
224 | } | 241 | } |
225 | } | 242 | } |
226 | ++count; | 243 | ++count; |
227 | mCalendarBox->insertItem( kkf->mName ); | 244 | mCalendarBox->insertItem( kkf->mName ); |
228 | } | 245 | } |
229 | kkf = KOPrefs::instance()->mCalendars.next(); | 246 | kkf = KOPrefs::instance()->mCalendars.next(); |
230 | } | 247 | } |
231 | mCalendarBox->setCurrentItem( std ); | 248 | mCalendarBox->setCurrentItem( std ); |
232 | } | 249 | } |
233 | 250 | ||
234 | void JournalEntry::toggleShowJournal() | 251 | void JournalEntry::toggleShowJournal() |
235 | { | 252 | { |
236 | if (!mEditor->text().isEmpty() || !mTitle->currentText ().isEmpty()) | 253 | if (!mEditor->text().isEmpty() || !mTitle->currentText ().isEmpty()) |
237 | flushEntry(); | 254 | flushEntry(); |
238 | if ( showOnlyMode ) | 255 | if ( showOnlyMode ) |
239 | emit showJournalOnly( 0 ); | 256 | emit showJournalOnly( 0 ); |
240 | else { | 257 | else { |
241 | // we have to protect mJournal from deleting if mJournal has empty text | 258 | // we have to protect mJournal from deleting if mJournal has empty text |
242 | visibleMode = false; // set to true via :setShowOnly() | 259 | visibleMode = false; // set to true via :setShowOnly() |
243 | emit showJournalOnly( mJournal ); | 260 | emit showJournalOnly( mJournal ); |
244 | //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) ); | 261 | //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) ); |
245 | } | 262 | } |
246 | } | 263 | } |
247 | void JournalEntry::setVisibleOn() | 264 | void JournalEntry::setVisibleOn() |
248 | { | 265 | { |
249 | visibleMode = true; | 266 | visibleMode = true; |
250 | } | 267 | } |
251 | void JournalEntry::setShowOnly() | 268 | void JournalEntry::setShowOnly() |
252 | { | 269 | { |
253 | showOnlyMode = true; | 270 | showOnlyMode = true; |
254 | if ( mTitle->currentText().isEmpty() ) | 271 | if ( mTitle->currentText().isEmpty() ) |
255 | mTitle->setFocus(); | 272 | mTitle->setFocus(); |
256 | else | 273 | else |
257 | mEditor->setFocus(); | 274 | mEditor->setFocus(); |
258 | } | 275 | } |
259 | void JournalEntry::setJournal(Journal *journal, bool saveJournal ) | 276 | void JournalEntry::setJournal(Journal *journal, bool saveJournal ) |
260 | { | 277 | { |
261 | if ( saveJournal ) | 278 | if ( saveJournal ) |
262 | writeJournal(); | 279 | writeJournal(); |
263 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); | 280 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); |
264 | 281 | ||
265 | mJournal = journal; | 282 | mJournal = journal; |
266 | if ( journal->isReadOnly() ) | 283 | if ( journal->isReadOnly() ) |
267 | mTitle->lineEdit ()->setText(mJournal->summary()+" ("+i18n("readonly")+")"); | 284 | mTitle->lineEdit ()->setText(mJournal->summary()+" ("+i18n("readonly")+")"); |
268 | else | 285 | else |
269 | mTitle->lineEdit ()->setText(mJournal->summary()); | 286 | mTitle->lineEdit ()->setText(mJournal->summary()); |
270 | mEditor->setText(mJournal->description()); | 287 | mEditor->setText(mJournal->description()); |
271 | mTitle->setEnabled (!journal->isReadOnly() ); | 288 | mTitle->setEnabled (!journal->isReadOnly() ); |
272 | mEditor->setReadOnly ( journal->isReadOnly() ); | 289 | mEditor->setReadOnly ( journal->isReadOnly() ); |
273 | mCalendarBox->setEnabled (!journal->isReadOnly() ); | 290 | mCalendarBox->setEnabled (!journal->isReadOnly() ); |
274 | fillCalendar( mJournal->calID() ); | 291 | fillCalendar( mJournal->calID() ); |
275 | } | 292 | } |
276 | 293 | ||
277 | Journal *JournalEntry::journal() const | 294 | Journal *JournalEntry::journal() const |
278 | { | 295 | { |
279 | return mJournal; | 296 | return mJournal; |
280 | } | 297 | } |
281 | 298 | ||
282 | 299 | ||
283 | void JournalEntry::clear() | 300 | void JournalEntry::clear() |
284 | { | 301 | { |
285 | mJournal = 0; | 302 | mJournal = 0; |
286 | mEditor->setText(""); | 303 | mEditor->setText(""); |
287 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); | 304 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); |
288 | mTitle->lineEdit ()->setText(""); | 305 | mTitle->lineEdit ()->setText(""); |
289 | } | 306 | } |
290 | 307 | ||
291 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) | 308 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) |
292 | { | 309 | { |
293 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; | 310 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; |
294 | 311 | ||
295 | if ( e->type() == QEvent::FocusOut ) { | 312 | if ( e->type() == QEvent::FocusOut ) { |
296 | writeJournal(); | 313 | writeJournal(); |
297 | } | 314 | } |
298 | if ( e->type() == QEvent::KeyPress ) { | 315 | if ( e->type() == QEvent::KeyPress ) { |
299 | QKeyEvent * k = (QKeyEvent *) e; | 316 | QKeyEvent * k = (QKeyEvent *) e; |
300 | if ( k->state() == Qt::ControlButton ) { | 317 | if ( k->state() == Qt::ControlButton ) { |
301 | k->ignore(); | 318 | k->ignore(); |
302 | //return true; | 319 | //return true; |
303 | } | 320 | } |
304 | } | 321 | } |
305 | 322 | ||
306 | return QFrame::eventFilter( o, e ); // standard event processing | 323 | return QFrame::eventFilter( o, e ); // standard event processing |
307 | } | 324 | } |
308 | 325 | ||
309 | void JournalEntry::writeJournal() | 326 | void JournalEntry::writeJournal() |
310 | { | 327 | { |
311 | if ( !visibleMode ) return; | 328 | if ( !visibleMode ) return; |
312 | if ( !mTitle->isEnabled() ) return; | 329 | if ( !mTitle->isEnabled() ) return; |
313 | if (mEditor->text().isEmpty() && mTitle->currentText().isEmpty()) { | 330 | if (mEditor->text().isEmpty() && mTitle->currentText().isEmpty()) { |
314 | if ( mJournal ) { | 331 | if ( mJournal ) { |
315 | Journal* j = mJournal; | 332 | Journal* j = mJournal; |
316 | mJournal = 0; | 333 | mJournal = 0; |
317 | bool conf = KOPrefs::instance()->mConfirm; | 334 | bool conf = KOPrefs::instance()->mConfirm; |
318 | KOPrefs::instance()->mConfirm = false; | 335 | KOPrefs::instance()->mConfirm = false; |
319 | emit deleteJournal(j); | 336 | emit deleteJournal(j); |
320 | KOPrefs::instance()->mConfirm = conf; | 337 | KOPrefs::instance()->mConfirm = conf; |
321 | } | 338 | } |
322 | return; | 339 | return; |
323 | } | 340 | } |
324 | 341 | ||
325 | // kdDebug() << "JournalEntry::writeJournal()..." << endl; | 342 | // kdDebug() << "JournalEntry::writeJournal()..." << endl; |
326 | 343 | ||
327 | if (!mJournal) { | 344 | if (!mJournal) { |
328 | mJournal = new Journal; | 345 | mJournal = new Journal; |
329 | mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); | 346 | mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); |
330 | mCalendar->addJournal(mJournal); | 347 | mCalendar->addJournal(mJournal); |
331 | } | 348 | } |
332 | if ( mJournal->description() != mEditor->text() ) { | 349 | if ( mJournal->description() != mEditor->text() ) { |
333 | mJournal->setDescription(mEditor->text()); | 350 | mJournal->setDescription(mEditor->text()); |
334 | } | 351 | } |
335 | if ( mJournal->summary() != mTitle->currentText() ) { | 352 | if ( mJournal->summary() != mTitle->currentText() ) { |
336 | mJournal->setSummary(mTitle->currentText()); | 353 | mJournal->setSummary(mTitle->currentText()); |
337 | mTitle->save(KOLocationBox::SUMMARYJOURNAL); | 354 | mTitle->save(KOLocationBox::SUMMARYJOURNAL); |
338 | } | 355 | } |
339 | int id = KOPrefs::instance()->getCalendarID( mCalendarBox->currentText() ); | 356 | int id = KOPrefs::instance()->getCalendarID( mCalendarBox->currentText() ); |
340 | if ( mJournal->calID() != id ) { | 357 | if ( mJournal->calID() != id ) { |
341 | mJournal->setCalID( id ); | 358 | mJournal->setCalID( id ); |
342 | } | 359 | } |
343 | } | 360 | } |
344 | 361 | ||
345 | void JournalEntry::flushEntry() | 362 | void JournalEntry::flushEntry() |
346 | { | 363 | { |
347 | writeJournal(); | 364 | writeJournal(); |
348 | } | 365 | } |
349 | void JournalEntry::keyPressEvent ( QKeyEvent * e ) | 366 | void JournalEntry::keyPressEvent ( QKeyEvent * e ) |
350 | { | 367 | { |
351 | e->ignore(); | 368 | e->ignore(); |
352 | 369 | ||
353 | } | 370 | } |