mirror of
https://github.com/edisionnano/QDiskInfo.git
synced 2026-04-12 00:21:27 +03:00
Highlight the correct disk on the grid view
This commit is contained in:
@@ -13,6 +13,8 @@ class GridView : public QWidget {
|
|||||||
public:
|
public:
|
||||||
explicit GridView(QWidget *parent = nullptr);
|
explicit GridView(QWidget *parent = nullptr);
|
||||||
void setDisks(const QVector<DiskItem> &newDisks);
|
void setDisks(const QVector<DiskItem> &newDisks);
|
||||||
|
void highlightDisk(qsizetype index);
|
||||||
|
void setActiveIndex(qsizetype index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *) override;
|
void resizeEvent(QResizeEvent *) override;
|
||||||
@@ -32,4 +34,6 @@ private:
|
|||||||
|
|
||||||
void extracted(const QVector<DiskItem> &filteredDisks, int &cols, int &row, int &col);
|
void extracted(const QVector<DiskItem> &filteredDisks, int &cols, int &row, int &col);
|
||||||
void populateGrid();
|
void populateGrid();
|
||||||
|
|
||||||
|
qsizetype activeIndex = -1;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -62,6 +62,35 @@ void GridView::setDisks(const QVector<DiskItem> &newDisks) {
|
|||||||
populateGrid();
|
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() {
|
void GridView::populateGrid() {
|
||||||
selectedButton = nullptr;
|
selectedButton = nullptr;
|
||||||
QLayoutItem *child;
|
QLayoutItem *child;
|
||||||
@@ -89,6 +118,10 @@ void GridView::populateGrid() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extracted(filteredDisks, cols, row, col);
|
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) {
|
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, [=]() {
|
connect(button, &QPushButton::clicked, this, [=]() {
|
||||||
updateWindow();
|
updateWindow();
|
||||||
disksGroup->actions().at(buttonIndex)->setChecked(true);
|
disksGroup->actions().at(buttonIndex)->setChecked(true);
|
||||||
|
gridView->highlightDisk(buttonIndex);
|
||||||
|
gridView->setActiveIndex(buttonIndex);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(diskAction, &QAction::triggered, this, [=]() {
|
connect(diskAction, &QAction::triggered, this, [=]() {
|
||||||
updateWindow();
|
updateWindow();
|
||||||
button->setChecked(true);
|
button->setChecked(true);
|
||||||
|
gridView->highlightDisk(buttonIndex);
|
||||||
|
gridView->setActiveIndex(buttonIndex);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (firstTime) {
|
if (firstTime) {
|
||||||
@@ -364,6 +368,7 @@ void MainWindow::updateUI()
|
|||||||
globalHealth = health;
|
globalHealth = health;
|
||||||
button->setChecked(true);
|
button->setChecked(true);
|
||||||
diskAction->setChecked(true);
|
diskAction->setChecked(true);
|
||||||
|
gridView->setActiveIndex(0);
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
globalIsNvme = isNvme;
|
globalIsNvme = isNvme;
|
||||||
if (isNvme) {
|
if (isNvme) {
|
||||||
|
|||||||
Reference in New Issue
Block a user