summaryrefslogtreecommitdiffabout
path: root/korganizer/komonthview.cpp
Side-by-side diff
Diffstat (limited to 'korganizer/komonthview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/komonthview.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index b9ce4f4..ab9a4b6 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -844,193 +844,197 @@ void MonthViewCell::enableScrollBars( bool enabled )
int ihei = fi->height( this );
int hei = numRows () * ihei;
if ( hei < height() - horizontalScrollBar()->height () ) {
setVScrollBarMode(QScrollView::AlwaysOff);
}
else
setVScrollBarMode(QScrollView::Auto);
if ( ihei *3 > height() )
setHScrollBarMode(QScrollView::AlwaysOff);
else
setHScrollBarMode(QScrollView::Auto);
} else {
setVScrollBarMode(QScrollView::Auto);
setHScrollBarMode(QScrollView::Auto);
}
} else {
setVScrollBarMode(QScrollView::AlwaysOff);
setHScrollBarMode(QScrollView::AlwaysOff);
}
}
Incidence *MonthViewCell::selectedIncidence()
{
int index = currentItem();
if ( index < 0 ) return 0;
MonthViewItem *mitem =
static_cast<MonthViewItem *>( item( index ) );
if ( !mitem ) return 0;
return mitem->incidence();
}
QDate MonthViewCell::selectedIncidenceDate()
{
QDate qd;
int index = currentItem();
if ( index < 0 ) return qd;
MonthViewItem *mitem =
static_cast<MonthViewItem *>( item( index ) );
if ( !mitem ) return qd;
return mitem->incidenceDate();
}
void MonthViewCell::deselect()
{
clearSelection();
enableScrollBars( false );
// updateCell();
}
void MonthViewCell::select()
{
;// updateCell();
}
void MonthViewCell::resizeEvent ( QResizeEvent * e )
{
if ( !mMonthView->isUpdatePossible() )
return;
//qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height());
deselect();
mLabel->setMaximumHeight( height() - lineWidth()*2 );
QString text;
mLabel->setText( text );
bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " ";
mLabel->resize( mLabelBigSize );
text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
} else {
mLabel->resize( mLabelSize );
text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
}
mLabel->setText( text );
int size = height() - mLabel->height() - lineWidth()-1;
//qDebug("LW %d ", lineWidth());
if ( size > 0 )
verticalScrollBar()->setMaximumHeight( size );
size = width() - mLabel->width() -lineWidth()-1;
if ( size > 0 )
horizontalScrollBar()->setMaximumWidth( size );
mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() );
//mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
// mItemList->resize ( width(), height () );
if ( e )
KNoScrollListBox::resizeEvent ( e );
}
void MonthViewCell::defaultAction( QListBoxItem *item )
{
- if ( !item ) return;
+ if ( !item ) {
+ QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
+ emit newEventSignal( dt );
+ return;
+ }
MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
Incidence *incidence = eventItem->incidence();
if ( incidence ) mMonthView->defaultAction( incidence );
}
void MonthViewCell::showDay()
{
emit showDaySignal( date() );
}
void MonthViewCell::newEvent()
{
QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
emit newEventSignal( dt );
}
void MonthViewCell::cellClicked( QListBoxItem *item )
{
static QListBoxItem * lastClicked = 0;
if ( item == 0 ) {
QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
emit newEventSignal( dt );
return;
}
/*
if ( lastClicked )
if ( ! item ) {
if ( lastClicked->listBox() != item->listBox() )
lastClicked->listBox()->clearSelection();
}
*/
mMonthView->setSelectedCell( this );
if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true );
select();
}
void MonthViewCell::contextMenu( QListBoxItem *item )
{
if ( !item ) return;
MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
Incidence *incidence = eventItem->incidence();
if ( incidence ) mMonthView->showContextMenu( incidence );
}
void MonthViewCell::selection( QListBoxItem *item )
{
if ( !item ) return;
mMonthView->setSelectedCell( this );
}
// *******************************************************************************
// *******************************************************************************
// *******************************************************************************
KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
: KOEventView( calendar, parent, name ),
mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
{
mFlagKeyPressed = false;
mShortDayLabelsM = false;
mShortDayLabelsW = false;
skipResize = false;
clPending = true;
mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" );
mWidStack = new QWidgetStack( this );
QVBoxLayout* hb = new QVBoxLayout( this );
mMonthView = new QWidget( mWidStack );
mWeekView = new QWidget( mWidStack );
#if QT_VERSION >= 0x030000
mWidStack->addWidget(mMonthView );
mWidStack->addWidget(mWeekView );
#else
mWidStack->addWidget( mMonthView, 1 );
mWidStack->addWidget( mWeekView , 1 );
#endif
hb->addWidget( mNavigatorBar );
hb->addWidget( mWidStack );
mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
updatePossible = false;
//updatePossible = true;
mCells.setAutoDelete( true );
mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
mDayLabels.resize( mDaysPerWeek );
mDayLabelsW.resize( mDaysPerWeek );
QFont bfont = font();
if ( QApplication::desktop()->width() < 650 ) {
bfont.setPointSize( bfont.pointSize() - 2 );
}
bfont.setBold( true );
int i;
for( i = 0; i < mDaysPerWeek; i++ ) {
@@ -1278,192 +1282,193 @@ void KOMonthView::updateDayLabels()
for (int i = 0; i < 7; i++) {
{
bool show = mShortDayLabelsW;
if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
show = true;
(*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
}
}
mDayLabelsT = &mDayLabels;
for (int i = 0; i < 7; i++) {
if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) {
bool show = mShortDayLabelsM;
if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
show = true;
(*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
} else {
if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM));
else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM));
}
}
}
void KOMonthView::showDates(const QDate &start, const QDate &)
{
// kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl;
QPtrVector<MonthViewCell> *cells;
QPtrVector<QLabel> *dayLabels;
QPtrVector<KOWeekButton> *weekLabels;
int weekNum = 6;
mStartDate = start;
if ( mShowWeekView ) {
weekNum = 1;
cells = &mCellsW;
dayLabels = &mDayLabelsW;
weekLabels = &mWeekLabelsW;
if ( !KGlobal::locale()->weekStartsMonday() ) {
mStartDate = mStartDate.addDays( 1 );
}
} else {
cells = &mCells;
dayLabels = &mDayLabels;
weekLabels = &mWeekLabels;
}
int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) {
mWeekStartsMonday = true;
}
int startWeekDay = mWeekStartsMonday ? 1 : 7;
while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) {
mStartDate = mStartDate.addDays( -1 );
}
bool primary = false;
uint i;
for( i = 0; i < (*cells).size(); ++i ) {
QDate date = mStartDate.addDays( i );
(*cells)[i]->setDate( date );
#ifndef KORG_NOPLUGINS
// add holiday, if present
QString hstring(KOCore::self()->holiday(date));
(*cells)[i]->setHoliday( hstring );
#endif
}
QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 );
for( i = 0; i < weekNum; ++i ) {
int wno;
// remember, according to ISO 8601, the first week of the year is the
// first week that contains a thursday. Thus we must subtract off 4,
// not just 1.
int dayOfYear = date.dayOfYear();
if (dayOfYear % 7 != 0)
wno = dayOfYear / 7 + 1;
else
wno =dayOfYear / 7;
(*weekLabels)[i]->setWeekNum( wno );
date = date.addDays( 7 );
}
updateView();
}
void KOMonthView::showEvents(QPtrList<Event>)
{
qDebug("KOMonthView::selectEvents is not implemented yet. ");
}
void KOMonthView::changeEventDisplay(Event *, int)
{
// this should be re-written to be much more efficient, but this
// quick-and-dirty-hack gets the job done for right now.
+ qDebug("KOMonthView::changeEventDisplay ");
updateView();
}
void KOMonthView::updateView()
{
if ( !updatePossible )
return;
//qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU ");
//QTime ti;
//ti.start();
clearSelection();
QPtrVector<MonthViewCell> *cells;
if ( mShowWeekView ) {
cells = &mCellsW;
} else {
cells = &mCells;
}
#if 1
int i;
int timeSpan = (*cells).size()-1;
if ( KOPrefs::instance()->mMonthViewWeek )
timeSpan = 6;
for( i = 0; i < timeSpan + 1; ++i ) {
(*cells)[i]->startUpdateCell();
}
QPtrList<Event> events = calendar()->events();
Event *event;
QDateTime dt;
bool ok;
QDate endDate = mStartDate.addDays( timeSpan );
for( event = events.first(); event; event = events.next() ) { // for event
if ( event->doesRecur() ) {
bool last;
QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
QDateTime incidenceEnd;
int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
bool invalid = false;
while( true ) {
if ( incidenceStart.isValid() ) {
incidenceEnd = incidenceStart.addDays( eventlen );
int st = incidenceStart.date().daysTo( endDate );
if ( st >= 0 ) { // start before timeend
int end = mStartDate.daysTo( incidenceEnd.date() );
if ( end >= 0 ) { // end after timestart --- got one!
//normalize
st = timeSpan - st;
if ( st < 0 ) st = 0;
if ( end > timeSpan ) end = timeSpan;
int iii;
//qDebug("found %s %d %d ",event->summary().latin1(), st, end );
for ( iii = st;iii<= end;++iii)
(*cells)[iii]->insertEvent( event );
}
}
} else {
if ( invalid )
break;
invalid = true;
//qDebug("invalid %s", event->summary().latin1());
incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
}
if ( last )
break;
bool ok;
incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
if ( ! ok )
break;
if ( incidenceStart.date() > endDate )
break;
}
} else { // no recur
int st = event->dtStart().date().daysTo( endDate );
if ( st >= 0 ) { // start before timeend
int end = mStartDate.daysTo( event->dtEnd().date() );
if ( end >= 0 ) { // end after timestart --- got one!
//normalize
st = timeSpan - st;
if ( st < 0 ) st = 0;
if ( end > timeSpan ) end = timeSpan;
int iii;
for ( iii = st;iii<= end;++iii)
(*cells)[iii]->insertEvent( event );
}
}
}
}
// insert due todos
QPtrList<Todo> todos = calendar()->todos( );
Todo *todo;
for(todo = todos.first(); todo; todo = todos.next()) {
//insertTodo( todo );
if ( todo->hasDueDate() ) {
int day = mStartDate.daysTo( todo->dtDue().date() );
if ( day >= 0 && day < timeSpan + 1) {