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
|
/***************************************************************************
tabpage.cpp - description
-------------------
begin : Fri Sep 13 2002
copyright : (C) 2003 by Troy Corbin Jr.
email : tcorbin@users.sf.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "tabpage.moc"
#include "tabmanager.h"
#include "tabgrip.h"
#include "resource.h"
#include <kiconloader.h>
#include <kdebug.h>
#include <klocale.h>
#include <tqlayout.h>
#include <tqtoolbutton.h>
///////////////////////////////////////
//
// TabPage::constructor
//
///////////////////////////////////////
TabPage::TabPage( TQWidget *parent, TQWidget *child, resource *rsrc ) : TQVBox(parent)
{
myResource = rsrc;
myChild = child;
actionBar = new TQHBox( this );
actionBar->show();
grip = new TabGrip( actionBar );
connect( grip, TQT_SIGNAL( wasDragged(const TQPoint&, const TQPoint&) ), this, TQT_SLOT( tabDragged(const TQPoint&, const TQPoint&) ) );
KIconLoader icons( TQString( "knights" ) );
TQPixmap map = icons.loadIcon( TQString("tab_remove"), KIcon::Small, 0, KIcon::DefaultState, 0, TRUE );
if( map.isNull() )
{
/* Keep for backward compatability with KDE 3.0 */
map = icons.loadIcon( TQString("fileclose"), KIcon::Small );
}
closeButton = new TQToolButton( actionBar, "closeButton" );
closeButton->setIconSet( TQIconSet( map ) );
closeButton->setAutoRaise( TRUE );
closeButton->setTextLabel( i18n( "Close This Tab" ), TRUE );
closeButton->tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
connect( closeButton, TQT_SIGNAL( clicked() ), this, TQT_SIGNAL( requestDestruction() ) );
myChild->reparent( this, TQPoint( 0, 0 ), TRUE );
myChild->show();
show();
}
///////////////////////////////////////
//
// TabPage::destructor
//
///////////////////////////////////////
TabPage::~TabPage()
{
}
///////////////////////////////////////
//
// TabPage::tabDragged
//
///////////////////////////////////////
void TabPage::tabDragged( const TQPoint &dest, const TQPoint &offset )
{
TabBox *myParent = parentTabBox();
if( myParent != NULL )
{
TQWidget *destWidget = TQApplication::widgetAt( dest, TRUE );
/* Find a TabBox */
while(1)
{
if( destWidget == NULL )
{
/* Create new TabBox */
TabBox *newBox = new TabBox( myResource );
newBox->resize( myParent->size() );
newBox->move( dest + offset );
newBox->show();
emit newParent( newBox );
myParent->removeTab( this );
newBox->addTab( this, myCaption );
break;
}
if( TQString( destWidget->className() ) == "TabBox" )
{
if( myParent != ((TabBox*)destWidget) )
{
/* We can latch on here */
myParent->removeTab( this );
((TabBox*)destWidget)->addTab( this, myCaption );
break;
}
else
{
break;
}
}
destWidget = destWidget->parentWidget();
}
if( myParent->count() == 0 )
{
/* TabManager will be notified of the delete via TQObject::destroyed(TQObject*) */
delete myParent;
}
}
else
{
kdError() << "TabPage::tabDragged: Can not move without a parent TabBox." << endl;
}
}
///////////////////////////////////////
//
// TabPage::setCaption
//
///////////////////////////////////////
void TabPage::setCaption( const TQString &caption )
{
myCaption = caption;
}
///////////////////////////////////////
//
// TabPage::parentTabBox
//
///////////////////////////////////////
TabBox* TabPage::parentTabBox( void )
{
TQWidget *myParent = this->parentWidget();
if( TQString( myParent->className() ) == TQWIDGETSTACK_OBJECT_NAME_STRING )
{
myParent = myParent->parentWidget();
if( TQString( myParent->className() ) == TQTABWIDGET_OBJECT_NAME_STRING )
{
myParent = myParent->parentWidget();
if( TQString( myParent->className() ) == "TabBox" )
{
return ((TabBox*)myParent);
}
}
}
return NULL;
}
///////////////////////////////////////
//
// TabPage::getChild
//
///////////////////////////////////////
TQWidget* TabPage::getChild( void )
{
return myChild;
}
|