author | zautrix <zautrix> | 2005-03-25 05:47:45 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-25 05:47:45 (UTC) |
commit | e3b935f4e24086117213662e670ab26cb2ad8822 (patch) (side-by-side diff) | |
tree | d20ad8e8dd09cc3efb9f9e57568d4d009048d518 /korganizer/komonthview.cpp | |
parent | 658354b7112aff72f0fadd924c82b977d803bc27 (diff) | |
download | kdepimpi-e3b935f4e24086117213662e670ab26cb2ad8822.zip kdepimpi-e3b935f4e24086117213662e670ab26cb2ad8822.tar.gz kdepimpi-e3b935f4e24086117213662e670ab26cb2ad8822.tar.bz2 |
mal sehn...
-rw-r--r-- | korganizer/komonthview.cpp | 226 |
1 files changed, 161 insertions, 65 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index 050bfb9..38cfda7 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp @@ -185,36 +185,55 @@ void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) void KNoScrollListBox::mousePressEvent(QMouseEvent *e) { QListBox::mousePressEvent(e); if(e->button() == RightButton) { emit rightClick(); } } MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) : QListBoxItem() { + mblockRepaint = true; setText( s ); mMultiday = 0; mIncidence = incidence; mDate = qd; mRecur = false; mAlarm = false; mReply = false; mInfo = false; + //qDebug("NEWWWWWWWWWWWWW "); +} +void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s) +{ + setText( s ); + mMultiday = 0; + mIncidence = incidence; + mDate = qd; + mRecur = false; + mAlarm = false; + mReply = false; + mInfo = false; + //qDebug("recucleeeeeeeeeeeeeeeee "); } void MonthViewItem::paint(QPainter *p) { + if ( mblockRepaint ) { + //qDebug("block "); + return; + } + //qDebug("NON block "); #if QT_VERSION >= 0x030000 bool sel = isSelected(); #else bool sel = selected(); #endif if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { p->setBackgroundColor( palette().color( QPalette::Normal, \ sel ? QColorGroup::Highlight : QColorGroup::Background ) ); p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); @@ -344,61 +363,62 @@ int MonthViewItem::width(const QListBox *lb) const x += size+1+2+size/2; } return( x + lb->fontMetrics().width( text() ) + 1 ); } if ( ! lb ) return 10; //qDebug("ret wid %d ", lb->width()); return lb->width(); } MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) - : QWidget( par ), + : KNoScrollListBox( par ), mMonthView( parent ) { + mCurrentAvailItem = 0; //QVBoxLayout *topLayout = new QVBoxLayout( this ); - + currentPalette = 0; // mLabel = new QLabel( this );QPushButton mLabel = new QPushButton( this ); //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); //mLabel->setLineWidth( 1 ); //mLabel->setAlignment( AlignCenter ); mLabel->setFlat( true ); mLabel->setFocusPolicy(NoFocus); - mItemList = new KNoScrollListBox( this ); - mItemList->setMinimumSize( 10, 10 ); - mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain ); - mItemList->setLineWidth( 1 ); + //mItemList = new KNoScrollListBox( this ); + setMinimumSize( 10, 10 ); + setFrameStyle( QFrame::Panel | QFrame::Plain ); + setLineWidth( 1 ); //topLayout->addWidget( mItemList ); mLabel->raise(); // QColor( 0,0,255 ) QColor( 160,1600,255 ) mStandardPalette = palette(); mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); enableScrollBars( false ); updateConfig(); //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); - connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ), + connect( this , SIGNAL( doubleClicked( QListBoxItem *) ), SLOT( defaultAction( QListBoxItem * ) ) ); - connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *, + connect( this, SIGNAL( rightButtonPressed( QListBoxItem *, const QPoint &) ), SLOT( contextMenu( QListBoxItem * ) ) ); - connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), + connect( this, SIGNAL( highlighted( QListBoxItem *) ), SLOT( selection( QListBoxItem * ) ) ); - connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), + connect( this, SIGNAL( clicked( QListBoxItem * ) ), SLOT( cellClicked( QListBoxItem * ) ) ); - connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), + connect( this, SIGNAL( clicked( QListBoxItem * ) ), SLOT( selection( QListBoxItem * ) ) ); } #ifdef DESKTOP_VERSION QToolTipGroup *MonthViewCell::toolTipGroup() { if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); return mToolTipGroup; } #endif void MonthViewCell::setDate( const QDate &date ) { @@ -413,35 +433,46 @@ void MonthViewCell::setDate( const QDate &date ) QDate MonthViewCell::date() const { return mDate; } void MonthViewCell::setPrimary( bool primary ) { mPrimary = primary; //setMyPalette(); } void MonthViewCell::setMyPalette() { - + if ( mHoliday) { + if ( currentPalette == 1 ) return; mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) )); - mItemList->setPalette( mHolidayPalette ); + setPalette( mHolidayPalette ); + //mLabel->setPalette( mHolidayPalette ); + currentPalette = 1; + } else { if ( mPrimary ) { + if ( currentPalette == 2 ) return; mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); - mItemList->setPalette( mPrimaryPalette ); + //mLabel->setPalette( mPrimaryPalette ); + setPalette( mPrimaryPalette ); + currentPalette = 2; + } else { - mItemList->setPalette( mNonPrimaryPalette ); - mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); + if ( currentPalette == 3 ) return; + setPalette( mNonPrimaryPalette ); + mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); + //mLabel->setPalette( mNonPrimaryPalette );; + currentPalette = 3; } } //QPalette pal = palette(); //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); } QPalette MonthViewCell::getPalette () { if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) return mStandardPalette; if ( mHoliday) { return mHolidayPalette ; @@ -462,82 +493,84 @@ void MonthViewCell::setHoliday( bool holiday ) mHoliday = holiday; //setMyPalette(); } void MonthViewCell::setHoliday( const QString &holiday ) { mHolidayString = holiday; if ( !holiday.isEmpty() ) { setHoliday( true ); } } -void MonthViewCell::keyPressEvent ( QKeyEvent * e ) -{ - - e->ignore(); - -} void MonthViewCell::startUpdateCell() { - mItemList->setFocusPolicy(NoFocus); + setFocusPolicy(NoFocus); if ( !mMonthView->isUpdatePossible() ) return; - + MonthViewItem *mitem = (MonthViewItem*) firstItem (); + while ( mitem ) { + mitem->setBlockRepaint( true ); + mitem = (MonthViewItem *)mitem->next(); + } /* if ( !isVisible() ){ return; } */ // qDebug("MonthViewCell::updateCell() "); setPrimary( mDate.month()%2 ); setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); if ( mDate == QDate::currentDate() ) { - mItemList->setLineWidth( 3 ); + setLineWidth( 3 ); } else { - mItemList->setLineWidth( 1 ); + setLineWidth( 1 ); } - mItemList->clear(); + mCurrentAvailItem = (MonthViewItem*) firstItem (); + //clear(); #ifdef DESKTOP_VERSION QToolTip::remove(this); #endif mToolTip.clear(); //qApp->processEvents(); +#if 0 if ( !mHolidayString.isEmpty() ) { MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); item->setPalette( mHolidayPalette ); - mItemList->insertItem( item ); + insertItem( item ); mToolTip.append ( mHolidayString ); } +#endif } void MonthViewCell::insertEvent(Event *event) { QString mToolTipText; - mItemList->setFocusPolicy(WheelFocus); + bool insertNewItem = false; + setFocusPolicy(WheelFocus); if ( !(event->doesRecur() == Recurrence::rNone) ) { if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) return; else if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) return; } if ( event->isHoliday()) { setHoliday( true ); if ( mDate.dayOfWeek() == 7 ) - mItemList->setLineWidth( 3 ); + setLineWidth( 3 ); } QString text; int multiday = 0;// 1 = start, 2 = midddle, 3 = end day if (event->isMultiDay()) { QString prefix = "<->";multiday = 2; QString time; if ( event->doesRecur() ) { if ( event->recursOn( mDate) ) { prefix ="->" ;multiday = 1; } else { int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); @@ -564,26 +597,40 @@ void MonthViewCell::insertEvent(Event *event) mToolTipText += prefix + text; } else { if (event->doesFloat()) { text = event->summary(); mToolTipText += text; } else { text = KGlobal::locale()->formatTime(event->dtStart().time()); text += " " + event->summary(); mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); } } - - MonthViewItem *item = new MonthViewItem( event, mDate, text ); + MonthViewItem *item ; + if ( mCurrentAvailItem ) { + item = mCurrentAvailItem; + mCurrentAvailItem = (MonthViewItem*) item->next(); + item->recycle( event, mDate, text ); + } else { + if ( mAvailItemList.count() ) { + item = mAvailItemList.first(); + mAvailItemList.remove( item ); + item->recycle( event, mDate, text ); + insertNewItem = true; + } else { + insertNewItem = true; + item = new MonthViewItem( event, mDate, text ); + } + } QPalette pal; if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { QStringList categories = event->categories(); QString cat = categories.first(); if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { pal = getPalette(); if (cat.isEmpty()) { pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); } else { pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); } @@ -605,40 +652,57 @@ void MonthViewCell::insertEvent(Event *event) #ifdef DESKTOP_VERSION Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, KOPrefs::instance()->email()); if ( me != 0 ) { if ( me->status() == Attendee::NeedsAction && me->RSVP()) item->setReply(true && multiday < 2); else item->setReply(false); } else item->setReply(false); #endif item->setMultiDay( multiday ); - mItemList->insertItem( item ); + if ( insertNewItem) + insertItem( item ); mToolTip.append( mToolTipText ); } void MonthViewCell::insertTodo(Todo *todo) { - mItemList->setFocusPolicy(WheelFocus); + bool insertNewItem = false; + setFocusPolicy(WheelFocus); QString text; if (todo->hasDueDate()) { if (!todo->doesFloat()) { text += KGlobal::locale()->formatTime(todo->dtDue().time()); text += " "; } } text += todo->summary(); - - MonthViewItem *item = new MonthViewItem( todo, mDate, text ); + MonthViewItem *item ; + if ( mCurrentAvailItem ) { + item = mCurrentAvailItem; + mCurrentAvailItem = (MonthViewItem*) item->next(); + item->recycle( todo, mDate, text ); + } else { + if ( mAvailItemList.count() ) { + item = mAvailItemList.first(); + mAvailItemList.remove( item ); + item->recycle( todo, mDate, text ); + insertNewItem = true; + } else { + insertNewItem = true; + item = new MonthViewItem( todo, mDate, text ); + } + } + //MonthViewItem *item = new MonthViewItem( todo, mDate, text ); //item->setPalette( mStandardPalette ); QPalette pal; if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { QStringList categories = todo->categories(); QString cat = categories.first(); if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { pal = getPalette(); if (cat.isEmpty()) { pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); } else { pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); } @@ -649,36 +713,54 @@ void MonthViewCell::insertTodo(Todo *todo) } else { pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); } } } else { pal = mStandardPalette ; } item->setPalette( pal ); item->setRecur( todo->recurrence()->doesRecur() ); item->setAlarm( todo->isAlarmEnabled() ); item->setMoreInfo( todo->description().length() > 0 ); - mItemList->insertItem( item ); + if ( insertNewItem) + insertItem( item ); mToolTip.append( text ); } +void MonthViewCell::repaintfinishUpdateCell() +{ + MonthViewItem *mitem = (MonthViewItem*) firstItem (); + while ( mitem ) { + mitem->setBlockRepaint( false ); + updateItem ( mitem ); + mitem = (MonthViewItem *)mitem->next(); + } +} void MonthViewCell::finishUpdateCell() { + while ( mCurrentAvailItem ) { + MonthViewItem *item = mCurrentAvailItem; + mCurrentAvailItem = (MonthViewItem *)item->next(); + mAvailItemList.append( item ); + takeItem ( item ); + } + + #ifdef DESKTOP_VERSION if (mToolTip.count() > 0 ) { mToolTip.sort(); QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); } #endif - mItemList->sort(); + sort(); //setMyPalette(); setMyPalette(); QString 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) ); } @@ -737,94 +819,103 @@ void MonthViewCell::updateConfig( bool bigFont ) // = false mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); } //updateCell(); } void MonthViewCell::enableScrollBars( bool enabled ) { if ( enabled ) { - //mItemList->setVScrollBarMode(QScrollView::Auto); - mItemList->setHScrollBarMode(QScrollView::Auto); - QListBoxItem *fi = mItemList->firstItem (); + + QListBoxItem *fi = firstItem (); if (fi ) { - int hei = mItemList->numRows () * fi->height(mItemList); - if ( hei < height() - mItemList->horizontalScrollBar()->height () ) - mItemList->setVScrollBarMode(QScrollView::AlwaysOff); + int ihei = fi->height( this ); + int hei = numRows () * ihei; + if ( hei < height() - horizontalScrollBar()->height () ) + setVScrollBarMode(QScrollView::AlwaysOff); else - mItemList->setVScrollBarMode(QScrollView::Auto); + setVScrollBarMode(QScrollView::Auto); + if ( ihei *3 > height() ) + setHScrollBarMode(QScrollView::AlwaysOff); + else + setHScrollBarMode(QScrollView::Auto); + } else { + setVScrollBarMode(QScrollView::Auto); + setHScrollBarMode(QScrollView::Auto); } } else { - mItemList->setVScrollBarMode(QScrollView::AlwaysOff); - mItemList->setHScrollBarMode(QScrollView::AlwaysOff); + setVScrollBarMode(QScrollView::AlwaysOff); + setHScrollBarMode(QScrollView::AlwaysOff); } } Incidence *MonthViewCell::selectedIncidence() { - int index = mItemList->currentItem(); + int index = currentItem(); if ( index < 0 ) return 0; - MonthViewItem *item = - static_cast<MonthViewItem *>( mItemList->item( index ) ); + MonthViewItem *mitem = + static_cast<MonthViewItem *>( item( index ) ); - if ( !item ) return 0; + if ( !mitem ) return 0; - return item->incidence(); + return mitem->incidence(); } QDate MonthViewCell::selectedIncidenceDate() { QDate qd; - int index = mItemList->currentItem(); + int index = currentItem(); if ( index < 0 ) return qd; - MonthViewItem *item = - static_cast<MonthViewItem *>( mItemList->item( index ) ); + MonthViewItem *mitem = + static_cast<MonthViewItem *>( item( index ) ); - if ( !item ) return qd; + if ( !mitem ) return qd; - return item->incidenceDate(); + return mitem->incidenceDate(); } void MonthViewCell::deselect() { - mItemList->clearSelection(); + 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(); - int size = height() - mLabel->height() - 2; + int size = height() - mLabel->height() - lineWidth()-1; + //qDebug("LW %d ", lineWidth()); if ( size > 0 ) - mItemList->verticalScrollBar()->setMaximumHeight( size ); - size = width() - mLabel->width() -2; + verticalScrollBar()->setMaximumHeight( size ); + size = width() - mLabel->width() -lineWidth()-1; if ( size > 0 ) - mItemList->horizontalScrollBar()->setMaximumWidth( size ); - mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() ); + horizontalScrollBar()->setMaximumWidth( size ); + mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); - mItemList->resize ( width(), height () ); - + // mItemList->resize ( width(), height () ); + if ( e ) + KNoScrollListBox::resizeEvent ( e ); } void MonthViewCell::defaultAction( QListBoxItem *item ) { if ( !item ) return; MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); Incidence *incidence = eventItem->incidence(); if ( incidence ) mMonthView->defaultAction( incidence ); } void MonthViewCell::showDay() { @@ -1251,24 +1342,25 @@ void KOMonthView::showEvents(QPtrList<Event>) 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. 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; @@ -1347,24 +1439,28 @@ void KOMonthView::updateView() if ( todo->hasDueDate() ) { int day = mStartDate.daysTo( todo->dtDue().date() ); if ( day >= 0 && day < timeSpan + 1) { (*cells)[day]->insertTodo( todo ); } } } for( i = 0; i < timeSpan+1; ++i ) { (*cells)[i]->finishUpdateCell(); } processSelectionChange(); + qApp->processEvents(); + for( i = 0; i < timeSpan+1; ++i ) { + (*cells)[i]->repaintfinishUpdateCell(); + } (*cells)[0]->setFocus(); #else // old code //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); int i; for( i = 0; i < (*cells).count(); ++i ) { (*cells)[i]->updateCell(); } //qDebug("KOMonthView::updateView() "); |