19#include <QApplication>
33const PianoPalette PianoKey::keyPalette(
PAL_KEYS);
35PianoKey::PianoKey(
const QRectF &rect,
const bool black,
const int note)
36 : QGraphicsRectItem(rect),
42 m_brush = keyPalette.getColor(black ? 1 : 0);
43 setAcceptedMouseButtons(Qt::NoButton);
46void PianoKey::paint(QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget *)
48 static const QPen blackPen(Qt::black, 1);
49 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(), 20, 15, Qt::RelativeSize);
62 QPixmap p = getPixmap();
63 painter->drawPixmap(rect(), p, p.rect());
67void PianoKey::setPressed(
bool p)
75const QPixmap& PianoKey::getPixmap()
const
77 static QPixmap blpixmap(QStringLiteral(
":/vpiano/blkey.png"));
78 static QPixmap whpixmap(QStringLiteral(
":/vpiano/whkey.png"));
79 static QColor bgColor;
80 if (!m_black && (bgColor != m_brush.color())) {
81 bgColor = m_brush.color();
82 paintPixmap(whpixmap, QColor::fromRgba(bgColor.rgba()^0xffffff));
84 if (m_pixmap.isNull()) {
85 return m_black ? blpixmap : whpixmap;
91QRectF PianoKey::pixmapRect()
const
93 return getPixmap().rect();
96void PianoKey::resetBrush()
98 m_brush = keyPalette.getColor(m_black ? 1 : 0);
101void PianoKey::setPixmap(
const QPixmap &p)
106bool PianoKey::getUsePixmap()
const
111void PianoKey::setUsePixmap(
bool usePixmap)
113 m_usePixmap = usePixmap;
116void PianoKey::paintPixmap(QPixmap &pixmap,
const QColor& color)
const
118 if (!pixmap.isNull()) {
119 QPainter painter(&pixmap);
120 painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing);
121 painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
122 painter.fillRect(pixmap.rect(), color);
Declaration of the PianoKey class.
Piano Palette declarations.