00001
00002 #include <QDebug>
00003 #include "engine.h"
00004
00005 Engine::Engine( QString decoder, int address, QString imagePath, QString name, QWidget *parent) : QGroupBox( name, parent )
00006 {
00007 _decoder = decoder ;
00008 _imagePath = imagePath ;
00009 _address = address ;
00010 _oldSpeed = 0 ;
00011 setObjectName( name ) ;
00012
00013 setMinimumSize( QSize(190, 250) ) ;
00014 setMaximumSize( QSize(190, 250) ) ;
00015
00016 setAlignment( Qt::AlignHCenter ) ;
00017
00018 _image = new QLabel( trUtf8("Image not available") ) ;
00019 _image->setScaledContents ( TRUE ) ;
00020
00021 _picture = new QPixmap() ;
00022 if ( _picture->load( _imagePath ) )
00023 _image->setPixmap( *_picture ) ;
00024
00025 _btnLight = new QPushButton( QIcon( ":img/light.png" ), "" ) ;
00026 _btnLight->setToolTip( trUtf8("Light") ) ;
00027
00028 _btnReverse = new QPushButton( QIcon( ":img/reverse.svg" ), "" ) ;
00029 _btnReverse->setToolTip( trUtf8("Reverse") ) ;
00030
00031 _btnStop = new QPushButton( QIcon( ":img/stop.svg" ), "" ) ;
00032 _btnStop->setToolTip( trUtf8("Stop") );
00033
00034 _btnF2 = new QPushButton( "F2" ) ;
00035 _btnF3 = new QPushButton( "F3" ) ;
00036 _btnF4 = new QPushButton( "F4" ) ;
00037
00038 _btnLight->setCheckable( TRUE ) ;
00039 connect( _btnLight, SIGNAL( clicked(bool) ), this, SIGNAL( stateChanged() ) ) ;
00040
00041 _btnReverse->setCheckable( TRUE ) ;
00042 connect( _btnReverse, SIGNAL( clicked(bool) ), this, SIGNAL( stateChanged() ) ) ;
00043
00044 connect( _btnStop, SIGNAL( clicked() ), this, SLOT( stop() ) );
00045
00046 _btnF2->setCheckable( TRUE ) ;
00047 connect( _btnF2, SIGNAL( clicked(bool) ), this, SIGNAL( stateChanged() ) ) ;
00048
00049 _btnF3->setCheckable( TRUE ) ;
00050 connect( _btnF3, SIGNAL( clicked(bool) ), this, SIGNAL( stateChanged() ) ) ;
00051
00052 _btnF4->setCheckable( TRUE ) ;
00053 connect( _btnF4, SIGNAL( clicked(bool) ), this, SIGNAL( stateChanged() ) ) ;
00054
00055 QGridLayout *gridFunctions = new QGridLayout;
00056 gridFunctions->addWidget( _btnLight, 0, 0 );
00057 gridFunctions->addWidget( _btnReverse, 0, 1 );
00058 gridFunctions->addWidget( _btnStop, 0, 2 );
00059 gridFunctions->addWidget( _btnF2, 1, 0 );
00060 gridFunctions->addWidget( _btnF3, 1, 1 );
00061 gridFunctions->addWidget( _btnF4, 1, 2 );
00062
00063 _speedSlider = new QSlider( Qt::Vertical, this ) ;
00064 _speedSlider->setMaximum( 100 ) ;
00065 _speedSlider->setSingleStep( 5 ) ;
00066 _speedBar = new QProgressBar( this ) ;
00067 _speedBar->setValue( 0 ) ;
00068
00069 _palette = QPalette() ;
00070 setColor( 0 ) ;
00071
00072 QVBoxLayout *vBox = new QVBoxLayout() ;
00073 vBox->addWidget( _image ) ;
00074 vBox->addWidget( _speedBar ) ;
00075 vBox->addLayout( gridFunctions ) ;
00076
00077 QHBoxLayout *hBoxMain = new QHBoxLayout( this ) ;
00078 hBoxMain->addLayout( vBox ) ;
00079 hBoxMain->addWidget( _speedSlider ) ;
00080
00081 connect( _speedSlider, SIGNAL( valueChanged(int) ), _speedBar , SLOT( setValue(int) ) ) ;
00082 connect( _speedSlider, SIGNAL( valueChanged(int) ), this, SIGNAL( stateChanged() ) ) ;
00083
00084 connect( _speedSlider, SIGNAL( valueChanged(int) ), this, SLOT( setColor(int) ) );
00085 }
00086
00087 Engine::~Engine()
00088 {
00089 stop() ;
00090 }
00091
00092 void Engine::setColor( int speed )
00093 {
00094 _palette.setColor( QPalette::Highlight, QColor( round( 255 * speed / 100 ), round( 255 * (100 - speed) / 100 ), 0) ) ;
00095
00096 _speedBar->setPalette( _palette ) ;
00097
00098 }
00099
00100 QString Engine::name()
00101 {
00102 return objectName() ;
00103 }
00104
00105 void Engine::setName( QString name )
00106 {
00107 setObjectName( name ) ;
00108 setTitle( name ) ;
00109 }
00110
00111 int Engine::address()
00112 {
00113 return _address ;
00114 }
00115
00116 void Engine::setAddress( int address )
00117 {
00118 _address = address ;
00119 }
00120
00121 QString Engine::imagePath()
00122 {
00123 return _imagePath ;
00124 }
00125
00126 void Engine::setImage( QString imagePath )
00127 {
00128 _imagePath = imagePath ;
00129
00130 if ( _picture->load( imagePath ) )
00131 _image->setPixmap( *_picture ) ;
00132 else
00133 _image->setText( trUtf8("No image available") ) ;
00134 }
00135
00136 void Engine::setDecoder( QString decoder )
00137 {
00138 _decoder = decoder ;
00139 }
00140
00141 QString Engine::decoder()
00142 {
00143 return _decoder ;
00144 }
00145
00146 int Engine::speed()
00147 {
00148 return _speedSlider->value() ;
00149 }
00150
00151 bool Engine::light()
00152 {
00153 return _btnLight->isChecked() ;
00154 }
00155
00156 bool Engine::f2()
00157 {
00158 return _btnF2->isChecked() ;
00159 }
00160
00161 bool Engine::f3()
00162 {
00163 return _btnF3->isChecked() ;
00164 }
00165
00166 bool Engine::f4()
00167 {
00168 return _btnF4->isChecked() ;
00169 }
00170
00171 bool Engine::isReversed()
00172 {
00173 return _btnReverse->isChecked() ;
00174 }
00175
00176 void Engine::askForDelete()
00177 {
00178 if ( QMessageBox::question( this, tr("QMessageBox::question()"), tr("Do you really want to delete this engine ?"), QMessageBox::Yes | QMessageBox::No ) == QMessageBox::Yes )
00179 close() ;
00180 }
00181
00182 void Engine::stop()
00183 {
00184 _oldSpeed = _speedSlider->value() ;
00185 _speedSlider->setValue( 0 ) ;
00186 }
00187
00188 void Engine::restart()
00189 {
00190 _speedSlider->setValue( _oldSpeed ) ;
00191 }
00192
00193
00194 void Engine::mousePressEvent( QMouseEvent *event )
00195 {
00196 if ( event->button() == Qt::LeftButton )
00197 {
00198 emit clicked() ;
00199 _dragStartPosition = event->pos() ;
00200 }
00201 }
00202
00203 void Engine::mouseMoveEvent( QMouseEvent *event )
00204 {
00205 if ( event->buttons() != Qt::LeftButton && (event->pos() - _dragStartPosition).manhattanLength() < QApplication::startDragDistance() )
00206 return;
00207
00208 QPixmap *pixmap = new QPixmap() ;
00209 *pixmap = pixmap->grabWidget( this ) ;
00210
00211 QMimeData *mimeData = new QMimeData;
00212 mimeData->setData( OrKEngine::MimeType , QByteArray() );
00213
00214 QDrag *drag = new QDrag( this );
00215 drag->setMimeData(mimeData);
00216 drag->setPixmap(*pixmap);
00217 drag->setHotSpot( event->pos() );
00218
00219 hide() ;
00220
00221 drag->exec( Qt::MoveAction ) ;
00222 show() ;
00223
00224 }