{
statusLabel
= new QLabel(tr
("Status: 0 todo / 0 done"));
hBox->addWidget(statusLabel);
hBox->addStretch();
hBox->addWidget(addTaskButtun);
vBox->addLayout(hBox);
vBox->addStretch();
cWidget->setLayout(vBox);
setCentralWidget(cWidget);
connect(addTaskButtun, &QPushButton::clicked, this, &List::addTask);
updateStatus();
}
//************************************************
void List::addTask() {
bool ok;
QLineEdit::Normal, tr
("Untitled task"),
&ok
);
if(ok && !name.isEmpty()) {
Task* task = new Task(name);
connect(task, &Task::removed, this, &List::removeTask);
connect(task, &Task::statusChanged, this, &List::taskStatusChanged);
mTasks.append(task);
vBox->insertWidget(vBox->count()-1, task);
updateStatus();
}
}
//*********************************************
void List::removeTask(Task* task) {
mTasks.removeOne(task);
vBox->removeWidget(task);
task->deleteLater();
updateStatus();
resize(height() - task->height(), task->width()); // Here we resize the window, List
}
List::List(QWidget *parent)
: QMainWindow(parent), mTasks()
{
statusLabel = new QLabel(tr("Status: 0 todo / 0 done"));
addTaskButtun = new QPushButton(tr("Add task"));
cWidget = new QWidget;
hBox = new QHBoxLayout;
hBox->addWidget(statusLabel);
hBox->addStretch();
hBox->addWidget(addTaskButtun);
vBox = new QVBoxLayout;
vBox->addLayout(hBox);
vBox->addStretch();
cWidget->setLayout(vBox);
setCentralWidget(cWidget);
connect(addTaskButtun, &QPushButton::clicked, this, &List::addTask);
updateStatus();
}
//************************************************
void List::addTask() {
bool ok;
QString name = QInputDialog::getText(this, tr("Add Task"), tr("Task name"),
QLineEdit::Normal, tr("Untitled task"), &ok);
if(ok && !name.isEmpty()) {
Task* task = new Task(name);
connect(task, &Task::removed, this, &List::removeTask);
connect(task, &Task::statusChanged, this, &List::taskStatusChanged);
mTasks.append(task);
vBox->insertWidget(vBox->count()-1, task);
updateStatus();
}
}
//*********************************************
void List::removeTask(Task* task) {
mTasks.removeOne(task);
vBox->removeWidget(task);
task->deleteLater();
updateStatus();
resize(height() - task->height(), task->width()); // Here we resize the window, List
}
To copy to clipboard, switch view to plain text mode
Bookmarks