46
50
#include <QToolTip>
49
#include "kodialogmanager.h"
51
#include <kcal/resourcecalendar.h>
54
#include <kstandardaction.h>
57
#include <kiconloader.h>
61
#include <QApplication>
62
#include <QDragLeaveEvent>
63
#include <QPaintEvent>
64
#include <QDragMoveEvent>
67
#include <QResizeEvent>
68
#include <QDragEnterEvent>
72
52
// ============================================================================
73
53
// K O D A Y M A T R I X
74
54
// ============================================================================
56
using namespace KCalCore;
57
using namespace KCalUtils;
76
59
const int KODayMatrix::NOSELECTION = -1000;
77
60
const int KODayMatrix::NUMDAYS = 42;
104
87
mCalendar->registerObserver( this );
105
CalendarResources *calres = dynamic_cast<CalendarResources*>( cal );
107
connect( calres, SIGNAL(signalResourceAdded(ResourceCalendar *)),
108
SLOT(resourcesChanged()) );
109
connect( calres, SIGNAL(signalResourceModified(ResourceCalendar *)),
110
SLOT(resourcesChanged()) );
111
connect( calres, SIGNAL(signalResourceDeleted(ResourceCalendar *)),
112
SLOT(resourcesChanged()) );
115
89
setAcceptDrops( mCalendar != 0 );
116
90
updateIncidences();
261
235
// there's no need to update the whole list of incidences... This is just a
262
236
// waste of computational power
263
237
updateIncidences();
238
QMap<QDate,QStringList> holidaysByDate = KOGlobals::self()->holiday( mDays[0], mDays[NUMDAYS-1] );
264
239
for ( int i = 0; i < NUMDAYS; i++ ) {
265
240
//if it is a holy day then draw it red. Sundays are consider holidays, too
266
QStringList holidays = KOGlobals::self()->holiday( mDays[i] );
241
QStringList holidays = holidaysByDate[mDays[i]];
269
244
if ( ( KOGlobals::self()->calendarSystem()->dayOfWeek( mDays[i] ) ==
270
KOGlobals::self()->calendarSystem()->weekDayOfPray() ) ||
245
KGlobal::locale()->weekDayOfPray() ) ||
271
246
!holidays.isEmpty() ) {
272
247
if ( !holidays.isEmpty() ) {
273
248
holiStr = holidays.join( i18nc( "delimiter for joining holiday names", "," ) );
306
281
void KODayMatrix::updateJournals()
308
Incidence::List incidences = mCalendar->incidences();
283
const Akonadi::Item::List items = mCalendar->incidences();
310
foreach ( Incidence *inc, incidences ) {
285
foreach ( const Akonadi::Item & item, items ) {
286
Incidence::Ptr inc = CalendarSupport::incidence( item );
311
288
QDate d = inc->dtStart().toTimeSpec( mCalendar->timeSpec() ).date();
312
if ( inc->type() == "Journal" &&
289
if ( inc->type() == Incidence::TypeJournal &&
314
291
d <= mDays[NUMDAYS-1] &&
315
292
!mEvents.contains( d ) ) {
316
293
mEvents.append( d );
295
if ( mEvents.count() == NUMDAYS ) {
296
// No point in wasting cpu, all days are bold already
330
311
void KODayMatrix::updateTodos()
332
Incidence::List incidences = mCalendar->incidences();
313
const Akonadi::Item::List items = mCalendar->todos();
334
foreach ( Incidence *inc, incidences ) {
335
if ( inc->type() == "Todo" ) {
336
Todo *t = static_cast<Todo *>( inc );
337
if ( t->hasDueDate() ) {
338
ushort recurType = t->recurrenceType();
341
!( recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur ) &&
342
!( recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur ) ) {
344
// It's a recurring todo, find out in which days it occurs
345
DateTimeList timeDateList = t->recurrence()->timesInInterval(
346
KDateTime( mDays[0], mCalendar->timeSpec() ),
347
KDateTime( mDays[NUMDAYS-1], mCalendar->timeSpec() ) );
349
foreach ( const KDateTime &dt, timeDateList ) {
350
d = dt.toTimeSpec( mCalendar->timeSpec() ).date();
351
if ( !mEvents.contains( d ) ) {
357
d = t->dtDue().toTimeSpec( mCalendar->timeSpec() ).date();
358
if ( d >= mDays[0] && d <= mDays[NUMDAYS-1] && !mEvents.contains( d ) ) {
315
foreach ( const Akonadi::Item &item, items ) {
316
if ( mEvents.count() == NUMDAYS ) {
317
// No point in wasting cpu, all days are bold already
320
const Todo::Ptr t = CalendarSupport::todo( item );
322
if ( t->hasDueDate() ) {
323
ushort recurType = t->recurrenceType();
326
!( recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur ) &&
327
!( recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur ) ) {
329
// It's a recurring todo, find out in which days it occurs
330
DateTimeList timeDateList = t->recurrence()->timesInInterval(
331
KDateTime( mDays[0], mCalendar->timeSpec() ),
332
KDateTime( mDays[NUMDAYS-1], mCalendar->timeSpec() ) );
334
foreach ( const KDateTime &dt, timeDateList ) {
335
d = dt.toTimeSpec( mCalendar->timeSpec() ).date();
336
if ( !mEvents.contains( d ) ) {
359
337
mEvents.append( d );
342
d = t->dtDue().toTimeSpec( mCalendar->timeSpec() ).date();
343
if ( d >= mDays[0] && d <= mDays[NUMDAYS-1] && !mEvents.contains( d ) ) {
367
351
void KODayMatrix::updateEvents()
369
Event::List eventlist = mCalendar->events( mDays[0], mDays[NUMDAYS-1],
370
mCalendar->timeSpec() );
372
Event::List::ConstIterator it;
374
for ( it=eventlist.constBegin(); it != eventlist.constEnd(); ++it ) {
376
ushort recurType = event->recurrenceType();
378
KDateTime dtStart = event->dtStart().toTimeSpec( mCalendar->timeSpec() );
379
KDateTime dtEnd = event->dtEnd().toTimeSpec( mCalendar->timeSpec() );
353
if ( mEvents.count() == NUMDAYS ) {
354
mPendingChanges = false;
355
// No point in wasting cpu, all days are bold already
358
Akonadi::Item::List eventlist = mCalendar->events( mDays[0], mDays[NUMDAYS-1],
359
mCalendar->timeSpec() );
361
Q_FOREACH ( const Akonadi::Item & item, eventlist ) {
362
if ( mEvents.count() == NUMDAYS ) {
363
// No point in wasting cpu, all days are bold already
366
const Event::Ptr event = CalendarSupport::event( item );
368
const ushort recurType = event->recurrenceType();
370
const KDateTime dtStart = event->dtStart().toTimeSpec( mCalendar->timeSpec() );
372
// timed incidences occur in [dtStart(), dtEnd()[. All-day incidences occur in [dtStart(), dtEnd()]
373
// so we subtract 1 second in the timed case
374
const int secsToAdd = event->allDay() ? 0 : -1;
375
const KDateTime dtEnd = event->dtEnd().toTimeSpec( mCalendar->timeSpec() ).addSecs( secsToAdd );
381
377
if ( !( recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur ) &&
382
378
!( recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur ) ) {
384
380
DateTimeList timeDateList;
385
bool isRecurrent = event->recurs();
386
int eventDuration = dtStart.daysTo( dtEnd );
381
const bool isRecurrent = event->recurs();
382
const int eventDuration = dtStart.daysTo( dtEnd );
388
384
if ( isRecurrent ) {
389
385
//Its a recurring event, find out in which days it occurs
668
DndFactory factory( mCalendar );
669
Event *event = factory.createDropEvent( e );
670
Todo *todo = factory.createDropTodo( e );
671
if ( !event && !todo ) {
662
QList<QUrl> urls = ( e->mimeData()->urls() );
663
//kDebug()<<" urls :"<<urls;
664
if ( urls.isEmpty() ) {
676
Todo *existingTodo = 0;
677
Event *existingEvent = 0;
679
// Find the incidence in the calendar, then we don't need the drag object any more
681
existingEvent = mCalendar->event( event->uid() );
684
existingTodo = mCalendar->todo( todo->uid() );
687
int action = DRAG_CANCEL;
689
Qt::KeyboardModifiers keyboardModifiers = e->keyboardModifiers();
691
if ( keyboardModifiers & Qt::ControlModifier ) {
693
} else if ( keyboardModifiers & Qt::ShiftModifier ) {
696
QAction *copy = 0, *move = 0, *cancel = 0;
697
KMenu *menu = new KMenu( this );
698
if ( existingEvent || existingTodo ) {
699
move = menu->addAction( KOGlobals::self()->smallIcon( "edit-paste" ), i18n( "&Move" ) );
700
if ( existingEvent ) {
701
copy = menu->addAction( KOGlobals::self()->smallIcon( "edit-copy" ), i18n( "&Copy" ) );
704
move = menu->addAction( KOGlobals::self()->smallIcon( "list-add" ), i18n( "&Add" ) );
669
//For the moment support 1 url
670
if ( urls.count() >= 1 ) {
671
KUrl res = urls.at( 0 );
673
Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( Akonadi::Item::fromUrl( res ) );
674
job->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
675
job->fetchScope().fetchFullPayload();
676
Akonadi::Item::List items;
678
items = job->items();
706
menu->addSeparator();
707
cancel = menu->addAction( KOGlobals::self()->smallIcon( "process-stop" ), i18n( "&Cancel" ) );
708
QAction *a = menu->exec( QCursor::pos() );
680
bool exist = items.at( 0 ).isValid();
681
int action = DRAG_CANCEL;
683
Qt::KeyboardModifiers keyboardModifiers = e->keyboardModifiers();
685
if ( keyboardModifiers & Qt::ControlModifier ) {
710
686
action = DRAG_COPY;
711
} else if ( a == move ) {
687
} else if ( keyboardModifiers & Qt::ShiftModifier ) {
712
688
action = DRAG_MOVE;
716
if ( action == DRAG_COPY || action == DRAG_MOVE ) {
718
int idx = getDayIndexFrom( e->pos().x(), e->pos().y() );
720
if ( action == DRAG_COPY ) {
722
emit incidenceDropped( event, mDays[idx] );
725
emit incidenceDropped( todo, mDays[idx] );
727
} else if ( action == DRAG_MOVE ) {
729
emit incidenceDroppedMove( event, mDays[idx] );
732
emit incidenceDroppedMove( todo, mDays[idx] );
690
QAction *copy = 0, *move = 0, *cancel = 0;
691
KMenu *menu = new KMenu( this );
693
move = menu->addAction( KOGlobals::self()->smallIcon( "edit-paste" ), i18n( "&Move" ) );
694
if ( /*existingEvent*/1 ) {
695
copy = menu->addAction( KOGlobals::self()->smallIcon( "edit-copy" ), i18n( "&Copy" ) );
698
move = menu->addAction( KOGlobals::self()->smallIcon( "list-add" ), i18n( "&Add" ) );
700
menu->addSeparator();
701
cancel = menu->addAction( KOGlobals::self()->smallIcon( "process-stop" ), i18n( "&Cancel" ) );
702
QAction *a = menu->exec( QCursor::pos() );
705
} else if ( a == move ) {
710
if ( action == DRAG_COPY || action == DRAG_MOVE ) {
712
int idx = getDayIndexFrom( e->pos().x(), e->pos().y() );
714
if ( action == DRAG_COPY ) {
715
emit incidenceDropped( items.at( 0 ), mDays[idx] );
716
} else if ( action == DRAG_MOVE ) {
717
emit incidenceDroppedMove( items.at( 0 ), mDays[idx] );
908
893
mDaySize.setWidth( sz.width() / 7 );
897
QPair<QDate,QDate> KODayMatrix::matrixLimits( const QDate &month )
899
const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
901
calSys->setYMD( d, calSys->year( month ), calSys->month( month ), 1 );
903
const int dayOfWeek = calSys->dayOfWeek( d );
904
const int weekstart = KGlobal::locale()->weekStartDay();
906
d = d.addDays( -( 7 + dayOfWeek - weekstart ) % 7 );
908
if ( dayOfWeek == weekstart ) {
909
d = d.addDays( -7 ); // Start on the second line
912
return qMakePair( d, d.addDays( NUMDAYS-1 ) );
911
916
#include "kodaymatrix.moc"