~ubuntu-branches/debian/lenny/linpsk/lenny

« back to all changes in this revision

Viewing changes to src/csquelch.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Hamish Moffatt
  • Date: 2005-04-10 18:17:27 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050410181727-3l9dnfg0sp7bhk13
Tags: 0.8.1-1
* New upstream release 0.8.1
  * Modified upstream configure.in to support FHS-compliant Qt
    installation! (ie /usr/include/qt3, not /usr/lib/qt3/include) :-(
  * Re-autotools with autoconf2.59 and automake-1.9
* linpsk is no longer a Debian-native package (dsc/tar.gz)
* Now maintained by the debian-hams group
* Switch to debhelper 4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          |FILENAME|  -  description
 
3
                             -------------------
 
4
    begin                : |DATE|
 
5
    copyright            : (C) |YEAR| by |AUTHOR|
 
6
    email                : |EMAIL|
 
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
 ***************************************************************************/
 
16
 
 
17
#include <qvariant.h>
 
18
#include <qradiobutton.h>
 
19
#include <qslider.h>
 
20
#include <qlayout.h>
 
21
#include <qpainter.h>
 
22
#include <qstyle.h>
 
23
#include <qlabel.h>
 
24
 
 
25
#include <qdrawutil.h>
 
26
#include <qpalette.h>
 
27
 
 
28
#include "csquelch.h"
 
29
#include "color.h"
 
30
 
 
31
#define Black color[0]
 
32
#define Grey  color[64]
 
33
#define Cyan  color[127]
 
34
#define Yellow color[192]
 
35
 
 
36
mySlider::mySlider(QWidget *parent, const char *name = 0) :
 
37
QSlider(parent,name)
 
38
{
 
39
    setOrientation( QSlider::Vertical );
 
40
    setTickmarks( QSlider::NoMarks );
 
41
    setTickInterval( 10 );
 
42
    setMinValue(0);
 
43
    setMaxValue(100);
 
44
 
 
45
setValue(50);
 
46
SquelchLevel=0;
 
47
 
 
48
 
 
49
}
 
50
 
 
51
mySlider::~mySlider()
 
52
{
 
53
}
 
54
/** Painting Slider Background depending on Threshold and Signal Strength
 
55
*/
 
56
 
 
57
void mySlider::paintEvent(QPaintEvent *)
 
58
{
 
59
 
 
60
QPainter p;
 
61
 
 
62
QColorGroup cg(colorGroup());
 
63
const QColor c0 = cg.shadow();
 
64
const QColor c1 = cg.dark();
 
65
const QColor c3 = cg.light();
 
66
QColor c4;
 
67
 
 
68
int scale;
 
69
 
 
70
//p=new QPainter();
 
71
p.begin(this);
 
72
 
 
73
int mid = this->width()/2;
 
74
QRect groove = this->rect();
 
75
QRect handle = this->sliderRect();
 
76
                
 
77
int x, y, w, h;
 
78
             
 
79
if ( this->orientation() == Horizontal )
 
80
 {
 
81
  x = 0;
 
82
  y = groove.y() + mid - 3;
 
83
  w = this->width();
 
84
  h = 7;
 
85
 }
 
86
 else
 
87
 {
 
88
   
 
89
   x = groove.x() + mid - 3;
 
90
   
 
91
   w = 10;
 
92
   y = w/2;
 
93
   h = this->height()-w;
 
94
 }
 
95
p.fillRect( x, y, w, h, c1);
 
96
scale=(h*(100-SquelchLevel))/100;
 
97
 
 
98
if (SquelchLevel > (100-value()) )
 
99
  c4=Yellow;
 
100
else
 
101
 c4 = Cyan;
 
102
 
 
103
if ( SquelchLevel == 0  )
 
104
 c4 = c1;
 
105
 
 
106
// the dark side
 
107
p.setPen( c1 );
 
108
//p->drawLine( x, y, x + w - 1, y );
 
109
p.drawLine( x, y, x, y + h - 1);
 
110
p.setPen( c0 );
 
111
//p->drawLine( x + 1, y + 1, x + w - 2, y + 1 );
 
112
p.drawLine( x + 1, y + 1, x + 1, y + h - 2 );
 
113
// the bright side!
 
114
 
 
115
p.drawLine( x + 1,  y + h - 2, x + w - 2,  y + h - 2 );
 
116
p.drawLine( x + w - 2, y + 1, x + w - 2, y + h - 2 );
 
117
p.setPen( c3 );
 
118
p.drawLine( x, y + h - 1, x + w - 1, y + h - 1 );
 
119
p.drawLine( x + w - 1, y, x + w - 1, y + h - 1 );
 
120
 
 
121
p.fillRect(x+1,y+scale,w-2,h-scale,c4);       
 
122
 
 
123
p.setBrush(c1);
 
124
p.setPen(c1);
 
125
p.drawPie(x,y-w/2,w-1,w-1,0,2880);
 
126
p.setBrush(c4);
 
127
p.setPen(c4);
 
128
p.drawPie(x,h,w-1,w-1,2880,2880);
 
129
p.setPen(c1);
 
130
p.drawArc(x,h,w-1,w-1,2880,1440);
 
131
p.setPen( c3 );
 
132
p.drawArc(x,h,w-1,w-1,4320,1440);
 
133
 
 
134
// ### end slider groove
 
135
 
 
136
// Slider Handle
 
137
                int x1 = handle.x();
 
138
                int x2 = handle.x() + handle.width() - 1;
 
139
                int y1 = handle.y();
 
140
                int y2 = handle.y() + handle.height() - 1;
 
141
                int mx = handle.width() / 2;
 
142
                int my = handle.height() / 2;
 
143
 
 
144
                if ( this->orientation() == Vertical ) {
 
145
                    // Background
 
146
                    QBrush oldBrush = p.brush();
 
147
                    p.setBrush( cg.brush( QColorGroup::Button ) );
 
148
                    p.setPen( NoPen );
 
149
                    QPointArray a(6);
 
150
                    a.setPoint( 0, x1 + 1, y1 + 1 );
 
151
                    a.setPoint( 1, x2 - my + 2, y1 + 1 );
 
152
                    a.setPoint( 2, x2 - 1, y1 + my - 1 );
 
153
                    a.setPoint( 3, x2 - 1, y2 - my + 1 );
 
154
                    a.setPoint( 4, x2 - my + 2, y2 - 1 );
 
155
                    a.setPoint( 5, x1 + 1, y2 - 1 );
 
156
                    p.drawPolygon( a );
 
157
                    p.setBrush( oldBrush );
 
158
 
 
159
                    // shadow border
 
160
                    p.setPen( c0 );
 
161
                    p.drawLine( x1, y1 + 1, x1,y2 - 1 );
 
162
                    p.drawLine( x2 - my + 2, y1, x2, y1 + my - 2 );
 
163
                    p.drawLine( x2 - my + 2, y2, x2, y1 + my + 2 );
 
164
                    p.drawLine( x2, y1 + my - 2, x2, y1 + my + 2 );
 
165
                    p.drawLine( x1 + 1, y1, x2 - my + 2, y1 );
 
166
                    p.drawLine( x1 + 1, y2, x2 - my + 2, y2 );
 
167
 
 
168
                    // light shadow
 
169
                    p.setPen( c3 );
 
170
                    p.drawLine( x1 + 1, y1 + 2, x1 + 1, y2 - 2 );
 
171
                    p.drawLine( x1 + 1, y1 + 1, x2 - my + 2, y1 + 1 );
 
172
                    p.drawLine( x2 - my + 2, y1 + 1, x2 - 1, y1 + my - 2 );
 
173
 
 
174
                    // dark shadow
 
175
                    p.setPen(c1);
 
176
                    p.drawLine( x2 - 1, y1 + my - 2, x2 - 1, y1 + my + 2 );
 
177
                    p.drawLine( x2 - my + 2, y2 - 1, x2 - 1, y1 + my + 2 );
 
178
                    p.drawLine( x1 + 1, y2 - 1, x2 -my + 2, y2 - 1 );
 
179
 
 
180
                } else {  // Horizontal
 
181
                    QBrush oldBrush = p.brush();
 
182
                    p.setBrush( cg.brush( QColorGroup::Button ) );
 
183
                    p.setPen( NoPen );
 
184
                    QPointArray a(6);
 
185
                    a.setPoint( 0, x2 - 1, y1 + 1 );
 
186
                    a.setPoint( 1, x2 - 1, y2 - mx + 2 );
 
187
                    a.setPoint( 2, x2 - mx + 1, y2 - 1 );
 
188
                    a.setPoint( 3, x1 + mx - 1, y2 - 1 );
 
189
                    a.setPoint( 4, x1 + 1, y2 - mx + 2 );
 
190
                    a.setPoint( 5, x1 + 1, y1 + 1 );
 
191
                    p.drawPolygon( a );
 
192
                    p.setBrush( oldBrush );
 
193
 
 
194
                    // shadow border
 
195
                    p.setPen( c0 );
 
196
                    p.drawLine( x1 + 1, y1, x2 - 1, y1 );
 
197
                    p.drawLine( x1, y2 - mx + 2, x1 + mx - 2, y2 );
 
198
                    p.drawLine( x2, y2 - mx + 2, x1 + mx + 2, y2 );
 
199
                    p.drawLine( x1 + mx - 2, y2, x1 + mx + 2, y2 );
 
200
                    p.drawLine( x1, y1 + 1, x1, y2 - mx + 2 );
 
201
                    p.drawLine( x2, y1 + 1, x2, y2 - mx + 2 );
 
202
 
 
203
                    // light shadow
 
204
                    p.setPen(c3);
 
205
                    p.drawLine( x1 + 1, y1 + 1, x2 - 1, y1 + 1 );
 
206
                    p.drawLine( x1 + 1, y1 + 1, x1 + 1, y2 - mx + 2 );
 
207
 
 
208
                    // dark shadow
 
209
                    p.setPen(c1);
 
210
                    p.drawLine( x2 - 1, y1 + 1, x2 - 1, y2 - mx + 2 );
 
211
                    p.drawLine( x1 + 1, y2 - mx + 2, x1 + mx - 2, y2 - 1 );
 
212
                    p.drawLine( x2 - 1, y2 - mx + 2, x1 + mx + 2, y2 - 1 );
 
213
                    p.drawLine( x1 + mx - 2, y2 - 1, x1 + mx + 2, y2 - 1 );
 
214
 
 
215
        }
 
216
 
 
217
 
 
218
 
 
219
p.end();
 
220
 
 
221
 
 
222
}
 
223
 
 
224
void mySlider::setSquelchLevel(int level)
 
225
{
 
226
SquelchLevel=level;
 
227
repaint();
 
228
}
 
229
 
 
230
int mySlider::getThreshold()
 
231
{
 
232
return 100-value();
 
233
}
 
234
 
 
235
/* 
 
236
 *  Constructs a CSquelch which is a child of 'parent', with the 
 
237
 *  name 'name'.' 
 
238
 */
 
239
CSquelch::CSquelch( QWidget* parent,  const char* name )
 
240
    : QGroupBox( parent, name )
 
241
{
 
242
    setFrameShape( QGroupBox::WinPanel );
 
243
    setFrameShadow( QGroupBox::Raised );
 
244
    setAlignment( int( QGroupBox::AlignHCenter ) );
 
245
 
 
246
    Activate = new QRadioButton( this, "Activate" );
 
247
    Activate->setGeometry( QRect( 120, 340, 60, 41 ) );
 
248
    ActivateText = new QLabel(this,"ActivateText");
 
249
    ActivateText->setAlignment(AlignHCenter);
 
250
 
 
251
 
 
252
    Squelch = new mySlider( this, "Squelch" );
 
253
 //   Squelch->setPaletteBackgroundColor( QColor( 0, 0, 0 ) );
 
254
    Squelch->setOrientation( QSlider::Vertical );
 
255
    Squelch->setTickmarks( QSlider::NoMarks );
 
256
    Squelch->setTickInterval( 10 );
 
257
    Squelch->setMinValue(0);
 
258
    Squelch->setMaxValue(100);
 
259
 
 
260
   
 
261
    languageChange();
 
262
 
 
263
}
 
264
 
 
265
/*
 
266
 *  Destroys the object and frees any allocated resources
 
267
 */
 
268
CSquelch::~CSquelch()
 
269
{
 
270
    // no need to delete child widgets, Qt does it all for us
 
271
}
 
272
 
 
273
/*
 
274
 *  Sets the strings of the subwidgets using the current
 
275
 *  language.
 
276
 */
 
277
void CSquelch::languageChange()
 
278
{
 
279
    setTitle( tr( "Squelch" ) );
 
280
    ActivateText->setText( tr( "On/Off" ) );
 
281
}
 
282
void CSquelch::resizeEvent( QResizeEvent * )
 
283
{
 
284
calculateSizeofComponents();
 
285
}
 
286
 
 
287
void CSquelch::calculateSizeofComponents()
 
288
{
 
289
/** Margins **/
 
290
#define TOPMARGIN 10
 
291
/** WIDTH and Height in % **/
 
292
#define SQUELCHWIDTH 25
 
293
#define SQUELCHHEIGHT 70
 
294
#define BUTTONWIDTH 90
 
295
#define BUTTONHEIGHT 10
 
296
 
 
297
int xpos,ypos, width,height,innerwidth,innerheight;
 
298
 
 
299
width=this->width();
 
300
height=this->height();
 
301
innerwidth=width*SQUELCHWIDTH/100;
 
302
xpos=(width-innerwidth)/2;
 
303
ypos=height*TOPMARGIN/100;
 
304
innerheight=height*SQUELCHHEIGHT/100;
 
305
Squelch->setGeometry(xpos,ypos,innerwidth,innerheight);
 
306
ypos=ypos+innerheight;
 
307
innerheight=height*BUTTONHEIGHT/100;
 
308
Activate->setGeometry(xpos,ypos,innerwidth,innerheight);
 
309
innerwidth=width*BUTTONWIDTH/100;
 
310
xpos=(width-innerwidth)/2;
 
311
ypos=ypos+innerheight;
 
312
ActivateText->setGeometry(xpos,ypos,innerwidth,innerheight);
 
313
 
 
314
this->setFrameRect(QRect(0,0,width,height));
 
315
}
 
316
 
 
317
 
 
318
void CSquelch::setSquelchLevel(int level)
 
319
{
 
320
Squelch->setSquelchLevel(level);
 
321
repaint();
 
322
 
 
323
}
 
324
int CSquelch::getThreshold()
 
325
{
 
326
return Squelch->getThreshold();
 
327
}
 
328
bool CSquelch::getSquelchState()
 
329
{
 
330
return Activate->isOn();
 
331
}
 
332
void CSquelch::setSquelchState(bool state)
 
333
{
 
334
Activate->setChecked(state);
 
335
}
 
336
void CSquelch::setThreshold(int Threshold)
 
337
{
 
338
Squelch->setValue(100-Threshold);
 
339
}