Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
* The program now uses a Qt Resource for managing icons instead of hardcoded file paths
* The base layout is now a QFormLayout
* The user can now stop and reset the timer
  • Loading branch information
nsh07 committed Dec 27, 2022
2 parents 72af47e + 7bb03fe commit c3fdbd5
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 38 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
build/
bin/
CMakeLists.txt.user
compile_commands.json
cmake_install.cmake
CMakeCache.txt
pomodoro_autogen/
Makefile
.cache/
.qt/
CMakeFiles/
todo.txt
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project(pomodoro VERSION 0.1 LANGUAGES CXX)
project(pomodoro VERSION 0.2 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

Expand All @@ -16,10 +16,14 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

set(PROJECT_SOURCES
set(
PROJECT_SOURCES
resources.qrc

src/customtimer.cpp
src/main.cpp
src/mainwindow.cpp

include/customtimer.h
include/mainwindow.h
)
Expand Down
3 changes: 3 additions & 0 deletions icons/list-add-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions icons/media-playback-stop-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions icons/system-restart-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <QLabel>
#include <QTabWidget>
#include <QVBoxLayout>
#include <QFormLayout>
#include <QLineEdit>
#include <QScrollArea>
#include <QFont>
Expand All @@ -23,18 +23,18 @@ class MainWindow : public QMainWindow

public slots:
void addTask();
void remTask(int index=2);
void remTask(int index=3);
void subTime();
void resetTime();

private:
QScrollArea *scrAr;
QWidget *base;
QTabWidget *tabWid;
QLabel *timeLbl;
QVBoxLayout *layout;
QFormLayout *layout;

QPushButton *addBtn;
QHBoxLayout *newTaskLayout;
QLineEdit *lineE;

int time;
Expand Down
9 changes: 9 additions & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<RCC>
<qresource prefix="/">
<file>icons/media-playback-start-symbolic.svg</file>
<file>icons/media-playback-stop-symbolic.svg</file>
<file>icons/preferences-system-time-symbolic.svg</file>
<file>icons/system-restart-symbolic.svg</file>
<file>icons/list-add-symbolic.svg</file>
</qresource>
</RCC>
76 changes: 44 additions & 32 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
#include "mainwindow.h"
#include "customtimer.h"
#include <QIcon>
#include <QPalette>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// Initialize all variables/pointers
base = new QWidget;
scrAr = new QScrollArea;
layout = new QVBoxLayout(base); // Base layout
tabWid = new QTabWidget(this);
timeLbl = new QLabel;
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);
addBtn = new QPushButton("Add task");
newTaskLayout = new QHBoxLayout; // Layout that holds the new task line edit and button
lineE = new QLineEdit;
timer = new CustomTimer;
QPushButton *playBtn = new QPushButton(QIcon("../icons/media-playback-start-symbolic.svg"), "Start");
taskFont = QFont("sans-serif", 18);
lineE = new QLineEdit;
timer = new CustomTimer;
addBtn = new QPushButton(QIcon(":/icons/list-add-symbolic.svg"), "");
QPushButton *startBtn = new QPushButton(QIcon(":/icons/media-playback-start-symbolic.svg"), "Start");
QPushButton *stopBtn = new QPushButton(QIcon(":/icons/media-playback-stop-symbolic.svg"), "Stop");
QPushButton *resetBtn = new QPushButton(QIcon(":/icons/system-restart-symbolic.svg"), "Reset");
QHBoxLayout *stopResetLayout = new QHBoxLayout;

// Setup and add widgets
newTaskLayout->addWidget(lineE);
newTaskLayout->addWidget(addBtn);
stopResetLayout->addWidget(stopBtn);
stopResetLayout->addWidget(resetBtn);

lineE-> setPlaceholderText("What to do next?");
lineE ->setPlaceholderText("What to do next?");
time = 1500;
timeLbl->setText("25:00");
timeLbl->setFont(timerFont);
timeLbl->setAlignment(Qt::AlignCenter);

base-> setLayout(layout);
scrAr-> setWidget(base);
layout->addWidget(timeLbl);
layout->addWidget(playBtn);
base-> setMinimumHeight(50);
base ->setLayout(layout);
scrAr ->setWidget(base);
layout->addRow(timeLbl);
layout->addRow(startBtn);
layout->addRow(stopResetLayout);
layout->addRow(addBtn, lineE);
base ->setMinimumHeight(50);
layout->setSizeConstraint(QLayout::SetMinimumSize);

tabWid->addTab(scrAr, QIcon("../icons/preferences-system-time-symbolic.svg"), "Tasks");
tabWid->setMinimumSize(500, 400);

layout->addLayout(newTaskLayout);
tabWid->addTab(scrAr, QIcon(":/icons/preferences-system-time-symbolic.svg"), "Tasks");
tabWid->setMinimumSize(640, 480);

// Connections
connect(addBtn, &QPushButton::clicked, this, &MainWindow::addTask);
connect(timer, &QTimer::timeout, this, &MainWindow::subTime);
connect(playBtn, &QPushButton::clicked, timer, &CustomTimer::startTmr);
connect(addBtn, &QPushButton::clicked, this, &MainWindow::addTask );
connect(lineE, &QLineEdit::returnPressed, this, &MainWindow::addTask );
connect(timer, &QTimer::timeout, this, &MainWindow::subTime );
connect(startBtn, &QPushButton::clicked, timer, &CustomTimer::startTmr);
connect(stopBtn, &QPushButton::clicked, timer, &CustomTimer::stop );
connect(resetBtn, &QPushButton::clicked, this, &MainWindow::resetTime);

layout->setAlignment(Qt::AlignCenter);
scrAr-> setAlignment(Qt::AlignCenter);
this-> setCentralWidget(tabWid);
scrAr->setAlignment(Qt::AlignCenter);
this ->setCentralWidget(tabWid);
}

MainWindow::~MainWindow()
Expand All @@ -65,19 +71,25 @@ void MainWindow::subTime()
*/
if (time != 0) time--;
else {
if (layout->count() == 3) {
if (layout->count() == 4) {
time = 1500;
timer->stop();
}
else {
remTask();
time = 1500;
if (layout->count() == 3) timer->stop();
if (layout->count() == 4) timer->stop();
}
}
timeLbl->setText(QString::number(time / 60) + ':' + QString::number(time % 60));
}

void MainWindow::resetTime()
{
time = 1500;
timeLbl->setText("25:00");
}

void MainWindow::addTask()
{
/*
Expand All @@ -88,7 +100,7 @@ void MainWindow::addTask()
taskLbl->setText(lineE->text());
taskLbl->setFont(taskFont);

layout->insertWidget(layout->count()-1, taskLbl);
layout->insertRow(layout->count()-2, taskLbl);
lineE->clear();
}
}
Expand Down

0 comments on commit c3fdbd5

Please sign in to comment.