favoritenamepopup.cpp 1.56 KB
#include "favoritenamepopup.h"
#include "ui_favoritenamepopup.h"

#include "soundplayer.h"
#include "primewindow.h"
#include "mainwindow.h"

FavoriteNamePopup::FavoriteNamePopup(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FavoriteNamePopup)
{
    ui->setupUi(this);

    ui->lineEdit->setFocus();
    ui->lineEdit->selectAll();

    connect(ui->okButton, &QPushButton::pressed, SoundPlayer::playClick);
    connect(ui->cancelButton, &QPushButton::pressed, SoundPlayer::playClick);
}

FavoriteNamePopup::FavoriteNamePopup(QWidget *parent, ManualCookSetting setting) : FavoriteNamePopup(parent)
{
    type = Manual;
    manualSetting = setting;
}

FavoriteNamePopup::FavoriteNamePopup(QWidget *parent, AutoCookSetting setting) : FavoriteNamePopup(parent)
{
    type = Auto;
    autoSetting = setting;
}

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

void FavoriteNamePopup::ok()
{
    int id;
    switch (type)
    {
    case Manual:
        id = CookHistory::addFavorite(manualSetting, ui->lineEdit->text());
        break;
    case Auto:
        id = CookHistory::addFavorite(autoSetting, ui->lineEdit->text());
        break;
    default:
        return;
    }

    PrimeWindow *w = new PrimeWindow(MainWindow::getInstance());
    w->setWindowModality(Qt::WindowModal);
    w->listFavorites();
    w->focusFavorite(id);
    w->showFullScreen();
    w->raise();

    MainWindow::jump(w);
}

void FavoriteNamePopup::cancel()
{
    deleteLater();
}

void FavoriteNamePopup::on_okButton_clicked()
{
    ok();
}

void FavoriteNamePopup::on_cancelButton_clicked()
{
    cancel();
}