color according to the selected theme

This commit is contained in:
DanielSvoboda 2024-11-16 16:53:57 -03:00
parent 3c8234757d
commit 2311bfa8cc
6 changed files with 156 additions and 67 deletions

View File

@ -42,6 +42,7 @@ path = [
"src/images/themes_icon.png",
"src/images/update_icon.png",
"src/images/youtube.png",
"src/images/website.png",
"src/shadps4.qrc",
"src/shadps4.rc",
]

BIN
src/images/website.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

View File

@ -7,23 +7,26 @@
#include <QImage>
#include <QLabel>
#include <QPixmap>
#include <common/config.h>
#include "about_dialog.h"
#include "main_window_themes.h"
#include "ui_about_dialog.h"
AboutDialog::AboutDialog(QWidget* parent) : QDialog(parent), ui(new Ui::AboutDialog) {
ui->setupUi(this);
preloadImages();
ui->image_1->setAttribute(Qt::WA_Hover, true);
ui->image_2->setAttribute(Qt::WA_Hover, true);
ui->image_3->setAttribute(Qt::WA_Hover, true);
ui->image_4->setAttribute(Qt::WA_Hover, true);
ui->image_5->setAttribute(Qt::WA_Hover, true);
ui->image_1->installEventFilter(this);
ui->image_2->installEventFilter(this);
ui->image_3->installEventFilter(this);
ui->image_4->installEventFilter(this);
ui->image_5->installEventFilter(this);
}
AboutDialog::~AboutDialog() {
@ -35,10 +38,10 @@ void AboutDialog::preloadImages() {
originalImages[1] = ui->image_2->pixmap().copy();
originalImages[2] = ui->image_3->pixmap().copy();
originalImages[3] = ui->image_4->pixmap().copy();
originalImages[4] = ui->image_5->pixmap().copy();
for (int i = 0; i < 4; ++i) {
for (int i = 0; i < 5; ++i) {
QImage image = originalImages[i].toImage();
for (int y = 0; y < image.height(); ++y) {
for (int x = 0; x < image.width(); ++x) {
QColor color = image.pixelColor(x, y);
@ -50,89 +53,142 @@ void AboutDialog::preloadImages() {
}
invertedImages[i] = QPixmap::fromImage(image);
}
updateImagesForCurrentTheme();
}
void AboutDialog::updateImagesForCurrentTheme() {
Theme currentTheme = static_cast<Theme>(Config::getMainWindowTheme());
bool isDarkTheme = (currentTheme == Theme::Dark || currentTheme == Theme::Green ||
currentTheme == Theme::Blue || currentTheme == Theme::Violet);
if (isDarkTheme) {
ui->image_1->setPixmap(invertedImages[0]);
ui->image_2->setPixmap(invertedImages[1]);
ui->image_3->setPixmap(invertedImages[2]);
ui->image_4->setPixmap(invertedImages[3]);
ui->image_5->setPixmap(invertedImages[4]);
} else {
ui->image_1->setPixmap(originalImages[0]);
ui->image_2->setPixmap(originalImages[1]);
ui->image_3->setPixmap(originalImages[2]);
ui->image_4->setPixmap(originalImages[3]);
ui->image_5->setPixmap(originalImages[4]);
}
}
bool AboutDialog::eventFilter(QObject* obj, QEvent* event) {
if (event->type() == QEvent::Enter) {
if (obj == ui->image_1) {
ui->image_1->setPixmap(invertedImages[0]);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect;
shadow->setBlurRadius(5);
shadow->setXOffset(2);
shadow->setYOffset(2);
shadow->setColor(Qt::gray);
ui->image_1->setGraphicsEffect(shadow);
if (isDarkTheme()) {
ui->image_1->setPixmap(originalImages[0]);
} else {
ui->image_1->setPixmap(invertedImages[0]);
}
applyHoverEffect(ui->image_1);
} else if (obj == ui->image_2) {
ui->image_2->setPixmap(invertedImages[1]);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect;
shadow->setBlurRadius(5);
shadow->setXOffset(2);
shadow->setYOffset(2);
shadow->setColor(Qt::gray);
ui->image_2->setGraphicsEffect(shadow);
if (isDarkTheme()) {
ui->image_2->setPixmap(originalImages[1]);
} else {
ui->image_2->setPixmap(invertedImages[1]);
}
applyHoverEffect(ui->image_2);
} else if (obj == ui->image_3) {
ui->image_3->setPixmap(invertedImages[2]);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect;
shadow->setBlurRadius(5);
shadow->setXOffset(2);
shadow->setYOffset(2);
shadow->setColor(Qt::gray);
ui->image_3->setGraphicsEffect(shadow);
if (isDarkTheme()) {
ui->image_3->setPixmap(originalImages[2]);
} else {
ui->image_3->setPixmap(invertedImages[2]);
}
applyHoverEffect(ui->image_3);
} else if (obj == ui->image_4) {
ui->image_4->setPixmap(invertedImages[3]);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect;
shadow->setBlurRadius(5);
shadow->setXOffset(2);
shadow->setYOffset(2);
shadow->setColor(Qt::gray);
ui->image_4->setGraphicsEffect(shadow);
if (isDarkTheme()) {
ui->image_4->setPixmap(originalImages[3]);
} else {
ui->image_4->setPixmap(invertedImages[3]);
}
applyHoverEffect(ui->image_4);
} else if (obj == ui->image_5) {
if (isDarkTheme()) {
ui->image_5->setPixmap(originalImages[4]);
} else {
ui->image_5->setPixmap(invertedImages[4]);
}
applyHoverEffect(ui->image_5);
}
} else if (event->type() == QEvent::Leave) {
if (obj == ui->image_1) {
ui->image_1->setPixmap(originalImages[0]);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect;
shadow->setBlurRadius(0);
shadow->setXOffset(0);
shadow->setYOffset(0);
shadow->setColor(Qt::gray);
ui->image_1->setGraphicsEffect(shadow);
if (isDarkTheme()) {
ui->image_1->setPixmap(invertedImages[0]);
} else {
ui->image_1->setPixmap(originalImages[0]);
}
removeHoverEffect(ui->image_1);
} else if (obj == ui->image_2) {
ui->image_2->setPixmap(originalImages[1]);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect;
shadow->setBlurRadius(0);
shadow->setXOffset(0);
shadow->setYOffset(0);
shadow->setColor(Qt::gray);
ui->image_2->setGraphicsEffect(shadow);
if (isDarkTheme()) {
ui->image_2->setPixmap(invertedImages[1]);
} else {
ui->image_2->setPixmap(originalImages[1]);
}
removeHoverEffect(ui->image_2);
} else if (obj == ui->image_3) {
ui->image_3->setPixmap(originalImages[2]);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect;
shadow->setBlurRadius(0);
shadow->setXOffset(0);
shadow->setYOffset(0);
shadow->setColor(Qt::gray);
ui->image_3->setGraphicsEffect(shadow);
if (isDarkTheme()) {
ui->image_3->setPixmap(invertedImages[2]);
} else {
ui->image_3->setPixmap(originalImages[2]);
}
removeHoverEffect(ui->image_3);
} else if (obj == ui->image_4) {
ui->image_4->setPixmap(originalImages[3]);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect;
shadow->setBlurRadius(0);
shadow->setXOffset(0);
shadow->setYOffset(0);
shadow->setColor(Qt::gray);
ui->image_4->setGraphicsEffect(shadow);
if (isDarkTheme()) {
ui->image_4->setPixmap(invertedImages[3]);
} else {
ui->image_4->setPixmap(originalImages[3]);
}
removeHoverEffect(ui->image_4);
} else if (obj == ui->image_5) {
if (isDarkTheme()) {
ui->image_5->setPixmap(invertedImages[4]);
} else {
ui->image_5->setPixmap(originalImages[4]);
}
removeHoverEffect(ui->image_5);
}
} else if (event->type() == QEvent::MouseButtonPress) {
if (obj == ui->image_1) {
QDesktopServices::openUrl(QUrl("https://github.com/shadps4-emu/shadPS4"));
} else if (obj == ui->image_2) {
QDesktopServices::openUrl(QUrl("https://discord.gg/bFJxfftGW6"));
} else if (obj == ui->image_3) {
QDesktopServices::openUrl(QUrl("https://ko-fi.com/shadps4"));
} else if (obj == ui->image_4) {
QDesktopServices::openUrl(QUrl("https://www.youtube.com/@shadPS4/videos"));
} else if (obj == ui->image_4) {
QDesktopServices::openUrl(QUrl("https://ko-fi.com/shadps4"));
} else if (obj == ui->image_5) {
QDesktopServices::openUrl(QUrl("https://shadps4.net"));
}
return true;
}
return QDialog::eventFilter(obj, event);
}
void AboutDialog::applyHoverEffect(QLabel* label) {
QColor shadowColor = isDarkTheme() ? QColor(0, 0, 0) : QColor(169, 169, 169);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect;
shadow->setBlurRadius(5);
shadow->setXOffset(2);
shadow->setYOffset(2);
shadow->setColor(shadowColor);
label->setGraphicsEffect(shadow);
}
void AboutDialog::removeHoverEffect(QLabel* label) {
QColor shadowColor = isDarkTheme() ? QColor(50, 50, 50) : QColor(169, 169, 169);
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect;
shadow->setBlurRadius(3);
shadow->setXOffset(0);
shadow->setYOffset(0);
shadow->setColor(shadowColor);
label->setGraphicsEffect(shadow);
}
bool AboutDialog::isDarkTheme() const {
Theme currentTheme = static_cast<Theme>(Config::getMainWindowTheme());
return currentTheme == Theme::Dark || currentTheme == Theme::Green ||
currentTheme == Theme::Blue || currentTheme == Theme::Violet;
}

View File

@ -25,6 +25,12 @@ private:
Ui::AboutDialog* ui;
void preloadImages();
QPixmap originalImages[4];
QPixmap invertedImages[4];
};
void updateImagesForCurrentTheme();
void applyHoverEffect(QLabel* label);
void removeHoverEffect(QLabel* label);
bool isDarkTheme() const;
QPixmap originalImages[5];
QPixmap invertedImages[5];
};

View File

@ -171,7 +171,7 @@
<string/>
</property>
<property name="pixmap">
<pixmap>:/images/ko-fi.png</pixmap>
<pixmap>:/images/youtube.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
@ -196,12 +196,37 @@
<string/>
</property>
<property name="pixmap">
<pixmap>:/images/youtube.png</pixmap>
<pixmap>:/images/ko-fi.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="image_5">
<property name="geometry">
<rect>
<x>670</x>
<y>210</y>
<width>80</width>
<height>80</height>
</rect>
</property>
<property name="cursor">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>:/images/website.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</widget>
<resources/>
<connections/>

View File

@ -29,5 +29,6 @@
<file>images/discord.png</file>
<file>images/ko-fi.png</file>
<file>images/youtube.png</file>
<file>images/website.png</file>
</qresource>
</RCC>