MidiNoteView.hpp
1 #pragma once
2 #include <Midi/MidiNote.hpp>
3 
4 #include <QGraphicsItem>
5 
6 namespace Midi
7 {
8 class View;
9 class Presenter;
10 class NoteView final : public QGraphicsItem
11 {
12  Q_INTERFACES(QGraphicsItem)
13 public:
14  const Note& note;
15 
16  NoteView(const Note& n, Presenter& presenter, View* parent);
17 
18  void setWidth(qreal w) noexcept
19  {
20  if(m_width != w)
21  {
22  prepareGeometryChange();
23  m_width = w;
24  }
25  }
26 
27  void setHeight(qreal h) noexcept
28  {
29  if(m_height != h)
30  {
31  prepareGeometryChange();
32  m_height = h;
33  }
34  }
35 
36  QRectF boundingRect() const override { return {0, 0, m_width, m_height}; }
37  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
38  override;
39 
40  QRectF computeRect() const noexcept;
41  QPointF closestPos(QPointF note) const noexcept;
42 
43 private:
44  bool canEdit() const;
45  QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
46  void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
47  void hoverMoveEvent(QGraphicsSceneHoverEvent* event) override;
48  void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
49  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
50  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
51  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
52 
53  Presenter& m_presenter;
54 
55  float m_width{};
56  float m_height{};
57 
58  enum Action
59  {
60  None,
61  Move,
62  Scale,
63  ChangeVelocity,
64  Duplicate
65  } m_action{};
66 };
67 }
The Note class.
Definition: MidiNote.hpp:59
Definition: MidiNoteView.hpp:11
Definition: MidiPresenter.hpp:19
Definition: MidiView.hpp:15