29 #include <tqintdict.h>
30 #include <tqdatetime.h>
31 #include <tqapplication.h>
32 #include <tqpopupmenu.h>
34 #include <tqpainter.h>
38 #include <tdelocale.h>
39 #include <kiconloader.h>
40 #include <tdeglobal.h>
41 #include <tdemessagebox.h>
43 #include "koagendaitem.h"
45 #include "koglobals.h"
46 #include "komessagebox.h"
47 #include "incidencechanger.h"
51 #include "koagenda.moc"
52 #include <korganizer/baseview.h>
54 #include <libkcal/event.h>
55 #include <libkcal/todo.h>
56 #include <libkcal/dndfactory.h>
57 #include <libkcal/icaldrag.h>
58 #include <libkcal/vcaldrag.h>
65 MarcusBains::MarcusBains(KOAgenda *_agenda,
const char *name )
66 : TQFrame(_agenda->viewport(), name), agenda(_agenda)
70 setBackgroundColor(TQt::red);
71 minutes =
new TQTimer(
this);
72 connect(minutes, TQ_SIGNAL(timeout()),
this, TQ_SLOT(updateLocation()));
73 minutes->start(0,
true);
75 mTimeBox =
new TQLabel(
this);
76 mTimeBox->setAlignment(TQt::AlignRight | TQt::AlignBottom);
77 TQPalette pal = mTimeBox->palette();
78 pal.setColor(TQColorGroup::Foreground, TQt::red);
79 mTimeBox->setPalette(pal);
80 mTimeBox->setAutoMask(
true);
82 agenda->addChild(mTimeBox);
84 mOldTime = TQTime( 0, 0 );
88 MarcusBains::~MarcusBains()
93 int MarcusBains::todayColumn()
95 TQDate currentDate = TQDate::currentDate();
97 DateList dateList = agenda->dateList();
98 DateList::ConstIterator it;
100 for(it = dateList.begin(); it != dateList.end(); ++it) {
101 if((*it) == currentDate)
102 return KOGlobals::self()->reverseLayout() ?
103 agenda->columns() - 1 - col : col;
110 void MarcusBains::updateLocation()
112 updateLocationRecalc();
115 void MarcusBains::updateLocationRecalc(
bool recalculate )
117 TQTime tim = TQTime::currentTime();
118 if((tim.hour() == 0) && (mOldTime.hour()==23))
121 int mins = tim.hour()*60 + tim.minute();
122 int minutesPerCell = 24 * 60 / agenda->rows();
123 int y = int( mins * agenda->gridSpacingY() / minutesPerCell );
124 int today = recalculate ? todayColumn() : mOldToday;
125 int x = int( agenda->gridSpacingX() * today );
130 bool hideIt = !( KOPrefs::instance()->mMarcusBainsEnabled );
132 if ( !isHidden() && ( hideIt || ( today < 0 ) ) ) {
138 if ( isHidden() && !hideIt ) {
143 if ( recalculate ) setFixedSize(
int( agenda->gridSpacingX() ), 1 );
144 agenda->moveChild(
this, x, y );
148 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont);
150 TQString timeStr = TDEGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds);
151 TQFontMetrics fm = fontMetrics();
152 mTimeBox->setText( timeStr );
153 TQSize sz( fm.width( timeStr +
' ' ), fm.height() );
154 mTimeBox->setFixedSize( sz );
156 if (y-mTimeBox->height()>=0) y-=mTimeBox->height();
else y++;
157 if (x-mTimeBox->width()+agenda->gridSpacingX() > 0)
158 x += int( agenda->gridSpacingX() - mTimeBox->width() - 1 );
160 agenda->moveChild(mTimeBox,x,y);
162 mTimeBox->setAutoMask(
true);
164 minutes->start(1000,
true);
174 KOAgenda::KOAgenda(
int columns,
int rows,
int rowSize,
CalendarView *calendarView,
175 TQWidget *parent,
const char *name, WFlags f )
176 : TQScrollView( parent, name, f ), mChanger( 0 )
180 mGridSpacingY = rowSize;
181 if ( mGridSpacingY < 4 || mGridSpacingY > 30 ) {
185 mCalendarView = calendarView;
191 viewport()->setMouseTracking(
true);
198 KOAgenda::KOAgenda(
int columns,
CalendarView *calendarView, TQWidget *parent,
199 const char *name, WFlags f ) : TQScrollView( parent, name, f )
205 mCalendarView = calendarView;
206 setVScrollBarMode( AlwaysOff );
212 KOAgenda::~KOAgenda()
218 Incidence *KOAgenda::selectedIncidence()
const
220 return ( mSelectedItem ? mSelectedItem->incidence() : 0 );
224 TQDate KOAgenda::selectedIncidenceDate()
const
226 return ( mSelectedItem ? mSelectedItem->itemDate() : TQDate() );
229 const TQString KOAgenda::lastSelectedUid()
const
235 void KOAgenda::init()
238 mDesiredGridSpacingY = KOPrefs::instance()->mHourSize;
239 if ( mDesiredGridSpacingY < 4 || mDesiredGridSpacingY > 30 ) {
240 mDesiredGridSpacingY = 10;
244 mGridSpacingY = (double)height() / (double)mRows;
245 if ( mGridSpacingY < mDesiredGridSpacingY ) {
246 mGridSpacingY = mDesiredGridSpacingY;
249 mResizeBorderWidth = 8;
250 mScrollBorderWidth = 8;
254 enableClipper(
true );
258 setFocusPolicy( TQWidget::WheelFocus );
260 connect( &mScrollUpTimer, TQ_SIGNAL( timeout() ), TQ_SLOT( scrollUp() ) );
261 connect( &mScrollDownTimer, TQ_SIGNAL( timeout() ), TQ_SLOT( scrollDown() ) );
263 mStartCell = TQPoint( 0, 0 );
264 mEndCell = TQPoint( 0, 0 );
266 mHasSelection =
false;
267 mSelectionStartPoint = TQPoint( 0, 0 );
268 mSelectionStartCell = TQPoint( 0, 0 );
269 mSelectionEndCell = TQPoint( 0, 0 );
271 mOldLowerScrollValue = -1;
272 mOldUpperScrollValue = -1;
282 mSelectedUid = TQString();
284 setAcceptDrops(
true );
285 installEventFilter(
this );
286 mItems.setAutoDelete(
true );
287 mItemsToDelete.setAutoDelete(
true );
289 resizeContents(
int( mGridSpacingX * mColumns ),
290 int( mGridSpacingY * mRows ) );
292 viewport()->update();
293 viewport()->setBackgroundMode( NoBackground );
294 viewport()->setFocusPolicy( TQWidget::WheelFocus );
296 setMinimumSize( 30,
int( mGridSpacingY + 1 ) );
302 setHScrollBarMode( AlwaysOff );
304 setStartTime( KOPrefs::instance()->mDayBegins.time() );
306 calculateWorkingHours();
308 connect( verticalScrollBar(), TQ_SIGNAL( valueChanged(
int ) ),
309 TQ_SLOT( checkScrollBoundaries(
int ) ) );
315 mMarcusBains =
new MarcusBains(
this );
316 addChild( mMarcusBains );
320 mTypeAheadReceiver = 0;
322 mReturnPressed =
false;
326 void KOAgenda::clear()
331 for ( item = mItems.first(); item != 0; item = mItems.next() ) {
335 mItemsToDelete.clear();
343 void KOAgenda::clearSelection()
345 mHasSelection =
false;
350 void KOAgenda::marcus_bains()
352 if(mMarcusBains) mMarcusBains->updateLocationRecalc(
true );
356 void KOAgenda::changeColumns(
int columns)
359 kdDebug(5850) <<
"KOAgenda::changeColumns() called with argument 0" << endl;
369 TQResizeEvent event( size(), size() );
371 TQApplication::sendEvent(
this, &event );
378 bool KOAgenda::eventFilter ( TQObject *
object, TQEvent *event )
382 switch( event->type() ) {
383 case TQEvent::MouseButtonPress:
384 case TQEvent::MouseButtonDblClick:
385 case TQEvent::MouseButtonRelease:
386 case TQEvent::MouseMove:
387 return eventFilter_mouse(
object,
static_cast<TQMouseEvent*
>( event ) );
388 #ifndef TQT_NO_WHEELEVENT
390 return eventFilter_wheel(
object,
static_cast<TQWheelEvent*
>( event ) );
392 case TQEvent::KeyPress:
393 case TQEvent::KeyRelease:
394 return eventFilter_key(
object,
static_cast<TQKeyEvent*
>( event ) );
396 case ( TQEvent::Leave ):
398 setCursor( arrowCursor );
399 if (
object == viewport() )
405 return TQScrollView::eventFilter(
object, event );
408 case TQEvent::DragEnter:
409 case TQEvent::DragMove:
410 case TQEvent::DragLeave:
413 return eventFilter_drag(
object,
static_cast<TQDropEvent*
>(event));
417 return TQScrollView::eventFilter(
object, event );
421 bool KOAgenda::eventFilter_drag( TQObject *
object, TQDropEvent *de )
425 if (
object != viewport() &&
object !=
this ) {
426 viewportPos =
static_cast<TQWidget*
>( object )->mapToParent( de->pos() );
428 viewportPos = de->pos();
431 switch ( de->type() ) {
432 case TQEvent::DragEnter:
433 case TQEvent::DragMove:
434 if ( ICalDrag::canDecode( de ) || VCalDrag::canDecode( de ) ) {
437 Todo *todo = factory.createDropTodo( de );
447 case TQEvent::DragLeave:
452 if ( !ICalDrag::canDecode( de ) && !VCalDrag::canDecode( de ) ) {
457 Todo *todo = factory.createDropTodo( de );
465 if (
object ==
this ) {
466 pos = viewportPos + TQPoint( contentsX(), contentsY() );
468 pos = viewportToContents( viewportPos );
470 TQPoint gpos = contentsToGrid( pos );
471 emit droppedToDo( todo, gpos, mAllDayMode );
477 case TQEvent::DragResponse:
486 bool KOAgenda::eventFilter_key( TQObject *, TQKeyEvent *ke )
491 if ( ke->key() == Key_Return ) {
492 if ( ke->type() == TQEvent::KeyPress ) mReturnPressed =
true;
493 else if ( ke->type() == TQEvent::KeyRelease ) {
494 if ( mReturnPressed ) {
495 emitNewEventForSelection();
496 mReturnPressed =
false;
499 mReturnPressed =
false;
505 if ( ke->text().isEmpty() )
return false;
507 if ( ke->type() == TQEvent::KeyPress || ke->type() == TQEvent::KeyRelease ) {
508 switch ( ke->key() ) {
529 mTypeAheadEvents.append(
new TQKeyEvent( ke->type(), ke->key(),
530 ke->ascii(), ke->state(),
531 ke->text(), ke->isAutoRepeat(),
535 emitNewEventForSelection();
543 void KOAgenda::emitNewEventForSelection()
545 TQPair<ResourceCalendar *, TQString>p = mCalendarView->viewSubResourceCalendar();
546 emit newEventSignal( p.first, p.second );
549 void KOAgenda::finishTypeAhead()
552 if ( typeAheadReceiver() ) {
553 for( TQEvent *e = mTypeAheadEvents.first(); e;
554 e = mTypeAheadEvents.next() ) {
556 TQApplication::sendEvent( typeAheadReceiver(), e );
559 mTypeAheadEvents.clear();
562 #ifndef TQT_NO_WHEELEVENT
563 bool KOAgenda::eventFilter_wheel ( TQObject *
object, TQWheelEvent *e )
567 if ( ( e->state() & ShiftButton) == ShiftButton ) {
568 if (
object != viewport() ) {
569 viewportPos = ( (TQWidget *)
object )->mapToParent( e->pos() );
571 viewportPos = e->pos();
575 emit zoomView( -e->delta() ,
576 contentsToGrid( viewportToContents( viewportPos ) ),
581 if ( ( e->state() & ControlButton ) == ControlButton ){
582 if (
object != viewport() ) {
583 viewportPos = ( (TQWidget *)
object )->mapToParent( e->pos() );
585 viewportPos = e->pos();
587 emit zoomView( -e->delta() ,
588 contentsToGrid( viewportToContents( viewportPos ) ),
590 emit mousePosSignal(gridToContents(contentsToGrid(viewportToContents( viewportPos ))));
593 if (accepted ) e->accept();
597 bool KOAgenda::eventFilter_mouse(TQObject *
object, TQMouseEvent *me)
600 if (
object != viewport()) {
601 viewportPos = ((TQWidget *)
object)->mapToParent(me->pos());
603 viewportPos = me->pos();
606 switch (me->type()) {
607 case TQEvent::MouseButtonPress:
609 if (
object != viewport()) {
610 if (me->button() == TQt::RightButton) {
611 mClickedItem =
dynamic_cast<KOAgendaItem *
>(object);
613 selectItem(mClickedItem);
614 emit showIncidencePopupSignal( mCalendar,
615 mClickedItem->incidence(),
616 mClickedItem->itemDate() );
618 return TQScrollView::eventFilter(
object, me );
621 KOAgendaItem* item =
dynamic_cast<KOAgendaItem *
>(object);
623 Incidence *incidence = item->incidence();
629 mResPair = CalHelper::incSubResourceCalendar( mCalendar, incidence );
630 startItemAction(viewportPos);
638 return TQScrollView::eventFilter(
object, me );
642 if ( me->button() == TQt::RightButton ) {
644 TQPoint gpos = contentsToGrid( viewportToContents( viewportPos ) );
645 if ( !ptInSelection( gpos ) ) {
646 mSelectionStartCell = gpos;
647 mSelectionEndCell = gpos;
648 mHasSelection =
true;
649 emit newStartSelectSignal();
650 emit newTimeSpanSignal( mSelectionStartCell, mSelectionEndCell );
653 showNewEventPopupSignal();
656 TQPoint gpos = contentsToGrid( viewportToContents( viewportPos ) );
657 if ( !ptInSelection( gpos ) ) {
661 setCursor(arrowCursor);
662 startSelectAction(viewportPos);
665 return TQScrollView::eventFilter(
object, me );
669 case TQEvent::MouseButtonRelease:
672 }
else if ( mActionType == SELECT ) {
673 endSelectAction( viewportPos );
677 emit mousePosSignal( gridToContents(contentsToGrid(
678 viewportToContents( viewportPos ) ) ));
681 case TQEvent::MouseMove: {
684 TQPoint indicatorPos = gridToContents(contentsToGrid(
685 viewportToContents( viewportPos )));
686 if (
object != viewport()) {
687 KOAgendaItem *moveItem =
dynamic_cast<KOAgendaItem *
>(object);
688 if (moveItem && !moveItem->incidence()->isReadOnly() ) {
690 setNoActionCursor(moveItem,viewportPos);
692 performItemAction(viewportPos);
694 if ( mActionType == MOVE ) {
696 KOAgendaItem *firstItem = mActionItem->firstMultiItem();
697 if (!firstItem) firstItem = mActionItem;
698 indicatorPos = gridToContents( TQPoint( firstItem->cellXLeft(),
699 firstItem->cellYTop() ) );
701 }
else if ( mActionType == RESIZEBOTTOM ) {
703 indicatorPos = gridToContents( TQPoint( mActionItem->cellXLeft(),
704 mActionItem->cellYBottom()+1 ) );
710 if ( mActionType == SELECT ) {
711 performSelectAction( viewportPos );
714 if ( ((mStartCell.y() < mEndCell.y()) && (mEndCell.x() >= mStartCell.x())) ||
715 (mEndCell.x() > mStartCell.x()) )
716 indicatorPos = gridToContents( TQPoint(mEndCell.x(), mEndCell.y()+1) );
718 indicatorPos = gridToContents( mEndCell );
721 emit mousePosSignal( indicatorPos );
724 case TQEvent::MouseButtonDblClick:
725 if (
object == viewport()) {
727 TQPair<ResourceCalendar *, TQString>p = mCalendarView->viewSubResourceCalendar();
728 emit newEventSignal( p.first, p.second );
730 KOAgendaItem *doubleClickedItem =
dynamic_cast<KOAgendaItem *
>( object );
731 if ( doubleClickedItem ) {
732 selectItem( doubleClickedItem );
733 emit editIncidenceSignal( doubleClickedItem->incidence(), doubleClickedItem->itemDate() );
745 bool KOAgenda::ptInSelection( TQPoint gpos )
const
747 if ( !mHasSelection ) {
749 }
else if ( gpos.x()<mSelectionStartCell.x() || gpos.x()>mSelectionEndCell.x() ) {
751 }
else if ( (gpos.x()==mSelectionStartCell.x()) && (gpos.y()<mSelectionStartCell.y()) ) {
753 }
else if ( (gpos.x()==mSelectionEndCell.x()) && (gpos.y()>mSelectionEndCell.y()) ) {
759 void KOAgenda::startSelectAction(
const TQPoint &viewportPos )
761 emit newStartSelectSignal();
763 mActionType = SELECT;
764 mSelectionStartPoint = viewportPos;
765 mHasSelection =
true;
767 TQPoint pos = viewportToContents( viewportPos );
768 TQPoint gpos = contentsToGrid( pos );
773 mSelectionStartCell = gpos;
774 mSelectionEndCell = gpos;
779 void KOAgenda::performSelectAction(
const TQPoint& viewportPos)
781 TQPoint pos = viewportToContents( viewportPos );
782 TQPoint gpos = contentsToGrid( pos );
784 TQPoint clipperPos = clipper()->
785 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
788 if (clipperPos.y() < mScrollBorderWidth) {
789 mScrollUpTimer.start(mScrollDelay);
790 }
else if (visibleHeight() - clipperPos.y() <
791 mScrollBorderWidth) {
792 mScrollDownTimer.start(mScrollDelay);
794 mScrollUpTimer.stop();
795 mScrollDownTimer.stop();
798 if ( gpos != mEndCell ) {
800 if ( mStartCell.x()>mEndCell.x() ||
801 ( mStartCell.x()==mEndCell.x() && mStartCell.y()>mEndCell.y() ) ) {
803 mSelectionStartCell = mEndCell;
804 mSelectionEndCell = mStartCell;
806 mSelectionStartCell = mStartCell;
807 mSelectionEndCell = mEndCell;
814 void KOAgenda::endSelectAction(
const TQPoint ¤tPos )
816 mScrollUpTimer.stop();
817 mScrollDownTimer.stop();
821 emit newTimeSpanSignal( mSelectionStartCell, mSelectionEndCell );
823 if ( KOPrefs::instance()->mSelectionStartsEditor ) {
824 if ( ( mSelectionStartPoint - currentPos ).manhattanLength() >
825 TQApplication::startDragDistance() ) {
826 emitNewEventForSelection();
831 KOAgenda::MouseActionType KOAgenda::isInResizeArea(
bool horizontal,
832 const TQPoint &pos, KOAgendaItem*item )
834 if (!item)
return NOP;
835 TQPoint gridpos = contentsToGrid( pos );
836 TQPoint contpos = gridToContents( gridpos +
837 TQPoint( (KOGlobals::self()->reverseLayout())?1:0, 0 ) );
843 int clXLeft = item->cellXLeft();
844 int clXRight = item->cellXRight();
845 if ( KOGlobals::self()->reverseLayout() ) {
850 int gridDistanceX = int( pos.x() - contpos.x() );
851 if (gridDistanceX < mResizeBorderWidth && clXLeft == gridpos.x() ) {
852 if ( KOGlobals::self()->reverseLayout() )
return RESIZERIGHT;
853 else return RESIZELEFT;
854 }
else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
855 clXRight == gridpos.x() ) {
856 if ( KOGlobals::self()->reverseLayout() )
return RESIZELEFT;
857 else return RESIZERIGHT;
862 int gridDistanceY = int( pos.y() - contpos.y() );
863 if (gridDistanceY < mResizeBorderWidth &&
864 item->cellYTop() == gridpos.y() &&
865 !item->firstMultiItem() ) {
867 }
else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
868 item->cellYBottom() == gridpos.y() &&
869 !item->lastMultiItem() ) {
877 void KOAgenda::startItemAction(
const TQPoint& viewportPos)
879 TQPoint pos = viewportToContents( viewportPos );
880 mStartCell = contentsToGrid( pos );
881 mEndCell = mStartCell;
883 bool noResize = ( mActionItem->incidence()->type() ==
"Todo");
887 mActionType = isInResizeArea( mAllDayMode, pos, mActionItem );
891 mActionItem->startMove();
892 setActionCursor( mActionType,
true );
895 void KOAgenda::performItemAction(
const TQPoint& viewportPos)
903 TQPoint pos = viewportToContents( viewportPos );
905 TQPoint gpos = contentsToGrid( pos );
906 TQPoint clipperPos = clipper()->
907 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
911 if ( clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||
912 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) {
913 if ( mActionType == MOVE ) {
914 mScrollUpTimer.stop();
915 mScrollDownTimer.stop();
916 mActionItem->resetMove();
917 placeSubCells( mActionItem );
918 emit startDragSignal( mActionItem->incidence() );
919 setCursor( arrowCursor );
927 setActionCursor( mActionType );
931 if (clipperPos.y() < mScrollBorderWidth) {
932 mScrollUpTimer.start(mScrollDelay);
933 }
else if (visibleHeight() - clipperPos.y() <
934 mScrollBorderWidth) {
935 mScrollDownTimer.start(mScrollDelay);
937 mScrollUpTimer.stop();
938 mScrollDownTimer.stop();
942 if ( mEndCell != gpos ) {
945 !mChanger->beginChange( mActionItem->incidence(), mResPair.first, mResPair.second ) ) {
946 KMessageBox::information(
this, i18n(
"Unable to lock item for "
947 "modification. You cannot make any changes."),
948 i18n(
"Locking Failed"),
"AgendaLockingFailed" );
949 mScrollUpTimer.stop();
950 mScrollDownTimer.stop();
951 mActionItem->resetMove();
952 placeSubCells( mActionItem );
953 setCursor( arrowCursor );
962 mActionItem->raise();
963 if (mActionType == MOVE) {
965 KOAgendaItem *firstItem = mActionItem->firstMultiItem();
966 if (!firstItem) firstItem = mActionItem;
967 KOAgendaItem *lastItem = mActionItem->lastMultiItem();
968 if (!lastItem) lastItem = mActionItem;
969 TQPoint deltapos = gpos - mEndCell;
970 KOAgendaItem *moveItem = firstItem;
973 if ( deltapos.x()!=0 ) {
974 moveItem->moveRelative( deltapos.x(), 0 );
978 if ( moveItem==firstItem && !mAllDayMode ) {
979 int newY = deltapos.y() + moveItem->cellYTop();
982 moveItem->expandTop( -moveItem->cellYTop() );
984 KOAgendaItem *newFirst = firstItem->prevMoveItem();
987 newFirst->setCellXY(moveItem->cellXLeft()-1, rows()+newY, rows()-1);
988 mItems.append( newFirst );
989 moveItem->resize(
int( mGridSpacingX * newFirst->cellWidth() ),
990 int( mGridSpacingY * newFirst->cellHeight() ));
991 TQPoint cpos = gridToContents( TQPoint( newFirst->cellXLeft(), newFirst->cellYTop() ) );
992 addChild( newFirst, cpos.x(), cpos.y() );
994 newFirst = insertItem( moveItem->incidence(), moveItem->itemDate(),
995 moveItem->cellXLeft()-1, rows()+newY, rows()-1, moveItem->itemPos(), moveItem->itemCount() ) ;
997 if (newFirst) newFirst->show();
998 moveItem->prependMoveItem(newFirst);
1000 }
else if ( newY>=rows() ) {
1003 firstItem = moveItem->nextMultiItem();
1005 mItems.take( mItems.find( moveItem ) );
1006 removeChild( moveItem );
1007 mActionItem->removeMoveItem(moveItem);
1010 if (moveItem) moveItem->expandTop( rows()-newY );
1012 moveItem->expandTop(deltapos.y());
1016 if ( !moveItem->lastMultiItem() && !mAllDayMode ) {
1017 int newY = deltapos.y()+moveItem->cellYBottom();
1020 lastItem = moveItem->prevMultiItem();
1022 mItems.take( mItems.find(moveItem) );
1023 removeChild( moveItem );
1024 moveItem->removeMoveItem( moveItem );
1025 moveItem = lastItem;
1026 moveItem->expandBottom(newY+1);
1027 }
else if (newY>=rows()) {
1028 moveItem->expandBottom( rows()-moveItem->cellYBottom()-1 );
1030 KOAgendaItem *newLast = lastItem->nextMoveItem();
1032 newLast->setCellXY( moveItem->cellXLeft()+1, 0, newY-rows()-1 );
1033 mItems.append(newLast);
1034 moveItem->resize(
int( mGridSpacingX * newLast->cellWidth() ),
1035 int( mGridSpacingY * newLast->cellHeight() ));
1036 TQPoint cpos = gridToContents( TQPoint( newLast->cellXLeft(), newLast->cellYTop() ) ) ;
1037 addChild( newLast, cpos.x(), cpos.y() );
1039 newLast = insertItem( moveItem->incidence(), moveItem->itemDate(),
1040 moveItem->cellXLeft()+1, 0, newY-rows()-1, moveItem->itemPos(), moveItem->itemCount() ) ;
1042 moveItem->appendMoveItem( newLast );
1046 moveItem->expandBottom( deltapos.y() );
1051 adjustItemPosition( moveItem );
1053 moveItem = moveItem->nextMultiItem();
1055 }
else if (mActionType == RESIZETOP) {
1056 if (mEndCell.y() <= mActionItem->cellYBottom()) {
1057 mActionItem->expandTop(gpos.y() - mEndCell.y());
1058 adjustItemPosition( mActionItem );
1060 }
else if (mActionType == RESIZEBOTTOM) {
1061 if (mEndCell.y() >= mActionItem->cellYTop()) {
1062 mActionItem->expandBottom(gpos.y() - mEndCell.y());
1063 adjustItemPosition( mActionItem );
1065 }
else if (mActionType == RESIZELEFT) {
1066 if (mEndCell.x() <= mActionItem->cellXRight()) {
1067 mActionItem->expandLeft( gpos.x() - mEndCell.x() );
1068 adjustItemPosition( mActionItem );
1070 }
else if (mActionType == RESIZERIGHT) {
1071 if (mEndCell.x() >= mActionItem->cellXLeft()) {
1072 mActionItem->expandRight(gpos.x() - mEndCell.x());
1073 adjustItemPosition( mActionItem );
1080 void KOAgenda::endItemAction()
1084 mScrollUpTimer.stop();
1085 mScrollDownTimer.stop();
1086 setCursor( arrowCursor );
1087 bool multiModify =
false;
1089 Incidence* inc = mActionItem->incidence();
1091 if ( mStartCell.x() == mEndCell.x() && mStartCell.y() == mEndCell.y() ) {
1095 mChanger->endChange( inc, mResPair.first, mResPair.second );
1101 if ( mActionItem->incidence()->doesRecur() ) {
1103 KOGlobals::WhichOccurrences chosenOption;
1104 incToChange = mCalendarView->singleOccurrenceOrAll( inc,
1107 mActionItem->itemDate() );
1109 if ( chosenOption == KOGlobals::ONLY_THIS_ONE ||
1110 chosenOption == KOGlobals::ONLY_FUTURE ) {
1114 int autoAnswerGroupWare = 1;
1117 int mai_xl = mActionItem->cellXLeft();
1118 int mai_xr = mActionItem->cellXRight();
1119 int mai_yt = mActionItem->cellYTop();
1120 int mai_yb = mActionItem->cellYBottom();
1123 emit startMultiModify( i18n(
"Dissociate event from recurrence") );
1124 enableAgendaUpdate(
false );
1126 mChanger->addIncidence( incToChange, mResPair.first, mResPair.second,
this, autoAnswerGroupWare );
1127 enableAgendaUpdate(
true );
1128 KOGlobals::WhatChanged wc = chosenOption == KOGlobals::ONLY_THIS_ONE ?
1129 KOGlobals::RECURRENCE_MODIFIED_ONE_ONLY :
1130 KOGlobals::RECURRENCE_MODIFIED_ALL_FUTURE;
1132 mChanger->changeIncidence( oldIncSaved, inc, wc,
this, autoAnswerGroupWare );
1140 KOAgendaItem *koai_insertedItem;
1141 for ( koai_insertedItem = mItems.first(); koai_insertedItem; koai_insertedItem = mItems.next() ) {
1142 if (koai_insertedItem->incidence() == incToChange) {
1143 selectItem( koai_insertedItem );
1144 mSelectedItem->startMove();
1145 mSelectedItem->setCellY(mai_yt, mai_yb);
1146 mSelectedItem->setCellX(mai_xl, mai_xr);
1147 mActionItem = mSelectedItem;
1153 mActionItem->dissociateFromMultiItem();
1154 mActionItem->setIncidence( incToChange );
1158 if ( incToChange ) {
1159 mActionItem->endMove();
1160 KOAgendaItem *placeItem = mActionItem->firstMultiItem();
1162 placeItem = mActionItem;
1165 KOAgendaItem *modif = placeItem;
1167 TQPtrList<KOAgendaItem> oldconflictItems = placeItem->conflictItems();
1169 for ( item = oldconflictItems.first(); item != 0;
1170 item = oldconflictItems.next() ) {
1171 placeSubCells( item );
1173 while ( placeItem ) {
1174 placeSubCells( placeItem );
1175 placeItem = placeItem->nextMultiItem();
1180 mChanger->endChange( inc, mResPair.first, mResPair.second );
1181 emit itemModified( modif );
1184 mActionItem->resetMove();
1185 placeSubCells( mActionItem );
1189 mChanger->endChange( inc, mResPair.first, mResPair.second );
1190 emit itemModified( mActionItem );
1198 if ( multiModify ) {
1199 emit endMultiModify();
1202 kdDebug(5850) <<
"KOAgenda::endItemAction() done" << endl;
1205 void KOAgenda::setActionCursor(
int actionType,
bool acting )
1207 switch ( actionType ) {
1209 if (acting) setCursor( sizeAllCursor );
1210 else setCursor( arrowCursor );
1214 setCursor( sizeVerCursor );
1218 setCursor( sizeHorCursor );
1221 setCursor( arrowCursor );
1225 void KOAgenda::setNoActionCursor( KOAgendaItem *moveItem,
const TQPoint& viewportPos )
1233 TQPoint pos = viewportToContents( viewportPos );
1234 bool noResize = (moveItem && moveItem->incidence() &&
1235 moveItem->incidence()->type() ==
"Todo");
1237 KOAgenda::MouseActionType resizeType = MOVE;
1238 if ( !noResize ) resizeType = isInResizeArea( mAllDayMode, pos , moveItem);
1239 setActionCursor( resizeType );
1245 double KOAgenda::calcSubCellWidth( KOAgendaItem *item )
1248 pt = gridToContents( TQPoint( item->cellXLeft(), item->cellYTop() ) );
1249 pt1 = gridToContents( TQPoint( item->cellXLeft(), item->cellYTop() ) +
1252 int maxSubCells = item->subCells();
1253 double newSubCellWidth;
1254 if ( mAllDayMode ) {
1255 newSubCellWidth = double( pt1.y() ) / maxSubCells;
1257 newSubCellWidth = double( pt1.x() ) / maxSubCells;
1259 return newSubCellWidth;
1262 void KOAgenda::adjustItemPosition( KOAgendaItem *item )
1265 item->resize(
int( mGridSpacingX * item->cellWidth() ),
1266 int( mGridSpacingY * item->cellHeight() ) );
1267 int clXLeft = item->cellXLeft();
1268 if ( KOGlobals::self()->reverseLayout() )
1269 clXLeft = item->cellXRight() + 1;
1270 TQPoint cpos = gridToContents( TQPoint( clXLeft, item->cellYTop() ) );
1271 moveChild( item, cpos.x(), cpos.y() );
1274 void KOAgenda::placeAgendaItem( KOAgendaItem *item,
double subCellWidth )
1280 TQPoint pt = gridToContents( TQPoint( item->cellXLeft(), item->cellYTop() ) );
1282 TQPoint pt1 = gridToContents( TQPoint( item->cellXLeft() + item->cellWidth(),
1283 item->cellYBottom()+1 ) );
1285 double subCellPos = item->subCell() * subCellWidth;
1290 if (subCellWidth<0) delta=-delta;
1291 int height, width, xpos, ypos;
1293 width = pt1.x()-pt.x();
1294 height = int( subCellPos + subCellWidth + delta ) - int( subCellPos );
1296 ypos = pt.y() + int( subCellPos );
1298 width = int( subCellPos + subCellWidth + delta ) - int( subCellPos );
1299 height = pt1.y()-pt.y();
1300 xpos = pt.x() + int( subCellPos );
1303 if ( KOGlobals::self()->reverseLayout() ) {
1311 item->resize( width, height );
1312 moveChild( item, xpos, ypos );
1325 void KOAgenda::placeSubCells( KOAgendaItem *placeItem )
1328 kdDebug(5850) <<
"KOAgenda::placeSubCells()" << endl;
1330 Incidence *
event = placeItem->incidence();
1332 kdDebug(5850) <<
" event is 0" << endl;
1334 kdDebug(5850) <<
" event: " <<
event->
summary() << endl;
1337 kdDebug(5850) <<
" placeItem is 0" << endl;
1339 kdDebug(5850) <<
"KOAgenda::placeSubCells()..." << endl;
1342 TQPtrList<KOrg::CellItem> cells;
1344 for ( item = mItems.first(); item != 0; item = mItems.next() ) {
1345 cells.append( item );
1348 TQPtrList<KOrg::CellItem> items = KOrg::CellItem::placeItem( cells,
1351 placeItem->setConflictItems( TQPtrList<KOAgendaItem>() );
1352 double newSubCellWidth = calcSubCellWidth( placeItem );
1354 for ( i = items.first(); i; i = items.next() ) {
1355 item =
static_cast<KOAgendaItem *
>( i );
1356 placeAgendaItem( item, newSubCellWidth );
1357 item->addConflictItem( placeItem );
1358 placeItem->addConflictItem( item );
1360 if ( items.isEmpty() ) {
1361 placeAgendaItem( placeItem, newSubCellWidth );
1363 placeItem->update();
1366 int KOAgenda::columnWidth(
int column )
1368 int start = gridToContents( TQPoint( column, 0 ) ).x();
1369 if (KOGlobals::self()->reverseLayout() )
1373 int end = gridToContents( TQPoint( column, 0 ) ).x();
1379 void KOAgenda::drawContents(TQPainter* p,
int cx,
int cy,
int cw,
int ch)
1381 TQPixmap db(cw, ch);
1382 db.fill(KOPrefs::instance()->mAgendaBgColor);
1384 dbp.translate(-cx,-cy);
1387 double lGridSpacingY = mGridSpacingY*2;
1390 if (mWorkingHoursEnable) {
1391 TQPoint pt1( cx, mWorkingHoursYTop );
1392 TQPoint pt2( cx+cw, mWorkingHoursYBottom );
1393 if ( pt2.x() >= pt1.x() ) {
1394 int gxStart = contentsToGrid( pt1 ).x();
1395 int gxEnd = contentsToGrid( pt2 ).x();
1397 if ( gxStart > gxEnd ) {
1402 int xoffset = ( KOGlobals::self()->reverseLayout()?1:0 );
1403 while( gxStart <= gxEnd ) {
1404 int xStart = gridToContents( TQPoint( gxStart+xoffset, 0 ) ).x();
1405 int xWidth = columnWidth( gxStart ) + 1;
1406 if ( pt2.y() < pt1.y() ) {
1408 if ( ( (gxStart==0) && !mHolidayMask->at(mHolidayMask->count()-1) ) ||
1409 ( (gxStart>0) && (gxStart<
int(mHolidayMask->count())) && (!mHolidayMask->at(gxStart-1) ) ) ) {
1410 if ( pt2.y() > cy ) {
1411 dbp.fillRect( xStart, cy, xWidth, pt2.y() - cy + 1,
1412 KOPrefs::instance()->mWorkingHoursColor);
1415 if ( (gxStart <
int(mHolidayMask->count()-1)) && (!mHolidayMask->at(gxStart)) ) {
1416 if ( pt1.y() < cy + ch - 1 ) {
1417 dbp.fillRect( xStart, pt1.y(), xWidth, cy + ch - pt1.y() + 1,
1418 KOPrefs::instance()->mWorkingHoursColor);
1423 if ( gxStart <
int(mHolidayMask->count()-1) && !mHolidayMask->at(gxStart)) {
1424 dbp.fillRect( xStart, pt1.y(), xWidth, pt2.y() - pt1.y() + 1,
1425 KOPrefs::instance()->mWorkingHoursColor );
1434 if ( mHasSelection ) {
1437 if ( mSelectionEndCell.x() > mSelectionStartCell.x() ) {
1439 pt = gridToContents( mSelectionStartCell );
1440 pt1 = gridToContents( TQPoint( mSelectionStartCell.x() + 1, mRows + 1 ) );
1441 dbp.fillRect( TQRect( pt, pt1 ), KOPrefs::instance()->mHighlightColor );
1443 for (
int c = mSelectionStartCell.x() + 1; c < mSelectionEndCell.x(); ++c ) {
1444 pt = gridToContents( TQPoint( c, 0 ) );
1445 pt1 = gridToContents( TQPoint( c + 1, mRows + 1 ) );
1446 dbp.fillRect( TQRect( pt, pt1 ), KOPrefs::instance()->mHighlightColor );
1449 pt = gridToContents( TQPoint( mSelectionEndCell.x(), 0 ) );
1450 pt1 = gridToContents( mSelectionEndCell + TQPoint(1,1) );
1451 dbp.fillRect( TQRect( pt, pt1), KOPrefs::instance()->mHighlightColor );
1453 pt = gridToContents( mSelectionStartCell );
1454 pt1 = gridToContents( mSelectionEndCell + TQPoint(1,1) );
1455 dbp.fillRect( TQRect( pt, pt1 ), KOPrefs::instance()->mHighlightColor );
1459 TQPen hourPen( KOPrefs::instance()->mAgendaBgColor.dark( 150 ) );
1460 TQPen halfHourPen( KOPrefs::instance()->mAgendaBgColor.dark( 125 ) );
1461 dbp.setPen( hourPen );
1465 double x = ( int( cx / mGridSpacingX ) ) * mGridSpacingX;
1466 while (x < cx + cw) {
1467 dbp.drawLine(
int( x ), cy, int( x ), cy + ch );
1472 double y = ( int( cy / (2*lGridSpacingY) ) ) * 2 * lGridSpacingY;
1473 while (y < cy + ch) {
1475 dbp.drawLine( cx,
int( y ), cx + cw, int( y ) );
1476 y += 2 * lGridSpacingY;
1478 y = ( 2 * int( cy / (2*lGridSpacingY) ) + 1) * lGridSpacingY;
1479 dbp.setPen( halfHourPen );
1480 while (y < cy + ch) {
1482 dbp.drawLine( cx,
int( y ), cx + cw, int( y ) );
1485 p->drawPixmap(cx,cy, db);
1491 TQPoint KOAgenda::contentsToGrid (
const TQPoint &pos )
const
1493 int gx = int( KOGlobals::self()->reverseLayout() ?
1494 mColumns - pos.x()/mGridSpacingX : pos.x()/mGridSpacingX );
1495 int gy = int( pos.y()/mGridSpacingY );
1496 return TQPoint( gx, gy );
1502 TQPoint KOAgenda::gridToContents(
const TQPoint &gpos )
const
1504 int x = int( KOGlobals::self()->reverseLayout() ?
1505 (mColumns - gpos.x())*mGridSpacingX : gpos.x()*mGridSpacingX );
1506 int y = int( gpos.y()*mGridSpacingY );
1507 return TQPoint( x, y );
1515 int KOAgenda::timeToY(
const TQTime &time)
1518 int minutesPerCell = 24 * 60 / mRows;
1520 int timeMinutes = time.hour() * 60 + time.minute();
1522 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell;
1533 TQTime KOAgenda::gyToTime(
int gy)
1536 int secondsPerCell = 24 * 60 * 60/ mRows;
1538 int timeSeconds = secondsPerCell * gy;
1540 TQTime time( 0, 0, 0 );
1541 if ( timeSeconds < 24 * 60 * 60 ) {
1542 time = time.addSecs(timeSeconds);
1544 time.setHMS( 23, 59, 59 );
1551 TQMemArray<int> KOAgenda::minContentsY()
1553 TQMemArray<int> minArray;
1554 minArray.fill( timeToY( TQTime(23, 59) ), mSelectedDates.count() );
1555 for ( KOAgendaItem *item = mItems.first();
1556 item != 0; item = mItems.next() ) {
1557 int ymin = item->cellYTop();
1558 int index = item->cellXLeft();
1559 if ( index>=0 && index<(
int)(mSelectedDates.count()) ) {
1560 if ( ymin < minArray[index] && mItemsToDelete.findRef( item ) == -1 )
1561 minArray[index] = ymin;
1568 TQMemArray<int> KOAgenda::maxContentsY()
1570 TQMemArray<int> maxArray;
1571 maxArray.fill( timeToY( TQTime(0, 0) ), mSelectedDates.count() );
1572 for ( KOAgendaItem *item = mItems.first();
1573 item != 0; item = mItems.next() ) {
1574 int ymax = item->cellYBottom();
1575 int index = item->cellXLeft();
1576 if ( index>=0 && index<(
int)(mSelectedDates.count()) ) {
1577 if ( ymax > maxArray[index] && mItemsToDelete.findRef( item ) == -1 )
1578 maxArray[index] = ymax;
1585 void KOAgenda::setStartTime(
const TQTime &startHour )
1587 double startPos = ( startHour.hour()/24. + startHour.minute()/1440. +
1588 startHour.second()/86400. ) * mRows * gridSpacingY();
1589 setContentsPos( 0,
int( startPos ) );
1596 KOAgendaItem *KOAgenda::insertItem(
Incidence *incidence,
const TQDate &qd,
int X,
1597 int YTop,
int YBottom,
int itemPos,
int itemCount )
1599 if ( mAllDayMode ) {
1600 kdDebug(5850) <<
"KOAgenda: calling insertItem in all-day mode is illegal." << endl;
1606 KOAgendaItem *agendaItem =
new KOAgendaItem( mCalendar, incidence, qd, viewport(), itemPos, itemCount );
1607 connect( agendaItem, TQ_SIGNAL( removeAgendaItem( KOAgendaItem * ) ),
1608 TQ_SLOT( removeAgendaItem( KOAgendaItem * ) ) );
1609 connect( agendaItem, TQ_SIGNAL( showAgendaItem( KOAgendaItem * ) ),
1610 TQ_SLOT( showAgendaItem( KOAgendaItem * ) ) );
1612 if ( YBottom <= YTop ) {
1613 kdDebug(5850) <<
"KOAgenda::insertItem(): Text: " << agendaItem->text() <<
" YSize<0" << endl;
1617 agendaItem->resize(
int( ( X + 1 ) * mGridSpacingX ) -
1618 int( X * mGridSpacingX ),
1619 int( YTop * mGridSpacingY ) -
1620 int( ( YBottom + 1 ) * mGridSpacingY ) );
1621 agendaItem->setCellXY( X, YTop, YBottom );
1622 agendaItem->setCellXRight( X );
1623 agendaItem->setResourceColor( KOHelper::resourceColor( mCalendar, incidence ) );
1624 agendaItem->installEventFilter(
this );
1626 addChild( agendaItem,
int( X * mGridSpacingX ),
int( YTop * mGridSpacingY ) );
1627 mItems.append( agendaItem );
1629 placeSubCells( agendaItem );
1641 KOAgendaItem *KOAgenda::insertAllDayItem(
Incidence *event,
const TQDate &qd,
1642 int XBegin,
int XEnd )
1644 if ( !mAllDayMode ) {
1645 kdDebug(5850) <<
"KOAgenda: calling insertAllDayItem in non all-day mode is illegal." << endl;
1651 KOAgendaItem *agendaItem =
new KOAgendaItem( mCalendar, event, qd, viewport(), 1, 1 );
1652 connect( agendaItem, TQ_SIGNAL( removeAgendaItem( KOAgendaItem* ) ),
1653 TQ_SLOT( removeAgendaItem( KOAgendaItem* ) ) );
1654 connect( agendaItem, TQ_SIGNAL( showAgendaItem( KOAgendaItem* ) ),
1655 TQ_SLOT( showAgendaItem( KOAgendaItem* ) ) );
1657 agendaItem->setCellXY( XBegin, 0, 0 );
1658 agendaItem->setCellXRight( XEnd );
1660 double startIt = mGridSpacingX * ( agendaItem->cellXLeft() );
1661 double endIt = mGridSpacingX * ( agendaItem->cellWidth() +
1662 agendaItem->cellXLeft() );
1664 agendaItem->resize(
int( endIt ) - int( startIt ), int( mGridSpacingY ) );
1666 agendaItem->installEventFilter(
this );
1667 agendaItem->setResourceColor( KOHelper::resourceColor( mCalendar, event ) );
1668 addChild( agendaItem,
int( XBegin * mGridSpacingX ), 0 );
1669 mItems.append( agendaItem );
1671 placeSubCells( agendaItem );
1679 void KOAgenda::insertMultiItem(
Event *event,
const TQDate &qd,
int XBegin,
int XEnd,
1680 int YTop,
int YBottom )
1682 if ( mAllDayMode ) {
1683 kdDebug(5850) <<
"KOAgenda: calling insertMultiItem in all-day mode is illegal." << endl;
1688 int cellX,cellYTop,cellYBottom;
1690 int width = XEnd - XBegin + 1;
1692 KOAgendaItem *current = 0;
1693 TQPtrList<KOAgendaItem> multiItems;
1694 const int visibleCount = mSelectedDates.first().daysTo( mSelectedDates.last() );
1695 for ( cellX = XBegin; cellX <= XEnd; ++cellX ) {
1698 if( cellX >= 0 && cellX <= visibleCount ) {
1699 if ( cellX == XBegin ) {
1705 if ( cellX == XEnd ) {
1706 cellYBottom = YBottom;
1708 cellYBottom = rows() - 1;
1711 newtext = TQString(
"(%1/%2): ").arg( count ).arg( width );
1712 newtext.append( event->
summary() );
1714 current = insertItem( event, qd, cellX, cellYTop, cellYBottom, count, width );
1715 current->setText( newtext );
1716 multiItems.append( current );
1719 TQPtrList<KOAgendaItem>::iterator it = multiItems.begin();
1720 TQPtrList<KOAgendaItem>::iterator e = multiItems.end();
1723 KOAgendaItem *first = multiItems.first();
1724 KOAgendaItem *last = multiItems.last();
1725 KOAgendaItem *prev = 0, *next = 0;
1728 KOAgendaItem *item = *it;
1730 next = ( it == e ) ? 0 : (*it);
1732 item->setMultiItem( ( item == first ) ? 0 : first,
1734 ( item == last ) ? 0 : last );
1743 void KOAgenda::removeIncidence(
Incidence *incidence )
1748 TQPtrList<KOAgendaItem> itemsToRemove;
1750 KOAgendaItem *item = mItems.first();
1752 if ( item->incidence() == incidence ) {
1753 itemsToRemove.append( item );
1755 item = mItems.next();
1757 item = itemsToRemove.first();
1759 removeAgendaItem( item );
1760 item = itemsToRemove.next();
1764 void KOAgenda::showAgendaItem( KOAgendaItem *agendaItem )
1766 if ( !agendaItem ) {
1771 addChild( agendaItem );
1772 if ( !mItems.containsRef( agendaItem ) ) {
1773 mItems.append( agendaItem );
1775 placeSubCells( agendaItem );
1780 bool KOAgenda::removeAgendaItem( KOAgendaItem *item )
1784 KOAgendaItem *thisItem = item;
1785 TQPtrList<KOAgendaItem> conflictItems = thisItem->conflictItems();
1786 removeChild( thisItem );
1788 int pos = mItems.find( thisItem );
1794 KOAgendaItem *confitem;
1795 for ( confitem = conflictItems.first(); confitem != 0;
1796 confitem = conflictItems.next() ) {
1798 if ( confitem != thisItem ) placeSubCells(confitem);
1801 mItemsToDelete.append( thisItem );
1802 TQTimer::singleShot( 0,
this, TQ_SLOT( deleteItemsToDelete() ) );
1806 void KOAgenda::deleteItemsToDelete()
1808 mItemsToDelete.clear();
1829 void KOAgenda::resizeEvent ( TQResizeEvent *ev )
1833 TQSize newSize( ev->size() );
1835 mGridSpacingX = double( newSize.width() - 2 * frameWidth() ) / (double)mColumns;
1836 mGridSpacingY = newSize.height() - 2 * frameWidth();
1838 int scrollbarWidth = vScrollBarMode() != AlwaysOff ? verticalScrollBar()->width() : 0;
1839 mGridSpacingX = double( newSize.width() - scrollbarWidth - 2 * frameWidth()) / double(mColumns);
1841 mGridSpacingY = double(newSize.height() - 2 * frameWidth()) / double(mRows);
1842 if ( mGridSpacingY < mDesiredGridSpacingY )
1843 mGridSpacingY = mDesiredGridSpacingY;
1845 calculateWorkingHours();
1846 TQTimer::singleShot( 0,
this, TQ_SLOT( resizeAllContents() ) );
1847 emit gridSpacingYChanged( mGridSpacingY * 4 );
1848 TQScrollView::resizeEvent(ev);
1851 void KOAgenda::resizeAllContents()
1853 double subCellWidth;
1854 if ( mItems.count() > 0 ) {
1857 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1858 subCellWidth = calcSubCellWidth( item );
1859 placeAgendaItem( item, subCellWidth );
1862 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1863 subCellWidth = calcSubCellWidth( item );
1864 placeAgendaItem( item, subCellWidth );
1868 checkScrollBoundaries();
1872 void KOAgenda::scrollUp()
1874 scrollBy(0,-mScrollOffset);
1878 void KOAgenda::scrollDown()
1880 scrollBy(0,mScrollOffset);
1887 int KOAgenda::minimumWidth()
const
1895 void KOAgenda::updateConfig()
1897 double oldGridSpacingY = mGridSpacingY;
1899 mDesiredGridSpacingY = KOPrefs::instance()->mHourSize;
1900 if ( mDesiredGridSpacingY < 4 || mDesiredGridSpacingY > 30 ) {
1901 mDesiredGridSpacingY = 10;
1905 mGridSpacingY = (double)height() / (double)mRows;
1906 if ( mGridSpacingY < mDesiredGridSpacingY ) {
1907 mGridSpacingY = mDesiredGridSpacingY;
1911 if ( fabs( oldGridSpacingY - mGridSpacingY ) > 0.1 ) {
1912 resizeContents(
int( mGridSpacingX * mColumns ),
1913 int( mGridSpacingY * mRows ) );
1916 calculateWorkingHours();
1921 void KOAgenda::checkScrollBoundaries()
1924 mOldLowerScrollValue = -1;
1925 mOldUpperScrollValue = -1;
1927 checkScrollBoundaries(verticalScrollBar()->value());
1930 void KOAgenda::checkScrollBoundaries(
int v )
1932 int yMin = int( (v) / mGridSpacingY );
1933 int yMax = int( ( v + visibleHeight() ) / mGridSpacingY );
1937 if ( yMin != mOldLowerScrollValue ) {
1938 mOldLowerScrollValue = yMin;
1939 emit lowerYChanged(yMin);
1941 if ( yMax != mOldUpperScrollValue ) {
1942 mOldUpperScrollValue = yMax;
1943 emit upperYChanged(yMax);
1947 int KOAgenda::visibleContentsYMin()
1949 int v = verticalScrollBar()->value();
1950 return int( v / mGridSpacingY );
1953 int KOAgenda::visibleContentsYMax()
1955 int v = verticalScrollBar()->value();
1956 return int( ( v + visibleHeight() ) / mGridSpacingY );
1959 void KOAgenda::deselectItem()
1961 if ( mSelectedItem.isNull() ) {
1964 mSelectedItem->select(
false);
1968 void KOAgenda::selectItem(KOAgendaItem *item)
1970 if ((KOAgendaItem *)mSelectedItem == item)
return;
1973 emit incidenceSelected( 0, TQDate() );
1976 mSelectedItem = item;
1977 mSelectedItem->select();
1978 assert( mSelectedItem->incidence() );
1979 mSelectedUid = mSelectedItem->incidence()->uid();
1980 emit incidenceSelected( mSelectedItem->incidence(), mSelectedItem->itemDate() );
1983 void KOAgenda::selectItemByUID(
const TQString& uid )
1986 for ( item = mItems.first(); item != 0; item = mItems.next() ) {
1987 if( item->incidence() && item->incidence()->uid() == uid ) {
1995 void KOAgenda::keyPressEvent( TQKeyEvent *kev )
1997 switch(kev->key()) {
1999 verticalScrollBar()->addPage();
2002 verticalScrollBar()->subtractPage();
2005 verticalScrollBar()->addLine();
2008 verticalScrollBar()->subtractLine();
2015 void KOAgenda::calculateWorkingHours()
2017 mWorkingHoursEnable = !mAllDayMode;
2019 TQTime tmp = KOPrefs::instance()->mWorkingHoursStart.time();
2020 mWorkingHoursYTop = int( 4 * mGridSpacingY *
2021 ( tmp.hour() + tmp.minute() / 60. +
2022 tmp.second() / 3600. ) );
2023 tmp = KOPrefs::instance()->mWorkingHoursEnd.time();
2024 mWorkingHoursYBottom = int( 4 * mGridSpacingY *
2025 ( tmp.hour() + tmp.minute() / 60. +
2026 tmp.second() / 3600. ) - 1 );
2030 DateList KOAgenda::dateList()
const
2032 return mSelectedDates;
2035 void KOAgenda::setDateList(
const DateList &selectedDates)
2037 mSelectedDates = selectedDates;
2041 void KOAgenda::setHolidayMask(TQMemArray<bool> *mask)
2043 mHolidayMask = mask;
2047 void KOAgenda::contentsMousePressEvent ( TQMouseEvent *event )
2049 kdDebug(5850) <<
"KOagenda::contentsMousePressEvent(): type: " <<
event->type() << endl;
2050 TQScrollView::contentsMousePressEvent(event);
2053 void KOAgenda::setTypeAheadReceiver( TQObject *o )
2055 mTypeAheadReceiver = o;
2058 TQObject *KOAgenda::typeAheadReceiver()
const
2060 return mTypeAheadReceiver;
This is the main calendar widget.
virtual bool accept(Visitor &)
virtual Incidence * clone()=0