diff --git a/kmatmlistview.cpp b/kmatmlistview.cpp index 2dd9527c6..0099a80cb 100644 --- a/kmatmlistview.cpp +++ b/kmatmlistview.cpp @@ -6,139 +6,25 @@ #include #include "kmatmlistview.h" - -#include "kmmainwin.h" -#include "kmreadermainwin.h" -#include "messagesender.h" -#include "kmmsgpartdlg.h" -#include -#include -#include "kmaddrbook.h" -#include "kmmsgdict.h" -#include "kmfolderimap.h" -#include "kmfoldermgr.h" -#include "kmtransport.h" -#include "kmcommands.h" -#include "kcursorsaver.h" -#include "partNode.h" -#include "attachmentlistview.h" -#include "transportmanager.h" -using KMail::AttachmentListView; -#include "dictionarycombobox.h" -using KMail::DictionaryComboBox; -#include "addressesdialog.h" -using KPIM::AddressesDialog; -#include "addresseeemailselection.h" -using KPIM::AddresseeEmailSelection; -using KPIM::AddresseeSelectorDialog; -#include -using KPIM::MailListDrag; -#include "recentaddresses.h" -using KRecentAddress::RecentAddresses; -#include "kleo_util.h" -#include "stl_util.h" -#include "recipientseditor.h" - -#include "attachmentcollector.h" -#include "objecttreeparser.h" - -#include "kmfoldermaildir.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - - -#include "klistboxdialog.h" - -#include "messagecomposer.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -#include "globalsettings.h" -#include "replyphrases.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include +#include #include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -KMAtmListViewItem::KMAtmListViewItem(Q3ListView *parent) +KMAtmListViewItem::KMAtmListViewItem( Q3ListView *parent ) : QObject(), - Q3ListViewItem( parent ), - mListview( parent ), - mCBSignEnabled( false ), - mCBEncryptEnabled( false ) + Q3ListViewItem( parent ) { - mCBEncrypt = new QCheckBox( mListview->viewport() ); - mCBSign = new QCheckBox( mListview->viewport() ); - mCBCompress = new QCheckBox( mListview->viewport() ); - connect( mCBCompress, SIGNAL( clicked() ), this, SLOT( slotCompress() ) ); + mCBCompress = new QCheckBox( listView()->viewport() ); + mCBEncrypt = new QCheckBox( listView()->viewport() ); + mCBSign = new QCheckBox( listView()->viewport() ); + mCBCompress->setVisible( true ); + updateAllCheckBoxes(); - mCBEncrypt->hide(); - mCBSign->hide(); + connect( mCBCompress, SIGNAL( clicked() ), this, SLOT( slotCompress() ) ); + connect( listView()->header(), SIGNAL( sizeChange(int, int, int) ), + SLOT( slotHeaderChange( int, int, int ) ) ); + connect( listView()->header(), SIGNAL( indexChange(int, int, int) ), + SLOT( slotHeaderChange( int, int, int ) ) ); + connect( listView()->header(), SIGNAL( clicked( int ) ), SLOT( slotHeaderClick( int ) ) ); } KMAtmListViewItem::~KMAtmListViewItem() @@ -151,122 +37,108 @@ KMAtmListViewItem::~KMAtmListViewItem() mCBCompress = 0; } -void KMAtmListViewItem::paintCell( QPainter * p, const QColorGroup & cg, - int column, int width, int align ) +void KMAtmListViewItem::updateCheckBox( int headerSection, QCheckBox *cb ) { - // this is also called for the encrypt/sign columns to assure that the - // background is cleared - Q3ListViewItem::paintCell( p, cg, column, width, align ); - if ( 4 == column ) { - QRect r = mListview->itemRect( this ); - if ( !r.size().isValid() ) { - mListview->ensureItemVisible( this ); - mListview->repaintContents( false ); - r = mListview->itemRect( this ); - } - int colWidth = mListview->header()->sectionSize( column ); - r.setX( mListview->header()->sectionPos( column ) - - mListview->header()->offset() - + colWidth / 2 - - r.height() / 2 - - 1 ); - r.setY( r.y() + 1 ); - r.setWidth( r.height() - 2 ); - r.setHeight( r.height() - 2 ); - r = QRect( mListview->viewportToContents( r.topLeft() ), r.size() ); - - mCBCompress->resize( r.size() ); - mListview->moveChild( mCBCompress, r.x(), r.y() ); + // Calculate some values to determine the x-position where the checkbox + // will be drawn + int sectionWidth = listView()->header()->sectionSize( headerSection ); + int sectionPos = listView()->header()->sectionPos( headerSection ); + int sectionOffset = sectionWidth / 2 - height() / 4; + + //Resize and move the checkbox + cb->resize( sectionWidth - sectionOffset - 1, height() - 2 ); + listView()->moveChild( cb, sectionPos + sectionOffset, itemPos() + 1 ); + + //Set the correct background color + if ( isSelected() ) { + cb->setBackgroundRole( QPalette::Highlight ); + } else { + cb->setBackgroundRole( QPalette::QPalette::Base ); + } +} - QColor bg; - if (isSelected()) - bg = cg.color( QPalette::Highlight ); - else - bg = cg.color( QPalette::Base ); +void KMAtmListViewItem::updateAllCheckBoxes() +{ + updateCheckBox( 4, mCBCompress ); + updateCheckBox( 5, mCBEncrypt ); + updateCheckBox( 6, mCBSign ); +} - QPalette pal; - pal.setColor( mCBCompress->backgroundRole(), bg ); - mCBCompress->setPalette(pal); - mCBCompress->show(); +// Each time a cell is about to be painted, the item's checkboxes are updated +// as well. This is necessary to keep the positions of the checkboxes +// up-to-date. The signals which are, in the constructor of this class, +// connected to the update slots are not sufficent because unfortunately, +// Qt does not provide a signal for changed item positions, e.g. during +// deleting or adding items. The problem with this is that this function +// does not catch updates which are off-screen, which means under some +// circumstances checkboxes have invalid positions. This should not happen +// anymore, but was the cause of bug 113458. Therefore, both the signals +// connected in the constructor and this function are necessary to keep the +// checkboxes' positions in sync, and hopefully is enough. +void KMAtmListViewItem::paintCell ( QPainter *p, const QColorGroup &cg, + int column, int width, int align ) +{ + switch ( column ) { + case 4: updateCheckBox( 4, mCBCompress ); break; + case 5: updateCheckBox( 5, mCBEncrypt ); break; + case 6: updateCheckBox( 6, mCBSign ); break; } - if( 5 == column || 6 == column ) { - QRect r = mListview->itemRect( this ); - if ( !r.size().isValid() ) { - mListview->ensureItemVisible( this ); - mListview->repaintContents( false ); - r = mListview->itemRect( this ); - } - int colWidth = mListview->header()->sectionSize( column ); - r.setX( mListview->header()->sectionPos( column ) - + colWidth / 2 - - r.height() / 2 - - 1 ); - r.setY( r.y() + 1 ); - r.setWidth( r.height() - 2 ); - r.setHeight( r.height() - 2 ); - r = QRect( mListview->viewportToContents( r.topLeft() ), r.size() ); - QCheckBox* cb = (5 == column) ? mCBEncrypt : mCBSign; - cb->resize( r.size() ); - mListview->moveChild( cb, r.x(), r.y() ); - - QColor bg; - if (isSelected()) - bg = cg.color( QPalette::Highlight ); - else - bg = cg.color( QPalette::Base ); + Q3ListViewItem::paintCell( p, cg, column, width, align ); +} - QPalette pal; - pal.setColor( cb->backgroundRole(), bg ); - cb->setPalette( pal ); - bool enabled = (5 == column) ? mCBEncryptEnabled : mCBSignEnabled; - if (enabled) cb->show(); +int KMAtmListViewItem::compare( Q3ListViewItem *i, int col, bool ascending ) const +{ + if ( col != 1 ) { + return Q3ListViewItem::compare( i, col, ascending ); } + + return mAttachmentSize - + (static_cast(i))->mAttachmentSize; } -void KMAtmListViewItem::enableCryptoCBs(bool on) +void KMAtmListViewItem::enableCryptoCBs( bool on ) { - if( mCBEncrypt ) { - mCBEncryptEnabled = on; - mCBEncrypt->setEnabled( on ); - mCBEncrypt->setVisible( on ); - } - if( mCBSign ) { - mCBSignEnabled = on; - mCBSign->setEnabled( on ); - mCBSign->setVisible( on ); - } + // Show/Hide the appropriate checkboxes. + // This should not be necessary because the caller hides the columns + // containing the checkboxes anyway. + mCBEncrypt->setVisible( on ); + mCBSign->setVisible( on ); } -void KMAtmListViewItem::setEncrypt(bool on) +void KMAtmListViewItem::setEncrypt( bool on ) { - if( mCBEncrypt ) + if ( mCBEncrypt ) { mCBEncrypt->setChecked( on ); + } } bool KMAtmListViewItem::isEncrypt() { - if( mCBEncrypt ) + if ( mCBEncrypt ) { return mCBEncrypt->isChecked(); - else + } else { return false; + } } -void KMAtmListViewItem::setSign(bool on) +void KMAtmListViewItem::setSign( bool on ) { - if( mCBSign ) + if ( mCBSign ) { mCBSign->setChecked( on ); + } } bool KMAtmListViewItem::isSign() { - if( mCBSign ) + if ( mCBSign ) { return mCBSign->isChecked(); - else + } else { return false; + } } -void KMAtmListViewItem::setCompress(bool on) +void KMAtmListViewItem::setCompress( bool on ) { mCBCompress->setChecked( on ); } @@ -278,10 +150,24 @@ bool KMAtmListViewItem::isCompress() void KMAtmListViewItem::slotCompress() { - if ( mCBCompress->isChecked() ) - emit compress( itemPos() ); - else + if ( mCBCompress->isChecked() ) { + emit compress( itemPos() ); + } else { emit uncompress( itemPos() ); + } +} + +// Update the item's checkboxes when the position of those change +// due to different column positions +void KMAtmListViewItem::slotHeaderChange( int, int, int ) +{ + updateAllCheckBoxes(); +} + +// Update the item's checkboxes when the list is being sorted +void KMAtmListViewItem::slotHeaderClick( int ) +{ + updateAllCheckBoxes(); } #include "kmatmlistview.moc" diff --git a/kmatmlistview.h b/kmatmlistview.h index 2bd57bfe6..7bdd1fcd0 100644 --- a/kmatmlistview.h +++ b/kmatmlistview.h @@ -1,5 +1,5 @@ /* -*- mode: C++; c-file-style: "gnu" -*- - * KMComposeWin Header File + * KMAtmListViewItem Header File * Author: Markus Wuebben */ #ifndef __KMAIL_KMATMLISTVIEW_H__ @@ -15,48 +15,59 @@ class QCheckBox; class KMAtmListViewItem : public QObject, public Q3ListViewItem { Q_OBJECT - friend class ::KMComposeWin; - friend class ::MessageComposer; public: - KMAtmListViewItem(Q3ListView * parent); + KMAtmListViewItem( Q3ListView *parent ); virtual ~KMAtmListViewItem(); - virtual void paintCell( QPainter * p, const QColorGroup & cg, - int column, int width, int align ); - void setUncompressedMimeType( const QByteArray & type, const QByteArray & subtype ) { + //A custom compare function is needed because the size column is + //human-readable and therefore doesn't sort correctly. + virtual int compare( Q3ListViewItem *i, int col, bool ascending ) const; + + virtual void paintCell( QPainter *p, const QColorGroup &cg, int column, + int width, int align ); + + void setUncompressedMimeType( const QByteArray &type, const QByteArray &subtype ) + { mType = type; mSubtype = subtype; } - void uncompressedMimeType( QByteArray & type, QByteArray & subtype ) const { + void setAttachmentSize( int numBytes ) + { + mAttachmentSize = numBytes; + } + void uncompressedMimeType( QByteArray & type, QByteArray & subtype ) const + { type = mType; subtype = mSubtype; } void setUncompressedCodec( const QByteArray & codec ) { mCodec = codec; } QByteArray uncompressedCodec() const { return mCodec; } -signals: - void compress( int ); - void uncompress( int ); - -protected: - void enableCryptoCBs(bool on); - void setEncrypt(bool on); + void enableCryptoCBs( bool on ); + void setEncrypt( bool on ); bool isEncrypt(); - void setSign(bool on); + void setSign( bool on ); bool isSign(); - void setCompress(bool on); + void setCompress( bool on ); bool isCompress(); +signals: + void compress( int ); + void uncompress( int ); + private slots: void slotCompress(); + void slotHeaderChange( int, int, int ); + void slotHeaderClick( int ); private: - Q3ListView* mListview; - QCheckBox* mCBEncrypt; - QCheckBox* mCBSign; - QCheckBox* mCBCompress; - bool mCBSignEnabled, mCBEncryptEnabled; + void updateCheckBox( int headerSection, QCheckBox *cb ); + void updateAllCheckBoxes(); + + QCheckBox *mCBEncrypt; + QCheckBox *mCBSign; + QCheckBox *mCBCompress; QByteArray mType, mSubtype, mCodec; + int mAttachmentSize; }; - #endif // __KMAIL_KMATMLISTVIEW_H__ diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index 8c748636a..8a6f884fa 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -2235,6 +2235,7 @@ void KMComposeWin::msgPartToItem(const KMMessagePart* msgPart, lvi->setText(1, KIO::convertSize( msgPart->decodedSize())); lvi->setText(2, msgPart->contentTransferEncodingStr()); lvi->setText(3, prettyMimeType(msgPart->typeStr() + '/' + msgPart->subtypeStr())); + lvi->setAttachmentSize(msgPart->decodedSize()); if ( loadDefaults ) { if( canSignEncryptAttachments() ) {