1 /**************************************************************************************** 2 * Copyright (c) 2003-2005 Max Howell <max.howell@methylblue.com> * 3 * Copyright (c) 2005-2013 Mark Kretschmann <kretschmann@kde.org> * 4 * * 5 * This program is free software; you can redistribute it and/or modify it under * 6 * the terms of the GNU General Public License as published by the Free Software * 7 * Foundation; either version 2 of the License, or (at your option) any later * 8 * version. * 9 * * 10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 12 * PARTICULAR PURPOSE. See the GNU General Pulic License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License along with * 15 * this program. If not, see <http://www.gnu.org/licenses/>. * 16 ****************************************************************************************/ 17 18 #ifndef BLOCKANALYZER_H 19 #define BLOCKANALYZER_H 20 21 #include "AnalyzerBase.h" 22 23 #include <QImage> 24 #include <QPixmap> 25 #include <QQuickWindow> 26 #include <QSharedPointer> 27 #include <QSize> 28 29 class QPalette; 30 31 class BlockAnalyzer : public Analyzer::Base 32 { 33 friend class BlockRenderer; 34 35 Q_OBJECT 36 Q_PROPERTY(FallSpeed fallSpeed READ fallSpeed WRITE setFallSpeed NOTIFY fallSpeedChanged) 37 Q_PROPERTY(int columnWidth READ columnWidth WRITE setColumnWidth NOTIFY columnWidthChanged) 38 Q_PROPERTY(bool showFadebars READ showFadebars WRITE setShowFadebars NOTIFY showFadebarsChanged) 39 40 public: 41 enum FallSpeed 42 { 43 VerySlow = 0, 44 Slow = 1, 45 Medium = 2, 46 Fast = 3, 47 VeryFast = 4 48 }; 49 Q_ENUM( FallSpeed ) 50 51 explicit BlockAnalyzer( QQuickItem *parent = nullptr ); 52 53 Renderer* createRenderer() const override; 54 fallSpeed()55 FallSpeed fallSpeed() const { return m_fallSpeed; } 56 void setFallSpeed( FallSpeed fallSpeed ); columnWidth()57 int columnWidth() const { return m_columnWidth; } 58 void setColumnWidth( int columnWidth ); showFadebars()59 bool showFadebars() const { return m_showFadebars; } 60 void setShowFadebars( bool showFadebars ); 61 62 // Signed ints because most of what we compare them against are ints 63 static const int BLOCK_HEIGHT = 2; 64 static const int FADE_SIZE = 90; 65 66 Q_SIGNALS: 67 void fallSpeedChanged(); 68 void columnWidthChanged(); 69 void showFadebarsChanged( bool ); 70 void stepChanged( qreal ); 71 void rowsChanged( int ); 72 void columnsChanged( int ); 73 void refreshRateChanged( qreal ); 74 75 protected: 76 void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) override; 77 Analyzer::Worker* createWorker() const override; 78 virtual void paletteChange( const QPalette& ); 79 80 void drawBackground( const QPalette &palette ); 81 void determineStep(); 82 83 private: 84 void newWindow( QQuickWindow *window ); 85 86 int m_columns, m_rows; //number of rows and columns of blocks 87 int m_columnWidth; 88 bool m_showFadebars; 89 QPixmap m_barPixmap; 90 QPixmap m_topBarPixmap; 91 QPixmap m_backgroundPixmap; 92 QVector<QPixmap> m_fadeBarsPixmaps; 93 bool m_pixmapsChanged; 94 95 qreal m_step; //rows to fall per frame 96 FallSpeed m_fallSpeed; 97 }; 98 99 #endif 100