akonadi
imdelegate.cpp
00001 /* 00002 This file is part of Akonadi Contact. 00003 00004 Copyright (c) 2010 Tobias Koenig <tokoe@kde.org> 00005 00006 This library is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU Library General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or (at your 00009 option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, but WITHOUT 00012 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to the 00018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00019 02110-1301, USA. 00020 */ 00021 00022 #include "imdelegate.h" 00023 00024 #include "immodel.h" 00025 #include "improtocols.h" 00026 00027 #include <kcombobox.h> 00028 #include <kicon.h> 00029 #include <klocale.h> 00030 00031 IMDelegate::IMDelegate( QObject *parent ) 00032 : QStyledItemDelegate( parent ) 00033 { 00034 } 00035 00036 IMDelegate::~IMDelegate() 00037 { 00038 } 00039 00040 QWidget* IMDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &item, const QModelIndex &index ) const 00041 { 00042 if ( index.column() == 0 ) { 00043 KComboBox *comboBox = new KComboBox( parent ); 00044 comboBox->setFrame( false ); 00045 comboBox->setAutoFillBackground( true ); 00046 00047 const QStringList protocols = IMProtocols::self()->protocols(); 00048 foreach ( const QString &protocol, protocols ) { 00049 comboBox->addItem( KIcon( IMProtocols::self()->icon( protocol ) ), 00050 IMProtocols::self()->name( protocol ), 00051 protocol ); 00052 } 00053 00054 return comboBox; 00055 } else { 00056 return QStyledItemDelegate::createEditor( parent, item, index ); 00057 } 00058 } 00059 00060 void IMDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const 00061 { 00062 if ( index.column() == 0 ) { 00063 KComboBox *comboBox = qobject_cast<KComboBox*>( editor ); 00064 if ( !comboBox ) 00065 return; 00066 00067 const QString protocol = index.data( IMModel::ProtocolRole ).toString(); 00068 comboBox->setCurrentIndex( comboBox->findData( protocol ) ); 00069 } else { 00070 QStyledItemDelegate::setEditorData( editor, index ); 00071 } 00072 } 00073 00074 void IMDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const 00075 { 00076 if ( index.column() == 0 ) { 00077 KComboBox *comboBox = qobject_cast<KComboBox*>( editor ); 00078 if ( !comboBox ) 00079 return; 00080 00081 model->setData( index, comboBox->itemData( comboBox->currentIndex() ), IMModel::ProtocolRole ); 00082 } else { 00083 QStyledItemDelegate::setModelData( editor, model, index ); 00084 } 00085 } 00086 00087 void IMDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const 00088 { 00089 if ( index.data( IMModel::IsPreferredRole ).toBool() ) { 00090 QStyleOptionViewItem newOption( option ); 00091 newOption.font.setBold( true ); 00092 00093 QStyledItemDelegate::paint( painter, newOption, index ); 00094 } else 00095 QStyledItemDelegate::paint( painter, option, index ); 00096 } 00097
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:52:56 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:52:56 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.