rework ui, add text from email scene

This commit is contained in:
2025-03-09 21:23:36 +03:00
parent 4f75e88b69
commit cb3d6c2a3f
19 changed files with 1194 additions and 437 deletions

107
main.cpp
View File

@@ -14,16 +14,118 @@
#endif
#include <QDateTime>
#include <QFile>
#include <QStackedLayout>
#include <QTextStream>
#include <QTranslator>
#include <qpushbutton.h>
#include <parser/parser.h>
static QWidget *loadUI(QWidget *parent, std::string filename) {
QUiLoader loader;
QFile file(QString::fromStdString(filename));
file.open(QIODevice::ReadOnly);
return loader.load(&file, parent);
}
int main(int argc, char *argv[]) {
QDateTime datetime = QDateTime::fromString("20171112T153500", "yyyyMMddThhmmss");
std::cout << datetime.toString().toStdString() << std::endl;
QUiLoader loader;
QApplication app(argc, argv);
QWidget *window = new QWidget();
QStackedLayout *sceneLayout = new QStackedLayout;
// Main Window setup
QWidget *mainwindowscene = loadUI(window, ":/scenes/scenes/mainwindow.ui");
// Main Window buttons setup
QPushButton *text_from_email_button = ((MainWindow *)mainwindowscene)->findChild<QPushButton *>("text_from_email_button");
QPushButton *ocr_button = ((MainWindow *)mainwindowscene)->findChild<QPushButton *>("ocr_button");
QPushButton *ofd_button = ((MainWindow *)mainwindowscene)->findChild<QPushButton *>("ofd_button");
QObject::connect(text_from_email_button, &QPushButton::clicked, [&]() {
// Text from email scene
sceneLayout->setCurrentIndex(1);
});
QObject::connect(ocr_button, &QPushButton::clicked, [&]() {
// OCR scene
sceneLayout->setCurrentIndex(2);
});
QObject::connect(ofd_button, &QPushButton::clicked, [&]() {
// OCR scene
sceneLayout->setCurrentIndex(3);
});
// Text from email setup
QWidget *emailtextscene = loadUI(window, ":/scenes/scenes/emailtextscene.ui");
//OCR scene
QWidget *ocrscene = loadUI(window, ":/scenes/scenes/ocrscene.ui");
sceneLayout->addWidget(mainwindowscene);
sceneLayout->addWidget(emailtextscene);
sceneLayout->addWidget(ocrscene);
//Setting all back buttons
for (uint32_t sceneIndex = 0; sceneIndex < sceneLayout->count(); sceneIndex ++) {
auto scene = sceneLayout->widget(sceneIndex);
QPushButton *back_button = scene->findChild<QPushButton *>("back_button");
if (back_button == nullptr) continue;
QObject::connect(back_button, &QPushButton::clicked, [&]() {
sceneLayout->setCurrentIndex(0);
});
}
window->setLayout(sceneLayout);
window->show();
app.exec();
return 0;
// QApplication app(argc, argv);
// QWidget *window = new QWidget;
// QStackedLayout *stackedLayout = new QStackedLayout;
// QWidget *scene1 = new QWidget;
// QWidget *scene2 = new QWidget;
// // Add some widgets to each scene
// QPushButton *button1 = new QPushButton("Switch to Scene 2");
// scene1->setLayout(new QVBoxLayout);
// scene1->layout()->addWidget(button1);
// QPushButton *button2 = new QPushButton("Switch to Scene 1");
// scene2->setLayout(new QVBoxLayout);
// scene2->layout()->addWidget(button2);
// // Add the scenes to the stacked layout
// stackedLayout->addWidget(scene1);
// stackedLayout->addWidget(scene2);
// // Set the layout of the window
// window->setLayout(stackedLayout);
// // Connect the buttons to switch scenes
// QObject::connect(button1, &QPushButton::clicked, [&]() {
// stackedLayout->setCurrentIndex(1);
// });
// QObject::connect(button2, &QPushButton::clicked, [&]() {
// stackedLayout->setCurrentIndex(0);
// });
// window->show();
// app.exec();
// return 0;
curl_global_init(CURL_GLOBAL_ALL);
std::string program_data_path = get_path_relative_to_home(".local/share/checks_parser");
@@ -68,7 +170,6 @@ int main(int argc, char *argv[]) {
a.installTranslator(&translator);
MainWindow w;
// MainWindow w;
w.update();
w.show();