From af8e61c1244d86141d01696bc56ce99e5af73b21 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sat, 16 Nov 2024 20:38:48 +0800 Subject: [PATCH] UI: add drop shadow to mainwindow labels --- main.cpp | 1 - mainwindow.cpp | 15 +++++++++++++++ mainwindow.h | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 73ac287..c6580a5 100644 --- a/main.cpp +++ b/main.cpp @@ -21,7 +21,6 @@ int main(int argc, char *argv[]) if (translator.load(QLocale(), QLatin1String("pineapple-music"), QLatin1String("_"), QLatin1String(":/i18n"))) { a.installTranslator(&translator); } - a.installTranslator(&translator); // parse commandline arguments QCommandLineParser parser; diff --git a/mainwindow.cpp b/mainwindow.cpp index 90bb15c..09808ac 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -33,6 +33,7 @@ #include #include #include +#include constexpr QSize miniSize(490, 160); constexpr QSize fullSize(490, 420); @@ -61,6 +62,11 @@ MainWindow::MainWindow(QWidget *parent) ui->actionOpen->setShortcut(QKeySequence::Open); addAction(ui->actionOpen); + ui->titleLabel->setGraphicsEffect(createLabelShadowEffect()); + ui->propLabel->setGraphicsEffect(createLabelShadowEffect()); + ui->nowTimeLabel->setGraphicsEffect(createLabelShadowEffect()); + ui->totalTimeLabel->setGraphicsEffect(createLabelShadowEffect()); + setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint); setAttribute(Qt::WA_TranslucentBackground, true); @@ -668,3 +674,12 @@ void MainWindow::on_actionHelp_triggered() infoBox.exec(); } +QGraphicsDropShadowEffect *MainWindow::createLabelShadowEffect() +{ + QGraphicsDropShadowEffect * effect = new QGraphicsDropShadowEffect(this); + effect->setBlurRadius(3); + effect->setColor(QColor(0, 0, 0, 180)); + effect->setOffset(1, 1); + return effect; +} + diff --git a/mainwindow.h b/mainwindow.h index 479a608..3906fbf 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -15,6 +15,7 @@ class QMediaDevices; class QMediaPlayer; class QAudioOutput; class QPropertyAnimation; +class QGraphicsDropShadowEffect; QT_END_NAMESPACE class FFTSpectrum; @@ -83,6 +84,8 @@ signals: void playbackModeChanged(enum PlaybackMode mode); private: + QGraphicsDropShadowEffect * createLabelShadowEffect(); + bool m_clickedOnWindow = false; bool m_playbackSliderPressed = false; QLinearGradient m_bgLinearGradient;