AcrylicLabel.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef ACRYLICLABEL_H
  2. #define ACRYLICLABEL_H
  3. #include <QThread>
  4. #include <QLabel>
  5. class BlurCoverThread : public QThread
  6. {
  7. Q_OBJECT
  8. public:
  9. BlurCoverThread(QObject *parent = nullptr);
  10. void blur(const QString &imagePath, int blurRadius = 6, const QSize &maxSize = QSize(450, 450));
  11. // QThread interface
  12. protected:
  13. void run() override;
  14. signals:
  15. void blurFinished(const QPixmap &pix);
  16. private:
  17. QString m_imagePath;
  18. int m_blurRadius;
  19. QSize m_maxSize;
  20. };
  21. class AcrylicTextureLabel : public QLabel
  22. {
  23. Q_OBJECT
  24. public:
  25. AcrylicTextureLabel(const QColor &tintColor, const QColor &luminosityColor, double noiseOpacity = 0.03,
  26. QWidget *parent = nullptr);
  27. void setTintColor(const QColor &color);
  28. // QWidget interface
  29. protected:
  30. void paintEvent(QPaintEvent *event) override;
  31. private:
  32. QColor m_tintColor;
  33. QColor m_luminosityColor;
  34. double m_noiseOpacity;
  35. QImage m_noiseImage;
  36. };
  37. class AcrylicLabel : public QLabel
  38. {
  39. Q_OBJECT
  40. public:
  41. explicit AcrylicLabel(int blurRadius, const QColor &tintColor,
  42. const QColor &luminosityColor = QColor(255, 255, 255, 0), const QSize &maxBlurSize = QSize(),
  43. QWidget *parent = nullptr);
  44. void setImage(const QString &imagePath);
  45. void setTintColor(const QColor &color);
  46. void setBlurRadius(int blurRadius);
  47. void setMaxBlurSize(const QSize &maxBlurSize);
  48. private slots:
  49. void onBlurFinished(const QPixmap &pixmap);
  50. // QWidget interface
  51. protected:
  52. void resizeEvent(QResizeEvent *event) override;
  53. signals:
  54. private:
  55. QString m_imagePath;
  56. int m_blurRadius;
  57. QSize m_maxBlurSize;
  58. QPixmap m_blurPixmap;
  59. AcrylicTextureLabel *m_acrylicTextureLabel;
  60. BlurCoverThread *m_blurThread;
  61. };
  62. #endif // ACRYLICLABEL_H