25 #include "tdemditoolviewaccessor_p.h"
26 #include "tdemdiguiclient.h"
27 #include "tdemdimainfrm.h"
29 #include "tdemditoolviewaccessor.h"
30 #include "tdemditoolviewaccessor_p.h"
32 KMdiToolViewAccessor::KMdiToolViewAccessor(
KMdiMainFrm *parent, TQWidget *widgetToWrap,
const TQString& tabToolTip,
const TQString& tabCaption )
36 d =
new KMdiToolViewAccessorPrivate();
37 if ( widgetToWrap->inherits(
"KDockWidget" ) )
39 d->widgetContainer =
dynamic_cast<KDockWidget*
>( widgetToWrap );
40 d->widget = d->widgetContainer->getWidget();
44 d->widget = widgetToWrap;
45 TQString finalTabCaption;
46 if ( tabCaption == 0 )
48 finalTabCaption = widgetToWrap->caption();
49 if ( finalTabCaption.isEmpty() && !widgetToWrap->icon() )
51 finalTabCaption = widgetToWrap->name();
56 finalTabCaption = tabCaption;
58 d->widgetContainer = parent->createDockWidget( widgetToWrap->name(),
59 ( widgetToWrap->icon() ? ( *( widgetToWrap->icon() ) ) : TQPixmap() ),
61 widgetToWrap->caption(),
63 d->widgetContainer->setWidget( widgetToWrap );
64 if ( tabToolTip != 0 )
66 d->widgetContainer->setToolTipString( tabToolTip );
70 if ( mdiMainFrm->m_mdiGUIClient )
73 kdDebug( 760 ) <<
"mdiMainFrm->m_mdiGUIClient == 0 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl;
75 d->widget->installEventFilter(
this );
78 KMdiToolViewAccessor::KMdiToolViewAccessor(
KMdiMainFrm *parent )
81 d =
new KMdiToolViewAccessorPrivate();
84 KMdiToolViewAccessor::~KMdiToolViewAccessor()
86 if ( mdiMainFrm->m_pToolViews )
87 mdiMainFrm->m_pToolViews->remove
93 TQWidget *KMdiToolViewAccessor::wrapperWidget()
95 if ( !d->widgetContainer )
97 d->widgetContainer = mdiMainFrm->createDockWidget(
"KMdiToolViewAccessor::null", TQPixmap() );
98 connect( d->widgetContainer, TQ_SIGNAL( widgetSet( TQWidget* ) ),
this, TQ_SLOT( setWidgetToWrap( TQWidget* ) ) );
100 return d->widgetContainer;
103 TQWidget *KMdiToolViewAccessor::wrappedWidget()
109 void KMdiToolViewAccessor::setWidgetToWrap( TQWidget *widgetToWrap,
const TQString& tabToolTip,
const TQString& tabCaption )
111 Q_ASSERT( !( d->widget ) );
112 Q_ASSERT( !widgetToWrap->inherits(
"KDockWidget" ) );
113 disconnect( d->widgetContainer, TQ_SIGNAL( widgetSet( TQWidget* ) ),
this, TQ_SLOT( setWidgetToWrap( TQWidget* ) ) );
115 d->widget = widgetToWrap;
116 KDockWidget *tmp = d->widgetContainer;
118 TQString finalTabCaption;
119 if ( tabCaption == 0 )
121 finalTabCaption = widgetToWrap->caption();
122 if ( finalTabCaption.isEmpty() && !widgetToWrap->icon() )
124 finalTabCaption = widgetToWrap->name();
129 finalTabCaption = tabCaption;
134 tmp = mdiMainFrm->createDockWidget( widgetToWrap->name(),
135 widgetToWrap->icon() ? ( *( widgetToWrap->icon() ) ) : TQPixmap(),
137 widgetToWrap->caption(),
139 d->widgetContainer = tmp;
140 if ( tabToolTip != 0 )
142 d->widgetContainer->setToolTipString( tabToolTip );
147 tmp->setCaption( widgetToWrap->caption() );
148 tmp->setTabPageLabel( finalTabCaption );
149 tmp->setPixmap( widgetToWrap->icon() ? ( *( widgetToWrap->icon() ) ) : TQPixmap() );
150 tmp->setName( widgetToWrap->name() );
151 if ( tabToolTip != 0 )
153 d->widgetContainer->setToolTipString( tabToolTip );
156 tmp->setWidget( widgetToWrap );
157 mdiMainFrm->m_pToolViews->insert( widgetToWrap,
this );
158 if ( mdiMainFrm->m_mdiGUIClient )
159 mdiMainFrm->m_mdiGUIClient->addToolView(
this );
161 kdDebug( 760 ) <<
"mdiMainFrm->m_mdiGUIClient == 0 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl;
163 d->widget->installEventFilter(
this );
167 bool KMdiToolViewAccessor::eventFilter( TQObject *, TQEvent *e )
169 if ( e->type() == TQEvent::IconChange )
171 d->widgetContainer->setPixmap( d->widget->icon() ? ( *d->widget->icon() ) : TQPixmap() );
176 void KMdiToolViewAccessor::placeAndShow( KDockWidget::DockPosition pos, TQWidget* pTargetWnd ,
int percent )
178 place( pos, pTargetWnd, percent );
181 void KMdiToolViewAccessor::place( KDockWidget::DockPosition pos, TQWidget* pTargetWnd ,
int percent )
183 Q_ASSERT( d->widgetContainer );
184 if ( !d->widgetContainer )
186 if ( pos == KDockWidget::DockNone )
188 d->widgetContainer->setEnableDocking( KDockWidget::DockNone );
189 d->widgetContainer->reparent( mdiMainFrm, (WFlags)(WType_TopLevel | WType_Dialog), TQPoint( 0, 0 ),
true );
194 KDockWidget* pCover = d->widgetContainer;
196 KDockWidget* pTargetDock = 0L;
197 if ( pTargetWnd->inherits(
"KDockWidget" ) || pTargetWnd->inherits(
"KDockWidget_Compat::KDockWidget" ) )
199 pTargetDock = ( KDockWidget* ) pTargetWnd;
203 bool DockToOurself =
false;
204 if ( mdiMainFrm->m_pDockbaseAreaOfDocumentViews )
206 if ( pTargetWnd == mdiMainFrm->m_pDockbaseAreaOfDocumentViews->getWidget() )
208 DockToOurself =
true;
209 pTargetDock = mdiMainFrm->m_pDockbaseAreaOfDocumentViews;
211 else if ( pTargetWnd == mdiMainFrm->m_pDockbaseAreaOfDocumentViews )
213 DockToOurself =
true;
214 pTargetDock = mdiMainFrm->m_pDockbaseAreaOfDocumentViews;
219 if ( !DockToOurself )
220 if ( pTargetWnd != 0L )
222 pTargetDock = mdiMainFrm->dockManager->findWidgetParentDock( pTargetWnd );
225 if ( pTargetWnd->parentWidget() )
227 pTargetDock = mdiMainFrm->dockManager->findWidgetParentDock( pTargetWnd->parentWidget() );
231 if ( !pTargetDock || pTargetWnd == mdiMainFrm->getMainDockWidget() )
233 if ( mdiMainFrm->m_managedDockPositionMode && ( mdiMainFrm->m_pMdi || mdiMainFrm->m_documentTabWidget ) )
235 KDockWidget * dw1 = pTargetDock->findNearestDockWidget( pos );
237 pCover->manualDock( dw1, KDockWidget::DockCenter, percent );
239 pCover->manualDock ( pTargetDock, pos, 20 );
243 pCover->manualDock( pTargetDock, pos, percent );
248 void KMdiToolViewAccessor::hide()
250 Q_ASSERT( d->widgetContainer );
251 if ( !d->widgetContainer )
253 d->widgetContainer->undock();
256 void KMdiToolViewAccessor::show()
258 Q_ASSERT( d->widgetContainer );
259 if ( !d->widgetContainer )
261 d->widgetContainer->makeDockVisible();
265 #ifndef NO_INCLUDE_MOCFILES
266 #include "tdemditoolviewaccessor.moc"
void addToolView(KMdiToolViewAccessor *)
Add a new tool view to this KMDIGUIClient.
Base class for all your special main frames.