tdeaccelaction.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2001,2002 Ellis Whitehead <ellis@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef _TDEACCELACTION_H 00021 #define _TDEACCELACTION_H 00022 00023 #include <tqmap.h> 00024 #include <tqptrvector.h> 00025 #include <tqstring.h> 00026 #include <tqvaluevector.h> 00027 00028 #include <tdeshortcut.h> 00029 00030 class TDEAccelBase; 00031 00032 class TQObject; 00033 class TDEConfig; 00034 class TDEConfigBase; 00035 00072 class TDECORE_EXPORT TDEAccelAction 00073 { 00074 public: 00079 TDEAccelAction(); 00080 00084 TDEAccelAction( const TDEAccelAction& ); 00085 00100 TDEAccelAction( const TQString& sName, const TQString& sLabel, const TQString& sWhatsThis, 00101 const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, 00102 const TQObject* pObjSlot, const char* psMethodSlot, 00103 bool bConfigurable, bool bEnabled ); 00104 ~TDEAccelAction(); 00105 00109 void clear(); 00110 00126 bool init( const TQString& sName, const TQString& sLabel, const TQString& sWhatsThis, 00127 const TDEShortcut& cutDef3, const TDEShortcut& cutDef4, 00128 const TQObject* pObjSlot, const char* psMethodSlot, 00129 bool bConfigurable, bool bEnabled ); 00130 00134 TDEAccelAction& operator=( const TDEAccelAction& ); 00135 00141 const TQString& name() const { return m_sName; } 00142 00148 const TQString& label() const { return m_sLabel; } 00149 00155 const TQString& whatsThis() const { return m_sWhatsThis; } 00156 00162 const TDEShortcut& shortcut() const { return m_cut; } 00163 00171 const TDEShortcut& shortcutDefault() const; 00172 00181 const TDEShortcut& shortcutDefault3() const { return m_cutDefault3; } 00182 00191 const TDEShortcut& shortcutDefault4() const { return m_cutDefault4; } 00192 00197 const TQObject* objSlotPtr() const { return m_pObjSlot; } 00198 00203 const char* methodSlotPtr() const { return m_psMethodSlot; } 00204 00209 bool isConfigurable() const { return m_bConfigurable; } 00210 00215 bool isEnabled() const { return m_bEnabled; } 00216 00221 void setName( const TQString& name ); 00222 00227 void setLabel( const TQString& label ); 00228 00233 void setWhatsThis( const TQString& whatsThis ); 00234 00240 bool setShortcut( const TDEShortcut& rgCuts ); 00241 00247 void setSlot( const TQObject* pObjSlot, const char* psMethodSlot ); 00248 00253 void setConfigurable( bool configurable ); 00254 00259 void setEnabled( bool enable ); 00260 00265 int getID() const { return m_nIDAccel; } 00266 00274 void setID( int n ) { m_nIDAccel = n; } 00275 00280 bool isConnected() const; 00281 00289 bool setKeySequence( uint i, const KKeySequence &keySeq ); 00290 00296 void clearShortcut(); 00297 00304 bool contains( const KKeySequence &keySeq ); 00305 00311 TQString toString() const; 00312 00316 TQString toStringInternal() const; 00317 00322 static bool useFourModifierKeys(); 00323 00329 static void useFourModifierKeys( bool use ); 00330 00331 protected: 00332 TQString m_sName , 00333 m_sLabel , 00334 m_sWhatsThis ; 00335 TDEShortcut m_cut ; 00336 TDEShortcut m_cutDefault3 , 00337 m_cutDefault4 ; 00338 const TQObject* m_pObjSlot ; 00339 const char* m_psMethodSlot ; 00340 bool m_bConfigurable , 00341 m_bEnabled ; 00342 int m_nIDAccel ; 00343 uint m_nConnections ; 00344 00346 void incConnections(); 00348 void decConnections(); 00349 00350 private: 00351 static int g_bUseFourModifierKeys; 00352 class TDEAccelActionPrivate* d; 00353 00354 friend class TDEAccelActions; 00355 friend class TDEAccelBase; 00356 }; 00357 00358 //--------------------------------------------------------------------- 00359 // TDEAccelActions 00360 //--------------------------------------------------------------------- 00361 00369 class TDECORE_EXPORT TDEAccelActions 00370 { 00371 public: 00375 TDEAccelActions(); 00376 00380 TDEAccelActions( const TDEAccelActions& ); 00381 virtual ~TDEAccelActions(); 00382 00386 void clear(); 00387 00394 bool init( const TDEAccelActions &actions ); 00395 00403 bool init( TDEConfigBase& config, const TQString& sGroup ); 00404 00411 void updateShortcuts( TDEAccelActions &shortcuts ); 00412 00418 int actionIndex( const TQString& sAction ) const; 00419 00427 TDEAccelAction* actionPtr( uint index ); 00428 00436 const TDEAccelAction* actionPtr( uint index ) const; 00437 00444 TDEAccelAction* actionPtr( const TQString& sAction ); 00445 00452 const TDEAccelAction* actionPtr( const TQString& sAction ) const; 00453 00460 TDEAccelAction* actionPtr( KKeySequence cut ); 00461 00470 TDEAccelAction& operator []( uint index ); 00471 00480 const TDEAccelAction& operator []( uint index ) const; 00481 00497 TDEAccelAction* insert( const TQString& sAction, const TQString& sLabel, const TQString& sWhatsThis, 00498 const TDEShortcut& rgCutDefaults3, const TDEShortcut& rgCutDefaults4, 00499 const TQObject* pObjSlot = 0, const char* psMethodSlot = 0, 00500 bool bConfigurable = true, bool bEnabled = true ); 00501 00508 TDEAccelAction* insert( const TQString& sName, const TQString& sLabel ); 00509 00515 bool remove( const TQString& sAction ); 00516 00524 bool readActions( const TQString& sConfigGroup = "Shortcuts", TDEConfigBase* pConfig = 0 ); 00525 00535 bool writeActions( const TQString& sConfigGroup = "Shortcuts", TDEConfigBase* pConfig = 0, 00536 bool bWriteAll = false, bool bGlobal = false ) const; 00537 00541 void emitKeycodeChanged(); 00542 00547 uint count() const; 00548 00549 protected: 00551 TDEAccelBase* m_pTDEAccelBase; 00553 TDEAccelAction** m_prgActions; 00554 uint m_nSizeAllocated , 00555 m_nSize ; 00556 00562 void resize( uint new_size ); 00564 void insertPtr( TDEAccelAction* ); 00565 00566 private: 00567 class TDEAccelActionsPrivate* d; 00568 00569 TDEAccelActions( TDEAccelBase* ); 00570 void initPrivate( TDEAccelBase* ); 00571 TDEAccelActions& operator =( TDEAccelActions& ); 00572 00573 friend class TDEAccelBase; 00574 }; 00575 00576 #endif // _TDEACCELACTION_H