You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
203 lines
5.3 KiB
203 lines
5.3 KiB
/***************************************************************************
|
|
tabmanager.cpp - description
|
|
-------------------
|
|
begin : Sat Sep 14 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 "tabmanager.moc"
|
|
#include "resource.h"
|
|
#include <kdebug.h>
|
|
|
|
static QString myConfigGroup( "TabManager" );
|
|
|
|
TabManager::TabManager( resource *rsrc ) : QObject()
|
|
{
|
|
myResource = rsrc;
|
|
appConfig = kapp->config();
|
|
}
|
|
|
|
TabManager::~TabManager()
|
|
{
|
|
}
|
|
|
|
///////////////////////////////////////
|
|
//
|
|
// TabManager::addTab
|
|
//
|
|
///////////////////////////////////////
|
|
void TabManager::addTab( QWidget *child, const QString &caption )
|
|
{
|
|
TabBox *boxPtr;
|
|
|
|
if( myList.count() == 0 )
|
|
{
|
|
/* First Tab always generates a new TabBox */
|
|
boxPtr = new TabBox( myResource );
|
|
manageNewBox( boxPtr );
|
|
boxPtr->addTab( child, caption );
|
|
|
|
/* Get Geometry from Saved Config */
|
|
appConfig->setGroup( myConfigGroup );
|
|
QSize defaultSize( 420, 360 );
|
|
QSize newSize = appConfig->readSizeEntry( QString( child->className() ), &defaultSize );
|
|
boxPtr->resize( newSize );
|
|
boxPtr->show();
|
|
}
|
|
else
|
|
{
|
|
boxPtr = myList.at(0);
|
|
boxPtr->addTab( child, caption );
|
|
}
|
|
}
|
|
///////////////////////////////////////
|
|
//
|
|
// TabManager::changeCaption
|
|
//
|
|
///////////////////////////////////////
|
|
void TabManager::changeCaption( QWidget *child, const QString &caption )
|
|
{
|
|
TabBox *boxPtr = getParentBox( child );
|
|
|
|
if( boxPtr != NULL )
|
|
{
|
|
boxPtr->changeCaption( child, caption );
|
|
}
|
|
}
|
|
///////////////////////////////////////
|
|
//
|
|
// TabManager::removeTab
|
|
//
|
|
///////////////////////////////////////
|
|
void TabManager::removeTab( QObject *child )
|
|
{
|
|
/* Make sure this is a QWidget we can manipulate */
|
|
if( !child->isWidgetType() )
|
|
{
|
|
kdError() << "TabManager::removeTab: Can not remove non-widget class " << child->className() << endl;
|
|
return;
|
|
}
|
|
|
|
if( myList.find( ((TabBox*)child) ) != -1 )
|
|
{
|
|
/* Remove Child Directly */
|
|
myList.remove( ((TabBox*)child) );
|
|
return;
|
|
}
|
|
|
|
QString childName( ((QWidget*)child)->className() );
|
|
TabBox *boxPtr = getParentBox( ((QWidget*)child) );
|
|
|
|
/* Remove this Child's Parent, the TabPage */
|
|
if( boxPtr != NULL )
|
|
{
|
|
kdDebug() << "Removing child: " << childName << endl;
|
|
boxPtr->removeTab( ((QWidget*)child), TRUE );
|
|
if( boxPtr->count() == 0 )
|
|
{
|
|
myList.remove( boxPtr );
|
|
delete boxPtr;
|
|
}
|
|
return;
|
|
}
|
|
kdWarning() << "Could not find child: " << childName << endl;
|
|
}
|
|
///////////////////////////////////////
|
|
//
|
|
// TabManager::showTab
|
|
//
|
|
///////////////////////////////////////
|
|
void TabManager::showTab( QWidget *child )
|
|
{
|
|
TabBox *boxPtr = getParentBox( child );
|
|
if( boxPtr != NULL )
|
|
{
|
|
boxPtr->showTab( child );
|
|
}
|
|
}
|
|
///////////////////////////////////////
|
|
//
|
|
// TabManager::isTab
|
|
//
|
|
///////////////////////////////////////
|
|
bool TabManager::isTab( QWidget *child )
|
|
{
|
|
if( getParentBox( child ) == NULL )
|
|
{
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
///////////////////////////////////////
|
|
//
|
|
// TabManager::saveTabGeometry
|
|
//
|
|
///////////////////////////////////////
|
|
void TabManager::saveTabGeometry( const QString &childName, const QSize &childSize )
|
|
{
|
|
/* Save This Widget's Size For Later */
|
|
appConfig->setGroup( myConfigGroup );
|
|
appConfig->writeEntry( childName, childSize );
|
|
appConfig->sync();
|
|
|
|
kdDebug() << "Saved geometry for Widget: " << childName << endl;
|
|
}
|
|
///////////////////////////////////////
|
|
//
|
|
// TabManager::childEvent
|
|
//
|
|
///////////////////////////////////////
|
|
void TabManager::childEvent( QChildEvent *event )
|
|
{
|
|
if( event->inserted() )
|
|
{
|
|
/* New Child */
|
|
if( QString( event->child()->className() ) == "TabBox" )
|
|
{
|
|
manageNewBox( ((TabBox*)event->child()) );
|
|
return;
|
|
}
|
|
addTab( ((QWidget*)event->child()), QString( "Untitled" ) );
|
|
}
|
|
}
|
|
///////////////////////////////////////
|
|
//
|
|
// TabManager::manageNewBox
|
|
//
|
|
///////////////////////////////////////
|
|
void TabManager::manageNewBox( TabBox *newBox )
|
|
{
|
|
myList.append( newBox );
|
|
connect( newBox, SIGNAL( destroyed( QObject* ) ), this, SLOT( removeTab( QObject* ) ) );
|
|
connect( newBox, SIGNAL( saveTabGeometry( const QString&, const QSize& ) ), this, SLOT( saveTabGeometry( const QString&, const QSize& ) ) );
|
|
connect( newBox, SIGNAL( newTabBox( TabBox* ) ), this, SLOT( manageNewBox( TabBox* ) ) );
|
|
}
|
|
///////////////////////////////////////
|
|
//
|
|
// TabManager::getParentBox
|
|
//
|
|
///////////////////////////////////////
|
|
TabBox* TabManager::getParentBox( QWidget *child )
|
|
{
|
|
TabBox *boxPtr;
|
|
for( unsigned int index=0; index < myList.count(); index++ )
|
|
{
|
|
boxPtr = myList.at(index);
|
|
if( boxPtr->isChild( child ) )
|
|
{
|
|
return boxPtr;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|