1 
2 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
3 
4 /*
5     Rosegarden
6     A MIDI and audio sequencer and musical notation editor.
7     Copyright 2000-2021 the Rosegarden development team.
8 
9     Other copyrights also apply to some parts of this work.  Please
10     see the AUTHORS file and individual file headers for details.
11 
12     This program is free software; you can redistribute it and/or
13     modify it under the terms of the GNU General Public License as
14     published by the Free Software Foundation; either version 2 of the
15     License, or (at your option) any later version.  See the file
16     COPYING included with this distribution for more information.
17 */
18 
19 #ifndef RG_CHORDNAMERULER_H
20 #define RG_CHORDNAMERULER_H
21 
22 #include "base/PropertyName.h"
23 #include <map>
24 #include <QFont>
25 #include <QFontMetrics>
26 #include <QSize>
27 #include <QWidget>
28 #include <vector>
29 #include "base/Event.h"
30 
31 
32 class QPaintEvent;
33 
34 
35 namespace Rosegarden
36 {
37 
38 class Studio;
39 class Segment;
40 class RulerScale;
41 class RosegardenDocument;
42 class Composition;
43 
44 
45 /**
46  * ChordNameRuler is a widget that shows a strip of text strings
47  * describing the chords in a composition.
48  */
49 
50 class ChordNameRuler : public QWidget
51 {
52     Q_OBJECT
53 
54 public:
55     /**
56      * Construct a ChordNameRuler that displays the chords in the
57      * given Composition at positions calculated by the given
58      * RulerScale.  Be aware that it will not be refreshed until
59      * setReady is called (because the first refresh is expensive).
60      */
61     ChordNameRuler(RulerScale *rulerScale,
62                    RosegardenDocument *doc,
63                    int height = 0,
64                    QWidget* parent = nullptr);
65 
66     /**
67      * Construct a ChordNameRuler that displays the chords in the
68      * given Segments at positions calculated by the given
69      * RulerScale.  Be aware that it will not be refreshed until
70      * setReady is called (because the first refresh is expensive).
71      */
72     ChordNameRuler(RulerScale *rulerScale,
73                    RosegardenDocument *doc,
74                    std::vector<Segment *> &segments,
75                    int height = 0,
76                    QWidget* parent = nullptr);
77 
78     ~ChordNameRuler() override;
79 
80     /// Indicate that the chord-name ruler should make itself ready and refresh
81     void setReady();
82 
83     // may have one of these; can be changed at any time (to any in given composition):
84     void setCurrentSegment(Segment *segment);
85 
86     // may have one of these (to avoid using percussion tracks in chords):
87     void setStudio(Studio *studio);
88 
89     QSize sizeHint() const override;
90     QSize minimumSizeHint() const override;
91 
setMinimumWidth(int width)92     void setMinimumWidth(int width) { m_width = width; }
93 
94 public slots:
95     void slotScrollHoriz(int x);
96 
97 protected:
98     void paintEvent(QPaintEvent *) override;
99 
100 private:
101     void recalculate(timeT from = 0,
102                      timeT to = 0);
103 
104     int    m_height;
105     int    m_currentXOffset;
106     int    m_width;
107     bool   m_ready;
108 
109     RulerScale  *m_rulerScale;
110 
111     Composition *m_composition;
112     unsigned int m_compositionRefreshStatusId;
113 
114     typedef std::map<Segment *, int> SegmentRefreshMap;
115     SegmentRefreshMap m_segments; // map to refresh status id
116     bool m_regetSegmentsOnChange;
117 
118     Segment *m_currentSegment;
119     Studio *m_studio;
120 
121     Segment *m_chordSegment;
122 
123     QFont m_font;
124     QFont m_boldFont;
125     QFontMetrics m_fontMetrics;
126 
127     const PropertyName TEXT_FORMAL_X;
128     const PropertyName TEXT_ACTUAL_X;
129 };
130 
131 
132 }
133 
134 #endif
135