30 #include <tqcheckbox.h>
31 #include <tqwhatsthis.h>
32 #include <tqtooltip.h>
33 #include <tqtoolbutton.h>
37 #include <tdeglobal.h>
38 #include <tdelocale.h>
39 #include <ktextedit.h>
40 #include <ktimeedit.h>
41 #include <klineedit.h>
42 #include <kactivelabel.h>
43 #include <kstdguiitem.h>
44 #include <tdemessagebox.h>
46 #include <libkcal/journal.h>
49 #include "kodialogmanager.h"
50 #include "incidencechanger.h"
51 #include "koglobals.h"
53 #include "journalentry.h"
54 #include "journalentry.moc"
55 #ifndef KORG_NOPRINTER
56 #include "kocorehelper.h"
57 #include "calprinter.h"
60 class JournalTitleLable :
public KActiveLabel
63 JournalTitleLable( TQWidget *parent,
const char *name=0 ) : KActiveLabel( parent, name ) {}
65 void openLink(
const TQString & ) {}
69 JournalDateEntry::JournalDateEntry(
Calendar *calendar, TQWidget *parent ) :
70 TQVBox( parent ), mCalendar( calendar )
75 mTitle =
new JournalTitleLable(
this );
77 mTitle->setSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed );
78 connect( mTitle, TQ_SIGNAL( linkClicked(
const TQString & ) ),
79 this, TQ_SLOT( emitNewJournal() ) );
82 JournalDateEntry::~JournalDateEntry()
86 void JournalDateEntry::setDate(
const TQDate &date)
88 TQString dtstring = TQString(
"<qt><center><b><i>%1</i></b> " )
89 .arg( TDEGlobal::locale()->formatDate(date) );
91 dtstring +=
" <font size=\"-1\"><a href=\"#\">" +
92 i18n(
"[Add Journal Entry]") +
93 "</a></font></center></qt>";
95 mTitle->setText( dtstring );
97 emit setDateSignal( date );
100 void JournalDateEntry::clear()
102 TQValueList<JournalEntry*> values( mEntries.values() );
104 TQValueList<JournalEntry*>::Iterator it = values.begin();
105 for ( ; it != values.end(); ++it ) {
112 void JournalDateEntry::addJournal(
Journal *j )
114 TQMap<Journal*,JournalEntry*>::Iterator pos = mEntries.find( j );
115 if ( pos != mEntries.end() )
return;
117 JournalEntry *entry =
new JournalEntry( j,
this );
119 entry->setDate( mDate );
120 entry->setIncidenceChanger( mChanger );
122 mEntries.insert( j, entry );
123 connect(
this, TQ_SIGNAL( setIncidenceChangerSignal( IncidenceChangerBase * ) ),
124 entry, TQ_SLOT( setIncidenceChanger( IncidenceChangerBase * ) ) );
125 connect(
this, TQ_SIGNAL( setDateSignal(
const TQDate & ) ),
126 entry, TQ_SLOT( setDate(
const TQDate & ) ) );
127 connect(
this, TQ_SIGNAL( flushEntries() ),
128 entry, TQ_SLOT( flushEntry() ) );
129 connect( entry, TQ_SIGNAL( deleteIncidence(
Incidence* ) ),
130 this, TQ_SIGNAL( deleteIncidence(
Incidence* ) ) );
131 connect( entry, TQ_SIGNAL( editIncidence(
Incidence*,
const TQDate& ) ),
132 this, TQ_SIGNAL( editIncidence(
Incidence*,
const TQDate& ) ) );
135 Journal::List JournalDateEntry::journals()
const
137 TQValueList<Journal*> jList( mEntries.keys() );
139 TQValueList<Journal*>::Iterator it = jList.begin();
140 for ( ; it != jList.end(); ++it ) {
146 void JournalDateEntry::setIncidenceChanger( IncidenceChangerBase *changer )
149 emit setIncidenceChangerSignal( changer );
152 void JournalDateEntry::emitNewJournal()
154 emit newJournal( 0, TQString(), mDate );
157 void JournalDateEntry::journalEdited(
Journal *journal )
159 TQMap<Journal*,JournalEntry*>::Iterator pos = mEntries.find( journal );
160 if ( pos == mEntries.end() )
return;
162 pos.data()->setJournal( journal );
166 void JournalDateEntry::journalDeleted(
Journal *journal )
168 TQMap<Journal*,JournalEntry*>::Iterator pos = mEntries.find( journal );
169 if ( pos == mEntries.end() )
return;
178 JournalEntry::JournalEntry(
Journal* j, TQWidget *parent ) :
179 TQWidget( parent ), mJournal( j )
183 mWriteInProgress =
false;
187 mLayout =
new TQGridLayout(
this );
188 mLayout->setSpacing( KDialog::spacingHint() );
189 mLayout->setMargin( KDialog::marginHint() );
191 TQString whatsThis = i18n(
"Sets the Title of this journal entry.");
193 mTitleLabel =
new TQLabel( i18n(
"&Title: "),
this );
194 mLayout->addWidget( mTitleLabel, 0, 0 );
195 mTitleEdit =
new KLineEdit(
this );
196 mLayout->addWidget( mTitleEdit, 0, 1 );
197 mTitleLabel->setBuddy( mTitleEdit );
199 TQWhatsThis::add( mTitleLabel, whatsThis );
200 TQWhatsThis::add( mTitleEdit, whatsThis );
202 mTimeCheck =
new TQCheckBox( i18n(
"Ti&me: "),
this );
203 mLayout->addWidget( mTimeCheck, 0, 2 );
204 mTimeEdit =
new KTimeEdit(
this );
205 mLayout->addWidget( mTimeEdit, 0, 3 );
206 connect( mTimeCheck, TQ_SIGNAL(toggled(
bool)),
207 this, TQ_SLOT(timeCheckBoxToggled(
bool)) );
208 TQWhatsThis::add( mTimeCheck, i18n(
"Determines whether this journal entry has "
209 "a time associated with it") );
210 TQWhatsThis::add( mTimeEdit, i18n(
"Sets the time associated with this journal "
213 mDeleteButton =
new TQToolButton(
this,
"deleteButton" );
214 TQPixmap pix = KOGlobals::self()->smallIcon(
"edit-delete" );
215 mDeleteButton->setPixmap( pix );
216 mDeleteButton->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
217 TQToolTip::add( mDeleteButton, i18n(
"Delete this journal entry") );
218 TQWhatsThis::add( mDeleteButton, i18n(
"Delete this journal entry") );
219 mLayout->addWidget( mDeleteButton, 0, 4 );
220 connect( mDeleteButton, TQ_SIGNAL(pressed()),
this, TQ_SLOT(deleteItem()) );
222 mEditButton =
new TQToolButton(
this,
"editButton" );
223 mEditButton->setPixmap( KOGlobals::self()->smallIcon(
"edit" ) );
224 mEditButton->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
225 TQToolTip::add( mEditButton, i18n(
"Edit this journal entry") );
226 TQWhatsThis::add( mEditButton, i18n(
"Opens an editor dialog for this journal entry") );
227 mLayout->addWidget( mEditButton, 0, 5 );
228 connect( mEditButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT( editItem() ) );
230 #ifndef KORG_NOPRINTER
231 mPrintButton =
new TQToolButton(
this,
"printButton" );
232 mPrintButton->setPixmap( KOGlobals::self()->smallIcon(
"printer" ) );
233 mPrintButton->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
234 TQToolTip::add( mPrintButton, i18n(
"Print this journal entry") );
235 TQWhatsThis::add( mPrintButton, i18n(
"Opens the print dialog for this journal entry") );
236 mLayout->addWidget( mPrintButton, 0, 6 );
237 connect( mPrintButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT( printItem() ) );
239 mEditor =
new KTextEdit(
this);
240 mLayout->addMultiCellWidget( mEditor, 1, 2, 0, 6 );
242 connect( mTitleEdit, TQ_SIGNAL(textChanged(
const TQString& )), TQ_SLOT(setDirty()) );
243 connect( mTimeCheck, TQ_SIGNAL(toggled(
bool)), TQ_SLOT(setDirty()) );
244 connect( mTimeEdit, TQ_SIGNAL(timeChanged(TQTime)), TQ_SLOT(setDirty()) );
245 connect( mEditor, TQ_SIGNAL(textChanged()), TQ_SLOT(setDirty()) );
247 mEditor->installEventFilter(
this);
249 readJournal( mJournal );
253 JournalEntry::~JournalEntry()
258 void JournalEntry::deleteItem()
267 emit deleteIncidence( mJournal );
271 void JournalEntry::editItem()
275 emit editIncidence( mJournal, mJournal->dtStart().date() );
279 void JournalEntry::printItem()
281 #ifndef KORG_NOPRINTER
286 connect(
this, TQ_SIGNAL(configChanged()), &printer, TQ_SLOT(updateConfig()) );
288 Incidence::List selectedIncidences;
289 selectedIncidences.append( mJournal );
291 printer.print( KOrg::CalPrinterBase::Incidence,
292 TQDate(), TQDate(), selectedIncidences );
297 void JournalEntry::setReadOnly(
bool readonly )
299 mReadOnly = readonly;
300 mTitleEdit->setReadOnly( mReadOnly );
301 mEditor->setReadOnly( mReadOnly );
302 mTimeCheck->setEnabled( !mReadOnly );
303 mTimeEdit->setEnabled( !mReadOnly && mTimeCheck->isChecked() );
304 mDeleteButton->setEnabled( !mReadOnly );
308 void JournalEntry::setDate(
const TQDate &date)
314 void JournalEntry::setJournal(
Journal *journal)
316 if ( !mWriteInProgress )
318 if ( !journal )
return;
321 readJournal( journal );
326 void JournalEntry::setDirty()
329 kdDebug(5850) <<
"JournalEntry::setDirty()" << endl;
332 bool JournalEntry::eventFilter( TQObject *o, TQEvent *e )
336 if ( e->type() == TQEvent::FocusOut || e->type() == TQEvent::Hide ||
337 e->type() == TQEvent::Close ) {
340 return TQWidget::eventFilter( o, e );
344 void JournalEntry::readJournal(
Journal *j )
347 mTitleEdit->setText( mJournal->summary() );
349 mTimeCheck->setChecked( hasTime );
350 mTimeEdit->setEnabled( hasTime );
352 mTimeEdit->setTime( mJournal->dtStart().time() );
354 mEditor->setText( mJournal->description() );
355 setReadOnly( mJournal->isReadOnly() );
358 void JournalEntry::writeJournalPrivate(
Journal *j )
361 bool hasTime = mTimeCheck->isChecked();
362 TQTime tm( mTimeEdit->getTime() );
363 j->
setDtStart( TQDateTime( mDate, hasTime?tm:TQTime(0,0,0) ) );
368 void JournalEntry::writeJournal()
372 if ( mReadOnly || !mDirty || !mChanger ) {
373 kdDebug(5850)<<
"Journal either read-only, unchanged or no changer object available"<<endl;
376 bool newJournal =
false;
377 mWriteInProgress =
true;
384 writeJournalPrivate( mJournal );
385 if ( !mChanger->addIncidence( mJournal, 0, TQString(),
this ) ) {
386 KODialogManager::errorSaveIncidence(
this, mJournal );
391 oldJournal = mJournal->
clone();
392 if ( mChanger->beginChange( mJournal, 0, TQString() ) ) {
393 writeJournalPrivate( mJournal );
394 mChanger->changeIncidence( oldJournal, mJournal, KOGlobals::DESCRIPTION_MODIFIED,
this );
395 mChanger->endChange( mJournal, 0, TQString() );
400 mWriteInProgress =
false;
403 void JournalEntry::flushEntry()
410 void JournalEntry::timeCheckBoxToggled(
bool on)
412 mTimeEdit->setEnabled(on);
414 mTimeEdit->setFocus();
CalPrinter is a class for printing Calendars.
void setSummary(const TQString &summary)
void setDescription(const TQString &description)
virtual void setDtStart(const TQDateTime &dtStart)