PianoView.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * PianoView.h - declaration of PianoView, an interactive piano/keyboard-widget
  3. *
  4. * Copyright (c) 2004-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef PIANO_VIEW_H
  25. #define PIANO_VIEW_H
  26. #include <QPixmap>
  27. #include <QScrollBar>
  28. #include "ModelView.h"
  29. class Piano;
  30. class PianoView : public QWidget, public ModelView
  31. {
  32. Q_OBJECT
  33. public:
  34. PianoView( QWidget * _parent );
  35. virtual ~PianoView() = default;
  36. static int getKeyFromKeyEvent( QKeyEvent * _ke );
  37. public:
  38. void keyPressEvent( QKeyEvent * ke ) override;
  39. void keyReleaseEvent( QKeyEvent * ke ) override;
  40. protected:
  41. void modelChanged() override;
  42. void contextMenuEvent( QContextMenuEvent * _me ) override;
  43. void paintEvent( QPaintEvent * ) override;
  44. void mousePressEvent( QMouseEvent * me ) override;
  45. void mouseReleaseEvent( QMouseEvent * me ) override;
  46. void mouseMoveEvent( QMouseEvent * me ) override;
  47. void focusOutEvent( QFocusEvent * _fe ) override;
  48. void resizeEvent( QResizeEvent * _event ) override;
  49. private:
  50. int getKeyFromMouse( const QPoint & _p ) const;
  51. int getKeyX( int _key_num ) const;
  52. static QPixmap * s_whiteKeyPm;
  53. static QPixmap * s_blackKeyPm;
  54. static QPixmap * s_whiteKeyPressedPm;
  55. static QPixmap * s_blackKeyPressedPm;
  56. Piano * m_piano;
  57. QScrollBar * m_pianoScroll;
  58. int m_startKey; // first key when drawing
  59. int m_lastKey;
  60. private slots:
  61. void pianoScrolled( int _new_pos );
  62. signals:
  63. void keyPressed( int );
  64. void baseNoteChanged();
  65. } ;
  66. #endif