view widgets/AdvancedToolBox.cpp @ 7:a5175615d153

add easaier tab widgets, style and pass the layer characteristics in the main window (remove from panestack)
author lbajardsilogic
date Fri, 11 May 2007 14:11:19 +0000
parents
children 51b1cbf1a7d7
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*   
	Sound Access
		EASAIER client application.
		Silogic 2007. Benoit Rigolleau.

	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.  See the file
	COPYING included with this distribution for more information.
*/

#include <QSizePolicy>
#include <QIcon>

#include "AdvancedToolBox.h"


/** PrivateWidget implementation*************************/

PrivateWidget::PrivateWidget(QWidget *parent, const QString &text,QWidget *newWidget){
	m_closed=false;
	m_layout=0;
	m_button=0;
	if(newWidget!=0){
		addWidget(text,newWidget);
	}
}

void PrivateWidget::addWidget( const QString &text,QWidget *newWidget ){
	
	if (m_layout!=0){
		delete m_layout;
	}
	if (m_button!=0){
		delete m_button;
	}

	m_layout = new QVBoxLayout;
	m_layout->setMargin(0);
	m_layout->setSpacing(0);
	m_button = new QPushButton(QIcon(), text);
	m_button->setMaximumHeight(m_btnHeight);
	m_button->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
	m_layout->addWidget(m_button);
	m_layout->addWidget(newWidget);
	m_widget = newWidget;
	connect(m_button,SIGNAL(clicked()),this,SLOT(changeSate()));

	this->setLayout(m_layout);
	refreshButtonIcone();

}

void PrivateWidget::refreshButtonIcone(){
	if(m_closed){
		m_button->setIcon(QIcon(":icons/right.png"));
	}else{
		m_button->setIcon(QIcon(":icons/bottom.png"));
	}
}


void PrivateWidget::changeSate(){
     if(&m_widget!=0 ){				
		m_widget->setVisible(m_closed);
		if(!m_closed){
			this->setMaximumHeight(m_btnHeight);
		}
		else{
			this->setMaximumHeight(m_widget->maximumHeight() + m_button->maximumHeight());
		}

     }
	 m_closed = !m_closed;
	 refreshButtonIcone();
}

/* end PrivateWidget Implementation**********************/





AdvancedToolBox::AdvancedToolBox(QWidget *parent) : QWidget(parent){
	m_splitter = new QSplitter;
	m_splitter->setOrientation(Qt::Vertical);

	QVBoxLayout *layout= new QVBoxLayout;
	layout->setMargin(0);
	layout->setSpacing(0);
	layout->addWidget(m_splitter);
	layout->addStretch();
	this->setLayout(layout);
}

void AdvancedToolBox::addItem( const QString &text,QWidget *newItem ){
	m_splitter->addWidget(new PrivateWidget(this,text,newItem));
	
}

void AdvancedToolBox::insertItem ( int index, const QString &text,QWidget *newItem ){
	m_splitter->insertWidget(index,new PrivateWidget(this,text,newItem));
}

void AdvancedToolBox::removeItem( int index ){
	delete m_splitter->widget(index);
}