katetabwidget.cpp
00001 /* This file is part of the KDE project 00002 Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org> 00003 Copyright (C) 2002,2003 Joseph Wenninger <jowenn@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "katetabwidget.h" 00021 #include "katetabwidget.moc" 00022 00023 #include <tqtabbar.h> 00024 00025 //BEGIN KateTabWidget 00026 00027 KateTabWidget::KateTabWidget(TQWidget* parent, const char* name) 00028 : KTabWidget(parent,name) 00029 , m_visibility (ShowWhenMoreThanOneTab) 00030 { 00031 tabBar()->hide(); 00032 00033 setHoverCloseButton(true); 00034 00035 connect(this, TQT_SIGNAL(closeRequest(TQWidget*)), this, TQT_SLOT(closeTab(TQWidget*))); 00036 } 00037 00038 KateTabWidget::~KateTabWidget() 00039 { 00040 } 00041 00042 void KateTabWidget::closeTab(TQWidget* w) 00043 { 00044 w->close(); 00045 } 00046 00047 void KateTabWidget::addTab ( TQWidget * child, const TQString & label ) 00048 { 00049 KTabWidget::addTab(child,label); 00050 showPage(child); 00051 maybeShow(); 00052 } 00053 00054 void KateTabWidget::addTab ( TQWidget * child, const TQIconSet & iconset, const TQString & label ) 00055 { 00056 KTabWidget::addTab(child,iconset,label); 00057 showPage(child); 00058 maybeShow(); 00059 } 00060 00061 void KateTabWidget::addTab ( TQWidget * child, TQTab * tab ) 00062 { 00063 KTabWidget::addTab(child,tab); 00064 showPage(child); 00065 maybeShow(); 00066 } 00067 00068 void KateTabWidget::insertTab ( TQWidget * child, const TQString & label, int index) 00069 { 00070 KTabWidget::insertTab(child,label,index); 00071 showPage(child); 00072 maybeShow(); 00073 tabBar()->repaint(); 00074 } 00075 00076 void KateTabWidget::insertTab ( TQWidget * child, const TQIconSet & iconset, const TQString & label, int index ) 00077 { 00078 KTabWidget::insertTab(child,iconset,label,index); 00079 showPage(child); 00080 maybeShow(); 00081 tabBar()->repaint(); 00082 } 00083 00084 void KateTabWidget::insertTab ( TQWidget * child, TQTab * tab, int index) 00085 { 00086 KTabWidget::insertTab(child,tab,index); 00087 showPage(child); 00088 maybeShow(); 00089 tabBar()->repaint(); 00090 } 00091 00092 void KateTabWidget::removePage ( TQWidget * w ) 00093 { 00094 KTabWidget::removePage(w); 00095 maybeShow(); 00096 } 00097 00098 void KateTabWidget::maybeShow() 00099 { 00100 switch (m_visibility) 00101 { 00102 case AlwaysShowTabs: 00103 tabBar()->show(); 00104 00105 // show/hide corner widgets 00106 if (count() == 0) 00107 setCornerWidgetVisibility(false); 00108 else 00109 setCornerWidgetVisibility(true); 00110 00111 break; 00112 00113 case ShowWhenMoreThanOneTab: 00114 if (count()<2) tabBar()->hide(); 00115 else tabBar()->show(); 00116 00117 // show/hide corner widgets 00118 if (count() < 2) 00119 setCornerWidgetVisibility(false); 00120 else 00121 setCornerWidgetVisibility(true); 00122 00123 break; 00124 00125 case NeverShowTabs: 00126 tabBar()->hide(); 00127 break; 00128 } 00129 } 00130 00131 void KateTabWidget::setCornerWidgetVisibility(bool visible) 00132 { 00133 // there are two corner widgets: on TopLeft and on TopTight! 00134 00135 if (cornerWidget(TQt::TopLeft) ) { 00136 if (visible) 00137 cornerWidget(TQt::TopLeft)->show(); 00138 else 00139 cornerWidget(TQt::TopLeft)->hide(); 00140 } 00141 00142 if (cornerWidget(TQt::TopRight) ) { 00143 if (visible) 00144 cornerWidget(TQt::TopRight)->show(); 00145 else 00146 cornerWidget(TQt::TopRight)->hide(); 00147 } 00148 } 00149 00150 void KateTabWidget::setTabWidgetVisibility( TabWidgetVisibility visibility ) 00151 { 00152 m_visibility = visibility; 00153 maybeShow(); 00154 } 00155 00156 KateTabWidget::TabWidgetVisibility KateTabWidget::tabWidgetVisibility( ) const 00157 { 00158 return m_visibility; 00159 } 00160 00161 //END KateTabWidget