kaction.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org> 00003 (C) 1999 Simon Hausmann <hausmann@kde.org> 00004 (C) 2000 Nicolas Hadacek <haadcek@kde.org> 00005 (C) 2000 Kurt Granroth <granroth@kde.org> 00006 (C) 2000 Michael Koch <koch@kde.org> 00007 (C) 2001 Holger Freyther <freyther@kde.org> 00008 (C) 2002 Ellis Whitehead <ellis@kde.org> 00009 00010 This library is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU Library General Public 00012 License version 2 as published by the Free Software Foundation. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Library General Public License for more details. 00018 00019 You should have received a copy of the GNU Library General Public License 00020 along with this library; see the file COPYING.LIB. If not, write to 00021 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00022 Boston, MA 02110-1301, USA. 00023 */ 00024 //$Id$ 00025 00026 #ifndef __kaction_h__ 00027 #define __kaction_h__ 00028 00029 #include <tqkeysequence.h> 00030 #include <tqobject.h> 00031 #include <tqvaluelist.h> 00032 #include <tqguardedptr.h> 00033 #include <kguiitem.h> 00034 #include <kshortcut.h> 00035 #include <kstdaction.h> 00036 #include <kicontheme.h> 00037 00038 class TQMenuBar; 00039 class TQPopupMenu; 00040 class TQComboBox; 00041 class TQPoint; 00042 class TQIconSet; 00043 class TQString; 00044 class KToolBar; 00045 00046 class KAccel; 00047 class KAccelActions; 00048 class KConfig; 00049 class KConfigBase; 00050 class KURL; 00051 class KInstance; 00052 class KToolBar; 00053 class KActionCollection; 00054 class KPopupMenu; 00055 class KMainWindow; 00056 00202 class KDEUI_EXPORT KAction : public TQObject 00203 { 00204 friend class KActionCollection; 00205 Q_OBJECT 00206 Q_PROPERTY( int containerCount READ containerCount ) 00207 Q_PROPERTY( TQString plainText READ plainText ) 00208 Q_PROPERTY( TQString text READ text WRITE setText ) 00209 Q_PROPERTY( TQString shortcut READ shortcutText WRITE setShortcutText ) 00210 Q_PROPERTY( bool enabled READ isEnabled WRITE setEnabled ) 00211 Q_PROPERTY( TQString group READ group WRITE setGroup ) 00212 Q_PROPERTY( TQString whatsThis READ whatsThis WRITE setWhatsThis ) 00213 Q_PROPERTY( TQString toolTip READ toolTip WRITE setToolTip ) 00214 Q_PROPERTY( TQString icon READ icon WRITE setIcon ) 00215 public: 00236 KAction( const TQString& text, const KShortcut& cut, 00237 const TQObject* receiver, const char* slot, 00238 KActionCollection* parent, const char* name ); 00239 00259 KAction( const TQString& text, const TQIconSet& pix, const KShortcut& cut, 00260 const TQObject* receiver, const char* slot, 00261 KActionCollection* parent, const char* name ); 00262 00283 KAction( const TQString& text, const TQString& pix, const KShortcut& cut, 00284 const TQObject* receiver, const char* slot, 00285 KActionCollection* parent, const char* name ); 00286 00298 KAction( const KGuiItem& item, const KShortcut& cut, 00299 const TQObject* receiver, const char* slot, 00300 KActionCollection* parent, const char* name ); 00301 00305 KAction( const TQString& text, const KShortcut& cut = KShortcut(), TQObject* parent = 0, const char* name = 0 ); 00309 KAction( const TQString& text, const KShortcut& cut, 00310 const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); 00314 KAction( const TQString& text, const TQIconSet& pix, const KShortcut& cut = KShortcut(), 00315 TQObject* parent = 0, const char* name = 0 ); 00319 KAction( const TQString& text, const TQString& pix, const KShortcut& cut = KShortcut(), 00320 TQObject* parent = 0, const char* name = 0 ); 00324 KAction( const TQString& text, const TQIconSet& pix, const KShortcut& cut, 00325 const TQObject* receiver, const char* slot, TQObject* parent, const char* name = 0 ); 00329 KAction( const TQString& text, const TQString& pix, const KShortcut& cut, 00330 const TQObject* receiver, const char* slot, TQObject* parent, 00331 const char* name = 0 ); 00335 KAction( TQObject* parent = 0, const char* name = 0 ); 00336 00340 virtual ~KAction(); 00341 00355 virtual int plug( TQWidget *widget, int index = -1 ); 00356 00367 virtual void plugAccel(KAccel *accel, bool configurable = true) KDE_DEPRECATED; 00368 00381 virtual void unplug( TQWidget *w ); 00382 00387 virtual void unplugAccel() KDE_DEPRECATED; 00388 00393 virtual bool isPlugged() const; 00394 00398 bool isPlugged( const TQWidget *container ) const; 00399 00404 virtual bool isPlugged( const TQWidget *container, int id ) const; 00405 00410 virtual bool isPlugged( const TQWidget *container, const TQWidget *_representative ) const; 00411 00412 TQWidget* container( int index ) const; 00413 int itemId( int index ) const; 00414 TQWidget* representative( int index ) const; 00415 int containerCount() const; 00417 uint kaccelCount() const; 00418 00419 virtual bool hasIcon() const; 00420 #ifndef KDE_NO_COMPAT 00421 bool hasIconSet() const { return hasIcon(); } 00422 #endif 00423 virtual TQString plainText() const; 00424 00428 virtual TQString text() const; 00429 00433 virtual const KShortcut& shortcut() const; 00437 virtual const KShortcut& shortcutDefault() const; 00438 00439 // These two methods are for Q_PROPERTY 00440 TQString shortcutText() const; 00441 void setShortcutText( const TQString& ); 00442 00446 virtual bool isEnabled() const; 00447 00451 virtual bool isShortcutConfigurable() const; 00452 00453 virtual TQString group() const; 00454 00458 virtual TQString whatsThis() const; 00459 00463 virtual TQString toolTip() const; 00464 00472 virtual TQIconSet iconSet( KIcon::Group group, int size=0 ) const; 00476 TQIconSet iconSet() const { return iconSet( KIcon::Small ); } 00477 00478 virtual TQString icon() const; 00479 00480 KActionCollection *parentCollection() const; 00481 00486 static int getToolButtonID(); 00487 00488 00489 void unplugAll(); 00490 00494 enum ActivationReason { UnknownActivation, EmulatedActivation, AccelActivation, PopupMenuActivation, ToolBarActivation }; 00495 00496 public slots: 00501 virtual void setText(const TQString &text); 00502 00506 virtual bool setShortcut( const KShortcut& ); 00507 00508 virtual void setGroup( const TQString& ); 00509 00517 virtual void setWhatsThis( const TQString& text ); 00518 00533 virtual void setToolTip( const TQString& ); 00534 00539 virtual void setIconSet( const TQIconSet &iconSet ); 00540 00541 virtual void setIcon( const TQString& icon ); 00542 00547 virtual void setEnabled(bool enable); 00548 00553 void setDisabled(bool disable) { return setEnabled(!disable); } 00554 00558 virtual void setShortcutConfigurable( bool ); 00559 00564 virtual void activate(); 00565 00566 protected slots: 00567 virtual void slotDestroyed(); 00568 virtual void slotKeycodeChanged(); 00569 virtual void slotActivated(); 00571 void slotPopupActivated(); // KDE4: make virtual 00573 void slotButtonClicked( int, TQt::ButtonState state ); // KDE4: make virtual 00574 00575 protected: 00576 KToolBar* toolBar( int index ) const; 00577 TQPopupMenu* popupMenu( int index ) const; 00578 void removeContainer( int index ); 00579 int findContainer( const TQWidget* widget ) const; 00580 int findContainer( int id ) const; 00581 void plugMainWindowAccel( TQWidget *w ); 00582 00583 void addContainer( TQWidget* parent, int id ); 00584 void addContainer( TQWidget* parent, TQWidget* representative ); 00585 00586 virtual void updateShortcut( int i ); 00587 virtual void updateShortcut( TQPopupMenu* menu, int id ); 00588 virtual void updateGroup( int id ); 00589 virtual void updateText(int i ); 00590 virtual void updateEnabled(int i); 00591 virtual void updateIconSet(int i); 00592 virtual void updateIcon( int i); 00593 virtual void updateToolTip( int id ); 00594 virtual void updateWhatsThis( int i ); 00595 00596 KActionCollection *m_parentCollection; 00597 TQString whatsThisWithIcon() const; 00602 const KGuiItem& guiItem() const; 00603 00604 signals: 00608 void activated(); 00623 void activated( KAction::ActivationReason reason, TQt::ButtonState state ); 00624 void enabled( bool ); 00625 00626 private: 00627 void initPrivate( const TQString& text, const KShortcut& cut, 00628 const TQObject* receiver, const char* slot ); 00629 KAccel* kaccelCurrent(); 00630 bool initShortcut( const KShortcut& ); 00631 void plugShortcut(); 00632 bool updateKAccelShortcut( KAccel* kaccel ); 00633 void insertKAccel( KAccel* ); 00635 void removeKAccel( KAccel* ); 00636 00637 #ifndef KDE_NO_COMPAT 00638 public: 00643 int accel() const KDE_DEPRECATED; 00644 00645 TQString statusText() const 00646 { return toolTip(); } 00647 00652 void setAccel( int key ) KDE_DEPRECATED; 00653 00657 void setStatusText( const TQString &text ) 00658 { setToolTip( text ); } 00659 00663 int menuId( int i ) { return itemId( i ); } 00664 #endif // !KDE_NO_COMPAT 00665 00666 protected: 00667 virtual void virtual_hook( int id, void* data ); 00668 private: 00669 class KActionPrivate; 00670 KActionPrivate* const d; 00671 }; 00672 00673 #include <kactioncollection.h> 00674 #include <kactionclasses.h> 00675 00676 #endif