~ubuntu-branches/ubuntu/quantal/linpsk/quantal

« back to all changes in this revision

Viewing changes to linpsk/csquelch.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bruce Walker
  • Date: 2002-02-06 11:43:38 UTC
  • Revision ID: james.westby@ubuntu.com-20020206114338-xqmjmhh01lpjm0g4
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          csquelch.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Sun Apr 2 2000
 
5
    copyright            : (C) 2000 by Volker Schroer
 
6
    email                : DL1KSV@gmx.de
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *    based on the work of  Moe Wheatly, AE4JY                             *  
 
16
 ***************************************************************************/
 
17
 
 
18
#include "csquelch.h"
 
19
 
 
20
#define Black color[0]
 
21
#define Grey  color[64]
 
22
#define Cyan  color[127]
 
23
#define Yellow color[192]
 
24
 
 
25
mySlider::mySlider(QWidget *parent, const char *name = 0) : QSlider(0,100,10,50,QSlider::Vertical,parent,name)
 
26
{
 
27
setBackgroundColor(Black);
 
28
setValue(50);
 
29
Threshold=50;
 
30
SquelchLevel=0;
 
31
SquelchStatus = false;
 
32
}
 
33
 
 
34
mySlider::~mySlider()
 
35
{
 
36
}
 
37
 
 
38
/** Painting Slider Background depending on Threshold and Signal Strength      */
 
39
void mySlider::paintEvent(QPaintEvent *)
 
40
{
 
41
QPainter p;
 
42
int scale;
 
43
int y;
 
44
int slide;
 
45
y=height();
 
46
scale =(100- SquelchLevel)*y/100;
 
47
slide =(100- Threshold)*y/100;
 
48
 
 
49
 
 
50
p.begin(this);
 
51
if (SquelchStatus)
 
52
        p.fillRect(0,scale,20,y-scale,Yellow);
 
53
else
 
54
        p.fillRect(0,scale,20,y-scale,Grey);
 
55
paintSlider(&p,colorGroup(),QRect(0,slide,20,5));
 
56
p.setPen(Cyan);
 
57
drawWinGroove(&p,10);
 
58
p.end();
 
59
}
 
60
 
 
61
/** sets a new Threshold for Squelch */
 
62
void mySlider::newThreshold(int value)
 
63
{
 
64
int i;
 
65
i= 100-value;
 
66
if ( i != Threshold)
 
67
        {
 
68
        Threshold=i;
 
69
        setValue(value);
 
70
        repaint();
 
71
  }
 
72
}
 
73
 
 
74
CSquelch::CSquelch(QWidget *parent, const char *name  ) :QGroupBox(1,Horizontal,"Squelch",parent,name)
 
75
{
 
76
        
 
77
setFrameStyle(QFrame::WinPanel | QFrame::Raised);
 
78
setAlignment(AlignCenter);
 
79
setMargin(0);
 
80
 
 
81
 
 
82
 
 
83
Slider = new mySlider(this);
 
84
connect(Slider,SIGNAL(valueChanged(int)),Slider,SLOT(newThreshold(int)));
 
85
OnOff = new QRadioButton("On/Off",this);
 
86
OnOff->setChecked(true);
 
87
connect(OnOff,SIGNAL(clicked()),this,SLOT(turnOnOffSquelch()));
 
88
OnOffStatus=true;
 
89
}
 
90
 
 
91
CSquelch::~CSquelch()
 
92
{
 
93
delete Slider;
 
94
}
 
95
 
 
96
 
 
97
bool CSquelch::SquelchOn()
 
98
{
 
99
if (!OnOffStatus)
 
100
        return true;
 
101
else    
 
102
return Slider->SquelchStatus;
 
103
 
 
104
}
 
105
 
 
106
void CSquelch::setSquelchLevel(int i)
 
107
{
 
108
if ( ((Slider->SquelchLevel - i) > 2) || ((i - Slider->SquelchLevel) > 2 ))
 
109
        {
 
110
        if ( i > Slider->SquelchLevel )         // Signalquality raises
 
111
         Slider->SquelchStatus = Slider->SquelchStatus || (i > Slider->Threshold);
 
112
 
 
113
        else                                                                                    // Signalquality falls
 
114
         Slider->SquelchStatus = Slider->SquelchStatus && (i > Slider->Threshold);
 
115
         Slider->SquelchLevel=i;
 
116
         Slider->update();
 
117
        }       
 
118
}
 
119
 
 
120
void CSquelch::setSquelchStatus(bool squelch)
 
121
{
 
122
 
 
123
Slider->SquelchStatus = Slider->SquelchStatus || squelch;
 
124
}
 
125
 
 
126
void CSquelch::turnOnOffSquelch()
 
127
{
 
128
OnOffStatus = !OnOffStatus;
 
129
}
 
130