view widgets/ItemLayerList.cpp @ 61:0387f53242b2

fix the 2ed color bug in the layer list. Now color in layer list is ok.
author benoitrigolleau
date Tue, 29 May 2007 09:26:15 +0000
parents 32b4949086a5
children ca1f73f027f5
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 "ItemLayerList.h"

#include "data/model/LayerItemModel.h"
#include "layer/Layer.h"
#include "base/PlayParameters.h"

#include <QWidget>

#include <QApplication>
#include <QLabel>


ItemLayerList::ItemLayerList(QWidget *parent) : GenericItemList(parent){
	setAcceptDrops(true);

	/* Init all variables*/
	m_labelIcon = new QLabel;
	m_labelName = new QLabel;
	m_checkBoxShow = new QCheckBox;
	m_checkBoxPlay = new QCheckBox;
	m_layoutMain = new QHBoxLayout;

	/* set the correct widget parameters*/
	m_labelIcon->setMaximumSize(25,25);
	//labelIcon->setPixmap(QIcon(":icons/layerViewer_btn_config.png").pixmap(20));

	m_labelName->setMaximumHeight(25);
	//labelName->setText("ljdh lksdf hl");

	m_checkBoxShow->setLayoutDirection(Qt::RightToLeft);
	m_checkBoxShow->setMaximumSize(30,30);
	//checkBox1->setText("");
	m_checkBoxShow->setAutoFillBackground(true);
	QPalette palette;
	palette.setColor(QPalette::Button,palette.color(QPalette::Background));
	m_checkBoxShow->setPalette(palette);

	m_checkBoxPlay->setMaximumSize(20,30);	

	m_layoutMain->setSpacing(5);
	m_layoutMain->setMargin(0);

	this->setMaximumHeight(30);
	this->setMinimumHeight(30);
	this->setFrameStyle(QFrame::Panel | QFrame::Raised);
	this->setLineWidth(1);
	
	/* build the interface*/
	m_layoutMain->addWidget(m_checkBoxShow);
	m_layoutMain->addWidget(m_checkBoxPlay);
	m_layoutMain->addWidget(m_labelIcon);
	m_layoutMain->addWidget(m_labelName);

	/*add the main layout in this widget*/
	this->setLayout(m_layoutMain);

	connect(this, SIGNAL(doubleClicked()), this, SLOT(openPropertyBox()));
}

void ItemLayerList::setIcon(QString &icon){
	m_labelIcon->setPixmap(QIcon(icon).pixmap(25));
}

void ItemLayerList::setName(QString &name){
	m_labelName->setText(name);
}

void ItemLayerList::setColor(QColor &color){
	QPalette palette;
	palette.setColor(QPalette::Button,color);
	m_checkBoxShow->setPalette(palette);
}

void ItemLayerList::changeCheckBoxShowState(bool state){
	m_checkBoxShow->setChecked(state);
}

void ItemLayerList::changeCheckBoxPlayState(bool state){
	m_checkBoxPlay->setChecked(state);
}

void ItemLayerList::setPropertyBox(PropertyBox *box){
	m_propertyBox = box;
	if(m_propertyBox!=0){
		
		m_container = m_propertyBox->container();

		
		updateCheckboxs();
		updateColor();
		connect(m_checkBoxShow,SIGNAL(stateChanged(int)),m_propertyBox,SLOT(layerVisibilityChanged(int)));
		connect(m_propertyBox, SIGNAL(showLayer(bool)), this, SLOT(showLayer(bool)));
	}

	//connect();
}

void ItemLayerList::configAction(){
	if(m_propertyBox!=0){
		m_propertyBox->close();
		m_propertyBox->show();
	}
}


/*********SLOTS ************/
void ItemLayerList::openPropertyBox(){
	ItemLayerList::configAction();
}

void ItemLayerList::showLayer(bool value){
	changeCheckBoxShowState(value);
	
}

void ItemLayerList::updateCheckboxs(){
	Layer *layer = dynamic_cast<Layer *>(m_container);
	if (layer) {
		m_checkBoxShow->setEnabled(true);
		m_checkBoxShow->setChecked(true);

		disconnect(layer, SIGNAL(modelReplaced()),
			this, SLOT(updateCheckboxs()));
		connect(layer, SIGNAL(modelReplaced()),
			this, SLOT(updateCheckboxs()));
		
		disconnect(layer, SIGNAL(layerParametersChanged()),
			this,SLOT(updateColor()));
		connect(layer, SIGNAL(layerParametersChanged()),
			this,SLOT(updateColor()));

	}else{
		m_checkBoxShow->setEnabled(false);
	}
	PlayParameters *params = m_container->getPlayParameters();

	if(params){
		m_checkBoxPlay->setEnabled(true);
        m_checkBoxPlay->setChecked(!params->isPlayMuted());

		connect(params, SIGNAL(playAudibleChanged(bool)),m_checkBoxPlay, SLOT(setState(bool)));
		connect(m_checkBoxPlay, SIGNAL(stateChanged(int)),params, SLOT(setPlayAudible(int)));
	}else{
		m_checkBoxPlay->setEnabled(false);
	}
}

void ItemLayerList::updateColor(){
	Layer *layer = dynamic_cast<Layer *>(m_container);
	if (layer) {
		QPalette palette;
		palette.setColor(QPalette::Button,layer->getBaseColour());
		m_checkBoxShow->setPalette(palette);
	}
}