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 {
34       ChordItem* _event;
35       int _gripType;          // 0 - start grip   1 - end grip
36       ChordView* _view;
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*);
type()46       virtual int type() const    { return GripTypeItem; }
event()47       ChordItem* event() const    { return _event; }
setEvent(ChordItem * e)48       void setEvent(ChordItem* e) { _event = e; }
49       };
50 
51 //---------------------------------------------------------
52 //   ChordItem
53 //---------------------------------------------------------
54 
55 class ChordItem : public QGraphicsRectItem {
56       ChordView* _view;
57       Note*      _note;
58       NoteEvent* _event;
59       bool       _current;
60 
61       virtual void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget* = 0);
62       virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*);
63 
64    public:
65       ChordItem(ChordView*, Note*, NoteEvent*);
type()66       virtual int type() const { return ChordTypeItem; }
event()67       NoteEvent* event() const { return _event; }
note()68       Note* note() const       { return _note;  }
current()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 
80       Chord* chord;
81       Note* _curNote;
82       int _locator;
83       int _pos;
84       QGraphicsLineItem* locatorLine;
85       int ticks;
86       int magStep;
87       GripItem* lg;
88       GripItem* rg;
89       ChordItem* curEvent;
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);
items()119       QList<QGraphicsItem*> items() { return scene()->selectedItems(); }
evenGrid()120       bool evenGrid() const         { return _evenGrid; }
setEvenGrid(bool val)121       void setEvenGrid(bool val)    { _evenGrid = val;  }
rightGrip()122       GripItem* rightGrip() const   { return rg;       }
123       void setCurItem(ChordItem*);
dirty()124       bool dirty() const            { return _dirty; }
setDirty(bool b)125       void setDirty(bool b)         { _dirty = b; }
curNote()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
137