#include "posdlg.h"
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>

PosDlg::PosDlg(QWidget *parent) : QDialog{parent} {
    setWindowTitle(tr("Set Position"));
    setWindowFlag(Qt::WindowContextHelpButtonHint, false);

    auto vBox = new QVBoxLayout(this);
    auto hBox = new QHBoxLayout();
    hBox->addStretch();
    hBox->addWidget(new QLabel("X"));
    auto fdX = new QLineEdit(QString::number(parent->x()));
    fdX->setMaximumWidth(80);
    hBox->addWidget(fdX);
    hBox->addStretch();

    vBox->addLayout(hBox);

    hBox = new QHBoxLayout();
    hBox->addStretch();
    hBox->addWidget(new QLabel("Y"));
    auto fdY = new QLineEdit(QString::number(parent->y()));
    fdY->setMaximumWidth(80);
    hBox->addWidget(fdY);
    hBox->addStretch();

    vBox->addLayout(hBox);

    hBox = new QHBoxLayout();
    hBox->addStretch();

    auto btnOk = new QPushButton(tr("OK"));
    connect(btnOk, &QPushButton::clicked, this, [parent, fdX, fdY] {
        parent->move(fdX->text().toInt(), fdY->text().toInt());
    });
    hBox->addWidget(btnOk);
    hBox->addStretch();

    vBox->addLayout(hBox);
}
