KDevelop API Documentation

lib/compat/kdevwidgetaction.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * * 00003 * This program is free software; you can redistribute it and/or modify * 00004 * it under the terms of the GNU General Public License as published by * 00005 * the Free Software Foundation; either version 2 of the License, or * 00006 * (at your option) any later version. * 00007 * * 00008 ***************************************************************************/ 00009 00010 #include "kdevwidgetaction.h" 00011 00012 #if !(KDE_VERSION > 305) 00013 00014 #include <ktoolbar.h> 00015 #include <kdebug.h> 00016 #include <kapplication.h> 00017 00018 namespace KDevCompat { 00019 00020 //--------------------begin-of-copy-of-kde-3.1----------- 00021 KWidgetAction::KWidgetAction( QWidget* widget, 00022 const QString& text, const KShortcut& cut, 00023 const QObject* receiver, const char* slot, 00024 KActionCollection* parent, const char* name ) 00025 : KAction( text, cut, receiver, slot, parent, name ) 00026 , m_widget( widget ) 00027 , m_autoSized( false ) 00028 { 00029 } 00030 00031 KWidgetAction::~KWidgetAction() 00032 { 00033 } 00034 00035 void KWidgetAction::setAutoSized( bool autoSized ) 00036 { 00037 if( m_autoSized == autoSized ) 00038 return; 00039 00040 m_autoSized = autoSized; 00041 00042 if( !m_widget || !isPlugged() ) 00043 return; 00044 00045 KToolBar* toolBar = (KToolBar*)m_widget->parent(); 00046 int i = findContainer( toolBar ); 00047 if ( i == -1 ) 00048 return; 00049 int id = itemId( i ); 00050 00051 toolBar->setItemAutoSized( id, m_autoSized ); 00052 } 00053 00054 int KWidgetAction::plug( QWidget* w, int index ) 00055 { 00056 if (kapp && !kapp->authorizeKAction(name())) 00057 return -1; 00058 00059 if ( !w->inherits( "KToolBar" ) ) { 00060 kdError() << "KWidgetAction::plug: KWidgetAction must be plugged into KToolBar." << endl; 00061 return -1; 00062 } 00063 if ( !m_widget ) { 00064 kdError() << "KWidgetAction::plug: Widget was deleted or null!" << endl; 00065 return -1; 00066 } 00067 00068 KToolBar* toolBar = static_cast<KToolBar*>( w ); 00069 00070 int id = KAction::getToolButtonID(); 00071 00072 m_widget->reparent( toolBar, QPoint() ); 00073 toolBar->insertWidget( id, 0, m_widget, index ); 00074 toolBar->setItemAutoSized( id, m_autoSized ); 00075 00076 addContainer( toolBar, id ); 00077 00078 connect( toolBar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); 00079 00080 return containerCount() - 1; 00081 } 00082 00083 void KWidgetAction::unplug( QWidget *w ) 00084 { 00085 // ### shouldn't this method check if w == m_widget->parent() ? (Simon) 00086 if( !m_widget ) 00087 return; 00088 00089 m_widget->reparent( 0L, QPoint(), false /*showIt*/ ); 00090 00091 KAction::unplug( w ); 00092 } 00093 00094 00095 void KWidgetAction::virtual_hook( int id, void* data ) 00096 { KAction::virtual_hook( id, data ); } 00097 00098 //--------------------end-of-copy-of-kde-3.1----------- 00099 00100 }; //namespace 00101 00102 #include "kdevwidgetaction.moc" 00103 00104 #endif // !(KDE_VERSION > 305) 00105
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:07 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003