kmdi Library API Documentation

kmditoolviewaccessor.cpp

00001 //---------------------------------------------------------------------------- 00002 // filename : kmditoolviewaccessor.h 00003 //---------------------------------------------------------------------------- 00004 // Project : KDE MDI extension 00005 // 00006 // begin : 08/2003 by Joseph Wenninger (jowenn@kde.org) 00007 // changes : --- 00008 // patches : --- 00009 // 00010 // copyright : (C) 2003 by Joseph Wenninger (jowenn@kde.org) 00011 //---------------------------------------------------------------------------- 00012 // 00013 //---------------------------------------------------------------------------- 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU Library General Public License as 00017 // published by the Free Software Foundation; either version 2 of the 00018 // License, or (at your option) any later version. 00019 // 00020 //---------------------------------------------------------------------------- 00021 00022 #ifndef NO_KDE 00023 # include <kdebug.h> 00024 #endif 00025 #include "kmditoolviewaccessor_p.h" 00026 #include "kmdiguiclient.h" 00027 #include "kmdimainfrm.h" 00028 00029 #include "kmditoolviewaccessor.h" 00030 #include "kmditoolviewaccessor_p.h" 00031 00032 KMdiToolViewAccessor::KMdiToolViewAccessor( KMdiMainFrm *parent, QWidget *widgetToWrap, const QString& tabToolTip, const QString& tabCaption ) 00033 : QObject( parent ) 00034 { 00035 mdiMainFrm = parent; 00036 d = new KMdiToolViewAccessorPrivate(); 00037 if ( widgetToWrap->inherits( "KDockWidget" ) ) 00038 { 00039 d->widgetContainer = dynamic_cast<KDockWidget*>( widgetToWrap ); 00040 d->widget = d->widgetContainer->getWidget(); 00041 } 00042 else 00043 { 00044 d->widget = widgetToWrap; 00045 QString finalTabCaption; 00046 if ( tabCaption == 0 ) 00047 { 00048 finalTabCaption = widgetToWrap->caption(); 00049 if ( finalTabCaption.isEmpty() && !widgetToWrap->icon() ) 00050 { 00051 finalTabCaption = widgetToWrap->name(); 00052 } 00053 } 00054 else 00055 { 00056 finalTabCaption = tabCaption; 00057 } 00058 d->widgetContainer = parent->createDockWidget( widgetToWrap->name(), 00059 ( widgetToWrap->icon() ? ( *( widgetToWrap->icon() ) ) : QPixmap() ), 00060 0L, // parent 00061 widgetToWrap->caption(), 00062 finalTabCaption ); 00063 d->widgetContainer->setWidget( widgetToWrap ); 00064 if ( tabToolTip != 0 ) 00065 { 00066 d->widgetContainer->setToolTipString( tabToolTip ); 00067 } 00068 } 00069 //mdiMainFrm->m_pToolViews->insert(d->widget,this); 00070 if ( mdiMainFrm->m_mdiGUIClient ) 00071 mdiMainFrm->m_mdiGUIClient->addToolView( this ); 00072 else 00073 kdDebug( 760 ) << "mdiMainFrm->m_mdiGUIClient == 0 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 00074 00075 d->widget->installEventFilter( this ); 00076 } 00077 00078 KMdiToolViewAccessor::KMdiToolViewAccessor( KMdiMainFrm *parent ) 00079 { 00080 mdiMainFrm = parent; 00081 d = new KMdiToolViewAccessorPrivate(); 00082 } 00083 00084 KMdiToolViewAccessor::~KMdiToolViewAccessor() 00085 { 00086 if ( mdiMainFrm->m_pToolViews ) 00087 mdiMainFrm->m_pToolViews->remove 00088 ( d->widget ); 00089 delete d; 00090 00091 } 00092 00093 QWidget *KMdiToolViewAccessor::wrapperWidget() 00094 { 00095 if ( !d->widgetContainer ) 00096 { 00097 d->widgetContainer = mdiMainFrm->createDockWidget( "KMdiToolViewAccessor::null", QPixmap() ); 00098 connect( d->widgetContainer, SIGNAL( widgetSet( QWidget* ) ), this, SLOT( setWidgetToWrap( QWidget* ) ) ); 00099 } 00100 return d->widgetContainer; 00101 } 00102 00103 QWidget *KMdiToolViewAccessor::wrappedWidget() 00104 { 00105 return d->widget; 00106 } 00107 00108 00109 void KMdiToolViewAccessor::setWidgetToWrap( QWidget *widgetToWrap, const QString& tabToolTip, const QString& tabCaption ) 00110 { 00111 Q_ASSERT( !( d->widget ) ); 00112 Q_ASSERT( !widgetToWrap->inherits( "KDockWidget" ) ); 00113 disconnect( d->widgetContainer, SIGNAL( widgetSet( QWidget* ) ), this, SLOT( setWidgetToWrap( QWidget* ) ) ); 00114 delete d->widget; 00115 d->widget = widgetToWrap; 00116 KDockWidget *tmp = d->widgetContainer; 00117 00118 QString finalTabCaption; 00119 if ( tabCaption == 0 ) 00120 { 00121 finalTabCaption = widgetToWrap->caption(); 00122 if ( finalTabCaption.isEmpty() && !widgetToWrap->icon() ) 00123 { 00124 finalTabCaption = widgetToWrap->name(); 00125 } 00126 } 00127 else 00128 { 00129 finalTabCaption = tabCaption; 00130 } 00131 00132 if ( !tmp ) 00133 { 00134 tmp = mdiMainFrm->createDockWidget( widgetToWrap->name(), 00135 widgetToWrap->icon() ? ( *( widgetToWrap->icon() ) ) : QPixmap(), 00136 0L, // parent 00137 widgetToWrap->caption(), 00138 finalTabCaption ); 00139 d->widgetContainer = tmp; 00140 if ( tabToolTip != 0 ) 00141 { 00142 d->widgetContainer->setToolTipString( tabToolTip ); 00143 } 00144 } 00145 else 00146 { 00147 tmp->setCaption( widgetToWrap->caption() ); 00148 tmp->setTabPageLabel( finalTabCaption ); 00149 tmp->setPixmap( widgetToWrap->icon() ? ( *( widgetToWrap->icon() ) ) : QPixmap() ); 00150 tmp->setName( widgetToWrap->name() ); 00151 if ( tabToolTip != 0 ) 00152 { 00153 d->widgetContainer->setToolTipString( tabToolTip ); 00154 } 00155 } 00156 tmp->setWidget( widgetToWrap ); 00157 mdiMainFrm->m_pToolViews->insert( widgetToWrap, this ); 00158 if ( mdiMainFrm->m_mdiGUIClient ) 00159 mdiMainFrm->m_mdiGUIClient->addToolView( this ); 00160 else 00161 kdDebug( 760 ) << "mdiMainFrm->m_mdiGUIClient == 0 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 00162 00163 d->widget->installEventFilter( this ); 00164 } 00165 00166 00167 bool KMdiToolViewAccessor::eventFilter( QObject *, QEvent *e ) 00168 { 00169 if ( e->type() == QEvent::IconChange ) 00170 { 00171 d->widgetContainer->setPixmap( d->widget->icon() ? ( *d->widget->icon() ) : QPixmap() ); 00172 } 00173 return false; 00174 } 00175 00176 void KMdiToolViewAccessor::placeAndShow( KDockWidget::DockPosition pos, QWidget* pTargetWnd , int percent ) 00177 { 00178 place( pos, pTargetWnd, percent ); 00179 show(); 00180 } 00181 void KMdiToolViewAccessor::place( KDockWidget::DockPosition pos, QWidget* pTargetWnd , int percent ) 00182 { 00183 Q_ASSERT( d->widgetContainer ); 00184 if ( !d->widgetContainer ) 00185 return ; 00186 if ( pos == KDockWidget::DockNone ) 00187 { 00188 d->widgetContainer->setEnableDocking( KDockWidget::DockNone ); 00189 d->widgetContainer->reparent( mdiMainFrm, Qt::WType_TopLevel | Qt::WType_Dialog, QPoint( 0, 0 ), true ); //pToolView->isVisible()); 00190 } 00191 else 00192 { // add (and dock) the toolview as DockWidget view 00193 00194 KDockWidget* pCover = d->widgetContainer; 00195 00196 KDockWidget* pTargetDock = 0L; 00197 if ( pTargetWnd->inherits( "KDockWidget" ) || pTargetWnd->inherits( "KDockWidget_Compat::KDockWidget" ) ) 00198 { 00199 pTargetDock = ( KDockWidget* ) pTargetWnd; 00200 } 00201 00202 // Should we dock to ourself? 00203 bool DockToOurself = false; 00204 if ( mdiMainFrm->m_pDockbaseAreaOfDocumentViews ) 00205 { 00206 if ( pTargetWnd == mdiMainFrm->m_pDockbaseAreaOfDocumentViews->getWidget() ) 00207 { 00208 DockToOurself = true; 00209 pTargetDock = mdiMainFrm->m_pDockbaseAreaOfDocumentViews; 00210 } 00211 else if ( pTargetWnd == mdiMainFrm->m_pDockbaseAreaOfDocumentViews ) 00212 { 00213 DockToOurself = true; 00214 pTargetDock = mdiMainFrm->m_pDockbaseAreaOfDocumentViews; 00215 } 00216 } 00217 // this is not inheriting QWidget*, its plain impossible that this condition is true 00218 //if (pTargetWnd == this) DockToOurself = true; 00219 if ( !DockToOurself ) 00220 if ( pTargetWnd != 0L ) 00221 { 00222 pTargetDock = mdiMainFrm->dockManager->findWidgetParentDock( pTargetWnd ); 00223 if ( !pTargetDock ) 00224 { 00225 if ( pTargetWnd->parentWidget() ) 00226 { 00227 pTargetDock = mdiMainFrm->dockManager->findWidgetParentDock( pTargetWnd->parentWidget() ); 00228 } 00229 } 00230 } 00231 if ( !pTargetDock || pTargetWnd == mdiMainFrm->getMainDockWidget() ) 00232 { 00233 if ( mdiMainFrm->m_managedDockPositionMode && ( mdiMainFrm->m_pMdi || mdiMainFrm->m_documentTabWidget ) ) 00234 { 00235 KDockWidget * dw1 = pTargetDock->findNearestDockWidget( pos ); 00236 if ( dw1 ) 00237 pCover->manualDock( dw1, KDockWidget::DockCenter, percent ); 00238 else 00239 pCover->manualDock ( pTargetDock, pos, 20 ); 00240 return ; 00241 } 00242 } 00243 pCover->manualDock( pTargetDock, pos, percent ); 00244 //check pCover->show(); 00245 } 00246 } 00247 00248 void KMdiToolViewAccessor::hide() 00249 { 00250 Q_ASSERT( d->widgetContainer ); 00251 if ( !d->widgetContainer ) 00252 return ; 00253 d->widgetContainer->undock(); 00254 } 00255 00256 void KMdiToolViewAccessor::show() 00257 { 00258 Q_ASSERT( d->widgetContainer ); 00259 if ( !d->widgetContainer ) 00260 return ; 00261 d->widgetContainer->makeDockVisible(); 00262 } 00263 00264 00265 #ifndef NO_INCLUDE_MOCFILES 00266 #include "kmditoolviewaccessor.moc" 00267 #endif 00268 // kate: space-indent off; tab-width 4; replace-tabs off; indent-mode csands; 00269
KDE Logo
This file is part of the documentation for kmdi Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 14 00:37:13 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003