diff --git a/CMakeLists.txt b/CMakeLists.txt index 30dff4a..5af1b9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -project(pomodoro VERSION 0.3 LANGUAGES CXX) +project(pomodoro VERSION 0.4 LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/icons/add_task-light.svg b/icons/add_task-light.svg new file mode 100644 index 0000000..8a0c9a1 --- /dev/null +++ b/icons/add_task-light.svg @@ -0,0 +1 @@ + diff --git a/icons/add_task.svg b/icons/add_task.svg new file mode 100644 index 0000000..577f204 --- /dev/null +++ b/icons/add_task.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/delete-light.svg b/icons/delete-light.svg new file mode 100644 index 0000000..e2aa0fc --- /dev/null +++ b/icons/delete-light.svg @@ -0,0 +1 @@ + diff --git a/icons/delete.svg b/icons/delete.svg new file mode 100644 index 0000000..0ac67f9 --- /dev/null +++ b/icons/delete.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/edit-delete-symbolic-light.svg b/icons/edit-delete-symbolic-light.svg deleted file mode 100644 index 9ceed60..0000000 --- a/icons/edit-delete-symbolic-light.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/icons/edit-delete-symbolic.svg b/icons/edit-delete-symbolic.svg deleted file mode 100644 index 4658cf2..0000000 --- a/icons/edit-delete-symbolic.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/icons/list-add-symbolic-light.svg b/icons/list-add-symbolic-light.svg deleted file mode 100644 index c796a3b..0000000 --- a/icons/list-add-symbolic-light.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/icons/list-add-symbolic.svg b/icons/list-add-symbolic.svg deleted file mode 100644 index 5461079..0000000 --- a/icons/list-add-symbolic.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/icons/local_cafe-light.svg b/icons/local_cafe-light.svg new file mode 100644 index 0000000..7724ca2 --- /dev/null +++ b/icons/local_cafe-light.svg @@ -0,0 +1 @@ + diff --git a/icons/local_cafe.svg b/icons/local_cafe.svg new file mode 100644 index 0000000..ab90f17 --- /dev/null +++ b/icons/local_cafe.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/media-playback-start-symbolic-light.svg b/icons/media-playback-start-symbolic-light.svg deleted file mode 100644 index 162f467..0000000 --- a/icons/media-playback-start-symbolic-light.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/icons/media-playback-start-symbolic.svg b/icons/media-playback-start-symbolic.svg deleted file mode 100644 index 770f184..0000000 --- a/icons/media-playback-start-symbolic.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/icons/media-playback-stop-symbolic-light.svg b/icons/media-playback-stop-symbolic-light.svg deleted file mode 100644 index 133feb8..0000000 --- a/icons/media-playback-stop-symbolic-light.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/icons/media-playback-stop-symbolic.svg b/icons/media-playback-stop-symbolic.svg deleted file mode 100644 index 3025635..0000000 --- a/icons/media-playback-stop-symbolic.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/icons/pause-light.svg b/icons/pause-light.svg new file mode 100644 index 0000000..e17ade2 --- /dev/null +++ b/icons/pause-light.svg @@ -0,0 +1 @@ + diff --git a/icons/pause.svg b/icons/pause.svg new file mode 100644 index 0000000..c79d039 --- /dev/null +++ b/icons/pause.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/pending_actions-light.svg b/icons/pending_actions-light.svg new file mode 100644 index 0000000..d49358b --- /dev/null +++ b/icons/pending_actions-light.svg @@ -0,0 +1 @@ + diff --git a/icons/pending_actions.svg b/icons/pending_actions.svg new file mode 100644 index 0000000..db73fa4 --- /dev/null +++ b/icons/pending_actions.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/play_arrow-light.svg b/icons/play_arrow-light.svg new file mode 100644 index 0000000..4fb97bd --- /dev/null +++ b/icons/play_arrow-light.svg @@ -0,0 +1 @@ + diff --git a/icons/play_arrow.svg b/icons/play_arrow.svg new file mode 100644 index 0000000..eb813b6 --- /dev/null +++ b/icons/play_arrow.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/preferences-system-time-symbolic-light.svg b/icons/preferences-system-time-symbolic-light.svg deleted file mode 100644 index 4938fea..0000000 --- a/icons/preferences-system-time-symbolic-light.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/icons/preferences-system-time-symbolic.svg b/icons/preferences-system-time-symbolic.svg deleted file mode 100644 index 1f214d2..0000000 --- a/icons/preferences-system-time-symbolic.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/icons/restart_alt-light.svg b/icons/restart_alt-light.svg new file mode 100644 index 0000000..dff4a25 --- /dev/null +++ b/icons/restart_alt-light.svg @@ -0,0 +1 @@ + diff --git a/icons/restart_alt.svg b/icons/restart_alt.svg new file mode 100644 index 0000000..ada5e3e --- /dev/null +++ b/icons/restart_alt.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/system-restart-symbolic-light.svg b/icons/system-restart-symbolic-light.svg deleted file mode 100644 index c418ce2..0000000 --- a/icons/system-restart-symbolic-light.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/icons/system-restart-symbolic.svg b/icons/system-restart-symbolic.svg deleted file mode 100644 index ca8989c..0000000 --- a/icons/system-restart-symbolic.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/include/mainwindow.h b/include/mainwindow.h index 3d9b934..8c98371 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -26,9 +26,13 @@ class MainWindow : public QMainWindow void remTask(int index=3); void remTask(QLabel *lbl); void subTime(); + void subBreakTime(); void resetTime(); private: + void startBreak(); + void endBreak(); + QScrollArea *scrAr; QWidget *base; QTabWidget *tabWid; @@ -40,6 +44,8 @@ class MainWindow : public QMainWindow QString iconSuffix; int time; + int breakTime; + QLabel *breakTimeLbl; CustomTimer *timer; QFont timerFont; QFont taskFont; diff --git a/resources.qrc b/resources.qrc index 6170347..910b5f9 100644 --- a/resources.qrc +++ b/resources.qrc @@ -1,16 +1,18 @@ - icons/media-playback-start-symbolic.svg - icons/media-playback-start-symbolic-light.svg - icons/media-playback-stop-symbolic.svg - icons/media-playback-stop-symbolic-light.svg - icons/preferences-system-time-symbolic.svg - icons/preferences-system-time-symbolic-light.svg - icons/system-restart-symbolic.svg - icons/system-restart-symbolic-light.svg - icons/list-add-symbolic.svg - icons/list-add-symbolic-light.svg - icons/edit-delete-symbolic.svg - icons/edit-delete-symbolic-light.svg + icons/play_arrow.svg + icons/play_arrow-light.svg + icons/pause.svg + icons/pause-light.svg + icons/pending_actions.svg + icons/pending_actions-light.svg + icons/restart_alt.svg + icons/restart_alt-light.svg + icons/add_task.svg + icons/add_task-light.svg + icons/delete.svg + icons/delete-light.svg + icons/local_cafe.svg + icons/local_cafe-light.svg \ No newline at end of file diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 005c8c1..fec7263 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -7,25 +7,26 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // Initialize all variables/pointers - base = new QWidget; - scrAr = new QScrollArea; - layout = new QFormLayout(base); // Base layout - tabWid = new QTabWidget(this); - timeLbl = new QLabel; - timerFont = QFont("sans-serif", 100); - taskFont = QFont("sans-serif", 18); - lineE = new QLineEdit; - timer = new CustomTimer; + base = new QWidget; + scrAr = new QScrollArea; + layout = new QFormLayout(base); // Base layout + tabWid = new QTabWidget(this); + timeLbl = new QLabel; + breakTimeLbl = new QLabel; + timerFont = QFont("sans-serif", 100); + taskFont = QFont("sans-serif", 18); + lineE = new QLineEdit; + timer = new CustomTimer; int textHSV = timeLbl->palette().color(QPalette::WindowText).value(); int bgHSV = timeLbl->palette().color(QPalette::Window).value(); iconSuffix = ""; if (textHSV > bgHSV) iconSuffix = "-light"; - addBtn = new QPushButton(QIcon(":/icons/list-add-symbolic" + iconSuffix + ".svg"), ""); - QPushButton *startBtn = new QPushButton(QIcon(":/icons/media-playback-start-symbolic" + iconSuffix + ".svg"), "Start"); - QPushButton *stopBtn = new QPushButton(QIcon(":/icons/media-playback-stop-symbolic" + iconSuffix + ".svg"), "Stop"); - QPushButton *resetBtn = new QPushButton(QIcon(":/icons/system-restart-symbolic" + iconSuffix + ".svg"), "Reset"); + addBtn = new QPushButton(QIcon(":/icons/add_task" + iconSuffix + ".svg"), ""); + QPushButton *startBtn = new QPushButton(QIcon(":/icons/play_arrow" + iconSuffix + ".svg"), "Start"); + QPushButton *stopBtn = new QPushButton(QIcon(":/icons/pause" + iconSuffix + ".svg"), "Stop"); + QPushButton *resetBtn = new QPushButton(QIcon(":/icons/restart_alt" + iconSuffix + ".svg"), "Reset"); QHBoxLayout *stopResetLayout = new QHBoxLayout; // Setup and add widgets @@ -34,9 +35,13 @@ MainWindow::MainWindow(QWidget *parent) lineE ->setPlaceholderText("What to do next?"); time = 1500; + breakTime = 300; timeLbl->setText("25:00"); + breakTimeLbl->setText("5:00"); timeLbl->setFont(timerFont); + breakTimeLbl->setFont(timerFont); timeLbl->setAlignment(Qt::AlignCenter); + breakTimeLbl->setAlignment(Qt::AlignCenter); base ->setLayout(layout); scrAr ->setWidget(base); @@ -47,7 +52,8 @@ MainWindow::MainWindow(QWidget *parent) base ->setMinimumHeight(50); layout->setSizeConstraint(QLayout::SetMinimumSize); - tabWid->addTab(scrAr, QIcon(":/icons/preferences-system-time-symbolic" + iconSuffix + ".svg"), "Tasks"); + tabWid->addTab(scrAr, QIcon(":/icons/pending_actions" + iconSuffix + ".svg"), "Tasks"); + tabWid->addTab(breakTimeLbl, QIcon(":/icons/local_cafe" + iconSuffix + ".svg"), "Break"); tabWid->setMinimumSize(640, 480); // Connections @@ -72,10 +78,10 @@ void MainWindow::subTime() Time step logic If the current time is not zero, reduce it by 1 second else, remove the topmost task from the task list if the number of - widgets in layout is not 3 (i.e. there is at least 1 task), else + widgets in layout is not 4 (i.e. there is at least 1 task), else stop the timer */ - if (time != 0) time--; + if (time > 0) time--; else { if (layout->rowCount() == 4) { time = 1500; @@ -85,15 +91,23 @@ void MainWindow::subTime() remTask(); time = 1500; if (layout->rowCount() == 4) timer->stop(); + else startBreak(); } } timeLbl->setText(QString::number(time / 60) + ':' + QString::number(time % 60)); } +void MainWindow::subBreakTime() +{ + if (breakTime != 0) breakTime--; + else endBreak(); + breakTimeLbl->setText(QString::number(breakTime / 60) + ':' + QString::number(breakTime % 60)); +} + void MainWindow::resetTime() { time = 1500; - timeLbl->setText("25:00"); + timeLbl->setText(QString::number(time / 60) + ':' + QString::number(time % 60)); } void MainWindow::addTask() @@ -105,7 +119,7 @@ void MainWindow::addTask() */ if (!(lineE->text().isEmpty())) { QLabel *taskLbl = new QLabel; - QPushButton *remBtn = new QPushButton(QIcon(":/icons/edit-delete-symbolic" + iconSuffix + ".svg"), ""); + QPushButton *remBtn = new QPushButton(QIcon(":/icons/delete" + iconSuffix + ".svg"), ""); taskLbl->setText(lineE->text()); taskLbl->setFont(taskFont); connect(remBtn, &QPushButton::clicked, this, [this, taskLbl]{ remTask(taskLbl); }); @@ -131,3 +145,24 @@ void MainWindow::remTask(QLabel *lbl) layout->getWidgetPosition(lbl, &i, nullptr); layout->removeRow(i); } + +void MainWindow::startBreak() +{ + /* + Connect timer to subBreakTime and switch to break tab + */ + disconnect(timer, &QTimer::timeout, this, &MainWindow::subTime); + tabWid->setCurrentIndex(1); + connect(timer, &QTimer::timeout, this, &MainWindow::subBreakTime); +} + +void MainWindow::endBreak() +{ + /* + Reset break time, connect timer to subTime and switch to tasks tab + */ + breakTime = 300; + disconnect(timer, &QTimer::timeout, this, &MainWindow::subBreakTime); + tabWid->setCurrentIndex(0); + connect(timer, &QTimer::timeout, this, &MainWindow::subTime); +}