From 4e60e966ead945c2e1131d0ed0e303c5285bfbdc Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Wed, 27 Nov 2024 22:07:18 -0500 Subject: [PATCH] New built-in app: FlashExam (barebones flashcards app) --- inkbox.pro | 3 + src/apps/apps.cpp | 12 ++ src/apps/apps.h | 3 + src/apps/apps.ui | 205 ++++++++++++++++------------- src/apps/flashexam.cpp | 132 +++++++++++++++++++ src/apps/flashexam.h | 41 ++++++ src/apps/flashexam.ui | 290 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 596 insertions(+), 90 deletions(-) create mode 100644 src/apps/flashexam.cpp create mode 100644 src/apps/flashexam.h create mode 100644 src/apps/flashexam.ui diff --git a/inkbox.pro b/inkbox.pro index e5ed15d..acaa7d8 100644 --- a/inkbox.pro +++ b/inkbox.pro @@ -24,6 +24,7 @@ DEFINES += GIT_COMMIT=\\\"$$GIT_COMMIT\\\" #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + src/apps/flashexam.cpp \ src/apps/todo.cpp \ src/audio/audiothread.cpp \ src/splash/alert.cpp \ @@ -74,6 +75,7 @@ SOURCES += \ src/settings/powerdaemonsettings.cpp HEADERS += \ + src/apps/flashexam.h \ src/audio/audiothread.h \ src/apps/todo.h \ src/splash/alert.h \ @@ -124,6 +126,7 @@ HEADERS += \ src/settings/powerdaemonsettings.h FORMS += \ + src/apps/flashexam.ui \ src/apps/todo.ui \ src/splash/alert.ui \ src/apps/apps.ui \ diff --git a/src/apps/apps.cpp b/src/apps/apps.cpp index 2368721..da751a1 100644 --- a/src/apps/apps.cpp +++ b/src/apps/apps.cpp @@ -24,6 +24,7 @@ apps::apps(QWidget *parent) : ui->reversiLaunchBtn->setProperty("type", "borderless"); ui->g2048LaunchBtn->setProperty("type", "borderless"); ui->todoLaunchBtn->setProperty("type", "borderless"); + ui->flashExamLaunchBtn->setProperty("type", "borderless"); ui->label->setStyleSheet("padding-top: 2px; padding-bottom: 5px"); ui->koboxAppsOpenButton->setStyleSheet("background: lightGrey; font-size: 9pt; padding: 8px"); @@ -34,6 +35,7 @@ apps::apps(QWidget *parent) : ui->reversiLaunchBtn->setStyleSheet("background: lightGrey; font-size: 9pt; padding: 8px"); ui->g2048LaunchBtn->setStyleSheet("background: lightGrey; font-size: 9pt; padding: 8px"); ui->todoLaunchBtn->setStyleSheet("background: lightGrey; font-size: 9pt; padding: 8px"); + ui->flashExamLaunchBtn->setStyleSheet("background: lightGrey; font-size: 9pt; padding: 8px"); ui->noUserAppsAvailableLabel->hide(); @@ -376,3 +378,13 @@ void apps::on_todoLaunchBtn_clicked() todoWindow->setGeometry(QRect(QPoint(0,0), qApp->primaryScreen()->geometry().size())); todoWindow->show(); } + +void apps::on_flashExamLaunchBtn_clicked() +{ + flashExam * flashExamWindow = new flashExam(); + QObject::connect(flashExamWindow, &flashExam::showToast, this, &apps::showToast); + flashExamWindow->setAttribute(Qt::WA_DeleteOnClose); + flashExamWindow->setGeometry(QRect(QPoint(0,0), qApp->primaryScreen()->geometry().size())); + flashExamWindow->show(); +} + diff --git a/src/apps/apps.h b/src/apps/apps.h index d9d138b..91b448b 100644 --- a/src/apps/apps.h +++ b/src/apps/apps.h @@ -7,6 +7,7 @@ #include "koboxappsdialog.h" #include "generaldialog.h" #include "todo.h" +#include "flashexam.h" #include @@ -41,6 +42,8 @@ private slots: void showFailedToParseMainUserAppsJsonFile(); void on_todoLaunchBtn_clicked(); + void on_flashExamLaunchBtn_clicked(); + private: Ui::apps * ui; savedwords * savedWordsWindow; diff --git a/src/apps/apps.ui b/src/apps/apps.ui index c43b243..37a6de8 100644 --- a/src/apps/apps.ui +++ b/src/apps/apps.ui @@ -34,16 +34,16 @@ - QFrame::NoFrame + QFrame::Shape::NoFrame - QFrame::Plain + QFrame::Shadow::Plain 0 - Qt::ScrollBarAlwaysOff + Qt::ScrollBarPolicy::ScrollBarAlwaysOff true @@ -53,8 +53,8 @@ 0 0 - 428 - 542 + 407 + 566 @@ -98,20 +98,20 @@ Built-in apps - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter - QFrame::Plain + QFrame::Shadow::Plain 3 - Qt::Horizontal + Qt::Orientation::Horizontal @@ -123,44 +123,8 @@ 10 - - - - - true - - - - KoBox apps - - - - - - - - true - - - - Launch - - - - - - - - true - - - - Reversi - - - - - + + Inter @@ -184,15 +148,29 @@ - - + + + Inter true - Calendar + Launch + + + + + + + + Inter + true + + + + Launch @@ -221,8 +199,8 @@ - - + + Inter @@ -234,6 +212,54 @@ + + + + + true + + + + Calendar + + + + + + + + true + + + + Launch + + + + + + + + true + + + + Reversi + + + + + + + + true + + + + Qalculate! + + + @@ -258,6 +284,18 @@ + + + + + true + + + + KoBox apps + + + @@ -270,19 +308,6 @@ - - - - - Inter - true - - - - Launch - - - @@ -296,20 +321,8 @@ - - - - - true - - - - Qalculate! - - - - - + + Inter @@ -321,6 +334,18 @@ + + + + + true + + + + FlashExam + + + @@ -328,13 +353,13 @@ - QFrame::Plain + QFrame::Shadow::Plain 3 - Qt::Horizontal + Qt::Orientation::Horizontal @@ -352,7 +377,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -381,7 +406,7 @@ User apps - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter @@ -390,10 +415,10 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -413,7 +438,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -428,13 +453,13 @@ - QFrame::Plain + QFrame::Shadow::Plain 3 - Qt::Horizontal + Qt::Orientation::Horizontal @@ -460,17 +485,17 @@ No user apps currently available - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::MinimumExpanding + QSizePolicy::Policy::MinimumExpanding diff --git a/src/apps/flashexam.cpp b/src/apps/flashexam.cpp new file mode 100644 index 0000000..cb88f79 --- /dev/null +++ b/src/apps/flashexam.cpp @@ -0,0 +1,132 @@ +#include "flashexam.h" +#include "ui_flashexam.h" + +#include "functions.h" + +flashExam::flashExam(QWidget *parent) + : QWidget(parent) + , ui(new Ui::flashExam) +{ + ui->setupUi(this); + this->setStyleSheet(readFile("/mnt/onboard/.adds/inkbox/eink.qss")); + this->setFont(QFont("u001")); + ui->listWidget->setFont(QFont("u001")); + ui->textBrowser->setFont(QFont("u001")); + + ui->startBtn->setProperty("type", "borderless"); + ui->closeBtn->setProperty("type", "borderless"); + ui->revealBtn->setProperty("type", "borderless"); + ui->nextBtn->setProperty("type", "borderless"); + ui->backBtn->setProperty("type", "borderless"); + ui->startBtn->setStyleSheet("padding: 20px; QPushButton[type='borderless']:pressed { background: black; color: white; border: none }"); + ui->closeBtn->setStyleSheet("QPushButton[type='borderless']:pressed { background: black; color: white; border: none}"); + ui->revealBtn->setStyleSheet("padding: 20px; QPushButton[type='borderless']:pressed { background: black; color: white; border: none}"); + ui->nextBtn->setStyleSheet("padding: 20px; QPushButton[type='borderless']:pressed { background: black; color: white; border: none}"); + ui->backBtn->setStyleSheet("QPushButton[type='borderless']:pressed { background: black; color: white; border: none}"); + ui->closeBtn->setIcon(QIcon(":/resources/close.png")); + ui->backBtn->setIcon(QIcon(":/resources/arrow-left.png")); + ui->randomizeCheckBox->click(); + + setupCardsList(); +} + +flashExam::~flashExam() +{ + delete ui; +} + +void flashExam::on_closeBtn_clicked() +{ + this->close(); +} + +void flashExam::setupCardsList() { + QDir dir("/mnt/onboard/onboard/.flashexam"); + for (const QString &filename : dir.entryList(QDir::Files)) { + ui->listWidget->addItem(filename); + } +} + +void flashExam::on_startBtn_clicked() +{ + QString currentItem = ui->listWidget->currentItem()->text(); + if(ui->listWidget->selectedItems().isEmpty()) { + emit showToast("You must select a cards list"); + } + else { + QString cardsList = "/mnt/onboard/onboard/.flashexam/" + currentItem; + QString answersList = "/mnt/onboard/onboard/.flashexam/" + currentItem + ".answers"; + if(QFile::exists(answersList)) { + log("Setting up cards list '" + currentItem + "'", className); + initCardsList(cardsList, answersList); + } + else { + emit showToast("No answers file found"); + } + } +} + +void flashExam::initCardsList(QString cardsList, QString answersList) { + cardsStringList = readFile(cardsList).split(QRegExp("(\\r\\n)|(\\n\\r)|\\r|\\n"), QString::SkipEmptyParts); + answersStringList = readFile(answersList).split(QRegExp("(\\r\\n)|(\\n\\r)|\\r|\\n"), QString::SkipEmptyParts); + randomize = ui->randomizeCheckBox->isChecked(); + + int it = 1; + for (auto& i : cardsStringList) { + i.prepend(QString::number(it) + " "); + it += 1; + } + + it = 1; + for (auto& i : answersStringList) { + i.prepend(QString::number(it) + " "); + it += 1; + } + + cardsTotal = it; + displayCard(false); + ui->stackedWidget->setCurrentIndex(1); +} + +void flashExam::on_backBtn_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); +} + + +void flashExam::on_revealBtn_clicked() +{ + if(answerShown) { + displayCard(true); + answerShown = false; + ui->revealBtn->setText("Show answer"); + } + else { + QString answerText = answersStringList.at(currentCardNumber); + answerText.remove(0, 2); + ui->textBrowser->setText(answerText); + answerShown = true; + ui->revealBtn->setText("Hide answer"); + } +} + + +void flashExam::on_nextBtn_clicked() +{ + displayCard(false); +} + +void flashExam::displayCard(bool existingCardNumber) { + QString cardText; + if(!existingCardNumber) { + if(randomize) { + currentCardNumber = QRandomGenerator::global()->bounded(cardsTotal - 1); + } + } + cardText = cardsStringList.at(currentCardNumber); + ui->graphicsView->hide(); + cardText.remove(0, 2); + ui->cardNumberLabel->setText("Card " + QString::number(currentCardNumber + 1)); + ui->textBrowser->setText(cardText); +} + diff --git a/src/apps/flashexam.h b/src/apps/flashexam.h new file mode 100644 index 0000000..5f3c655 --- /dev/null +++ b/src/apps/flashexam.h @@ -0,0 +1,41 @@ +#ifndef FLASHEXAM_H +#define FLASHEXAM_H + +#include + +namespace Ui { +class flashExam; +} + +class flashExam : public QWidget +{ + Q_OBJECT + +public: + QString className = this->metaObject()->className(); + explicit flashExam(QWidget *parent = nullptr); + ~flashExam(); + +private: + Ui::flashExam *ui; + int cardsTotal; + int currentCardNumber; + bool randomize; + bool answerShown = false; + QStringList cardsStringList; + QStringList answersStringList; + void setupCardsList(); + void initCardsList(QString cardsList, QString answersList); + void displayCard(bool existingCardNumber); + +signals: + void showToast(QString messageToDisplay); +private slots: + void on_closeBtn_clicked(); + void on_startBtn_clicked(); + void on_backBtn_clicked(); + void on_revealBtn_clicked(); + void on_nextBtn_clicked(); +}; + +#endif // FLASHEXAM_H diff --git a/src/apps/flashexam.ui b/src/apps/flashexam.ui new file mode 100644 index 0000000..fe49268 --- /dev/null +++ b/src/apps/flashexam.ui @@ -0,0 +1,290 @@ + + + flashExam + + + + 0 + 0 + 580 + 636 + + + + Form + + + + + + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + true + + + + Start + + + + + + + QFrame::Shadow::Plain + + + 2 + + + Qt::Orientation::Horizontal + + + + + + + + U001 + + + + Randomized mode + + + + + + + 0 + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + U001 + + + + Select a cards list + + + + + + + + true + + + + FlashExam + + + Qt::AlignmentFlag::AlignCenter + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + QFrame::Shadow::Plain + + + Qt::Orientation::Horizontal + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + 0 + + + + + + + + + + + + + U001 + + + + Card number + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + + true + + + + Next card + + + + + + + QFrame::Shadow::Plain + + + Qt::Orientation::Horizontal + + + + + + + + + + + + + + true + + + + Show answer + + + + + + + QFrame::Shadow::Plain + + + 2 + + + Qt::Orientation::Horizontal + + + + + + + QFrame::Shadow::Plain + + + 2 + + + Qt::Orientation::Horizontal + + + + + + + + + + + + + +