20 #include <QApplication> 32 const PianoPalette PianoKey::keyPalette(
PAL_KEYS);
34 PianoKey::PianoKey(
const QRectF &rect,
const bool black,
const int note)
35 : QGraphicsRectItem(rect),
40 m_brush = keyPalette.getColor(black ? 1 : 0);
41 setAcceptedMouseButtons(Qt::NoButton);
44 void PianoKey::paint(QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget *)
46 static const QPen blackPen(Qt::black, 1);
47 static const QPen grayPen(QBrush(Qt::gray), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
48 painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
51 if (m_selectedBrush.style() != Qt::NoBrush) {
52 painter->setBrush(m_selectedBrush);
54 painter->setBrush(QApplication::palette().highlight());
57 painter->setBrush(m_brush);
59 painter->setPen(blackPen);
60 painter->drawRoundedRect(rect(), 15, 15, Qt::RelativeSize);
62 painter->drawPixmap(rect(), getPixmap(), pixmapRect());
65 QPointF(rect().left()+1.5, rect().bottom()-1),
66 QPointF(rect().right()-1, rect().bottom()-1),
67 QPointF(rect().right()-1, rect().top()+1),
69 painter->setPen(grayPen);
70 painter->drawPolyline(points, 3);
74 void PianoKey::setPressed(
bool p)
82 QPixmap& PianoKey::getPixmap()
const 84 static QPixmap pixmap(QStringLiteral(
":/vpiano/blkey.png"));
88 QRectF PianoKey::pixmapRect()
const 90 return getPixmap().rect();
93 void PianoKey::resetBrush()
95 m_brush = keyPalette.getColor(m_black ? 1 : 0);
Declaration of the PianoKey class.
Piano Palette declarations.