#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    resize(500,300);
    setWindowTitle("热了与冷饮");
    n=0;

    btn = new QPushButton("热了",this);
    btn->setFixedSize(100,50);
    btn->move(100,100);

    btn2 = new QPushButton("没钱了",this);
    btn2->setFixedSize(100,50);
    btn2->move(100,200);

    lable1 = new QLabel("显示",this);
    lable1->setFixedSize(200,50);
    lable1->move(250,100);

    lable2 = new QLabel("请客次数: ",this);
    lable2->setFixedSize(200,50);
    lable2->move(250,200);




    t1 = new Teacher();
    s1 = new Student();

    connect(t1,&Teacher::hot,s1,&Student::drink);
    connect(btn,&QPushButton::clicked,this,&Widget::handleHot);
    connect(btn2,&QPushButton::clicked,this,&Widget::noMoney);


    emit t1->hot();
}

void Widget::handleHot()
{
    emit t1->hot();
    Widget::print();
}

void Widget::print()
{

    n++;
    if(n>0){
        if(n%2==0)
            lable1->setText("请老师吃巧乐兹");
        else
            lable1->setText("请老师吃老冰棍");
        lable2->setText("请客次数: "+QString::number(n));
    }
}

void Widget::noMoney()
{
    n=0;
    lable1->setText("请老师喝西北风");
    lable2->setText("请客次数: "+QString::number(n));
}

Widget::~Widget()
{
}

