00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "./accountviewdelegate.h"
00019
00020 AccountViewDelegate::AccountViewDelegate( QObject* parent )
00021 : QItemDelegate( parent )
00022 {
00023
00024
00025 picActive = KIcon( KStandardDirs::locate( "data", "kshowmail/pics/accountActive.png" ) );
00026 picNotActive = KIcon( KStandardDirs::locate( "data", "kshowmail/pics/accountNotActive.png" ) );
00027
00028 }
00029
00030 QWidget* AccountViewDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index ) const
00031 {
00032
00033 if( !index.isValid() ) return NULL;
00034 if( index.column() != 0 ) return NULL;
00035
00036
00037 KComboBox* cmbEditor = new KComboBox( parent );
00038 cmbEditor->addItem( KIcon( picActive ), i18nc( "@item:inlistbox account is active", "active" ) );
00039 cmbEditor->addItem( KIcon( picNotActive ), i18nc( "@item:inlistbox account is not active", "inactive" ) );
00040
00041 return cmbEditor;
00042
00043 }
00044
00045 void AccountViewDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const
00046 {
00047
00048 if( !index.isValid() ) return;
00049 if( index.column() != 0 ) return;
00050
00051
00052 bool state = index.model()->data( index, Qt::EditRole ).toBool();
00053
00054
00055 KComboBox* box = static_cast<KComboBox*>( editor );
00056 if( state == true )
00057 {
00058 box->setCurrentIndex( 0 );
00059 }
00060 else
00061 {
00062 box->setCurrentIndex( 1 );
00063 }
00064 }
00065
00066 void AccountViewDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
00067 {
00068
00069 if( index.column() != 0 ) return;
00070
00071
00072 KComboBox* box = static_cast<KComboBox*>( editor );
00073 switch( box->currentIndex() )
00074 {
00075 case 0 : model->setData( index, QVariant( true ) ); break;
00076 case 1 : model->setData( index, QVariant( false ) ); break;
00077 default : return;
00078 }
00079 }
00080
00081 void AccountViewDelegate::updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& ) const
00082 {
00083 editor->setGeometry( option.rect.x(), option.rect.y(), option.rect.width(), editor->minimumSizeHint().height() );
00084 }