/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2013                                                                         *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
    Description:
    .

*/

/* ************************************************************************** */
/* Revision:
### 20130306 JFM
    Verision d'origine.

### YYYYMMDD Description du besoin ou du bug
    Description du changement.
 */

/* ************************************************************************** */

#include "TextButtonWidget.h"
#include <QPainter>
#include <ToggleTextButtonWidget.h>

CToggleTextButtonWidget::CToggleTextButtonWidget(QString ActivatedText, QString DeActivatedText, QPixmap ActivatedButtonImage, QPixmap DeActivatedButtonImage, int ButtonHeight,int ButtonWidth,int FontSize, int ToggleTextButtonData)
{
    mButtonState = false;
    mActivatedBtnText = ActivatedText;
    mDeActivatedButtonText = DeActivatedText;
    mActivatedBtnImage = ActivatedButtonImage;
    mDeActivatedBtnImage = DeActivatedButtonImage;
    mButtonHeight = ButtonHeight;
    mButtonData = ToggleTextButtonData;

	if(mDeActivatedBtnImage.isNull())
		mTextButton = new CTextButtonWidget(DeActivatedText,mButtonData,mButtonHeight,ButtonWidth,FontSize,0);
	else
		mTextButton = new CTextButtonWidget(DeActivatedText,mButtonData,mButtonHeight,ButtonWidth,FontSize,&mDeActivatedBtnImage);
    connect(mTextButton, SIGNAL(TxtButtonClicked(CTextButtonWidget *)), this, SLOT(ChildTextButtonClicked(CTextButtonWidget *)));

    setGeometry(mTextButton->rect());
    mTextButton->setParentItem(this);
}
CToggleTextButtonWidget::~CToggleTextButtonWidget()
{
    delete mTextButton;
}

void CToggleTextButtonWidget::ChildTextButtonClicked(CTextButtonWidget *TextButtonPtr)
{
	Q_UNUSED(TextButtonPtr)

    if(mButtonState)
    {
		if(!mDeActivatedBtnImage.isNull())
			mTextButton->SetButtonImage(&mDeActivatedBtnImage);

        mTextButton->SetButtonText(mDeActivatedButtonText);
        mTextButton->SetBackgroundColor(QColor(245, 245, 255, 220));
        mButtonState = false;
        emit ToggleBtnDeActivate(this);
    }
    else
    {
		if(!mActivatedBtnImage.isNull())
			mTextButton->SetButtonImage(&mActivatedBtnImage);

        mTextButton->SetButtonText(mActivatedBtnText);
        mTextButton->SetBackgroundColor(Qt::green);
        mButtonState = true;
        emit ToggleBtnActivate(this);
    }
}

void CToggleTextButtonWidget::ForceActivation(bool Emit)
{
	if(!mActivatedBtnImage.isNull())
		mTextButton->SetButtonImage(&mActivatedBtnImage);

    mTextButton->SetButtonText(mActivatedBtnText);
    mTextButton->SetBackgroundColor(Qt::green);
    mButtonState = true;

    if(Emit == true)
        emit ToggleBtnActivate(this);
}
void CToggleTextButtonWidget::ForceDeactivation(bool Emit)
{
	if(!mDeActivatedBtnImage.isNull())
		mTextButton->SetButtonImage(&mDeActivatedBtnImage);

    mTextButton->SetButtonText(mDeActivatedButtonText);
    mTextButton->SetBackgroundColor(QColor(245, 245, 255, 220));
    mButtonState = false;

    if(Emit == true)
        emit ToggleBtnDeActivate(this);
}
