File indexing completed on 2024-05-12 04:50:07

0001 /*
0002     SPDX-FileCopyrightText: 2003-2005 Max Howell <max.howell@methylblue.com>                       *
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef BLOCKANALYZER_H
0008 #define BLOCKANALYZER_H
0009 
0010 #include "analyzerBase.h"
0011 
0012 #include <QColor>
0013 #include <QContextMenuEvent>
0014 #include <QMouseEvent>
0015 #include <QPixmap>
0016 #include <QResizeEvent>
0017 
0018 class QPalette;
0019 
0020 /**
0021  * @author Max Howell
0022  */
0023 
0024 class BlockAnalyzer : public Analyzer::Base2D
0025 {
0026 public:
0027     explicit BlockAnalyzer(QWidget *);
0028     ~BlockAnalyzer() override;
0029 
0030     // Signed ints because most of what we compare them against are ints
0031     static const int HEIGHT = 2;
0032     static const int WIDTH = 4;
0033     static const int MIN_ROWS = 48; // arbitrary
0034     static const int MIN_COLUMNS = 128; // arbitrary
0035     static const int MAX_COLUMNS = 128; // must be 2**n
0036     static const int FADE_SIZE = 90;
0037 
0038 protected:
0039     void transform(QVector<float> &) override;
0040     void analyze(const QVector<float> &) override;
0041     void paintEvent(QPaintEvent *) override;
0042     void resizeEvent(QResizeEvent *) override;
0043     void paletteChange(const QPalette &);
0044 
0045     void drawBackground();
0046     void determineStep();
0047 
0048 private:
0049     QPixmap *bar()
0050     {
0051         return &m_barPixmap;
0052     }
0053 
0054     uint m_columns, m_rows; // number of rows and columns of blocks
0055     uint m_y; // y-offset from top of widget
0056     QPixmap m_barPixmap;
0057     QPixmap m_topBarPixmap;
0058     QVector<float> m_scope; // so we don't create a vector every frame
0059     std::vector<float> m_store; // current bar heights
0060     std::vector<float> m_yscale;
0061 
0062     // FIXME why can't I namespace these? c++ issue?
0063     std::vector<QPixmap> m_fade_bars;
0064     std::vector<uint> m_fade_pos;
0065     std::vector<int> m_fade_intensity;
0066     QPixmap m_background;
0067 
0068     float m_step; // rows to fall per frame
0069 };
0070 
0071 #endif