20#include <QApplication>
32const PianoPalette PianoKey::keyPalette(
PAL_KEYS);
34PianoKey::PianoKey(
const QRectF &rect,
const bool black,
const int note)
35 : QGraphicsRectItem(rect),
41 m_brush = keyPalette.getColor(black ? 1 : 0);
42 setAcceptedMouseButtons(Qt::NoButton);
45void PianoKey::paint(QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget *)
47 static const QPen blackPen(Qt::black, 1);
48 painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
50 if (m_selectedBrush.style() != Qt::NoBrush) {
51 painter->setBrush(m_selectedBrush);
53 painter->setBrush(QApplication::palette().highlight());
56 painter->setBrush(m_brush);
58 painter->setPen(blackPen);
59 painter->drawRoundedRect(rect(), 20, 15, Qt::RelativeSize);
61 painter->drawPixmap(rect(), getPixmap(), pixmapRect());
65void PianoKey::setPressed(
bool p)
73const QPixmap& PianoKey::getPixmap()
const
75 static QPixmap blpixmap(QStringLiteral(
":/vpiano/blkey.png"));
76 static QPixmap whpixmap(QStringLiteral(
":/vpiano/whkey.png"));
77 if (m_pixmap.isNull()) {
78 return m_black ? blpixmap : whpixmap;
84QRectF PianoKey::pixmapRect()
const
86 return getPixmap().rect();
89void PianoKey::resetBrush()
91 m_brush = keyPalette.getColor(m_black ? 1 : 0);
94void PianoKey::setPixmap(
const QPixmap &p)
99bool PianoKey::getUsePixmap()
const
104void PianoKey::setUsePixmap(
bool usePixmap)
106 m_usePixmap = usePixmap;
Declaration of the PianoKey class.
Piano Palette declarations.