From 5d1fbe2c839aa33d3855a29efc628e49a17b95f4 Mon Sep 17 00:00:00 2001 From: Louie S Date: Wed, 21 Feb 2024 20:15:03 -0500 Subject: Create entry class --- src/entry.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/entry.cpp (limited to 'src/entry.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 + +#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() + "link.toString() + "\" " "style=\"color: " + (this->color.isEmpty() ? "default" : this->color ) + ";\">"); + } + body->setText(body->text() + this->desc); + if(!this->link.isEmpty()) { + body->setText(body->text() + ""); + 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); +} -- cgit