KDECore
kcompletionbase.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qobject.h>
00022
00023 #include <kcompletion.h>
00024
00025 KCompletionBase::KCompletionBase()
00026 {
00027 m_delegate = 0L;
00028
00029 m_iCompletionMode = KGlobalSettings::completionMode();
00030
00031
00032
00033 useGlobalKeyBindings();
00034
00035
00036
00037
00038 setup( false, false, false );
00039 }
00040
00041 KCompletionBase::~KCompletionBase()
00042 {
00043 if( m_bAutoDelCompObj && m_pCompObj )
00044 {
00045 delete m_pCompObj;
00046 }
00047 }
00048
00049 void KCompletionBase::setDelegate( KCompletionBase *delegate )
00050 {
00051 m_delegate = delegate;
00052
00053 if ( m_delegate ) {
00054 m_delegate->m_bAutoDelCompObj = m_bAutoDelCompObj;
00055 m_delegate->m_bHandleSignals = m_bHandleSignals;
00056 m_delegate->m_bEmitSignals = m_bEmitSignals;
00057 m_delegate->m_iCompletionMode = m_iCompletionMode;
00058 m_delegate->m_keyMap = m_keyMap;
00059 }
00060 }
00061
00062 KCompletion* KCompletionBase::completionObject( bool hsig )
00063 {
00064 if ( m_delegate )
00065 return m_delegate->completionObject( hsig );
00066
00067 if ( !m_pCompObj )
00068 {
00069 setCompletionObject( new KCompletion(), hsig );
00070 m_bAutoDelCompObj = true;
00071 }
00072 return m_pCompObj;
00073 }
00074
00075 void KCompletionBase::setCompletionObject( KCompletion* compObj, bool hsig )
00076 {
00077 if ( m_delegate ) {
00078 m_delegate->setCompletionObject( compObj, hsig );
00079 return;
00080 }
00081
00082 if ( m_bAutoDelCompObj && compObj != m_pCompObj )
00083 delete m_pCompObj;
00084
00085 m_pCompObj = compObj;
00086
00087
00088
00089 setup( false, hsig, !m_pCompObj.isNull() );
00090 }
00091
00092
00093 void KCompletionBase::setHandleSignals( bool handle )
00094 {
00095 if ( m_delegate )
00096 m_delegate->setHandleSignals( handle );
00097 else
00098 m_bHandleSignals = handle;
00099 }
00100
00101 void KCompletionBase::setCompletionMode( KGlobalSettings::Completion mode )
00102 {
00103 if ( m_delegate ) {
00104 m_delegate->setCompletionMode( mode );
00105 return;
00106 }
00107
00108 m_iCompletionMode = mode;
00109
00110
00111 if( m_pCompObj && m_iCompletionMode != KGlobalSettings::CompletionNone )
00112 m_pCompObj->setCompletionMode( m_iCompletionMode );
00113 }
00114
00115 bool KCompletionBase::setKeyBinding( KeyBindingType item, const KShortcut& cut )
00116 {
00117 if ( m_delegate )
00118 return m_delegate->setKeyBinding( item, cut );
00119
00120
00121 if( !cut.isNull() )
00122 {
00123 for( KeyBindingMap::Iterator it = m_keyMap.begin(); it != m_keyMap.end(); ++it )
00124 if( it.data() == cut ) return false;
00125 }
00126 m_keyMap.replace( item, cut );
00127 return true;
00128 }
00129
00130 void KCompletionBase::useGlobalKeyBindings()
00131 {
00132 if ( m_delegate ) {
00133 m_delegate->useGlobalKeyBindings();
00134 return;
00135 }
00136
00137 m_keyMap.clear();
00138 m_keyMap.insert( TextCompletion, 0 );
00139 m_keyMap.insert( PrevCompletionMatch, 0 );
00140 m_keyMap.insert( NextCompletionMatch, 0 );
00141 m_keyMap.insert( SubstringCompletion, 0 );
00142 }
00143
00144 void KCompletionBase::setup( bool autodel, bool hsig, bool esig )
00145 {
00146 if ( m_delegate ) {
00147 m_delegate->setup( autodel, hsig, esig );
00148 return;
00149 }
00150
00151 m_bAutoDelCompObj = autodel;
00152 m_bHandleSignals = hsig;
00153 m_bEmitSignals = esig;
00154 }