Version 2 // Add detailled breaks
This commit is contained in:
@@ -6,9 +6,8 @@ SetDayDialog::SetDayDialog(Day d, bool isNotValidable, QWidget *parent) :
|
||||
ui(new Ui::SetDayDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->window_title->setText(this->windowTitle());
|
||||
this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
|
||||
ui->validateButton->setEnabled(!isNotValidable);
|
||||
ui->validateButton->setVisible(!isNotValidable);
|
||||
this->d = d;
|
||||
init();
|
||||
}
|
||||
@@ -18,45 +17,31 @@ SetDayDialog::~SetDayDialog()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void SetDayDialog::mousePressEvent(QMouseEvent *event) {
|
||||
m_nMouseClick_X_Coordinate = event->x();
|
||||
m_nMouseClick_Y_Coordinate = event->y();
|
||||
}
|
||||
|
||||
void SetDayDialog::mouseMoveEvent(QMouseEvent *event) {
|
||||
if (isWidgetIsTitleBar()) {
|
||||
move(event->globalX() - m_nMouseClick_X_Coordinate ,
|
||||
event->globalY() - m_nMouseClick_Y_Coordinate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool SetDayDialog::isWidgetIsTitleBar() {
|
||||
return (m_nMouseClick_X_Coordinate >= xmin &&
|
||||
m_nMouseClick_X_Coordinate < xmax &&
|
||||
m_nMouseClick_Y_Coordinate >= ymin &&
|
||||
m_nMouseClick_Y_Coordinate < ymax);
|
||||
}
|
||||
|
||||
void SetDayDialog::init() {
|
||||
ui->start_edit->setTime(d.get_start());
|
||||
ui->end_edit->setTime(d.get_end());
|
||||
ui->break_edit->setValue(d.get_time_break());
|
||||
xmax = ui->titleBar->x() + ui->titleBar->width();
|
||||
xmin = ui->titleBar->x();
|
||||
ymax = ui->titleBar->x() + ui->titleBar->height();
|
||||
ymin = ui->titleBar->y();
|
||||
updateBreakList();
|
||||
connect(ui->start_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time);
|
||||
connect(ui->end_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time);
|
||||
connect(ui->validateButton, &QPushButton::clicked, this, &SetDayDialog::validate);
|
||||
connect(ui->break_edit, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &SetDayDialog::compute_time);
|
||||
connect(ui->addBreakButton, &QPushButton::clicked, this, &SetDayDialog::add_break_point);
|
||||
connect(ui->removeBreakButton, &QPushButton::clicked, this, &SetDayDialog::remove_break_point);
|
||||
connect(ui->breakList, &QListWidget::currentRowChanged, this, &SetDayDialog::break_selected);
|
||||
ui->total_label->setText(Tools::double_to_string_time(d.get_total()));
|
||||
}
|
||||
|
||||
void SetDayDialog::updateBreakList()
|
||||
{
|
||||
ui->breakList->clear();
|
||||
foreach (BreakPoint bp, d.getBreaks()) {
|
||||
ui->breakList->addItem(QString("%1 -> %2").arg(bp.getStart().toString("hh:mm"), bp.getEnd().toString("hh:mm")));
|
||||
}
|
||||
}
|
||||
|
||||
void SetDayDialog::compute_time() {
|
||||
d.set_validate(false);
|
||||
d.set_start(ui->start_edit->time());
|
||||
d.set_end(ui->end_edit->time());
|
||||
d.set_time_break(ui->break_edit->value());
|
||||
ui->total_label->setText(Tools::double_to_string_time(d.get_total()));
|
||||
}
|
||||
|
||||
@@ -68,3 +53,34 @@ void SetDayDialog::validate() {
|
||||
d.set_validate(true);
|
||||
accept();
|
||||
}
|
||||
|
||||
void SetDayDialog::add_break_point()
|
||||
{
|
||||
BreakDialog bd(this);
|
||||
int result = bd.exec();
|
||||
if (result == QDialog::Accepted) {
|
||||
BreakPoint bp = bd.get_result();
|
||||
auto breaks = d.getBreaks();
|
||||
breaks.append(bp);
|
||||
d.setBreaks(breaks);
|
||||
updateBreakList();
|
||||
compute_time();
|
||||
}
|
||||
}
|
||||
|
||||
void SetDayDialog::remove_break_point()
|
||||
{
|
||||
int i = ui->breakList->currentRow();
|
||||
if (i > -1) {
|
||||
auto breaks = d.getBreaks();
|
||||
breaks.removeAt(i);
|
||||
d.setBreaks(breaks);
|
||||
updateBreakList();
|
||||
compute_time();
|
||||
}
|
||||
}
|
||||
|
||||
void SetDayDialog::break_selected(int i)
|
||||
{
|
||||
ui->removeBreakButton->setEnabled(i > -1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user