26#include <tqpopupmenu.h>
28#include <tqfontmetrics.h>
32#include <tqpushbutton.h>
44#include <kiconloader.h>
47#include <kcalendarsystem.h>
48#include <libkcal/calfilter.h>
50#include <libkcal/incidenceformatter.h>
55#include "koincidencetooltip.h"
56#include "koeventpopupmenu.h"
59#include "komonthview.h"
60#include "komonthview.moc"
64KOMonthCellToolTip::KOMonthCellToolTip( TQWidget *parent,
67 KNoScrollListBox *lv )
68 : TQToolTip( parent ), mCalendar( calendar ), mDate( date )
73void KOMonthCellToolTip::maybeTip(
const TQPoint &pos )
76 TQListBoxItem *it = eventlist->itemAt( pos );
77 MonthViewItem *i =
static_cast<MonthViewItem*
>( it );
79 if( i && KOPrefs::instance()->mEnableToolTips ) {
81 r=eventlist->itemRect( it );
83 TQString tipText( IncidenceFormatter::toolTipStr( mCalendar, i->incidence(), mDate ) );
84 if ( tipText.isEmpty() && !i->incidence() ) {
85 const TQStringList holidays = KOGlobals::self()->holiday( mDate );
86 tipText =
"<qt><b>" + holidays.join(
"<br/>" ) +
"</b><br/>----------<br/>";
87 tipText += i18n(
"<i>Date:</i> %1" )
88 .arg( TDEGlobal::locale()->formatDate( mDate ).replace(
" ",
" " ) );
89 tipText +=
"<br/>" + i18n(
"<i>Day of year:</i> %1" )
90 .arg( KOGlobals::self()->calendarSystem()->dayOfYear( mDate ) );
93 if ( !tipText.isEmpty() ) {
99KNoScrollListBox::KNoScrollListBox( TQWidget *parent,
const char *name )
100 : TQListBox( parent, name ),
103 TQPalette pal = palette();
104 pal.setColor( TQColorGroup::Foreground, KOPrefs::instance()->agendaBgColor().dark( 150 ) );
105 pal.setColor( TQColorGroup::Base, KOPrefs::instance()->agendaBgColor() );
109void KNoScrollListBox::setBackground(
bool primary,
bool workDay )
113 color = KOPrefs::instance()->workingHoursColor();
115 color = KOPrefs::instance()->agendaBgColor();
118 TQPalette pal = palette();
120 pal.setColor( TQColorGroup::Base, color );
122 pal.setColor( TQColorGroup::Base, color.dark( 115 ) );
127void KNoScrollListBox::keyPressEvent( TQKeyEvent *e )
137 if ( !count() )
break;
138 setCurrentItem( ( currentItem() + count() - 1 ) % count() );
139 if ( !itemVisible( currentItem() ) ) {
140 if ( (
unsigned int)currentItem() == ( count() - 1 ) ) {
141 setTopItem( currentItem() - numItemsVisible() + 1 );
143 setTopItem( topItem() - 1 );
148 if ( !count() )
break;
149 setCurrentItem( ( currentItem() + 1 ) % count() );
150 if( !itemVisible( currentItem() ) ) {
151 if( currentItem() == 0 ) {
154 setTopItem( topItem() + 1 );
165void KNoScrollListBox::keyReleaseEvent( TQKeyEvent *e )
176void KNoScrollListBox::mousePressEvent( TQMouseEvent *e )
178 TQListBox::mousePressEvent( e );
180 if ( e->button() == TQt::RightButton ) {
185void KNoScrollListBox::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
187 TQListBox::contentsMouseDoubleClickEvent( e );
188 TQListBoxItem *item = itemAt( e->pos() );
190 emit doubleClicked( item );
194void KNoScrollListBox::resizeEvent( TQResizeEvent *e )
196 bool s = count() && ( maxItemWidth() > e->size().width() );
197 if ( mSqueezing || s )
198 triggerUpdate(
false );
201 TQListBox::resizeEvent( e );
204MonthViewItem::MonthViewItem(
Incidence *incidence,
const TQDateTime &qd,
205 const TQString & s ) : TQListBoxItem()
209 mIncidence = incidence;
212 mEventPixmap = KOGlobals::self()->smallIcon(
"appointment" );
213 mBirthdayPixmap = KOGlobals::self()->smallIcon(
"calendarbirthday" );
214 mAnniversaryPixmap= KOGlobals::self()->smallIcon(
"calendaranniversary" );
215 mTodoPixmap = KOGlobals::self()->smallIcon(
"todo" );
216 mTodoDonePixmap = KOGlobals::self()->smallIcon(
"checkedbox" );
217 mAlarmPixmap = KOGlobals::self()->smallIcon(
"bell" );
218 mRecurPixmap = KOGlobals::self()->smallIcon(
"recur" );
219 mReplyPixmap = KOGlobals::self()->smallIcon(
"mail-reply-sender" );
229TQColor MonthViewItem::catColor()
const
236 TQStringList categories = mIncidence->
categories();
238 if ( !categories.isEmpty() ) {
239 cat = categories.first();
241 if ( cat.isEmpty() ) {
242 retColor = KOPrefs::instance()->unsetCategoryColor();
244 retColor = *( KOPrefs::instance()->categoryColor( cat ) );
249void MonthViewItem::paint( TQPainter *p )
251 bool sel = isSelected();
253 TQColor bgColor = TQColor();
254 if ( mIncidence && mTodo ) {
255 if (
static_cast<Todo*
>( mIncidence )->isOverdue() ) {
256 bgColor = KOPrefs::instance()->todoOverdueColor();
257 }
else if (
static_cast<Todo*
>( mIncidence )->dtDue().date() == TQDate::currentDate() ) {
258 bgColor = KOPrefs::instance()->todoDueTodayColor();
262 if ( !bgColor.isValid() ) {
263 if ( KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceOnly ||
264 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceInsideCategoryOutside ) {
265 bgColor = resourceColor();
267 bgColor = catColor();
270 if ( !bgColor.isValid() ) {
271 bgColor = palette().color( TQPalette::Active,
272 sel ? TQColorGroup::Highlight :
273 TQColorGroup::Background );
278 if ( KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceOnly ||
279 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryInsideResourceOutside ) {
280 frameColor = resourceColor();
282 frameColor = catColor();
286 if ( mIncidence->categories().isEmpty() &&
287 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceInsideCategoryOutside ) {
288 frameColor = bgColor;
291 if ( mIncidence->categories().isEmpty() &&
292 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryInsideResourceOutside ) {
293 bgColor = frameColor;
297 if ( !frameColor.isValid() ) {
298 frameColor = palette().color( TQPalette::Active,
299 sel ? TQColorGroup::Highlight :
300 TQColorGroup::Foreground );
302 frameColor = frameColor.dark( 115 );
306 p->setBackgroundColor( frameColor );
307 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
309 p->setBackgroundColor( bgColor );
310 p->eraseRect( offset, offset, listBox()->maxItemWidth()-2*offset, height( listBox() )-2*offset );
314 bool specialEvent =
false;
316 if ( mIncidence->customProperty(
"KABC",
"BIRTHDAY" ) ==
"YES" ) {
318 if ( mIncidence->customProperty(
"KABC",
"ANNIVERSARY" ) ==
"YES" ) {
319 p->drawPixmap( x, 0, mAnniversaryPixmap );
320 x += mAnniversaryPixmap.width() + 2;
322 p->drawPixmap( x, 0, mBirthdayPixmap );
323 x += mBirthdayPixmap.width() + 2;
334 p->drawPixmap( x, 0, mTodoPixmap );
335 x += mTodoPixmap.width() + 2;
338 p->drawPixmap( x, 0, mTodoDonePixmap );
339 x += mTodoPixmap.width() + 2;
341 if ( mRecur && !specialEvent ) {
342 p->drawPixmap( x, 0, mRecurPixmap );
343 x += mRecurPixmap.width() + 2;
345 if ( mAlarm && !specialEvent ) {
346 p->drawPixmap( x, 0, mAlarmPixmap );
347 x += mAlarmPixmap.width() + 2;
350 p->drawPixmap(x, 0, mReplyPixmap );
351 x += mReplyPixmap.width() + 2;
353 TQFontMetrics fm = p->fontMetrics();
355 int pmheight = TQMAX( mRecurPixmap.height(),
356 TQMAX( mAlarmPixmap.height(), mReplyPixmap.height() ) );
357 if( pmheight < fm.height() )
358 yPos = fm.ascent() + fm.leading()/2;
360 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
361 TQColor textColor = getTextColor( bgColor );
362 p->setPen( textColor );
364 KWordWrap::drawFadeoutText( p, x, yPos, listBox()->width() - x, text() );
367int MonthViewItem::height(
const TQListBox *lb )
const
369 return TQMAX( TQMAX( mRecurPixmap.height(), mReplyPixmap.height() ),
370 TQMAX( mAlarmPixmap.height(), lb->fontMetrics().lineSpacing()+1) );
373int MonthViewItem::width(
const TQListBox *lb )
const
377 x += mRecurPixmap.width()+2;
380 x += mAlarmPixmap.width()+2;
383 x += mReplyPixmap.width()+2;
386 return( x + lb->fontMetrics().boundingRect( text() ).width() + 1 );
391 : TQWidget( parent ),
392 mMonthView( parent ), mPrimary( false ), mHoliday( false ),
395 TQVBoxLayout *topLayout =
new TQVBoxLayout(
this );
397 mLabel =
new TQLabel(
this );
398 mLabel->setFrameStyle( TQFrame::Panel | TQFrame::Plain );
399 mLabel->setLineWidth( 1 );
400 mLabel->setAlignment( AlignCenter );
402 mItemList =
new KNoScrollListBox(
this );
403 mItemList->setMinimumSize( 10, 10 );
404 mItemList->setFrameStyle( TQFrame::Panel | TQFrame::Plain );
405 mItemList->setLineWidth( 1 );
407 topLayout->addWidget( mItemList );
411 mStandardPalette = palette();
413 enableScrollBars(
false );
417 connect( mItemList, TQ_SIGNAL( doubleClicked( TQListBoxItem *) ),
418 TQ_SLOT( defaultAction( TQListBoxItem * ) ) );
419 connect( mItemList, TQ_SIGNAL( rightButtonPressed( TQListBoxItem *,
421 TQ_SLOT( contextMenu( TQListBoxItem * ) ) );
422 connect( mItemList, TQ_SIGNAL( clicked( TQListBoxItem * ) ),
423 TQ_SLOT( select() ) );
435 if ( KOGlobals::self()->calendarSystem()->day(
date ) == 1 ) {
436 text = i18n(
"'Month day' for month view cells",
"%1 %2")
437 .arg( KOGlobals::self()->calendarSystem()->monthName(
date,
true ) )
438 .arg( KOGlobals::self()->calendarSystem()->day(mDate) );
439 TQFontMetrics fm( mLabel->font() );
440 mLabel->resize( mLabelSize + TQSize( fm.width( text ), 0 ) );
442 mLabel->resize( mLabelSize );
443 text = TQString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
445 mLabel->setText( text );
447 new KOMonthCellToolTip( mItemList->viewport(),
450 static_cast<KNoScrollListBox *
>( mItemList ) );
460void MonthViewCell::setFrameWidth()
463 if ( mDate == TQDate::currentDate() ) {
464 mItemList->setLineWidth( 3 );
465 }
else if ( !isSelected ) {
466 mItemList->setLineWidth( 1 );
475 mLabel->setBackgroundMode( PaletteBase );
477 mLabel->setBackgroundMode( PaletteBackground );
480 mItemList->setBackground( mPrimary, KOGlobals::self()->isWorkDay( mDate ) );
493 setPalette( mHolidayPalette );
495 setPalette( mStandardPalette );
501 mHolidayString = holiday;
504void MonthViewCell::updateCell()
508 if ( mDate == TQDate::currentDate() ) {
509 setPalette( mTodayPalette );
511 TQPalette pal = mItemList->palette();
512 pal.setColor( TQColorGroup::Foreground, KOPrefs::instance()->highlightColor() );
513 mItemList->setPalette( pal );
517 setPalette( mHolidayPalette );
519 setPalette( mStandardPalette );
521 TQPalette pal = mItemList->palette();
522 pal.setColor( TQColorGroup::Foreground, KOPrefs::instance()->agendaBgColor().dark( 150 ) );
523 mItemList->setPalette( pal );
528 if ( !mHolidayString.isEmpty() ) {
529 MonthViewItem *item =
new MonthViewItem( 0, TQDateTime( mDate ), mHolidayString );
530 item->setPalette( mHolidayPalette );
531 mItemList->insertItem( item );
535class MonthViewCell::CreateItemVisitor :
539 CreateItemVisitor() : mItem(0) { emails = KOPrefs::instance()->allEmails(); }
541 bool act(
IncidenceBase *incidence, TQDate
date, TQPalette stdPal,
int multiDay )
545 mStandardPalette = stdPal;
546 mMultiDay = multiDay;
547 return incidence->
accept( *
this );
549 MonthViewItem *item()
const {
return mItem; }
555 TQDateTime dt( mDate );
557 TQDate dtEnd =
event->dtEnd().addSecs( event->
doesFloat() ? 0 : -1).
date();
558 int length =
event->dtStart().daysTo( TQDateTime(dtEnd) );
560 if ( mDate == event->
dtStart().date()
561 || ( mMultiDay == 0 && event->
recursOn( mDate ) ) ) {
562 text =
"(-- " +
event->summary();
563 dt =
event->dtStart();
564 }
else if ( !event->
doesRecur() && mDate == dtEnd
566 || ( mMultiDay == length && event->
recursOn( mDate.addDays( -length ) ) ) ) {
567 text =
event->summary() +
" --)";
568 }
else if (!(event->
dtStart().date().daysTo(mDate) % 7) && length > 7 ) {
569 text =
"-- " +
event->summary() +
" --";
571 text =
"----------------";
572 dt = TQDateTime( mDate );
576 text =
event->summary();
578 text = TDEGlobal::locale()->formatTime(event->
dtStart().time());
579 dt.setTime( event->
dtStart().time() );
580 text +=
' ' +
event->summary();
584 mItem =
new MonthViewItem( event, dt, text );
585 mItem->setEvent(
true );
586 if ( KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryOnly ||
587 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryInsideResourceOutside ) {
588 TQStringList categories =
event->categories();
589 TQString cat = categories.first();
591 mItem->setPalette(TQPalette(KOPrefs::instance()->unsetCategoryColor(),
592 KOPrefs::instance()->unsetCategoryColor()) );
594 mItem->setPalette(TQPalette(*(KOPrefs::instance()->categoryColor(cat)),
595 *(KOPrefs::instance()->categoryColor(cat))));
598 mItem->setPalette( mStandardPalette );
601 Attendee *me =
event->attendeeByMails( emails );
603 mItem->setReply( me->
status() == Attendee::NeedsAction && me->
RSVP() );
605 mItem->setReply(
false);
610 if ( !KOPrefs::instance()->showAllDayTodo() )
612 TQDateTime dt( mDate );
614 todo->
dtDue().time() != TQTime( 0,0 ) && todo->
dtDue().time().isValid() ) {
615 text += TDEGlobal::locale()->formatTime( todo->
dtDue().time() );
617 dt.setTime( todo->
dtDue().time() );
621 mItem =
new MonthViewItem( todo, dt, text );
623 mDate < todo->
dtDue().date() ?
624 mItem->setTodoDone(
true ) : mItem->setTodo(
true );
627 todo->
isCompleted() ? mItem->setTodoDone(
true ) : mItem->setTodo(
true );
628 mItem->setPalette( mStandardPalette );
632 MonthViewItem *mItem;
634 TQPalette mStandardPalette;
641 if ( v.act( incidence, mDate, mStandardPalette, multiDay ) ) {
642 MonthViewItem *item = v.item();
645 item->setRecur( incidence->recurrenceType() );
647 TQColor resourceColor = KOHelper::resourceColor(
monthView()->calendar(), incidence );
648 if ( !resourceColor.isValid() )
649 resourceColor = KOPrefs::instance()->unsetCategoryColor();
650 item->setResourceColor( resourceColor );
657 TQDateTime dt( item->incidenceDateTime() );
659 while ( i < mItemList->count() && pos<0 ) {
660 TQListBoxItem *item = mItemList->item( i );
661 MonthViewItem *mvitem =
dynamic_cast<MonthViewItem*
>( item );
662 if ( mvitem && mvitem->incidenceDateTime()>dt ) {
667 mItemList->insertItem( item, pos );
674 for ( uint i = 0; i < mItemList->count(); ++i ) {
675 MonthViewItem *item =
static_cast<MonthViewItem *
>(mItemList->item( i ) );
676 if ( item && item->incidence() &&
677 item->incidence()->uid() == incidence->
uid() ) {
678 mItemList->removeItem( i );
684void MonthViewCell::updateConfig()
686 setFont( KOPrefs::instance()->mMonthViewFont );
688 TQFontMetrics fm( font() );
689 mLabelSize = fm.size( 0,
"30" ) +
690 TQSize( mLabel->frameWidth() * 2, mLabel->frameWidth() * 2 ) +
693 TQColor bg = mStandardPalette.color( TQPalette::Active, TQColorGroup::Background );
695 bg.getHsv( &h, &s, &v );
696 if (
date().month() %2 == 0 ) {
698 bg = bg.light( 125 );
703 setPaletteBackgroundColor( bg );
706 mHolidayPalette = mStandardPalette;
707 mHolidayPalette.setColor( TQColorGroup::Foreground,
708 KOPrefs::instance()->holidayColor() );
709 mHolidayPalette.setColor( TQColorGroup::Text,
710 KOPrefs::instance()->holidayColor() );
711 mTodayPalette = mStandardPalette;
712 mTodayPalette.setColor( TQColorGroup::Foreground,
713 KOPrefs::instance()->highlightColor() );
714 mTodayPalette.setColor( TQColorGroup::Text,
715 KOPrefs::instance()->highlightColor() );
718 mItemList->setBackground( mPrimary, KOGlobals::self()->isWorkDay( mDate ) );
721void MonthViewCell::enableScrollBars(
bool enabled )
724 mItemList->setVScrollBarMode( TQScrollView::Auto );
725 mItemList->setHScrollBarMode( TQScrollView::Auto );
727 mItemList->setVScrollBarMode( TQScrollView::AlwaysOff );
728 mItemList->setHScrollBarMode( TQScrollView::AlwaysOff );
732Incidence *MonthViewCell::selectedIncidence()
734 int index = mItemList->currentItem();
735 if ( index < 0 )
return 0;
737 MonthViewItem *item =
738 static_cast<MonthViewItem *
>( mItemList->item( index ) );
740 if ( !item )
return 0;
742 return item->incidence();
745TQDate MonthViewCell::selectedIncidenceDate()
748 int index = mItemList->currentItem();
749 if ( index < 0 )
return qd;
751 MonthViewItem *item =
752 static_cast<MonthViewItem *
>( mItemList->item( index ) );
754 if ( !item )
return qd;
756 return item->incidenceDateTime().date();
759void MonthViewCell::select()
765 mMonthView->setSelectedCell(
this );
767 if( KOPrefs::instance()->enableMonthScroll() )
768 enableScrollBars(
true );
771 if( mDate != TQDate::currentDate() ) {
772 mItemList->setFrameStyle( TQFrame::Sunken | TQFrame::Panel );
773 mItemList->setLineWidth( 3 );
777void MonthViewCell::deselect()
781 mItemList->clearSelection();
782 mItemList->setFrameStyle( TQFrame::Plain | TQFrame::Panel );
785 enableScrollBars(
false );
788void MonthViewCell::resizeEvent ( TQResizeEvent * )
790 mLabel->move( width() - mLabel->width(), height() - mLabel->height() );
793void MonthViewCell::defaultAction( TQListBoxItem *item )
800 MonthViewItem *eventItem =
static_cast<MonthViewItem *
>( item );
801 Incidence *incidence = eventItem->incidence();
806void MonthViewCell::contextMenu( TQListBoxItem *item )
811 MonthViewItem *eventItem =
static_cast<MonthViewItem *
>( item );
812 Incidence *incidence = eventItem->incidence();
817 mMonthView->showGeneralContextMenu();
822KOMonthView::KOMonthView(
Calendar *calendar, TQWidget *parent,
const char *name )
824 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
825 mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
827 mCells.setAutoDelete(
true );
829 TQGridLayout *dayLayout =
new TQGridLayout(
this );
831 TQFont bfont = font();
832 bfont.setBold(
true );
834 TQFont mfont = bfont;
835 mfont.setPointSize( 20 );
838 mLabel =
new TQLabel(
this );
839 mLabel->setFont( mfont );
840 mLabel->setAlignment( AlignCenter );
841 mLabel->setLineWidth( 0 );
842 mLabel->setFrameStyle( TQFrame::Plain );
844 dayLayout->addMultiCellWidget( mLabel, 0, 0, 0, mDaysPerWeek );
848 mDayLabels.resize( mDaysPerWeek );
850 for( i = 0; i < mDaysPerWeek; i++ ) {
851 TQLabel *label =
new TQLabel(
this );
852 label->setFont( bfont );
853 label->setFrameStyle( TQFrame::Panel | TQFrame::Raised );
854 label->setLineWidth( 1 );
855 label->setAlignment( AlignCenter );
857 mDayLabels.insert( i, label );
859 dayLayout->addWidget( label, 1, i );
860 dayLayout->addColSpacing( i, 10 );
861 dayLayout->setColStretch( i, 1 );
866 mCells.resize( mNumCells );
867 for( row = 0; row < mNumWeeks; ++row ) {
868 for( col = 0; col < mDaysPerWeek; ++col ) {
870 mCells.insert( row * mDaysPerWeek + col, cell );
871 dayLayout->addWidget( cell, row + 2, col );
873 connect( cell, TQ_SIGNAL(defaultAction(
Incidence *)),
878 dayLayout->setRowStretch( row + 2, 1 );
881 mEventContextMenu = eventPopup();
885 emit incidenceSelected( 0, TQDate() );
888KOMonthView::~KOMonthView()
890 delete mEventContextMenu;
905 Incidence::List selected;
907 if ( mSelectedCell ) {
908 Incidence *incidence = mSelectedCell->selectedIncidence();
909 if ( incidence ) selected.append( incidence );
919 if ( mSelectedCell ) {
920 TQDate qd = mSelectedCell->selectedIncidenceDate();
921 if ( qd.isValid() ) selected.append( qd );
929 if ( mSelectedCell ) {
930 startDt.setDate( mSelectedCell->
date() );
931 endDt.setDate( mSelectedCell->
date() );
938void KOMonthView::updateConfig()
940 mWeekStartDay = TDEGlobal::locale()->weekStartDay();
942 TQFontMetrics fontmetric( mDayLabels[0]->font() );
943 mWidthLongDayLabel = 0;
945 for (
int i = 0; i < 7; ++i ) {
947 fontmetric.width( KOGlobals::self()->calendarSystem()->weekDayName( i + 1 ) );
948 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
953 for ( uint i = 0; i < mCells.count(); ++i ) {
954 mCells[i]->updateConfig();
957 showLabel( !KOPrefs::instance()->fullViewMonth() );
960void KOMonthView::updateDayLabels()
962 kdDebug(5850) <<
"KOMonthView::updateDayLabels()" << endl;
964 const KCalendarSystem*calsys=KOGlobals::self()->calendarSystem();
966 for (
int i = 0; i < 7; i++ ) {
967 currDay = i+mWeekStartDay;
968 if ( currDay > 7 ) currDay -= 7;
969 mDayLabels[i]->setText( calsys->weekDayName( currDay, mShortDayLabels ) );
973void KOMonthView::showDates(
const TQDate &start,
const TQDate & )
977 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
982 mStartDate = start.addDays( -start.day() + 1 );
984 int weekdayCol=( mStartDate.dayOfWeek() + 7 - mWeekStartDay ) % 7;
985 mStartDate = mStartDate.addDays( -weekdayCol );
987 mLabel->setText( i18n(
"monthname year",
"%1 %2" )
988 .arg( calSys->monthName( start ) )
989 .arg( calSys->year( start ) ) );
991 showLabel( !KOPrefs::instance()->fullViewMonth() );
993 bool primary =
false;
995 for( i = 0; i < mCells.size(); ++i ) {
996 TQDate date = mStartDate.addDays( i );
997 if ( calSys->day( date ) == 1 ) {
1001 mCells[i]->setDate( date );
1002 mDateToCell[ date ] = mCells[ i ];
1003 if( date == start ) {
1004 mCells[i]->select();
1007 mCells[i]->setPrimary( primary );
1009 bool isHoliday = calSys->dayOfWeek( date ) == calSys->weekDayOfPray()
1010 || !KOGlobals::self()->isWorkDay( date );
1011 mCells[i]->setHoliday( isHoliday );
1014 TQStringList holidays( KOGlobals::self()->holiday( date ) );
1015 mCells[i]->setHolidayString( holidays.join( i18n(
"delimiter for joining holiday names",
", " ) ) );
1023 if ( mSelectedCell) {
1024 return TQDateTime( mSelectedCell->
date() );
1026 return TQDateTime();
1036void KOMonthView::showIncidences(
const Incidence::List &,
const TQDate & )
1038 kdDebug(5850) <<
"KOMonthView::showIncidences( const Incidence::List & ) is not implemented yet." << endl;
1048 return incidence->
accept( *
this );
1050 TQDateTime startDate()
const {
return mStartDate; }
1051 TQDateTime endDate()
const {
return mEndDate; }
1055 mStartDate =
event->dtStart();
1056 mEndDate =
event->dtEnd();
1061 if ( todo->
dtDue().time() != TQTime( 0, 0 ) &&
1062 todo->
dtDue().time().isValid() ) {
1063 mStartDate = todo->
dtDue();
1064 mEndDate = todo->
dtDue();
1066 mStartDate = TQDateTime( todo->
dtDue().date(), TQTime( 23,59 ) );
1067 mEndDate = mStartDate;
1074 mStartDate = journal->
dtStart();
1075 mEndDate = journal->
dtStart();
1079 TQDateTime mStartDate;
1080 TQDateTime mEndDate;
1083void KOMonthView::changeIncidenceDisplayAdded(
Incidence *incidence, MonthViewCell::CreateItemVisitor& v)
1087 if ( !gdv.act( incidence ) ) {
1088 kdDebug(5850) <<
"Visiting GetDateVisitor failed." << endl;
1095 for ( uint i = 0; i < mCells.count(); ++i ) {
1099 int length = gdv.startDate().daysTo( TQDateTime(gdv.endDate().addSecs( floats ? 0 : -1 ).date()) );
1100 for (
int j = 0; j <= length && i+j < mCells.count(); ++j ) {
1101 mCells[i+j]->addIncidence( incidence, v, j );
1107 if ( gdv.endDate().isValid() ) {
1108 TQDate endDate = gdv.endDate().addSecs( floats ? 0 : -1).date();
1109 for ( TQDate date = gdv.startDate().date();
1110 date <= endDate; date = date.addDays( 1 ) ) {
1118void KOMonthView::changeIncidenceDisplay(
Incidence *incidence,
int action )
1120 MonthViewCell::CreateItemVisitor v;
1122 case KOGlobals::INCIDENCEADDED:
1123 changeIncidenceDisplayAdded( incidence, v );
1125 case KOGlobals::INCIDENCEEDITED:
1126 for( uint i = 0; i < mCells.count(); i++ )
1127 mCells[i]->removeIncidence( incidence );
1128 changeIncidenceDisplayAdded( incidence, v );
1130 case KOGlobals::INCIDENCEDELETED:
1131 for( uint i = 0; i < mCells.count(); i++ )
1132 mCells[i]->removeIncidence( incidence );
1139void KOMonthView::updateView()
1141 for( uint i = 0; i < mCells.count(); ++i ) {
1142 mCells[i]->updateCell();
1146 Incidence::List::ConstIterator it;
1148 MonthViewCell::CreateItemVisitor v;
1149 for ( it = incidences.begin(); it != incidences.end(); ++it )
1150 changeIncidenceDisplayAdded( *it, v );
1152 processSelectionChange();
1155void KOMonthView::resizeEvent( TQResizeEvent * )
1161 if( mDayLabels[0]->width() < mWidthLongDayLabel ) {
1162 if ( !mShortDayLabels ) {
1163 mShortDayLabels =
true;
1167 if ( mShortDayLabels ) {
1168 mShortDayLabels =
false;
1174void KOMonthView::showEventContextMenu(
Calendar *cal,
Incidence *incidence,
const TQDate &qd )
1176 mEventContextMenu->showIncidencePopup( cal, incidence, qd );
1179void KOMonthView::showGeneralContextMenu()
1181 showNewEventPopup();
1186 if ( mSelectedCell && cell != mSelectedCell )
1187 mSelectedCell->deselect();
1189 mSelectedCell = cell;
1191 if ( !mSelectedCell )
1192 emit incidenceSelected( 0, TQDate() );
1195 emit incidenceSelected( mSelectedCell->selectedIncidence(), TQDate() );
1201void KOMonthView::processSelectionChange()
1204 if (incidences.count() > 0) {
1206 emit incidenceSelected( incidences.first(), TQDate() );
1211 emit incidenceSelected( 0, TQDate() );
1215void KOMonthView::clearSelection()
1217 if ( mSelectedCell ) {
1218 mSelectedCell->deselect();
1223void KOMonthView::showLabel(
bool show )
virtual Incidence::List incidences()
virtual bool visit(Event *)
virtual TQDateTime dtStart() const
virtual bool accept(Visitor &)
TQStringList categories() const
bool isAlarmEnabled() const
virtual bool recursOn(const TQDate &qd) 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.
The class KOMonthView represents the monthly view in KOrganizer.
virtual bool eventDurationHint(TQDateTime &startDt, TQDateTime &endDt, bool &allDay)
Set the default start/end date/time for new events.
virtual DateList selectedIncidenceDates()
Returns dates of the currently selected events.
virtual TQDateTime selectionEnd()
Returns the end of the selection, or an invalid TQDateTime if there is no selection or the view doesn...
virtual int currentDateCount()
Returns number of currently shown dates.
virtual Incidence::List selectedIncidences()
Returns the currently selected events.
virtual int maxDatesHint()
Returns maximum number of days supported by the komonthview.
virtual TQDateTime selectionStart()
Returns the start of the selection, or an invalid TQDateTime if there is no selection or the view doe...
virtual Calendar * calendar()
Return calendar object of this view.
This class represents one day in KOrganizer's month view.
void setPrimary(bool primary)
Set this cell as primary if primary is true.
void removeIncidence(Incidence *)
Removes an incidence from the cell.
void setHolidayString(const TQString &name)
Sets the holiday name to this cell.
KOMonthView * monthView()
void addIncidence(Incidence *incidence, MonthViewCell::CreateItemVisitor &v, int multiDay=0)
Adds an incidence to the cell.
void setHoliday(bool)
Make this cell show as a holiday.
void newEventSignal(ResourceCalendar *res, const TQString &subResource, const TQDate &date)
Notify the view manager that we want to create a new event, so an editor will pop up.
void setDate(const TQDate &)
Sets the date of the cell.