korganizer

koeditorgeneraljournal.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005         large parts of code taken from KOEditorGeneralJournal.cpp:
00006     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021 
00022     As a special exception, permission is given to link this program
00023     with any edition of Qt, and distribute the resulting executable,
00024     without including the source code for Qt in the source distribution.
00025 */
00026 
00027 #include "koeditorgeneraljournal.h"
00028 #include "koeditorgeneral.h"
00029 
00030 #include <libkcal/journal.h>
00031 
00032 #include <ktextedit.h>
00033 #include <kdateedit.h>
00034 #include <ktimeedit.h>
00035 //#include <klineedit.h>
00036 #include <klocale.h>
00037 #include <kmessagebox.h>
00038 #include <kdebug.h>
00039 
00040 #include <tqgroupbox.h>
00041 #include <tqdatetime.h>
00042 #include <tqcheckbox.h>
00043 #include <tqlabel.h>
00044 #include <tqlayout.h>
00045 #include <tqwhatsthis.h>
00046 
00047 
00048 KOEditorGeneralJournal::KOEditorGeneralJournal( TQWidget *parent,
00049                                                 const char *name )
00050   : KOEditorGeneral( parent, name )
00051 {
00052   setType( "Journal" );
00053 }
00054 
00055 KOEditorGeneralJournal::~KOEditorGeneralJournal()
00056 {
00057 }
00058 
00059 void KOEditorGeneralJournal::initTitle( TQWidget *parent, TQBoxLayout *topLayout )
00060 {
00061   TQHBoxLayout *hbox = new TQHBoxLayout( topLayout );
00062 
00063   TQString whatsThis = i18n("Sets the title of this journal.");
00064   TQLabel *summaryLabel = new TQLabel( i18n("T&itle:"), parent );
00065   TQWhatsThis::add( summaryLabel, whatsThis );
00066   TQFont f = summaryLabel->font();
00067   f.setBold( true );
00068   summaryLabel->setFont( f );
00069   hbox->addWidget( summaryLabel );
00070 
00071   mSummaryEdit = new FocusLineEdit( parent );
00072   TQWhatsThis::add( mSummaryEdit, whatsThis );
00073   summaryLabel->setBuddy( mSummaryEdit );
00074   hbox->addWidget( mSummaryEdit );
00075 }
00076 
00077 
00078 void KOEditorGeneralJournal::initDate( TQWidget *parent, TQBoxLayout *topLayout )
00079 {
00080 //  TQBoxLayout *dateLayout = new TQVBoxLayout(topLayout);
00081   TQBoxLayout *dateLayout = new TQHBoxLayout( topLayout );
00082 
00083   mDateLabel = new TQLabel( i18n("&Date:"), parent);
00084   dateLayout->addWidget( mDateLabel );
00085 
00086   mDateEdit = new KDateEdit( parent );
00087   dateLayout->addWidget( mDateEdit );
00088   mDateLabel->setBuddy( mDateEdit );
00089 
00090   dateLayout->addStretch();
00091 
00092   mTimeCheckBox = new TQCheckBox( i18n("&Time: "), parent );
00093   dateLayout->addWidget( mTimeCheckBox );
00094 
00095   mTimeEdit = new KTimeEdit( parent );
00096   dateLayout->addWidget( mTimeEdit );
00097   connect( mTimeCheckBox, TQT_SIGNAL(toggled(bool)),
00098            mTimeEdit, TQT_SLOT(setEnabled(bool)) );
00099 
00100   dateLayout->addStretch();
00101   setTime( TQTime( -1, -1, -1 ) );
00102 }
00103 
00104 void KOEditorGeneralJournal::setDate( const TQDate &date )
00105 {
00106 //  kdDebug(5850) << "KOEditorGeneralJournal::setDate(): Date: " << date.toString() << endl;
00107 
00108   mDateEdit->setDate( date );
00109 }
00110 
00111 void KOEditorGeneralJournal::setTime( const TQTime &time )
00112 {
00113 kdDebug()<<"KOEditorGeneralJournal::setTime, time="<<time.toString()<<endl;
00114   bool validTime = time.isValid();
00115   mTimeCheckBox->setChecked( validTime );
00116   mTimeEdit->setEnabled( validTime );
00117   if ( validTime ) {
00118 kdDebug()<<"KOEditorGeneralJournal::setTime, time is valid"<<endl;
00119     mTimeEdit->setTime( time );
00120   }
00121 }
00122 
00123 void KOEditorGeneralJournal::initDescription( TQWidget *parent, TQBoxLayout *topLayout )
00124 {
00125   mDescriptionEdit = new KTextEdit( parent );
00126   mDescriptionEdit->append("");
00127   mDescriptionEdit->setReadOnly( false );
00128   mDescriptionEdit->setOverwriteMode( false );
00129   mDescriptionEdit->setWordWrap( KTextEdit::WidgetWidth );
00130   mDescriptionEdit->setTabChangesFocus( true );
00131   topLayout->addWidget( mDescriptionEdit );
00132 }
00133 
00134 void KOEditorGeneralJournal::setDefaults( const TQDate &date )
00135 {
00136   setDate( date );
00137 }
00138 
00139 void KOEditorGeneralJournal::readJournal( Journal *journal, const TQDate &, bool tmpl )
00140 {
00141   setSummary( journal->summary() );
00142   if ( !tmpl ) {
00143     setDate( journal->dtStart().date() );
00144     if ( !journal->doesFloat() ) {
00145 kdDebug()<<"KOEditorGeneralJournal::readJournal, does not float, time="<<(journal->dtStart().time().toString())<<endl;
00146       setTime( journal->dtStart().time() );
00147     } else {
00148 kdDebug()<<"KOEditorGeneralJournal::readJournal, does float"<<endl;
00149       setTime( TQTime( -1, -1, -1 ) );
00150     }
00151   }
00152   setDescription( journal->description() );
00153 }
00154 
00155 void KOEditorGeneralJournal::writeJournal( Journal *journal )
00156 {
00157 //  kdDebug(5850) << "KOEditorGeneralJournal::writeIncidence()" << endl;
00158   journal->setSummary( mSummaryEdit->text() );
00159   journal->setDescription( mDescriptionEdit->text() );
00160 
00161   TQDateTime tmpDT( mDateEdit->date(), TQTime(0,0,0) );
00162   bool hasTime = mTimeCheckBox->isChecked();
00163   journal->setFloats( !hasTime );
00164   if ( hasTime ) {
00165     tmpDT.setTime( mTimeEdit->getTime() );
00166   }
00167   journal->setDtStart(tmpDT);
00168 
00169 //  kdDebug(5850) << "KOEditorGeneralJournal::writeJournal() done" << endl;
00170 }
00171 
00172 
00173 void KOEditorGeneralJournal::setDescription( const TQString &text )
00174 {
00175   mDescriptionEdit->setText( text );
00176 }
00177 
00178 void KOEditorGeneralJournal::setSummary( const TQString &text )
00179 {
00180   mSummaryEdit->setText( text );
00181 }
00182 
00183 void KOEditorGeneralJournal::finishSetup()
00184 {
00185   TQWidget::setTabOrder( mSummaryEdit, mDateEdit );
00186   TQWidget::setTabOrder( mDateEdit, mTimeCheckBox );
00187   TQWidget::setTabOrder( mTimeCheckBox, mTimeEdit );
00188   TQWidget::setTabOrder( mTimeEdit, mDescriptionEdit );
00189   mSummaryEdit->setFocus();
00190 }
00191 
00192 bool KOEditorGeneralJournal::validateInput()
00193 {
00194 //  kdDebug(5850) << "KOEditorGeneralJournal::validateInput()" << endl;
00195 
00196   if (!mDateEdit->date().isValid()) {
00197     KMessageBox::sorry( 0,
00198         i18n("Please specify a valid date, for example '%1'.")
00199         .arg( KGlobal::locale()->formatDate( TQDate::currentDate() ) ) );
00200     return false;
00201   }
00202 
00203   return true;
00204 }
00205 
00206 #include "koeditorgeneraljournal.moc"