1
0
forked from BRT/arc
arc/views/MainWindow.cpp
slava b1876bc3b9 Refactor includes and add AccountInfoScreener functionality
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.
2025-04-21 23:12:21 +07:00

64 lines
2.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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));
}
}