mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
added qscintilla and edit button for mdems
This commit is contained in:
@@ -12,11 +12,15 @@ set(CMAKE_AUTORCC ON)
|
|||||||
set(CMAKE_AUTOUIC ON)
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
|
||||||
find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
||||||
|
|
||||||
|
# find_package(QScintilla REQUIRED)
|
||||||
|
include_directories(/usr/include/qt/Qsci)
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
MdemoryApp
|
MdemoryApp
|
||||||
main.cpp
|
main.cpp
|
||||||
trainWindow.cpp
|
trainWindow.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(MdemoryApp Qt5::Widgets api)
|
target_link_libraries(MdemoryApp Qt5::Widgets /usr/lib/libqscintilla2_qt5.so api)
|
||||||
target_include_directories(MdemoryApp PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
target_include_directories(MdemoryApp PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
||||||
|
|||||||
@@ -18,6 +18,9 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <Qsci/qsciscintilla.h>
|
||||||
|
#include <Qsci/qscilexercpp.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@@ -61,9 +64,11 @@ struct Mdem {
|
|||||||
QHBoxLayout hFront;
|
QHBoxLayout hFront;
|
||||||
QWidget wBack;
|
QWidget wBack;
|
||||||
QVBoxLayout hBack;
|
QVBoxLayout hBack;
|
||||||
QVector<QLabel*> backLabels;
|
QToolButton editButton;
|
||||||
QToolButton showButton;
|
QToolButton showButton;
|
||||||
int labelCount;
|
int labelCount;
|
||||||
|
QVector<QLabel*> backLabels;
|
||||||
|
Question *question;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ErrorView {
|
struct ErrorView {
|
||||||
@@ -110,6 +115,9 @@ QToolButton *save;
|
|||||||
QToolButton *load;
|
QToolButton *load;
|
||||||
QToolButton *practice;
|
QToolButton *practice;
|
||||||
|
|
||||||
|
QsciScintilla *editor;
|
||||||
|
QMainWindow* editorWindow;
|
||||||
|
|
||||||
const std::regex lastPathElementExp = std::regex("(.+\\/)*(.+)");
|
const std::regex lastPathElementExp = std::regex("(.+\\/)*(.+)");
|
||||||
|
|
||||||
void showBacklabels(Mdem *mdem) {
|
void showBacklabels(Mdem *mdem) {
|
||||||
@@ -126,6 +134,64 @@ void showBacklabels(Mdem *mdem) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string outputMdem(std::vector<Question*> questions) {
|
||||||
|
std::stringstream ss;
|
||||||
|
for (auto question: questions) {
|
||||||
|
std::string cooldownPart;
|
||||||
|
if (question->Cooldown != 0) {
|
||||||
|
cooldownPart = std::format("[{:.2f}]", question->Cooldown);
|
||||||
|
}
|
||||||
|
ss << wrapText(
|
||||||
|
std::format("- {} {} >\n",
|
||||||
|
cooldownPart,
|
||||||
|
escapeText(question->QuestionText)),
|
||||||
|
WRAP_WIDTH
|
||||||
|
);
|
||||||
|
if (MultiElementQuestion* mw = dynamic_cast<MultiElementQuestion*>(question)) {
|
||||||
|
for (auto choice: mw->Choices) {
|
||||||
|
char opener;
|
||||||
|
if (choice.IsCorrect) {
|
||||||
|
opener = '+';
|
||||||
|
} else {
|
||||||
|
opener = '-';
|
||||||
|
}
|
||||||
|
std::string orderModifier;
|
||||||
|
if (mw->type == MultiElementType::Order) {
|
||||||
|
orderModifier = "^";
|
||||||
|
}
|
||||||
|
ss <<
|
||||||
|
wrapText(
|
||||||
|
std::format(
|
||||||
|
"\t{}{} {}\n",
|
||||||
|
opener,
|
||||||
|
orderModifier,
|
||||||
|
escapeText(choice.Answer)
|
||||||
|
)
|
||||||
|
, WRAP_WIDTH);
|
||||||
|
}
|
||||||
|
} else if (GroupQuestion* gq = dynamic_cast<GroupQuestion*>(question)) {
|
||||||
|
for (auto group: gq->Groups) {
|
||||||
|
ss << wrapText(
|
||||||
|
std::format(
|
||||||
|
"\t- {}:\n",
|
||||||
|
escapeText(group.name)
|
||||||
|
)
|
||||||
|
, WRAP_WIDTH);
|
||||||
|
for (auto element: group.elements) {
|
||||||
|
ss << wrapText(
|
||||||
|
std::format(
|
||||||
|
"\t\t- {}\n",
|
||||||
|
escapeText(element)
|
||||||
|
)
|
||||||
|
, WRAP_WIDTH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ss << std::endl;
|
||||||
|
}
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
Mdem* makeMdem() {
|
Mdem* makeMdem() {
|
||||||
auto mdem = new Mdem;
|
auto mdem = new Mdem;
|
||||||
mdem->wMdem.setLayout(&mdem->vMdem);
|
mdem->wMdem.setLayout(&mdem->vMdem);
|
||||||
@@ -153,6 +219,20 @@ Mdem* makeMdem() {
|
|||||||
mdem->hFront.addWidget(&mdem->wFrontText);
|
mdem->hFront.addWidget(&mdem->wFrontText);
|
||||||
mdem->hFront.addStretch(1);
|
mdem->hFront.addStretch(1);
|
||||||
|
|
||||||
|
mdem->editButton.setText("Edit");
|
||||||
|
mdem->hFront.addWidget(&mdem->editButton);
|
||||||
|
|
||||||
|
QObject::connect(&mdem->editButton, &QToolButton::clicked, [mdem]() {
|
||||||
|
if (mdem->question) {
|
||||||
|
editor->setText(
|
||||||
|
QString::fromStdString(
|
||||||
|
outputMdem(std::vector<Question*>{mdem->question})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
editorWindow->show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
mdem->showButton.setText("Show");
|
mdem->showButton.setText("Show");
|
||||||
mdem->hFront.addWidget(&mdem->showButton);
|
mdem->hFront.addWidget(&mdem->showButton);
|
||||||
|
|
||||||
@@ -211,6 +291,7 @@ void CreateMdems(std::vector<Question*>& questions) {
|
|||||||
|
|
||||||
|
|
||||||
for (size_t i = 0; i < questions.size(); ++i) {
|
for (size_t i = 0; i < questions.size(); ++i) {
|
||||||
|
mdems[i]->question = questions[i];
|
||||||
if (MultiElementQuestion* mw = dynamic_cast<MultiElementQuestion*>(questions[i])) {
|
if (MultiElementQuestion* mw = dynamic_cast<MultiElementQuestion*>(questions[i])) {
|
||||||
mdems[i]->wFrontText.setText(
|
mdems[i]->wFrontText.setText(
|
||||||
QString::fromStdString(mw->QuestionText)
|
QString::fromStdString(mw->QuestionText)
|
||||||
@@ -501,6 +582,7 @@ void pickDirectory(QString directory) {
|
|||||||
reloadMdem();
|
reloadMdem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
QMainWindow window;
|
QMainWindow window;
|
||||||
@@ -525,6 +607,33 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
window.setMenuBar(menuBar);
|
window.setMenuBar(menuBar);
|
||||||
|
|
||||||
|
{ // Setup editor.
|
||||||
|
editorWindow = new QMainWindow;
|
||||||
|
|
||||||
|
editorWindow->setWindowTitle("QScintilla Simple Editor");
|
||||||
|
editorWindow->resize(800, 600);
|
||||||
|
QWidget *wEditor = new QWidget;
|
||||||
|
QVBoxLayout *vlEditor = new QVBoxLayout;
|
||||||
|
wEditor->setLayout(vlEditor);
|
||||||
|
|
||||||
|
editor = new QsciScintilla;
|
||||||
|
QsciLexerCPP *lexer = new QsciLexerCPP;
|
||||||
|
editor->setLexer(lexer);
|
||||||
|
editor->setUtf8(true);
|
||||||
|
editor->setMarginWidth(0, 15);
|
||||||
|
|
||||||
|
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||||
|
QWidget *editorButtons = new QWidget;
|
||||||
|
auto save = new QToolButton;
|
||||||
|
editorButtons->setLayout(buttonLayout);
|
||||||
|
save->setText(QString::fromStdString("Save"));
|
||||||
|
buttonLayout->addWidget(save);
|
||||||
|
|
||||||
|
vlEditor->addWidget(editor);
|
||||||
|
vlEditor->addWidget(editorButtons);
|
||||||
|
editorWindow->setCentralWidget(wEditor);
|
||||||
|
}
|
||||||
|
|
||||||
QSplitter *hSplitter = new QSplitter();
|
QSplitter *hSplitter = new QSplitter();
|
||||||
|
|
||||||
// LeftSide
|
// LeftSide
|
||||||
@@ -599,63 +708,8 @@ int main(int argc, char *argv[]) {
|
|||||||
practice->setText("Practice");
|
practice->setText("Practice");
|
||||||
QObject::connect(save, &QToolButton::clicked, []() {
|
QObject::connect(save, &QToolButton::clicked, []() {
|
||||||
auto filename = getFilename(currentMdem);
|
auto filename = getFilename(currentMdem);
|
||||||
std::stringstream ss;
|
|
||||||
for (auto question: questions) {
|
|
||||||
std::string cooldownPart;
|
|
||||||
if (question->Cooldown != 0) {
|
|
||||||
cooldownPart = std::format("[{:.2f}]", question->Cooldown);
|
|
||||||
}
|
|
||||||
ss << wrapText(
|
|
||||||
std::format("- {} {} >\n",
|
|
||||||
cooldownPart,
|
|
||||||
escapeText(question->QuestionText)),
|
|
||||||
WRAP_WIDTH
|
|
||||||
);
|
|
||||||
if (MultiElementQuestion* mw = dynamic_cast<MultiElementQuestion*>(question)) {
|
|
||||||
for (auto choice: mw->Choices) {
|
|
||||||
char opener;
|
|
||||||
if (choice.IsCorrect) {
|
|
||||||
opener = '+';
|
|
||||||
} else {
|
|
||||||
opener = '-';
|
|
||||||
}
|
|
||||||
std::string orderModifier;
|
|
||||||
if (mw->type == MultiElementType::Order) {
|
|
||||||
orderModifier = "^";
|
|
||||||
}
|
|
||||||
ss <<
|
|
||||||
wrapText(
|
|
||||||
std::format(
|
|
||||||
"\t{}{} {}\n",
|
|
||||||
opener,
|
|
||||||
orderModifier,
|
|
||||||
escapeText(choice.Answer)
|
|
||||||
)
|
|
||||||
, WRAP_WIDTH);
|
|
||||||
}
|
|
||||||
} else if (GroupQuestion* gq = dynamic_cast<GroupQuestion*>(question)) {
|
|
||||||
for (auto group: gq->Groups) {
|
|
||||||
ss << wrapText(
|
|
||||||
std::format(
|
|
||||||
"\t- {}:\n",
|
|
||||||
escapeText(group.name)
|
|
||||||
)
|
|
||||||
, WRAP_WIDTH);
|
|
||||||
for (auto element: group.elements) {
|
|
||||||
ss << wrapText(
|
|
||||||
std::format(
|
|
||||||
"\t\t- {}\n",
|
|
||||||
escapeText(element)
|
|
||||||
)
|
|
||||||
, WRAP_WIDTH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ss << std::endl;
|
|
||||||
|
|
||||||
std::ofstream out("generated.mdem");
|
std::ofstream out("generated.mdem");
|
||||||
out << ss.str();
|
out << outputMdem(questions);;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
QObject::connect(load, &QToolButton::clicked, &reloadMdem);
|
QObject::connect(load, &QToolButton::clicked, &reloadMdem);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user