view widgets/ExpandWidget.cpp @ 205:00cf9a7faa4d

add menu and shortcut to show/hide both ExpandWidget (layers and filters, search/info tab)
author lbajardsilogic
date Wed, 30 Jan 2008 10:20:41 +0000
parents bc5b79e7b1d8
children
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(changePaneState()));
}

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){

	QList<int> sizes;
	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);
			sizes.push_back(widgetAux->height());
			sizes.push_back(m_otherPane->height());
			this->setSizes(sizes);
			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);
			sizes.push_back(m_otherPane->height());
			sizes.push_back(widgetAux->height());
			this->setSizes(sizes);
			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);
			sizes.push_back(m_otherPane->width());
			sizes.push_back(widgetAux->width());
			this->setSizes(sizes);
			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);
			sizes.push_back(widgetAux->width());
			sizes.push_back(m_otherPane->width());
			this->setSizes(sizes);
			break;
	}
}


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

void ExpandWidget::setPercentage(int a, int b)
{
	int percent = a + b;
	
	if (percent == 0)
		return;

	QList<int> newSizes;
	int totalSize = 0;

	QList<int> sizes = this->sizes();
	QList<int>::iterator iter = sizes.begin();
	
	QListIterator<int> it(this->sizes());
    while (it.hasNext())
	{
		totalSize += it.next();
	}

	newSizes.push_back(totalSize*a/percent);
	newSizes.push_back(totalSize*b/percent);
	this->setSizes(newSizes);
}