26 #include <tqpopupmenu.h>
28 #include <tqfontmetrics.h>
29 #include <tqkeycode.h>
32 #include <tqpushbutton.h>
33 #include <tqtooltip.h>
34 #include <tqpainter.h>
36 #include <tqlistbox.h>
41 #include <tdelocale.h>
42 #include <tdeglobal.h>
43 #include <tdeconfig.h>
44 #include <kiconloader.h>
45 #include <kwordwrap.h>
47 #include <kcalendarsystem.h>
48 #include <libkcal/calfilter.h>
50 #include <libkcal/incidenceformatter.h>
54 #include "koglobals.h"
55 #include "koincidencetooltip.h"
56 #include "koeventpopupmenu.h"
59 #include "komonthview.h"
60 #include "komonthview.moc"
64 KOMonthCellToolTip::KOMonthCellToolTip( TQWidget *parent,
69 : TQToolTip( parent ), mCalendar( calendar ), mDate( date ), cell(cl)
74 void KOMonthCellToolTip::maybeTip(
const TQPoint &pos )
77 TQListBoxItem *it = eventlist->itemAt( pos );
78 MonthViewItem *i =
static_cast<MonthViewItem*
>( it );
80 if( i && KOPrefs::instance()->mEnableToolTips ) {
82 r=eventlist->itemRect( it );
84 TQString tipText( IncidenceFormatter::toolTipStr( mCalendar, i->incidence(), mDate ) );
85 if(tipText.isEmpty()) tipText = cell->holidayString();
86 if ( !tipText.isEmpty() ) {
92 KNoScrollListBox::KNoScrollListBox( TQWidget *parent,
const char *name )
93 : TQListBox( parent, name ),
96 TQPalette pal = palette();
97 pal.setColor( TQColorGroup::Foreground, KOPrefs::instance()->agendaBgColor().dark( 150 ) );
98 pal.setColor( TQColorGroup::Base, KOPrefs::instance()->agendaBgColor() );
102 void KNoScrollListBox::setBackground(
bool primary,
bool workDay )
106 color = KOPrefs::instance()->workingHoursColor();
108 color = KOPrefs::instance()->agendaBgColor();
111 TQPalette pal = palette();
113 pal.setColor( TQColorGroup::Base, color );
115 pal.setColor( TQColorGroup::Base, color.dark( 115 ) );
120 void KNoScrollListBox::keyPressEvent( TQKeyEvent *e )
130 if ( !count() )
break;
131 setCurrentItem( ( currentItem() + count() - 1 ) % count() );
132 if ( !itemVisible( currentItem() ) ) {
133 if ( (
unsigned int)currentItem() == ( count() - 1 ) ) {
134 setTopItem( currentItem() - numItemsVisible() + 1 );
136 setTopItem( topItem() - 1 );
141 if ( !count() )
break;
142 setCurrentItem( ( currentItem() + 1 ) % count() );
143 if( !itemVisible( currentItem() ) ) {
144 if( currentItem() == 0 ) {
147 setTopItem( topItem() + 1 );
158 void KNoScrollListBox::keyReleaseEvent( TQKeyEvent *e )
169 void KNoScrollListBox::mousePressEvent( TQMouseEvent *e )
171 TQListBox::mousePressEvent( e );
173 if ( e->button() == Qt::RightButton ) {
178 void KNoScrollListBox::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
180 TQListBox::contentsMouseDoubleClickEvent( e );
181 TQListBoxItem *item = itemAt( e->pos() );
183 emit doubleClicked( item );
187 void KNoScrollListBox::resizeEvent( TQResizeEvent *e )
189 bool s = count() && ( maxItemWidth() > e->size().width() );
190 if ( mSqueezing || s )
191 triggerUpdate(
false );
194 TQListBox::resizeEvent( e );
197 MonthViewItem::MonthViewItem(
Incidence *incidence,
const TQDateTime &qd,
198 const TQString & s ) : TQListBoxItem()
202 mIncidence = incidence;
205 mEventPixmap = KOGlobals::self()->smallIcon(
"appointment" );
206 mBirthdayPixmap = KOGlobals::self()->smallIcon(
"calendarbirthday" );
207 mAnniversaryPixmap= KOGlobals::self()->smallIcon(
"calendaranniversary" );
208 mTodoPixmap = KOGlobals::self()->smallIcon(
"todo" );
209 mTodoDonePixmap = KOGlobals::self()->smallIcon(
"checkedbox" );
210 mAlarmPixmap = KOGlobals::self()->smallIcon(
"bell" );
211 mRecurPixmap = KOGlobals::self()->smallIcon(
"recur" );
212 mReplyPixmap = KOGlobals::self()->smallIcon(
"mail-reply-sender" );
222 TQColor MonthViewItem::catColor()
const
229 TQStringList categories = mIncidence->
categories();
231 if ( !categories.isEmpty() ) {
232 cat = categories.first();
234 if ( cat.isEmpty() ) {
235 retColor = KOPrefs::instance()->unsetCategoryColor();
237 retColor = *( KOPrefs::instance()->categoryColor( cat ) );
242 void MonthViewItem::paint( TQPainter *p )
244 bool sel = isSelected();
246 TQColor bgColor = TQColor();
247 if ( mIncidence && mTodo ) {
248 if (
static_cast<Todo*
>( mIncidence )->isOverdue() ) {
249 bgColor = KOPrefs::instance()->todoOverdueColor();
250 }
else if (
static_cast<Todo*
>( mIncidence )->dtDue().date() == TQDate::currentDate() ) {
251 bgColor = KOPrefs::instance()->todoDueTodayColor();
255 if ( !bgColor.isValid() ) {
256 if ( KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceOnly ||
257 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceInsideCategoryOutside ) {
258 bgColor = resourceColor();
260 bgColor = catColor();
263 if ( !bgColor.isValid() ) {
264 bgColor = palette().color( TQPalette::Normal,
265 sel ? TQColorGroup::Highlight :
266 TQColorGroup::Background );
271 if ( KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceOnly ||
272 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryInsideResourceOutside ) {
273 frameColor = resourceColor();
275 frameColor = catColor();
279 if ( mIncidence->categories().isEmpty() &&
280 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceInsideCategoryOutside ) {
281 frameColor = bgColor;
284 if ( mIncidence->categories().isEmpty() &&
285 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryInsideResourceOutside ) {
286 bgColor = frameColor;
290 if ( !frameColor.isValid() ) {
291 frameColor = palette().color( TQPalette::Normal,
292 sel ? TQColorGroup::Highlight :
293 TQColorGroup::Foreground );
295 frameColor = frameColor.dark( 115 );
299 p->setBackgroundColor( frameColor );
300 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
302 p->setBackgroundColor( bgColor );
303 p->eraseRect( offset, offset, listBox()->maxItemWidth()-2*offset, height( listBox() )-2*offset );
307 bool specialEvent =
false;
309 if ( mIncidence->customProperty(
"KABC",
"BIRTHDAY" ) ==
"YES" ) {
311 if ( mIncidence->customProperty(
"KABC",
"ANNIVERSARY" ) ==
"YES" ) {
312 p->drawPixmap( x, 0, mAnniversaryPixmap );
313 x += mAnniversaryPixmap.width() + 2;
315 p->drawPixmap( x, 0, mBirthdayPixmap );
316 x += mBirthdayPixmap.width() + 2;
327 p->drawPixmap( x, 0, mTodoPixmap );
328 x += mTodoPixmap.width() + 2;
331 p->drawPixmap( x, 0, mTodoDonePixmap );
332 x += mTodoPixmap.width() + 2;
334 if ( mRecur && !specialEvent ) {
335 p->drawPixmap( x, 0, mRecurPixmap );
336 x += mRecurPixmap.width() + 2;
338 if ( mAlarm && !specialEvent ) {
339 p->drawPixmap( x, 0, mAlarmPixmap );
340 x += mAlarmPixmap.width() + 2;
343 p->drawPixmap(x, 0, mReplyPixmap );
344 x += mReplyPixmap.width() + 2;
346 TQFontMetrics fm = p->fontMetrics();
348 int pmheight = TQMAX( mRecurPixmap.height(),
349 TQMAX( mAlarmPixmap.height(), mReplyPixmap.height() ) );
350 if( pmheight < fm.height() )
351 yPos = fm.ascent() + fm.leading()/2;
353 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
354 TQColor textColor = getTextColor( bgColor );
355 p->setPen( textColor );
357 KWordWrap::drawFadeoutText( p, x, yPos, listBox()->width() - x, text() );
360 int MonthViewItem::height(
const TQListBox *lb )
const
362 return TQMAX( TQMAX( mRecurPixmap.height(), mReplyPixmap.height() ),
363 TQMAX( mAlarmPixmap.height(), lb->fontMetrics().lineSpacing()+1) );
366 int MonthViewItem::width(
const TQListBox *lb )
const
370 x += mRecurPixmap.width()+2;
373 x += mAlarmPixmap.width()+2;
376 x += mReplyPixmap.width()+2;
379 return( x + lb->fontMetrics().boundingRect( text() ).width() + 1 );
384 : TQWidget( parent ),
385 mMonthView( parent ), mPrimary( false ), mHoliday( false ),
388 TQVBoxLayout *topLayout =
new TQVBoxLayout(
this );
390 mLabel =
new TQLabel(
this );
391 mLabel->setFrameStyle( TQFrame::Panel | TQFrame::Plain );
392 mLabel->setLineWidth( 1 );
393 mLabel->setAlignment( AlignCenter );
395 mItemList =
new KNoScrollListBox(
this );
396 mItemList->setMinimumSize( 10, 10 );
397 mItemList->setFrameStyle( TQFrame::Panel | TQFrame::Plain );
398 mItemList->setLineWidth( 1 );
400 topLayout->addWidget( mItemList );
404 mStandardPalette = palette();
406 enableScrollBars(
false );
410 connect( mItemList, TQT_SIGNAL( doubleClicked( TQListBoxItem *) ),
411 TQT_SLOT( defaultAction( TQListBoxItem * ) ) );
412 connect( mItemList, TQT_SIGNAL( rightButtonPressed( TQListBoxItem *,
414 TQT_SLOT( contextMenu( TQListBoxItem * ) ) );
415 connect( mItemList, TQT_SIGNAL( clicked( TQListBoxItem * ) ),
416 TQT_SLOT( select() ) );
428 if ( KOGlobals::self()->calendarSystem()->day(
date ) == 1 ) {
429 text = i18n(
"'Month day' for month view cells",
"%1 %2")
430 .arg( KOGlobals::self()->calendarSystem()->monthName(
date,
true ) )
431 .arg( KOGlobals::self()->calendarSystem()->day(mDate) );
432 TQFontMetrics fm( mLabel->font() );
433 mLabel->resize( mLabelSize + TQSize( fm.width( text ), 0 ) );
435 mLabel->resize( mLabelSize );
436 text = TQString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
438 mLabel->setText( text );
440 new KOMonthCellToolTip( mItemList->viewport(),
443 static_cast<KNoScrollListBox *
>( mItemList ),
this );
453 void MonthViewCell::setFrameWidth()
456 if ( mDate == TQDate::currentDate() ) {
457 mItemList->setLineWidth( 3 );
458 }
else if ( !isSelected ) {
459 mItemList->setLineWidth( 1 );
468 mLabel->setBackgroundMode( PaletteBase );
470 mLabel->setBackgroundMode( PaletteBackground );
473 mItemList->setBackground( mPrimary, KOGlobals::self()->isWorkDay( mDate ) );
486 setPalette( mHolidayPalette );
488 setPalette( mStandardPalette );
494 mHolidayString = holiday;
497 void MonthViewCell::updateCell()
501 if ( mDate == TQDate::currentDate() ) {
502 setPalette( mTodayPalette );
504 TQPalette pal = mItemList->palette();
505 pal.setColor( TQColorGroup::Foreground, KOPrefs::instance()->highlightColor() );
506 mItemList->setPalette( pal );
510 setPalette( mHolidayPalette );
512 setPalette( mStandardPalette );
514 TQPalette pal = mItemList->palette();
515 pal.setColor( TQColorGroup::Foreground, KOPrefs::instance()->agendaBgColor().dark( 150 ) );
516 mItemList->setPalette( pal );
521 if ( !mHolidayString.isEmpty() ) {
522 MonthViewItem *item =
new MonthViewItem( 0, TQDateTime( mDate ), mHolidayString );
523 item->setPalette( mHolidayPalette );
524 mItemList->insertItem( item );
528 class MonthViewCell::CreateItemVisitor :
532 CreateItemVisitor() : mItem(0) { emails = KOPrefs::instance()->allEmails(); }
534 bool act(
IncidenceBase *incidence, TQDate
date, TQPalette stdPal,
int multiDay )
538 mStandardPalette = stdPal;
539 mMultiDay = multiDay;
540 return incidence->
accept( *
this );
542 MonthViewItem *item()
const {
return mItem; }
548 TQDateTime dt( mDate );
550 TQDate dtEnd =
event->dtEnd().addSecs( event->
doesFloat() ? 0 : -1).date();
551 int length =
event->dtStart().daysTo( TQDateTime(dtEnd) );
553 if ( mDate == event->
dtStart().date()
554 || ( mMultiDay == 0 && event->
recursOn( mDate ) ) ) {
555 text =
"(-- " +
event->summary();
556 dt =
event->dtStart();
557 }
else if ( !event->
doesRecur() && mDate == dtEnd
559 || ( mMultiDay == length && event->
recursOn( mDate.addDays( -length ) ) ) ) {
560 text =
event->summary() +
" --)";
561 }
else if (!(event->
dtStart().date().daysTo(mDate) % 7) && length > 7 ) {
562 text =
"-- " +
event->summary() +
" --";
564 text =
"----------------";
565 dt = TQDateTime( mDate );
569 text =
event->summary();
571 text = TDEGlobal::locale()->formatTime(event->
dtStart().time());
572 dt.setTime( event->
dtStart().time() );
573 text +=
' ' +
event->summary();
577 mItem =
new MonthViewItem( event, dt, text );
578 mItem->setEvent(
true );
579 if ( KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryOnly ||
580 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryInsideResourceOutside ) {
581 TQStringList categories =
event->categories();
582 TQString cat = categories.first();
584 mItem->setPalette(TQPalette(KOPrefs::instance()->unsetCategoryColor(),
585 KOPrefs::instance()->unsetCategoryColor()) );
587 mItem->setPalette(TQPalette(*(KOPrefs::instance()->categoryColor(cat)),
588 *(KOPrefs::instance()->categoryColor(cat))));
591 mItem->setPalette( mStandardPalette );
594 Attendee *me =
event->attendeeByMails( emails );
596 mItem->setReply( me->
status() == Attendee::NeedsAction && me->
RSVP() );
598 mItem->setReply(
false);
603 if ( !KOPrefs::instance()->showAllDayTodo() )
605 TQDateTime dt( mDate );
607 todo->
dtDue().time() != TQTime( 0,0 ) && todo->
dtDue().time().isValid() ) {
608 text += TDEGlobal::locale()->formatTime( todo->
dtDue().time() );
610 dt.setTime( todo->
dtDue().time() );
614 mItem =
new MonthViewItem( todo, dt, text );
616 mDate < todo->
dtDue().date() ?
617 mItem->setTodoDone(
true ) : mItem->setTodo(
true );
620 todo->
isCompleted() ? mItem->setTodoDone(
true ) : mItem->setTodo(
true );
621 mItem->setPalette( mStandardPalette );
625 MonthViewItem *mItem;
627 TQPalette mStandardPalette;
634 if ( v.act( incidence, mDate, mStandardPalette, multiDay ) ) {
635 MonthViewItem *item = v.item();
638 item->setRecur( incidence->recurrenceType() );
640 TQColor resourceColor = KOHelper::resourceColor(
monthView()->calendar(), incidence );
641 if ( !resourceColor.isValid() )
642 resourceColor = KOPrefs::instance()->unsetCategoryColor();
643 item->setResourceColor( resourceColor );
650 TQDateTime dt( item->incidenceDateTime() );
652 while ( i < mItemList->count() && pos<0 ) {
653 TQListBoxItem *item = mItemList->item( i );
654 MonthViewItem *mvitem =
dynamic_cast<MonthViewItem*
>( item );
655 if ( mvitem && mvitem->incidenceDateTime()>dt ) {
660 mItemList->insertItem( item, pos );
667 for ( uint i = 0; i < mItemList->count(); ++i ) {
668 MonthViewItem *item =
static_cast<MonthViewItem *
>(mItemList->item( i ) );
669 if ( item && item->incidence() &&
670 item->incidence()->uid() == incidence->
uid() ) {
671 mItemList->removeItem( i );
677 void MonthViewCell::updateConfig()
679 setFont( KOPrefs::instance()->mMonthViewFont );
681 TQFontMetrics fm( font() );
682 mLabelSize = fm.size( 0,
"30" ) +
683 TQSize( mLabel->frameWidth() * 2, mLabel->frameWidth() * 2 ) +
686 TQColor bg = mStandardPalette.color( TQPalette::Active, TQColorGroup::Background );
688 bg.getHsv( &h, &s, &v );
689 if (
date().month() %2 == 0 ) {
691 bg = bg.light( 125 );
696 setPaletteBackgroundColor( bg );
699 mHolidayPalette = mStandardPalette;
700 mHolidayPalette.setColor( TQColorGroup::Foreground,
701 KOPrefs::instance()->holidayColor() );
702 mHolidayPalette.setColor( TQColorGroup::Text,
703 KOPrefs::instance()->holidayColor() );
704 mTodayPalette = mStandardPalette;
705 mTodayPalette.setColor( TQColorGroup::Foreground,
706 KOPrefs::instance()->highlightColor() );
707 mTodayPalette.setColor( TQColorGroup::Text,
708 KOPrefs::instance()->highlightColor() );
711 mItemList->setBackground( mPrimary, KOGlobals::self()->isWorkDay( mDate ) );
714 void MonthViewCell::enableScrollBars(
bool enabled )
717 mItemList->setVScrollBarMode( TQScrollView::Auto );
718 mItemList->setHScrollBarMode( TQScrollView::Auto );
720 mItemList->setVScrollBarMode( TQScrollView::AlwaysOff );
721 mItemList->setHScrollBarMode( TQScrollView::AlwaysOff );
725 Incidence *MonthViewCell::selectedIncidence()
727 int index = mItemList->currentItem();
728 if ( index < 0 )
return 0;
730 MonthViewItem *item =
731 static_cast<MonthViewItem *
>( mItemList->item( index ) );
733 if ( !item )
return 0;
735 return item->incidence();
738 TQDate MonthViewCell::selectedIncidenceDate()
741 int index = mItemList->currentItem();
742 if ( index < 0 )
return qd;
744 MonthViewItem *item =
745 static_cast<MonthViewItem *
>( mItemList->item( index ) );
747 if ( !item )
return qd;
749 return item->incidenceDateTime().date();
752 void MonthViewCell::select()
758 mMonthView->setSelectedCell(
this );
760 if( KOPrefs::instance()->enableMonthScroll() )
761 enableScrollBars(
true );
764 if( mDate != TQDate::currentDate() ) {
765 mItemList->setFrameStyle( TQFrame::Sunken | TQFrame::Panel );
766 mItemList->setLineWidth( 3 );
770 void MonthViewCell::deselect()
774 mItemList->clearSelection();
775 mItemList->setFrameStyle( TQFrame::Plain | TQFrame::Panel );
778 enableScrollBars(
false );
781 void MonthViewCell::resizeEvent ( TQResizeEvent * )
783 mLabel->move( width() - mLabel->width(), height() - mLabel->height() );
786 void MonthViewCell::defaultAction( TQListBoxItem *item )
793 MonthViewItem *eventItem =
static_cast<MonthViewItem *
>( item );
794 Incidence *incidence = eventItem->incidence();
799 void MonthViewCell::contextMenu( TQListBoxItem *item )
804 MonthViewItem *eventItem =
static_cast<MonthViewItem *
>( item );
805 Incidence *incidence = eventItem->incidence();
810 mMonthView->showGeneralContextMenu();
815 KOMonthView::KOMonthView(
Calendar *calendar, TQWidget *parent,
const char *name )
817 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
818 mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
820 mCells.setAutoDelete(
true );
822 TQGridLayout *dayLayout =
new TQGridLayout(
this );
824 TQFont bfont = font();
825 bfont.setBold(
true );
827 TQFont mfont = bfont;
828 mfont.setPointSize( 20 );
831 mLabel =
new TQLabel(
this );
832 mLabel->setFont( mfont );
833 mLabel->setAlignment( AlignCenter );
834 mLabel->setLineWidth( 0 );
835 mLabel->setFrameStyle( TQFrame::Plain );
837 dayLayout->addMultiCellWidget( mLabel, 0, 0, 0, mDaysPerWeek );
841 mDayLabels.resize( mDaysPerWeek );
843 for( i = 0; i < mDaysPerWeek; i++ ) {
844 TQLabel *label =
new TQLabel(
this );
845 label->setFont( bfont );
846 label->setFrameStyle( TQFrame::Panel | TQFrame::Raised );
847 label->setLineWidth( 1 );
848 label->setAlignment( AlignCenter );
850 mDayLabels.insert( i, label );
852 dayLayout->addWidget( label, 1, i );
853 dayLayout->addColSpacing( i, 10 );
854 dayLayout->setColStretch( i, 1 );
859 mCells.resize( mNumCells );
860 for( row = 0; row < mNumWeeks; ++row ) {
861 for( col = 0; col < mDaysPerWeek; ++col ) {
863 mCells.insert( row * mDaysPerWeek + col, cell );
864 dayLayout->addWidget( cell, row + 2, col );
866 connect( cell, TQT_SIGNAL(defaultAction(
Incidence *)),
871 dayLayout->setRowStretch( row + 2, 1 );
874 mEventContextMenu = eventPopup();
878 emit incidenceSelected( 0, TQDate() );
881 KOMonthView::~KOMonthView()
883 delete mEventContextMenu;
898 Incidence::List selected;
900 if ( mSelectedCell ) {
901 Incidence *incidence = mSelectedCell->selectedIncidence();
902 if ( incidence ) selected.append( incidence );
912 if ( mSelectedCell ) {
913 TQDate qd = mSelectedCell->selectedIncidenceDate();
914 if ( qd.isValid() ) selected.append( qd );
922 if ( mSelectedCell ) {
923 startDt.setDate( mSelectedCell->
date() );
924 endDt.setDate( mSelectedCell->
date() );
931 void KOMonthView::updateConfig()
933 mWeekStartDay = TDEGlobal::locale()->weekStartDay();
935 TQFontMetrics fontmetric( mDayLabels[0]->font() );
936 mWidthLongDayLabel = 0;
938 for (
int i = 0; i < 7; ++i ) {
940 fontmetric.width( KOGlobals::self()->calendarSystem()->weekDayName( i + 1 ) );
941 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
946 for ( uint i = 0; i < mCells.count(); ++i ) {
947 mCells[i]->updateConfig();
950 showLabel( !KOPrefs::instance()->fullViewMonth() );
953 void KOMonthView::updateDayLabels()
955 kdDebug(5850) <<
"KOMonthView::updateDayLabels()" << endl;
957 const KCalendarSystem*calsys=KOGlobals::self()->calendarSystem();
959 for (
int i = 0; i < 7; i++ ) {
960 currDay = i+mWeekStartDay;
961 if ( currDay > 7 ) currDay -= 7;
962 mDayLabels[i]->setText( calsys->weekDayName( currDay, mShortDayLabels ) );
966 void KOMonthView::showDates(
const TQDate &start,
const TQDate & )
970 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
975 mStartDate = start.addDays( -start.day() + 1 );
977 int weekdayCol=( mStartDate.dayOfWeek() + 7 - mWeekStartDay ) % 7;
978 mStartDate = mStartDate.addDays( -weekdayCol );
980 mLabel->setText( i18n(
"monthname year",
"%1 %2" )
981 .arg( calSys->monthName( start ) )
982 .arg( calSys->year( start ) ) );
984 showLabel( !KOPrefs::instance()->fullViewMonth() );
986 bool primary =
false;
988 for( i = 0; i < mCells.size(); ++i ) {
989 TQDate date = mStartDate.addDays( i );
990 if ( calSys->day( date ) == 1 ) {
994 mCells[i]->setDate( date );
995 mDateToCell[ date ] = mCells[ i ];
996 if( date == start ) {
1000 mCells[i]->setPrimary( primary );
1002 bool isHoliday = calSys->dayOfWeek( date ) == calSys->weekDayOfPray()
1003 || !KOGlobals::self()->isWorkDay( date );
1004 mCells[i]->setHoliday( isHoliday );
1007 TQStringList holidays( KOGlobals::self()->holiday( date ) );
1008 mCells[i]->setHolidayString( holidays.join( i18n(
"delimiter for joining holiday names",
", " ) ) );
1016 if ( mSelectedCell) {
1017 return TQDateTime( mSelectedCell->
date() );
1019 return TQDateTime();
1029 void KOMonthView::showIncidences(
const Incidence::List &,
const TQDate & )
1031 kdDebug(5850) <<
"KOMonthView::showIncidences( const Incidence::List & ) is not implemented yet." << endl;
1041 return incidence->
accept( *
this );
1043 TQDateTime startDate()
const {
return mStartDate; }
1044 TQDateTime endDate()
const {
return mEndDate; }
1048 mStartDate =
event->dtStart();
1049 mEndDate =
event->dtEnd();
1054 if ( todo->
dtDue().time() != TQTime( 0, 0 ) &&
1055 todo->
dtDue().time().isValid() ) {
1056 mStartDate = todo->
dtDue();
1057 mEndDate = todo->
dtDue();
1059 mStartDate = TQDateTime( todo->
dtDue().date(), TQTime( 23,59 ) );
1060 mEndDate = mStartDate;
1067 mStartDate = journal->
dtStart();
1068 mEndDate = journal->
dtStart();
1072 TQDateTime mStartDate;
1073 TQDateTime mEndDate;
1076 void KOMonthView::changeIncidenceDisplayAdded(
Incidence *incidence, MonthViewCell::CreateItemVisitor& v)
1080 if ( !gdv.act( incidence ) ) {
1081 kdDebug(5850) <<
"Visiting GetDateVisitor failed." << endl;
1088 for ( uint i = 0; i < mCells.count(); ++i ) {
1092 int length = gdv.startDate().daysTo( TQDateTime(gdv.endDate().addSecs( floats ? 0 : -1 ).date()) );
1093 for (
int j = 0; j <= length && i+j < mCells.count(); ++j ) {
1094 mCells[i+j]->addIncidence( incidence, v, j );
1100 if ( gdv.endDate().isValid() ) {
1101 TQDate endDate = gdv.endDate().addSecs( floats ? 0 : -1).date();
1102 for ( TQDate date = gdv.startDate().date();
1103 date <= endDate; date = date.addDays( 1 ) ) {
1111 void KOMonthView::changeIncidenceDisplay(
Incidence *incidence,
int action )
1113 MonthViewCell::CreateItemVisitor v;
1115 case KOGlobals::INCIDENCEADDED:
1116 changeIncidenceDisplayAdded( incidence, v );
1118 case KOGlobals::INCIDENCEEDITED:
1119 for( uint i = 0; i < mCells.count(); i++ )
1120 mCells[i]->removeIncidence( incidence );
1121 changeIncidenceDisplayAdded( incidence, v );
1123 case KOGlobals::INCIDENCEDELETED:
1124 for( uint i = 0; i < mCells.count(); i++ )
1125 mCells[i]->removeIncidence( incidence );
1132 void KOMonthView::updateView()
1134 for( uint i = 0; i < mCells.count(); ++i ) {
1135 mCells[i]->updateCell();
1139 Incidence::List::ConstIterator it;
1141 MonthViewCell::CreateItemVisitor v;
1142 for ( it = incidences.begin(); it != incidences.end(); ++it )
1143 changeIncidenceDisplayAdded( *it, v );
1145 processSelectionChange();
1148 void KOMonthView::resizeEvent( TQResizeEvent * )
1154 if( mDayLabels[0]->width() < mWidthLongDayLabel ) {
1155 if ( !mShortDayLabels ) {
1156 mShortDayLabels =
true;
1160 if ( mShortDayLabels ) {
1161 mShortDayLabels =
false;
1167 void KOMonthView::showEventContextMenu(
Calendar *cal,
Incidence *incidence,
const TQDate &qd )
1169 mEventContextMenu->showIncidencePopup( cal, incidence, qd );
1172 void KOMonthView::showGeneralContextMenu()
1174 showNewEventPopup();
1179 if ( mSelectedCell && cell != mSelectedCell )
1180 mSelectedCell->deselect();
1182 mSelectedCell = cell;
1184 if ( !mSelectedCell )
1185 emit incidenceSelected( 0, TQDate() );
1188 emit incidenceSelected( mSelectedCell->selectedIncidence(), TQDate() );
1194 void KOMonthView::processSelectionChange()
1197 if (incidences.count() > 0) {
1199 emit incidenceSelected( incidences.first(), TQDate() );
1204 emit incidenceSelected( 0, TQDate() );
1208 void KOMonthView::clearSelection()
1210 if ( mSelectedCell ) {
1211 mSelectedCell->deselect();
1216 void 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.
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.
KOMonthView * monthView()
void setDate(const TQDate &)
Sets the date of the cell.