PouringWindow::PouringWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::PouringWindow)
{
    ui->setupUi(this);
    setStyleSheet(App::CssStyle);

    QObject::connect(FlowMeterManager::Instance, SIGNAL(PourStarted()), this, SLOT(onPourStarted()));
    QObject::connect(FlowMeterManager::Instance, SIGNAL(PourFinished()), this, SLOT(onPourFinished()));
    QObject::connect(FlowMeterManager::Instance, SIGNAL(FlowMeterTicked()), this, SLOT(onFlowMeterTick()));

    connect(&updateTimer, SIGNAL(timeout()), this, SLOT(updateUI()));
    connect(this, SIGNAL(updateCamImageSignal()), this, SLOT(updateCamImageSlot()));

    ticksPerLiter = Settings::GetDouble("ticksPerLiter");
    logPours = Settings::GetBool("logPours");
    photoFrequency = Settings::GetInt("pourPhotoFrequency");

    currentUser = User::UnknownUser;
    currentPour = NULL;

    ui->usersComboBox->view()->setItemDelegate(new CustomComboBoxItem(this));
    vector<User*>::iterator iter;
    for (iter = User::UsersList.begin(); iter != User::UsersList.end(); ++iter)
    {
        User* user = (*iter);
        ui->usersComboBox->addItem(QString(user->Name.c_str()));
    }
    connect(ui->usersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(userSelectedSlot(int)));
}
UsersWindow::UsersWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::UsersWindow)
{
    ui->setupUi(this);
    setStyleSheet(App::CssStyle);

    connect(FlowMeterManager::Instance, SIGNAL(PourStarted()), this, SLOT(onPourStarted()));
    connect(ui->scrollPane, SIGNAL(SelectionChanged(int)), this, SLOT(setSelectedIndex(int)));
    connect(this, SIGNAL(updateCamImageSignal()), this, SLOT(updateCamImageSlot()));

    updateLearningButtons();
    ui->scrollPane->SetSelectedIndex(-1);

    this->ui->nameLabel->setText(QString(""));
    this->ui->owedLabel->setText(QString(""));

    //ui->saveImageButton->setEnabled(false);
    //ui->startSearchButton->setEnabled(false);
}
void PouringWindow::updateCamImage()
{
    cv::resize(RaspiCvCam::ImageMat, displayMat, cv::Size(ui->cameraDisplay->size().width(), ui->cameraDisplay->size().height()));
    qImage = QImage((uchar*)displayMat.data, displayMat.cols, displayMat.rows, displayMat.step, QImage::Format_RGB888);
    emit updateCamImageSignal();
}
void UsersWindow::updateCamImage()
{
    emit updateCamImageSignal();
}