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 <qlistview.h>
00025
00026
00027
00028
00029
00030
00031
00032 KoPartSelectDia::KoPartSelectDia(
QWidget* parent,
const char* name ) :
00033 KDialogBase( parent, name, TRUE, i18n("Insert Object"), KDialogBase::Ok | KDialogBase::Cancel )
00034 {
00035 listview =
new QListView(
this );
00036 listview->addColumn( i18n(
"Object" ) );
00037 listview->addColumn( i18n(
"Comment" ) );
00038 listview->setAllColumnsShowFocus( TRUE );
00039 listview->setShowSortIndicator( TRUE );
00040 setMainWidget( listview );
00041 connect( listview, SIGNAL( doubleClicked(
QListViewItem * ) ),
00042
this, SLOT( slotOk() ) );
00043 connect( listview, SIGNAL( selectionChanged(
QListViewItem * ) ),
00044
this, SLOT( selectionChanged(
QListViewItem * ) ) );
00045
00046
00047 m_lstEntries = KoDocumentEntry::query();
00048
QValueList<KoDocumentEntry>::Iterator it = m_lstEntries.begin();
00049
for( ; it != m_lstEntries.end(); ++it ) {
00050 KService::Ptr serv = (*it).service();
00051
if (!serv->genericName().isEmpty()) {
00052
QListViewItem *item =
new QListViewItem( listview, serv->name(), serv->genericName() );
00053 item->setPixmap( 0, SmallIcon( serv->icon() ) );
00054 }
00055 }
00056
00057 selectionChanged( 0 );
00058 setFocus();
00059 resize( listview->sizeHint().width() + 20, 300 );
00060 }
00061
00062
void KoPartSelectDia::selectionChanged(
QListViewItem *item )
00063 {
00064 enableButtonOK( item != 0 );
00065 }
00066
00067 KoDocumentEntry KoPartSelectDia::entry()
00068 {
00069
if ( listview->currentItem() ) {
00070
QValueList<KoDocumentEntry>::Iterator it = m_lstEntries.begin();
00071
for ( ; it != m_lstEntries.end(); ++it ) {
00072
if ( ( *it ).service()->name() == listview->currentItem()->text( 0 ) )
00073
return *it;
00074 }
00075 }
00076
return KoDocumentEntry();
00077 }
00078
00079 KoDocumentEntry KoPartSelectDia::selectPart(
QWidget *parent )
00080 {
00081
KoDocumentEntry e;
00082
00083
KoPartSelectDia *dlg =
new KoPartSelectDia( parent,
"PartSelect" );
00084 dlg->setFocus();
00085
if (dlg->exec() == QDialog::Accepted)
00086 e = dlg->
entry();
00087
00088
delete dlg;
00089
00090
return e;
00091 }
00092
00093
#include <koPartSelectDia.moc>