• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

kcompletionbase.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <QtCore/QMap>
00022 #include <QtCore/QObject>
00023 
00024 #include <kcompletion.h>
00025 
00026 class KCompletionBasePrivate
00027 {
00028 public:
00029     KCompletionBasePrivate()
00030       // Assign the default completion type to use.
00031       : m_iCompletionMode( KGlobalSettings::completionMode() )
00032       , m_delegate( 0 )
00033     {
00034     }
00035     ~KCompletionBasePrivate()
00036     {
00037         if( m_bAutoDelCompObj && m_pCompObj )
00038         {
00039             delete m_pCompObj;
00040         }
00041     }
00042     // Flag that determined whether the completion object
00043     // should be deleted when this object is destroyed.
00044     bool m_bAutoDelCompObj;
00045     // Determines whether this widget handles completion signals
00046     // internally or not
00047     bool m_bHandleSignals;
00048     // Determines whether this widget fires rotation signals
00049     bool m_bEmitSignals;
00050     // Stores the completion mode locally.
00051     KGlobalSettings::Completion m_iCompletionMode;
00052     // Pointer to Completion object.
00053     QPointer<KCompletion> m_pCompObj;
00054     // Keybindings
00055     KCompletionBase::KeyBindingMap m_keyMap;
00056     // we may act as a proxy to another KCompletionBase object
00057     KCompletionBase *m_delegate;
00058 };
00059 
00060 KCompletionBase::KCompletionBase()
00061     : d( new KCompletionBasePrivate )
00062 {
00063     // Initialize all key-bindings to 0 by default so that
00064     // the event filter will use the global settings.
00065     useGlobalKeyBindings();
00066 
00067     // By default we initialize everything except hsig to false.
00068     // All the variables would be setup properly when
00069     // the appropriate member functions are called.
00070     setup( false, true, false );
00071 }
00072 
00073 KCompletionBase::~KCompletionBase()
00074 {
00075     delete d;
00076 }
00077 
00078 void KCompletionBase::setDelegate( KCompletionBase *delegate )
00079 {
00080     d->m_delegate = delegate;
00081 
00082     if ( delegate ) {
00083         delegate->d->m_bAutoDelCompObj = d->m_bAutoDelCompObj;
00084         delegate->d->m_bHandleSignals  = d->m_bHandleSignals;
00085         delegate->d->m_bEmitSignals    = d->m_bEmitSignals;
00086         delegate->d->m_iCompletionMode = d->m_iCompletionMode;
00087         delegate->d->m_keyMap          = d->m_keyMap;
00088     }
00089 }
00090 
00091 KCompletionBase *KCompletionBase::delegate() const
00092 {
00093     return d->m_delegate;
00094 }
00095 
00096 KCompletion* KCompletionBase::completionObject( bool hsig )
00097 {
00098     if ( d->m_delegate )
00099         return d->m_delegate->completionObject( hsig );
00100     
00101     if ( !d->m_pCompObj )
00102     {
00103         setCompletionObject( new KCompletion(), hsig );
00104         d->m_bAutoDelCompObj = true;
00105     }
00106     return d->m_pCompObj;
00107 }
00108 
00109 void KCompletionBase::setCompletionObject( KCompletion* compObj, bool hsig )
00110 {
00111     if ( d->m_delegate ) {
00112         d->m_delegate->setCompletionObject( compObj, hsig );
00113         return;
00114     }
00115     
00116     if ( d->m_bAutoDelCompObj && compObj != d->m_pCompObj )
00117         delete d->m_pCompObj;
00118 
00119     d->m_pCompObj = compObj;
00120 
00121     // We emit rotation and completion signals
00122     // if completion object is not NULL.
00123     setup( false, hsig, !d->m_pCompObj.isNull() );
00124 }
00125 
00126 // BC: Inline this function and possibly rename it to setHandleEvents??? (DA)
00127 void KCompletionBase::setHandleSignals( bool handle )
00128 {
00129     if ( d->m_delegate )
00130         d->m_delegate->setHandleSignals( handle );
00131     else
00132         d->m_bHandleSignals = handle;
00133 }
00134 
00135 bool KCompletionBase::isCompletionObjectAutoDeleted() const
00136 {
00137     return d->m_delegate ? d->m_delegate->isCompletionObjectAutoDeleted()
00138                       : d->m_bAutoDelCompObj;
00139 }
00140 
00141 void KCompletionBase::setAutoDeleteCompletionObject( bool autoDelete )
00142 {
00143     if ( d->m_delegate )
00144         d->m_delegate->setAutoDeleteCompletionObject( autoDelete );
00145     else
00146         d->m_bAutoDelCompObj = autoDelete;
00147 }
00148 
00149 void KCompletionBase::setEnableSignals( bool enable )
00150 {
00151     if ( d->m_delegate )
00152         d->m_delegate->setEnableSignals( enable );
00153     else
00154         d->m_bEmitSignals = enable;
00155 }
00156 
00157 bool KCompletionBase::handleSignals() const
00158 {
00159     return d->m_delegate ? d->m_delegate->handleSignals() : d->m_bHandleSignals;
00160 }
00161 
00162 bool KCompletionBase::emitSignals() const
00163 {
00164     return d->m_delegate ? d->m_delegate->emitSignals() : d->m_bEmitSignals;
00165 }
00166 
00167 void KCompletionBase::setCompletionMode( KGlobalSettings::Completion mode )
00168 {
00169     if ( d->m_delegate ) {
00170         d->m_delegate->setCompletionMode( mode );
00171         return;
00172     }
00173     
00174     d->m_iCompletionMode = mode;
00175     // Always sync up KCompletion mode with ours as long as we
00176     // are performing completions.
00177     if( d->m_pCompObj && d->m_iCompletionMode != KGlobalSettings::CompletionNone )
00178         d->m_pCompObj->setCompletionMode( d->m_iCompletionMode );
00179 }
00180 
00181 KGlobalSettings::Completion KCompletionBase::completionMode() const
00182 {
00183     return d->m_delegate ? d->m_delegate->completionMode() : d->m_iCompletionMode;
00184 }
00185 
00186 bool KCompletionBase::setKeyBinding( KeyBindingType item, const KShortcut& cut )
00187 {
00188     if ( d->m_delegate )
00189         return d->m_delegate->setKeyBinding( item, cut );
00190 
00191 
00192     if( !cut.isEmpty() )
00193     {
00194         for( KeyBindingMap::Iterator it = d->m_keyMap.begin(); it != d->m_keyMap.end(); ++it )
00195             if( it.value() == cut )  return false;
00196     }
00197     d->m_keyMap.insert( item, cut );
00198     return true;
00199 }
00200 
00201 KShortcut KCompletionBase::getKeyBinding( KeyBindingType item ) const
00202 {
00203     return d->m_delegate ? d->m_delegate->getKeyBinding( item ) : d->m_keyMap[ item ];
00204 }
00205 
00206 void KCompletionBase::useGlobalKeyBindings()
00207 {
00208     if ( d->m_delegate ) {
00209         d->m_delegate->useGlobalKeyBindings();
00210         return;
00211     }
00212     
00213     d->m_keyMap.clear();
00214     d->m_keyMap.insert( TextCompletion, KShortcut() );
00215     d->m_keyMap.insert( PrevCompletionMatch, KShortcut() );
00216     d->m_keyMap.insert( NextCompletionMatch, KShortcut() );
00217     d->m_keyMap.insert( SubstringCompletion, KShortcut() );
00218 }
00219 
00220 KCompletion* KCompletionBase::compObj() const
00221 {
00222     return d->m_delegate ? d->m_delegate->compObj()
00223                       : static_cast<KCompletion*>(d->m_pCompObj);
00224 }
00225 
00226 KCompletionBase::KeyBindingMap KCompletionBase::getKeyBindings() const
00227 {
00228     return d->m_delegate ? d->m_delegate->getKeyBindings() : d->m_keyMap;
00229 }
00230 
00231 void KCompletionBase::setup( bool autodel, bool hsig, bool esig )
00232 {
00233     if ( d->m_delegate ) {
00234         d->m_delegate->setup( autodel, hsig, esig );
00235         return;
00236     }
00237     
00238     d->m_bAutoDelCompObj = autodel;
00239     d->m_bHandleSignals = hsig;
00240     d->m_bEmitSignals = esig;
00241 }
00242 
00243 void KCompletionBase::virtual_hook( int, void* )
00244 { /*BASE::virtual_hook( id, data );*/ }
00245 

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal