refactoring main view

This commit is contained in:
jorenchik
2024-10-06 12:50:43 +03:00
parent 5c3cbfa58a
commit 1c6e28468e

View File

@@ -42,12 +42,11 @@
#include "parser.h"
#include "trainWindow.h"
#define TEXT_LG = 20
struct Page {
int start;
int end;
};
#define TEXT_LG = 20
#define ERROR_POOL_CHUNK 50
#define DISTANCE 2
#define PER_PAGE 8
#define MDEM_BACKGROUND "#F7F7F7"
struct Mdem {
QWidget wMdem;
@@ -62,6 +61,45 @@ struct Mdem {
int labelCount;
};
struct ErrorView {
QWidget box;
QVBoxLayout layout;
QLabel label;
};
struct Page {
int start;
int end;
};
QString workingPath = "/home/jorenchik/Code/mdemory/memorybase";
std::string currentPath = "";
// Mdem list
QLabel *deckListLabel;
QVBoxLayout *hMdemScroll;
QList<Mdem*> mdems = QList<Mdem*>();
std::vector<Question*> questions = std::vector<Question*>();
QSpacerItem *mdemSpacer;
std::vector<ErrorView*> errorPool;
std::vector<ErrorView*> errorViews;
// Pagination
int currentPage = -1;
std::vector<Page> pages;
QList<QToolButton*> paginationButtons;
QToolButton* prevButton;
QToolButton* firstButton;
QToolButton* lastButton;
QToolButton* nextButton;
QLabel* paginationLabel;
// Mdem actions
QToolButton *load;
QToolButton *practice;
const std::regex lastPathElementExp = std::regex("(.+\\/)*(.+)");
void showBacklabels(Mdem *mdem) {
for (int i = 0; i < mdem->backLabels.size(); ++i) {
if (i < mdem->labelCount) {
@@ -76,8 +114,6 @@ void showBacklabels(Mdem *mdem) {
}
}
auto mdemBackground = "#F7F7F7";
Mdem* makeMdem() {
auto mdem = new Mdem;
mdem->wMdem.setLayout(&mdem->vMdem);
@@ -99,7 +135,7 @@ Mdem* makeMdem() {
"QWidget#%1 > QWidget[first=\"true\"] {"
"border-top: 1px solid gray;"
"}"
).arg(id, mdemBackground));
).arg(id, MDEM_BACKGROUND));
// Add Front Content
mdem->hFront.addWidget(&mdem->wFrontText);
@@ -143,28 +179,6 @@ Mdem* makeMdem() {
return mdem;
}
QString workingPath = "/home/jorenchik/Code/mdemory/memorybase";
std::string currentPath = "";
QList<Mdem*> mdems = QList<Mdem*>();
std::vector<Question*> questions = std::vector<Question*>();
QLabel *deckListLabel;
QVBoxLayout *hMdemScroll;
QSpacerItem *mdemSpacer;
const int PER_PAGE = 8;
int currentPage = -1;
std::vector<Page> pages;
QList<QToolButton*> paginationButtons;
QToolButton* prevButton;
QToolButton* firstButton;
QToolButton* lastButton;
QToolButton* nextButton;
QLabel* paginationLabel;
QToolButton *load;
QToolButton *practice;
void CreateMdems(std::vector<Question*>& questions) {
hMdemScroll->removeItem(mdemSpacer);
@@ -250,9 +264,6 @@ void CreateMdems(std::vector<Question*>& questions) {
hMdemScroll->addItem(mdemSpacer);
}
const int DISTANCE = 2;
void makePages() {
pages.clear();
auto len = questions.size();
@@ -266,7 +277,6 @@ void makePages() {
}
}
void SwitchPage(int pageIdx) {
currentPage = pageIdx;
@@ -337,18 +347,6 @@ void SwitchPage(int pageIdx) {
CreateMdems(pageSlice);
}
std::regex lastPathElementExp = std::regex("(.+\\/)*(.+)");
struct ErrorView {
QWidget box;
QVBoxLayout layout;
QLabel label;
};
std::vector<ErrorView*> errorPool;
std::vector<ErrorView*> errorViews;
#define ERROR_POOL_CHUNK 50
ErrorView *makeErrorView() {
auto errorView = new ErrorView;
errorView->box.setObjectName("error-box");
@@ -360,7 +358,7 @@ ErrorView *makeErrorView() {
"border: 1px solid red;"
"background: %2;"
"}"
).arg(mdemBackground)
).arg(MDEM_BACKGROUND)
);
errorView->layout.addWidget(&errorView->label);
errorView->label.setWordWrap(true);