korganizer
koeditorgeneraljournal.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00036 #include <klocale.h>
00037 #include <kmessagebox.h>
00038 #include <kdebug.h>
00039
00040 #include <qgroupbox.h>
00041 #include <qdatetime.h>
00042 #include <qcheckbox.h>
00043 #include <qlabel.h>
00044 #include <qlayout.h>
00045 #include <qwhatsthis.h>
00046
00047
00048 KOEditorGeneralJournal::KOEditorGeneralJournal( QWidget *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( QWidget *parent, QBoxLayout *topLayout )
00060 {
00061 QHBoxLayout *hbox = new QHBoxLayout( topLayout );
00062
00063 QString whatsThis = i18n("Sets the title of this journal.");
00064 QLabel *summaryLabel = new QLabel( i18n("T&itle:"), parent );
00065 QWhatsThis::add( summaryLabel, whatsThis );
00066 QFont f = summaryLabel->font();
00067 f.setBold( true );
00068 summaryLabel->setFont( f );
00069 hbox->addWidget( summaryLabel );
00070
00071 mSummaryEdit = new FocusLineEdit( parent );
00072 QWhatsThis::add( mSummaryEdit, whatsThis );
00073 summaryLabel->setBuddy( mSummaryEdit );
00074 hbox->addWidget( mSummaryEdit );
00075 }
00076
00077
00078 void KOEditorGeneralJournal::initDate( QWidget *parent, QBoxLayout *topLayout )
00079 {
00080
00081 QBoxLayout *dateLayout = new QHBoxLayout( topLayout );
00082
00083 mDateLabel = new QLabel( 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 QCheckBox( i18n("&Time: "), parent );
00093 dateLayout->addWidget( mTimeCheckBox );
00094
00095 mTimeEdit = new KTimeEdit( parent );
00096 dateLayout->addWidget( mTimeEdit );
00097 connect( mTimeCheckBox, SIGNAL(toggled(bool)),
00098 mTimeEdit, SLOT(setEnabled(bool)) );
00099
00100 dateLayout->addStretch();
00101 setTime( QTime( -1, -1, -1 ) );
00102 }
00103
00104 void KOEditorGeneralJournal::setDate( const QDate &date )
00105 {
00106
00107
00108 mDateEdit->setDate( date );
00109 }
00110
00111 void KOEditorGeneralJournal::setTime( const QTime &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( QWidget *parent, QBoxLayout *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 QDate &date )
00135 {
00136 setDate( date );
00137 }
00138
00139 void KOEditorGeneralJournal::readJournal( Journal *journal, const QDate &, 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( QTime( -1, -1, -1 ) );
00150 }
00151 }
00152 setDescription( journal->description() );
00153 }
00154
00155 void KOEditorGeneralJournal::writeJournal( Journal *journal )
00156 {
00157
00158 journal->setSummary( mSummaryEdit->text() );
00159 journal->setDescription( mDescriptionEdit->text() );
00160
00161 QDateTime tmpDT( mDateEdit->date(), QTime(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
00170 }
00171
00172
00173 void KOEditorGeneralJournal::setDescription( const QString &text )
00174 {
00175 mDescriptionEdit->setText( text );
00176 }
00177
00178 void KOEditorGeneralJournal::setSummary( const QString &text )
00179 {
00180 mSummaryEdit->setText( text );
00181 }
00182
00183 void KOEditorGeneralJournal::finishSetup()
00184 {
00185 QWidget::setTabOrder( mSummaryEdit, mDateEdit );
00186 QWidget::setTabOrder( mDateEdit, mTimeCheckBox );
00187 QWidget::setTabOrder( mTimeCheckBox, mTimeEdit );
00188 QWidget::setTabOrder( mTimeEdit, mDescriptionEdit );
00189 mSummaryEdit->setFocus();
00190 }
00191
00192 bool KOEditorGeneralJournal::validateInput()
00193 {
00194
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( QDate::currentDate() ) ) );
00200 return false;
00201 }
00202
00203 return true;
00204 }
00205
00206 #include "koeditorgeneraljournal.moc"
|