mirror of
https://github.com/iDescriptor/iDescriptor.git
synced 2026-06-22 03:45:51 +08:00
add DiskUsageWidget and enhance DeviceInfoWidget layout and functionality
This commit is contained in:
+182
-55
@@ -1,36 +1,103 @@
|
||||
#include "deviceinfowidget.h"
|
||||
#include "diskusagewidget.h"
|
||||
#include "fileexplorerwidget.h"
|
||||
#include "iDescriptor.h"
|
||||
#include <QDebug>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsView>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QList>
|
||||
#include <QMessageBox>
|
||||
#include <QPainter>
|
||||
#include <QPair>
|
||||
#include <QPixmap>
|
||||
#include <QPushButton>
|
||||
#include <QResizeEvent>
|
||||
#include <QTabWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
// A custom QGraphicsView that keeps the content fitted with aspect ratio on
|
||||
// resize
|
||||
class ResponsiveGraphicsView : public QGraphicsView
|
||||
{
|
||||
public:
|
||||
ResponsiveGraphicsView(QGraphicsScene *scene, QWidget *parent = nullptr)
|
||||
: QGraphicsView(scene, parent)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override
|
||||
{
|
||||
if (scene() && !scene()->items().isEmpty()) {
|
||||
fitInView(scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
QGraphicsView::resizeEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
DeviceInfoWidget::DeviceInfoWidget(iDescriptorDevice *device, QWidget *parent)
|
||||
: QWidget(parent), device(device)
|
||||
{
|
||||
// Create main layout for this widget
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
||||
// Main layout with horizontal orientation
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout(this);
|
||||
mainLayout->setContentsMargins(10, 10, 10, 10);
|
||||
mainLayout->setSpacing(10);
|
||||
|
||||
// Create device info section
|
||||
QWidget *devWidget = new QWidget();
|
||||
QVBoxLayout *devLayout = new QVBoxLayout(devWidget);
|
||||
devLayout->setContentsMargins(10, 10, 10, 10);
|
||||
devLayout->setSpacing(10);
|
||||
QGraphicsScene *scene = new QGraphicsScene(this);
|
||||
QGraphicsPixmapItem *pixmapItem =
|
||||
new QGraphicsPixmapItem(QPixmap(":/resources/iphone.png"));
|
||||
scene->addItem(pixmapItem);
|
||||
|
||||
QGraphicsView *graphicsView = new ResponsiveGraphicsView(scene, this);
|
||||
graphicsView->setRenderHint(QPainter::Antialiasing);
|
||||
graphicsView->setMinimumWidth(200);
|
||||
graphicsView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding);
|
||||
graphicsView->setStyleSheet("background: transparent; border: none;");
|
||||
|
||||
mainLayout->addWidget(graphicsView, 1); // Stretch factor 1
|
||||
|
||||
// Right side: Info Table
|
||||
QWidget *infoContainer = new QWidget();
|
||||
infoContainer->setObjectName("infoContainer");
|
||||
infoContainer->setStyleSheet("QWidget#infoContainer { "
|
||||
" border: 1px solid #ccc; "
|
||||
" border-radius: 6px; "
|
||||
"}");
|
||||
infoContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
||||
|
||||
QVBoxLayout *infoLayout = new QVBoxLayout(infoContainer);
|
||||
infoLayout->setContentsMargins(15, 15, 15, 15);
|
||||
infoLayout->setSpacing(10);
|
||||
|
||||
// Header
|
||||
QLabel *headerLabel = new QLabel(
|
||||
"Device: " + QString::fromStdString(device->deviceInfo.productType));
|
||||
headerLabel->setStyleSheet("font-size: 1rem; padding-bottom: 10px; "
|
||||
"border-bottom: 1px solid #eee; "
|
||||
"font-weight: bold;");
|
||||
infoLayout->addWidget(headerLabel);
|
||||
|
||||
// Grid for device details
|
||||
QGridLayout *gridLayout = new QGridLayout();
|
||||
gridLayout->setSpacing(8);
|
||||
gridLayout->setColumnStretch(1, 1); // Allow value column to stretch
|
||||
gridLayout->setColumnStretch(
|
||||
3, 1); // Allow value column for right side to stretch
|
||||
|
||||
QList<QPair<QString, QWidget *>> infoItems;
|
||||
|
||||
auto createValueLabel = [](const QString &text) {
|
||||
return new QLabel(text);
|
||||
};
|
||||
|
||||
infoItems.append({"iOS Version:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.productVersion))});
|
||||
infoItems.append({"Device Name:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.deviceName))});
|
||||
|
||||
devLayout->addWidget(new QLabel(
|
||||
"Device: " + QString::fromStdString(device->deviceInfo.productType)));
|
||||
devLayout->addWidget(
|
||||
new QLabel("iOS Version: " +
|
||||
QString::fromStdString(device->deviceInfo.productVersion)));
|
||||
devLayout->addWidget(
|
||||
new QLabel("Device Name: " +
|
||||
QString::fromStdString(device->deviceInfo.deviceName)));
|
||||
// Activation state label with color and tooltip
|
||||
QLabel *activationLabel = new QLabel;
|
||||
QString stateText;
|
||||
@@ -55,50 +122,110 @@ DeviceInfoWidget::DeviceInfoWidget(iDescriptorDevice *device, QWidget *parent)
|
||||
break;
|
||||
}
|
||||
|
||||
activationLabel->setText("Activation State: " + stateText);
|
||||
activationLabel->setText(stateText);
|
||||
activationLabel->setStyleSheet("color: " + color.name() + ";");
|
||||
activationLabel->setToolTip(tooltipText);
|
||||
devLayout->addWidget(activationLabel);
|
||||
devLayout->addWidget(
|
||||
new QLabel("Device Class: " +
|
||||
QString::fromStdString(device->deviceInfo.deviceClass)));
|
||||
devLayout->addWidget(
|
||||
new QLabel("Device Color: " +
|
||||
QString::fromStdString(device->deviceInfo.deviceColor)));
|
||||
devLayout->addWidget(new QLabel(
|
||||
"Jailbroken: " +
|
||||
QString::fromStdString(device->deviceInfo.jailbroken ? "Yes" : "No")));
|
||||
devLayout->addWidget(
|
||||
new QLabel("Model Number: " +
|
||||
QString::fromStdString(device->deviceInfo.modelNumber)));
|
||||
devLayout->addWidget(
|
||||
new QLabel("CPU Architecture: " +
|
||||
QString::fromStdString(device->deviceInfo.cpuArchitecture)));
|
||||
devLayout->addWidget(
|
||||
new QLabel("Build Version: " +
|
||||
QString::fromStdString(device->deviceInfo.buildVersion)));
|
||||
devLayout->addWidget(
|
||||
new QLabel("Hardware Model: " +
|
||||
QString::fromStdString(device->deviceInfo.hardwareModel)));
|
||||
devLayout->addWidget(new QLabel(
|
||||
"Hardware Platform: " +
|
||||
QString::fromStdString(device->deviceInfo.hardwarePlatform)));
|
||||
devLayout->addWidget(
|
||||
new QLabel("Ethernet Address: " +
|
||||
QString::fromStdString(device->deviceInfo.ethernetAddress)));
|
||||
devLayout->addWidget(new QLabel(
|
||||
"Bluetooth Address: " +
|
||||
QString::fromStdString(device->deviceInfo.bluetoothAddress)));
|
||||
devLayout->addWidget(
|
||||
new QLabel("Firmware Version: " +
|
||||
QString::fromStdString(device->deviceInfo.firmwareVersion)));
|
||||
infoItems.append({"Activation State:", activationLabel});
|
||||
|
||||
devWidget->setStyleSheet(
|
||||
"QWidget { border: 1px solid #ccc; margin: 8px; border-radius: 6px; "
|
||||
"background: #fff; color: #000; }");
|
||||
infoItems.append({"Device Class:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.deviceClass))});
|
||||
infoItems.append({"Device Color:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.deviceColor))});
|
||||
infoItems.append(
|
||||
{"Jailbroken:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.jailbroken ? "Yes" : "No"))});
|
||||
infoItems.append({"Model Number:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.modelNumber))});
|
||||
infoItems.append(
|
||||
{"CPU Architecture:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.cpuArchitecture))});
|
||||
infoItems.append({"Build Version:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.buildVersion))});
|
||||
infoItems.append(
|
||||
{"Hardware Model:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.hardwareModel))});
|
||||
infoItems.append(
|
||||
{"Hardware Platform:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.hardwarePlatform))});
|
||||
infoItems.append(
|
||||
{"Ethernet Address:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.ethernetAddress))});
|
||||
infoItems.append(
|
||||
{"Bluetooth Address:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.bluetoothAddress))});
|
||||
infoItems.append(
|
||||
{"Firmware Version:", createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.firmwareVersion))});
|
||||
|
||||
// Add device info widget to main layout
|
||||
mainLayout->addWidget(devWidget);
|
||||
// Battery Info
|
||||
QWidget *batteryWidget = new QWidget();
|
||||
QHBoxLayout *batteryLayout = new QHBoxLayout(batteryWidget);
|
||||
batteryLayout->setContentsMargins(0, 0, 0, 0);
|
||||
batteryLayout->setSpacing(5);
|
||||
batteryLayout->addWidget(new QLabel(device->deviceInfo.batteryInfo.health));
|
||||
QPushButton *moreButton = new QPushButton("More");
|
||||
connect(moreButton, &QPushButton::clicked, this,
|
||||
&DeviceInfoWidget::onBatteryMoreClicked);
|
||||
batteryLayout->addWidget(moreButton);
|
||||
batteryLayout->addStretch();
|
||||
infoItems.append({"Battery Health:", batteryWidget});
|
||||
|
||||
infoItems.append(
|
||||
{"Production Device:",
|
||||
createValueLabel(QString::fromStdString(
|
||||
device->deviceInfo.productionDevice ? "Yes" : "No"))});
|
||||
|
||||
// Distribute items into the grid
|
||||
int numRows = (infoItems.size() + 1) / 2;
|
||||
for (int i = 0; i < numRows; ++i) {
|
||||
// Left column item
|
||||
QLabel *keyLabelLeft = new QLabel(infoItems[i].first);
|
||||
keyLabelLeft->setStyleSheet("font-weight: bold;");
|
||||
gridLayout->addWidget(keyLabelLeft, i, 0);
|
||||
gridLayout->addWidget(infoItems[i].second, i, 1);
|
||||
|
||||
// Right column item
|
||||
int rightIndex = i + numRows;
|
||||
if (rightIndex < infoItems.size()) {
|
||||
QLabel *keyLabelRight = new QLabel(infoItems[rightIndex].first);
|
||||
keyLabelRight->setStyleSheet("font-weight: bold;");
|
||||
gridLayout->addWidget(keyLabelRight, i, 2);
|
||||
gridLayout->addWidget(infoItems[rightIndex].second, i, 3);
|
||||
}
|
||||
}
|
||||
|
||||
infoLayout->addLayout(gridLayout);
|
||||
infoLayout->addStretch(); // Pushes footer to the bottom
|
||||
|
||||
// Footer
|
||||
QLabel *footerLabel =
|
||||
new QLabel("UDID: " + QString::fromStdString(device->udid));
|
||||
footerLabel->setStyleSheet(
|
||||
"font-size: 10px; color: #666; padding-top: 5px; "
|
||||
"border-top: 1px solid #eee;");
|
||||
footerLabel->setWordWrap(true);
|
||||
infoLayout->addWidget(footerLabel);
|
||||
|
||||
// Create a vertical layout for the right side to stack info and disk usage
|
||||
QVBoxLayout *rightSideLayout = new QVBoxLayout();
|
||||
rightSideLayout->setSpacing(10);
|
||||
rightSideLayout->addWidget(infoContainer);
|
||||
rightSideLayout->addWidget(new DiskUsageWidget(device, this));
|
||||
rightSideLayout->setAlignment(Qt::AlignCenter);
|
||||
mainLayout->addLayout(rightSideLayout, 2); // Stretch factor 2
|
||||
}
|
||||
|
||||
void DeviceInfoWidget::onBatteryMoreClicked()
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Battery Details");
|
||||
QString details =
|
||||
"Battery Cycle Count: " +
|
||||
QString::number(device->deviceInfo.batteryInfo.cycleCount) + "\n" +
|
||||
"Battery Serial Number: " +
|
||||
QString::fromStdString(device->deviceInfo.batteryInfo.serialNumber);
|
||||
msgBox.setText(details);
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
QPixmap DeviceInfoWidget::getDeviceIcon(const std::string &productType)
|
||||
|
||||
Reference in New Issue
Block a user