lib

KoPartSelectDia.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 1998 Torben Weis <weis@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <KoPartSelectDia.h>
21
22#include <kiconloader.h>
23#include <tdelocale.h>
24#include <tqlistview.h>
25
26/****************************************************
27 *
28 * KoPartSelectDia
29 *
30 ****************************************************/
31
32KoPartSelectDia::KoPartSelectDia( TQWidget* parent, const char* name ) :
33 KDialogBase( parent, name, true, i18n("Insert Object"), KDialogBase::Ok | KDialogBase::Cancel )
34{
35 listview = new TQListView( this );
36 listview->addColumn( i18n( "Object" ) );
37 listview->addColumn( i18n( "Comment" ) );
38 listview->setAllColumnsShowFocus( true );
39 listview->setShowSortIndicator( true );
40 setMainWidget( listview );
41 connect( listview, TQ_SIGNAL( doubleClicked( TQListViewItem * ) ),
42 this, TQ_SLOT( slotOk() ) );
43 connect( listview, TQ_SIGNAL( selectionChanged( TQListViewItem * ) ),
44 this, TQ_SLOT( selectionChanged( TQListViewItem * ) ) );
45
46 // Query for documents
47 m_lstEntries = KoDocumentEntry::query();
48 TQValueList<KoDocumentEntry>::Iterator it = m_lstEntries.begin();
49 for( ; it != m_lstEntries.end(); ++it ) {
50 KService::Ptr serv = (*it).service();
51 if (!serv->genericName().isEmpty()) {
52 TQListViewItem *item = new TQListViewItem( listview, serv->name(), serv->genericName() );
53 item->setPixmap( 0, SmallIcon( serv->icon() ) );
54 }
55 }
56
57 selectionChanged( 0 );
58 setFocus();
59 resize( listview->sizeHint().width() + 20, 300 );
60}
61
62void KoPartSelectDia::selectionChanged( TQListViewItem *item )
63{
64 enableButtonOK( item != 0 );
65}
66
68{
69 if ( listview->currentItem() ) {
70 TQValueList<KoDocumentEntry>::Iterator it = m_lstEntries.begin();
71 for ( ; it != m_lstEntries.end(); ++it ) {
72 if ( ( *it ).service()->name() == listview->currentItem()->text( 0 ) )
73 return *it;
74 }
75 }
76 return KoDocumentEntry();
77}
78
80{
82
83 KoPartSelectDia *dlg = new KoPartSelectDia( parent, "PartSelect" );
84 dlg->setFocus();
85 if (dlg->exec() == TQDialog::Accepted)
86 e = dlg->entry();
87
88 delete dlg;
89
90 return e;
91}
92
93#include <KoPartSelectDia.moc>
void setMainWidget(TQWidget *widget)
void enableButtonOK(bool state)
KDialogBase(TQWidget *parent=0, const char *name=0, bool modal=true, const TQString &caption=TQString::null, int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem())
virtual void slotOk()
Represents an available KOffice component that supports the document interface.
static TQValueList< KoDocumentEntry > query(const TQString &_constr=TQString())
This function will query tdesycoca to find all available components.
KoPartSelectDia(TQWidget *parent=0, const char *name=0)
Constructor.
KoDocumentEntry entry()
Retrieves the result of the part selection.
static KoDocumentEntry selectPart(TQWidget *parent=0L)
Convenience function for using the dialog.