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

View File

@ -171,7 +171,7 @@
<string/> <string/>
</property> </property>
<property name="pixmap"> <property name="pixmap">
<pixmap>:/images/ko-fi.png</pixmap> <pixmap>:/images/youtube.png</pixmap>
</property> </property>
<property name="scaledContents"> <property name="scaledContents">
<bool>true</bool> <bool>true</bool>
@ -196,12 +196,37 @@
<string/> <string/>
</property> </property>
<property name="pixmap"> <property name="pixmap">
<pixmap>:/images/youtube.png</pixmap> <pixmap>:/images/ko-fi.png</pixmap>
</property> </property>
<property name="scaledContents"> <property name="scaledContents">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </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> </widget>
<resources/> <resources/>
<connections/> <connections/>

View File

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