summaryrefslogtreecommitdiffstats
path: root/knights/tabmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'knights/tabmanager.cpp')
-rw-r--r--knights/tabmanager.cpp202
1 files changed, 202 insertions, 0 deletions
diff --git a/knights/tabmanager.cpp b/knights/tabmanager.cpp
new file mode 100644
index 0000000..f2d72fc
--- /dev/null
+++ b/knights/tabmanager.cpp
@@ -0,0 +1,202 @@
+/***************************************************************************
+ 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;
+}