drumstick 2.10.0
C++ MIDI libraries using Qt objects, idioms, and style.
pianokey.h
Go to the documentation of this file.
1/*
2 Virtual Piano Widget for Qt
3 Copyright (C) 2008-2024, 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
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 m_usePixmap(true)
42 { }
43 PianoKey(const QRectF &rect, const bool black, const int note);
44 void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override;
45 int getNote() const { return m_note; }
46 void setBrush(const QBrush& b) { m_brush = b; }
47 void setPressedBrush(const QBrush& b) { m_selectedBrush = b; }
48 void resetBrush();
49 bool isPressed() const { return m_pressed; }
50 void setPressed(bool p);
51 int getDegree() const { return m_note % 12; }
52 int getType() const { return (m_black ? 1 : 0); }
53 bool isBlack() const { return m_black; }
54 const QPixmap& getPixmap() const;
55 void setPixmap(const QPixmap& p);
56 QRectF pixmapRect() const;
57 bool getUsePixmap() const;
58 void setUsePixmap(bool usePixmap);
59 void paintPixmap(QPixmap &pixmap, const QColor& color) const;
60
61 static const PianoPalette keyPalette;
62
63 private:
64 bool m_pressed;
65 QBrush m_selectedBrush;
66 QBrush m_brush;
67 int m_note;
68 bool m_black;
69 QPixmap m_pixmap;
70 bool m_usePixmap;
71 };
72
73}} // namespace drumstick::widgets
74
75#endif /*PIANOKEY_H_*/
Drumstick common.
Definition: alsaclient.cpp:71