memoserv/src/qt/widgets/block_grid.hpp
King_DuckZ 0d287a60f1 Draw blank squares for empty blocks in the grid.
Import vectorwrapper, it's just too convenient. It's only used
in one place for now but I will probably use it more from now on.
2020-03-28 21:33:46 +01:00

62 lines
1.6 KiB
C++

/* Copyright 2020, Michele Santullo
* This file is part of memoserv.
*
* Memoserv is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Memoserv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Memoserv. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "../animated_pixmap.hpp"
#include <QWidget>
#include <QPixmap>
#include <memory>
#include <vector>
class QTimer;
namespace duck::widget {
class BlockGrid : public QWidget {
Q_OBJECT
public:
explicit BlockGrid (QWidget* parent=nullptr, unsigned int rows=0, unsigned int columns=0, float fps=24.0f);
~BlockGrid() noexcept;
QSize minimumSizeHint() const override;
QSize sizeHint() const override;
void set_icon_size (const QSize& sz);
void set_icon_size (int sz);
QSize icon_size() const;
void push_back (AnimatedPixmap&& anim);
std::size_t size() const;
protected:
void paintEvent (QPaintEvent* event) override;
private slots:
void advance_frame();
private:
unsigned int rows() const;
unsigned int columns() const;
std::vector<AnimatedPixmap> m_icons;
QTimer* m_anim_timer;
std::unique_ptr<QPixmap> m_empty_icon;
QSize m_icon_size;
unsigned int m_rows;
unsigned int m_columns;
};
} //namespace duck::widget