diff --git a/kmheaders.cpp b/kmheaders.cpp index 81a54ebae..34e4935ea 100644 --- a/kmheaders.cpp +++ b/kmheaders.cpp @@ -778,7 +778,7 @@ void KMHeaders::msgChanged() QValueList curItems = selectedItems(); updateMessageList(); // do not change the selection // restore the old state - setTopItemByIndex( i ); + setTopItemByIndex( i, true); setCurrentMsg( cur ); setSelectedByIndex( curItems, true ); connect(this,SIGNAL(currentChanged(QListViewItem*)), @@ -2352,37 +2352,40 @@ void KMHeaders::setCurrentItemByIndex(int msgIdx) //----------------------------------------------------------------------------- int KMHeaders::topItemIndex() { - HeaderItem *item = static_cast(itemAt(QPoint(1,1))); - if (item) - return item->msgId(); - else - return -1; -} - -// If sorting ascending by date/ooa then try to scroll list when new mail -// arrives to show it, but don't scroll current item out of view. -void KMHeaders::showNewMail() -{ - if (mSortCol != mPaintInfo.dateCol) - return; - for( int i = 0; i < (int)mItems.size(); ++i) - if (mFolder->getMsgBase(i)->isNew()) { - if (!mSortDescending) - setTopItemByIndex( currentItemIndex() ); - break; - } + int i=0; + HeaderItem *topItem = static_cast(itemAt(QPoint(1,1))); + QListViewItem *item = firstChild(); + while(item && item != topItem) { + item = item->itemBelow(); + i++; + } + if(item) + return i; + return -1; } //----------------------------------------------------------------------------- -void KMHeaders::setTopItemByIndex( int aMsgIdx) +void KMHeaders::setTopItemByIndex( int aMsgIdx, bool fuzzy) { - int msgIdx = aMsgIdx; - if (msgIdx < 0) - msgIdx = 0; - else if (msgIdx >= (int)mItems.size()) - msgIdx = mItems.size() - 1; - if ((msgIdx >= 0) && (msgIdx < (int)mItems.size())) - setContentsPos( 0, itemPos( mItems[msgIdx] )); + int y = 0; + QListViewItem *item = firstChild(); + while(item) { + if(aMsgIdx-- <= 0) + break; + y += item->totalHeight(); + item = item->itemBelow(); + } + if(fuzzy) { + item = item->itemAbove(); + while(item) { + int mesgId = static_cast(item)->msgId(); + if( !mFolder->getMsgBase(mesgId)->isUnread() ) + break; + y -= item->totalHeight(); + item = item->itemAbove(); + } + } + setContentsPos( 0, y ); } //----------------------------------------------------------------------------- diff --git a/kmheaders.h b/kmheaders.h index d77cd8dea..0fa040a21 100644 --- a/kmheaders.h +++ b/kmheaders.h @@ -125,9 +125,6 @@ public: /** Read color options and set palette. */ virtual void readColorConfig(void); - /** Scroll to show new mail */ - void showNewMail(); - /** Return the current message */ virtual KMMessage* currentMsg(); /** Return the current list view item */ @@ -142,7 +139,7 @@ public: virtual int topItemIndex(); /** Make the item corresponding to the message with the given id the top most visible item. */ - virtual void setTopItemByIndex( int aMsgIdx ); + virtual void setTopItemByIndex( int aMsgIdx, bool fuzzy=false); virtual void setNestedOverride( bool override ); virtual void setSubjectThreading( bool subjThreading ); /** Double force items to always be open */ diff --git a/kmmainwidget.cpp b/kmmainwidget.cpp index 9ae8fb5af..59985334d 100644 --- a/kmmainwidget.cpp +++ b/kmmainwidget.cpp @@ -847,11 +847,6 @@ void KMMainWidget::slotMailChecked( bool newMail, bool sendOnCheck, if (mBeepOnNew) { KNotifyClient::beep(); } - - // Todo: - // scroll mHeaders to show new items if current item would - // still be visible - // mHeaders->showNewMail(); }