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);
44 setFlag(QGraphicsItem::ItemClipsChildrenToShape);
47void PianoKey::paint(QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget *)
49 static const QPen blackPen(Qt::black, 1);
50 painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
52 if (m_selectedBrush.style() != Qt::NoBrush) {
53 painter->setBrush(m_selectedBrush);
55 painter->setBrush(QApplication::palette().highlight());
58 painter->setBrush(m_brush);
60 painter->setPen(blackPen);
61 painter->drawRoundedRect(rect(), 20, 15, Qt::RelativeSize);
63 QPixmap p = getPixmap();
64 painter->drawPixmap(rect(), p, p.rect());
68void PianoKey::setPressed(
bool p)
76const QPixmap& PianoKey::getPixmap()
const
78 static QPixmap blpixmap(QStringLiteral(
":/vpiano/blkey.png"));
79 static QPixmap whpixmap(QStringLiteral(
":/vpiano/whkey.png"));
80 static QColor bgColor;
81 if (!m_black && (bgColor != m_brush.color())) {
82 bgColor = m_brush.color();
83 paintPixmap(whpixmap, QColor::fromRgba(bgColor.rgba()^0xffffff));
85 if (m_pixmap.isNull()) {
86 return m_black ? blpixmap : whpixmap;
92QRectF PianoKey::pixmapRect()
const
94 return getPixmap().rect();
97void PianoKey::resetBrush()
99 m_brush = keyPalette.getColor(m_black ? 1 : 0);
102void PianoKey::setPixmap(
const QPixmap &p)
107bool PianoKey::getUsePixmap()
const
112void PianoKey::setUsePixmap(
bool usePixmap)
114 m_usePixmap = usePixmap;
117void PianoKey::paintPixmap(QPixmap &pixmap,
const QColor& color)
const
119 if (!pixmap.isNull()) {
120 QPainter painter(&pixmap);
121 painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing);
122 painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
123 painter.fillRect(pixmap.rect(), color);
Declaration of the PianoKey class.
Piano Palette declarations.