#include "lodateselector.h"
#include <QDialog>
#include <QVBoxLayout>
#include <QCalendarWidget>

LoDateSelector::LoDateSelector(QWidget *parent) : QPushButton(parent) {
    setStyleSheet(R"rrr(
LoDateSelector {
    background-color: transparent;
    image: url(:/res/program/DateSelect_enable.png);
    padding: 0;
    max-width: 32px;
    max-height: 32px;
}
LoDateSelector:!enabled{
    image: url(:/res/program/DateSelect_e.png);
}
LoDateSelector:pressed {
    margin-top: 1px;
    margin-left: 1px;
    margin-bottom: -1px;
    margin-right: -1px;
}
)rrr");
    connect(this, &QPushButton::clicked, this, [this] {
        QDialog dlg(this);
        dlg.setWindowTitle(tr("Date selector"));
        dlg.setWindowFlag(Qt::WindowContextHelpButtonHint, false);
        auto vBox = new QVBoxLayout(&dlg);
        vBox->setContentsMargins(0,0,0,0);
        auto calendar = new QCalendarWidget();
        connect(calendar, &QCalendarWidget::clicked, &dlg, &QDialog::accept);
        connect(calendar, &QCalendarWidget::clicked, this, &LoDateSelector::sDateSelected);
        vBox->addWidget(calendar);
        dlg.exec();
    });
}
