To-Do app: Basic working prototype

This commit is contained in:
Nicolas Mailloux 2022-09-14 08:30:17 -04:00
parent e94de73eb3
commit afa7220f92
6 changed files with 449 additions and 315 deletions

View file

@ -10,17 +10,26 @@ todo::todo(QWidget *parent) :
ui->setupUi(this);
this->setStyleSheet(readFile("/mnt/onboard/.adds/inkbox/eink.qss"));
this->setFont(QFont("u001"));
ui->listWidget->setFont(QFont("u001"));
ui->itemsListWidget->setFont(QFont("u001"));
ui->deleteBtn->setEnabled(false);
ui->setupBtn->setEnabled(false);
ui->closeBtn->setProperty("type", "borderless");
ui->newListBtn->setProperty("type", "borderless");
ui->newBtn->setProperty("type", "borderless");
ui->deleteBtn->setProperty("type", "borderless");
ui->setupBtn->setProperty("type", "borderless");
ui->deleteBtn->setStyleSheet("padding: 10px");
ui->setupBtn->setStyleSheet("padding: 10px");
ui->closeBtn->setIcon(QIcon(":/resources/close.png"));
ui->newListBtn->setIcon(QIcon(":/resources/new.png"));
ui->newBtn->setIcon(QIcon(":/resources/new.png"));
ui->deleteBtn->setIcon(QIcon(":/resources/x-circle.png"));
ui->setupBtn->setIcon(QIcon(":/resources/arrow-right.png"));
ui->listWidget->setStyleSheet("font-size: 10pt");
ui->listWidget->setWordWrap(true);
ui->itemsListWidget->setStyleSheet("font-size: 10pt");
ui->itemsListWidget->setWordWrap(true);
refreshList();
}
@ -32,18 +41,34 @@ todo::~todo()
void todo::on_closeBtn_clicked()
{
this->close();
if(currentView == currentView::home) {
this->close();
}
else {
saveCurrentList();
ui->stackedWidget->setCurrentIndex(0);
ui->closeBtn->setIcon(QIcon(":/resources/close.png"));
ui->deleteBtn->setEnabled(true);
ui->setupBtn->setEnabled(true);
currentView = currentView::home;
}
}
void todo::on_newListBtn_clicked()
void todo::on_newBtn_clicked()
{
global::keyboard::embed = false;
virtualkeyboard * virtualKeyboardWidget = new virtualkeyboard(this);
virtualKeyboardWidget->setAttribute(Qt::WA_DeleteOnClose);
QObject::connect(virtualKeyboardWidget, &virtualkeyboard::enterBtnPressed, this, &todo::createNewList);
if(currentView == currentView::home) {
QObject::connect(virtualKeyboardWidget, &virtualkeyboard::enterBtnPressed, this, &todo::createNewList);
ui->statusLabel->setText("Enter the list's name");
}
else {
QObject::connect(virtualKeyboardWidget, &virtualkeyboard::enterBtnPressed, this, &todo::addItem);
ui->statusLabel->setText("Enter the item's name");
}
virtualKeyboardWidget->show();
ui->statusLabel->setText("Enter the list's name");
}
void todo::createNewList(QString listName) {
@ -69,6 +94,31 @@ void todo::createNewList(QString listName) {
refreshList();
}
void todo::addItem(QString itemName) {
log("Adding item with name '" + itemName + "' to current list", className);
// Accessing the current list's items array
QJsonDocument document = readTodoDatabase();
QJsonObject object = document.object();
QJsonArray mainArray = object["List"].toArray();
QJsonArray listArray = mainArray.at(listIndex).toArray();
QJsonArray itemArray;
// Item name
itemArray.insert(0, itemName);
// Check state (always set to false)
itemArray.insert(1, false);
// Adding item array to list array
listArray.push_back(itemArray);
mainArray.replace(listIndex, listArray);
object["List"] = mainArray;
document.setObject(object);
writeTodoDatabase(document);
setupList(listArray.at(0).toString());
}
void todo::refreshList() {
if(QFile::exists(global::localLibrary::todoDatabasePath)) {
ui->listWidget->clear();
@ -85,16 +135,40 @@ void todo::refreshList() {
void todo::setupList(QString listName) {
log("Setting up list with name '" + listName + "'", className);
QJsonArray array = readTodoDatabase().object()["List"].toArray();
int index;
// Iterate through the To-Do lists array to find the list's array index
for(int i = 0; i < array.count(); i++) {
QString name = array.at(i).toArray().at(0).toString();
log("name is " + name);
if(name == listName) {
index = i;
listIndex = i;
break;
}
}
log("List index is " + QString::number(index), className);
log("List index is " + QString::number(listIndex), className);
ui->stackedWidget->setCurrentIndex(1);
currentView = currentView::list;
// Iterate through the selected list's array to find item arrays
int count = array.at(listIndex).toArray().count();
log("List's items count is " + QString::number(count - 1), className);
// Starting at index 1 because 0 represents the list's name
ui->itemsListWidget->clear();
for(int i = 1; i < count; i++) {
QJsonArray itemArray = array.at(listIndex).toArray().at(i).toArray();
QListWidgetItem * item = new QListWidgetItem();
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
// Set the item's name
item->setText(array.at(listIndex).toArray().at(i).toArray().at(0).toString());
// Is the item checked?
if(itemArray.at(1).toBool() == true) {
item->setCheckState(Qt::Checked);
}
else {
item->setCheckState(Qt::Unchecked);
}
ui->itemsListWidget->addItem(item);
}
ui->closeBtn->setIcon(QIcon(":/resources/check.png"));
ui->statusLabel->setText("Select or create a new item");
}
void todo::on_setupBtn_clicked()
@ -110,3 +184,32 @@ void todo::on_listWidget_itemClicked(QListWidgetItem *item)
ui->deleteBtn->setEnabled(true);
ui->setupBtn->setEnabled(true);
}
void todo::saveCurrentList() {
QJsonDocument document = readTodoDatabase();
QJsonObject object = document.object();
QJsonArray mainArray = object["List"].toArray();
QJsonArray listArray = mainArray.at(listIndex).toArray();
for(int i = 1; i < ui->itemsListWidget->count() + 1; i++) {
QJsonArray itemArray = listArray.at(i).toArray();
if(ui->itemsListWidget->item(i - 1)->checkState() == Qt::Checked) {
itemArray.replace(1, true);
}
else {
itemArray.replace(1, false);
}
listArray.replace(i, itemArray);
}
// Adding item array to list array
mainArray.replace(listIndex, listArray);
object["List"] = mainArray;
document.setObject(object);
writeTodoDatabase(document);
}
void todo::on_deleteBtn_clicked()
{
}

View file

@ -18,15 +18,24 @@ public:
QString className = this->metaObject()->className();
explicit todo(QWidget *parent = nullptr);
~todo();
enum class currentView {
home,
list
};
currentView currentView = currentView::home;
int listIndex;
private slots:
void on_closeBtn_clicked();
void on_newListBtn_clicked();
void on_newBtn_clicked();
void createNewList(QString listName);
void addItem(QString itemName);
void refreshList();
void saveCurrentList();
void setupList(QString listName);
void on_setupBtn_clicked();
void on_listWidget_itemClicked(QListWidgetItem *item);
void on_deleteBtn_clicked();
private:
Ui::todo *ui;

View file

@ -78,7 +78,7 @@
</spacer>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="newListBtn">
<widget class="QPushButton" name="newBtn">
<property name="text">
<string/>
</property>
@ -133,73 +133,55 @@
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<widget class="Line" name="line_4">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>4</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>382</width>
<height>229</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="deleteBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="setupBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="deleteBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="setupBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_4">
@ -217,7 +199,11 @@
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5"/>
<layout class="QVBoxLayout" name="listVerticalLayout">
<item>
<widget class="QListWidget" name="itemsListWidget"/>
</item>
</layout>
</item>
</layout>
</widget>

View file

@ -19,6 +19,7 @@ virtualkeyboard::virtualkeyboard(QWidget *parent) :
ui->rightSpacerWidget->hide();
ui->leftSpacerWidget->deleteLater();
ui->rightSpacerWidget->deleteLater();
ui->closeBtn->setProperty("type", "borderless");
ui->enterBtn->setProperty("type", "borderless");
{
int padding = 13;
@ -28,12 +29,18 @@ virtualkeyboard::virtualkeyboard(QWidget *parent) :
else if(global::deviceID == "n437\n") {
padding = 20;
}
ui->closeBtn->setStyleSheet("font-weight: bold; font-size: 9pt; padding: " + QString::number(padding) + "px");
ui->closeBtn->setIcon(QIcon(":/resources/close.png"));
ui->enterBtn->setStyleSheet("font-weight: bold; font-size: 9pt; padding: " + QString::number(padding) + "px");
ui->enterBtn->setIcon(QIcon(":/resources/arrow-right.png"));
}
}
else {
embed = true;
ui->line->hide();
ui->line->deleteLater();
ui->closeBtn->hide();
ui->closeBtn->deleteLater();
ui->enterBtn->hide();
ui->enterBtn->deleteLater();
}
@ -705,7 +712,7 @@ void virtualkeyboard::adjust_size_function() {
emit adjust_size();
}
else {
this->setFixedHeight(QGuiApplication::screens()[0]->size().height() * 45 / 100);
this->setFixedHeight(QGuiApplication::screens()[0]->size().height() * 50 / 100);
this->setFixedWidth(QGuiApplication::screens()[0]->size().width());
this->move(0, (QGuiApplication::screens()[0]->size().height() - this->height()));
}
@ -719,6 +726,13 @@ void virtualkeyboard::clearLineEdit() {
void virtualkeyboard::on_enterBtn_clicked()
{
emit enterBtnPressed(ui->lineEdit->text());
global::keyboard::keyboardText = ui->lineEdit->text();
emit enterBtnPressed(global::keyboard::keyboardText);
this->close();
}
void virtualkeyboard::on_closeBtn_clicked()
{
global::keyboard::keyboardText = "";
this->close();
}

View file

@ -72,6 +72,8 @@ private slots:
void adjust_size_function();
void on_enterBtn_clicked();
void on_closeBtn_clicked();
private:
Ui::virtualkeyboard *ui;
keyboardMode currentMode = keyboardMode::lowerCase;

View file

@ -30,6 +30,19 @@
<widget class="QStackedWidget" name="mainWidget">
<widget class="QWidget" name="page_7">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="Line" name="line">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="bottomMargin">
@ -76,23 +89,6 @@
</property>
</widget>
</item>
<item row="1" column="2">
<layout class="QGridLayout" name="gridLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="enterBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="2">
<widget class="QStackedWidget" name="stackedWidget">
<property name="lineWidth">
@ -119,10 +115,73 @@
<layout class="QGridLayout" name="gridLayout_3">
<item row="13" column="3">
<layout class="QGridLayout" name="gridLayout_4">
<item row="2" column="12">
<widget class="QPushButton" name="lp">
<item row="7" column="12">
<widget class="QPushButton" name="eraseBtn">
<property name="text">
<string>p</string>
<string>⌫</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="n3">
<property name="text">
<string>3</string>
</property>
</widget>
</item>
<item row="7" column="9">
<widget class="QPushButton" name="lm">
<property name="text">
<string>m</string>
</property>
</widget>
</item>
<item row="6" column="4">
<widget class="QPushButton" name="ld">
<property name="text">
<string>d</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="lq">
<property name="text">
<string>q</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="n2">
<property name="text">
<string>2</string>
</property>
</widget>
</item>
<item row="6" column="7">
<widget class="QPushButton" name="lg">
<property name="text">
<string>g</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QPushButton" name="lz">
<property name="text">
<string>z</string>
</property>
</widget>
</item>
<item row="0" column="10">
<widget class="QPushButton" name="n9">
<property name="text">
<string>9</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QPushButton" name="n4">
<property name="text">
<string>4</string>
</property>
</widget>
</item>
@ -133,6 +192,27 @@
</property>
</widget>
</item>
<item row="0" column="9">
<widget class="QPushButton" name="n8">
<property name="text">
<string>8</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="lw">
<property name="text">
<string>w</string>
</property>
</widget>
</item>
<item row="6" column="12">
<widget class="QPushButton" name="ll">
<property name="text">
<string>l</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="le">
<property name="text">
@ -140,6 +220,55 @@
</property>
</widget>
</item>
<item row="7" column="7">
<widget class="QPushButton" name="lb">
<property name="text">
<string>b</string>
</property>
</widget>
</item>
<item row="6" column="9">
<widget class="QPushButton" name="lj">
<property name="text">
<string>j</string>
</property>
</widget>
</item>
<item row="7" column="4">
<widget class="QPushButton" name="lc">
<property name="text">
<string>c</string>
</property>
</widget>
</item>
<item row="2" column="8">
<widget class="QPushButton" name="lu">
<property name="text">
<string>u</string>
</property>
</widget>
</item>
<item row="6" column="8">
<widget class="QPushButton" name="lh">
<property name="text">
<string>h</string>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QPushButton" name="n7">
<property name="text">
<string>7</string>
</property>
</widget>
</item>
<item row="6" column="10">
<widget class="QPushButton" name="lk">
<property name="text">
<string>k</string>
</property>
</widget>
</item>
<item row="0" column="12">
<widget class="QPushButton" name="n0">
<property name="text">
@ -147,10 +276,87 @@
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="lr">
<item row="2" column="10">
<widget class="QPushButton" name="lo">
<property name="text">
<string>r</string>
<string>o</string>
</property>
</widget>
</item>
<item row="6" column="6">
<widget class="QPushButton" name="lf">
<property name="text">
<string>f</string>
</property>
</widget>
</item>
<item row="2" column="9">
<widget class="QPushButton" name="li">
<property name="text">
<string>i</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QPushButton" name="shiftBtn">
<property name="text">
<string>⇧</string>
</property>
</widget>
</item>
<item row="6" column="3">
<widget class="QPushButton" name="ls">
<property name="text">
<string>s</string>
</property>
</widget>
</item>
<item row="7" column="10">
<widget class="QPushButton" name="spt">
<property name="text">
<string>.</string>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QPushButton" name="lt">
<property name="text">
<string>t</string>
</property>
</widget>
</item>
<item row="7" column="8">
<widget class="QPushButton" name="ln">
<property name="text">
<string>n</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="sat">
<property name="text">
<string>#</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QPushButton" name="la">
<property name="text">
<string>a</string>
</property>
</widget>
</item>
<item row="2" column="12">
<widget class="QPushButton" name="lp">
<property name="text">
<string>p</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="n1">
<property name="text">
<string>1</string>
</property>
</widget>
</item>
@ -168,62 +374,6 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="n2">
<property name="text">
<string>2</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="n3">
<property name="text">
<string>3</string>
</property>
</widget>
</item>
<item row="0" column="10">
<widget class="QPushButton" name="n9">
<property name="text">
<string>9</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="n1">
<property name="text">
<string>1</string>
</property>
</widget>
</item>
<item row="7" column="4">
<widget class="QPushButton" name="lc">
<property name="text">
<string>c</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QPushButton" name="shiftBtn">
<property name="text">
<string>⇧</string>
</property>
</widget>
</item>
<item row="7" column="7">
<widget class="QPushButton" name="lb">
<property name="text">
<string>b</string>
</property>
</widget>
</item>
<item row="0" column="9">
<widget class="QPushButton" name="n8">
<property name="text">
<string>8</string>
</property>
</widget>
</item>
<item row="2" column="7">
<widget class="QPushButton" name="ly">
<property name="text">
@ -231,13 +381,6 @@
</property>
</widget>
</item>
<item row="2" column="8">
<widget class="QPushButton" name="lu">
<property name="text">
<string>u</string>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QPushButton" name="n5">
<property name="text">
@ -245,157 +388,10 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="lw">
<item row="2" column="4">
<widget class="QPushButton" name="lr">
<property name="text">
<string>w</string>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QPushButton" name="lt">
<property name="text">
<string>t</string>
</property>
</widget>
</item>
<item row="7" column="9">
<widget class="QPushButton" name="lm">
<property name="text">
<string>m</string>
</property>
</widget>
</item>
<item row="7" column="12">
<widget class="QPushButton" name="eraseBtn">
<property name="text">
<string>⌫</string>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QPushButton" name="n7">
<property name="text">
<string>7</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="lq">
<property name="text">
<string>q</string>
</property>
</widget>
</item>
<item row="2" column="9">
<widget class="QPushButton" name="li">
<property name="text">
<string>i</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QPushButton" name="lz">
<property name="text">
<string>z</string>
</property>
</widget>
</item>
<item row="7" column="10">
<widget class="QPushButton" name="spt">
<property name="text">
<string>.</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QPushButton" name="n4">
<property name="text">
<string>4</string>
</property>
</widget>
</item>
<item row="2" column="10">
<widget class="QPushButton" name="lo">
<property name="text">
<string>o</string>
</property>
</widget>
</item>
<item row="7" column="8">
<widget class="QPushButton" name="ln">
<property name="text">
<string>n</string>
</property>
</widget>
</item>
<item row="6" column="12">
<widget class="QPushButton" name="ll">
<property name="text">
<string>l</string>
</property>
</widget>
</item>
<item row="6" column="10">
<widget class="QPushButton" name="lk">
<property name="text">
<string>k</string>
</property>
</widget>
</item>
<item row="6" column="9">
<widget class="QPushButton" name="lj">
<property name="text">
<string>j</string>
</property>
</widget>
</item>
<item row="6" column="8">
<widget class="QPushButton" name="lh">
<property name="text">
<string>h</string>
</property>
</widget>
</item>
<item row="6" column="7">
<widget class="QPushButton" name="lg">
<property name="text">
<string>g</string>
</property>
</widget>
</item>
<item row="6" column="6">
<widget class="QPushButton" name="lf">
<property name="text">
<string>f</string>
</property>
</widget>
</item>
<item row="6" column="4">
<widget class="QPushButton" name="ld">
<property name="text">
<string>d</string>
</property>
</widget>
</item>
<item row="6" column="3">
<widget class="QPushButton" name="ls">
<property name="text">
<string>s</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QPushButton" name="la">
<property name="text">
<string>a</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="sat">
<property name="text">
<string>#</string>
<string>r</string>
</property>
</widget>
</item>
@ -445,6 +441,30 @@
<widget class="QWidget" name="page_10"/>
</widget>
</item>
<item row="1" column="2">
<layout class="QGridLayout" name="gridLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item row="1" column="0">
<widget class="QPushButton" name="closeBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="enterBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>