author | paule <paule> | 2007-01-31 09:30:53 (UTC) |
---|---|---|
committer | paule <paule> | 2007-01-31 09:30:53 (UTC) |
commit | 6b321230cf24e50b11783b3511a457f22ae79a58 (patch) (side-by-side diff) | |
tree | 9d04ba6204bdc7be6b9e4ee2645b00d56a9c6f77 | |
parent | e9c5c237e27d908c890779215b19c22a3706b614 (diff) | |
download | opie-6b321230cf24e50b11783b3511a457f22ae79a58.zip opie-6b321230cf24e50b11783b3511a457f22ae79a58.tar.gz opie-6b321230cf24e50b11783b3511a457f22ae79a58.tar.bz2 |
Show events on all visible days in the month view, not just those within the current month. Fixes bug #1351.
-rw-r--r-- | core/pim/datebook/modules/monthview/odatebookmonth.cpp | 60 | ||||
-rw-r--r-- | core/pim/datebook/modules/monthview/odatebookmonth.h | 2 |
2 files changed, 45 insertions, 17 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 @@ -132,165 +132,191 @@ void ODateBookMonthTable::setWeekStart( bool onMonday ) void ODateBookMonthTable::setupTable() { QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday ); QValueList<Calendar::Day>::Iterator it = days.begin(); int row = 0, col = 0; int crow = 0; int ccol = 0; for ( ; it != days.end(); ++it ) { DayItemMonth *i = (DayItemMonth *)item( row, col ); if ( !i ) { i = new DayItemMonth( this, QTableItem::Never, "" ); setItem( row, col, i ); } Calendar::Day calDay = *it; i->clearEffEvents(); i->setDay( calDay.date ); i->setType( calDay.type ); if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) { crow = row; ccol = col; } updateCell( row, col ); if ( col == 6 ) { ++row; col = 0; } else { ++col; } } setCurrentCell( crow, ccol ); getEvents(); } void ODateBookMonthTable::findDay( int day, int &row, int &col ) { QDate dtBegin( year, month, 1 ); int skips = dtBegin.dayOfWeek(); int effective_day = day + skips - 1; // row/columns begin at 0 // make an extra adjustment if we start on Mondays. 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 ); } 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--; } - selDay = i->day(); + else if ( itemMonth > 12 ) { + itemMonth = 1; + itemYear++; } + 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; 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 ); + findDate( e.date(), row, col ); DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) ); w->setEvents( dayEvent ); updateCell( row, col ); dayEvent.clear(); } } void ODateBookMonthTable::setupLabels() { for ( int i = 0; i < 7; ++i ) { // horizontalHeader()->resizeSection( i, 30 ); // setColumnStretchable( i, TRUE ); if ( d->onMonday ) horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) ); else { if ( i == 0 ) horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) ); else horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) ); } } } //--------------------------------------------------------------------------- ODateBookMonth::ODateBookMonth( QWidget *parent, const char *name, bool ac, DateBookDBHoliday *data ) : QVBox( parent, name ), autoClose( ac ) { setFocusPolicy(StrongFocus); year = QDate::currentDate().year(); month = QDate::currentDate().month(); day = QDate::currentDate().day(); header = new DateBookMonthHeader( this, "DateBookMonthHeader" ); table = new ODateBookMonthTable( this, "DateBookMonthTable", data ); header->setDate( year, month ); table->setDate( year, month, QDate::currentDate().day() ); header->setFocusPolicy(NoFocus); table->setFocusPolicy(NoFocus); connect( header, SIGNAL( dateChanged(int,int) ), this, SLOT( setDate(int,int) ) ); connect( table, SIGNAL( dateClicked(int,int,int) ), this, SLOT( finalDate(int,int,int) ) ); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChange(bool)) ); 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 @@ -36,97 +36,99 @@ #include <qpe/calendar.h> #include <qpe/timestring.h> class QToolButton; class QComboBox; class QSpinBox; class Event; class DateBookDB; class DateBookDBHoliday; class ODateBookMonthTablePrivate; class ODateBookMonthTable : public QTable { Q_OBJECT public: ODateBookMonthTable( QWidget *parent = 0, const char *name = 0, DateBookDBHoliday *newDb = 0 ); virtual ~ODateBookMonthTable(); void setDate( int y, int m, int d ); void redraw(); QSize minimumSizeHint() const { return sizeHint(); } QSize minimumSize() const { return sizeHint(); } void getDate( int& y, int &m, int &d ) const {y=selYear;m=selMonth;d=selDay;} void setWeekStart( bool onMonday ); signals: void dateClicked( int year, int month, int day ); protected: virtual void viewportMouseReleaseEvent( QMouseEvent * ); protected slots: virtual void keyPressEvent(QKeyEvent *e ) { e->ignore(); } private slots: void dayClicked( int row, int col ); void dragDay( int row, int col ); 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; }; class ODateBookMonthPrivate; class ODateBookMonth : public QVBox { Q_OBJECT public: /* ac = Auto Close */ ODateBookMonth( QWidget *parent = 0, const char *name = 0, bool ac = FALSE, DateBookDBHoliday *data = 0 ); virtual ~ODateBookMonth(); QDate selectedDate() const; signals: /* ### FIXME add a signal with QDate -zecke */ void dateClicked( int year, int month, int day ); public slots: void setDate( int y, int m ); void setDate( int y, int m, int d ); void setDate( QDate ); void redraw(); void slotWeekChange( bool ); protected slots: virtual void keyPressEvent(QKeyEvent *e); private slots: void forwardDateClicked( int y, int m, int d ) { emit dateClicked( y, m, d ); } void finalDate(int, int, int); private: DateBookMonthHeader *header; ODateBookMonthTable *table; int year, month, day; bool autoClose; class ODateBookMonthPrivate *d; }; #endif |