selectdialog.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <kbuttonbox.h>
00025 #include <kglobalsettings.h>
00026 #include <klistbox.h>
00027 #include <klocale.h>
00028 #include <kmessagebox.h>
00029 #include <kiconloader.h>
00030
00031 #include <qgroupbox.h>
00032 #include <qlayout.h>
00033 #include <qpushbutton.h>
00034
00035 #include "resource.h"
00036
00037 #include "selectdialog.h"
00038
00039 using namespace KRES;
00040
00041 SelectDialog::SelectDialog( QPtrList<Resource> list, QWidget *parent,
00042 const char *name )
00043 : KDialog( parent, name, true )
00044 {
00045 setCaption( i18n( "Resource Selection" ) );
00046 resize( 300, 200 );
00047
00048 QVBoxLayout *mainLayout = new QVBoxLayout( this );
00049 mainLayout->setMargin( marginHint() );
00050
00051 QGroupBox *groupBox = new QGroupBox( 2, Qt::Horizontal, this );
00052 groupBox->setTitle( i18n( "Resources" ) );
00053
00054 mResourceId = new KListBox( groupBox );
00055
00056 mainLayout->addWidget( groupBox );
00057
00058 mainLayout->addSpacing( 10 );
00059
00060 KButtonBox *buttonBox = new KButtonBox( this );
00061
00062 buttonBox->addStretch();
00063 QPushButton* ok = buttonBox->addButton( i18n( "&OK" ), this, SLOT( accept() ) );
00064 QPushButton* cancel = buttonBox->addButton( i18n( "&Cancel" ), this, SLOT( reject() ) );
00065 if (KGlobalSettings::showIconsOnPushButtons()) {
00066 ok->setIconSet( SmallIconSet("button_ok") );
00067 cancel->setIconSet( SmallIconSet("button_cancel") );
00068 }
00069 buttonBox->layout();
00070
00071 mainLayout->addWidget( buttonBox );
00072
00073
00074 uint counter = 0;
00075 for ( uint i = 0; i < list.count(); ++i ) {
00076 Resource *resource = list.at( i );
00077 if ( resource && !resource->readOnly() ) {
00078 mResourceMap.insert( counter, resource );
00079 mResourceId->insertItem( resource->resourceName() );
00080 counter++;
00081 }
00082 }
00083
00084 mResourceId->setCurrentItem( 0 );
00085 connect( mResourceId, SIGNAL(returnPressed(QListBoxItem*)),
00086 SLOT(accept()) );
00087 connect( mResourceId, SIGNAL( executed( QListBoxItem* ) ),
00088 SLOT( accept() ) );
00089 }
00090
00091 Resource *SelectDialog::resource()
00092 {
00093 if ( mResourceId->currentItem() != -1 )
00094 return mResourceMap[ mResourceId->currentItem() ];
00095 else
00096 return 0;
00097 }
00098
00099 Resource *SelectDialog::getResource( QPtrList<Resource> list, QWidget *parent )
00100 {
00101 if ( list.count() == 0 ) {
00102 KMessageBox::error( parent, i18n( "There is no resource available!" ) );
00103 return 0;
00104 }
00105
00106 if ( list.count() == 1 ) return list.first();
00107
00108
00109
00110 Resource *found = 0;
00111 Resource *it = list.first();
00112 while ( it ) {
00113 if ( !it->readOnly() ) {
00114 if ( found ) {
00115 found = 0;
00116 break;
00117 } else
00118 found = it;
00119 }
00120 it = list.next();
00121 }
00122
00123 if ( found )
00124 return found;
00125
00126 SelectDialog dlg( list, parent );
00127 if ( dlg.exec() == KDialog::Accepted ) return dlg.resource();
00128 else return 0;
00129 }
This file is part of the documentation for kresources Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Apr 21 18:44:12 2004 by
doxygen 1.3.6-20040222 written by
Dimitri van Heesch, © 1997-2003