File indexing completed on 2026-07-12 13:30:35
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Han Young <hanyoung@protonmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #pragma once 0007 0008 #include <QOpenGLFunctions> 0009 #include <QtQuick/QQuickFramebufferObject> 0010 0011 class BackgroundRenderer; 0012 0013 class WeatherBackgroundRenderer : public QQuickFramebufferObject 0014 { 0015 Q_OBJECT 0016 QML_NAMED_ELEMENT(WeatherBackground) 0017 Q_PROPERTY(bool rain READ rain WRITE setRain NOTIFY rainChanged) 0018 Q_PROPERTY(bool cloud READ cloud WRITE setCloud NOTIFY cloudChanged) 0019 Q_PROPERTY(bool sun READ sun WRITE setSun NOTIFY sunChanged) 0020 Q_PROPERTY(bool star READ star WRITE setStar NOTIFY starChanged) 0021 Q_PROPERTY(bool snow READ snow WRITE setSnow NOTIFY snowChanged) 0022 Q_PROPERTY(QColor colorTop READ colorTop WRITE setColorTop NOTIFY colorTopChanged) 0023 Q_PROPERTY(QColor colorBottom READ colorBottom WRITE setColorBottom NOTIFY colorBottomChanged) 0024 Q_PROPERTY(QColor cloudColor READ cloudColor WRITE setCloudColor NOTIFY cloudColorChanged) 0025 public: 0026 WeatherBackgroundRenderer(QQuickItem *parent = nullptr); 0027 Renderer *createRenderer() const override; 0028 bool rain() const; 0029 bool cloud() const; 0030 bool sun() const; 0031 bool star() const; 0032 bool snow() const; 0033 QColor colorTop() const; 0034 QColor colorBottom() const; 0035 QColor cloudColor() const; 0036 0037 void setRain(bool); 0038 void setCloud(bool); 0039 void setSun(bool); 0040 void setStar(bool); 0041 void setSnow(bool); 0042 void setColorTop(const QColor &); 0043 void setColorBottom(const QColor &); 0044 void setCloudColor(const QColor &); 0045 0046 Q_SIGNALS: 0047 void rainChanged(); 0048 void cloudChanged(); 0049 void sunChanged(); 0050 void starChanged(); 0051 void snowChanged(); 0052 void colorTopChanged(); 0053 void colorBottomChanged(); 0054 void cloudColorChanged(); 0055 0056 private Q_SLOTS: 0057 void handleTimeout(); 0058 0059 protected: 0060 friend class WeatherBackgroundContentRenderer; 0061 int minFPS = 60; 0062 int modifiedMinFPS = 60; 0063 0064 private: 0065 QTimer *m_timer = nullptr; 0066 bool m_rain = false; 0067 bool m_cloud = false; 0068 bool m_sun = false; 0069 bool m_star = false; 0070 bool m_snow = false; 0071 0072 QColor m_colourTop; 0073 QColor m_colourBottom; 0074 QColor m_cloudColor; 0075 }; 0076 0077 class CloudsRenderer; 0078 class RainRenderer; 0079 class SunRenderer; 0080 class StarsRendererBase; 0081 class SnowRendererBase; 0082 class WeatherBackgroundContentRenderer : public QQuickFramebufferObject::Renderer, QOpenGLFunctions 0083 { 0084 public: 0085 void render() override; 0086 void synchronize(QQuickFramebufferObject *item) override; 0087 QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) override; 0088 0089 protected: 0090 friend class WeatherBackgroundRenderer; 0091 WeatherBackgroundContentRenderer(); 0092 WeatherBackgroundContentRenderer(const WeatherBackgroundContentRenderer &other) = delete; 0093 WeatherBackgroundContentRenderer(WeatherBackgroundContentRenderer &&other) = delete; 0094 WeatherBackgroundContentRenderer operator=(const WeatherBackgroundContentRenderer &other) = delete; 0095 0096 private: 0097 CloudsRenderer *m_clouds = nullptr; 0098 RainRenderer *m_rain = nullptr; 0099 std::function<float()> dice; 0100 BackgroundRenderer *background; 0101 SunRenderer *m_sun = nullptr; 0102 StarsRendererBase *m_stars = nullptr; 0103 SnowRendererBase *m_snow = nullptr; 0104 0105 float aspectRatio = 1; 0106 int m_minFPS = 60; 0107 bool synchronized = false; 0108 0109 bool m_showRain = false; 0110 bool m_showCloud = false; 0111 bool m_showSun = false; 0112 bool m_showStar = false; 0113 bool m_showSnow = false; 0114 QColor m_colourTop; 0115 QColor m_colourBottom; 0116 QColor m_cloudColor; 0117 bool m_legacyMode = false; 0118 };