summaryrefslogtreecommitdiffstats
path: root/korganizer/datenavigator.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-01 00:37:02 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-01 00:37:02 +0000
commitcc29364f06178f8f6b457384f2ec37a042bd9d43 (patch)
tree7c77a3184c698bbf9d98cef09fb1ba8124daceba /korganizer/datenavigator.cpp
parent4f6c584bacc8c3c694228f36ada3de77a76614a6 (diff)
downloadtdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.tar.gz
tdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.zip
* Massive set of changes to bring in all fixes and enhancements from the Enterprise PIM branch
* Ensured that the Trinity changes were applied on top of those enhancements, and any redundancy removed * Added journal read support to the CalDAV resource * Fixed CalDAV resource to use events URL for tasks and journals when separate URL checkbox unchecked git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1170461 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'korganizer/datenavigator.cpp')
-rw-r--r--korganizer/datenavigator.cpp124
1 files changed, 92 insertions, 32 deletions
diff --git a/korganizer/datenavigator.cpp b/korganizer/datenavigator.cpp
index 6f5570a10..edc036ce4 100644
--- a/korganizer/datenavigator.cpp
+++ b/korganizer/datenavigator.cpp
@@ -54,11 +54,11 @@ int DateNavigator::datesCount() const
return mSelectedDates.count();
}
-void DateNavigator::selectDates( const DateList& dateList )
+void DateNavigator::selectDates( const DateList &dateList )
{
- if (dateList.count() > 0) {
+ if ( dateList.count() > 0 ) {
mSelectedDates = dateList;
-
+
emitSelected();
}
}
@@ -83,26 +83,33 @@ void DateNavigator::selectDates( int count )
selectDates( mSelectedDates.first(), count );
}
-void DateNavigator::selectDates( const TQDate &d, int count )
+void DateNavigator::selectDates( const TQDate &d, int count, const TQDate &preferredMonth )
{
+ if ( count > MAX_SELECTABLE_DAYS ) {
+ count = MAX_SELECTABLE_DAYS;
+ }
+
DateList dates;
int i;
for( i = 0; i < count; ++i ) {
dates.append( d.addDays( i ) );
}
-
+
mSelectedDates = dates;
-
- emitSelected();
+
+ emitSelected( preferredMonth );
}
-void DateNavigator::selectWeekByDay( int weekDay, const TQDate &d )
+void DateNavigator::selectWeekByDay( int weekDay, const TQDate &d, const TQDate &preferredMonth )
{
int dateCount = mSelectedDates.count();
bool weekStart = ( weekDay == KGlobal::locale()->weekStartDay() );
- if ( weekStart && dateCount == 7 ) selectWeek( d );
- else selectDates( d, dateCount );
+ if ( weekStart && dateCount == 7 ) {
+ selectWeek( d, preferredMonth );
+ } else {
+ selectDates( d, dateCount, preferredMonth );
+ }
}
void DateNavigator::selectWeek()
@@ -110,7 +117,7 @@ void DateNavigator::selectWeek()
selectWeek( mSelectedDates.first() );
}
-void DateNavigator::selectWeek( const TQDate &d )
+void DateNavigator::selectWeek( const TQDate &d, const TQDate &preferredMonth )
{
int dayOfWeek = KOGlobals::self()->calendarSystem()->dayOfWeek( d );
@@ -122,7 +129,7 @@ void DateNavigator::selectWeek( const TQDate &d )
firstDate = firstDate.addDays( -7 );
}
- selectDates( firstDate, 7 );
+ selectDates( firstDate, 7, preferredMonth );
}
void DateNavigator::selectWorkWeek()
@@ -133,7 +140,7 @@ void DateNavigator::selectWorkWeek()
void DateNavigator::selectWorkWeek( const TQDate &d )
{
int weekStart = KGlobal::locale()->weekStartDay();
-
+
int dayOfWeek = KOGlobals::self()->calendarSystem()->dayOfWeek( d );
TQDate currentDate = d.addDays( weekStart - dayOfWeek );
@@ -147,10 +154,10 @@ void DateNavigator::selectWorkWeek( const TQDate &d )
for ( int i = 0; i < 7; ++i ) {
if( (1<< ((i + weekStart + 6) % 7)) & (mask) ) {
- mSelectedDates.append(currentDate.addDays(i));
+ mSelectedDates.append( currentDate.addDays(i) );
}
}
-
+
emitSelected();
}
@@ -160,8 +167,13 @@ void DateNavigator::selectToday()
int dateCount = mSelectedDates.count();
- if ( dateCount == 7 ) selectWeek( d );
- else selectDates( d, dateCount );
+ if ( dateCount == 7 ) {
+ selectWeek( d );
+ } else if ( dateCount == 5 ) {
+ selectWorkWeek( d );
+ } else {
+ selectDates( d, dateCount );
+ }
}
void DateNavigator::selectPreviousYear()
@@ -173,13 +185,14 @@ void DateNavigator::selectPreviousYear()
selectWeekByDay( weekDay, firstSelected );
}
-void DateNavigator::selectPreviousMonth()
+void DateNavigator::selectPreviousMonth( const TQDate &currentMonth,
+ const TQDate &selectionLowerLimit,
+ const TQDate &selectionUpperLimit )
{
- TQDate firstSelected = mSelectedDates.first();
- int weekDay = firstSelected.dayOfWeek();
- firstSelected = KOGlobals::self()->calendarSystem()->addMonths( firstSelected, -1 );
-
- selectWeekByDay( weekDay, firstSelected );
+ shiftMonth( currentMonth,
+ selectionLowerLimit,
+ selectionUpperLimit,
+ -1 );
}
void DateNavigator::selectPreviousWeek()
@@ -201,14 +214,46 @@ void DateNavigator::selectNextWeek()
selectWeekByDay( weekDay, firstSelected );
}
-void DateNavigator::selectNextMonth()
+void DateNavigator::shiftMonth( const TQDate &currentMonth,
+ const TQDate &selectionLowerLimit,
+ const TQDate &selectionUpperLimit,
+ int offset )
{
+ const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
+
TQDate firstSelected = mSelectedDates.first();
int weekDay = firstSelected.dayOfWeek();
+ firstSelected = calSys->addMonths( firstSelected, offset );
+
+ /* Don't trust firstSelected to calculate the nextMonth. firstSelected
+ can belong to a month other than currentMonth because KDateNavigator
+ displays 7*6 days. firstSelected should only be used for selection
+ purposes */
+ const TQDate nextMonth = currentMonth.isValid() ?
+ calSys->addMonths( currentMonth, offset ) : firstSelected;
+
+ /* When firstSelected doesn't belong to currentMonth it can happen
+ that the new selection won't be visible on our KDateNavigators
+ so we must adjust it */
+ if ( selectionLowerLimit.isValid() &&
+ firstSelected < selectionLowerLimit ) {
+ firstSelected = selectionLowerLimit;
+ } else if ( selectionUpperLimit.isValid() &&
+ firstSelected > selectionUpperLimit ) {
+ firstSelected = selectionUpperLimit.addDays( -6 );
+ }
- firstSelected = KOGlobals::self()->calendarSystem()->addMonths( firstSelected, 1 );
+ selectWeekByDay( weekDay, firstSelected, nextMonth );
+}
- selectWeekByDay( weekDay, firstSelected );
+void DateNavigator::selectNextMonth( const TQDate &currentMonth,
+ const TQDate &selectionLowerLimit,
+ const TQDate &selectionUpperLimit )
+{
+ shiftMonth( currentMonth,
+ selectionLowerLimit,
+ selectionUpperLimit,
+ 1 );
}
void DateNavigator::selectNextYear()
@@ -240,26 +285,41 @@ void DateNavigator::selectNext()
selectDates( mSelectedDates.first().addDays( offset ), datesCount() );
}
-void DateNavigator::selectMonth(int month)
+void DateNavigator::selectMonth( int month )
{
+ const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
+
TQDate firstSelected = mSelectedDates.first();
int weekDay = firstSelected.dayOfWeek();
- const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
int day = calSys->day( firstSelected );
- calSys->setYMD( firstSelected, calSys->year(firstSelected), month, 1 );
+ calSys->setYMD( firstSelected, calSys->year( firstSelected ), month, 1 );
int days = calSys->daysInMonth( firstSelected );
// As day we use either the selected date, or if the month has less days
// than that, we use the max day of that month
- if ( day > days ) day = days;
+ if ( day > days ) {
+ day = days;
+ }
+ TQDate requestedMonth;
calSys->setYMD( firstSelected, calSys->year( firstSelected ), month, day );
+ calSys->setYMD( requestedMonth, calSys->year( firstSelected ), month, 1 );
+
+ selectWeekByDay( weekDay, firstSelected, requestedMonth );
+}
+void DateNavigator::selectYear( int year )
+{
+ TQDate firstSelected = mSelectedDates.first();
+ int deltaYear = year - KOGlobals::self()->calendarSystem()->year( firstSelected );
+ firstSelected = KOGlobals::self()->calendarSystem()->addYears( firstSelected, deltaYear );
+
+ int weekDay = firstSelected.dayOfWeek();
selectWeekByDay( weekDay, firstSelected );
}
-void DateNavigator::emitSelected()
+void DateNavigator::emitSelected( const TQDate &preferredMonth )
{
- emit datesSelected( mSelectedDates );
+ emit datesSelected( mSelectedDates, preferredMonth );
}
#include "datenavigator.moc"