Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SyntaxTutor.pro
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ HEADERS += \
src/gui/grammareditordialog.h \
src/gui/lltabledialog.h \
src/gui/lltutorwindow.h \
src/gui/llwizard.h \
src/gui/llwizardpage.h \
src/gui/mainwindow.h \
src/gui/slrtabledialog.h \
src/gui/slrtutorwindow.h \
Expand Down
48 changes: 32 additions & 16 deletions resources/styles/app.qss
Original file line number Diff line number Diff line change
Expand Up @@ -519,41 +519,48 @@ QTextBrowser#infoDialogContent a {
color: #36C5CC;
}

QDialog[guidedDialog="slr"] {
QDialog[guidedDialog="slr"],
QDialog[guidedDialog="ll"] {
background-color: #1F1F1F;
border: none;
}

QDialog[guidedDialog="slr"] QFrame#slrWizardPanel {
QDialog[guidedDialog="slr"] QFrame#slrWizardPanel,
QDialog[guidedDialog="ll"] QFrame#llWizardPanel {
background: transparent;
border: none;
border-radius: 0;
}

QDialog[guidedDialog="slr"] QLabel#slrWizardTitle {
QDialog[guidedDialog="slr"] QLabel#slrWizardTitle,
QDialog[guidedDialog="ll"] QLabel#llWizardTitle {
color: #F4F7F8;
font-size: 28px;
font-weight: 700;
}

QDialog[guidedDialog="slr"] QLabel#slrWizardStepCounter {
QDialog[guidedDialog="slr"] QLabel#slrWizardStepCounter,
QDialog[guidedDialog="ll"] QLabel#llWizardStepCounter {
color: #9AA5A8;
font-size: 12px;
font-weight: 600;
}

QDialog[guidedDialog="slr"] QProgressBar#slrWizardProgress {
QDialog[guidedDialog="slr"] QProgressBar#slrWizardProgress,
QDialog[guidedDialog="ll"] QProgressBar#llWizardProgress {
background-color: rgba(255, 255, 255, 0.05);
border: none;
border-radius: 2px;
}

QDialog[guidedDialog="slr"] QProgressBar#slrWizardProgress::chunk {
QDialog[guidedDialog="slr"] QProgressBar#slrWizardProgress::chunk,
QDialog[guidedDialog="ll"] QProgressBar#llWizardProgress::chunk {
background-color: #11B3BC;
border-radius: 2px;
}

QDialog[guidedDialog="slr"] QPushButton#slrWizardCloseButton {
QDialog[guidedDialog="slr"] QPushButton#slrWizardCloseButton,
QDialog[guidedDialog="ll"] QPushButton#llWizardCloseButton {
background: transparent;
color: #AAB5B8;
border: 1px solid rgba(255, 255, 255, 0.08);
Expand All @@ -563,31 +570,36 @@ QDialog[guidedDialog="slr"] QPushButton#slrWizardCloseButton {
font-weight: 600;
}

QDialog[guidedDialog="slr"] QPushButton#slrWizardCloseButton:hover {
QDialog[guidedDialog="slr"] QPushButton#slrWizardCloseButton:hover,
QDialog[guidedDialog="ll"] QPushButton#llWizardCloseButton:hover {
background-color: rgba(255, 255, 255, 0.03);
color: #FFFFFF;
border: 1px solid rgba(255, 255, 255, 0.12);
}

QDialog[guidedDialog="slr"] QPushButton#slrWizardCloseButton:pressed {
QDialog[guidedDialog="slr"] QPushButton#slrWizardCloseButton:pressed,
QDialog[guidedDialog="ll"] QPushButton#llWizardCloseButton:pressed {
background-color: rgba(255, 255, 255, 0.06);
}

QDialog[guidedDialog="slr"] QLabel#slrWizardSectionTitle {
QDialog[guidedDialog="slr"] QLabel#slrWizardSectionTitle,
QDialog[guidedDialog="ll"] QLabel#llWizardSectionTitle {
color: #9FCFD2;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}

QDialog[guidedDialog="slr"] QLabel#slrWizardExplanationLabel {
QDialog[guidedDialog="slr"] QLabel#slrWizardExplanationLabel,
QDialog[guidedDialog="ll"] QLabel#llWizardExplanationLabel {
color: #DEE5E7;
font-size: 15px;
line-height: 1.5;
}

QDialog[guidedDialog="slr"] QLineEdit#slrWizardAnswerEdit {
QDialog[guidedDialog="slr"] QLineEdit#slrWizardAnswerEdit,
QDialog[guidedDialog="ll"] QLineEdit#llWizardAnswerEdit {
background-color: #2B3133;
color: #F1F4F5;
border: 1px solid rgba(255, 255, 255, 0.10);
Expand All @@ -597,23 +609,27 @@ QDialog[guidedDialog="slr"] QLineEdit#slrWizardAnswerEdit {
selection-background-color: #35515A;
}

QDialog[guidedDialog="slr"] QLineEdit#slrWizardAnswerEdit:focus {
QDialog[guidedDialog="slr"] QLineEdit#slrWizardAnswerEdit:focus,
QDialog[guidedDialog="ll"] QLineEdit#llWizardAnswerEdit:focus {
border: 1px solid #11B3BC;
}

QDialog[guidedDialog="slr"] QLabel#slrWizardFeedbackLabel {
QDialog[guidedDialog="slr"] QLabel#slrWizardFeedbackLabel,
QDialog[guidedDialog="ll"] QLabel#llWizardFeedbackLabel {
color: #AEB9BC;
min-height: 40px;
padding-top: 2px;
}

QDialog[guidedDialog="slr"] QPushButton#slrWizardNextButton {
QDialog[guidedDialog="slr"] QPushButton#slrWizardNextButton,
QDialog[guidedDialog="ll"] QPushButton#llWizardNextButton {
min-width: 136px;
padding: 11px 18px;
border-radius: 10px;
}

QDialog[guidedDialog="slr"] QPushButton#slrWizardNextButton:disabled {
QDialog[guidedDialog="slr"] QPushButton#slrWizardNextButton:disabled,
QDialog[guidedDialog="ll"] QPushButton#llWizardNextButton:disabled {
background-color: #2A2E30;
color: #6F7A7E;
border: 1px solid #353D40;
Expand Down
29 changes: 28 additions & 1 deletion src/gui/lltabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,22 @@ LLTableDialog::LLTableDialog(const QStringList& rowHeaders,
submitButton->setCursor(Qt::PointingHandCursor);
submitButton->setProperty("role", "primary");

guidedButton = new QPushButton(tr("Modo guiado"), this);
guidedButton->setObjectName("llTableGuidedButton");
guidedButton->setCursor(Qt::PointingHandCursor);
guidedButton->setProperty("role", "primary");

QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(table);
layout->addWidget(submitButton);

auto* buttons = new QHBoxLayout;
buttons->setContentsMargins(0, 0, 0, 0);
buttons->setSpacing(10);
buttons->addStretch();
buttons->addWidget(guidedButton);
buttons->addWidget(submitButton);

layout->addLayout(buttons);
layout->setContentsMargins(10, 10, 10, 10);
setLayout(layout);

Expand Down Expand Up @@ -104,6 +117,20 @@ LLTableDialog::LLTableDialog(const QStringList& rowHeaders,
commitPendingEdit();
emit submitted(getTableData());
});
connect(guidedButton, &QPushButton::clicked, this,
[this]() {
commitPendingEdit();
emit guidedRequested(getTableData());
});
}

void LLTableDialog::setGuidedModeActive(bool active) {
guidedButton->setEnabled(!active);
submitButton->setEnabled(!active);
}

void LLTableDialog::setGuidedButtonVisible(bool visible) {
guidedButton->setVisible(visible);
}

void LLTableDialog::commitPendingEdit() {
Expand Down
23 changes: 23 additions & 0 deletions src/gui/lltabledialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,41 @@ class LLTableDialog : public QDialog {
*/
void highlightIncorrectCells(const QList<QPair<int, int>>& coords);

/**
* @brief Enables or disables the dialog buttons while the guided mode
* dialog is open.
* @param active Whether the guided mode is currently active.
*/
void setGuidedModeActive(bool active);

/**
* @brief Shows or hides the guided mode button.
*
* Exam mode hides it: the guided walkthrough would reveal the answers.
*
* @param visible Whether the button should be visible.
*/
void setGuidedButtonVisible(bool visible);

signals:
/**
* @brief Signal emitted when the user submits the table.
* @param data The filled table data submitted by the user.
*/
void submitted(const QVector<QVector<QString>>& data);

/**
* @brief Signal emitted when the user asks for the guided mode.
* @param data The current table data, restored when the wizard closes.
*/
void guidedRequested(const QVector<QVector<QString>>& data);

private:
void commitPendingEdit();

QTableWidget* table; ///< The widget representing the LL(1) parsing table.
QPushButton* submitButton; ///< Button to submit the completed table.
QPushButton* guidedButton; ///< Button to launch guided mode.
};

#endif // LLTABLEDIALOG_H
33 changes: 33 additions & 0 deletions src/gui/lltutorwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "lltutorwindow.h"
#include "examreportdialog.h"
#include "grammarview.h"
#include "llwizard.h"
#include "tutorialmanager.h"
#include "ui_lltutorwindow.h"
#include <QApplication>
Expand Down Expand Up @@ -611,6 +612,26 @@ void LLTutorWindow::addMessage(const QString& text, bool isUser) {
ui->listWidget->scrollToBottom();
}

void LLTutorWindow::connectGuidedMode(LLTableDialog* dialog,
const QStringList& colHeaders) {
connect(dialog, &LLTableDialog::guidedRequested, this,
[this, dialog, colHeaders](const QVector<QVector<QString>>& data) {
const QVector<QVector<QString>> snapshot = data;
auto* wizard =
new LLWizard(ll1, sortedNonTerminals, colHeaders, dialog);
wizard->setAttribute(Qt::WA_DeleteOnClose);
wizard->setWindowModality(Qt::WindowModal);
dialog->setGuidedModeActive(true);

connect(wizard, &QDialog::finished, dialog,
[dialog, snapshot](int) {
dialog->setGuidedModeActive(false);
dialog->setInitialData(snapshot);
});
wizard->show();
});
}

void LLTutorWindow::showTableForCPrime() {
QStringList colHeaders;

Expand All @@ -623,6 +644,12 @@ void LLTutorWindow::showTableForCPrime() {
colHeaders.sort();
auto* dialog =
new LLTableDialog(sortedNonTerminals, colHeaders, this, &rawTable);
if (examMode) {
// The guided walkthrough reveals the answers; not during an exam.
dialog->setGuidedButtonVisible(false);
}

connectGuidedMode(dialog, colHeaders);

connect(dialog, &LLTableDialog::submitted, this,
[this, dialog, colHeaders](const QVector<QVector<QString>>& data) {
Expand Down Expand Up @@ -676,6 +703,12 @@ void LLTutorWindow::showTable() {
auto* dialog =
new LLTableDialog(sortedNonTerminals, colHeaders, this, &rawTable);
currentDlg = dialog;
if (examMode) {
// The guided walkthrough reveals the answers; not during an exam.
dialog->setGuidedButtonVisible(false);
}

connectGuidedMode(dialog, colHeaders);

connect(dialog, &LLTableDialog::submitted, this,
[this, colHeaders](const QVector<QVector<QString>>& data) {
Expand Down
13 changes: 13 additions & 0 deletions src/gui/lltutorwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ class LLTutorWindow : public QWidget {

void handleTableSubmission(const QVector<QVector<QString>>& raw,
const QStringList& colHeaders);

/**
* @brief Hooks the table dialog's guided mode button to the LL wizard.
*
* Opens the step-by-step LL(1) table assistant when requested, freezing
* the table dialog while it is active and restoring the user's snapshot
* when it closes.
*
* @param dialog Table dialog to connect.
* @param colHeaders Terminal symbols in the dialog's column order.
*/
void connectGuidedMode(LLTableDialog* dialog,
const QStringList& colHeaders);
void updatePlaceholder();
bool confirmExitToHome();
QString promptExportFilePath() const;
Expand Down
Loading
Loading