MuseScore  3.4
Music composition and notation
chordview.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2012 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __CHORDVIEW_H__
14 #define __CHORDVIEW_H__
15 
16 #include "libmscore/pos.h"
17 
18 namespace Ms {
19 
20 class Staff;
21 class Chord;
22 class Note;
23 class NoteEvent;
24 class ChordItem;
25 class ChordView;
26 
27 enum { GripTypeItem = QGraphicsItem::UserType, ChordTypeItem };
28 
29 //---------------------------------------------------------
30 // GripItem
31 //---------------------------------------------------------
32 
33 class GripItem : public QGraphicsRectItem {
35  int _gripType; // 0 - start grip 1 - end grip
37 
38 
39  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
40 
41  protected:
42  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*);
43 
44  public:
45  GripItem(int gripType, ChordView*);
46  virtual int type() const { return GripTypeItem; }
47  ChordItem* event() const { return _event; }
48  void setEvent(ChordItem* e) { _event = e; }
49  };
50 
51 //---------------------------------------------------------
52 // ChordItem
53 //---------------------------------------------------------
54 
55 class ChordItem : public QGraphicsRectItem {
59  bool _current;
60 
61  virtual void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget* = 0);
62  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*);
63 
64  public:
66  virtual int type() const { return ChordTypeItem; }
67  NoteEvent* event() const { return _event; }
68  Note* note() const { return _note; }
69  bool current() const { return _current; }
70  void setCurrent(bool v);
71  };
72 
73 //---------------------------------------------------------
74 // ChordView
75 //---------------------------------------------------------
76 
77 class ChordView : public QGraphicsView {
78  Q_OBJECT
79 
82  int _locator;
83  int _pos;
84  QGraphicsLineItem* locatorLine;
85  int ticks;
86  int magStep;
90 
91  bool _evenGrid;
92  bool _dirty;
93 
94  virtual void drawBackground(QPainter*, const QRectF& rect);
95 
96  protected:
97  virtual void wheelEvent(QWheelEvent*);
98  virtual void mouseMoveEvent(QMouseEvent*);
99  virtual void leaveEvent(QEvent*);
100  virtual void mousePressEvent(QMouseEvent*);
101 
102  signals:
103  void magChanged(double, double);
104  void xposChanged(int);
105  void pitchChanged(int);
106  void posChanged(int);
107 
108  protected slots:
109  void deleteItem();
110 
111  public slots:
112  void moveLocator();
113  void selectionChanged();
114 
115  public:
116  ChordView();
117  void setChord(Chord*);
118  void ensureVisible(int tick);
119  QList<QGraphicsItem*> items() { return scene()->selectedItems(); }
120  bool evenGrid() const { return _evenGrid; }
121  void setEvenGrid(bool val) { _evenGrid = val; }
122  GripItem* rightGrip() const { return rg; }
123  void setCurItem(ChordItem*);
124  bool dirty() const { return _dirty; }
125  void setDirty(bool b) { _dirty = b; }
126  Note* curNote() const { return _curNote; }
127 
128  static int pos2pix(int pos);
129  static int pix2pos(int pix);
130  static int y2pitch(int pix);
131  static int pitch2y(int pitch);
132  };
133 
134 
135 } // namespace Ms
136 #endif
Definition: chordview.h:77
Definition: chordview.h:55
virtual int type() const
Definition: chordview.h:46
NoteEvent * event() const
Definition: chordview.h:67
Definition: noteevent.h:25
int _pos
Definition: chordview.h:83
GripItem * rg
Definition: chordview.h:88
int y2pitch(qreal y, ClefType clef, qreal _spatium)
Definition: utils.cpp:404
bool _current
Definition: chordview.h:59
Definition: chordview.h:27
QList< QGraphicsItem * > items()
Definition: chordview.h:119
GripItem * rightGrip() const
Definition: chordview.h:122
Note * note() const
Definition: chordview.h:68
ChordView * _view
Definition: chordview.h:56
void setDirty(bool b)
Definition: chordview.h:125
Definition: chordview.h:33
bool current() const
Definition: chordview.h:69
bool dirty() const
Definition: chordview.h:124
void setEvent(ChordItem *e)
Definition: chordview.h:48
void setEvenGrid(bool val)
Definition: chordview.h:121
Definition: aeolus.cpp:26
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Definition: chordview.cpp:48
bool _dirty
Definition: chordview.h:92
ChordView * _view
Definition: chordview.h:36
GripItem(int gripType, ChordView *)
Definition: chordview.cpp:32
GripItem * lg
Definition: chordview.h:87
Graphic representation of a chord.
Definition: chord.h:55
int _locator
Definition: chordview.h:82
ChordItem * _event
Definition: chordview.h:34
int pitch2y(int pitch, int enh, int clefOffset, int key, int &prefix, const char *tversatz)
Note * curNote() const
Definition: chordview.h:126
int magStep
Definition: chordview.h:86
NoteEvent * _event
Definition: chordview.h:58
Graphic representation of a note.
Definition: note.h:212
int _gripType
Definition: chordview.h:35
ChordItem * curEvent
Definition: chordview.h:89
virtual int type() const
Definition: chordview.h:66
int ticks
Definition: chordview.h:85
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *)
Definition: chordview.cpp:61
bool _evenGrid
Definition: chordview.h:91
ChordItem * event() const
Definition: chordview.h:47
Note * _curNote
Definition: chordview.h:81
bool evenGrid() const
Definition: chordview.h:120
Definition: chordview.h:27
Note * _note
Definition: chordview.h:57
Chord * chord
Definition: chordview.h:80
QGraphicsLineItem * locatorLine
Definition: chordview.h:84