summaryrefslogtreecommitdiff
path: root/library/datebookmonth.cpp
Side-by-side diff
Diffstat (limited to 'library/datebookmonth.cpp') (more/less context) (show whitespace changes)
-rw-r--r--library/datebookmonth.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp
index e8be313..728045f 100644
--- a/library/datebookmonth.cpp
+++ b/library/datebookmonth.cpp
@@ -43,256 +43,261 @@ DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
begin = new QToolButton( this );
begin->setFocusPolicy(NoFocus);
begin->setPixmap( Resource::loadPixmap( "start" ) );
begin->setAutoRaise( TRUE );
begin->setFixedSize( begin->sizeHint() );
QWhatsThis::add( begin, tr("Show January in the selected year") );
back = new QToolButton( this );
back->setFocusPolicy(NoFocus);
back->setPixmap( Resource::loadPixmap( "back" ) );
back->setAutoRaise( TRUE );
back->setFixedSize( back->sizeHint() );
QWhatsThis::add( back, tr("Show the previous month") );
month = new QComboBox( FALSE, this );
for ( int i = 0; i < 12; ++i )
month->insertItem( Calendar::nameOfMonth( i + 1 ) );
year = new QSpinBox( 1752, 8000, 1, this );
next = new QToolButton( this );
next->setFocusPolicy(NoFocus);
next->setPixmap( Resource::loadPixmap( "forward" ) );
next->setAutoRaise( TRUE );
next->setFixedSize( next->sizeHint() );
QWhatsThis::add( next, tr("Show the next month") );
end = new QToolButton( this );
end->setFocusPolicy(NoFocus);
end->setPixmap( Resource::loadPixmap( "finish" ) );
end->setAutoRaise( TRUE );
end->setFixedSize( end->sizeHint() );
QWhatsThis::add( end, tr("Show December in the selected year") );
connect( month, SIGNAL( activated( int ) ),
this, SLOT( updateDate() ) );
connect( year, SIGNAL( valueChanged( int ) ),
this, SLOT( updateDate() ) );
connect( begin, SIGNAL( clicked() ),
this, SLOT( firstMonth() ) );
connect( end, SIGNAL( clicked() ),
this, SLOT( lastMonth() ) );
connect( back, SIGNAL( clicked() ),
this, SLOT( monthBack() ) );
connect( next, SIGNAL( clicked() ),
this, SLOT( monthForward() ) );
back->setAutoRepeat( TRUE );
next->setAutoRepeat( TRUE );
}
DateBookMonthHeader::~DateBookMonthHeader()
{
}
void DateBookMonthHeader::updateDate()
{
emit dateChanged( year->value(), month->currentItem() + 1 );
}
void DateBookMonthHeader::firstMonth()
{
emit dateChanged( year->value(), 1 );
month->setCurrentItem( 0 );
}
void DateBookMonthHeader::lastMonth()
{
emit dateChanged( year->value(), 12 );
month->setCurrentItem( 11 );
}
void DateBookMonthHeader::monthBack()
{
if ( month->currentItem() > 0 ) {
emit dateChanged( year->value(), month->currentItem() );
month->setCurrentItem( month->currentItem() - 1 );
} else {
emit dateChanged( year->value() - 1, 12 );
// we have a signal set to a changed value in year so we only need to change
// year to get the result...
month->setCurrentItem( 11 );
year->setValue( year->value() - 1 );
}
}
void DateBookMonthHeader::monthForward()
{
if ( month->currentItem() < 11 ) {
emit dateChanged( year->value(), month->currentItem() + 2 );
month->setCurrentItem( month->currentItem() + 1 );
} else {
// we have a signal set to a changed value in year so we only need to change
// year to get the result...
month->setCurrentItem( 0 );
year->setValue( year->value() + 1 );
}
}
void DateBookMonthHeader::setDate( int y, int m )
{
year->setValue( y );
month->setCurrentItem( m - 1 );
}
//---------------------------------------------------------------------------
class DateBookMonthTablePrivate
{
public:
DateBookMonthTablePrivate() {};
~DateBookMonthTablePrivate() { mMonthEvents.clear(); };
QValueList<EffectiveEvent> mMonthEvents;
bool onMonday;
};
DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name,
DateBookDB *newDb )
: QTable( 6, 7, parent, name ),
db( newDb )
{
d = new DateBookMonthTablePrivate();
selYear = -1;
selMonth = -1;
selDay = -1;
+ /* init these as well make valgrind happy and be consistent with Qtopia1.6 -zecke */
+ year = -1;
+ month = -1;
+ day = -1;
+
Config cfg( "qpe" );
cfg.setGroup( "Time" );
d->onMonday = cfg.readBoolEntry( "MONDAY" );
horizontalHeader()->setResizeEnabled( FALSE );
// we have to do this here... or suffer the consequences later...
for ( int i = 0; i < 7; i++ ){
horizontalHeader()->resizeSection( i, 30 );
setColumnStretchable( i, TRUE );
}
setupLabels();
verticalHeader()->hide();
setLeftMargin( 0 );
for ( int i = 0; i < 6; ++i )
setRowStretchable( i, TRUE );
setSelectionMode( NoSelection );
connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ),
this, SLOT( dayClicked( int, int ) ) );
connect( this, SIGNAL( currentChanged( int, int ) ),
this, SLOT( dragDay( int, int ) ) );
setVScrollBarMode( AlwaysOff );
setHScrollBarMode( AlwaysOff );
}
DateBookMonthTable::~DateBookMonthTable()
{
monthsEvents.clear();
delete d;
}
void DateBookMonthTable::setDate(int y, int m, int d)
{
if (month == m && year == y) {
if ( selYear == -1 )
year = selYear;
if ( selMonth == -1 )
month = selMonth;
int r1, c1, r2, c2;
findDay(selDay, r1, c1);
selDay = day = d;
findDay(selDay, r2, c2);
setCurrentCell( r2, c2 );
//updateCell(r1,c1);
//updateCell(r2,c2);
} else {
selYear = year = y;
selMonth = month = m;
selDay = day = d;
setupTable();
}
}
void DateBookMonthTable::redraw()
{
setupLabels();
setupTable();
}
void DateBookMonthTable::setWeekStart( bool onMonday )
{
d->onMonday = onMonday;
setupLabels();
setupTable();
}
void DateBookMonthTable::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 DateBookMonthTable::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;
}
void DateBookMonthTable::dayClicked( int row, int col )
{
changeDaySelection( row, col );
emit dateClicked( selYear, selMonth, selDay );
}
void DateBookMonthTable::dragDay( int row, int col )
{
changeDaySelection( row, col );
}
void DateBookMonthTable::changeDaySelection( int row, int col )
{