00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <KoPartSelectDia.h>
00021
00022 #include <kiconloader.h>
00023 #include <klocale.h>
00024 #include <q3listview.h>
00025 #include <QPixmap>
00026
00027 #include <Q3ValueList>
00028
00029
00030
00031
00032
00033
00034
00035 KoPartSelectDia::KoPartSelectDia( QWidget* parent, const char* name ) :
00036 KDialog( parent )
00037 {
00038 setButtons( KDialog::Ok | KDialog::Cancel );
00039 setCaption( i18n("Insert Object") );
00040 setModal( true );
00041 setObjectName( name );
00042
00043 listview = new Q3ListView( this );
00044 listview->addColumn( i18n( "Object" ) );
00045 listview->addColumn( i18n( "Comment" ) );
00046 listview->setAllColumnsShowFocus( true );
00047 listview->setShowSortIndicator( true );
00048 setMainWidget( listview );
00049 connect( listview, SIGNAL( doubleClicked( Q3ListViewItem * ) ),
00050 this, SLOT( slotOk() ) );
00051 connect( listview, SIGNAL( selectionChanged( Q3ListViewItem * ) ),
00052 this, SLOT( selectionChanged( Q3ListViewItem * ) ) );
00053
00054
00055 m_lstEntries = KoDocumentEntry::query();
00056 Q3ValueList<KoDocumentEntry>::Iterator it = m_lstEntries.begin();
00057 for( ; it != m_lstEntries.end(); ++it ) {
00058 KService::Ptr serv = (*it).service();
00059 if (!serv->genericName().isEmpty()) {
00060 Q3ListViewItem *item = new Q3ListViewItem( listview, serv->name(), serv->genericName() );
00061 item->setPixmap( 0, SmallIcon( serv->icon() ) );
00062 }
00063 }
00064
00065 selectionChanged( 0 );
00066 setFocus();
00067 resize( listview->sizeHint().width() + 20, 300 );
00068 }
00069
00070 void KoPartSelectDia::selectionChanged( Q3ListViewItem *item )
00071 {
00072 enableButton( Ok, item != 0 );
00073 }
00074
00075 KoDocumentEntry KoPartSelectDia::entry()
00076 {
00077 if ( listview->currentItem() ) {
00078 Q3ValueList<KoDocumentEntry>::Iterator it = m_lstEntries.begin();
00079 for ( ; it != m_lstEntries.end(); ++it ) {
00080 if ( ( *it ).service()->name() == listview->currentItem()->text( 0 ) )
00081 return *it;
00082 }
00083 }
00084 return KoDocumentEntry();
00085 }
00086
00087 KoDocumentEntry KoPartSelectDia::selectPart( QWidget *parent )
00088 {
00089 KoDocumentEntry e;
00090
00091 KoPartSelectDia *dlg = new KoPartSelectDia( parent, "PartSelect" );
00092 dlg->setFocus();
00093 if (dlg->exec() == QDialog::Accepted)
00094 e = dlg->entry();
00095
00096 delete dlg;
00097
00098 return e;
00099 }
00100
00101 #include <KoPartSelectDia.moc>