mirror of
https://github.com/edisionnano/QDiskInfo.git
synced 2026-03-07 11:59:57 +03:00
Highlight the correct disk on the grid view
This commit is contained in:
@@ -13,6 +13,8 @@ class GridView : public QWidget {
|
||||
public:
|
||||
explicit GridView(QWidget *parent = nullptr);
|
||||
void setDisks(const QVector<DiskItem> &newDisks);
|
||||
void highlightDisk(qsizetype index);
|
||||
void setActiveIndex(qsizetype index);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *) override;
|
||||
@@ -32,4 +34,6 @@ private:
|
||||
|
||||
void extracted(const QVector<DiskItem> &filteredDisks, int &cols, int &row, int &col);
|
||||
void populateGrid();
|
||||
|
||||
qsizetype activeIndex = -1;
|
||||
};
|
||||
|
||||
@@ -62,6 +62,35 @@ void GridView::setDisks(const QVector<DiskItem> &newDisks) {
|
||||
populateGrid();
|
||||
}
|
||||
|
||||
void GridView::highlightDisk(qsizetype index) {
|
||||
if (index < 0 || index >= gridLayout->count())
|
||||
return;
|
||||
|
||||
QWidget *diskWidget = gridLayout->itemAt(static_cast<int>(index))->widget();
|
||||
if (!diskWidget)
|
||||
return;
|
||||
|
||||
QPushButton *iconButton = diskWidget->findChild<QPushButton *>();
|
||||
if (!iconButton)
|
||||
return;
|
||||
|
||||
if (selectedButton) {
|
||||
selectedButton->setStyleSheet(iconButton->styleSheet());
|
||||
}
|
||||
|
||||
selectedButton = iconButton;
|
||||
selectedButton->setStyleSheet(
|
||||
QString("QPushButton { border: 2px solid %1; background-color: %2; }")
|
||||
.arg(selectedColor, hoverColor));
|
||||
}
|
||||
|
||||
void GridView::setActiveIndex(qsizetype index) {
|
||||
activeIndex = index;
|
||||
if (gridLayout && gridLayout->count() > 0) {
|
||||
highlightDisk(activeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void GridView::populateGrid() {
|
||||
selectedButton = nullptr;
|
||||
QLayoutItem *child;
|
||||
@@ -89,6 +118,10 @@ void GridView::populateGrid() {
|
||||
}
|
||||
|
||||
extracted(filteredDisks, cols, row, col);
|
||||
|
||||
if (activeIndex >= 0 && activeIndex < filteredDisks.size()) {
|
||||
highlightDisk(activeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void GridView::extracted(const QVector<DiskItem> &filteredDisks, int &cols, int &row, int &col) {
|
||||
|
||||
@@ -352,11 +352,15 @@ void MainWindow::updateUI()
|
||||
connect(button, &QPushButton::clicked, this, [=]() {
|
||||
updateWindow();
|
||||
disksGroup->actions().at(buttonIndex)->setChecked(true);
|
||||
gridView->highlightDisk(buttonIndex);
|
||||
gridView->setActiveIndex(buttonIndex);
|
||||
});
|
||||
|
||||
connect(diskAction, &QAction::triggered, this, [=]() {
|
||||
updateWindow();
|
||||
button->setChecked(true);
|
||||
gridView->highlightDisk(buttonIndex);
|
||||
gridView->setActiveIndex(buttonIndex);
|
||||
});
|
||||
|
||||
if (firstTime) {
|
||||
@@ -364,6 +368,7 @@ void MainWindow::updateUI()
|
||||
globalHealth = health;
|
||||
button->setChecked(true);
|
||||
diskAction->setChecked(true);
|
||||
gridView->setActiveIndex(0);
|
||||
firstTime = false;
|
||||
globalIsNvme = isNvme;
|
||||
if (isNvme) {
|
||||
|
||||
Reference in New Issue
Block a user