aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/widgets/rtp_audio_graph.cpp
blob: fe88236c6fe213f83a3434f309f491a3eccb5265 (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
/* rtp_audio_graph.c
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "rtp_audio_graph.h"

#include <glib.h>

#include <epan/prefs.h>
#include <ui/qt/utils/color_utils.h>

static const double wf_graph_normal_width_ = 0.5;

RtpAudioGraph::RtpAudioGraph(QCustomPlot *audio_plot, QRgb color)
{
    QPen p;
    QPalette sel_pal;

    color_ = color;
    wave_ = audio_plot->addGraph();
    p = QPen(wave_->pen());
    p.setColor(color_);
    p.setWidthF(wf_graph_normal_width_);
    wave_->setPen(p);
    wave_->setSelectable(QCP::stNone);
    wave_->removeFromLegend();
    selection_color_ = sel_pal.color(QPalette::Highlight);
}

// Indicate that audio will not be hearable
void RtpAudioGraph::setMuted(bool isMuted)
{
    QPen p = wave_->pen();
    if (isMuted) {
        p.setStyle(Qt::DotLine);
    } else {
        p.setStyle(Qt::SolidLine);
    }
    wave_->setPen(p);
}

void RtpAudioGraph::setHighlight(bool isHighlighted)
{
    wave_->setSelection(isHighlighted ? QCPDataSelection(QCPDataRange()) : QCPDataSelection());
    QPen p = wave_->pen();
    if (isHighlighted) {
        p.setWidthF(wf_graph_normal_width_*2);
    } else {
        p.setWidthF(wf_graph_normal_width_);
    }
    wave_->setPen(p);
}

void RtpAudioGraph::setSelected(bool isSelected)
{
    wave_->setSelection(isSelected ? QCPDataSelection(QCPDataRange()) : QCPDataSelection());
    QPen p = wave_->pen();
    if (isSelected) {
        p.setColor(selection_color_);
    } else {
        p.setColor(color_);
    }
    wave_->setPen(p);
}

void RtpAudioGraph::setData(const QVector<double> &keys, const QVector<double> &values, bool alreadySorted)
{
    wave_->setData(keys, values, alreadySorted);
}

void RtpAudioGraph::remove(QCustomPlot *audioPlot)
{
    audioPlot->removeGraph(wave_);
}

bool RtpAudioGraph::isMyPlottable(QCPAbstractPlottable *plottable)
{
    if (plottable == wave_) {
        return true;
    } else {
        return false;
    }
}