summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/modules/monthview/odatebookmonth.cpp62
-rw-r--r--core/pim/datebook/modules/monthview/odatebookmonth.h2
2 files changed, 46 insertions, 18 deletions
diff --git a/core/pim/datebook/modules/monthview/odatebookmonth.cpp b/core/pim/datebook/modules/monthview/odatebookmonth.cpp
index d52a092..e4de279 100644
--- a/core/pim/datebook/modules/monthview/odatebookmonth.cpp
+++ b/core/pim/datebook/modules/monthview/odatebookmonth.cpp
@@ -174,12 +174,28 @@ void ODateBookMonthTable::findDay( int day, int &row, int &col )
if ( d->onMonday )
effective_day--;
row = effective_day / 7;
col = effective_day % 7;
}
+bool ODateBookMonthTable::findDate( QDate date, int &row, int &col )
+{
+ int rows = numRows();
+ int cols = numCols();
+ for(int r=0;r<rows;r++) {
+ for(int c=0;c<cols;c++) {
+ if(getDateAt(r, c) == date) {
+ row = r;
+ col = c;
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
void ODateBookMonthTable::dayClicked( int row, int col )
{
changeDaySelection( row, col );
emit dateClicked( selYear, selMonth, selDay );
}
@@ -187,52 +203,62 @@ void ODateBookMonthTable::dragDay( int row, int col )
{
changeDaySelection( row, col );
}
void ODateBookMonthTable::changeDaySelection( int row, int col )
{
+ QDate selDate = getDateAt( row, col );
+ selYear = selDate.year();
+ selMonth = selDate.month();
+ selDay = selDate.day();
+}
+
+QDate ODateBookMonthTable::getDateAt( int row, int col )
+{
+ int itemMonth, itemYear;
+
DayItemMonth *i = (DayItemMonth*)item( row, col );
if ( !i )
- return;
+ return QDate(1900, 1, 1);
switch ( i->type() ) {
case Calendar::Day::ThisMonth:
- selMonth = month;
+ itemMonth = month;
break;
case Calendar::Day::PrevMonth:
- selMonth = month-1;
+ itemMonth = month-1;
break;
default:
- selMonth = month+1;
+ itemMonth = month+1;
}
- selYear = year;
- if ( selMonth <= 0 ) {
- selMonth = 12;
- selYear--;
- } else if ( selMonth > 12 ) {
- selMonth = 1;
- selYear++;
+ itemYear = year;
+ if ( itemMonth <= 0 ) {
+ itemMonth = 12;
+ itemYear--;
+ }
+ else if ( itemMonth > 12 ) {
+ itemMonth = 1;
+ itemYear++;
}
- selDay = i->day();
-}
+ return QDate( itemYear, itemMonth, i->day());
+}
void ODateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * )
{
dayClicked( currentRow(), currentColumn() );
}
void ODateBookMonthTable::getEvents()
{
if ( !db )
return;
- QDate dtStart( year, month, 1 );
- d->mMonthEvents = db->getEffectiveEvents( dtStart,
- QDate( year, month,
- dtStart.daysInMonth() ) );
+ QDate dtStart = getDateAt(0,0);
+ QDate dtEnd = getDateAt(numRows()-1, numCols()-1);
+ d->mMonthEvents = db->getEffectiveEvents( dtStart, dtEnd);
QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin();
// now that the events are sorted, basically go through the list, make
// a small list for every day and set it for each item...
// clear all the items...
while ( it != d->mMonthEvents.end() ) {
QValueList<EffectiveEvent> dayEvent;
@@ -242,13 +268,13 @@ void ODateBookMonthTable::getEvents()
while ( it != d->mMonthEvents.end()
&& e.date() == (*it).date() ) {
dayEvent.append( *it );
++it;
}
int row, col;
- findDay( e.date().day(), row, col );
+ findDate( e.date(), row, col );
DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) );
w->setEvents( dayEvent );
updateCell( row, col );
dayEvent.clear();
}
}
diff --git a/core/pim/datebook/modules/monthview/odatebookmonth.h b/core/pim/datebook/modules/monthview/odatebookmonth.h
index e967abe..a81a161 100644
--- a/core/pim/datebook/modules/monthview/odatebookmonth.h
+++ b/core/pim/datebook/modules/monthview/odatebookmonth.h
@@ -78,14 +78,16 @@ private slots:
private:
void setupTable();
void setupLabels();
void findDay( int day, int &row, int &col );
+ bool findDate( QDate date, int &row, int &col );
void getEvents();
void changeDaySelection( int row, int col );
+ QDate getDateAt( int row, int col );
int year, month, day;
int selYear, selMonth, selDay;
QValueList<Event> monthsEvents; // not used anymore...
DateBookDBHoliday *db;
ODateBookMonthTablePrivate *d;