certmanager

customactions.cpp

00001 /*
00002     customactions.cpp
00003 
00004     This file is part of Kleopatra, the KDE keymanager
00005     Copyright (c) 2001,2002,2004 Klarälvdalens Datakonsult AB
00006 
00007     Kleopatra is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     Kleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 */
00032 
00033 #include "customactions.h"
00034 
00035 #include <ktoolbar.h>
00036 #include <kapplication.h>
00037 
00038 #include <qlineedit.h>
00039 #include <qlabel.h>
00040 
00041 
00042 LabelAction::LabelAction( const QString & text,  KActionCollection * parent,
00043               const char* name )
00044   : KAction( text, QIconSet(), KShortcut(), 0, 0, parent, name )
00045 {
00046 
00047 }
00048 
00049 int LabelAction::plug( QWidget * widget, int index ) {
00050   if ( kapp && !kapp->authorizeKAction( name() ) )
00051     return -1;
00052   if ( widget->inherits( "KToolBar" ) ) {
00053     KToolBar * bar = (KToolBar *)widget;
00054     int id_ = getToolButtonID();
00055     QLabel* label = new QLabel( text(), bar, "kde toolbar widget" );
00056     bar->insertWidget( id_, label->width(), label, index );
00057     addContainer( bar, id_ );
00058     connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
00059     return containerCount() - 1;
00060   }
00061 
00062   return KAction::plug( widget, index );
00063 }
00064 
00065 LineEditAction::LineEditAction( const QString & text, KActionCollection * parent,
00066                 QObject * receiver, const char * member, const char * name )
00067   : KAction( text, QIconSet(), KShortcut(), 0, 0, parent, name ),
00068     _le(0), _receiver(receiver), _member(member)
00069 {
00070 
00071 }
00072 
00073 int LineEditAction::plug( QWidget * widget, int index ) {
00074   if ( kapp && !kapp->authorizeKAction( name() ) )
00075     return -1;
00076   if ( widget->inherits( "KToolBar" ) ) {
00077     KToolBar *bar = (KToolBar *)widget;
00078     int id_ = getToolButtonID();
00079     // The toolbar trick doesn't seem to work for lineedits
00080     //_le = new QLineEdit( bar, "kde toolbar widget" );
00081     _le = new QLineEdit( bar );
00082     bar->insertWidget( id_, _le->width(), _le, index );
00083     bar->setStretchableWidget( _le );
00084     addContainer( bar, id_ );
00085     connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
00086     connect( _le, SIGNAL( returnPressed() ), _receiver, _member );
00087     return containerCount() - 1;
00088   }
00089 
00090   return KAction::plug( widget, index );
00091 }
00092 
00093 void LineEditAction::clear() {
00094   _le->clear();
00095 }
00096 
00097 void LineEditAction::focusAll() {
00098   _le->selectAll();
00099   _le->setFocus();
00100 }
00101 
00102 QString LineEditAction::text() const {
00103   return _le->text();
00104 }
00105 
00106 void LineEditAction::setText( const QString & txt ) {
00107   _le->setText(txt);
00108 }
00109 
00110 
00111 ComboAction::ComboAction( const QStringList & lst,  KActionCollection * parent,
00112               QObject * receiver, const char * member, const char * name,
00113                           int selectedID )
00114   : KAction( QString::null, QIconSet(), KShortcut(), 0, 0, parent, name ),
00115     _lst(lst), _receiver(receiver), _member(member), _selectedId( selectedID )
00116 {
00117 
00118 }
00119 
00120 int ComboAction::plug( QWidget * widget, int index ) {
00121   if ( kapp && !kapp->authorizeKAction( name() ) )
00122     return -1;
00123   if ( widget->inherits( "KToolBar" ) ) {
00124     KToolBar *bar = (KToolBar *)widget;
00125     int id_ = getToolButtonID();
00126     bar->insertCombo( _lst, id_, false, SIGNAL( highlighted(int) ), _receiver, _member );
00127     bar->setCurrentComboItem( id_,_selectedId );
00128     addContainer( bar, id_ );
00129     connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
00130     return containerCount() - 1;
00131   }
00132 
00133   return KAction::plug( widget, index );
00134 }
00135 
00136 #include "customactions.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys