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,
67 KNoScrollListBox *lv )
68 : TQToolTip( parent ), mCalendar( calendar ), mDate( date )
73 void 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() ) {
90 KNoScrollListBox::KNoScrollListBox( TQWidget *parent,
const char *name )
91 : TQListBox( parent, name ),
94 TQPalette pal = palette();
95 pal.setColor( TQColorGroup::Foreground, KOPrefs::instance()->agendaBgColor().dark( 150 ) );
96 pal.setColor( TQColorGroup::Base, KOPrefs::instance()->agendaBgColor() );
100 void KNoScrollListBox::setBackground(
bool primary,
bool workDay )
104 color = KOPrefs::instance()->workingHoursColor();
106 color = KOPrefs::instance()->agendaBgColor();
109 TQPalette pal = palette();
111 pal.setColor( TQColorGroup::Base, color );
113 pal.setColor( TQColorGroup::Base, color.dark( 115 ) );
118 void KNoScrollListBox::keyPressEvent( TQKeyEvent *e )
128 if ( !count() )
break;
129 setCurrentItem( ( currentItem() + count() - 1 ) % count() );
130 if ( !itemVisible( currentItem() ) ) {
131 if ( (
unsigned int)currentItem() == ( count() - 1 ) ) {
132 setTopItem( currentItem() - numItemsVisible() + 1 );
134 setTopItem( topItem() - 1 );
139 if ( !count() )
break;
140 setCurrentItem( ( currentItem() + 1 ) % count() );
141 if( !itemVisible( currentItem() ) ) {
142 if( currentItem() == 0 ) {
145 setTopItem( topItem() + 1 );
156 void KNoScrollListBox::keyReleaseEvent( TQKeyEvent *e )
167 void KNoScrollListBox::mousePressEvent( TQMouseEvent *e )
169 TQListBox::mousePressEvent( e );
171 if ( e->button() == TQt::RightButton ) {
176 void KNoScrollListBox::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
178 TQListBox::contentsMouseDoubleClickEvent( e );
179 TQListBoxItem *item = itemAt( e->pos() );
181 emit doubleClicked( item );
185 void KNoScrollListBox::resizeEvent( TQResizeEvent *e )
187 bool s = count() && ( maxItemWidth() > e->size().width() );
188 if ( mSqueezing || s )
189 triggerUpdate(
false );
192 TQListBox::resizeEvent( e );
195 MonthViewItem::MonthViewItem(
Incidence *incidence,
const TQDateTime &qd,
196 const TQString & s ) : TQListBoxItem()
200 mIncidence = incidence;
203 mEventPixmap = KOGlobals::self()->smallIcon(
"appointment" );
204 mBirthdayPixmap = KOGlobals::self()->smallIcon(
"calendarbirthday" );
205 mAnniversaryPixmap= KOGlobals::self()->smallIcon(
"calendaranniversary" );
206 mTodoPixmap = KOGlobals::self()->smallIcon(
"todo" );
207 mTodoDonePixmap = KOGlobals::self()->smallIcon(
"checkedbox" );
208 mAlarmPixmap = KOGlobals::self()->smallIcon(
"bell" );
209 mRecurPixmap = KOGlobals::self()->smallIcon(
"recur" );
210 mReplyPixmap = KOGlobals::self()->smallIcon(
"mail-reply-sender" );
220 TQColor MonthViewItem::catColor()
const
227 TQStringList categories = mIncidence->
categories();
229 if ( !categories.isEmpty() ) {
230 cat = categories.first();
232 if ( cat.isEmpty() ) {
233 retColor = KOPrefs::instance()->unsetCategoryColor();
235 retColor = *( KOPrefs::instance()->categoryColor( cat ) );
240 void MonthViewItem::paint( TQPainter *p )
242 bool sel = isSelected();
244 TQColor bgColor = TQColor();
245 if ( mIncidence && mTodo ) {
246 if (
static_cast<Todo*
>( mIncidence )->isOverdue() ) {
247 bgColor = KOPrefs::instance()->todoOverdueColor();
248 }
else if (
static_cast<Todo*
>( mIncidence )->dtDue().date() == TQDate::currentDate() ) {
249 bgColor = KOPrefs::instance()->todoDueTodayColor();
253 if ( !bgColor.isValid() ) {
254 if ( KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceOnly ||
255 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceInsideCategoryOutside ) {
256 bgColor = resourceColor();
258 bgColor = catColor();
261 if ( !bgColor.isValid() ) {
262 bgColor = palette().color( TQPalette::Active,
263 sel ? TQColorGroup::Highlight :
264 TQColorGroup::Background );
269 if ( KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceOnly ||
270 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryInsideResourceOutside ) {
271 frameColor = resourceColor();
273 frameColor = catColor();
277 if ( mIncidence->categories().isEmpty() &&
278 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemResourceInsideCategoryOutside ) {
279 frameColor = bgColor;
282 if ( mIncidence->categories().isEmpty() &&
283 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryInsideResourceOutside ) {
284 bgColor = frameColor;
288 if ( !frameColor.isValid() ) {
289 frameColor = palette().color( TQPalette::Active,
290 sel ? TQColorGroup::Highlight :
291 TQColorGroup::Foreground );
293 frameColor = frameColor.dark( 115 );
297 p->setBackgroundColor( frameColor );
298 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
300 p->setBackgroundColor( bgColor );
301 p->eraseRect( offset, offset, listBox()->maxItemWidth()-2*offset, height( listBox() )-2*offset );
305 bool specialEvent =
false;
307 if ( mIncidence->customProperty(
"KABC",
"BIRTHDAY" ) ==
"YES" ) {
309 if ( mIncidence->customProperty(
"KABC",
"ANNIVERSARY" ) ==
"YES" ) {
310 p->drawPixmap( x, 0, mAnniversaryPixmap );
311 x += mAnniversaryPixmap.width() + 2;
313 p->drawPixmap( x, 0, mBirthdayPixmap );
314 x += mBirthdayPixmap.width() + 2;
325 p->drawPixmap( x, 0, mTodoPixmap );
326 x += mTodoPixmap.width() + 2;
329 p->drawPixmap( x, 0, mTodoDonePixmap );
330 x += mTodoPixmap.width() + 2;
332 if ( mRecur && !specialEvent ) {
333 p->drawPixmap( x, 0, mRecurPixmap );
334 x += mRecurPixmap.width() + 2;
336 if ( mAlarm && !specialEvent ) {
337 p->drawPixmap( x, 0, mAlarmPixmap );
338 x += mAlarmPixmap.width() + 2;
341 p->drawPixmap(x, 0, mReplyPixmap );
342 x += mReplyPixmap.width() + 2;
344 TQFontMetrics fm = p->fontMetrics();
346 int pmheight = TQMAX( mRecurPixmap.height(),
347 TQMAX( mAlarmPixmap.height(), mReplyPixmap.height() ) );
348 if( pmheight < fm.height() )
349 yPos = fm.ascent() + fm.leading()/2;
351 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
352 TQColor textColor = getTextColor( bgColor );
353 p->setPen( textColor );
355 KWordWrap::drawFadeoutText( p, x, yPos, listBox()->width() - x, text() );
358 int MonthViewItem::height(
const TQListBox *lb )
const
360 return TQMAX( TQMAX( mRecurPixmap.height(), mReplyPixmap.height() ),
361 TQMAX( mAlarmPixmap.height(), lb->fontMetrics().lineSpacing()+1) );
364 int MonthViewItem::width(
const TQListBox *lb )
const
368 x += mRecurPixmap.width()+2;
371 x += mAlarmPixmap.width()+2;
374 x += mReplyPixmap.width()+2;
377 return( x + lb->fontMetrics().boundingRect( text() ).width() + 1 );
382 : TQWidget( parent ),
383 mMonthView( parent ), mPrimary( false ), mHoliday( false ),
386 TQVBoxLayout *topLayout =
new TQVBoxLayout(
this );
388 mLabel =
new TQLabel(
this );
389 mLabel->setFrameStyle( TQFrame::Panel | TQFrame::Plain );
390 mLabel->setLineWidth( 1 );
391 mLabel->setAlignment( AlignCenter );
393 mItemList =
new KNoScrollListBox(
this );
394 mItemList->setMinimumSize( 10, 10 );
395 mItemList->setFrameStyle( TQFrame::Panel | TQFrame::Plain );
396 mItemList->setLineWidth( 1 );
398 topLayout->addWidget( mItemList );
402 mStandardPalette = palette();
404 enableScrollBars(
false );
408 connect( mItemList, TQ_SIGNAL( doubleClicked( TQListBoxItem *) ),
409 TQ_SLOT( defaultAction( TQListBoxItem * ) ) );
410 connect( mItemList, TQ_SIGNAL( rightButtonPressed( TQListBoxItem *,
412 TQ_SLOT( contextMenu( TQListBoxItem * ) ) );
413 connect( mItemList, TQ_SIGNAL( clicked( TQListBoxItem * ) ),
414 TQ_SLOT( select() ) );
426 if ( KOGlobals::self()->calendarSystem()->day(
date ) == 1 ) {
427 text = i18n(
"'Month day' for month view cells",
"%1 %2")
428 .arg( KOGlobals::self()->calendarSystem()->monthName(
date,
true ) )
429 .arg( KOGlobals::self()->calendarSystem()->day(mDate) );
430 TQFontMetrics fm( mLabel->font() );
431 mLabel->resize( mLabelSize + TQSize( fm.width( text ), 0 ) );
433 mLabel->resize( mLabelSize );
434 text = TQString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
436 mLabel->setText( text );
438 new KOMonthCellToolTip( mItemList->viewport(),
441 static_cast<KNoScrollListBox *
>( mItemList ) );
451 void MonthViewCell::setFrameWidth()
454 if ( mDate == TQDate::currentDate() ) {
455 mItemList->setLineWidth( 3 );
456 }
else if ( !isSelected ) {
457 mItemList->setLineWidth( 1 );
466 mLabel->setBackgroundMode( PaletteBase );
468 mLabel->setBackgroundMode( PaletteBackground );
471 mItemList->setBackground( mPrimary, KOGlobals::self()->isWorkDay( mDate ) );
484 setPalette( mHolidayPalette );
486 setPalette( mStandardPalette );
492 mHolidayString = holiday;
495 void MonthViewCell::updateCell()
499 if ( mDate == TQDate::currentDate() ) {
500 setPalette( mTodayPalette );
502 TQPalette pal = mItemList->palette();
503 pal.setColor( TQColorGroup::Foreground, KOPrefs::instance()->highlightColor() );
504 mItemList->setPalette( pal );
508 setPalette( mHolidayPalette );
510 setPalette( mStandardPalette );
512 TQPalette pal = mItemList->palette();
513 pal.setColor( TQColorGroup::Foreground, KOPrefs::instance()->agendaBgColor().dark( 150 ) );
514 mItemList->setPalette( pal );
519 if ( !mHolidayString.isEmpty() ) {
520 MonthViewItem *item =
new MonthViewItem( 0, TQDateTime( mDate ), mHolidayString );
521 item->setPalette( mHolidayPalette );
522 mItemList->insertItem( item );
526 class MonthViewCell::CreateItemVisitor :
530 CreateItemVisitor() : mItem(0) { emails = KOPrefs::instance()->allEmails(); }
532 bool act(
IncidenceBase *incidence, TQDate
date, TQPalette stdPal,
int multiDay )
536 mStandardPalette = stdPal;
537 mMultiDay = multiDay;
538 return incidence->
accept( *
this );
540 MonthViewItem *item()
const {
return mItem; }
546 TQDateTime dt( mDate );
548 TQDate dtEnd =
event->dtEnd().addSecs( event->
doesFloat() ? 0 : -1).date();
549 int length =
event->dtStart().daysTo( TQDateTime(dtEnd) );
551 if ( mDate == event->
dtStart().date()
552 || ( mMultiDay == 0 && event->
recursOn( mDate ) ) ) {
553 text =
"(-- " +
event->summary();
554 dt =
event->dtStart();
555 }
else if ( !event->
doesRecur() && mDate == dtEnd
557 || ( mMultiDay == length && event->
recursOn( mDate.addDays( -length ) ) ) ) {
558 text =
event->summary() +
" --)";
559 }
else if (!(event->
dtStart().date().daysTo(mDate) % 7) && length > 7 ) {
560 text =
"-- " +
event->summary() +
" --";
562 text =
"----------------";
563 dt = TQDateTime( mDate );
567 text =
event->summary();
569 text = TDEGlobal::locale()->formatTime(event->
dtStart().time());
570 dt.setTime( event->
dtStart().time() );
571 text +=
' ' +
event->summary();
575 mItem =
new MonthViewItem( event, dt, text );
576 mItem->setEvent(
true );
577 if ( KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryOnly ||
578 KOPrefs::instance()->monthItemColors() == KOPrefs::MonthItemCategoryInsideResourceOutside ) {
579 TQStringList categories =
event->categories();
580 TQString cat = categories.first();
582 mItem->setPalette(TQPalette(KOPrefs::instance()->unsetCategoryColor(),
583 KOPrefs::instance()->unsetCategoryColor()) );
585 mItem->setPalette(TQPalette(*(KOPrefs::instance()->categoryColor(cat)),
586 *(KOPrefs::instance()->categoryColor(cat))));
589 mItem->setPalette( mStandardPalette );
592 Attendee *me =
event->attendeeByMails( emails );
594 mItem->setReply( me->
status() == Attendee::NeedsAction && me->
RSVP() );
596 mItem->setReply(
false);
601 if ( !KOPrefs::instance()->showAllDayTodo() )
603 TQDateTime dt( mDate );
605 todo->
dtDue().time() != TQTime( 0,0 ) && todo->
dtDue().time().isValid() ) {
606 text += TDEGlobal::locale()->formatTime( todo->
dtDue().time() );
608 dt.setTime( todo->
dtDue().time() );
612 mItem =
new MonthViewItem( todo, dt, text );
614 mDate < todo->
dtDue().date() ?
615 mItem->setTodoDone(
true ) : mItem->setTodo(
true );
618 todo->
isCompleted() ? mItem->setTodoDone(
true ) : mItem->setTodo(
true );
619 mItem->setPalette( mStandardPalette );
623 MonthViewItem *mItem;
625 TQPalette mStandardPalette;
632 if ( v.act( incidence, mDate, mStandardPalette, multiDay ) ) {
633 MonthViewItem *item = v.item();
636 item->setRecur( incidence->recurrenceType() );
638 TQColor resourceColor = KOHelper::resourceColor(
monthView()->calendar(), incidence );
639 if ( !resourceColor.isValid() )
640 resourceColor = KOPrefs::instance()->unsetCategoryColor();
641 item->setResourceColor( resourceColor );
648 TQDateTime dt( item->incidenceDateTime() );
650 while ( i < mItemList->count() && pos<0 ) {
651 TQListBoxItem *item = mItemList->item( i );
652 MonthViewItem *mvitem =
dynamic_cast<MonthViewItem*
>( item );
653 if ( mvitem && mvitem->incidenceDateTime()>dt ) {
658 mItemList->insertItem( item, pos );
665 for ( uint i = 0; i < mItemList->count(); ++i ) {
666 MonthViewItem *item =
static_cast<MonthViewItem *
>(mItemList->item( i ) );
667 if ( item && item->incidence() &&
668 item->incidence()->uid() == incidence->
uid() ) {
669 mItemList->removeItem( i );
675 void MonthViewCell::updateConfig()
677 setFont( KOPrefs::instance()->mMonthViewFont );
679 TQFontMetrics fm( font() );
680 mLabelSize = fm.size( 0,
"30" ) +
681 TQSize( mLabel->frameWidth() * 2, mLabel->frameWidth() * 2 ) +
684 TQColor bg = mStandardPalette.color( TQPalette::Active, TQColorGroup::Background );
686 bg.getHsv( &h, &s, &v );
687 if (
date().month() %2 == 0 ) {
689 bg = bg.light( 125 );
694 setPaletteBackgroundColor( bg );
697 mHolidayPalette = mStandardPalette;
698 mHolidayPalette.setColor( TQColorGroup::Foreground,
699 KOPrefs::instance()->holidayColor() );
700 mHolidayPalette.setColor( TQColorGroup::Text,
701 KOPrefs::instance()->holidayColor() );
702 mTodayPalette = mStandardPalette;
703 mTodayPalette.setColor( TQColorGroup::Foreground,
704 KOPrefs::instance()->highlightColor() );
705 mTodayPalette.setColor( TQColorGroup::Text,
706 KOPrefs::instance()->highlightColor() );
709 mItemList->setBackground( mPrimary, KOGlobals::self()->isWorkDay( mDate ) );
712 void MonthViewCell::enableScrollBars(
bool enabled )
715 mItemList->setVScrollBarMode( TQScrollView::Auto );
716 mItemList->setHScrollBarMode( TQScrollView::Auto );
718 mItemList->setVScrollBarMode( TQScrollView::AlwaysOff );
719 mItemList->setHScrollBarMode( TQScrollView::AlwaysOff );
723 Incidence *MonthViewCell::selectedIncidence()
725 int index = mItemList->currentItem();
726 if ( index < 0 )
return 0;
728 MonthViewItem *item =
729 static_cast<MonthViewItem *
>( mItemList->item( index ) );
731 if ( !item )
return 0;
733 return item->incidence();
736 TQDate MonthViewCell::selectedIncidenceDate()
739 int index = mItemList->currentItem();
740 if ( index < 0 )
return qd;
742 MonthViewItem *item =
743 static_cast<MonthViewItem *
>( mItemList->item( index ) );
745 if ( !item )
return qd;
747 return item->incidenceDateTime().date();
750 void MonthViewCell::select()
756 mMonthView->setSelectedCell(
this );
758 if( KOPrefs::instance()->enableMonthScroll() )
759 enableScrollBars(
true );
762 if( mDate != TQDate::currentDate() ) {
763 mItemList->setFrameStyle( TQFrame::Sunken | TQFrame::Panel );
764 mItemList->setLineWidth( 3 );
768 void MonthViewCell::deselect()
772 mItemList->clearSelection();
773 mItemList->setFrameStyle( TQFrame::Plain | TQFrame::Panel );
776 enableScrollBars(
false );
779 void MonthViewCell::resizeEvent ( TQResizeEvent * )
781 mLabel->move( width() - mLabel->width(), height() - mLabel->height() );
784 void MonthViewCell::defaultAction( TQListBoxItem *item )
791 MonthViewItem *eventItem =
static_cast<MonthViewItem *
>( item );
792 Incidence *incidence = eventItem->incidence();
797 void MonthViewCell::contextMenu( TQListBoxItem *item )
802 MonthViewItem *eventItem =
static_cast<MonthViewItem *
>( item );
803 Incidence *incidence = eventItem->incidence();
808 mMonthView->showGeneralContextMenu();
813 KOMonthView::KOMonthView(
Calendar *calendar, TQWidget *parent,
const char *name )
815 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
816 mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
818 mCells.setAutoDelete(
true );
820 TQGridLayout *dayLayout =
new TQGridLayout(
this );
822 TQFont bfont = font();
823 bfont.setBold(
true );
825 TQFont mfont = bfont;
826 mfont.setPointSize( 20 );
829 mLabel =
new TQLabel(
this );
830 mLabel->setFont( mfont );
831 mLabel->setAlignment( AlignCenter );
832 mLabel->setLineWidth( 0 );
833 mLabel->setFrameStyle( TQFrame::Plain );
835 dayLayout->addMultiCellWidget( mLabel, 0, 0, 0, mDaysPerWeek );
839 mDayLabels.resize( mDaysPerWeek );
841 for( i = 0; i < mDaysPerWeek; i++ ) {
842 TQLabel *label =
new TQLabel(
this );
843 label->setFont( bfont );
844 label->setFrameStyle( TQFrame::Panel | TQFrame::Raised );
845 label->setLineWidth( 1 );
846 label->setAlignment( AlignCenter );
848 mDayLabels.insert( i, label );
850 dayLayout->addWidget( label, 1, i );
851 dayLayout->addColSpacing( i, 10 );
852 dayLayout->setColStretch( i, 1 );
857 mCells.resize( mNumCells );
858 for( row = 0; row < mNumWeeks; ++row ) {
859 for( col = 0; col < mDaysPerWeek; ++col ) {
861 mCells.insert( row * mDaysPerWeek + col, cell );
862 dayLayout->addWidget( cell, row + 2, col );
864 connect( cell, TQ_SIGNAL(defaultAction(
Incidence *)),
869 dayLayout->setRowStretch( row + 2, 1 );
872 mEventContextMenu = eventPopup();
876 emit incidenceSelected( 0, TQDate() );
879 KOMonthView::~KOMonthView()
881 delete mEventContextMenu;
896 Incidence::List selected;
898 if ( mSelectedCell ) {
899 Incidence *incidence = mSelectedCell->selectedIncidence();
900 if ( incidence ) selected.append( incidence );
910 if ( mSelectedCell ) {
911 TQDate qd = mSelectedCell->selectedIncidenceDate();
912 if ( qd.isValid() ) selected.append( qd );
920 if ( mSelectedCell ) {
921 startDt.setDate( mSelectedCell->
date() );
922 endDt.setDate( mSelectedCell->
date() );
929 void KOMonthView::updateConfig()
931 mWeekStartDay = TDEGlobal::locale()->weekStartDay();
933 TQFontMetrics fontmetric( mDayLabels[0]->font() );
934 mWidthLongDayLabel = 0;
936 for (
int i = 0; i < 7; ++i ) {
938 fontmetric.width( KOGlobals::self()->calendarSystem()->weekDayName( i + 1 ) );
939 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
944 for ( uint i = 0; i < mCells.count(); ++i ) {
945 mCells[i]->updateConfig();
948 showLabel( !KOPrefs::instance()->fullViewMonth() );
951 void KOMonthView::updateDayLabels()
953 kdDebug(5850) <<
"KOMonthView::updateDayLabels()" << endl;
955 const KCalendarSystem*calsys=KOGlobals::self()->calendarSystem();
957 for (
int i = 0; i < 7; i++ ) {
958 currDay = i+mWeekStartDay;
959 if ( currDay > 7 ) currDay -= 7;
960 mDayLabels[i]->setText( calsys->weekDayName( currDay, mShortDayLabels ) );
964 void KOMonthView::showDates(
const TQDate &start,
const TQDate & )
968 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
973 mStartDate = start.addDays( -start.day() + 1 );
975 int weekdayCol=( mStartDate.dayOfWeek() + 7 - mWeekStartDay ) % 7;
976 mStartDate = mStartDate.addDays( -weekdayCol );
978 mLabel->setText( i18n(
"monthname year",
"%1 %2" )
979 .arg( calSys->monthName( start ) )
980 .arg( calSys->year( start ) ) );
982 showLabel( !KOPrefs::instance()->fullViewMonth() );
984 bool primary =
false;
986 for( i = 0; i < mCells.size(); ++i ) {
987 TQDate date = mStartDate.addDays( i );
988 if ( calSys->day( date ) == 1 ) {
992 mCells[i]->setDate( date );
993 mDateToCell[ date ] = mCells[ i ];
994 if( date == start ) {
998 mCells[i]->setPrimary( primary );
1000 bool isHoliday = calSys->dayOfWeek( date ) == calSys->weekDayOfPray()
1001 || !KOGlobals::self()->isWorkDay( date );
1002 mCells[i]->setHoliday( isHoliday );
1005 TQStringList holidays( KOGlobals::self()->holiday( date ) );
1006 mCells[i]->setHolidayString( holidays.join( i18n(
"delimiter for joining holiday names",
", " ) ) );
1014 if ( mSelectedCell) {
1015 return TQDateTime( mSelectedCell->
date() );
1017 return TQDateTime();
1027 void KOMonthView::showIncidences(
const Incidence::List &,
const TQDate & )
1029 kdDebug(5850) <<
"KOMonthView::showIncidences( const Incidence::List & ) is not implemented yet." << endl;
1039 return incidence->
accept( *
this );
1041 TQDateTime startDate()
const {
return mStartDate; }
1042 TQDateTime endDate()
const {
return mEndDate; }
1046 mStartDate =
event->dtStart();
1047 mEndDate =
event->dtEnd();
1052 if ( todo->
dtDue().time() != TQTime( 0, 0 ) &&
1053 todo->
dtDue().time().isValid() ) {
1054 mStartDate = todo->
dtDue();
1055 mEndDate = todo->
dtDue();
1057 mStartDate = TQDateTime( todo->
dtDue().date(), TQTime( 23,59 ) );
1058 mEndDate = mStartDate;
1065 mStartDate = journal->
dtStart();
1066 mEndDate = journal->
dtStart();
1070 TQDateTime mStartDate;
1071 TQDateTime mEndDate;
1074 void KOMonthView::changeIncidenceDisplayAdded(
Incidence *incidence, MonthViewCell::CreateItemVisitor& v)
1078 if ( !gdv.act( incidence ) ) {
1079 kdDebug(5850) <<
"Visiting GetDateVisitor failed." << endl;
1086 for ( uint i = 0; i < mCells.count(); ++i ) {
1090 int length = gdv.startDate().daysTo( TQDateTime(gdv.endDate().addSecs( floats ? 0 : -1 ).date()) );
1091 for (
int j = 0; j <= length && i+j < mCells.count(); ++j ) {
1092 mCells[i+j]->addIncidence( incidence, v, j );
1098 if ( gdv.endDate().isValid() ) {
1099 TQDate endDate = gdv.endDate().addSecs( floats ? 0 : -1).date();
1100 for ( TQDate date = gdv.startDate().date();
1101 date <= endDate; date = date.addDays( 1 ) ) {
1109 void KOMonthView::changeIncidenceDisplay(
Incidence *incidence,
int action )
1111 MonthViewCell::CreateItemVisitor v;
1113 case KOGlobals::INCIDENCEADDED:
1114 changeIncidenceDisplayAdded( incidence, v );
1116 case KOGlobals::INCIDENCEEDITED:
1117 for( uint i = 0; i < mCells.count(); i++ )
1118 mCells[i]->removeIncidence( incidence );
1119 changeIncidenceDisplayAdded( incidence, v );
1121 case KOGlobals::INCIDENCEDELETED:
1122 for( uint i = 0; i < mCells.count(); i++ )
1123 mCells[i]->removeIncidence( incidence );
1130 void KOMonthView::updateView()
1132 for( uint i = 0; i < mCells.count(); ++i ) {
1133 mCells[i]->updateCell();
1137 Incidence::List::ConstIterator it;
1139 MonthViewCell::CreateItemVisitor v;
1140 for ( it = incidences.begin(); it != incidences.end(); ++it )
1141 changeIncidenceDisplayAdded( *it, v );
1143 processSelectionChange();
1146 void KOMonthView::resizeEvent( TQResizeEvent * )
1152 if( mDayLabels[0]->width() < mWidthLongDayLabel ) {
1153 if ( !mShortDayLabels ) {
1154 mShortDayLabels =
true;
1158 if ( mShortDayLabels ) {
1159 mShortDayLabels =
false;
1165 void KOMonthView::showEventContextMenu(
Calendar *cal,
Incidence *incidence,
const TQDate &qd )
1167 mEventContextMenu->showIncidencePopup( cal, incidence, qd );
1170 void KOMonthView::showGeneralContextMenu()
1172 showNewEventPopup();
1177 if ( mSelectedCell && cell != mSelectedCell )
1178 mSelectedCell->deselect();
1180 mSelectedCell = cell;
1182 if ( !mSelectedCell )
1183 emit incidenceSelected( 0, TQDate() );
1186 emit incidenceSelected( mSelectedCell->selectedIncidence(), TQDate() );
1192 void KOMonthView::processSelectionChange()
1195 if (incidences.count() > 0) {
1197 emit incidenceSelected( incidences.first(), TQDate() );
1202 emit incidenceSelected( 0, TQDate() );
1206 void KOMonthView::clearSelection()
1208 if ( mSelectedCell ) {
1209 mSelectedCell->deselect();
1214 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.