PianoView.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "AutomatableModel.h"
  29. #include "ModelView.h"
  30. class Piano;
  31. class PianoView : public QWidget, public ModelView
  32. {
  33. Q_OBJECT
  34. public:
  35. PianoView( QWidget * _parent );
  36. virtual ~PianoView() = default;
  37. static int getKeyFromKeyEvent( QKeyEvent * _ke );
  38. public:
  39. void keyPressEvent( QKeyEvent * ke ) override;
  40. void keyReleaseEvent( QKeyEvent * ke ) override;
  41. protected:
  42. void modelChanged() override;
  43. void contextMenuEvent( QContextMenuEvent * _me ) override;
  44. void paintEvent( QPaintEvent * ) override;
  45. void mousePressEvent( QMouseEvent * me ) override;
  46. void mouseReleaseEvent( QMouseEvent * me ) override;
  47. void mouseMoveEvent( QMouseEvent * me ) override;
  48. void focusOutEvent( QFocusEvent * _fe ) override;
  49. void focusInEvent( QFocusEvent * fe ) override;
  50. void resizeEvent( QResizeEvent * _event ) override;
  51. private:
  52. int getKeyFromMouse( const QPoint & _p ) const;
  53. int getKeyX( int _key_num ) const;
  54. int getKeyWidth(int key_num) const;
  55. int getKeyHeight(int key_num) const;
  56. IntModel *getNearestMarker(int key, QString* title = nullptr);
  57. static QPixmap * s_whiteKeyPm;
  58. static QPixmap * s_blackKeyPm;
  59. static QPixmap * s_whiteKeyPressedPm;
  60. static QPixmap * s_blackKeyPressedPm;
  61. static QPixmap * s_whiteKeyDisabledPm;
  62. static QPixmap * s_blackKeyDisabledPm;
  63. Piano * m_piano;
  64. QScrollBar * m_pianoScroll;
  65. int m_startKey; //!< first key when drawing
  66. int m_lastKey; //!< previously pressed key
  67. IntModel *m_movedNoteModel; //!< note marker which is being moved
  68. private slots:
  69. void pianoScrolled( int _new_pos );
  70. signals:
  71. void keyPressed( int );
  72. void baseNoteChanged();
  73. } ;
  74. #endif