-rw-r--r-- | korganizer/journalentry.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp index 5269af7..2814c61 100644 --- a/korganizer/journalentry.cpp +++ b/korganizer/journalentry.cpp | |||
@@ -17,69 +17,76 @@ | |||
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 <q3vbox.h> |
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qtextstream.h> | 32 | #include <q3textstream.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 | #include <QDesktopWidget> | ||
38 | //Added by qt3to4: | ||
39 | #include <QResizeEvent> | ||
40 | #include <Q3Frame> | ||
41 | #include <QKeyEvent> | ||
42 | #include <QEvent> | ||
43 | #include <Q3VBoxLayout> | ||
37 | 44 | ||
38 | #include <kdebug.h> | 45 | #include <kdebug.h> |
39 | #include <kglobal.h> | 46 | #include <kglobal.h> |
40 | #include <klocale.h> | 47 | #include <klocale.h> |
41 | #include <ktextedit.h> | 48 | #include <ktextedit.h> |
42 | #include <kfiledialog.h> | 49 | #include <kfiledialog.h> |
43 | #include <kmessagebox.h> | 50 | #include <kmessagebox.h> |
44 | #include "koprefs.h" | 51 | #include "koprefs.h" |
45 | #include <klineedit.h> | 52 | #include <klineedit.h> |
46 | #include <kdialog.h> | 53 | #include <kdialog.h> |
47 | #include "kolocationbox.h" | 54 | #include "kolocationbox.h" |
48 | 55 | ||
49 | #include <libkcal/journal.h> | 56 | #include <libkcal/journal.h> |
50 | #include <libkcal/calendarresources.h> | 57 | #include <libkcal/calendarresources.h> |
51 | #include <libkcal/resourcecalendar.h> | 58 | #include <libkcal/resourcecalendar.h> |
52 | #include <kresources/resourceselectdialog.h> | 59 | #include <kresources/resourceselectdialog.h> |
53 | 60 | ||
54 | #include "journalentry.h" | 61 | #include "journalentry.h" |
55 | //#include "journalentry.moc" | 62 | //#include "journalentry.moc" |
56 | #ifndef DESKTOP_VERSION | 63 | #ifndef DESKTOP_VERSION |
57 | #include <qpe/qpeapplication.h> | 64 | #include <qpe/qpeapplication.h> |
58 | #endif | 65 | #endif |
59 | JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | 66 | JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : |
60 | QFrame(parent) | 67 | Q3Frame(parent) |
61 | { | 68 | { |
62 | 69 | ||
63 | int fac = 5; | 70 | int fac = 5; |
64 | heiHint = QApplication::desktop()->height(); | 71 | heiHint = QApplication::desktop()->height(); |
65 | if ( heiHint > 800 ) | 72 | if ( heiHint > 800 ) |
66 | fac += 2; | 73 | fac += 2; |
67 | heiHint = heiHint / fac; | 74 | heiHint = heiHint / fac; |
68 | 75 | ||
69 | showOnlyMode = false; | 76 | showOnlyMode = false; |
70 | mCalendar = calendar; | 77 | mCalendar = calendar; |
71 | mJournal = 0; | 78 | mJournal = 0; |
72 | visibleMode = true; | 79 | visibleMode = true; |
73 | QHBox * vb = new QHBox ( this ); | 80 | Q3HBox * vb = new Q3HBox ( this ); |
74 | QPixmap iconp; | 81 | QPixmap iconp; |
75 | vb->setMargin ( KDialog::marginHint()-1 ); | 82 | vb->setMargin ( KDialog::marginHint()-1 ); |
76 | QPushButton * toggleJournal = new QPushButton( vb ); | 83 | QPushButton * toggleJournal = new QPushButton( vb ); |
77 | iconp = SmallIcon("1updownarrow"); | 84 | iconp = SmallIcon("1updownarrow"); |
78 | toggleJournal->setPixmap (iconp ) ; | 85 | toggleJournal->setPixmap (iconp ) ; |
79 | QLabel* textLabel = new QLabel(" "+i18n("Title: "),vb); | 86 | QLabel* textLabel = new QLabel(" "+i18n("Title: "),vb); |
80 | mTitle = new KOLocationBox(TRUE, vb, 30); | 87 | mTitle = new KOLocationBox(TRUE, vb, 30); |
81 | mTitle->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::Fixed ,FALSE) ); | 88 | mTitle->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::Fixed ,FALSE) ); |
82 | mCalendarBox = new QComboBox(vb); | 89 | mCalendarBox = new QComboBox(vb); |
83 | mCalendarBox->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::Fixed ,FALSE) ); | 90 | mCalendarBox->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::Fixed ,FALSE) ); |
84 | #ifndef DESKTOP_VERSION | 91 | #ifndef DESKTOP_VERSION |
85 | mTitle->setSizeLimit( 8 ); | 92 | mTitle->setSizeLimit( 8 ); |
@@ -120,31 +127,31 @@ JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | |||
120 | mMaxWidDiff = 3*size - 2*frameWidth() - textLabel->sizeHint().width(); | 127 | mMaxWidDiff = 3*size - 2*frameWidth() - textLabel->sizeHint().width(); |
121 | mDeskWid = QApplication::desktop()->width(); | 128 | mDeskWid = QApplication::desktop()->width(); |
122 | int maxwid = mDeskWid - mMaxWidDiff; | 129 | int maxwid = mDeskWid - mMaxWidDiff; |
123 | if ( QApplication::desktop()->width() < 640 ) { | 130 | if ( QApplication::desktop()->width() < 640 ) { |
124 | mTitle->setMaximumWidth( maxwid/2 +20 ); | 131 | mTitle->setMaximumWidth( maxwid/2 +20 ); |
125 | mCalendarBox->setMaximumWidth( maxwid/2 -20); | 132 | mCalendarBox->setMaximumWidth( maxwid/2 -20); |
126 | } else { | 133 | } else { |
127 | mTitle->setMaximumWidth( (maxwid/4)*3); | 134 | mTitle->setMaximumWidth( (maxwid/4)*3); |
128 | mCalendarBox->setMaximumWidth( maxwid/2 ); | 135 | mCalendarBox->setMaximumWidth( maxwid/2 ); |
129 | } | 136 | } |
130 | //mCalendarBox->setMaximumWidth( maxwid/2 -20 ); | 137 | //mCalendarBox->setMaximumWidth( maxwid/2 -20 ); |
131 | mEditor->setWordWrap( KTextEdit::WidgetWidth ); | 138 | mEditor->setWordWrap( KTextEdit::WidgetWidth ); |
132 | QBoxLayout *topLayout = new QVBoxLayout(this); | 139 | Q3BoxLayout *topLayout = new Q3VBoxLayout(this); |
133 | topLayout->addWidget(vb); | 140 | topLayout->addWidget(vb); |
134 | topLayout->addWidget(mEditor); | 141 | topLayout->addWidget(mEditor); |
135 | mEditor->installEventFilter(this); | 142 | mEditor->installEventFilter(this); |
136 | installEventFilter(this); | 143 | installEventFilter(this); |
137 | mTitle->installEventFilter(this); | 144 | mTitle->installEventFilter(this); |
138 | setFocusPolicy (QWidget::NoFocus); | 145 | setFocusPolicy (Qt::NoFocus); |
139 | 146 | ||
140 | connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); | 147 | connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); |
141 | connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); | 148 | connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); |
142 | connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); | 149 | connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); |
143 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); | 150 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); |
144 | mTitle->lineEdit ()->setText(""); | 151 | mTitle->lineEdit ()->setText(""); |
145 | } | 152 | } |
146 | 153 | ||
147 | JournalEntry::~JournalEntry() | 154 | JournalEntry::~JournalEntry() |
148 | { | 155 | { |
149 | //qDebug("JournalEntry::~JournalEntry() "); | 156 | //qDebug("JournalEntry::~JournalEntry() "); |
150 | } | 157 | } |
@@ -159,70 +166,70 @@ void JournalEntry::resizeEvent(QResizeEvent* e ) | |||
159 | mTitle->setMaximumWidth( maxwid/2 +20 ); | 166 | mTitle->setMaximumWidth( maxwid/2 +20 ); |
160 | mCalendarBox->setMaximumWidth( maxwid/2 -20); | 167 | mCalendarBox->setMaximumWidth( maxwid/2 -20); |
161 | } | 168 | } |
162 | else { | 169 | else { |
163 | mTitle->setMaximumWidth( (maxwid/4)*3); | 170 | mTitle->setMaximumWidth( (maxwid/4)*3); |
164 | mCalendarBox->setMaximumWidth( maxwid/2 ); | 171 | mCalendarBox->setMaximumWidth( maxwid/2 ); |
165 | } | 172 | } |
166 | //mCalendarBox->setMaximumWidth( maxwid/2 -20 ); | 173 | //mCalendarBox->setMaximumWidth( maxwid/2 -20 ); |
167 | } | 174 | } |
168 | //setMaximumWidth( QApplication::desktop()->width() ); | 175 | //setMaximumWidth( QApplication::desktop()->width() ); |
169 | //qDebug("MAXXX %d ", QApplication::desktop()->width()); | 176 | //qDebug("MAXXX %d ", QApplication::desktop()->width()); |
170 | #endif | 177 | #endif |
171 | QFrame::resizeEvent( e ); | 178 | Q3Frame::resizeEvent( e ); |
172 | } | 179 | } |
173 | QSize JournalEntry::sizeHint() const | 180 | QSize JournalEntry::sizeHint() const |
174 | { | 181 | { |
175 | return QSize ( 240, heiHint ); | 182 | return QSize ( 240, heiHint ); |
176 | } | 183 | } |
177 | void JournalEntry::slotSaveTemplate() | 184 | void JournalEntry::slotSaveTemplate() |
178 | { | 185 | { |
179 | QString fileName =locateLocal( "templates", "journals" ); | 186 | QString fileName =locateLocal( "templates", "journals" ); |
180 | QDir t_dir; | 187 | QDir t_dir; |
181 | if ( !t_dir.exists(fileName) ) | 188 | if ( !t_dir.exists(fileName) ) |
182 | t_dir.mkdir ( fileName ); | 189 | t_dir.mkdir ( fileName ); |
183 | fileName += "/journal"; | 190 | fileName += "/journal"; |
184 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); | 191 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); |
185 | if ( fileName.length() == 0 ) | 192 | if ( fileName.length() == 0 ) |
186 | return; | 193 | return; |
187 | 194 | ||
188 | QFile fileIn( fileName ); | 195 | QFile fileIn( fileName ); |
189 | if (!fileIn.open( IO_WriteOnly ) ) { | 196 | if (!fileIn.open( QIODevice::WriteOnly ) ) { |
190 | KMessageBox::error( this, i18n("Error saving template file\n '%1'.") | 197 | KMessageBox::error( this, i18n("Error saving template file\n '%1'.") |
191 | .arg( fileName ) ); | 198 | .arg( fileName ) ); |
192 | return; | 199 | return; |
193 | } | 200 | } |
194 | // QString text; | 201 | // QString text; |
195 | QTextStream tsIn( &fileIn ); | 202 | Q3TextStream tsIn( &fileIn ); |
196 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 203 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
197 | tsIn << mEditor->text(); | 204 | tsIn << mEditor->text(); |
198 | fileIn.close(); | 205 | fileIn.close(); |
199 | } | 206 | } |
200 | void JournalEntry::slotLoadTemplate() | 207 | void JournalEntry::slotLoadTemplate() |
201 | { | 208 | { |
202 | QString fileName =locateLocal( "templates", "journals" ); | 209 | QString fileName =locateLocal( "templates", "journals" ); |
203 | QDir t_dir; | 210 | QDir t_dir; |
204 | if ( !t_dir.exists(fileName) ) | 211 | if ( !t_dir.exists(fileName) ) |
205 | t_dir.mkdir ( fileName ); | 212 | t_dir.mkdir ( fileName ); |
206 | fileName += "/journal"; | 213 | fileName += "/journal"; |
207 | fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); | 214 | fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); |
208 | if ( fileName.length() == 0 ) | 215 | if ( fileName.length() == 0 ) |
209 | return; | 216 | return; |
210 | QFile fileIn( fileName ); | 217 | QFile fileIn( fileName ); |
211 | if (!fileIn.open( IO_ReadOnly ) ) { | 218 | if (!fileIn.open( QIODevice::ReadOnly ) ) { |
212 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") | 219 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") |
213 | .arg( fileName ) ); | 220 | .arg( fileName ) ); |
214 | return; | 221 | return; |
215 | } | 222 | } |
216 | QTextStream tsIn( &fileIn ); | 223 | Q3TextStream tsIn( &fileIn ); |
217 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 224 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
218 | QString text = tsIn.read(); | 225 | QString text = tsIn.read(); |
219 | fileIn.close(); | 226 | fileIn.close(); |
220 | int line, col; | 227 | int line, col; |
221 | mEditor->getCursorPosition (& line, & col ); | 228 | mEditor->getCursorPosition (& line, & col ); |
222 | mEditor-> insertAt ( text, line, col, true ); | 229 | mEditor-> insertAt ( text, line, col, true ); |
223 | //mEditor->setIgnoreMark( true ); | 230 | //mEditor->setIgnoreMark( true ); |
224 | } | 231 | } |
225 | void JournalEntry::setDate(const QDate &date) | 232 | void JournalEntry::setDate(const QDate &date) |
226 | { | 233 | { |
227 | showOnlyMode = false; | 234 | showOnlyMode = false; |
228 | writeJournal(); | 235 | writeJournal(); |
@@ -307,44 +314,44 @@ Journal *JournalEntry::journal() const | |||
307 | void JournalEntry::clear() | 314 | void JournalEntry::clear() |
308 | { | 315 | { |
309 | mJournal = 0; | 316 | mJournal = 0; |
310 | mEditor->setText(""); | 317 | mEditor->setText(""); |
311 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); | 318 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); |
312 | mTitle->lineEdit ()->setText(""); | 319 | mTitle->lineEdit ()->setText(""); |
313 | } | 320 | } |
314 | 321 | ||
315 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) | 322 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) |
316 | { | 323 | { |
317 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; | 324 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; |
318 | if ( isVisible() ) { | 325 | if ( isVisible() ) { |
319 | mEditor->setFocusPolicy (QWidget::StrongFocus); | 326 | mEditor->setFocusPolicy (Qt::StrongFocus); |
320 | mTitle->setFocusPolicy (QWidget::StrongFocus); | 327 | mTitle->setFocusPolicy (Qt::StrongFocus); |
321 | } else { | 328 | } else { |
322 | mEditor->setFocusPolicy (QWidget::NoFocus); | 329 | mEditor->setFocusPolicy (Qt::NoFocus); |
323 | mTitle->setFocusPolicy (QWidget::NoFocus); | 330 | mTitle->setFocusPolicy (Qt::NoFocus); |
324 | } | 331 | } |
325 | if ( e->type() == QEvent::FocusOut ) { | 332 | if ( e->type() == QEvent::FocusOut ) { |
326 | writeJournal(); | 333 | writeJournal(); |
327 | } | 334 | } |
328 | if ( e->type() == QEvent::KeyPress ) { | 335 | if ( e->type() == QEvent::KeyPress ) { |
329 | QKeyEvent * k = (QKeyEvent *) e; | 336 | QKeyEvent * k = (QKeyEvent *) e; |
330 | if ( !isVisible() ) | 337 | if ( !isVisible() ) |
331 | return true; | 338 | return true; |
332 | if ( k->state() == Qt::ControlButton ) { | 339 | if ( k->state() == Qt::ControlButton ) { |
333 | k->ignore(); | 340 | k->ignore(); |
334 | //return true; | 341 | //return true; |
335 | } | 342 | } |
336 | } | 343 | } |
337 | 344 | ||
338 | return QFrame::eventFilter( o, e ); // standard event processing | 345 | return Q3Frame::eventFilter( o, e ); // standard event processing |
339 | } | 346 | } |
340 | 347 | ||
341 | void JournalEntry::writeJournal() | 348 | void JournalEntry::writeJournal() |
342 | { | 349 | { |
343 | if ( !visibleMode ) return; | 350 | if ( !visibleMode ) return; |
344 | if ( !mTitle->isEnabled() ) return; | 351 | if ( !mTitle->isEnabled() ) return; |
345 | if (mEditor->text().isEmpty() && mTitle->currentText().isEmpty()) { | 352 | if (mEditor->text().isEmpty() && mTitle->currentText().isEmpty()) { |
346 | if ( mJournal ) { | 353 | if ( mJournal ) { |
347 | Journal* j = mJournal; | 354 | Journal* j = mJournal; |
348 | mJournal = 0; | 355 | mJournal = 0; |
349 | bool conf = KOPrefs::instance()->mConfirm; | 356 | bool conf = KOPrefs::instance()->mConfirm; |
350 | KOPrefs::instance()->mConfirm = false; | 357 | KOPrefs::instance()->mConfirm = false; |