cookpanelbutton.cpp 1.55 KB
#include "cookpanelbutton.h"
#include "ui_cookpanelbutton.h"

#include "soundplayer.h"
#include "manualcooksettingwidget.h"

CookPanelButton::CookPanelButton(CookRecord record, QWidget *parent) :
    QWidget(parent),
    record(record),
    ui(new Ui::CookPanelButton),
    rendered(false)
{
    ui->setupUi(this);

    setText(record.name);

    foreach (QPushButton *button, findChildren<QPushButton *>())
        connect(button, &QPushButton::pressed, SoundPlayer::playClick);
}

CookPanelButton::~CookPanelButton()
{
    delete ui;
}

void CookPanelButton::setText(QString text)
{
    ui->pushButton->setText(text);
}

void CookPanelButton::showInfo()
{
    if (!rendered)
    {
        QPixmap p = CookHistory::render(record);

        label = new QLabel(this);
        label->setPixmap(p);
        label->setGeometry((width() - p.width()) / 2, 65, p.width(), p.height());
    }

    label->show();
    setMinimumHeight(ui->pushButton->height() + label->height());
}

void CookPanelButton::hideInfo()
{
    label->hide();
    setMinimumHeight(ui->pushButton->height());
}

void CookPanelButton::focusBar()
{
    ui->pushButton->setFocus();
}

void CookPanelButton::focusInfoButton()
{
    ui->showInfoButton->setFocus();
}

void CookPanelButton::focusDeleteButton()
{
    ui->deleteButton->setFocus();
}


void CookPanelButton::on_showInfoButton_toggled(bool checked)
{
    emit infoClicked(this);
}

void CookPanelButton::on_pushButton_clicked()
{
    CookHistory::start(record, parentWidget());
}

void CookPanelButton::on_deleteButton_clicked()
{
    emit deleteClicked(this);
}