summaryrefslogtreecommitdiffstats
path: root/tdemdi/tdemdidocumentviewtabwidget.cpp
blob: 7ef98747f3e98d95ff67b1c27110dde1b65f3e44 (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
//----------------------------------------------------------------------------
//
//    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.
//
//----------------------------------------------------------------------------

#include <tqtimer.h>

#include <ktabbar.h>
#include <tdepopupmenu.h>
#include "tdemdidocumentviewtabwidget.h"

KMdiDocumentViewTabWidget::KMdiDocumentViewTabWidget( TQWidget* parent, const char* name ) : KTabWidget( parent, name )
{
	m_visibility = KMdi::ShowWhenMoreThanOneTab;
	tabBar() ->hide();
	setHoverCloseButton( true );
	connect( this, TQ_SIGNAL( closeRequest( TQWidget* ) ), this, TQ_SLOT( closeTab( TQWidget* ) ) );
}

KMdiDocumentViewTabWidget::~KMdiDocumentViewTabWidget()
{}

void KMdiDocumentViewTabWidget::closeTab( TQWidget* w )
{
	w->close();
}
void KMdiDocumentViewTabWidget::addTab ( TQWidget * child, const TQString & label )
{
	KTabWidget::addTab( child, label );
	showPage( child );
	TQTimer::singleShot(0, this, TQ_SLOT(maybeShow()));
}

void KMdiDocumentViewTabWidget::addTab ( TQWidget * child, const TQIconSet & iconset, const TQString & label )
{
	KTabWidget::addTab( child, iconset, label );
	showPage( child );
	TQTimer::singleShot(0, this, TQ_SLOT(maybeShow()));
}

void KMdiDocumentViewTabWidget::addTab ( TQWidget * child, TQTab * tab )
{
	KTabWidget::addTab( child, tab );
	showPage( child );
	TQTimer::singleShot(0, this, TQ_SLOT(maybeShow()));
}

void KMdiDocumentViewTabWidget::insertTab ( TQWidget * child, const TQString & label, int index )
{
	KTabWidget::insertTab( child, label, index );
	showPage( child );
	TQTimer::singleShot(0, this, TQ_SLOT(maybeShow()));
	tabBar() ->repaint();
}

void KMdiDocumentViewTabWidget::insertTab ( TQWidget * child, const TQIconSet & iconset, const TQString & label, int index )
{
	KTabWidget::insertTab( child, iconset, label, index );
	showPage( child );
	TQTimer::singleShot(0, this, TQ_SLOT(maybeShow()));
	tabBar() ->repaint();
}

void KMdiDocumentViewTabWidget::insertTab ( TQWidget * child, TQTab * tab, int index )
{
	KTabWidget::insertTab( child, tab, index );
	showPage( child );
	TQTimer::singleShot(0, this, TQ_SLOT(maybeShow()));
	tabBar() ->repaint();
}

void KMdiDocumentViewTabWidget::removePage ( TQWidget * w )
{
	KTabWidget::removePage( w );
	TQTimer::singleShot(0, this, TQ_SLOT(maybeShow()));
}

void KMdiDocumentViewTabWidget::updateIconInView( TQWidget *w, TQPixmap icon )
{
	changeTab( w, icon, tabLabel( w ) );
}

void KMdiDocumentViewTabWidget::updateCaptionInView( TQWidget *w, const TQString &caption )
{
	changeTab( w, caption );
}

void KMdiDocumentViewTabWidget::maybeShow()
{
	switch (m_visibility)
	{
		case KMdi::AlwaysShowTabs:
			tabBar() ->show();
			if ( cornerWidget() )
			{
				if ( count() == 0 )
					cornerWidget() ->hide();
				else
					cornerWidget() ->show();
			}
			break;

		case KMdi::ShowWhenMoreThanOneTab:
			if ( count() < 2 )
				tabBar() ->hide();
			else tabBar() ->show();
			if ( cornerWidget() )
			{
				if ( count() < 2 )
					cornerWidget() ->hide();
				else
					cornerWidget() ->show();
			}
			break;
		case KMdi::NeverShowTabs:
			tabBar() ->hide();
			break;
	}
}

void KMdiDocumentViewTabWidget::setTabWidgetVisibility( KMdi::TabWidgetVisibility visibility )
{
	m_visibility = visibility;
	maybeShow();
}

void KMdiDocumentViewTabWidget::moveTab( int from, int to )
{
  emit initiateTabMove( from, to );
  KTabWidget::moveTab( from, to );
}

KMdi::TabWidgetVisibility KMdiDocumentViewTabWidget::tabWidgetVisibility( )
{
	return m_visibility;
}


#ifndef NO_INCLUDE_MOCFILES
#include "tdemdidocumentviewtabwidget.moc"
#endif