Updated include paths for consistent structure under the `db` directory. Added `AccountInfoScreener` for parsing card data using Tesseract OCR and enhanced related models. Removed unused code and simplified main workflow.
64 lines
2.0 KiB
C++
64 lines
2.0 KiB
C++
#include "MainWindow.h"
|
||
|
||
#include <QLabel>
|
||
#include <QScrollArea>
|
||
|
||
#include "db/DeviceInfo.h"
|
||
#include "DeviceWidget.h"
|
||
#include "dao/DeviceDAO.h"
|
||
#include "widget/FlowLayout.h"
|
||
|
||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
||
// QPushButton* btn = new QPushButton("Hello Qt6!", this);
|
||
// setCentralWidget(btn);
|
||
|
||
auto* scrollArea = new QScrollArea(this);
|
||
auto* contentWidget = new QWidget;
|
||
flowLayout = new FlowLayout(contentWidget);
|
||
|
||
|
||
|
||
contentWidget->setContentsMargins(0, 0, 0, 0); // Убираем отступы у контейнера
|
||
flowLayout->setContentsMargins(0, 0, 0, 0); // Убираем отступы у layout
|
||
flowLayout->setSpacing(0);
|
||
|
||
|
||
QVector<DeviceInfo> devices = DeviceDAO::getAllDevices();
|
||
for (const auto& device : devices) {
|
||
auto* deviceWidget = new DeviceWidget(device); // Создаем виджет, используя первый элемент из списка devices
|
||
deviceWidget->setFixedWidth(220);
|
||
deviceWidget->setFixedHeight(400);
|
||
|
||
deviceWidget->setContentsMargins(0, 0, 0, 0);
|
||
flowLayout->addWidget(deviceWidget);
|
||
}
|
||
|
||
resize(800, 600);
|
||
|
||
contentWidget->setLayout(flowLayout);
|
||
scrollArea->setWidget(contentWidget);
|
||
scrollArea->setWidgetResizable(true);
|
||
setCentralWidget(scrollArea);
|
||
|
||
timer = new QTimer(this);
|
||
connect(timer, &QTimer::timeout, this, &MainWindow::loadDevices);
|
||
timer->start(1000); // каждые 1 сек
|
||
}
|
||
|
||
|
||
void MainWindow::loadDevices() const {
|
||
const auto devices = DeviceDAO::getAllDevices();
|
||
|
||
// Очистить старые виджеты
|
||
QLayoutItem* item;
|
||
while ((item = flowLayout->takeAt(0)) != nullptr) {
|
||
delete item->widget(); // Удаляем виджет
|
||
delete item; // Удаляем сам элемент из layout
|
||
}
|
||
|
||
// Добавляем новые виджеты для каждого устройства
|
||
for (const auto& device : devices) {
|
||
flowLayout->addWidget(new DeviceWidget(device));
|
||
}
|
||
}
|