F:/KPlato/koffice/libs/kofficeui/KoPartSelectDia.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 1998 Torben Weis <weis@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB. If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <KoPartSelectDia.h>
00021 
00022 #include <kiconloader.h>
00023 #include <klocale.h>
00024 #include <q3listview.h>
00025 #include <QPixmap>
00026 //Added by qt3to4:
00027 #include <Q3ValueList>
00028 
00029 /****************************************************
00030  *
00031  * KoPartSelectDia
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     // Query for documents
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>

Généré le Wed Nov 22 23:41:05 2006 pour KPlato par  doxygen 1.5.1-p1