mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
many UI improvement
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <qfilesystemmodel.h>
|
||||||
|
#include <qnamespace.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -72,6 +74,28 @@ QLabel *mdemLabel;
|
|||||||
QLabel *lastPracticeLabel;
|
QLabel *lastPracticeLabel;
|
||||||
QMainWindow *trainWindow;
|
QMainWindow *trainWindow;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pielāgots modelis, kas parāda * indikatoru atbilstoši buferu sarakstam.
|
||||||
|
* */
|
||||||
|
class IndicatorFileSystemModel : public QFileSystemModel {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit IndicatorFileSystemModel(QObject *parent = nullptr) : QFileSystemModel(parent) {}
|
||||||
|
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override {
|
||||||
|
auto path = filePath(index);
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
QString originalName = QFileSystemModel::data(index, role).toString();
|
||||||
|
if (buffers.contains(path.toStdString()) && buffers[path.toStdString()]->isModified) {
|
||||||
|
return QString("%1 *").arg(originalName);
|
||||||
|
} else {
|
||||||
|
return QString("%1").arg(originalName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QFileSystemModel::data(index, role);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Pielāgots lodziņa objekts, kas izveido ziņojuma
|
// Pielāgots lodziņa objekts, kas izveido ziņojuma
|
||||||
// lodziņu ar objektu pirms lietotne tiek aizvērta.
|
// lodziņu ar objektu pirms lietotne tiek aizvērta.
|
||||||
class CloseableMainWindow : public QMainWindow {
|
class CloseableMainWindow : public QMainWindow {
|
||||||
@@ -107,8 +131,8 @@ protected:
|
|||||||
|
|
||||||
// Apstrādā izvēli.
|
// Apstrādā izvēli.
|
||||||
if (msgBox.clickedButton() == saveButton) {
|
if (msgBox.clickedButton() == saveButton) {
|
||||||
for (auto buffer: buffers) {
|
for (auto pair: buffers) {
|
||||||
saveMdem(buffer.second, buffer.first);
|
saveMdem(pair.second, pair.first);
|
||||||
}
|
}
|
||||||
QApplication::exit();
|
QApplication::exit();
|
||||||
} else if (msgBox.clickedButton() == exitButton) {
|
} else if (msgBox.clickedButton() == exitButton) {
|
||||||
@@ -122,6 +146,7 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "mdemList.moc"
|
#include "mdemList.moc"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -360,9 +385,20 @@ std::string getFilename(std::string path) {
|
|||||||
* Atjauno atmiņas kartīšu faila augšējo informāciju.
|
* Atjauno atmiņas kartīšu faila augšējo informāciju.
|
||||||
* */
|
* */
|
||||||
void updateMdemInfo(std::string filename, bool isChanged) {
|
void updateMdemInfo(std::string filename, bool isChanged) {
|
||||||
|
// Uzstāda indikatoru.
|
||||||
if (currentMdemBuffer) {
|
if (currentMdemBuffer) {
|
||||||
|
bool previousValue = currentMdemBuffer->isModified;
|
||||||
currentMdemBuffer->isModified = isChanged;
|
currentMdemBuffer->isModified = isChanged;
|
||||||
|
if (previousValue != isChanged) {
|
||||||
|
model->dataChanged(
|
||||||
|
model->index(0, 0),
|
||||||
|
model->index(model->rowCount() - 1, model->columnCount() - 1),
|
||||||
|
{Qt::DisplayRole}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Uzstāda informāciju.
|
||||||
if (filename.length() > 0) {
|
if (filename.length() > 0) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << std::format("Atmiņas kartīšu fails: {}", filename);
|
ss << std::format("Atmiņas kartīšu fails: {}", filename);
|
||||||
@@ -424,6 +460,7 @@ Mdem* makeMdem() {
|
|||||||
&mdem->editButton,
|
&mdem->editButton,
|
||||||
&QToolButton::clicked,
|
&QToolButton::clicked,
|
||||||
[mdem]() {
|
[mdem]() {
|
||||||
|
trainWindow->close();
|
||||||
editMdem = mdem;
|
editMdem = mdem;
|
||||||
if (mdem->question) {
|
if (mdem->question) {
|
||||||
int wrap_width = 80;
|
int wrap_width = 80;
|
||||||
@@ -448,6 +485,7 @@ Mdem* makeMdem() {
|
|||||||
&mdem->deleteButton,
|
&mdem->deleteButton,
|
||||||
&QToolButton::clicked,
|
&QToolButton::clicked,
|
||||||
[mdem]() {
|
[mdem]() {
|
||||||
|
trainWindow->close();
|
||||||
if (mdem->question) {
|
if (mdem->question) {
|
||||||
Question* deleted = nullptr;
|
Question* deleted = nullptr;
|
||||||
for (size_t i = 0; i < currentMdemBuffer->questions.size(); ++i) {
|
for (size_t i = 0; i < currentMdemBuffer->questions.size(); ++i) {
|
||||||
@@ -661,26 +699,26 @@ void reloadMdem(std::string path) {
|
|||||||
buffers.erase(key);
|
buffers.erase(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
MdemBuffer *buffer;
|
|
||||||
auto filename = getFilename(path);
|
auto filename = getFilename(path);
|
||||||
if (path == "") {
|
if (path == "") {
|
||||||
// Atiesta atmiņas kartīšu failus.
|
// Atiesta atmiņas kartīšu failus.
|
||||||
currentMdemBuffer = nullptr;
|
currentMdemBuffer = nullptr;
|
||||||
currentMdemPath = path;
|
currentMdemPath = path;
|
||||||
} else if (currentMdemPath == path) {
|
} else if (currentMdemPath == path) {
|
||||||
// Pārlādē tagadējo failu - izdzēš esošo bufferi.
|
// Pārlādē tagadējo failu - nonullē esošo bufferi.
|
||||||
if (buffers.contains(path)) {
|
for (auto question: currentMdemBuffer->questions) {
|
||||||
buffers.erase(path);
|
delete question;
|
||||||
}
|
}
|
||||||
|
currentMdemBuffer->questions.clear();
|
||||||
} else if (!buffers.contains(path)) {
|
} else if (!buffers.contains(path)) {
|
||||||
// Izveido bufferi, ja tāds neeksistē.
|
// Izveido bufferi, ja tāds neeksistē.
|
||||||
buffer = new MdemBuffer;
|
auto *buffer = new MdemBuffer;
|
||||||
buffers[path] = buffer;
|
buffers[path] = buffer;
|
||||||
currentMdemBuffer = buffer;
|
currentMdemBuffer = buffer;
|
||||||
currentMdemPath = path;
|
currentMdemPath = path;
|
||||||
} else {
|
} else {
|
||||||
// Bufferis eksistē, ielādē to no atmiņas.
|
// Bufferis eksistē, ielādē to no atmiņas.
|
||||||
buffer = buffers[path];
|
auto *buffer = buffers[path];
|
||||||
currentMdemBuffer = buffer;
|
currentMdemBuffer = buffer;
|
||||||
currentMdemPath = path;
|
currentMdemPath = path;
|
||||||
makePages();
|
makePages();
|
||||||
@@ -705,7 +743,7 @@ void reloadMdem(std::string path) {
|
|||||||
currentMdemBuffer->questions.clear();
|
currentMdemBuffer->questions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO comment
|
// Transpilē faila saturu un izveido kartītes.
|
||||||
if (currentMdemBuffer) {
|
if (currentMdemBuffer) {
|
||||||
if (file) {
|
if (file) {
|
||||||
// Ielādē faila saturu buferī.
|
// Ielādē faila saturu buferī.
|
||||||
@@ -973,6 +1011,7 @@ void setupEditorSave() {
|
|||||||
* */
|
* */
|
||||||
void saveMdem() {
|
void saveMdem() {
|
||||||
saveMdem(currentMdemBuffer, currentMdemPath);
|
saveMdem(currentMdemBuffer, currentMdemPath);
|
||||||
|
updateMdemInfo(getFilename(currentMdemPath), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1017,8 +1056,6 @@ void saveMdem(MdemBuffer* buffer, std::string path) {
|
|||||||
wrap_width,
|
wrap_width,
|
||||||
timezoneOffset
|
timezoneOffset
|
||||||
);
|
);
|
||||||
// Indikators - kartīšu faila saturs nav mainīts pēc pēdējās saglabāšanas.
|
|
||||||
updateMdemInfo(getFilename(path), false);
|
|
||||||
|
|
||||||
end = std::chrono::high_resolution_clock::now();
|
end = std::chrono::high_resolution_clock::now();
|
||||||
showTimes = settings->value(SETTING_SHOW_TIMES).toBool();
|
showTimes = settings->value(SETTING_SHOW_TIMES).toBool();
|
||||||
@@ -1057,6 +1094,7 @@ QMainWindow *initMdemListWindow() {
|
|||||||
|
|
||||||
QAction *actionOpen;
|
QAction *actionOpen;
|
||||||
QAction *revealMbase;
|
QAction *revealMbase;
|
||||||
|
QAction *saveAll;
|
||||||
QAction *openSettings;
|
QAction *openSettings;
|
||||||
QAction *actionHelp;
|
QAction *actionHelp;
|
||||||
{ // Izvēlne.
|
{ // Izvēlne.
|
||||||
@@ -1066,9 +1104,9 @@ QMainWindow *initMdemListWindow() {
|
|||||||
// Darbību saraksts.
|
// Darbību saraksts.
|
||||||
QMenu *menu = new QMenu("Darbības");
|
QMenu *menu = new QMenu("Darbības");
|
||||||
menu->setStyleSheet("font-size: 15px;");
|
menu->setStyleSheet("font-size: 15px;");
|
||||||
actionOpen = menu->addAction("Atvērt atmiņas bāzi (Ctrl+O)");
|
|
||||||
|
|
||||||
// Bāzes atvēršana.
|
// Bāzes atvēršana.
|
||||||
|
actionOpen = menu->addAction("Atvērt atmiņas bāzi (Ctrl+O)");
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
actionOpen,
|
actionOpen,
|
||||||
&QAction::triggered,
|
&QAction::triggered,
|
||||||
@@ -1110,6 +1148,25 @@ QMainWindow *initMdemListWindow() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Saglabāt visus failus.
|
||||||
|
saveAll = menu->addAction("Saglabāt atmiņas bāzi (Ctrl+D)");
|
||||||
|
QObject::connect(
|
||||||
|
saveAll,
|
||||||
|
&QAction::triggered,
|
||||||
|
[]() {
|
||||||
|
for (auto pair: buffers) {
|
||||||
|
saveMdem(pair.second, pair.first);
|
||||||
|
pair.second->isModified = false;
|
||||||
|
}
|
||||||
|
model->dataChanged(
|
||||||
|
model->index(0, 0),
|
||||||
|
model->index(model->rowCount() - 1, model->columnCount() - 1),
|
||||||
|
{Qt::DisplayRole}
|
||||||
|
);
|
||||||
|
updateMdemInfo(getFilename(currentMdemPath), false);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Konfigurācija.
|
// Konfigurācija.
|
||||||
openSettings = menu->addAction("Iestatījumi (Ctrl+,)");
|
openSettings = menu->addAction("Iestatījumi (Ctrl+,)");
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
@@ -1224,6 +1281,7 @@ QMainWindow *initMdemListWindow() {
|
|||||||
if (!currentMdemBuffer) {
|
if (!currentMdemBuffer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
trainWindow->close();
|
||||||
editMdem = nullptr;
|
editMdem = nullptr;
|
||||||
editorWindow->show();
|
editorWindow->show();
|
||||||
editor->setText("");
|
editor->setText("");
|
||||||
@@ -1239,6 +1297,7 @@ QMainWindow *initMdemListWindow() {
|
|||||||
});
|
});
|
||||||
QObject::connect(&toolbar->btnSave, &QToolButton::clicked, []() {
|
QObject::connect(&toolbar->btnSave, &QToolButton::clicked, []() {
|
||||||
saveMdem();
|
saveMdem();
|
||||||
|
updateMdemInfo(getFilename(currentMdemPath), false);
|
||||||
});
|
});
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
&toolbar->btnPractice,
|
&toolbar->btnPractice,
|
||||||
@@ -1295,7 +1354,7 @@ QMainWindow *initMdemListWindow() {
|
|||||||
QVBoxLayout *leftLayout = new QVBoxLayout();
|
QVBoxLayout *leftLayout = new QVBoxLayout();
|
||||||
leftWidget->setLayout(leftLayout);
|
leftWidget->setLayout(leftLayout);
|
||||||
|
|
||||||
model = new QFileSystemModel();
|
model = new IndicatorFileSystemModel();
|
||||||
mdemList = new QTreeView();
|
mdemList = new QTreeView();
|
||||||
|
|
||||||
QStringList filters;
|
QStringList filters;
|
||||||
@@ -1319,9 +1378,13 @@ QMainWindow *initMdemListWindow() {
|
|||||||
&QTreeView::doubleClicked,
|
&QTreeView::doubleClicked,
|
||||||
[](const QModelIndex &index) {
|
[](const QModelIndex &index) {
|
||||||
auto fileInfo = model->fileInfo(index);
|
auto fileInfo = model->fileInfo(index);
|
||||||
|
auto path = fileInfo.filePath().toStdString();
|
||||||
|
if (currentMdemPath == path) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!fileInfo.isDir()) {
|
if (!fileInfo.isDir()) {
|
||||||
trainWindow->close();
|
trainWindow->close();
|
||||||
reloadMdem(fileInfo.filePath().toStdString());
|
reloadMdem(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -1463,6 +1526,9 @@ QMainWindow *initMdemListWindow() {
|
|||||||
addShortcut("Ctrl+M", [revealMbase]() {
|
addShortcut("Ctrl+M", [revealMbase]() {
|
||||||
revealMbase->trigger();
|
revealMbase->trigger();
|
||||||
});
|
});
|
||||||
|
addShortcut("Ctrl+D", [saveAll]() {
|
||||||
|
saveAll->trigger();
|
||||||
|
});
|
||||||
addShortcut("Ctrl+H", [actionHelp]() {
|
addShortcut("Ctrl+H", [actionHelp]() {
|
||||||
actionHelp->trigger();
|
actionHelp->trigger();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include <charconv>
|
||||||
|
#include <qlabel.h>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -211,6 +213,7 @@ QVBoxLayout *vTrainWidget;
|
|||||||
CustomItemDelegate *itemDelegate;
|
CustomItemDelegate *itemDelegate;
|
||||||
|
|
||||||
// Jautājums.
|
// Jautājums.
|
||||||
|
QLabel *intervalLabel;
|
||||||
QWidget *questionBox;
|
QWidget *questionBox;
|
||||||
QVBoxLayout *vQuestionBox;
|
QVBoxLayout *vQuestionBox;
|
||||||
QLabel *lQuestionText;
|
QLabel *lQuestionText;
|
||||||
@@ -710,6 +713,22 @@ time_t getTime() {
|
|||||||
).count();
|
).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Uzstāda intervāla skaitļa tekstu.
|
||||||
|
* Ja ir padots -1, intervāla tekstu paslēp.
|
||||||
|
*/
|
||||||
|
void setInterval(double interval) {
|
||||||
|
if (interval == -1.0) {
|
||||||
|
intervalLabel->setText("");
|
||||||
|
} else {
|
||||||
|
intervalLabel->setText(
|
||||||
|
QString::fromStdString(
|
||||||
|
std::format("Intervāls: {} stundas", interval)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Uzstāda nākamo jautajumu atbilstoši algoritmam.
|
* Uzstāda nākamo jautajumu atbilstoši algoritmam.
|
||||||
*/
|
*/
|
||||||
@@ -717,6 +736,7 @@ void setupNextQuestion() {
|
|||||||
if (practiceBuffer->questions.size() <= 0) {
|
if (practiceBuffer->questions.size() <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setInterval(-1.0);
|
||||||
switch (practiceAlgoritm) {
|
switch (practiceAlgoritm) {
|
||||||
case PRIMARY: {
|
case PRIMARY: {
|
||||||
// Uzstāda nākamo pēc indeksa.
|
// Uzstāda nākamo pēc indeksa.
|
||||||
@@ -814,6 +834,7 @@ void setCooldownHours(double cooldown) {
|
|||||||
practiceBuffer->trainedAt = time;
|
practiceBuffer->trainedAt = time;
|
||||||
auto question = practiceBuffer->questions[currentQuestionIndex];
|
auto question = practiceBuffer->questions[currentQuestionIndex];
|
||||||
question->cooldown = cooldown;
|
question->cooldown = cooldown;
|
||||||
|
setInterval(cooldown);
|
||||||
update(true);
|
update(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -856,6 +877,12 @@ QMainWindow *initTrainWindow() {
|
|||||||
topButtons->setStyleSheet(buttonStyle);
|
topButtons->setStyleSheet(buttonStyle);
|
||||||
topButtons->setLayout(hTopButtons);
|
topButtons->setLayout(hTopButtons);
|
||||||
|
|
||||||
|
// Intervāla teksts.
|
||||||
|
intervalLabel = new QLabel;
|
||||||
|
hTopButtons->addWidget(intervalLabel);
|
||||||
|
intervalLabel->setStyleSheet("font-size: 20px");
|
||||||
|
setInterval(-1.0);
|
||||||
|
|
||||||
// Starplika, lai poga parādās labā pusē.
|
// Starplika, lai poga parādās labā pusē.
|
||||||
auto topLeftSpacer = new QSpacerItem(
|
auto topLeftSpacer = new QSpacerItem(
|
||||||
50,
|
50,
|
||||||
@@ -1071,8 +1098,7 @@ QMainWindow *initTrainWindow() {
|
|||||||
[]() {
|
[]() {
|
||||||
if (btnCheck->isVisible()) {
|
if (btnCheck->isVisible()) {
|
||||||
btnCheck->click();
|
btnCheck->click();
|
||||||
}
|
} else if (btnShowAnswer->isVisible()) {
|
||||||
if (btnShowAnswer->isVisible()) {
|
|
||||||
btnShowAnswer->click();
|
btnShowAnswer->click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user