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:
@@ -31,7 +31,7 @@ struct Mdem {
|
||||
QToolButton deleteButton;
|
||||
QToolButton toggleVisibility;
|
||||
int labelCount;
|
||||
QVector<QLabel*> backLabels;
|
||||
std::vector<QLabel*> backLabels;
|
||||
Question *question;
|
||||
};
|
||||
|
||||
@@ -70,6 +70,7 @@ void saveMdem();
|
||||
void updateMdemInfo(std::string filename = "", bool isChanged = true);
|
||||
QMainWindow *initMdemListWindow();
|
||||
|
||||
#define SETTING_PER_PAGE "perPage"
|
||||
#define SETTING_MEMORYBASE "defaultMemorybase"
|
||||
#define SETTING_TIMEZONE "timezone"
|
||||
#define SETTING_CHARACTER_WRAP "characterWrap"
|
||||
@@ -83,5 +84,4 @@ QMainWindow *initMdemListWindow();
|
||||
#define TEXT_LG = 20
|
||||
#define ERROR_POOL_CHUNK 50
|
||||
#define DISTANCE 2
|
||||
#define PER_PAGE 8
|
||||
#define MDEM_BACKGROUND "#F7F7F7"
|
||||
|
||||
@@ -85,6 +85,7 @@ QVBoxLayout *hMdemScroll;
|
||||
QSpacerItem *mdemSpacer;
|
||||
ErrorView *errorView;
|
||||
Pagination *pagination;
|
||||
int perPage;
|
||||
|
||||
// Editor
|
||||
QsciScintilla *editor;
|
||||
@@ -189,15 +190,16 @@ std::string outputMdem(std::vector<Question*> questions, time_t time = 0) {
|
||||
void makePages() {
|
||||
pagination->pages.clear();
|
||||
auto len = currentMdemBuffer->questions.size();
|
||||
auto pageAmount = len / PER_PAGE;
|
||||
if (len % PER_PAGE != 0) {
|
||||
perPage = settings->value(SETTING_PER_PAGE).toInt();
|
||||
auto pageAmount = len / perPage;
|
||||
if (len % perPage != 0) {
|
||||
pageAmount += 1;
|
||||
}
|
||||
for (size_t i = 0; i < pageAmount; i++) {
|
||||
size_t startingIndex = PER_PAGE * i ;
|
||||
size_t amount = PER_PAGE;
|
||||
if (i == currentMdemBuffer->questions.size() / PER_PAGE) {
|
||||
amount = currentMdemBuffer->questions.size() % PER_PAGE;
|
||||
size_t startingIndex = perPage * i ;
|
||||
size_t amount = perPage;
|
||||
if (i == currentMdemBuffer->questions.size() / perPage) {
|
||||
amount = currentMdemBuffer->questions.size() % perPage;
|
||||
}
|
||||
pagination->pages.push_back(
|
||||
Page{startingIndex, startingIndex + amount}
|
||||
@@ -420,14 +422,16 @@ void CreateMdems(std::vector<Question*>& questions) {
|
||||
}
|
||||
}
|
||||
|
||||
if (questions.size() > mdems.size()) {
|
||||
auto amount = questions.size() - mdems.size();
|
||||
for (size_t i = 0; i < amount; ++i) {
|
||||
perPage = settings->value(SETTING_PER_PAGE).toInt();
|
||||
if (perPage > mdems.size()) {
|
||||
for (size_t i = mdems.size(); i < perPage; i++) {
|
||||
if (i >= mdems.size()) {
|
||||
auto mdem = makeMdem();
|
||||
mdems.push_back(mdem);
|
||||
hMdemScroll->addWidget(&mdem->wMdem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < questions.size(); ++i) {
|
||||
mdems[i]->question = questions[i];
|
||||
@@ -462,7 +466,7 @@ void switchPage(int pageIdx) {
|
||||
snprintf(buffer, sizeof(buffer), "Page: %d", pageIdx + 1);
|
||||
pagination->paginationLabel.setText(buffer);
|
||||
|
||||
// Hide widgets in mdems
|
||||
// Adjust mdem amount, hide widgets in mdems
|
||||
for (auto& mdem : mdems) {
|
||||
if (mdem->wBack.isVisible()) {
|
||||
mdem->wBack.hide();
|
||||
@@ -1042,6 +1046,7 @@ QMainWindow *initMdemListWindow() {
|
||||
|
||||
auto wPagination = new QWidget();
|
||||
auto hPagination = new QHBoxLayout();
|
||||
|
||||
wPagination->setLayout(hPagination);
|
||||
|
||||
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();
|
||||
elButton->setText(QString("%1").arg(i+1));
|
||||
hPagination->addWidget(elButton);
|
||||
@@ -1107,12 +1113,12 @@ QMainWindow *initMdemListWindow() {
|
||||
});
|
||||
};
|
||||
|
||||
addShortcut("Ctrl+S", []() {
|
||||
saveMdem();
|
||||
});
|
||||
addShortcut("Ctrl+,", [settingsWindow]() {
|
||||
settingsWindow->show();
|
||||
});
|
||||
addShortcut("Ctrl+S", [toolbar]() {
|
||||
toolbar->btnSave.click();
|
||||
});
|
||||
addShortcut("Ctrl+P", [toolbar]() {
|
||||
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;
|
||||
characterWrap->setRange(30, 150);
|
||||
formLayout->addRow("Character wrap in code gen [30-150]:", characterWrap);
|
||||
@@ -143,6 +147,7 @@ QWidget *initSettings () {
|
||||
|
||||
// @Improve: validate setting values
|
||||
auto setSettingInputs = [
|
||||
perPage,
|
||||
mbaseInput,
|
||||
characterWrap,
|
||||
timezone,
|
||||
@@ -153,6 +158,7 @@ QWidget *initSettings () {
|
||||
debug,
|
||||
showTimes
|
||||
]() {
|
||||
perPage->setValue(settings->value(SETTING_PER_PAGE).toInt());
|
||||
mbaseInput->setText(settings->value(SETTING_MEMORYBASE).toString());
|
||||
characterWrap->setValue(settings->value(SETTING_CHARACTER_WRAP).toInt());
|
||||
timezone->setValue(settings->value(SETTING_TIMEZONE).toInt());
|
||||
@@ -214,6 +220,7 @@ QWidget *initSettings () {
|
||||
}
|
||||
};
|
||||
|
||||
attachChangeListener(perPage, SETTING_PER_PAGE);
|
||||
attachChangeListener(mbaseInput, SETTING_MEMORYBASE);
|
||||
attachChangeListener(characterWrap, SETTING_CHARACTER_WRAP);
|
||||
attachChangeListener(timezone, SETTING_TIMEZONE);
|
||||
@@ -225,6 +232,7 @@ QWidget *initSettings () {
|
||||
attachChangeListener(showTimes, SETTING_SHOW_TIMES);
|
||||
|
||||
auto saveSettings = [
|
||||
perPage,
|
||||
mbaseInput,
|
||||
characterWrap,
|
||||
timezone,
|
||||
@@ -236,6 +244,7 @@ QWidget *initSettings () {
|
||||
showTimes,
|
||||
updateSettingsLabel
|
||||
]() {
|
||||
settings->setValue(SETTING_PER_PAGE, perPage->value());
|
||||
settings->setValue(SETTING_MEMORYBASE, mbaseInput->text());
|
||||
settings->setValue(SETTING_CHARACTER_WRAP, characterWrap->value());
|
||||
settings->setValue(SETTING_TIMEZONE, timezone->value());
|
||||
|
||||
Reference in New Issue
Block a user