/*******************************************************************************
*                                                                              *
* 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;

    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)
{
    if(mButtonState)
    {
        mTextButton->SetButtonImage(&mDeActivatedBtnImage);
        mTextButton->SetButtonText(mDeActivatedButtonText);
        mTextButton->SetBackgroundColor(QColor(245, 245, 255, 220));
        mButtonState = false;
        emit ToggleBtnDeActivate(this);
    }
    else
    {
        mTextButton->SetButtonImage(&mActivatedBtnImage);
        mTextButton->SetButtonText(mActivatedBtnText);
        mTextButton->SetBackgroundColor(Qt::green);
        mButtonState = true;
        emit ToggleBtnActivate(this);
    }
}

void CToggleTextButtonWidget::ForceActivation()
{
    mTextButton->SetButtonImage(&mActivatedBtnImage);
    mTextButton->SetButtonText(mActivatedBtnText);
    mTextButton->SetBackgroundColor(Qt::green);
    mButtonState = true;
}
void CToggleTextButtonWidget::ForceDeactivation()
{
    mTextButton->SetButtonImage(&mDeActivatedBtnImage);
    mTextButton->SetButtonText(mDeActivatedButtonText);
    mTextButton->SetBackgroundColor(QColor(245, 245, 255, 220));
    mButtonState = false;
}

void CToggleTextButtonWidget::OverrideText(QString text)
{
    mTextButton->SetButtonText(text);
}
