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( QObject *parent,
00049 const char *name )
00050 : QObject( parent, name )
00051 {
00052 }
00053
00054 KOEditorGeneralJournal::~KOEditorGeneralJournal()
00055 {
00056 }
00057
00058 void KOEditorGeneralJournal::initTitle( QWidget *parent, QBoxLayout *topLayout )
00059 {
00060 QHBoxLayout *hbox = new QHBoxLayout( topLayout );
00061
00062 QString whatsThis = i18n("Sets the title of this journal.");
00063 QLabel *summaryLabel = new QLabel( i18n("T&itle:"), parent );
00064 QWhatsThis::add( summaryLabel, whatsThis );
00065 QFont f = summaryLabel->font();
00066 f.setBold( true );
00067 summaryLabel->setFont( f );
00068 hbox->addWidget( summaryLabel );
00069
00070 mSummaryEdit = new FocusLineEdit( parent );
00071 QWhatsThis::add( mSummaryEdit, whatsThis );
00072 summaryLabel->setBuddy( mSummaryEdit );
00073 hbox->addWidget( mSummaryEdit );
00074 }
00075
00076
00077 void KOEditorGeneralJournal::initDate( QWidget *parent, QBoxLayout *topLayout )
00078 {
00079
00080 QBoxLayout *dateLayout = new QHBoxLayout( topLayout );
00081
00082 mDateLabel = new QLabel( i18n("&Date:"), parent);
00083 dateLayout->addWidget( mDateLabel );
00084
00085 mDateEdit = new KDateEdit( parent );
00086 dateLayout->addWidget( mDateEdit );
00087 mDateLabel->setBuddy( mDateEdit );
00088
00089 dateLayout->addStretch();
00090
00091 mTimeCheckBox = new QCheckBox( i18n("&Time: "), parent );
00092 dateLayout->addWidget( mTimeCheckBox );
00093
00094 mTimeEdit = new KTimeEdit( parent );
00095 dateLayout->addWidget( mTimeEdit );
00096 connect( mTimeCheckBox, SIGNAL(toggled(bool)),
00097 mTimeEdit, SLOT(setEnabled(bool)) );
00098
00099 dateLayout->addStretch();
00100 setTime( QTime( -1, -1, -1 ) );
00101 }
00102
00103 void KOEditorGeneralJournal::setDate( const QDate &date )
00104 {
00105
00106
00107 mDateEdit->setDate( date );
00108 }
00109
00110 void KOEditorGeneralJournal::setTime( const QTime &time )
00111 {
00112 kdDebug()<<"KOEditorGeneralJournal::setTime, time="<<time.toString()<<endl;
00113 bool validTime = time.isValid();
00114 mTimeCheckBox->setChecked( validTime );
00115 mTimeEdit->setEnabled( validTime );
00116 if ( validTime ) {
00117 kdDebug()<<"KOEditorGeneralJournal::setTime, time is valid"<<endl;
00118 mTimeEdit->setTime( time );
00119 }
00120 }
00121
00122 void KOEditorGeneralJournal::initDescription( QWidget *parent, QBoxLayout *topLayout )
00123 {
00124 mDescriptionEdit = new KTextEdit( parent );
00125 mDescriptionEdit->append("");
00126 mDescriptionEdit->setReadOnly( false );
00127 mDescriptionEdit->setOverwriteMode( false );
00128 mDescriptionEdit->setWordWrap( KTextEdit::WidgetWidth );
00129 mDescriptionEdit->setTabChangesFocus( true );
00130 topLayout->addWidget( mDescriptionEdit );
00131 }
00132
00133 void KOEditorGeneralJournal::setDefaults( const QDate &date )
00134 {
00135 setDate( date );
00136 }
00137
00138 void KOEditorGeneralJournal::readJournal( Journal *journal, bool tmpl )
00139 {
00140 setSummary( journal->summary() );
00141 if ( !tmpl ) {
00142 setDate( journal->dtStart().date() );
00143 if ( !journal->doesFloat() ) {
00144 kdDebug()<<"KOEditorGeneralJournal::readJournal, does not float, time="<<(journal->dtStart().time().toString())<<endl;
00145 setTime( journal->dtStart().time() );
00146 } else {
00147 kdDebug()<<"KOEditorGeneralJournal::readJournal, does float"<<endl;
00148 setTime( QTime( -1, -1, -1 ) );
00149 }
00150 }
00151 setDescription( journal->description() );
00152 }
00153
00154 void KOEditorGeneralJournal::writeJournal( Journal *journal )
00155 {
00156
00157 journal->setSummary( mSummaryEdit->text() );
00158 journal->setDescription( mDescriptionEdit->text() );
00159
00160 QDateTime tmpDT( mDateEdit->date(), QTime(0,0,0) );
00161 bool hasTime = mTimeCheckBox->isChecked();
00162 journal->setFloats( !hasTime );
00163 if ( hasTime ) {
00164 tmpDT.setTime( mTimeEdit->getTime() );
00165 }
00166 journal->setDtStart(tmpDT);
00167
00168
00169 }
00170
00171
00172 void KOEditorGeneralJournal::setDescription( const QString &text )
00173 {
00174 mDescriptionEdit->setText( text );
00175 }
00176
00177 void KOEditorGeneralJournal::setSummary( const QString &text )
00178 {
00179 mSummaryEdit->setText( text );
00180 }
00181
00182 void KOEditorGeneralJournal::finishSetup()
00183 {
00184 QWidget::setTabOrder( mSummaryEdit, mDateEdit );
00185 QWidget::setTabOrder( mDateEdit, mTimeCheckBox );
00186 QWidget::setTabOrder( mTimeCheckBox, mTimeEdit );
00187 QWidget::setTabOrder( mTimeEdit, mDescriptionEdit );
00188 mSummaryEdit->setFocus();
00189 }
00190
00191 bool KOEditorGeneralJournal::validateInput()
00192 {
00193
00194
00195 if (!mDateEdit->date().isValid()) {
00196 KMessageBox::sorry( 0,
00197 i18n("Please specify a valid date, for example '%1'.")
00198 .arg( KGlobal::locale()->formatDate( QDate::currentDate() ) ) );
00199 return false;
00200 }
00201
00202 return true;
00203 }
00204
00205 #include "koeditorgeneraljournal.moc"
|