Re: [PATCH] datebook: show events on all days in month view
Dmitriy Korovkin <[email protected]> Wed, 03 Jan 2007 14:51:49 +0300
| Newsgroups | gmane.comp.handhelds.opie.devel |
|---|---|
| Message-ID | <[email protected]> |
Dear Colleagues,
Will someone familiar with PIM review this patch?
Thanks in advance,
Dmitriy
Paul Eggleton wrote:
> Hi there,
>
> The attached patch makes the datebook month view show events on all days
> including the extra days from the previous/next month. It also prevents the
> events from being refreshed twice.
>
> This fixes bug #1351 (http://opie-bugs.oszine.de/view.php?id=1351).
>
> Cheers,
> Paul
>
> ------------------------------------------------------------------------
>
> Index: odatebookmonth.cpp
> ===================================================================
> RCS file: /cvs/opie/core/pim/datebook/modules/monthview/odatebookmonth.cpp,v
> retrieving revision 1.2
> diff -u -r1.2 odatebookmonth.cpp
> --- odatebookmonth.cpp 15 Jun 2005 19:45:55 -0000 1.2
> +++ odatebookmonth.cpp 29 Dec 2006 08:32:25 -0000
> @@ -177,6 +177,22 @@
> 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 );
> @@ -190,32 +206,43 @@
>
> void ODateBookMonthTable::changeDaySelection( int row, int col )
> {
> - DayItemMonth *i = (DayItemMonth*)item( row, col );
> - if ( !i )
> - return;
> - switch ( i->type() ) {
> - case Calendar::Day::ThisMonth:
> - selMonth = month;
> - break;
> - case Calendar::Day::PrevMonth:
> - selMonth = month-1;
> - break;
> - default:
> - selMonth = month+1;
> - }
> -
> - selYear = year;
> - if ( selMonth <= 0 ) {
> - selMonth = 12;
> - selYear--;
> - } else if ( selMonth > 12 ) {
> - selMonth = 1;
> - selYear++;
> - }
> - selDay = i->day();
> + 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 QDate(1900, 1, 1);
> + switch ( i->type() ) {
> + case Calendar::Day::ThisMonth:
> + itemMonth = month;
> + break;
> + case Calendar::Day::PrevMonth:
> + itemMonth = month-1;
> + break;
> + default:
> + itemMonth = month+1;
> + }
> +
> + itemYear = year;
> + if ( itemMonth <= 0 ) {
> + itemMonth = 12;
> + itemYear--;
> + }
> + else if ( itemMonth > 12 ) {
> + itemMonth = 1;
> + itemYear++;
> + }
> +
> + return QDate( itemYear, itemMonth, i->day());
> }
>
> -
> void ODateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * )
> {
> dayClicked( currentRow(), currentColumn() );
> @@ -223,34 +250,33 @@
>
> void ODateBookMonthTable::getEvents()
> {
> - if ( !db )
> - return;
> -
> - QDate dtStart( year, month, 1 );
> - d->mMonthEvents = db->getEffectiveEvents( dtStart,
> - QDate( year, month,
> - dtStart.daysInMonth() ) );
> - 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;
> - EffectiveEvent e = *it;
> - ++it;
> - dayEvent.append( e );
> - while ( it != d->mMonthEvents.end()
> - && e.date() == (*it).date() ) {
> - dayEvent.append( *it );
> - ++it;
> - }
> - int row, col;
> - findDay( e.date().day(), row, col );
> - DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) );
> - w->setEvents( dayEvent );
> - updateCell( row, col );
> - dayEvent.clear();
> - }
> + if ( !db )
> + return;
> +
> + 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;
> + EffectiveEvent e = *it;
> + ++it;
> + dayEvent.append( e );
> + while ( it != d->mMonthEvents.end()
> + && e.date() == (*it).date() ) {
> + dayEvent.append( *it );
> + ++it;
> + }
> + int row, col;
> + findDate( e.date(), row, col );
> + DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) );
> + w->setEvents( dayEvent );
> + updateCell( row, col );
> + dayEvent.clear();
> + }
> }
>
>
> @@ -345,7 +371,9 @@
> void ODateBookMonth::redraw()
> {
> table->setDate( year, month, day );
> - table->redraw();
> + // table->setDate already calls setupTable, which is all that
> + // redraw will do here that's useful - bluelightning
> + //table->redraw();
> }
>
> QDate ODateBookMonth::selectedDate() const
> Index: odatebookmonth.h
> ===================================================================
> RCS file: /cvs/opie/core/pim/datebook/modules/monthview/odatebookmonth.h,v
> retrieving revision 1.1
> diff -u -r1.1 odatebookmonth.h
> --- odatebookmonth.h 20 Mar 2005 10:51:55 -0000 1.1
> +++ odatebookmonth.h 29 Dec 2006 08:32:26 -0000
> @@ -81,8 +81,10 @@
> 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;
>
> ------------------------------------------------------------------------
>
> _______________________________________________
>
> http://opie.handhelds.org/cgi-bin/moin.cgi/DeveloperWikiIndex
>
> Opie-devel mailing list
> [email protected]
> https://handhelds.org/mailman/listinfo/opie-devel
>
_______________________________________________
http://opie.handhelds.org/cgi-bin/moin.cgi/DeveloperWikiIndex
Opie-devel mailing list
[email protected]
https://handhelds.org/mailman/listinfo/opie-devel