summaryrefslogtreecommitdiffstats
path: root/src/waveform/renderers/waveformmark.h
blob: ab11862df18aa925a4987d33258de56e8a898d52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef WAVEFORMMARK_H
#define WAVEFORMMARK_H

#include <QDomNode>
#include <QImage>

#include "waveform/waveformmarklabel.h"
#include "control/controlproxy.h"
#include "util/memory.h"

#include "control/controlobject.h"

class SkinContext;
class WaveformSignalColors;

class WOverview;

class WaveformMark {
  public:
    static const int kNoHotCue = -1;
    WaveformMark(
            const QString& group,
            const QDomNode& node,
            const SkinContext& context,
            const WaveformSignalColors& signalColors,
            int hotCue = kNoHotCue);

    // Disable copying
    WaveformMark(const WaveformMark&) = delete;
    WaveformMark& operator=(const WaveformMark&) = delete;

    int getHotCue() const { return m_iHotCue; };

    //The m_pPointCos related function
    bool isValid() const { return m_pPointCos && m_pPointCos->valid(); }

    template <typename Receiver, typename Slot>
    void connectSamplePositionChanged(Receiver receiver, Slot slot) const {
        m_pPointCos->connectValueChanged(receiver, slot, Qt::AutoConnection);
    };
    double getSamplePosition() const { return m_pPointCos->get(); }
    QString getItem() const { return m_pPointCos->getKey().item; }

    // The m_pVisibleCos related function
    bool hasVisible() const { return m_pVisibleCos && m_pVisibleCos->valid(); }
    bool isVisible() const {
        if (!hasVisible()) {
            return true;
        }
        return m_pVisibleCos->get();
    }

    template <typename Receiver, typename Slot>
    void connectVisibleChanged(Receiver receiver, Slot slot) const {
        m_pVisibleCos->connectValueChanged(receiver, slot, Qt::AutoConnection);
    }

    // Sets the appropriate mark colors based on the base color
    void setBaseColor(QColor baseColor);
    QColor fillColor() const {
        return m_fillColor;
    }
    QColor borderColor() const {
        return m_borderColor;
    }
    QColor labelColor() const {
        return m_labelColor;
    }

    QColor m_textColor;
    QString m_text;
    Qt::Alignment m_align;
    QString m_pixmapPath;

    float m_linePosition;

    WaveformMarkLabel m_label;

  private:
    std::unique_ptr<ControlProxy> m_pPointCos;
    std::unique_ptr<ControlProxy> m_pVisibleCos;
    int m_iHotCue;
    QImage m_image;

    QColor m_fillColor;
    QColor m_borderColor;
    QColor m_labelColor;

    friend class WaveformRenderMark;
};

typedef QSharedPointer<WaveformMark> WaveformMarkPointer;

inline bool operator<(const WaveformMarkPointer& lhs, const WaveformMarkPointer& rhs) {
    double leftPosition = lhs->getSamplePosition();
    int leftHotcue = lhs->getHotCue();
    double rightPosition = rhs->getSamplePosition();
    int rightHotcue = rhs->getHotCue();
    if (leftPosition == rightPosition) {
        // Sort WaveformMarks without hotcues before those with hotcues;
        // if both have hotcues, sort numerically by hotcue number.
        if (leftHotcue == WaveformMark::kNoHotCue && rightHotcue != WaveformMark::kNoHotCue) {
            return true;
        } else if (leftHotcue != WaveformMark::kNoHotCue && rightHotcue == WaveformMark::kNoHotCue) {
            return false;
        } else {
            return leftHotcue < rightHotcue;
        }
    }
    return leftPosition < rightPosition;
}

#endif // WAVEFORMMARK_H