diff --git a/images/alfa_icon.png b/images/alfa_icon.png new file mode 100644 index 0000000..40bb199 Binary files /dev/null and b/images/alfa_icon.png differ diff --git a/images/cogwheel.png b/images/cogwheel.png new file mode 100644 index 0000000..23d33ba Binary files /dev/null and b/images/cogwheel.png differ diff --git a/images/img.png b/images/img.png deleted file mode 100644 index 1f48195..0000000 Binary files a/images/img.png and /dev/null differ diff --git a/images/turn_off.png b/images/turn_off.png new file mode 100644 index 0000000..bcce6c6 Binary files /dev/null and b/images/turn_off.png differ diff --git a/images/turn_on.png b/images/turn_on.png new file mode 100644 index 0000000..53b7552 Binary files /dev/null and b/images/turn_on.png differ diff --git a/views/MainWindow.cpp b/views/MainWindow.cpp index 3cdde7e..f51c391 100644 --- a/views/MainWindow.cpp +++ b/views/MainWindow.cpp @@ -77,14 +77,14 @@ void MainWindow::createDevicePage() { auto *scrollArea = new QScrollArea(this); auto *contentWidget = new QWidget; - flowLayout = new FlowLayout(contentWidget); - flowLayout->setContentsMargins(0, 0, 0, 0); - flowLayout->setSpacing(0); + flowLayout = new FlowLayout(contentWidget, 0, 0, 0); + // flowLayout->setContentsMargins(0, 0, 0, 0); + // flowLayout->setSpacing(0); QVector devices = DeviceDAO::getAllDevices(true); for (const auto &device: devices) { auto *deviceWidget = new DeviceWidget(device); - deviceWidget->setFixedSize(220, 400); + // deviceWidget->setFixedSize(220, 400); flowLayout->addWidget(deviceWidget); } diff --git a/views/device/DeviceWidget.cpp b/views/device/DeviceWidget.cpp index e8bf756..11ec977 100644 --- a/views/device/DeviceWidget.cpp +++ b/views/device/DeviceWidget.cpp @@ -3,35 +3,129 @@ #include #include #include +#include +#include DeviceWidget::DeviceWidget(const DeviceInfo &device, QWidget *parent): QWidget(parent) { - auto *layout = new QVBoxLayout(this); - - this->setStyleSheet("background-color: lightgray;padding: 10px;"); + auto *layout = new QGridLayout(this); + layout->setContentsMargins(2, 2, 2, 2); + layout->setSpacing(0); + this->setStyleSheet("background-color: lightgray;padding: 2px;"); QImage img; img.loadFromData(device.image, "JPG"); auto *imageLabel = new QLabel(this); - // qDebug() << "imageLabel" << img.width() ; - imageLabel->setPixmap(QPixmap::fromImage(img).scaled(200, 350, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + imageLabel->setPixmap(QPixmap::fromImage(img).scaled(300, 450, Qt::KeepAspectRatio, Qt::SmoothTransformation)); imageLabel->setAlignment(Qt::AlignCenter); - layout->addWidget(imageLabel); + layout->addWidget(imageLabel, 0, 0); - const QString result = QString("%1, Android %2, battery %3% [%4x%5]") - .arg(device.name).arg(device.android).arg(device.battery). - arg(device.screenWidth).arg(device.screenHeight); - - auto *statusLabel = new QLabel(result, this); - statusLabel->setAlignment(Qt::AlignCenter); - statusLabel->setMaximumWidth(200); + auto *statusLabel = new QLabel(device.name, this); statusLabel->setWordWrap(true); + statusLabel->setMaximumWidth(300); + statusLabel->setStyleSheet( + "background-color: rgba(0, 0, 0, 0.5);" + "color: white;" + ); + // статус — в ту же ячейку, но поверх картинки и по углу + layout->addWidget(statusLabel, 0, 0, Qt::AlignTop | Qt::AlignLeft); - const QString styleSheet = QString("color: %1; font-weight: bold;") - .arg(device.status == "online" ? "green" : "red"); - statusLabel->setStyleSheet(styleSheet); + auto *batteryLabel = new QLabel(QString("%1%").arg(device.battery), this); + batteryLabel->setWordWrap(true); + batteryLabel->setMaximumWidth(300); + batteryLabel->setStyleSheet( + "background-color: rgba(0, 0, 0, 0.5);" + "color: white;" + ); + // статус — в ту же ячейку, но поверх картинки и по углу + layout->addWidget(batteryLabel, 0, 0, Qt::AlignTop | Qt::AlignRight); - // layout->setContentsMargins(10, 10, 10, 10); - layout->setSpacing(0); - layout->addWidget(statusLabel); + + auto *overlay = new QWidget(this); + overlay->setAttribute(Qt::WA_TransparentForMouseEvents, false); + overlay->setStyleSheet("background: transparent;"); // сам фон прозрачный + // вертикальный лэйаут списка внутри overlay + auto *vbox = new QVBoxLayout(overlay); + vbox->setContentsMargins(2, 0, 0, 2); + vbox->setSpacing(2); + + // пример трёх строк (можете генерировать их динамически) + for (int i = 0; i < 3; ++i) { + auto *rowWidget = new QWidget(overlay); + rowWidget->setContentsMargins(0, 0, 0, 0); + rowWidget->setStyleSheet( + "background-color: rgba(0, 0, 0, 0.6);" // полупрозрачный фон + "border-radius: 4px;" // скруглённые углы, если нужно + ); + + // вешаем на контейнер ваш QHBoxLayout + auto *hbox = new QHBoxLayout(rowWidget); + hbox->setContentsMargins(2, 1, 1, 1); + hbox->setSpacing(0); + + auto *icon = new QLabel(overlay); + QPixmap pixmap(QCoreApplication::applicationDirPath() + "/images/alfa_icon.png"); + icon->setPixmap(pixmap); + icon->setPixmap(pixmap.scaled(18, 18, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + icon->setStyleSheet( + "background-color: transparent;" + "margin: 0px;" + ); + + + auto *label = new QLabel(QString("Банк %1").arg(i + 1), overlay); + label->setStyleSheet( + "background-color: transparent;" + "margin: 0px;" + "font-size: 10px;" + "color: white;" + ); + + auto *circle = new QLabel(overlay); + circle->setFixedSize(12, 12); + circle->setStyleSheet( + "margin: 0px;" + "background-color: red; " + "border-radius: 6px;" + ); + + // 3) две кнопки + auto *btn1 = new QPushButton(overlay); + QIcon btnIcon(QCoreApplication::applicationDirPath() + "/images/turn_on.png"); + btn1->setIcon(btnIcon); + btn1->setIconSize(QSize(16, 16)); + btn1->setFlat(true); + btn1->setStyleSheet( + "margin: 0px;" + "background-color: transparent;" + "border: none;" + ); + + auto *btn2 = new QPushButton(overlay); + QIcon btn2Icon(QCoreApplication::applicationDirPath() + "/images/cogwheel.png"); + btn2->setIcon(btn2Icon); + btn2->setIconSize(QSize(16, 16)); + btn2->setFlat(true); + btn2->setStyleSheet( + "margin: 0px;" + "background-color: transparent;" + "border: none;" + ); + + + // собираем + hbox->addWidget(icon); + hbox->addWidget(label); + hbox->addWidget(circle); + hbox->addWidget(btn1); + hbox->addWidget(btn2); + + hbox->addStretch(); + vbox->addWidget(rowWidget); + } + vbox->addStretch(); + + // кладём overlay в ту же ячейку, что и картинку, + // но выравниваем его по левому-нижнему углу + layout->addWidget(overlay, 0, 0, Qt::AlignLeft | Qt::AlignBottom); }