drumstick 2.0.0
pianokey.h
Go to the documentation of this file.
1/*
2 Virtual Piano Widget for Qt5
3 Copyright (C) 2008-2020, Pedro Lopez-Cabanillas <plcl@users.sf.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef PIANOKEY_H_
20#define PIANOKEY_H_
21
22#include <QGraphicsRectItem>
23#include <QBrush>
24
29
30namespace drumstick { namespace widgets {
31
32 class PianoPalette;
33
34 class PianoKey : public QGraphicsRectItem
35 {
36 public:
37 explicit PianoKey(QGraphicsItem * parent = nullptr ): QGraphicsRectItem(parent),
38 m_pressed(false),
39 m_note(0),
40 m_black(false)
41 { }
42 PianoKey(const QRectF &rect, const bool black, const int note);
43 void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override;
44 int getNote() const { return m_note; }
45 void setBrush(const QBrush& b) { m_brush = b; }
46 void setPressedBrush(const QBrush& b) { m_selectedBrush = b; }
47 void resetBrush();
48 bool isPressed() const { return m_pressed; }
49 void setPressed(bool p);
50 int getDegree() const { return m_note % 12; }
51 int getType() const { return (m_black ? 1 : 0); }
52 bool isBlack() const { return m_black; }
53 QPixmap& getPixmap() const;
54 QRectF pixmapRect() const;
55
56 static const PianoPalette keyPalette;
57
58 private:
59 bool m_pressed;
60 QBrush m_selectedBrush;
61 QBrush m_brush;
62 int m_note;
63 bool m_black;
64 };
65
66}} // namespace drumstick::widgets
67
68#endif /*PIANOKEY_H_*/
The PianoPalette class.
Drumstick Widgets library MIDI related widgets and functions.
Drumstick common.