27 #include <tqlistview.h>
29 #include <tqpopupmenu.h>
33 #include <tdelocale.h>
35 #include <kiconloader.h>
36 #include <tdeglobal.h>
39 #include <libkcal/incidenceformatter.h>
41 #include "koglobals.h"
43 #include "koincidencetooltip.h"
44 #include "koeventpopupmenu.h"
46 #include "kolistview.h"
47 #include "kolistview.moc"
59 KOListViewToolTip::KOListViewToolTip( TQWidget* parent,
62 :TQToolTip( parent ), mCalendar( calendar )
67 void KOListViewToolTip::maybeTip(
const TQPoint &pos )
70 TQListViewItem *it = eventlist->itemAt( pos );
71 KOListViewItem *i =
static_cast<KOListViewItem*
>( it );
73 if ( i && KOPrefs::instance()->mEnableToolTips ) {
75 r = eventlist->itemRect( it );
77 TQString tipText( IncidenceFormatter::toolTipStr( mCalendar, i->data() ) );
78 if ( !tipText.isEmpty() ) {
91 ListItemVisitor( KOListViewItem *item ) : mItem( item ) {}
99 KOListViewItem *mItem;
104 mItem->setText( Summary_Column, e->
summary() );
106 static const TQPixmap alarmPxmp = KOGlobals::self()->smallIcon(
"bell" );
107 mItem->setPixmap( Reminder_Column, alarmPxmp );
108 mItem->setSortKey( Reminder_Column,
"1" );
110 mItem->setSortKey( Reminder_Column,
"0" );
114 static const TQPixmap recurPxmp = KOGlobals::self()->smallIcon(
"recur" );
115 mItem->setPixmap( Recurs_Column, recurPxmp );
116 mItem->setSortKey( Recurs_Column,
"1" );
118 mItem->setSortKey( Recurs_Column,
"0" );
124 eventPxmp = KOGlobals::self()->smallIcon(
"calendaranniversary" );
126 eventPxmp = KOGlobals::self()->smallIcon(
"calendarbirthday" );
129 eventPxmp = KOGlobals::self()->smallIcon(
"appointment" );
132 mItem->setPixmap( Summary_Column, eventPxmp );
134 TQString startDateTime;
135 TQString endDateTime;
137 mItem->setText( StartDateTime_Column, IncidenceFormatter::dateTimeToString( e->
dtStart(), e->
doesFloat() ) );
138 mItem->setSortKey( StartDateTime_Column, e->
dtStart().toString( TQt::ISODate ) );
139 mItem->setText( EndDateTime_Column, IncidenceFormatter::dateTimeToString( e->
dtEnd(), e->
doesFloat() ) );
140 mItem->setSortKey( EndDateTime_Column, e->
dtEnd().toString( TQt::ISODate ) );
148 static const TQPixmap todoPxmp = KOGlobals::self()->smallIcon(
"todo" );
149 static const TQPixmap todoDonePxmp = KOGlobals::self()->smallIcon(
"checkedbox" );
150 mItem->setPixmap(Summary_Column, t->
isCompleted() ? todoDonePxmp : todoPxmp );
151 mItem->setText(Summary_Column, t->
summary());
153 static const TQPixmap alarmPxmp = KOGlobals::self()->smallIcon(
"bell" );
154 mItem->setPixmap( Reminder_Column, alarmPxmp );
155 mItem->setSortKey( Reminder_Column,
"1" );
157 mItem->setSortKey( Reminder_Column,
"0" );
161 static const TQPixmap recurPxmp = KOGlobals::self()->smallIcon(
"recur" );
162 mItem->setPixmap( Recurs_Column, recurPxmp );
163 mItem->setSortKey( Recurs_Column,
"1" );
165 mItem->setSortKey( Recurs_Column,
"0" );
169 mItem->setText( StartDateTime_Column, IncidenceFormatter::dateTimeToString( t->
dtStart(), t->
doesFloat() ) );
170 mItem->setSortKey( StartDateTime_Column, t->
dtStart().toString( TQt::ISODate ) );
172 mItem->setText( StartDateTime_Column,
"---" );
176 mItem->setText( EndDateTime_Column, IncidenceFormatter::dateTimeToString( t->
dtDue(), t->
doesFloat() ) );
177 mItem->setSortKey( EndDateTime_Column, t->
dtDue().toString( TQt::ISODate ) );
179 mItem->setText( EndDateTime_Column,
"---" );
188 static const TQPixmap jornalPxmp = KOGlobals::self()->smallIcon(
"journal" );
189 mItem->setPixmap( Summary_Column, jornalPxmp );
191 mItem->setText( Summary_Column, j->
description().section(
"\n", 0, 0 ) );
192 mItem->setText( StartDateTime_Column, IncidenceFormatter::dateTimeToString( j->
dtStart(), j->
doesFloat() ) );
193 mItem->setSortKey( StartDateTime_Column, j->
dtStart().toString( TQt::ISODate ) );
198 KOListView::KOListView(
Calendar *calendar,
201 bool nonInteractive )
205 mIsNonInteractive = nonInteractive;
207 mListView =
new TDEListView(
this );
208 mListView->addColumn( i18n(
"Summary") );
209 mListView->addColumn( i18n(
"Reminder") );
210 mListView->setColumnAlignment( Reminder_Column, AlignHCenter );
212 mListView->addColumn( i18n(
"Recurs") );
213 mListView->setColumnAlignment( Recurs_Column, AlignHCenter );
215 mListView->addColumn( i18n(
"Start Date/Time") );
216 mListView->setColumnAlignment( StartDateTime_Column, AlignHCenter );
218 mListView->addColumn( i18n(
"End Date/Time") );
219 mListView->setColumnAlignment( EndDateTime_Column, AlignHCenter );
221 mListView->addColumn( i18n(
"Categories") );
223 TQBoxLayout *layoutTop =
new TQVBoxLayout(
this );
224 layoutTop->addWidget( mListView );
226 mPopupMenu = eventPopup();
235 connect( mListView, TQ_SIGNAL( doubleClicked( TQListViewItem * ) ),
236 TQ_SLOT( defaultItemAction( TQListViewItem * ) ) );
237 connect( mListView, TQ_SIGNAL( returnPressed( TQListViewItem * ) ),
238 TQ_SLOT( defaultItemAction( TQListViewItem * ) ) );
239 connect( mListView, TQ_SIGNAL( rightButtonClicked ( TQListViewItem *,
242 TQ_SLOT( popupMenu( TQListViewItem *,
const TQPoint &,
int ) ) );
243 connect( mListView, TQ_SIGNAL( selectionChanged() ),
244 TQ_SLOT( processSelectionChange() ) );
247 mListView->restoreLayout( KOGlobals::self()->config(),
"KOListView Layout" );
249 new KOListViewToolTip( mListView->viewport(), calendar, mListView );
251 mSelectedDates.append( TQDate::currentDate() );
254 KOListView::~KOListView()
266 return mSelectedDates.count();
271 Incidence::List eventList;
273 TQListViewItem *item = mListView->selectedItem();
275 eventList.append(
static_cast<KOListViewItem *
>( item )->data() );
283 return mSelectedDates;
286 void KOListView::showDates(
bool show )
290 static int oldColWidth1 = 0;
291 static int oldColWidth3 = 0;
294 oldColWidth1 = mListView->columnWidth( 1 );
295 oldColWidth3 = mListView->columnWidth( 3 );
296 mListView->setColumnWidth( 1, 0 );
297 mListView->setColumnWidth( 3, 0 );
299 mListView->setColumnWidth( 1, oldColWidth1 );
300 mListView->setColumnWidth( 3, oldColWidth3 );
302 mListView->repaint();
305 void KOListView::showDates()
310 void KOListView::hideDates()
315 void KOListView::updateView()
317 kdDebug(5850) <<
"KOListView::updateView() does nothing" << endl;
320 void KOListView::showDates(
const TQDate &start,
const TQDate &end )
325 while( date <= end ) {
326 addIncidences(
calendar()->incidences( date ), date );
327 mSelectedDates.append( date );
328 date = date.addDays( 1 );
331 emit incidenceSelected( 0, TQDate() );
334 void KOListView::showAll()
338 Incidence::List::ConstIterator it;
339 for( it = incidenceList.begin(); it != incidenceList.end(); ++it ) {
341 addIncidence( *it, TQDate() );
345 void KOListView::addIncidences(
const Incidence::List &incidenceList,
const TQDate &date )
347 Incidence::List::ConstIterator it;
348 for( it = incidenceList.begin(); it != incidenceList.end(); ++it ) {
349 addIncidence( *it, date );
353 void KOListView::addIncidence(
Incidence *incidence,
const TQDate &date )
355 if ( mUidDict.find( incidence->
uid() ) ) {
359 mDateList[incidence->
uid()] = date;
360 mUidDict.insert( incidence->
uid(), incidence );
362 KOListViewItem *item =
new KOListViewItem( incidence, mListView );
363 ListItemVisitor v( item );
364 if (incidence->
accept( v ) ) {
371 void KOListView::showIncidences(
const Incidence::List &incidenceList,
const TQDate &date )
375 addIncidences( incidenceList, date );
378 emit incidenceSelected( 0, date );
381 void KOListView::changeIncidenceDisplay(
Incidence *incidence,
int action )
383 KOListViewItem *item;
384 TQDate f = mSelectedDates.first();
385 TQDate l = mSelectedDates.last();
388 if ( incidence->type() ==
"Todo" ) {
389 date =
static_cast<Todo *
>( incidence )->dtDue().date();
391 date = incidence->
dtStart().date();
395 case KOGlobals::INCIDENCEADDED: {
396 if ( date >= f && date <= l )
397 addIncidence( incidence, date );
400 case KOGlobals::INCIDENCEEDITED: {
401 item = getItemForIncidence( incidence );
404 mUidDict.remove( incidence->
uid() );
405 mDateList.remove( incidence->
uid() );
407 if ( date >= f && date <= l ) {
408 addIncidence( incidence, date );
412 case KOGlobals::INCIDENCEDELETED: {
413 item = getItemForIncidence( incidence );
420 kdDebug(5850) <<
"KOListView::changeIncidenceDisplay(): Illegal action " << action << endl;
424 KOListViewItem *KOListView::getItemForIncidence(
Incidence *incidence )
426 KOListViewItem *item =
static_cast<KOListViewItem *
>( mListView->firstChild() );
429 if ( item->data() == incidence ) {
432 item =
static_cast<KOListViewItem *
>( item->nextSibling() );
437 void KOListView::defaultItemAction( TQListViewItem *i )
439 if ( !mIsNonInteractive ) {
440 KOListViewItem *item =
static_cast<KOListViewItem *
>( i );
447 void KOListView::popupMenu( TQListViewItem *item,
const TQPoint &,
int )
449 if ( !mIsNonInteractive ) {
450 mActiveItem =
static_cast<KOListViewItem *
>( item );
452 Incidence *incidence = mActiveItem->data();
455 mPopupMenu->showIncidencePopup(
calendar(), incidence, TQDate() );
462 void KOListView::readSettings( TDEConfig *config )
464 mListView->restoreLayout( config,
"KOListView Layout" );
467 void KOListView::writeSettings( TDEConfig *config )
469 mListView->saveLayout( config,
"KOListView Layout" );
472 void KOListView::processSelectionChange()
474 if ( !mIsNonInteractive ) {
475 kdDebug(5850) <<
"KOListView::processSelectionChange()" << endl;
477 KOListViewItem *item =
478 static_cast<KOListViewItem *
>( mListView->selectedItem() );
481 emit incidenceSelected( 0, TQDate() );
484 emit incidenceSelected( incidence, mDateList[incidence->
uid()] );
489 void KOListView::clearSelection()
491 mListView->selectAll(
false );
494 void KOListView::clear()
496 mSelectedDates.clear();
502 TQSize KOListView::sizeHint()
const
504 const TQSize s = KOEventView::sizeHint();
505 return TQSize( s.width() + style().pixelMetric( TQStyle::PM_ScrollBarExtent ) + 1,
virtual Incidence::List incidences()
TQString customProperty(const TQCString &app, const TQCString &key) const
virtual TQDateTime dtEnd() const
virtual bool visit(FreeBusy *)
virtual bool visit(Event *)
virtual TQDateTime dtStart() const
virtual bool accept(Visitor &)
TQString description() const
bool isAlarmEnabled() const
TQString categoriesStr() const
bool hasStartDate() const
TQDateTime dtStart(bool first=false) const
TQDateTime dtDue(bool first=false) const
KOEventView is the abstract base class from which all other calendar views for event data are derived...
void defaultAction(Incidence *)
Perform the default action for an incidence, e.g.
virtual int currentDateCount()
Return number of currently shown dates.
virtual DateList selectedIncidenceDates()
virtual int maxDatesHint()
provides a hint back to the caller on the maximum number of dates that the view supports.
virtual Incidence::List selectedIncidences()
virtual Calendar * calendar()
Return calendar object of this view.