kmail

folderviewtooltip.h

Go to the documentation of this file.
00001 #ifndef __FOLDERVIEWTOOLTIP_H__
00002 #define __FOLDERVIEWTOOLTIP_H__
00003 
00004 #include <kmfoldercachedimap.h>
00005 
00006 #include <qtooltip.h>
00007 
00008 namespace KMail {
00009 
00010 class FolderViewToolTip : public QToolTip
00011 {
00012   public:
00013     FolderViewToolTip( QListView* parent ) :
00014       QToolTip( parent->viewport() ),
00015       mListView( parent ) {}
00016 
00017   protected:
00018     void maybeTip( const QPoint &point )
00019     {
00020       KMFolderTreeItem *item = dynamic_cast<KMFolderTreeItem*>( mListView->itemAt( point ) );
00021       if  ( !item )
00022         return;
00023       const QRect itemRect = mListView->itemRect( item );
00024       if ( !itemRect.isValid() )
00025         return;
00026       const QRect headerRect = mListView->header()->sectionRect( 0 );
00027       if ( !headerRect.isValid() )
00028         return;
00029       
00030       if ( !item->folder() || item->folder()->noContent() )
00031         return;
00032       
00033       item->updateCount();
00034       QString tipText = i18n("<qt><b>%1</b><br>Total: %2<br>Unread: %3<br>Size: %4" )
00035           .arg( item->folder()->prettyURL().replace( " ", "&nbsp;" ) )
00036           .arg( item->totalCount() < 0 ? "-" : QString::number( item->totalCount() ) )
00037           .arg( item->unreadCount() < 0 ? "-" : QString::number( item->unreadCount() ) )
00038           .arg( KIO::convertSize( item->folderSize() ) );
00039       
00040       if ( KMFolderCachedImap* imap = dynamic_cast<KMFolderCachedImap*>( item->folder()->storage() ) ) {
00041           QuotaInfo info = imap->quotaInfo();
00042           if ( info.isValid() && !info.isEmpty() )
00043               tipText += i18n("<br>Quota: %1").arg( info.toString() );
00044       }
00045       
00046       tip( QRect( headerRect.left(), itemRect.top(), headerRect.width(), itemRect.height() ), tipText );
00047     }
00048 
00049   private:
00050     QListView *mListView;
00051 };
00052 
00053 }
00054 
00055 #endif /* __FOLDERVIEWTOOLTIP_H__ */