korganizer

koeditorgeneraljournal.cpp
1/*
2 This file is part of KOrganizer.
3
4 Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 large parts of code taken from KOEditorGeneralJournal.cpp:
6 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 As a special exception, permission is given to link this program
23 with any edition of TQt, and distribute the resulting executable,
24 without including the source code for TQt in the source distribution.
25*/
26
27#include "koeditorgeneraljournal.h"
28#include "koeditorgeneral.h"
29
30#include <libkcal/journal.h>
31
32#include <ktextedit.h>
33#include <kdateedit.h>
34#include <ktimeedit.h>
35//#include <klineedit.h>
36#include <tdelocale.h>
37#include <tdemessagebox.h>
38#include <kdebug.h>
39
40#include <tqgroupbox.h>
41#include <tqdatetime.h>
42#include <tqcheckbox.h>
43#include <tqlabel.h>
44#include <tqlayout.h>
45#include <tqwhatsthis.h>
46
47
48KOEditorGeneralJournal::KOEditorGeneralJournal( TQWidget *parent,
49 const char *name )
50 : KOEditorGeneral( parent, name )
51{
52 setType( "Journal" );
53}
54
55KOEditorGeneralJournal::~KOEditorGeneralJournal()
56{
57}
58
59void KOEditorGeneralJournal::initTitle( TQWidget *parent, TQBoxLayout *topLayout )
60{
61 TQHBoxLayout *hbox = new TQHBoxLayout( topLayout );
62
63 TQString whatsThis = i18n("Sets the title of this journal.");
64 TQLabel *summaryLabel = new TQLabel( i18n("T&itle:"), parent );
65 TQWhatsThis::add( summaryLabel, whatsThis );
66 TQFont f = summaryLabel->font();
67 f.setBold( true );
68 summaryLabel->setFont( f );
69 hbox->addWidget( summaryLabel );
70
71 mSummaryEdit = new FocusLineEdit( parent );
72 TQWhatsThis::add( mSummaryEdit, whatsThis );
73 summaryLabel->setBuddy( mSummaryEdit );
74 hbox->addWidget( mSummaryEdit );
75}
76
77
78void KOEditorGeneralJournal::initDate( TQWidget *parent, TQBoxLayout *topLayout )
79{
80// TQBoxLayout *dateLayout = new TQVBoxLayout(topLayout);
81 TQBoxLayout *dateLayout = new TQHBoxLayout( topLayout );
82
83 mDateLabel = new TQLabel( i18n("&Date:"), parent);
84 dateLayout->addWidget( mDateLabel );
85
86 mDateEdit = new KDateEdit( parent );
87 dateLayout->addWidget( mDateEdit );
88 mDateLabel->setBuddy( mDateEdit );
89
90 dateLayout->addStretch();
91
92 mTimeCheckBox = new TQCheckBox( i18n("&Time: "), parent );
93 dateLayout->addWidget( mTimeCheckBox );
94
95 mTimeEdit = new KTimeEdit( parent );
96 dateLayout->addWidget( mTimeEdit );
97 connect( mTimeCheckBox, TQ_SIGNAL(toggled(bool)),
98 mTimeEdit, TQ_SLOT(setEnabled(bool)) );
99
100 dateLayout->addStretch();
101 setTime( TQTime( -1, -1, -1 ) );
102}
103
104void KOEditorGeneralJournal::setDate( const TQDate &date )
105{
106// kdDebug(5850) << "KOEditorGeneralJournal::setDate(): Date: " << date.toString() << endl;
107
108 mDateEdit->setDate( date );
109}
110
111void KOEditorGeneralJournal::setTime( const TQTime &time )
112{
113kdDebug()<<"KOEditorGeneralJournal::setTime, time="<<TQString(time.toString())<<endl;
114 bool validTime = time.isValid();
115 mTimeCheckBox->setChecked( validTime );
116 mTimeEdit->setEnabled( validTime );
117 if ( validTime ) {
118kdDebug()<<"KOEditorGeneralJournal::setTime, time is valid"<<endl;
119 mTimeEdit->setTime( time );
120 }
121}
122
123void KOEditorGeneralJournal::initDescription( TQWidget *parent, TQBoxLayout *topLayout )
124{
125 mDescriptionEdit = new KTextEdit( parent );
126 mDescriptionEdit->append("");
127 mDescriptionEdit->setReadOnly( false );
128 mDescriptionEdit->setOverwriteMode( false );
129 mDescriptionEdit->setWordWrap( KTextEdit::WidgetWidth );
130 mDescriptionEdit->setTabChangesFocus( true );
131 topLayout->addWidget( mDescriptionEdit );
132}
133
134void KOEditorGeneralJournal::setDefaults( const TQDate &date )
135{
136 setDate( date );
137}
138
139void KOEditorGeneralJournal::readJournal( Journal *journal, const TQDate &, bool tmpl )
140{
141 setSummary( journal->summary() );
142 if ( !tmpl ) {
143 setDate( journal->dtStart().date() );
144 if ( !journal->doesFloat() ) {
145kdDebug()<<"KOEditorGeneralJournal::readJournal, does not float, time="<<TQString(journal->dtStart().time().toString())<<endl;
146 setTime( journal->dtStart().time() );
147 } else {
148kdDebug()<<"KOEditorGeneralJournal::readJournal, does float"<<endl;
149 setTime( TQTime( -1, -1, -1 ) );
150 }
151 }
152 setDescription( journal->description() );
153}
154
155void KOEditorGeneralJournal::writeJournal( Journal *journal )
156{
157// kdDebug(5850) << "KOEditorGeneralJournal::writeIncidence()" << endl;
158 journal->setSummary( mSummaryEdit->text() );
159 journal->setDescription( mDescriptionEdit->text() );
160
161 TQDateTime tmpDT( mDateEdit->date(), TQTime(0,0,0) );
162 bool hasTime = mTimeCheckBox->isChecked();
163 journal->setFloats( !hasTime );
164 if ( hasTime ) {
165 tmpDT.setTime( mTimeEdit->getTime() );
166 }
167 journal->setDtStart(tmpDT);
168
169// kdDebug(5850) << "KOEditorGeneralJournal::writeJournal() done" << endl;
170}
171
172
173void KOEditorGeneralJournal::setDescription( const TQString &text )
174{
175 mDescriptionEdit->setText( text );
176}
177
178void KOEditorGeneralJournal::setSummary( const TQString &text )
179{
180 mSummaryEdit->setText( text );
181}
182
183void KOEditorGeneralJournal::finishSetup()
184{
185 TQWidget::setTabOrder( mSummaryEdit, mDateEdit );
186 TQWidget::setTabOrder( mDateEdit, mTimeCheckBox );
187 TQWidget::setTabOrder( mTimeCheckBox, mTimeEdit );
188 TQWidget::setTabOrder( mTimeEdit, mDescriptionEdit );
189 mSummaryEdit->setFocus();
190}
191
192bool KOEditorGeneralJournal::validateInput()
193{
194// kdDebug(5850) << "KOEditorGeneralJournal::validateInput()" << endl;
195
196 if (!mDateEdit->date().isValid()) {
197 KMessageBox::sorry( 0,
198 i18n("Please specify a valid date, for example '%1'.")
199 .arg( TDEGlobal::locale()->formatDate( TQDate::currentDate() ) ) );
200 return false;
201 }
202
203 return true;
204}
205
206#include "koeditorgeneraljournal.moc"
bool doesFloat() const
virtual TQDateTime dtStart() const
void setSummary(const TQString &summary)
TQString description() const
void setDescription(const TQString &description)
void setFloats(bool f)
virtual void setDtStart(const TQDateTime &dtStart)
TQString summary() const