summaryrefslogtreecommitdiffabout
path: root/korganizer/journalentry.cpp
Unidiff
Diffstat (limited to 'korganizer/journalentry.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/journalentry.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp
index b8a4cf2..f0e0f86 100644
--- a/korganizer/journalentry.cpp
+++ b/korganizer/journalentry.cpp
@@ -1,226 +1,246 @@
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
59JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : 59JournalEntry::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 vb->setStretchFactor (new QLabel(" "+i18n("Title: "),vb),1); 79 QLabel* textLabel = new QLabel(" "+i18n("Title: "),vb);
80 vb->setStretchFactor (textLabel,1);
80 vb->setStretchFactor( toggleJournal, 1 ); 81 vb->setStretchFactor( toggleJournal, 1 );
81 mTitle = new KOLocationBox(TRUE, vb, 30); 82 mTitle = new KOLocationBox(TRUE, vb, 30);
82 mTitle->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) ); 83 mTitle->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) );
83 mCalendarBox = new QComboBox(vb); 84 mCalendarBox = new QComboBox(vb);
84 mCalendarBox->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) ); 85 mCalendarBox->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) );
85#ifndef DESKTOP_VERSION 86#ifndef DESKTOP_VERSION
86 mTitle->setSizeLimit( 8 ); 87 mTitle->setSizeLimit( 8 );
87 mCalendarBox->setSizeLimit( 8 ); 88 mCalendarBox->setSizeLimit( 8 );
88#endif 89#endif
89 vb->setStretchFactor ( mTitle, 8 ); 90 vb->setStretchFactor ( mTitle, 8 );
90 vb->setStretchFactor ( mCalendarBox, 3 ); 91 vb->setStretchFactor ( mCalendarBox, 3 );
91 //mTitleLabel->setMargin(0); 92 //mTitleLabel->setMargin(0);
92 //mTitleLabel->setAlignment(AlignCenter); 93 //mTitleLabel->setAlignment(AlignCenter);
93 QPushButton * loadTemplate = new QPushButton( vb ); 94 QPushButton * loadTemplate = new QPushButton( vb );
94 QPushButton * saveTemplate = new QPushButton( vb ); 95 QPushButton * saveTemplate = new QPushButton( vb );
95 if ( QApplication::desktop()->width() < 321 ) 96 if ( QApplication::desktop()->width() < 321 )
96 iconp = SmallIcon("fileexport16"); 97 iconp = SmallIcon("fileexport16");
97 else 98 else
98 iconp = SmallIcon("fileexport"); 99 iconp = SmallIcon("fileexport");
99 saveTemplate->setPixmap (iconp ) ; 100 saveTemplate->setPixmap (iconp ) ;
100 int size = saveTemplate->sizeHint().height(); 101 int size = saveTemplate->sizeHint().height();
101 if ( QApplication::desktop()->width() < 321 ) 102 if ( QApplication::desktop()->width() < 321 )
102 iconp = SmallIcon("fileimport16"); 103 iconp = SmallIcon("fileimport16");
103 else 104 else
104 iconp = SmallIcon("fileimport"); 105 iconp = SmallIcon("fileimport");
105 loadTemplate->setPixmap (iconp ) ; 106 loadTemplate->setPixmap (iconp ) ;
106 loadTemplate->setFixedSize( size, size ); 107 loadTemplate->setFixedSize( size, size );
107 saveTemplate->setFixedSize( size, size ); 108 saveTemplate->setFixedSize( size, size );
108 toggleJournal->setFixedSize( size , size ); 109 toggleJournal->setFixedSize( size , size );
109 mTitle->setFixedHeight( size+4); 110 mTitle->setFixedHeight( size+4);
110 mCalendarBox->setFixedHeight( size+4); 111 mCalendarBox->setFixedHeight( size+4);
111 mEditor = new KTextEdit(this); 112 mEditor = new KTextEdit(this);
112#ifndef DESKTOP_VERSION 113#ifndef DESKTOP_VERSION
113 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); 114 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold );
114#endif 115#endif
116 mMaxWidDiff = 3*size - 2*frameWidth() - textLabel->sizeHint().width();
117 mDeskWid = QApplication::desktop()->width();
118 int maxwid = mDeskWid - mMaxWidDiff;
119 mTitle->setMaximumWidth( maxwid/2 +20 );
120 mCalendarBox->setMaximumWidth( maxwid/2 -20 );
115 mEditor->setWordWrap( KTextEdit::WidgetWidth ); 121 mEditor->setWordWrap( KTextEdit::WidgetWidth );
116 QBoxLayout *topLayout = new QVBoxLayout(this); 122 QBoxLayout *topLayout = new QVBoxLayout(this);
117 topLayout->addWidget(vb); 123 topLayout->addWidget(vb);
118 topLayout->addWidget(mEditor); 124 topLayout->addWidget(mEditor);
119 mEditor->installEventFilter(this); 125 mEditor->installEventFilter(this);
120 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 126 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
121 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 127 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
122 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); 128 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) );
123 mTitle->load( KOLocationBox::SUMMARYJOURNAL ); 129 mTitle->load( KOLocationBox::SUMMARYJOURNAL );
124 mTitle->lineEdit ()->setText(""); 130 mTitle->lineEdit ()->setText("");
125} 131}
126 132
127JournalEntry::~JournalEntry() 133JournalEntry::~JournalEntry()
128{ 134{
129 //qDebug("JournalEntry::~JournalEntry() "); 135 //qDebug("JournalEntry::~JournalEntry() ");
130} 136}
137void JournalEntry::resizeEvent(QResizeEvent* e )
138{
139#ifndef DESKTOP_VERSION
140 if ( mDeskWid != QApplication::desktop()->width() ) {
141 mDeskWid == QApplication::desktop()->width();
142 int maxwid = mDeskWid - mMaxWidDiff;
143 mTitle->setMaximumWidth( maxwid/2 +20 );
144 mCalendarBox->setMaximumWidth( maxwid/2 -20 );
145 }
146 setMaximumWidth( QApplication::desktop()->width() );
147 qDebug("MAXXX %d ", QApplication::desktop()->width());
148#endif
149 QFrame::resizeEvent( e );
150}
131QSize JournalEntry::sizeHint() const 151QSize JournalEntry::sizeHint() const
132{ 152{
133 return QSize ( 240, heiHint ); 153 return QSize ( 240, heiHint );
134} 154}
135void JournalEntry::slotSaveTemplate() 155void JournalEntry::slotSaveTemplate()
136{ 156{
137 QString fileName =locateLocal( "templates", "journals" ); 157 QString fileName =locateLocal( "templates", "journals" );
138 QDir t_dir; 158 QDir t_dir;
139 if ( !t_dir.exists(fileName) ) 159 if ( !t_dir.exists(fileName) )
140 t_dir.mkdir ( fileName ); 160 t_dir.mkdir ( fileName );
141 fileName += "/journal"; 161 fileName += "/journal";
142 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); 162 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this );
143 if ( fileName.length() == 0 ) 163 if ( fileName.length() == 0 )
144 return; 164 return;
145 165
146 QFile fileIn( fileName ); 166 QFile fileIn( fileName );
147 if (!fileIn.open( IO_WriteOnly ) ) { 167 if (!fileIn.open( IO_WriteOnly ) ) {
148 KMessageBox::error( this, i18n("Error saving template file\n '%1'.") 168 KMessageBox::error( this, i18n("Error saving template file\n '%1'.")
149 .arg( fileName ) ); 169 .arg( fileName ) );
150 return; 170 return;
151 } 171 }
152 // QString text; 172 // QString text;
153 QTextStream tsIn( &fileIn ); 173 QTextStream tsIn( &fileIn );
154 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 174 tsIn.setCodec( QTextCodec::codecForName("utf8") );
155 tsIn << mEditor->text(); 175 tsIn << mEditor->text();
156 fileIn.close(); 176 fileIn.close();
157} 177}
158void JournalEntry::slotLoadTemplate() 178void JournalEntry::slotLoadTemplate()
159{ 179{
160 QString fileName =locateLocal( "templates", "journals" ); 180 QString fileName =locateLocal( "templates", "journals" );
161 QDir t_dir; 181 QDir t_dir;
162 if ( !t_dir.exists(fileName) ) 182 if ( !t_dir.exists(fileName) )
163 t_dir.mkdir ( fileName ); 183 t_dir.mkdir ( fileName );
164 fileName += "/journal"; 184 fileName += "/journal";
165 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); 185 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this );
166 if ( fileName.length() == 0 ) 186 if ( fileName.length() == 0 )
167 return; 187 return;
168 QFile fileIn( fileName ); 188 QFile fileIn( fileName );
169 if (!fileIn.open( IO_ReadOnly ) ) { 189 if (!fileIn.open( IO_ReadOnly ) ) {
170 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 190 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
171 .arg( fileName ) ); 191 .arg( fileName ) );
172 return; 192 return;
173 } 193 }
174 QTextStream tsIn( &fileIn ); 194 QTextStream tsIn( &fileIn );
175 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 195 tsIn.setCodec( QTextCodec::codecForName("utf8") );
176 QString text = tsIn.read(); 196 QString text = tsIn.read();
177 fileIn.close(); 197 fileIn.close();
178 int line, col; 198 int line, col;
179 mEditor->getCursorPosition (& line, & col ); 199 mEditor->getCursorPosition (& line, & col );
180 mEditor-> insertAt ( text, line, col, true ); 200 mEditor-> insertAt ( text, line, col, true );
181 //mEditor->setIgnoreMark( true ); 201 //mEditor->setIgnoreMark( true );
182} 202}
183void JournalEntry::setDate(const QDate &date) 203void JournalEntry::setDate(const QDate &date)
184{ 204{
185 showOnlyMode = false; 205 showOnlyMode = false;
186 writeJournal(); 206 writeJournal();
187 mDate = date; 207 mDate = date;
188 fillCalendar( mCalendar->defaultCalendar() ); 208 fillCalendar( mCalendar->defaultCalendar() );
189} 209}
190void JournalEntry::fillCalendar( int setToID ) 210void JournalEntry::fillCalendar( int setToID )
191{ 211{
192 mCalendarBox->clear(); 212 mCalendarBox->clear();
193 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); 213 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first();
194 int std = 0; 214 int std = 0;
195 int count = 0; 215 int count = 0;
196 while ( kkf ) { 216 while ( kkf ) {
197 if ( (!kkf->mErrorOnLoad &&! kkf->isReadOnly) || setToID == kkf->mCalNumber ) { 217 if ( (!kkf->mErrorOnLoad &&! kkf->isReadOnly) || setToID == kkf->mCalNumber ) {
198 if ( setToID ) { 218 if ( setToID ) {
199 if ( kkf->mCalNumber == setToID ) 219 if ( kkf->mCalNumber == setToID )
200 std = count; 220 std = count;
201 } else { 221 } else {
202 if ( kkf->isStandard ) { 222 if ( kkf->isStandard ) {
203 std = count; 223 std = count;
204 } 224 }
205 } 225 }
206 ++count; 226 ++count;
207 mCalendarBox->insertItem( kkf->mName ); 227 mCalendarBox->insertItem( kkf->mName );
208 } 228 }
209 kkf = KOPrefs::instance()->mCalendars.next(); 229 kkf = KOPrefs::instance()->mCalendars.next();
210 } 230 }
211 mCalendarBox->setCurrentItem( std ); 231 mCalendarBox->setCurrentItem( std );
212} 232}
213 233
214void JournalEntry::toggleShowJournal() 234void JournalEntry::toggleShowJournal()
215{ 235{
216 if (!mEditor->text().isEmpty() || !mTitle->currentText ().isEmpty()) 236 if (!mEditor->text().isEmpty() || !mTitle->currentText ().isEmpty())
217 flushEntry(); 237 flushEntry();
218 if ( showOnlyMode ) 238 if ( showOnlyMode )
219 emit showJournalOnly( 0 ); 239 emit showJournalOnly( 0 );
220 else { 240 else {
221 // we have to protect mJournal from deleting if mJournal has empty text 241 // we have to protect mJournal from deleting if mJournal has empty text
222 visibleMode = false; // set to true via :setShowOnly() 242 visibleMode = false; // set to true via :setShowOnly()
223 emit showJournalOnly( mJournal ); 243 emit showJournalOnly( mJournal );
224 //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) ); 244 //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) );
225 } 245 }
226} 246}