# kmdi/kmdi Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# tabwidget.cpp

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 2004 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 as published by the Free Software Foundation; either
    00008    version 2 of the License, or (at your option) any later version.
    00009
    00010    This library is distributed in the hope that it will be useful,
    00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013    Library General Public License for more details.
    00014
    00015    You should have received a copy of the GNU Library General Public License
    00016    along with this library; see the file COPYING.LIB.  If not, write to
    00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018    Boston, MA 02111-1307, USA.
    00019
    00020    Based on:
    00021
    00022    //----------------------------------------------------------------------------
    00023    //    Project              : KDE MDI extension
    00024    //
    00025    //    begin                : 07/1999       by Szymon Stefanek as part of kvirc
    00026    //                                         (an IRC application)
    00027    //    changes              : 09/1999       by Falk Brettschneider to create an
    00028    //                           - 06/2000     stand-alone Qt extension set of
    00029    //                                         classes and a Qt-based library
    00030    //                         : 02/2000       by Massimo Morin (mmorin@schedsys.com)
    00031    //                           2000-2003     maintained by the KDevelop project
    00032    //    patches              : -/2000        by Lars Beikirch (Lars.Beikirch@gmx.net)
    00033    //                         : 01/2003       by Jens Zurheide (jens.zurheide@gmx.de)
    00034    //
    00035    //    copyright            : (C) 1999-2003 by Falk Brettschneider
    00036    //                                         and
    00037    //                                         Szymon Stefanek (stefanek@tin.it)
    00038    //    email                :  falkbr@kdevelop.org (Falk Brettschneider)
    00039    //----------------------------------------------------------------------------
    00040 */
    00041
    00042 #include <ktabbar.h>
    00043 #include <kpopupmenu.h>
    00044 #include <kdebug.h>
    00045
    00046 #include <qobjectlist.h>
    00047
    00048 #include "tabwidget.h"
    00049 #include "tabwidget.moc"
    00050
    00051 namespace KMDIPrivate
    00052 {
    00053   class TabWidgetPrivate
    00054   {
    00055
    00056   };
    00057 }
    00058
    00059 namespace KMDI
    00060 {
    00061
    00062 TabWidget::TabWidget(QWidget* parent, const char* name)
    00063  : KTabWidget(parent,name)
    00064  , m_visibility (KMDI::ShowWhenMoreThanOneTab)
    00065  , d (new KMDIPrivate::TabWidgetPrivate())
    00066 {
    00067   installEventFilter (this);
    00068
    00069   tabBar()->hide();
    00070
    00071   setHoverCloseButton(true);
    00072
    00073   connect(this, SIGNAL(closeRequest(QWidget*)), this, SLOT(closeTab(QWidget*)));
    00074 }
    00075
    00076 TabWidget::~TabWidget()
    00077 {
    00078   delete d;
    00079   d = 0;
    00080 }
    00081
    00082 bool TabWidget::eventFilter(QObject *obj, QEvent *e )
    00083 {
    00084   if(e->type() == QEvent::FocusIn)
    00085   {
    00086     emit focusInEvent ();
    00087   }
    00088   else if (e->type() == QEvent::ChildRemoved)
    00089   {
    00090     // if we lost a child we uninstall ourself as event filter for the lost
    00091     // child and its children
    00092     QObject* pLostChild = ((QChildEvent*)e)->child();
    00093     if ((pLostChild != 0L) && (pLostChild->isWidgetType())) {
    00094        QObjectList *list = pLostChild->queryList( "QWidget" );
    00095        list->insert(0, pLostChild);        // add the lost child to the list too, just to save code
    00096        QObjectListIt it( *list );          // iterate over all lost child widgets
    00097        QObject * o;
    00098        while ( (o=it.current()) != 0 ) { // for each found object...
    00099           QWidget* widg = (QWidget*)o;
    00100           ++it;
    00101           widg->removeEventFilter(this);
    00102        }
    00103        delete list;                        // delete the list, not the objects
    00104     }
    00105   }
    00106   else if (e->type() == QEvent::ChildInserted)
    00107   {
    00108     // if we got a new child and we are attached to the MDI system we
    00109     // install ourself as event filter for the new child and its children
    00110     // (as we did when we were added to the MDI system).
    00111     QObject* pNewChild = ((QChildEvent*)e)->child();
    00112     if ((pNewChild != 0L) && (pNewChild->isWidgetType()))
    00113     {
    00114        QWidget* pNewWidget = (QWidget*)pNewChild;
    00115        if (pNewWidget->testWFlags(Qt::WType_Dialog | Qt::WShowModal))
    00116            return false;
    00117        QObjectList *list = pNewWidget->queryList( "QWidget" );
    00118        list->insert(0, pNewChild);         // add the new child to the list too, just to save code
    00119        QObjectListIt it( *list );          // iterate over all new child widgets
    00120        QObject * o;
    00121        while ( (o=it.current()) != 0 ) { // for each found object...
    00122           QWidget* widg = (QWidget*)o;
    00123           ++it;
    00124           widg->installEventFilter(this);
    00125           connect(widg, SIGNAL(destroyed()), this, SLOT(childDestroyed()));
    00126        }
    00127        delete list;                        // delete the list, not the objects
    00128     }
    00129   }
    00130
    00131   return KTabWidget::eventFilter (obj, e);
    00132 }
    00133
    00134 void TabWidget::childDestroyed()
    00135 {
    00136   // if we lost a child we uninstall ourself as event filter for the lost
    00137   // child and its children
    00138   const QObject* pLostChild = QObject::sender();
    00139   if ((pLostChild != 0L) && (pLostChild->isWidgetType()))
    00140   {
    00141      QObjectList *list = ((QObject*)(pLostChild))->queryList("QWidget");
    00142      list->insert(0, pLostChild);        // add the lost child to the list too, just to save code
    00143      QObjectListIt it( *list );          // iterate over all lost child widgets
    00144      QObject * obj;
    00145      while ( (obj=it.current()) != 0 ) { // for each found object...
    00146        QWidget* widg = (QWidget*)obj;
    00147        ++it;
    00148        widg->removeEventFilter(this);
    00149      }
    00150      delete list;                        // delete the list, not the objects
    00151   }
    00152 }
    00153
    00154 void TabWidget::closeTab(QWidget* w)
    00155 {
    00156   w->close();
    00157 }
    00158
    00159 void TabWidget::addTab ( QWidget * child, const QString & label )
    00160 {
    00161   KTabWidget::addTab(child,label);
    00162   showPage(child);
    00163   maybeShow();
    00164 }
    00165
    00166 void TabWidget::addTab ( QWidget * child, const QIconSet & iconset, const QString & label )
    00167 {
    00168   KTabWidget::addTab(child,iconset,label);
    00169   showPage(child);
    00170   maybeShow();
    00171 }
    00172
    00173 void TabWidget::addTab ( QWidget * child, QTab * tab )
    00174 {
    00175   KTabWidget::addTab(child,tab);
    00176   showPage(child);
    00177   maybeShow();
    00178 }
    00179
    00180 void TabWidget::insertTab ( QWidget * child, const QString & label, int index)
    00181 {
    00182   KTabWidget::insertTab(child,label,index);
    00183   showPage(child);
    00184   maybeShow();
    00185   tabBar()->repaint();
    00186 }
    00187
    00188 void TabWidget::insertTab ( QWidget * child, const QIconSet & iconset, const QString & label, int index )
    00189 {
    00190   KTabWidget::insertTab(child,iconset,label,index);
    00191   showPage(child);
    00192   maybeShow();
    00193   tabBar()->repaint();
    00194 }
    00195
    00196 void TabWidget::insertTab ( QWidget * child, QTab * tab, int index)
    00197 {
    00198   KTabWidget::insertTab(child,tab,index);
    00199   showPage(child);
    00200   maybeShow();
    00201   tabBar()->repaint();
    00202 }
    00203
    00204 void TabWidget::removePage ( QWidget * w )
    00205 {
    00206   KTabWidget::removePage(w);
    00207   maybeShow();
    00208 }
    00209
    00210 void TabWidget::updateIconInView( QWidget *w, QPixmap icon )
    00211 {
    00212   changeTab(w,icon,tabLabel(w));
    00213 }
    00214
    00215 void TabWidget::updateCaptionInView( QWidget *w, const QString &caption )
    00216 {
    00217   changeTab(w, caption);
    00218 }
    00219
    00220 void TabWidget::maybeShow()
    00221 {
    00222   switch (m_visibility)
    00223   {
    00224     case KMDI::AlwaysShowTabs:
    00225       tabBar()->show();
    00226
    00227       // show/hide corner widgets
    00228       if (count() == 0)
    00229         setCornerWidgetVisibility(false);
    00230       else
    00231         setCornerWidgetVisibility(true);
    00232
    00233       break;
    00234
    00235     case KMDI::ShowWhenMoreThanOneTab:
    00236       if (count()<2) tabBar()->hide();
    00237       else tabBar()->show();
    00238
    00239       // show/hide corner widgets
    00240       if (count() < 2)
    00241         setCornerWidgetVisibility(false);
    00242       else
    00243         setCornerWidgetVisibility(true);
    00244
    00245       break;
    00246
    00247     case KMDI::NeverShowTabs:
    00248       tabBar()->hide();
    00249       break;
    00250   }
    00251 }
    00252
    00253 void TabWidget::setCornerWidgetVisibility(bool visible) {
    00254   // there are two corner widgets: on TopLeft and on TopTight!
    00255
    00256   if (cornerWidget(Qt::TopLeft) ) {
    00257     if (visible)
    00258       cornerWidget(Qt::TopLeft)->show();
    00259     else
    00260       cornerWidget(Qt::TopLeft)->hide();
    00261   }
    00262
    00263   if (cornerWidget(Qt::TopRight) ) {
    00264     if (visible)
    00265       cornerWidget(Qt::TopRight)->show();
    00266     else
    00267       cornerWidget(Qt::TopRight)->hide();
    00268   }
    00269 }
    00270
    00271 void TabWidget::setTabWidgetVisibility( KMDI::TabWidgetVisibility visibility )
    00272 {
    00273   m_visibility = visibility;
    00274   maybeShow();
    00275 }
    00276
    00277 KMDI::TabWidgetVisibility TabWidget::tabWidgetVisibility( ) const
    00278 {
    00279   return m_visibility;
    00280 }
    00281
    00282 }
    00283
    00284 // kate: space-indent on; indent-width 2; replace-tabs on;

This file is part of the documentation for kmdi/kmdi Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:32:30 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003