mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
refactoring main view
This commit is contained in:
@@ -43,11 +43,10 @@
|
|||||||
#include "trainWindow.h"
|
#include "trainWindow.h"
|
||||||
|
|
||||||
#define TEXT_LG = 20
|
#define TEXT_LG = 20
|
||||||
|
#define ERROR_POOL_CHUNK 50
|
||||||
struct Page {
|
#define DISTANCE 2
|
||||||
int start;
|
#define PER_PAGE 8
|
||||||
int end;
|
#define MDEM_BACKGROUND "#F7F7F7"
|
||||||
};
|
|
||||||
|
|
||||||
struct Mdem {
|
struct Mdem {
|
||||||
QWidget wMdem;
|
QWidget wMdem;
|
||||||
@@ -62,6 +61,45 @@ struct Mdem {
|
|||||||
int labelCount;
|
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) {
|
void showBacklabels(Mdem *mdem) {
|
||||||
for (int i = 0; i < mdem->backLabels.size(); ++i) {
|
for (int i = 0; i < mdem->backLabels.size(); ++i) {
|
||||||
if (i < mdem->labelCount) {
|
if (i < mdem->labelCount) {
|
||||||
@@ -76,8 +114,6 @@ void showBacklabels(Mdem *mdem) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto mdemBackground = "#F7F7F7";
|
|
||||||
|
|
||||||
Mdem* makeMdem() {
|
Mdem* makeMdem() {
|
||||||
auto mdem = new Mdem;
|
auto mdem = new Mdem;
|
||||||
mdem->wMdem.setLayout(&mdem->vMdem);
|
mdem->wMdem.setLayout(&mdem->vMdem);
|
||||||
@@ -99,7 +135,7 @@ Mdem* makeMdem() {
|
|||||||
"QWidget#%1 > QWidget[first=\"true\"] {"
|
"QWidget#%1 > QWidget[first=\"true\"] {"
|
||||||
"border-top: 1px solid gray;"
|
"border-top: 1px solid gray;"
|
||||||
"}"
|
"}"
|
||||||
).arg(id, mdemBackground));
|
).arg(id, MDEM_BACKGROUND));
|
||||||
|
|
||||||
// Add Front Content
|
// Add Front Content
|
||||||
mdem->hFront.addWidget(&mdem->wFrontText);
|
mdem->hFront.addWidget(&mdem->wFrontText);
|
||||||
@@ -143,28 +179,6 @@ Mdem* makeMdem() {
|
|||||||
return mdem;
|
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) {
|
void CreateMdems(std::vector<Question*>& questions) {
|
||||||
hMdemScroll->removeItem(mdemSpacer);
|
hMdemScroll->removeItem(mdemSpacer);
|
||||||
|
|
||||||
@@ -250,9 +264,6 @@ void CreateMdems(std::vector<Question*>& questions) {
|
|||||||
hMdemScroll->addItem(mdemSpacer);
|
hMdemScroll->addItem(mdemSpacer);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int DISTANCE = 2;
|
|
||||||
|
|
||||||
|
|
||||||
void makePages() {
|
void makePages() {
|
||||||
pages.clear();
|
pages.clear();
|
||||||
auto len = questions.size();
|
auto len = questions.size();
|
||||||
@@ -266,7 +277,6 @@ void makePages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SwitchPage(int pageIdx) {
|
void SwitchPage(int pageIdx) {
|
||||||
currentPage = pageIdx;
|
currentPage = pageIdx;
|
||||||
|
|
||||||
@@ -337,18 +347,6 @@ void SwitchPage(int pageIdx) {
|
|||||||
CreateMdems(pageSlice);
|
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() {
|
ErrorView *makeErrorView() {
|
||||||
auto errorView = new ErrorView;
|
auto errorView = new ErrorView;
|
||||||
errorView->box.setObjectName("error-box");
|
errorView->box.setObjectName("error-box");
|
||||||
@@ -360,7 +358,7 @@ ErrorView *makeErrorView() {
|
|||||||
"border: 1px solid red;"
|
"border: 1px solid red;"
|
||||||
"background: %2;"
|
"background: %2;"
|
||||||
"}"
|
"}"
|
||||||
).arg(mdemBackground)
|
).arg(MDEM_BACKGROUND)
|
||||||
);
|
);
|
||||||
errorView->layout.addWidget(&errorView->label);
|
errorView->layout.addWidget(&errorView->label);
|
||||||
errorView->label.setWordWrap(true);
|
errorView->label.setWordWrap(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user