| 1 | /****************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Implementation of LCDRange class, Qt tutorial 12
|
|---|
| 4 | **
|
|---|
| 5 | ****************************************************************/
|
|---|
| 6 |
|
|---|
| 7 | #include "lcdrange.h"
|
|---|
| 8 |
|
|---|
| 9 | #include <qslider.h>
|
|---|
| 10 | #include <qlcdnumber.h>
|
|---|
| 11 | #include <qlabel.h>
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | LCDRange::LCDRange( QWidget *parent, const char *name )
|
|---|
| 15 | : QVBox( parent, name )
|
|---|
| 16 | {
|
|---|
| 17 | init();
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 | LCDRange::LCDRange( const char *s, QWidget *parent,
|
|---|
| 22 | const char *name )
|
|---|
| 23 | : QVBox( parent, name )
|
|---|
| 24 | {
|
|---|
| 25 | init();
|
|---|
| 26 | setText( s );
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | void LCDRange::init()
|
|---|
| 31 | {
|
|---|
| 32 | QLCDNumber *lcd = new QLCDNumber( 2, this, "lcd" );
|
|---|
| 33 | slider = new QSlider( Horizontal, this, "slider" );
|
|---|
| 34 | slider->setRange( 0, 99 );
|
|---|
| 35 | slider->setValue( 0 );
|
|---|
| 36 |
|
|---|
| 37 | label = new QLabel( " ", this, "label" );
|
|---|
| 38 | label->setAlignment( AlignCenter );
|
|---|
| 39 |
|
|---|
| 40 | connect( slider, SIGNAL(valueChanged(int)),
|
|---|
| 41 | lcd, SLOT(display(int)) );
|
|---|
| 42 | connect( slider, SIGNAL(valueChanged(int)),
|
|---|
| 43 | SIGNAL(valueChanged(int)) );
|
|---|
| 44 |
|
|---|
| 45 | setFocusProxy( slider );
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | int LCDRange::value() const
|
|---|
| 50 | {
|
|---|
| 51 | return slider->value();
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 | const char *LCDRange::text() const
|
|---|
| 56 | {
|
|---|
| 57 | return label->text();
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | void LCDRange::setValue( int value )
|
|---|
| 62 | {
|
|---|
| 63 | slider->setValue( value );
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | void LCDRange::setRange( int minVal, int maxVal )
|
|---|
| 68 | {
|
|---|
| 69 | if ( minVal < 0 || maxVal > 99 || minVal > maxVal ) {
|
|---|
| 70 | qWarning( "LCDRange::setRange(%d,%d)\n"
|
|---|
| 71 | "\tRange must be 0..99\n"
|
|---|
| 72 | "\tand minVal must not be greater than maxVal",
|
|---|
| 73 | minVal, maxVal );
|
|---|
| 74 | return;
|
|---|
| 75 | }
|
|---|
| 76 | slider->setRange( minVal, maxVal );
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | void LCDRange::setText( const char *s )
|
|---|
| 81 | {
|
|---|
| 82 | label->setText( s );
|
|---|
| 83 | }
|
|---|