kdecore Library: kcompletionbase.cpp Source File (kdecore Library)

| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kcompletionbase.cpp

    00001 /* This file is part of the KDE libraries
    00002
    00003    Copyright (c) 2000 Dawit Alemayehu <adawit@kde.org>
    00004
    00005    This library is free software; you can redistribute it and/or
    00006    modify it under the terms of the GNU Library General Public
    00007    License (LGPL) as published by the Free Software Foundation; either
    00008    version 2 of the License, or (at your option) any later version.
    00009
    00010    This library is distributed in the hope that it will be useful,
    00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013    Library General Public License for more details.
    00014
    00015    You should have received a copy of the GNU Library General Public License
    00016    along with this library; see the file COPYING.LIB.  If not, write to
    00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018    Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 #include <qobject.h>
    00022
    00023 #include <kcompletion.h>
    00024
    00025 KCompletionBase::KCompletionBase()
    00026 {
    00027     m_delegate = 0L;
    00028     // Assign the default completion type to use.
    00029     m_iCompletionMode = KGlobalSettings::completionMode();
    00030
    00031     // Initialize all key-bindings to 0 by default so that
    00032     // the event filter will use the global settings.
    00033     useGlobalKeyBindings();
    00034
    00035     // By default we initialize everything to false.
    00036     // All the variables would be setup properly when
    00037     // the appropriate member functions are called.
    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     // We emit rotation and completion signals
    00088     // if completion object is not NULL.
    00089     setup( false, hsig, !m_pCompObj.isNull() );
    00090 }
    00091
    00092 // BC: Inline this function and possibly rename it to setHandleEvents??? (DA)
    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     // Always sync up KCompletion mode with ours as long as we
    00110     // are performing completions.
    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 }

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:02 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003