19#include <QApplication>
34inline void initResources()
36 Q_INIT_RESOURCE(pianokeybd);
80#if defined(Q_OS_LINUX)
207class PianoKeybd::PianoKeybdPrivate {
209 PianoKeybdPrivate(): m_rotation(0), m_scene(nullptr), m_rawMap(nullptr)
211 ~PianoKeybdPrivate() =
default;
244 initScene(baseOctave, numKeys, startKey);
252 d->m_scene->setRawKeyboardMode(
false);
265 return d->m_scene->getPianoHandler();
278 d->m_scene->setPianoHandler(handler);
287 return d->m_scene->getHighlightPalette();
298 d->m_scene->setHighlightPalette(p);
307 return d->m_scene->getBackgroundPalette();
316 d->m_scene->setBackgroundPalette(p);
326 return d->m_scene->getForegroundPalette();
336 d->m_scene->setForegroundPalette(p);
345 return d->m_scene->showColorScale();
354 d->m_scene->setShowColorScale(show);
368 d->m_scene->useCustomNoteNames(names);
377 d->m_scene->useStandardNoteNames();
386 return d->m_scene->customNoteNames();
395 return d->m_scene->standardNoteNames();
405 d->m_scene->retranslate();
417 d->m_scene =
new PianoScene(base, num, strt, c,
this);
422 setScene(d->m_scene);
431 setAttribute(Qt::WA_AcceptTouchEvents);
432 setAttribute(Qt::WA_InputMethodEnabled,
false);
433 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
434 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
435 setViewportUpdateMode(MinimalViewportUpdate);
436 setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing|QPainter::SmoothPixmapTransform);
437#if (QT_VERSION < QT_VERSION_CHECK(5,15,0))
438 setOptimizationFlag(DontClipPainter,
true);
440 setOptimizationFlag(DontSavePainterState,
true);
441 setOptimizationFlag(DontAdjustForAntialiasing,
true);
452 QGraphicsView::resizeEvent(event);
453 fitInView(d->m_scene->sceneRect(), Qt::KeepAspectRatio);
464#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
465 static const auto touchScreen = QTouchDevice::DeviceType::TouchScreen;
467 static const auto touchScreen = QInputDevice::DeviceType::TouchScreen;
470 case QEvent::TouchBegin:
471 case QEvent::TouchUpdate:
472 case QEvent::TouchEnd:
473 case QEvent::TouchCancel:
476 QTouchEvent *touchEvent =
static_cast<QTouchEvent*
>(ev);
477 if (
isTouchEnabled() && (touchEvent->device()->type() == touchScreen)) {
478 return d->m_scene->touchScreenEvent(touchEvent);
485 return QGraphicsView::viewportEvent(ev);
502 if ( numKeys != d->m_scene->numKeys() || startKey != d->m_scene->startKey() )
504 QByteArray dataBuffer;
505 int baseOctave = d->m_scene->baseOctave();
506 QColor color = d->m_scene->getKeyPressedColor();
508 KeyboardMap* keyMap = d->m_scene->getKeyboardMap();
509 d->m_scene->saveData(dataBuffer);
511 initScene(baseOctave, numKeys, startKey, color);
512 d->m_scene->loadData(dataBuffer);
513 d->m_scene->setPianoHandler(handler);
514 d->m_scene->setKeyboardMap(keyMap);
515 d->m_scene->hideOrShowKeys();
516 d->m_scene->refreshKeys();
517 d->m_scene->refreshLabels();
518 fitInView(d->m_scene->sceneRect(), Qt::KeepAspectRatio);
528 if (r != d->m_rotation) {
531 rotate(d->m_rotation);
532 fitInView(d->m_scene->sceneRect(), Qt::KeepAspectRatio);
542 return mapFromScene(sceneRect()).boundingRect().size();
548 if (d->m_scene->isKeyboardEnabled() && d->m_rawMap !=
nullptr && d->m_rawMap->contains(keycode)) {
549 d->m_scene->keyOn(d->m_rawMap->value(keycode));
557 if (d->m_scene->isKeyboardEnabled() && d->m_rawMap !=
nullptr && d->m_rawMap->contains(keycode)) {
558 d->m_scene->keyOff(d->m_rawMap->value(keycode));
572 d->m_scene->setKeyPicture(natural, pix);
582 return d->m_scene->getKeyPicture(natural);
591 d->m_scene->setUseKeyPictures(enable);
600 return d->m_scene->getUseKeyPictures();
615 d->m_scene->setUsingNativeFilter( newState );
627 return d->m_scene->isUsingNativeFilter();
643 d->m_scene->setOctaveSubscript( enable );
658 return d->m_scene->octaveSubscript();
682int PianoKeybd::baseOctave()
const
684 return d->m_scene->baseOctave();
693 d->m_scene->setBaseOctave(baseOctave);
701int PianoKeybd::numKeys()
const
703 return d->m_scene->numKeys();
710int PianoKeybd::startKey()
const
712 return d->m_scene->startKey();
721 return d->m_rotation;
730 return d->m_scene->getKeyPressedColor();
741 d->m_scene->setKeyPressedColor(c);
749 d->m_scene->resetKeyPressedColor();
759 return d->m_scene->showLabels();
769 d->m_scene->setShowLabels(show);
779 return d->m_scene->alterations();
789 d->m_scene->setAlterations(use);
799 return d->m_scene->getOrientation();
809 d->m_scene->setOrientation(orientation);
819 return d->m_scene->getOctave();
829 d->m_scene->setOctave(octave);
839 return d->m_scene->getTranspose();
849 d->m_scene->setTranspose(t);
858 return d->m_scene->getChannel();
867 d->m_scene->setChannel(c);
877 return d->m_scene->getVelocity();
887 d->m_scene->setVelocity(v);
896 return d->m_scene->isKeyboardEnabled();
905 d->m_scene->setKeyboardEnabled(enable);
914 return d->m_scene->isMouseEnabled();
923 d->m_scene->setMouseEnabled(enable);
932 return d->m_scene->isTouchEnabled();
941 d->m_scene->setTouchEnabled(enable);
950 return d->m_scene->velocityTint();
960 d->m_scene->setVelocityTint(enable);
968 d->m_scene->allKeysOff();
977 d->m_scene->setKeyboardMap(m);
986 return d->m_scene->getKeyboardMap();
1004 return d->m_scene->getRawKeyboardMode();
1013 d->m_scene->setRawKeyboardMode(b);
1031 d->m_scene->setKeyboardMap(m);
1051 d->m_scene->showNoteOn(note, color, vel);
1061 d->m_scene->showNoteOn(note, vel);
1071 d->m_scene->showNoteOff(note, vel);
1080 QWidget::setFont(font);
1081 d->m_scene->setFont(font);
1082 d->m_scene->refreshLabels();
The QEvent class is the base class of all event classes.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
PianoScene class declaration.