1 /* rtp_audio_graph.c
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #include "rtp_audio_graph.h"
11 
12 #include <glib.h>
13 
14 #include <epan/prefs.h>
15 #include <ui/qt/utils/color_utils.h>
16 
17 static const double wf_graph_normal_width_ = 0.5;
18 
19 RtpAudioGraph::RtpAudioGraph(QCustomPlot *audio_plot, QRgb color)
20 {
21     QPen p;
22     QPalette sel_pal;
23 
24     color_ = color;
25     wave_ = audio_plot->addGraph();
26     p = QPen(wave_->pen());
27     p.setColor(color_);
28     p.setWidthF(wf_graph_normal_width_);
29     wave_->setPen(p);
30     wave_->setSelectable(QCP::stNone);
31     wave_->removeFromLegend();
32     selection_color_ = sel_pal.color(QPalette::Highlight);
33 }
34 
35 // Indicate that audio will not be hearable
36 void RtpAudioGraph::setMuted(bool isMuted)
37 {
38     QPen p = wave_->pen();
39     if (isMuted) {
40         p.setStyle(Qt::DotLine);
41     } else {
42         p.setStyle(Qt::SolidLine);
43     }
44     wave_->setPen(p);
45 }
46 
47 void RtpAudioGraph::setHighlight(bool isHighlighted)
48 {
49     wave_->setSelection(isHighlighted ? QCPDataSelection(QCPDataRange()) : QCPDataSelection());
50     QPen p = wave_->pen();
51     if (isHighlighted) {
52         p.setWidthF(wf_graph_normal_width_*2);
53     } else {
54         p.setWidthF(wf_graph_normal_width_);
55     }
56     wave_->setPen(p);
57 }
58 
59 void RtpAudioGraph::setSelected(bool isSelected)
60 {
61     wave_->setSelection(isSelected ? QCPDataSelection(QCPDataRange()) : QCPDataSelection());
62     QPen p = wave_->pen();
63     if (isSelected) {
64         p.setColor(selection_color_);
65     } else {
66         p.setColor(color_);
67     }
68     wave_->setPen(p);
69 }
70 
71 void RtpAudioGraph::setData(const QVector<double> &keys, const QVector<double> &values, bool alreadySorted)
72 {
pack_i1(gfc_array_i1 * ret,const gfc_array_i1 * array,const gfc_array_l1 * mask,const gfc_array_i1 * vector)73     wave_->setData(keys, values, alreadySorted);
74 }
75 
76 void RtpAudioGraph::remove(QCustomPlot *audioPlot)
77 {
78     audioPlot->removeGraph(wave_);
79 }
80 
81 bool RtpAudioGraph::isMyPlottable(QCPAbstractPlottable *plottable)
82 {
83     if (plottable == wave_) {
84         return true;
85     } else {
86         return false;
87     }
88 }
89