Add support for CrystalDiskInfo Anime Themes

Closes #7
This commit is contained in:
spiros
2024-06-24 17:45:51 +03:00
parent 959b96046c
commit de03f84e27
17 changed files with 622 additions and 360 deletions

View File

@@ -24,10 +24,18 @@ MainWindow::MainWindow(QWidget *parent)
horizontalLayout->setContentsMargins(0, 0, 0, 0);
ui->scrollArea->setWidget(containerWidget);
verticalLayout = ui->centralwidget->findChild<QVBoxLayout*>("verticalLayout");
gridLayout = ui->centralwidget->findChild<QGridLayout*>("gridLayout");
diskName = qobject_cast<QLabel *>(ui->centralwidget->findChild<QLabel*>("diskName"));
temperatureValue = qobject_cast<QLabel *>(ui->centralwidget->findChild<QLabel*>("temperatureValueLabel"));
healthStatusValue = qobject_cast<QLabel *>(ui->centralwidget->findChild<QLabel*>("healthStatusValueLabel"));
temperatureLabelHorizontal = qobject_cast<QLabel *>(ui->centralwidget->findChild<QLabel*>("healthStatusLabelHorizozontal"));
healthStatusLabelHorizontal = qobject_cast<QLabel *>(ui->centralwidget->findChild<QLabel*>("temperatureLabelHorizontal"));
temperatureValueHorizontal = qobject_cast<QLabel *>(ui->centralwidget->findChild<QLabel*>("temperatureValueLabelHorizontal"));
healthStatusValueHorizontal = qobject_cast<QLabel *>(ui->centralwidget->findChild<QLabel*>("healthStatusValueLabelHorizontal"));
firmwareLineEdit = qobject_cast<QLineEdit *>(ui->centralwidget->findChild<QLineEdit*>("firmwareLineEdit"));
serialNumberLineEdit = qobject_cast<QLineEdit *>(ui->centralwidget->findChild<QLineEdit*>("serialNumberLineEdit"));
typeLineEdit = qobject_cast<QLineEdit *>(ui->centralwidget->findChild<QLineEdit*>("typeLineEdit"));
@@ -76,6 +84,8 @@ MainWindow::MainWindow(QWidget *parent)
badColor = QColor(Qt::red);
naColor = QColor(Qt::gray);
statusLabel = new QLabel;
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());
@@ -101,6 +111,30 @@ MainWindow::MainWindow(QWidget *parent)
}
this->setFocus();
initializing = false;
if (!INCLUDE_OPTIONAL_RESOURCES || CHARACTER_IS_RIGHT) {
QLayoutItem *leftSpacerItem = gridLayout->itemAtPosition(2, 0);
if (leftSpacerItem) {
gridLayout->removeItem(leftSpacerItem);
if (dynamic_cast<QSpacerItem*>(leftSpacerItem)) {
delete leftSpacerItem;
}
else if (QWidget *widget = leftSpacerItem->widget()) {
delete widget;
} else {
delete leftSpacerItem;
}
}
}
if (INCLUDE_OPTIONAL_RESOURCES) {
transformWindow();
} else {
delete temperatureLabelHorizontal;
delete healthStatusLabelHorizontal;
delete temperatureValueHorizontal;
delete healthStatusValueHorizontal;
}
}
MainWindow::~MainWindow()
@@ -601,14 +635,23 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
}
}
if (temperatureInt > warningTemperature) { // TODO: Let the user set an alarm temp.
temperatureValue->setStyleSheet("background-color: " + badColor.name() + ";");
} else if ((temperatureInt < criticalTemperature) && (temperatureInt > warningTemperature)){
temperatureValue->setStyleSheet("background-color: " + cautionColor.name() + ";");
} else if (temperatureInt == 0) {
temperatureValue->setStyleSheet("background-color: " + naColor.name() + ";");
QLabel *temperatureValueLabel, *healthStatusValueLabel;
if (INCLUDE_OPTIONAL_RESOURCES) {
temperatureValueLabel = temperatureValueHorizontal;
healthStatusValueLabel = healthStatusValueHorizontal;
} else {
temperatureValue->setStyleSheet("background-color: " + goodColor.name() + ";");
temperatureValueLabel = temperatureValue;
healthStatusValueLabel = healthStatusValue;
}
if (temperatureInt > warningTemperature) { // TODO: Let the user set an alarm temp.
temperatureValueLabel->setStyleSheet("background-color: " + badColor.name() + ";");
} else if ((temperatureInt < criticalTemperature) && (temperatureInt > warningTemperature)){
temperatureValueLabel->setStyleSheet("background-color: " + cautionColor.name() + ";");
} else if (temperatureInt == 0) {
temperatureValueLabel->setStyleSheet("background-color: " + naColor.name() + ";");
} else {
temperatureValueLabel->setStyleSheet("background-color: " + goodColor.name() + ";");
}
QString labelStyle = "font-size:12pt; font-weight:700; color:black";
@@ -616,32 +659,54 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
if (temperatureInt > 0) {
if (ui->actionUse_Fahrenheit->isChecked()) {
int fahrenheit = static_cast<int>((temperatureInt * 9.0 / 5.0) + 32.0);
temperatureValue->setText("<html><head/><body><p><span style='" + labelStyle +"'>" + QString::number(fahrenheit) + " °F</span></p></body></html>");
temperatureValueLabel->setText("<html><head/><body><p><span style='" + labelStyle +"'>" + QString::number(fahrenheit) + " °F</span></p></body></html>");
} else {
temperatureValue->setText("<html><head/><body><p><span style='" + labelStyle +"'>" + QString::number(temperatureInt) + " °C</span></p></body></html>");
temperatureValueLabel->setText("<html><head/><body><p><span style='" + labelStyle +"'>" + QString::number(temperatureInt) + " °C</span></p></body></html>");
}
} else {
temperatureValue->setText("<html><head/><body><p><span style='" + labelStyle +"'>" + "-- °C" + "</span></p></body></html>");
temperatureValueLabel->setText("<html><head/><body><p><span style='" + labelStyle +"'>" + "-- °C" + "</span></p></body></html>");
}
temperatureValue->setAlignment(Qt::AlignCenter);
temperatureValueLabel->setAlignment(Qt::AlignCenter);
if (health == tr("Bad")) {
healthStatusValue->setStyleSheet("background-color: " + badColor.name() + ";");
healthStatusValueLabel->setStyleSheet("background-color: " + badColor.name() + ";");
} else if (health == tr("Caution")){
healthStatusValue->setStyleSheet("background-color: " + cautionColor.name() + ";");
healthStatusValueLabel->setStyleSheet("background-color: " + cautionColor.name() + ";");
} else if (health == tr("Good")) {
healthStatusValue->setStyleSheet("background-color: " + goodColor.name() + ";");
healthStatusValueLabel->setStyleSheet("background-color: " + goodColor.name() + ";");
} else {
healthStatusValue->setStyleSheet("background-color: " + naColor.name() + ";");
healthStatusValueLabel->setStyleSheet("background-color: " + naColor.name() + ";");
}
if (INCLUDE_OPTIONAL_RESOURCES) {
QPixmap statusAnimeBackground;
QSize labelSize(100, 30);
if (health == tr("Bad")) {
statusAnimeBackground = QPixmap(":/icons/bad.png");
} else if (health == tr("Caution")){
statusAnimeBackground = QPixmap(":/icons/caution.png");
} else if (health == tr("Good")) {
statusAnimeBackground = QPixmap(":/icons/good.png");
} else {
statusAnimeBackground = QPixmap(":/icons/unknown.png");
}
QPixmap statusAnimeBackgroundScaled = statusAnimeBackground.scaled(labelSize, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
statusLabel->setPixmap(statusAnimeBackgroundScaled);
statusLabel->setToolTip(health);
}
QString percentageText = "";
if (!percentage.isEmpty()) {
percentageText = "<br/>" + percentage;
if (INCLUDE_OPTIONAL_RESOURCES) {
percentageText = " (" + percentage + ")"; // 2 spaces is not a mistake
} else {
percentageText = "<br>" + percentage;
}
}
healthStatusValue->setText("<html><head/><body><p><span style='" + labelStyle +"'>" + health + percentageText + "</span></p></body></html>");
healthStatusValue->setAlignment(Qt::AlignCenter);
healthStatusValueLabel->setText("<html><head/><body><p><span style='" + labelStyle +"'>" + health + percentageText + "</span></p></body></html>");
healthStatusValueLabel->setAlignment(Qt::AlignCenter);
if (protocol != "NVMe") {
addSmartAttributesTable(attributes);
@@ -936,6 +1001,54 @@ void MainWindow::addSmartAttributesTable(const QJsonArray &attributes)
tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
void MainWindow::transformWindow() {
setMaximumSize(960, 960);
resize(960, 600);
QLayoutItem *item;
while ((item = verticalLayout->takeAt(0)) != nullptr) {
QWidget *widget = item->widget();
if (widget) {
delete widget;
}
delete item;
}
verticalLayout->addWidget(statusLabel);
if (CHARACTER_IS_RIGHT) {
QSpacerItem *spacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(spacer,3,3);
setMinimumWidth(645);
} else {
setMinimumWidth(960);
}
QHBoxLayout *infoLayout = ui->centralwidget->findChild<QHBoxLayout*>("info");
QSpacerItem *spacerItem = infoLayout->itemAt(1)->spacerItem();
if (spacerItem) {
infoLayout->removeItem(spacerItem);
delete spacerItem;
}
QPalette palette = QApplication::palette();
QColor backgroundColor = palette.color(QPalette::Window);
int lightness = backgroundColor.lightness();
bool darkTheme = lightness < 128;
QPixmap animeBackground;
if (darkTheme) {
animeBackground = QPixmap(":/icons/bg_dark.png");
} else {
animeBackground = QPixmap(":/icons/bg_light.png");
}
animeBackground = animeBackground.scaled(this->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
palette.setBrush(QPalette::Window, QBrush(animeBackground));
ui->centralwidget->setPalette(palette);
ui->centralwidget->setAutoFillBackground(true);
}
void MainWindow::on_actionQuit_triggered()
{
qApp->quit();

View File

@@ -51,12 +51,16 @@ private:
utils Utils;
QButtonGroup *buttonGroup;
QHBoxLayout *horizontalLayout;
QVBoxLayout *verticalLayout;
QGridLayout *gridLayout;
QLabel *diskName, *temperatureValue, *healthStatusValue;
QLabel *temperatureLabelHorizontal, *healthStatusLabelHorizontal, *temperatureValueHorizontal, *healthStatusValueHorizontal;
QLineEdit *firmwareLineEdit, *serialNumberLineEdit, *typeLineEdit, *protocolLineEdit, *deviceNodeLineEdit;
QLineEdit *totalReadsLineEdit, *totalWritesLineEdit, *rotationRateLineEdit, *powerOnCountLineEdit, *powerOnHoursLineEdit;
QTableWidget *tableWidget;
QPushButton *prevButton, *nextButton;
QColor goodColor, cautionColor, badColor, naColor;
QLabel *statusLabel;
QJsonObject deviceJson;
QSpacerItem *buttonStretch;
QAction *actionCyclic_Navigation;
@@ -79,5 +83,6 @@ private:
void populateWindow(const QJsonObject &tempObj, const QString &health, const QVector<QPair<QString, int>>& nvmeLogOrdered = QVector<QPair<QString, int>>());
void addNvmeLogTable(const QVector<QPair<QString, int>>& nvmeLogOrdered);
void addSmartAttributesTable(const QJsonArray &attributes);
void transformWindow();
void mousePressEvent(QMouseEvent*);
};

View File

@@ -30,46 +30,7 @@
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="disks">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>784</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<item row="3" column="1">
<widget class="QTableWidget" name="dataTable">
<property name="autoFillBackground">
<bool>false</bool>
@@ -82,64 +43,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="navigation">
<item>
<widget class="QPushButton" name="previousButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="go-previous"/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="diskName">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:14pt; font-weight:700;&quot;&gt;Hard Drive Name&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="nextButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="go-next"/>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<item row="2" column="1">
<layout class="QHBoxLayout" name="info">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -303,11 +207,43 @@
<property name="text">
<string/>
</property>
<property name="frame">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="healthStatusValueLabelHorizontal">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>180</width>
<height>30</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 255, 0);</string>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt; font-weight:700; color:#000000;&quot;&gt;Good 100 %&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="healthStatusLabelHorizozontal">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;Health Status&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="typeLabel">
<property name="text">
@@ -400,12 +336,150 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="temperatureValueLabelHorizontal">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>135</width>
<height>30</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 255, 0);</string>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt; font-weight:700; color:#000000;&quot;&gt;23° C&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="temperatureLabelHorizontal">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;Temperature&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="navigation">
<item>
<widget class="QPushButton" name="previousButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="go-previous"/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="diskName">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:14pt; font-weight:700;&quot;&gt;Hard Drive Name&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="nextButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="go-next"/>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="disks">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>670</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
@@ -560,7 +634,7 @@
<iconset theme="help-about"/>
</property>
<property name="text">
<string>About Qt</string>
<string>About &amp;Qt</string>
</property>
</action>
</widget>