PianoScene::PianoScene ( const int baseOctave, const int numOctaves, const QColor& keyPressedColor, QObject * parent ) : QGraphicsScene( QRectF(0, 0, KEYWIDTH * numOctaves * 7, KEYHEIGHT), parent ), m_baseOctave( baseOctave ), m_numOctaves( numOctaves ), m_minNote( 0 ), m_maxNote( 127 ), m_transpose( 0 ), m_showLabels( false ), m_useFlats( false ), m_rawkbd( false ), m_keyPressedColor( keyPressedColor ), m_mousePressed( false ), m_velocity( 100 ), m_handler( 0 ) { QBrush hilightBrush(m_keyPressedColor.isValid() ? m_keyPressedColor : QApplication::palette().highlight()); QFont lblFont(QApplication::font()); int i, numkeys = m_numOctaves * 12; lblFont.setPointSize(KEYLABELFONTSIZE); for(i = 0; i < numkeys; ++i) { float x = 0; PianoKey* key = NULL; KeyLabel* lbl = NULL; int octave = i / 12 * 7; int j = i % 12; if (j >= 5) j++; if ((j % 2) == 0) { x = (octave + j / 2) * KEYWIDTH; key = new PianoKey( QRectF(x, 0, KEYWIDTH, KEYHEIGHT), false, i ); lbl = new KeyLabel(key); lbl->setDefaultTextColor(Qt::black); lbl->setPos(x, KEYHEIGHT); } else { x = (octave + j / 2) * KEYWIDTH + KEYWIDTH * 6/10 + 1; key = new PianoKey( QRectF( x, 0, KEYWIDTH * 8/10 - 1, KEYHEIGHT * 6/10 ), true, i ); key->setZValue( 1 ); lbl = new KeyLabel(key); lbl->setDefaultTextColor(Qt::white); lbl->setPos(x - 3, KEYHEIGHT * 6/10 - 3); } if (m_keyPressedColor.isValid()) key->setPressedBrush(hilightBrush); m_keys.insert(i, key); addItem( key ); lbl->setFont(lblFont); m_labels.insert(i, lbl); } hideOrShowKeys(); retranslate(); }
PianoScene::PianoScene ( const int baseOctave, const int numKeys, const int startKey, const QColor& keyPressedColor, QObject * parent ) : QGraphicsScene( QRectF(0, 0, sceneWidth(numKeys), KEYHEIGHT), parent ), m_baseOctave( baseOctave ), m_numKeys( numKeys ), m_startKey( startKey ), m_minNote( 0 ), m_maxNote( 127 ), m_transpose( 0 ), m_showLabels( false ), m_useFlats( false ), m_rawkbd( false ), m_keyboardEnabled( true ), m_mouseEnabled( true ), m_touchEnabled( true ), m_keyPressedColor( keyPressedColor ), m_mousePressed( false ), m_velocity( 100 ), m_channel( 0 ), m_velocityTint( true ), m_handler( 0 ) #if defined(PALETTE_SUPPORT) ,m_showColorScale( false ) ,m_palette( 0 ) ,m_scalePalette( 0 ) #endif { QBrush hilightBrush(m_keyPressedColor.isValid() ? m_keyPressedColor : QApplication::palette().highlight()); QFont lblFont(QApplication::font()); lblFont.setPointSize(KEYLABELFONTSIZE); int upperLimit = m_numKeys + m_startKey; int adj = m_startKey % 12; if (adj >= 5) adj++; for(int i = m_startKey; i < upperLimit; ++i) { float x = 0; PianoKey* key = NULL; KeyLabel* lbl = NULL; int ocs = i / 12 * 7; int j = i % 12; if (j >= 5) j++; if ((j % 2) == 0) { x = (ocs + qFloor((j-adj) / 2.0)) * KEYWIDTH; key = new PianoKey( QRectF(x, 0, KEYWIDTH, KEYHEIGHT), false, i ); lbl = new KeyLabel(key); lbl->setDefaultTextColor(Qt::black); lbl->setPos(x, KEYHEIGHT); } else { x = (ocs + qFloor((j-adj) / 2.0)) * KEYWIDTH + KEYWIDTH * 6/10 + 1; key = new PianoKey( QRectF( x, 0, KEYWIDTH * 8/10 - 1, KEYHEIGHT * 6/10 ), true, i ); key->setZValue( 1 ); lbl = new KeyLabel(key); lbl->setDefaultTextColor(Qt::white); lbl->setPos(x - 3, KEYHEIGHT * 6/10 - 3); } //qDebug() << "i=" << i << "ocs=" << ocs << "j=" << j << "x=" << x; key->setAcceptTouchEvents(true); if (m_keyPressedColor.isValid()) key->setPressedBrush(hilightBrush); m_keys.insert(i, key); addItem( key ); lbl->setFont(lblFont); m_labels.insert(i, lbl); } hideOrShowKeys(); retranslate(); }