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 TQt library by Trolltech AS, Norway (or with modified versions 00024 of TQt that use the same license as TQt), 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 TQt. 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 <tqlineedit.h> 00039 #include <tqlabel.h> 00040 00041 00042 LabelAction::LabelAction( const TQString & text, KActionCollection * parent, 00043 const char* name ) 00044 : KAction( text, TQIconSet(), KShortcut(), 0, 0, parent, name ) 00045 { 00046 00047 } 00048 00049 int LabelAction::plug( TQWidget * 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 TQLabel* label = new TQLabel( text(), bar, "kde toolbar widget" ); 00056 bar->insertWidget( id_, label->width(), label, index ); 00057 addContainer( bar, id_ ); 00058 connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); 00059 return containerCount() - 1; 00060 } 00061 00062 return KAction::plug( widget, index ); 00063 } 00064 00065 LineEditAction::LineEditAction( const TQString & text, KActionCollection * parent, 00066 TQObject * receiver, const char * member, const char * name ) 00067 : KAction( text, TQIconSet(), KShortcut(), 0, 0, parent, name ), 00068 _le(0), _receiver(receiver), _member(member) 00069 { 00070 00071 } 00072 00073 int LineEditAction::plug( TQWidget * 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 TQLineEdit( bar, "kde toolbar widget" ); 00081 _le = new TQLineEdit( bar ); 00082 bar->insertWidget( id_, _le->width(), _le, index ); 00083 bar->setStretchableWidget( _le ); 00084 addContainer( bar, id_ ); 00085 connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); 00086 connect( _le, TQT_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 TQString LineEditAction::text() const { 00103 return _le->text(); 00104 } 00105 00106 void LineEditAction::setText( const TQString & txt ) { 00107 _le->setText(txt); 00108 } 00109 00110 00111 ComboAction::ComboAction( const TQStringList & lst, KActionCollection * parent, 00112 TQObject * receiver, const char * member, const char * name, 00113 int selectedID ) 00114 : KAction( TQString(), TQIconSet(), KShortcut(), 0, 0, parent, name ), 00115 _lst(lst), _receiver(receiver), _member(member), _selectedId( selectedID ) 00116 { 00117 00118 } 00119 00120 int ComboAction::plug( TQWidget * 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, TQT_SIGNAL( highlighted(int) ), _receiver, _member ); 00127 bar->setCurrentComboItem( id_,_selectedId ); 00128 addContainer( bar, id_ ); 00129 connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); 00130 return containerCount() - 1; 00131 } 00132 00133 return KAction::plug( widget, index ); 00134 } 00135 00136 #include "customactions.moc"