mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
per page config param
This commit is contained in:
@@ -20,19 +20,19 @@ struct MdemBuffer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Mdem {
|
struct Mdem {
|
||||||
QWidget wMdem;
|
QWidget wMdem;
|
||||||
QVBoxLayout vMdem;
|
QVBoxLayout vMdem;
|
||||||
QLabel wFrontText;
|
QLabel wFrontText;
|
||||||
QWidget wFront;
|
QWidget wFront;
|
||||||
QHBoxLayout hFront;
|
QHBoxLayout hFront;
|
||||||
QWidget wBack;
|
QWidget wBack;
|
||||||
QVBoxLayout hBack;
|
QVBoxLayout hBack;
|
||||||
QToolButton editButton;
|
QToolButton editButton;
|
||||||
QToolButton deleteButton;
|
QToolButton deleteButton;
|
||||||
QToolButton toggleVisibility;
|
QToolButton toggleVisibility;
|
||||||
int labelCount;
|
int labelCount;
|
||||||
QVector<QLabel*> backLabels;
|
std::vector<QLabel*> backLabels;
|
||||||
Question *question;
|
Question *question;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ErrorView {
|
struct ErrorView {
|
||||||
@@ -70,6 +70,7 @@ void saveMdem();
|
|||||||
void updateMdemInfo(std::string filename = "", bool isChanged = true);
|
void updateMdemInfo(std::string filename = "", bool isChanged = true);
|
||||||
QMainWindow *initMdemListWindow();
|
QMainWindow *initMdemListWindow();
|
||||||
|
|
||||||
|
#define SETTING_PER_PAGE "perPage"
|
||||||
#define SETTING_MEMORYBASE "defaultMemorybase"
|
#define SETTING_MEMORYBASE "defaultMemorybase"
|
||||||
#define SETTING_TIMEZONE "timezone"
|
#define SETTING_TIMEZONE "timezone"
|
||||||
#define SETTING_CHARACTER_WRAP "characterWrap"
|
#define SETTING_CHARACTER_WRAP "characterWrap"
|
||||||
@@ -83,5 +84,4 @@ QMainWindow *initMdemListWindow();
|
|||||||
#define TEXT_LG = 20
|
#define TEXT_LG = 20
|
||||||
#define ERROR_POOL_CHUNK 50
|
#define ERROR_POOL_CHUNK 50
|
||||||
#define DISTANCE 2
|
#define DISTANCE 2
|
||||||
#define PER_PAGE 8
|
|
||||||
#define MDEM_BACKGROUND "#F7F7F7"
|
#define MDEM_BACKGROUND "#F7F7F7"
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ QVBoxLayout *hMdemScroll;
|
|||||||
QSpacerItem *mdemSpacer;
|
QSpacerItem *mdemSpacer;
|
||||||
ErrorView *errorView;
|
ErrorView *errorView;
|
||||||
Pagination *pagination;
|
Pagination *pagination;
|
||||||
|
int perPage;
|
||||||
|
|
||||||
// Editor
|
// Editor
|
||||||
QsciScintilla *editor;
|
QsciScintilla *editor;
|
||||||
@@ -189,15 +190,16 @@ std::string outputMdem(std::vector<Question*> questions, time_t time = 0) {
|
|||||||
void makePages() {
|
void makePages() {
|
||||||
pagination->pages.clear();
|
pagination->pages.clear();
|
||||||
auto len = currentMdemBuffer->questions.size();
|
auto len = currentMdemBuffer->questions.size();
|
||||||
auto pageAmount = len / PER_PAGE;
|
perPage = settings->value(SETTING_PER_PAGE).toInt();
|
||||||
if (len % PER_PAGE != 0) {
|
auto pageAmount = len / perPage;
|
||||||
|
if (len % perPage != 0) {
|
||||||
pageAmount += 1;
|
pageAmount += 1;
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < pageAmount; i++) {
|
for (size_t i = 0; i < pageAmount; i++) {
|
||||||
size_t startingIndex = PER_PAGE * i ;
|
size_t startingIndex = perPage * i ;
|
||||||
size_t amount = PER_PAGE;
|
size_t amount = perPage;
|
||||||
if (i == currentMdemBuffer->questions.size() / PER_PAGE) {
|
if (i == currentMdemBuffer->questions.size() / perPage) {
|
||||||
amount = currentMdemBuffer->questions.size() % PER_PAGE;
|
amount = currentMdemBuffer->questions.size() % perPage;
|
||||||
}
|
}
|
||||||
pagination->pages.push_back(
|
pagination->pages.push_back(
|
||||||
Page{startingIndex, startingIndex + amount}
|
Page{startingIndex, startingIndex + amount}
|
||||||
@@ -420,12 +422,14 @@ void CreateMdems(std::vector<Question*>& questions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (questions.size() > mdems.size()) {
|
perPage = settings->value(SETTING_PER_PAGE).toInt();
|
||||||
auto amount = questions.size() - mdems.size();
|
if (perPage > mdems.size()) {
|
||||||
for (size_t i = 0; i < amount; ++i) {
|
for (size_t i = mdems.size(); i < perPage; i++) {
|
||||||
auto mdem = makeMdem();
|
if (i >= mdems.size()) {
|
||||||
mdems.push_back(mdem);
|
auto mdem = makeMdem();
|
||||||
hMdemScroll->addWidget(&mdem->wMdem);
|
mdems.push_back(mdem);
|
||||||
|
hMdemScroll->addWidget(&mdem->wMdem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,7 +466,7 @@ void switchPage(int pageIdx) {
|
|||||||
snprintf(buffer, sizeof(buffer), "Page: %d", pageIdx + 1);
|
snprintf(buffer, sizeof(buffer), "Page: %d", pageIdx + 1);
|
||||||
pagination->paginationLabel.setText(buffer);
|
pagination->paginationLabel.setText(buffer);
|
||||||
|
|
||||||
// Hide widgets in mdems
|
// Adjust mdem amount, hide widgets in mdems
|
||||||
for (auto& mdem : mdems) {
|
for (auto& mdem : mdems) {
|
||||||
if (mdem->wBack.isVisible()) {
|
if (mdem->wBack.isVisible()) {
|
||||||
mdem->wBack.hide();
|
mdem->wBack.hide();
|
||||||
@@ -1042,6 +1046,7 @@ QMainWindow *initMdemListWindow() {
|
|||||||
|
|
||||||
auto wPagination = new QWidget();
|
auto wPagination = new QWidget();
|
||||||
auto hPagination = new QHBoxLayout();
|
auto hPagination = new QHBoxLayout();
|
||||||
|
|
||||||
wPagination->setLayout(hPagination);
|
wPagination->setLayout(hPagination);
|
||||||
|
|
||||||
pagination->firstButton.setText(QString::fromStdString("<<"));
|
pagination->firstButton.setText(QString::fromStdString("<<"));
|
||||||
@@ -1062,7 +1067,8 @@ QMainWindow *initMdemListWindow() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (size_t i = 0; i < PER_PAGE; i++) {
|
perPage = settings->value(SETTING_PER_PAGE).toInt();
|
||||||
|
for (size_t i = 0; i < perPage; i++) {
|
||||||
auto elButton = new QToolButton();
|
auto elButton = new QToolButton();
|
||||||
elButton->setText(QString("%1").arg(i+1));
|
elButton->setText(QString("%1").arg(i+1));
|
||||||
hPagination->addWidget(elButton);
|
hPagination->addWidget(elButton);
|
||||||
@@ -1107,12 +1113,12 @@ QMainWindow *initMdemListWindow() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
addShortcut("Ctrl+S", []() {
|
|
||||||
saveMdem();
|
|
||||||
});
|
|
||||||
addShortcut("Ctrl+,", [settingsWindow]() {
|
addShortcut("Ctrl+,", [settingsWindow]() {
|
||||||
settingsWindow->show();
|
settingsWindow->show();
|
||||||
});
|
});
|
||||||
|
addShortcut("Ctrl+S", [toolbar]() {
|
||||||
|
toolbar->btnSave.click();
|
||||||
|
});
|
||||||
addShortcut("Ctrl+P", [toolbar]() {
|
addShortcut("Ctrl+P", [toolbar]() {
|
||||||
toolbar->btnPractice.click();
|
toolbar->btnPractice.click();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -104,6 +104,10 @@ QWidget *initSettings () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
auto perPage = new QSpinBox;
|
||||||
|
perPage->setRange(5, 50);
|
||||||
|
formLayout->addRow("Mdems per page [5-50]:", perPage);
|
||||||
|
|
||||||
auto characterWrap = new QSpinBox;
|
auto characterWrap = new QSpinBox;
|
||||||
characterWrap->setRange(30, 150);
|
characterWrap->setRange(30, 150);
|
||||||
formLayout->addRow("Character wrap in code gen [30-150]:", characterWrap);
|
formLayout->addRow("Character wrap in code gen [30-150]:", characterWrap);
|
||||||
@@ -143,6 +147,7 @@ QWidget *initSettings () {
|
|||||||
|
|
||||||
// @Improve: validate setting values
|
// @Improve: validate setting values
|
||||||
auto setSettingInputs = [
|
auto setSettingInputs = [
|
||||||
|
perPage,
|
||||||
mbaseInput,
|
mbaseInput,
|
||||||
characterWrap,
|
characterWrap,
|
||||||
timezone,
|
timezone,
|
||||||
@@ -153,6 +158,7 @@ QWidget *initSettings () {
|
|||||||
debug,
|
debug,
|
||||||
showTimes
|
showTimes
|
||||||
]() {
|
]() {
|
||||||
|
perPage->setValue(settings->value(SETTING_PER_PAGE).toInt());
|
||||||
mbaseInput->setText(settings->value(SETTING_MEMORYBASE).toString());
|
mbaseInput->setText(settings->value(SETTING_MEMORYBASE).toString());
|
||||||
characterWrap->setValue(settings->value(SETTING_CHARACTER_WRAP).toInt());
|
characterWrap->setValue(settings->value(SETTING_CHARACTER_WRAP).toInt());
|
||||||
timezone->setValue(settings->value(SETTING_TIMEZONE).toInt());
|
timezone->setValue(settings->value(SETTING_TIMEZONE).toInt());
|
||||||
@@ -214,17 +220,19 @@ QWidget *initSettings () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
attachChangeListener(mbaseInput, SETTING_MEMORYBASE);
|
attachChangeListener(perPage, SETTING_PER_PAGE);
|
||||||
|
attachChangeListener(mbaseInput, SETTING_MEMORYBASE);
|
||||||
attachChangeListener(characterWrap, SETTING_CHARACTER_WRAP);
|
attachChangeListener(characterWrap, SETTING_CHARACTER_WRAP);
|
||||||
attachChangeListener(timezone, SETTING_TIMEZONE);
|
attachChangeListener(timezone, SETTING_TIMEZONE);
|
||||||
attachChangeListener(notRemembered, SETTING_NOT_REMEMBERED);
|
attachChangeListener(notRemembered, SETTING_NOT_REMEMBERED);
|
||||||
attachChangeListener(hard, SETTING_HARD);
|
attachChangeListener(hard, SETTING_HARD);
|
||||||
attachChangeListener(medium, SETTING_MEDIUM);
|
attachChangeListener(medium, SETTING_MEDIUM);
|
||||||
attachChangeListener(easy, SETTING_EASY);
|
attachChangeListener(easy, SETTING_EASY);
|
||||||
attachChangeListener(debug, SETTING_DEBUG);
|
attachChangeListener(debug, SETTING_DEBUG);
|
||||||
attachChangeListener(showTimes, SETTING_SHOW_TIMES);
|
attachChangeListener(showTimes, SETTING_SHOW_TIMES);
|
||||||
|
|
||||||
auto saveSettings = [
|
auto saveSettings = [
|
||||||
|
perPage,
|
||||||
mbaseInput,
|
mbaseInput,
|
||||||
characterWrap,
|
characterWrap,
|
||||||
timezone,
|
timezone,
|
||||||
@@ -236,6 +244,7 @@ QWidget *initSettings () {
|
|||||||
showTimes,
|
showTimes,
|
||||||
updateSettingsLabel
|
updateSettingsLabel
|
||||||
]() {
|
]() {
|
||||||
|
settings->setValue(SETTING_PER_PAGE, perPage->value());
|
||||||
settings->setValue(SETTING_MEMORYBASE, mbaseInput->text());
|
settings->setValue(SETTING_MEMORYBASE, mbaseInput->text());
|
||||||
settings->setValue(SETTING_CHARACTER_WRAP, characterWrap->value());
|
settings->setValue(SETTING_CHARACTER_WRAP, characterWrap->value());
|
||||||
settings->setValue(SETTING_TIMEZONE, timezone->value());
|
settings->setValue(SETTING_TIMEZONE, timezone->value());
|
||||||
|
|||||||
Reference in New Issue
Block a user