- Don't eat escape or enter keypresses, so that moving a message to a folder
  with the keyboard works again

- actually return the correct folder, by setting the currentItem as well, instead of
  only selecting an item.

Other stuff:

- Add some consts
- use QAction::setData instead of comparing the action names
- //< => ///<, so that doxygen recognises those
- some style fixes (identation, whitespace mainly)
- remove the ifdef'd out styleDependantFrameWidth


svn path=/trunk/KDE/kdepim/; revision=802876
wilder-work
Thomas McGuire 18 years ago
parent 0d6539ac84
commit 84ab0070f2
  1. 2
      folderselectiondialog.cpp
  2. 2
      folderselectiondialog.h
  3. 63
      folderselectiontreewidget.cpp
  4. 20
      folderselectiontreewidget.h
  5. 80
      kmmimeparttree.cpp
  6. 16
      kmmimeparttree.h

@ -86,7 +86,7 @@ FolderSelectionDialog::~FolderSelectionDialog()
}
KMFolder * FolderSelectionDialog::folder( void )
KMFolder * FolderSelectionDialog::folder( void ) const
{
return mTreeView->folder();
}

@ -78,7 +78,7 @@ public:
/**
* Returns the currently selected folder, or 0 if no folder is selected (yet)
*/
virtual KMFolder * folder();
KMFolder * folder() const;
/**
* Set the selected folder. Forwarded to FolderSelectionTreeWidget.

@ -44,7 +44,7 @@ public:
void setFolder( KMFolder * folder )
{ mFolder = folder; };
KMFolder * folder()
KMFolder * folder() const
{ return mFolder; };
private:
@ -62,10 +62,8 @@ FolderSelectionTreeWidget::FolderSelectionTreeWidget( QWidget * parent , KMFolde
mPathColumnIndex = addColumn( i18n( "Path" ) );
setContextMenuPolicy( Qt::CustomContextMenu );
connect(
this, SIGNAL( customContextMenuRequested( const QPoint & ) ),
this, SLOT( slotContextMenuRequested( const QPoint & ) )
);
connect( this, SIGNAL( customContextMenuRequested( const QPoint & ) ),
this, SLOT( slotContextMenuRequested( const QPoint & ) ) );
}
void FolderSelectionTreeWidget::recursiveReload( KMFolderTreeItem *fti , FolderSelectionTreeWidgetItem *parent )
@ -83,19 +81,20 @@ void FolderSelectionTreeWidget::recursiveReload( KMFolderTreeItem *fti , FolderS
return;
// top level
FolderSelectionTreeWidgetItem *item = parent ? new FolderSelectionTreeWidgetItem( parent ) : new FolderSelectionTreeWidgetItem( this );
FolderSelectionTreeWidgetItem *item = parent ? new FolderSelectionTreeWidgetItem( parent )
: new FolderSelectionTreeWidgetItem( this );
// Build the path (ParentItemPath/CurrentItemName)
QString path;
if( parent )
path = parent->text( mPathColumnIndex ) + "/";
path = parent->text( mPathColumnIndex ) + "/";
path += fti->text( 0 );
item->setText( mNameColumnIndex , fti->text( 0 ) );
item->setText( mPathColumnIndex , path );
item->setProtocol( (KPIM::FolderTreeWidgetItem::Protocol)( fti->protocol() ) );
item->setFolderType( (KPIM::FolderTreeWidgetItem::FolderType)( fti->type() ) );
QPixmap pix = fti->normalIcon(KIconLoader::SizeSmall);
item->setProtocol( static_cast<KPIM::FolderTreeWidgetItem::Protocol>( fti->protocol() ) );
item->setFolderType( static_cast<KPIM::FolderTreeWidgetItem::FolderType>( fti->type() ) );
QPixmap pix = fti->normalIcon( KIconLoader::SizeSmall );
item->setIcon( mNameColumnIndex , pix.isNull() ? SmallIcon( "folder" ) : QIcon( pix ) );
item->setExpanded( true );
@ -129,7 +128,7 @@ void FolderSelectionTreeWidget::reload( bool mustBeReadWrite, bool showOutbox,
if ( selected.isEmpty() && folder() )
selected = folder()->idString();
mFilter = "";
mFilter = QString();
for (
KMFolderTreeItem * fti = static_cast<KMFolderTreeItem *>( mFolderTree->firstChild() ) ;
@ -139,20 +138,21 @@ void FolderSelectionTreeWidget::reload( bool mustBeReadWrite, bool showOutbox,
recursiveReload( fti , 0 );
if ( preSelection.isEmpty() )
return; // nothing more to do
return; // nothing more to do
QTreeWidgetItemIterator it( this );
while ( FolderSelectionTreeWidgetItem * fitem = static_cast<FolderSelectionTreeWidgetItem *>( *it ) )
{
if ( fitem->folder() ) {
if ( fitem->folder()->idString() == preSelection ) {
// found
fitem->setSelected( true );
scrollToItem( fitem );
return;
}
}
++it;
if ( fitem->folder() ) {
if ( fitem->folder()->idString() == preSelection ) {
// found
fitem->setSelected( true );
scrollToItem( fitem );
setCurrentItem( fitem );
return;
}
}
++it;
}
}
@ -200,7 +200,7 @@ void FolderSelectionTreeWidget::slotContextMenuRequested( const QPoint &p )
{
QTreeWidgetItem * lvi = itemAt( p );
if (!lvi)
if ( !lvi )
return;
setCurrentItem( lvi );
lvi->setSelected( true );
@ -257,7 +257,7 @@ void FolderSelectionTreeWidget::applyFilter( const QString& filter )
// Now search...
QList<QTreeWidgetItem *> lItems = findItems( mFilter , Qt::MatchContains | Qt::MatchRecursive , mPathColumnIndex );
for( QList<QTreeWidgetItem *>::Iterator it = lItems.begin(); it != lItems.end(); ++it)
for( QList<QTreeWidgetItem *>::Iterator it = lItems.begin(); it != lItems.end(); ++it )
{
( *it )->setDisabled( false );
( *it )->setHidden( false );
@ -274,12 +274,13 @@ void FolderSelectionTreeWidget::applyFilter( const QString& filter )
// Iterate through the list to find the first selectable item
QTreeWidgetItemIterator first ( this );
QTreeWidgetItemIterator first( this );
while ( FolderSelectionTreeWidgetItem * item = static_cast< FolderSelectionTreeWidgetItem* >( *first ) )
{
if ( ( !item->isHidden() ) && ( !item->isDisabled() ) && ( item->flags() & Qt::ItemIsSelectable ) )
{
item->setSelected( true );
setCurrentItem( item );
scrollToItem( item );
break;
}
@ -303,7 +304,7 @@ void FolderSelectionTreeWidget::keyPressEvent( QKeyEvent *e )
QString s = e->text();
switch(e->key())
switch( e->key() )
{
case Qt::Key_Backspace:
if ( mFilter.length() > 0 )
@ -317,12 +318,12 @@ void FolderSelectionTreeWidget::keyPressEvent( QKeyEvent *e )
return;
break;
default:
if ( !s.isEmpty() )
{
mFilter += s;
applyFilter( mFilter );
return;
}
int ch = s.isEmpty() ? 0 : s[0].toAscii();
if ( !s.isEmpty() && ch >= 32 && ch <= 126 ) {
mFilter += s;
applyFilter( mFilter );
return;
}
break;
}

@ -48,13 +48,13 @@ class FolderSelectionTreeWidget : public KPIM::FolderTreeWidget
{
Q_OBJECT
private:
int mNameColumnIndex; //< The index of the folder name column
int mPathColumnIndex; //< The index of the path column
KMFolderTree* mFolderTree; //< The KMFolderTree to fetch the data from
QString mFilter; //< The current folder path filter string
bool mLastMustBeReadWrite; //< Internal state for reload()
bool mLastShowOutbox; //< Internal state for reload()
bool mLastShowImapFolders; //< Internal state for reload()
int mNameColumnIndex; ///< The index of the folder name column
int mPathColumnIndex; ///< The index of the path column
KMFolderTree* mFolderTree; ///< The KMFolderTree to fetch the data from
QString mFilter; ///< The current folder path filter string
bool mLastMustBeReadWrite; ///< Internal state for reload()
bool mLastShowOutbox; ///< Internal state for reload()
bool mLastShowImapFolders; ///< Internal state for reload()
public:
/**
@ -107,18 +107,18 @@ public:
* Apply the given filter string.
* Folders NOT matching the string are hidden and disabled (can't be selected).
*/
void applyFilter( const QString& filter );
void applyFilter( const QString &filter );
/**
* Returns the folder name column logical index.
*/
int nameColumnIndex()
int nameColumnIndex() const
{ return mNameColumnIndex; };
/**
* Returns the folder path column logical index.
*/
int pathColumnIndex()
int pathColumnIndex() const
{ return mPathColumnIndex; };
public slots:

@ -46,7 +46,6 @@
#include <kmenu.h>
#include <QClipboard>
#include <QStyle>
#include <QHeaderView>
@ -55,17 +54,12 @@ KMMimePartTree::KMMimePartTree( KMReaderWin* readerWin,
: QTreeWidget( parent ),
mReaderWin( readerWin ), mLayoutColumnsOnFirstShow( false )
{
#if 0
/* FIXME: Remove this ifdefed code if nobody complains (2008.04.23) */
setStyleDependantFrameWidth();
#endif
// Setup the header
QStringList headerNames;
headerNames << i18n("Description") << i18n("Type")
<< i18n("Encoding") << i18n("Size");
<< i18n("Encoding") << i18n("Size");
QTreeWidgetItem * hitem = new QTreeWidgetItem( headerNames );
QTreeWidgetItem * hitem = new QTreeWidgetItem( headerNames );
hitem->setTextAlignment( 3 , Qt::AlignRight );
setHeaderItem( hitem );
@ -170,6 +164,7 @@ void KMMimePartTree::slotHeaderContextMenuRequested( const QPoint& p )
int cc = hitem->columnCount();
for ( int i = 1 ; i < cc; i++ ) {
QAction * act = popup.addAction( hitem->text( i ) );
act->setData( i );
act->setCheckable( true );
if ( !header()->isSectionHidden( i ) )
act->setChecked( true );
@ -183,32 +178,21 @@ void KMMimePartTree::slotHeaderContextMenuRequested( const QPoint& p )
void KMMimePartTree::slotToggleColumn( QAction* a )
{
Q_ASSERT( a );
if ( !a )
return; // hm ?
// This is tricky: we actually trust translators to do the correct
// job and the user's language to have different words for each
// one of our column names :)
QString columnName = a->text();
QTreeWidgetItem * hitem = headerItem();
if ( !hitem )
return; // oops..
int cc = hitem->columnCount();
for ( int i = 1; i < cc; i++ ) {
if ( columnName == hitem->text( i ) ) {
// got the column to hide/show
if ( a->isChecked() )
header()->showSection( i );
else
header()->hideSection( i );
return;
}
}
// oops.. found no column to hide/show ?
int column = a->data().toInt();
Q_ASSERT( column >= 0 && column < hitem->columnCount() );
if ( a->isChecked() )
header()->showSection( column );
else
header()->hideSection( column );
}
void KMMimePartTree::slotContextMenuRequested( const QPoint& p )
@ -222,12 +206,12 @@ void KMMimePartTree::slotContextMenuRequested( const QPoint& p )
KMenu popup;
popup.addAction( SmallIcon( "document-save-as" ),i18n( "Save &As..." ),
popup.addAction( SmallIcon( "document-save-as" ), i18n( "Save &As..." ),
this, SLOT( slotSaveAs() ) );
if ( isAttachment ) {
popup.addAction( SmallIcon( "document-open" ), i18nc( "to open", "Open" ),
this, SLOT( slotOpen() ) );
this, SLOT( slotOpen() ) );
popup.addAction( i18n( "Open With..." ), this, SLOT( slotOpenWith() ) );
popup.addAction( i18nc( "to view something", "View" ), this, SLOT( slotView() ) );
}
@ -239,7 +223,7 @@ void KMMimePartTree::slotContextMenuRequested( const QPoint& p )
*/
popup.addAction( i18n( "Save All Attachments..." ), this,
SLOT( slotSaveAll() ) );
SLOT( slotSaveAll() ) );
// edit + delete only for attachments
if ( isAttachment ) {
@ -303,40 +287,10 @@ void KMMimePartTree::slotSaveAll()
command->start();
}
#if 0
/* FIXME: Remove this ifdefed code if nobody complains (2008.04.23) */
//-----------------------------------------------------------------------------
void KMMimePartTree::setStyleDependantFrameWidth()
{
// FIXME: This seems to be hack...Is it still needed with Qt4/KDE4 ?
// set the width of the frame to a reasonable value for the current GUI style
int frameWidth;
#if 0 // is this hack still needed with kde4?
if ( !qstrcmp( style()->metaObject()->className(), "KeramikStyle" ) )
frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth ) - 1;
else
#endif
frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
if ( frameWidth < 0 )
frameWidth = 0;
if ( frameWidth != lineWidth() )
setLineWidth( frameWidth );
}
//-----------------------------------------------------------------------------
void KMMimePartTree::styleChange( QStyle& oldStyle )
{
setStyleDependantFrameWidth();
QTreeWidget::styleChange( oldStyle );
}
#endif
//-----------------------------------------------------------------------------
void KMMimePartTree::correctSize( QTreeWidgetItem * item )
{
if (!item)
if ( !item )
return;
// Gather size for all the children
@ -351,7 +305,7 @@ void KMMimePartTree::correctSize( QTreeWidgetItem * item )
}
if ( totalSize > static_cast<KMMimePartTreeItem*>(item)->origSize() )
item->setText( 3 , KIO::convertSize(totalSize) );
item->setText( 3 , KIO::convertSize( totalSize ) );
if ( item->parent() )
correctSize( item->parent() );
@ -445,7 +399,7 @@ KMMimePartTreeItem::KMMimePartTreeItem( KMMimePartTree * parent,
: QTreeWidgetItem( parent ),
mPartNode( node ), mOrigSize( size )
{
Q_ASSERT(parent);
Q_ASSERT( parent );
if ( node )
node->setMimePartTreeItem( this );
setText( 0 , description );

@ -60,6 +60,7 @@ public:
virtual ~KMMimePartTree();
public:
/**
* Corrects the size displayed by the specified item
* by accounting for its current children.
@ -85,21 +86,10 @@ protected slots:
void slotCopy();
protected:
#if 0
/* FIXME: Remove this ifdefed code if nobody complains (2008.04.23) */
/** reimplemented in order to update the frame width in case of a changed
GUI style FIXME: Still needed with Qt4 ? */
virtual void styleChange( QStyle& oldStyle );
#endif
virtual void startDrag( Qt::DropActions actions );
virtual void showEvent( QShowEvent* e );
#if 0
/* FIXME: Remove this ifdefed code if nobody complains (2008.04.23) */
/** Set the width of the frame to a reasonable value for the current GUI
style */
void setStyleDependantFrameWidth();
#endif
void restoreLayoutIfPresent();
void startHandleAttachmentCommand( int action );
void saveSelectedBodyParts( bool encoded );
@ -140,10 +130,12 @@ public:
* @returns a pointer to the partNode this item is displaying.
*/
partNode* node() const { return mPartNode; }
/**
* @returns the initial size of the tree node data.
*/
KIO::filesize_t origSize() const { return mOrigSize; }
/**
* Sets the initial size of the tree node data.
*/

Loading…
Cancel
Save