diff --git a/include/diskitem.h b/include/diskitem.h new file mode 100644 index 0000000..0f49c7e --- /dev/null +++ b/include/diskitem.h @@ -0,0 +1,7 @@ +#include + +struct DiskItem { + QString name; + QString temperature; + QString health; +}; diff --git a/include/gridview.h b/include/gridview.h index aa83d50..42c3755 100644 --- a/include/gridview.h +++ b/include/gridview.h @@ -5,22 +5,22 @@ #include #include +#include "diskitem.h" + class GridView : public QWidget { Q_OBJECT public: explicit GridView(QWidget *parent = nullptr); + void setDisks(const QVector &newDisks); protected: void resizeEvent(QResizeEvent *) override; -private: - struct DiskItem { - QString name; - QString category; - QString icon; - }; +signals: + void diskSelected(const QString &diskName); +private: QString searchQuery; QScrollArea *scrollArea; QWidget *gridContainer; diff --git a/include/mainwindow.h b/include/mainwindow.h index 1d87d15..248982e 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -14,6 +14,7 @@ #include #include "utils.h" +#include "gridview.h" QT_BEGIN_NAMESPACE namespace Ui { @@ -80,6 +81,7 @@ private: QString globalHealth; bool globalIsNvme; QVector> globalNvmeSmartOrdered; + GridView *gridView; void onNextButtonClicked(); void onPrevButtonClicked(); diff --git a/src/gridview.cpp b/src/gridview.cpp index f68481d..e805f17 100644 --- a/src/gridview.cpp +++ b/src/gridview.cpp @@ -50,13 +50,6 @@ GridView::GridView(QWidget *parent) : QWidget(parent) { gridLayout->setAlignment(Qt::AlignTop | Qt::AlignHCenter); gridLayout->setSpacing(gridLayoutSpacing); gridFrame->setLayout(gridLayout); - disks = { - {"/dev/sda", "40C", "Bad"}, - {"/dev/sdb", "40C", "Good"}, - {"/dev/sdc", "40C", "Unknown"}, - {"/dev/sdd", "40C", "Warning"} - }; - populateGrid(); setLayout(mainLayout); } @@ -65,6 +58,11 @@ void GridView::resizeEvent(QResizeEvent *) { populateGrid(); } +void GridView::setDisks(const QVector &newDisks) { + disks = newDisks; + populateGrid(); +} + void GridView::populateGrid() { selectedButton = nullptr; QLayoutItem *child; @@ -86,7 +84,7 @@ void GridView::populateGrid() { const DiskItem &disk = *it; if (searchQuery.isEmpty() || disk.name.contains(searchQuery, Qt::CaseInsensitive) || - disk.category.contains(searchQuery, Qt::CaseInsensitive)) { + disk.temperature.contains(searchQuery, Qt::CaseInsensitive)) { filteredDisks.append(disk); } } @@ -103,7 +101,7 @@ void GridView::extracted(const QVector &filteredDisks, int &cols, int diskLayout->setContentsMargins(0, 0, 0, 0); QPushButton *iconButton = new QPushButton(); - QString iconPath = QString(":/icons/Disk_%1.svg").arg(disk.icon); + QString iconPath = QString(":/icons/Disk_%1.svg").arg(disk.health); iconButton->setIcon(QIcon(iconPath)); iconButton->setIconSize(QSize(48, 48)); iconButton->setFixedSize(iconButtonSize, iconButtonSize); @@ -116,9 +114,9 @@ void GridView::extracted(const QVector &filteredDisks, int &cols, int QLabel *nameLabel = new QLabel(disk.name); nameLabel->setAlignment(Qt::AlignCenter); - QLabel *categoryLabel = new QLabel(disk.category); - categoryLabel->setAlignment(Qt::AlignCenter); - categoryLabel->setStyleSheet("font-size: 10px; color: gray;"); + QLabel *temperatureLabel = new QLabel(disk.temperature); + temperatureLabel->setAlignment(Qt::AlignCenter); + temperatureLabel->setStyleSheet("font-size: 10px; color: gray;"); connect(iconButton, &QPushButton::clicked, this, [this, iconButton]() { if (selectedButton) { @@ -133,7 +131,7 @@ void GridView::extracted(const QVector &filteredDisks, int &cols, int diskLayout->addWidget(iconButton, 0, Qt::AlignCenter); diskLayout->addWidget(nameLabel, 0, Qt::AlignCenter); - diskLayout->addWidget(categoryLabel, 0, Qt::AlignCenter); + diskLayout->addWidget(temperatureLabel, 0, Qt::AlignCenter); diskWidget->setLayout(diskLayout); gridLayout->addWidget(diskWidget, row, col); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9d534c8..38f297c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4,7 +4,6 @@ #include "statusdot.h" #include "custombutton.h" #include "jsonparser.h" -#include "gridview.h" #include #include @@ -94,6 +93,8 @@ MainWindow::MainWindow(QWidget *parent) statusLabel = new QLabel; + gridView = new GridView(nullptr); + ui->actionIgnore_C4_Reallocation_Event_Count->setChecked(settings.value("IgnoreC4", true).toBool()); ui->actionHEX->setChecked(settings.value("HEX", true).toBool()); ui->actionUse_Fahrenheit->setChecked(settings.value("Fahrenheit", false).toBool()); @@ -174,6 +175,8 @@ void MainWindow::updateNavigationButtons(qsizetype currentIndex) void MainWindow::updateUI() { + QVector diskItems; + bool firstTime = true; globalIsNvme = false; @@ -326,6 +329,8 @@ void MainWindow::updateUI() qsizetype buttonIndex = buttonGroup->buttons().indexOf(button); + diskItems.append({ deviceName, temperature, health }); + auto updateWindow = [=]() { if (isNvme) { populateWindow(localObj, health, nvmeSmartOrdered); @@ -368,6 +373,7 @@ void MainWindow::updateUI() } updateNavigationButtons(buttonGroup->buttons().indexOf(buttonGroup->checkedButton())); + gridView->setDisks(diskItems); } void MainWindow::populateWindow(const QJsonObject &localObj, const QString &health, const QVector>& nvmeLogOrdered) @@ -1207,6 +1213,16 @@ void MainWindow::transformWindow() { ui->centralwidget->setAutoFillBackground(true); } +void MainWindow::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::ForwardButton && nextButton->isEnabled()) { + onNextButtonClicked(); + } else if (event->button() == Qt::BackButton && prevButton->isEnabled()) { + onPrevButtonClicked(); + } +} + +// Slots void MainWindow::on_actionQuit_triggered() { qApp->quit(); @@ -1316,15 +1332,6 @@ void MainWindow::on_actionUse_GB_instead_of_TB_toggled(bool gigabytes) } } -void MainWindow::mousePressEvent(QMouseEvent *event) -{ - if (event->button() == Qt::ForwardButton && nextButton->isEnabled()) { - onNextButtonClicked(); - } else if (event->button() == Qt::BackButton && prevButton->isEnabled()) { - onPrevButtonClicked(); - } -} - void MainWindow::on_actionClear_Settings_triggered() { QMessageBox msgBox; @@ -1412,11 +1419,8 @@ void MainWindow::on_actionASCII_View_triggered() asciiViewDialog->exec(); } - void MainWindow::on_actionGrid_View_triggered() { - auto *gridView = new GridView(nullptr); - gridView->setAttribute(Qt::WA_DeleteOnClose); gridView->show(); }