summaryrefslogtreecommitdiffstats
path: root/lib/compatibility/kmdi/qextmdi/kmditoolviewaccessor.cpp
blob: f9921e18cc1f87105ce2e53bb8756ad667d797a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
//----------------------------------------------------------------------------
//    filename             : kmditoolviewaccessor.h
//----------------------------------------------------------------------------
//    Project              : KDE MDI extension
//
//    begin                : 08/2003       by Joseph Wenninger ([email protected])
//    changes              : ---
//    patches              : ---
//
//    copyright            : (C) 2003 by Joseph Wenninger ([email protected])
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU Library General Public License as
//    published by the Free Software Foundation; either version 2 of the
//    License, or (at your option) any later version.
//
//----------------------------------------------------------------------------

#ifndef NO_KDE
# include <kdebug.h>
#endif
#include "kmditoolviewaccessor_p.h"
#include "kmdiguiclient.h"
#include "kmdimainfrm.h"

#include "kmditoolviewaccessor.h"
#include "kmditoolviewaccessor_p.h"

KMdiToolViewAccessor::KMdiToolViewAccessor( KMdiMainFrm *parent, QWidget *widgetToWrap, const QString& tabToolTip, const QString& tabCaption )
		: QObject( parent )
{
	mdiMainFrm = parent;
	d = new KMdiToolViewAccessorPrivate();
	if ( widgetToWrap->inherits( "KDockWidget" ) )
	{
		d->widgetContainer = dynamic_cast<KDockWidget*>( widgetToWrap );
		d->widget = d->widgetContainer->getWidget();
	}
	else
	{
		d->widget = widgetToWrap;
		QString finalTabCaption;
		if ( tabCaption == 0 )
		{
			finalTabCaption = widgetToWrap->caption();
			if ( finalTabCaption.isEmpty() && !widgetToWrap->icon() )
			{
				finalTabCaption = widgetToWrap->name();
			}
		}
		else
		{
			finalTabCaption = tabCaption;
		}
		d->widgetContainer = parent->createDockWidget( widgetToWrap->name(),
		                     ( widgetToWrap->icon() ? ( *( widgetToWrap->icon() ) ) : QPixmap() ),
		                     0L,   // parent
		                     widgetToWrap->caption(),
		                     finalTabCaption );
		d->widgetContainer->setWidget( widgetToWrap );
		if ( tabToolTip != 0 )
		{
			d->widgetContainer->setToolTipString( tabToolTip );
		} 
	}
	//mdiMainFrm->m_pToolViews->insert(d->widget,this);
	if ( mdiMainFrm->m_mdiGUIClient )
		mdiMainFrm->m_mdiGUIClient->addToolView( this );
	else
		kdDebug( 760 ) << "mdiMainFrm->m_mdiGUIClient == 0 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl;

	d->widget->installEventFilter( this );
}

KMdiToolViewAccessor::KMdiToolViewAccessor( KMdiMainFrm *parent )
{
	mdiMainFrm = parent;
	d = new KMdiToolViewAccessorPrivate();
}

KMdiToolViewAccessor::~KMdiToolViewAccessor()
{
	if ( mdiMainFrm->m_pToolViews )
		mdiMainFrm->m_pToolViews->remove
		( d->widget );
	delete d;

}

QWidget *KMdiToolViewAccessor::wrapperWidget()
{
	if ( !d->widgetContainer )
	{
		d->widgetContainer = mdiMainFrm->createDockWidget( "KMdiToolViewAccessor::null", QPixmap() );
		connect( d->widgetContainer, SIGNAL( widgetSet( QWidget* ) ), this, SLOT( setWidgetToWrap( QWidget* ) ) );
	}
	return d->widgetContainer;
}

QWidget *KMdiToolViewAccessor::wrappedWidget()
{
	return d->widget;
}


void KMdiToolViewAccessor::setWidgetToWrap( QWidget *widgetToWrap, const QString& tabToolTip, const QString& tabCaption )
{
	Q_ASSERT( !( d->widget ) );
	Q_ASSERT( !widgetToWrap->inherits( "KDockWidget" ) );
	disconnect( d->widgetContainer, SIGNAL( widgetSet( QWidget* ) ), this, SLOT( setWidgetToWrap( QWidget* ) ) );
	delete d->widget;
	d->widget = widgetToWrap;
	KDockWidget *tmp = d->widgetContainer;

	QString finalTabCaption;
	if ( tabCaption == 0 )
	{
		finalTabCaption = widgetToWrap->caption();
		if ( finalTabCaption.isEmpty() && !widgetToWrap->icon() )
		{
			finalTabCaption = widgetToWrap->name();
		}
	}
	else
	{
		finalTabCaption = tabCaption;
	}

	if ( !tmp )
	{
		tmp = mdiMainFrm->createDockWidget( widgetToWrap->name(),
		                                    widgetToWrap->icon() ? ( *( widgetToWrap->icon() ) ) : QPixmap(),
		                                    0L,   // parent
		                                    widgetToWrap->caption(),
		                                    finalTabCaption );
		d->widgetContainer = tmp;
		if ( tabToolTip != 0 )
		{
			d->widgetContainer->setToolTipString( tabToolTip );
		}
	}
	else
	{
		tmp->setCaption( widgetToWrap->caption() );
		tmp->setTabPageLabel( finalTabCaption );
		tmp->setPixmap( widgetToWrap->icon() ? ( *( widgetToWrap->icon() ) ) : QPixmap() );
		tmp->setName( widgetToWrap->name() );
		if ( tabToolTip != 0 )
		{
			d->widgetContainer->setToolTipString( tabToolTip );
		}
	}
	tmp->setWidget( widgetToWrap );
	mdiMainFrm->m_pToolViews->insert( widgetToWrap, this );
	if ( mdiMainFrm->m_mdiGUIClient )
		mdiMainFrm->m_mdiGUIClient->addToolView( this );
	else
		kdDebug( 760 ) << "mdiMainFrm->m_mdiGUIClient == 0 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl;

	d->widget->installEventFilter( this );
}


bool KMdiToolViewAccessor::eventFilter( QObject *, QEvent *e )
{
	if ( e->type() == QEvent::IconChange )
	{
		d->widgetContainer->setPixmap( d->widget->icon() ? ( *d->widget->icon() ) : QPixmap() );
	}
	return false;
}

void KMdiToolViewAccessor::placeAndShow( KDockWidget::DockPosition pos, QWidget* pTargetWnd , int percent )
{
	place( pos, pTargetWnd, percent );
	show();
}
void KMdiToolViewAccessor::place( KDockWidget::DockPosition pos, QWidget* pTargetWnd , int percent )
{
	Q_ASSERT( d->widgetContainer );
	if ( !d->widgetContainer )
		return ;
	if ( pos == KDockWidget::DockNone )
	{
		d->widgetContainer->setEnableDocking( KDockWidget::DockNone );
		d->widgetContainer->reparent( mdiMainFrm, Qt::WType_TopLevel | Qt::WType_Dialog, QPoint( 0, 0 ), true ); //pToolView->isVisible());
	}
	else
	{   // add (and dock) the toolview as DockWidget view

		KDockWidget* pCover = d->widgetContainer;

		KDockWidget* pTargetDock = 0L;
		if ( pTargetWnd->inherits( "KDockWidget" ) || pTargetWnd->inherits( "KDockWidget_Compat::KDockWidget" ) )
		{
			pTargetDock = ( KDockWidget* ) pTargetWnd;
		}

		// Should we dock to ourself?
		bool DockToOurself = false;
		if ( mdiMainFrm->m_pDockbaseAreaOfDocumentViews )
		{
			if ( pTargetWnd == mdiMainFrm->m_pDockbaseAreaOfDocumentViews->getWidget() )
			{
				DockToOurself = true;
				pTargetDock = mdiMainFrm->m_pDockbaseAreaOfDocumentViews;
			}
			else if ( pTargetWnd == mdiMainFrm->m_pDockbaseAreaOfDocumentViews )
			{
				DockToOurself = true;
				pTargetDock = mdiMainFrm->m_pDockbaseAreaOfDocumentViews;
			}
		}
		// this is not inheriting QWidget*, its plain impossible that this condition is true
		//if (pTargetWnd == this) DockToOurself = true;
		if ( !DockToOurself )
			if ( pTargetWnd != 0L )
			{
				pTargetDock = mdiMainFrm->dockManager->findWidgetParentDock( pTargetWnd );
				if ( !pTargetDock )
				{
					if ( pTargetWnd->parentWidget() )
					{
						pTargetDock = mdiMainFrm->dockManager->findWidgetParentDock( pTargetWnd->parentWidget() );
					}
				}
			}
		if ( !pTargetDock || pTargetWnd == mdiMainFrm->getMainDockWidget() )
		{
			if ( mdiMainFrm->m_managedDockPositionMode && ( mdiMainFrm->m_pMdi || mdiMainFrm->m_documentTabWidget ) )
			{
				KDockWidget * dw1 = pTargetDock->findNearestDockWidget( pos );
				if ( dw1 )
					pCover->manualDock( dw1, KDockWidget::DockCenter, percent );
				else
					pCover->manualDock ( pTargetDock, pos, 20 );
				return ;
			}
		}
		pCover->manualDock( pTargetDock, pos, percent );
		//check      pCover->show();
	}
}

void KMdiToolViewAccessor::hide()
{
	Q_ASSERT( d->widgetContainer );
	if ( !d->widgetContainer )
		return ;
	d->widgetContainer->undock();
}

void KMdiToolViewAccessor::show()
{
	Q_ASSERT( d->widgetContainer );
	if ( !d->widgetContainer )
		return ;
	d->widgetContainer->makeDockVisible();
}


#ifndef NO_INCLUDE_MOCFILES
#include "kmditoolviewaccessor.moc"
#endif 
// kate: space-indent off; tab-width 4; replace-tabs off; indent-mode csands;