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),
41 m_brush = keyPalette.getColor(black ? 1 : 0);
42 setAcceptedMouseButtons(Qt::NoButton);
45 void 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());
65 void PianoKey::setPressed(
bool p)
73 const 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;
84 QRectF PianoKey::pixmapRect()
const
86 return getPixmap().rect();
89 void PianoKey::resetBrush()
91 m_brush = keyPalette.getColor(m_black ? 1 : 0);
94 void PianoKey::setPixmap(
const QPixmap &p)
99 bool PianoKey::getUsePixmap()
const
104 void PianoKey::setUsePixmap(
bool usePixmap)
106 m_usePixmap = usePixmap;
Declaration of the PianoKey class.
Piano Palette declarations.