view widgets/ExpandWidget.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 c5387d9e572a
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 "ExpandWidget.h"



ExpandWidget::ExpandWidget(QWidget *parent) : QSplitter(parent){
	m_paneClosed = 0;
    m_button = new QPushButton();    
	m_button->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
    m_paneClosed = false;

	setWidgetLocation(ExpandWidget::Location_Left);

    connect(m_button,SIGNAL(clicked()),this,SLOT(changePaneSate()));
}

void ExpandWidget::refreshButtonIcone(){
	switch(m_widgetLocation){
		case ExpandWidget::Location_Bottom:
			if(m_paneClosed){
				m_button->setIcon(QIcon(":icons/top.png"));
			}else{
				m_button->setIcon(QIcon(":icons/bottom.png"));
			}
			break;
		case ExpandWidget::Location_Top:
			if(m_paneClosed){
				m_button->setIcon(QIcon(":icons/bottom.png"));
			}else{
				m_button->setIcon(QIcon(":icons/top.png"));
			}
			break;
		case ExpandWidget::Location_Left:
			if(m_paneClosed){
				m_button->setIcon(QIcon(":icons/right.png"));
			}else{
				m_button->setIcon(QIcon(":icons/left.png"));
			}

			break;
		case ExpandWidget::Location_Right:
		default :
			if(m_paneClosed){
				m_button->setIcon(QIcon(":icons/left.png"));
			}else{
				m_button->setIcon(QIcon(":icons/right.png"));
			}
			break;
	}
}


void ExpandWidget::setWidgetLocation(ExpandWidget::Location newWidgetLocation){

	m_widgetLocation = newWidgetLocation;

	switch(m_widgetLocation){
		case ExpandWidget::Location_Bottom:
		case ExpandWidget::Location_Top:
			this->setOrientation(Qt::Vertical);
			m_button->setFixedSize(50,8);
			break;
		case ExpandWidget::Location_Left:
		case ExpandWidget::Location_Right:
		default :
			this->setOrientation(Qt::Horizontal);
			m_button->setFixedSize(8,50);
			break;
	}
	refreshButtonIcone();
}

void ExpandWidget::setPanes(QWidget *newCenterPane, QWidget *newOtherPane){

	m_centerPane =  newCenterPane;
	m_otherPane = newOtherPane;
	

	newCenterPane->setParent(this);
	newOtherPane->setParent(this);

	QWidget *widgetAux = new QWidget;
	QLayout *lay;
	// only to center the button
	QWidget *widgetForBtn = new QWidget;
	QHBoxLayout *layForBtn = new QHBoxLayout();
	layForBtn->setMargin(0);
	layForBtn->setSpacing(0);
	widgetForBtn->setMaximumHeight(8);


	switch(m_widgetLocation){
		case ExpandWidget::Location_Bottom:
			lay = new QVBoxLayout();
			lay->setMargin(0);
			lay->setSpacing(0);
			lay->addWidget(m_centerPane);
		
			// this code is only to center the button.
			layForBtn->addStretch();	
			layForBtn->addWidget(m_button);
			layForBtn->addStretch();
			widgetForBtn->setLayout(layForBtn);
			lay->addWidget(widgetForBtn);

			widgetAux->setLayout(lay);
			this->addWidget(widgetAux);
			this->addWidget(m_otherPane);
			break;
		case ExpandWidget::Location_Top:
			lay = new QVBoxLayout();
			lay->setMargin(0);
			lay->setSpacing(0);
			
			// this code is only for center the button.
			layForBtn->addStretch();	
			layForBtn->addWidget(m_button);
			layForBtn->addStretch();
			widgetForBtn->setLayout(layForBtn);

			lay->addWidget(widgetForBtn);
			lay->addWidget(m_centerPane);
			widgetAux->setLayout(lay);
			this->addWidget(m_otherPane);
			this->addWidget(widgetAux);
			break;
		case ExpandWidget::Location_Left:
			lay = new QHBoxLayout();
			lay->setMargin(0);
			lay->setSpacing(0);
			lay->addWidget(m_button);
			lay->addWidget(m_centerPane);
			widgetAux->setLayout(lay);
			this->addWidget(m_otherPane);
			this->addWidget(widgetAux);
			break;
		case ExpandWidget::Location_Right:
		default :
			lay = new QHBoxLayout();
			lay->setMargin(0);
			lay->setSpacing(0);
			lay->addWidget(m_centerPane);
			lay->addWidget(m_button);
			widgetAux->setLayout(lay);
			this->addWidget(widgetAux);
			this->addWidget(m_otherPane);
			break;
	}
}


void ExpandWidget::changePaneSate(){
     if(&m_paneClosed!=0 ){				
		 m_otherPane->setVisible(m_paneClosed);
     }
	 m_paneClosed = !m_paneClosed;
	 refreshButtonIcone();
}