diff options
author | Louie S <louie@example.com> | 2024-02-21 20:15:03 -0500 |
---|---|---|
committer | Louie S <louie@example.com> | 2024-02-21 20:15:03 -0500 |
commit | 5d1fbe2c839aa33d3855a29efc628e49a17b95f4 (patch) | |
tree | e8f85cb80fbd9ed1a76c68d096d69b7577f68f8f | |
parent | 2af22ca34e5120ba69cf20911bf802be57cc18dd (diff) |
Create entry class
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/entry.cpp | 82 | ||||
-rw-r--r-- | src/entry.h | 36 | ||||
-rw-r--r-- | src/group.h | 8 |
4 files changed, 127 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ae8e9e..c623193 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,8 @@ set(project_sources "src/assignmentList.cpp" "src/assignmentList.h" "src/assignmentList.ui" + "src/entry.cpp" + "src/entry.h" "src/group.cpp" "src/group.h" "src/main.cpp" diff --git a/src/entry.cpp b/src/entry.cpp new file mode 100644 index 0000000..ed602d0 --- /dev/null +++ b/src/entry.cpp @@ -0,0 +1,82 @@ +#include <QLabel> + +#include "entry.h" + +Entry::Entry(int id, int parent_id, QString desc, QDateTime due, QString due_alt, QUrl link, QString color, QString highlight, bool done, bool hidden) : + id(id), + parent_id(parent_id), + desc(desc), + due(due), + due_alt(due_alt), + link(link), + color(color), + highlight(highlight), + done(done), + hidden(hidden) +{ + QLabel *bullet = new QLabel(); + QLabel *body = new QLabel(); + + // set styling + this->setContentsMargins(2, 2, 2, 2); + + bullet->setFont(QFont("Arial", 11)); + bullet->setMaximumWidth(15); + + body->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); + body->setFont(QFont("Arial", 11)); + body->setWordWrap(true); + body->setToolTip("Right-Click for actions"); + + // Check rules + // TODO + + // set conditional styling + if(this->done) { + bullet->setText("\u2713"); + bullet->setStyleSheet( + "QLabel {" + " color: green;" + "}" + ); + } + else + bullet->setText("- "); + this->addWidget(bullet); + + if(!this->due.isNull()) + body->setText(this->due.toString("M/d/yyyy")); + else if(!this->due_alt.isEmpty()) + body->setText(this->due_alt + ": "); + + if(!this->link.isEmpty()) { + body->setOpenExternalLinks(true); + body->setText(body->text() + "<a href=\"" + this->link.toString() + "\" " "style=\"color: " + (this->color.isEmpty() ? "default" : this->color ) + ";\">"); + } + body->setText(body->text() + this->desc); + if(!this->link.isEmpty()) { + body->setText(body->text() + "</a>"); + body->setToolTip(this->link.toString()); + } + + if(this->done) { + QFont body_font = body->font(); + body_font.setStrikeOut(true); + body->setFont(body_font); + body->setStyleSheet( + "QLabel {" + " color: green" + "}" + ); + } + else { + body->setStyleSheet( + "QLabel {" + " color: " + (this->color.isEmpty() ? "default" : this->color) + ";" + " background-color: " + (this->highlight.isEmpty() ? "none" : this->highlight) + ";" + " font-weight: " + (this->due.isValid() && this->due <= QDateTime::currentDateTime() ? "bold" : "normal") + ";" + ";" + ); + } + this->addWidget(body); +} diff --git a/src/entry.h b/src/entry.h new file mode 100644 index 0000000..6bee76c --- /dev/null +++ b/src/entry.h @@ -0,0 +1,36 @@ +#ifndef ENTRY_H +#define ENTRY_H + +#include <QDateTime> +#include <QHBoxLayout> +#include <QString> +#include <QUrl> + +class Entry : QHBoxLayout { + public: + int id; + int parent_id; + QString desc; + QDateTime due; + QString due_alt; + QUrl link; + QString color; // consider making this a QColor instead + QString highlight; // see color comment + bool done; + bool hidden; + + Entry( + int id, + int parent_id, + QString desc, + QDateTime due = QDateTime(), + QString due_alt = "", + QUrl link = QUrl(), + QString color = "", + QString highlight = "", + bool done = false, + bool hidden = false + ); +}; + +#endif diff --git a/src/group.h b/src/group.h index 2c450f1..901a29f 100644 --- a/src/group.h +++ b/src/group.h @@ -12,7 +12,13 @@ class Group : QVBoxLayout { QString link; bool hidden; - Group(int id, QString name, QString column = "left", QString link = "", bool hidden = false); + Group( + int id, + QString name, + QString column = "left", + QString link = "", + bool hidden = false + ); }; #endif |