File indexing completed on 2025-01-05 04:25:41
0001 /**************************************************************************************** 0002 * Copyright (c) 2003-2005 Max Howell <max.howell@methylblue.com> * 0003 * Copyright (c) 2005-2013 Mark Kretschmann <kretschmann@kde.org> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Pulic License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #ifndef BLOCKANALYZER_H 0019 #define BLOCKANALYZER_H 0020 0021 #include "AnalyzerBase.h" 0022 0023 #include <QImage> 0024 #include <QPixmap> 0025 #include <QQuickWindow> 0026 #include <QSharedPointer> 0027 #include <QSize> 0028 0029 class QPalette; 0030 0031 class BlockAnalyzer : public Analyzer::Base 0032 { 0033 friend class BlockRenderer; 0034 0035 Q_OBJECT 0036 Q_PROPERTY(FallSpeed fallSpeed READ fallSpeed WRITE setFallSpeed NOTIFY fallSpeedChanged) 0037 Q_PROPERTY(int columnWidth READ columnWidth WRITE setColumnWidth NOTIFY columnWidthChanged) 0038 Q_PROPERTY(bool showFadebars READ showFadebars WRITE setShowFadebars NOTIFY showFadebarsChanged) 0039 0040 public: 0041 enum FallSpeed 0042 { 0043 VerySlow = 0, 0044 Slow = 1, 0045 Medium = 2, 0046 Fast = 3, 0047 VeryFast = 4 0048 }; 0049 Q_ENUM( FallSpeed ) 0050 0051 explicit BlockAnalyzer( QQuickItem *parent = nullptr ); 0052 0053 Renderer* createRenderer() const override; 0054 0055 FallSpeed fallSpeed() const { return m_fallSpeed; } 0056 void setFallSpeed( FallSpeed fallSpeed ); 0057 int columnWidth() const { return m_columnWidth; } 0058 void setColumnWidth( int columnWidth ); 0059 bool showFadebars() const { return m_showFadebars; } 0060 void setShowFadebars( bool showFadebars ); 0061 0062 // Signed ints because most of what we compare them against are ints 0063 static const int BLOCK_HEIGHT = 2; 0064 static const int FADE_SIZE = 90; 0065 0066 Q_SIGNALS: 0067 void fallSpeedChanged(); 0068 void columnWidthChanged(); 0069 void showFadebarsChanged( bool ); 0070 void stepChanged( qreal ); 0071 void rowsChanged( int ); 0072 void columnsChanged( int ); 0073 void refreshRateChanged( qreal ); 0074 0075 protected: 0076 void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) override; 0077 Analyzer::Worker* createWorker() const override; 0078 virtual void paletteChange( const QPalette& ); 0079 0080 void drawBackground( const QPalette &palette ); 0081 void determineStep(); 0082 0083 private: 0084 void newWindow( QQuickWindow *window ); 0085 0086 int m_columns, m_rows; //number of rows and columns of blocks 0087 int m_columnWidth; 0088 bool m_showFadebars; 0089 QPixmap m_barPixmap; 0090 QPixmap m_topBarPixmap; 0091 QPixmap m_backgroundPixmap; 0092 QVector<QPixmap> m_fadeBarsPixmaps; 0093 bool m_pixmapsChanged; 0094 0095 qreal m_step; //rows to fall per frame 0096 FallSpeed m_fallSpeed; 0097 }; 0098 0099 #endif