lib

KoPartSelectDia.cpp

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 <qlistview.h>
00025 
00026 /****************************************************
00027  *
00028  * KoPartSelectDia
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     // Query for documents
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>
KDE Home | KDE Accessibility Home | Description of Access Keys