1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
22 #define y2log_component "qt-ui"
23 #include <ycp/y2log.h>
27 #include "YQDownloadProgress.h"
28 #include "YQWidgetCaption.h"
29 #include <QVBoxLayout>
30 #include <QProgressBar>
32 YQDownloadProgress::YQDownloadProgress( YWidget * parent,
34 const string & filename,
35 YFileSize_t expectedSize )
36 : QFrame( (QWidget *) parent->widgetRep() )
37 , YDownloadProgress( parent, label, filename, expectedSize )
39 QVBoxLayout* layout = new QVBoxLayout( this );
43 layout->setMargin( YQWidgetMargin );
45 _caption = new YQWidgetCaption( this, label );
46 YUI_CHECK_NEW( _caption );
47 layout->addWidget( _caption );
49 _qt_progressBar = new QProgressBar( this );
50 YUI_CHECK_NEW( _qt_progressBar );
51 layout->addWidget( _qt_progressBar );
53 _qt_progressBar->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
54 _qt_progressBar->setRange( 0, 100 ); // Using percent
55 _qt_progressBar->setValue( currentPercent() );
57 _timer = new QTimer( this );
59 connect( _timer, SIGNAL( timeout() ),
60 this, SLOT ( pollFileSize() ) );
62 _timer->setSingleShot(false);
63 _timer->start( 250 );// millisec
67 YQDownloadProgress::~YQDownloadProgress()
74 YQDownloadProgress::setLabel( const string & label )
76 _caption->setText( label );
77 YDownloadProgress::setLabel( label );
82 YQDownloadProgress::setFilename( const string & filename )
84 YDownloadProgress::setFilename( filename );
85 _qt_progressBar->setValue( currentPercent() );
90 YQDownloadProgress::setExpectedSize( YFileSize_t expectedSize )
92 _qt_progressBar->setValue( currentPercent() );
93 YDownloadProgress::setExpectedSize( expectedSize );
98 YQDownloadProgress::pollFileSize()
100 _qt_progressBar->setValue( currentPercent() );
105 YQDownloadProgress::setEnabled( bool enabled )
107 _caption->setEnabled( enabled );
108 _qt_progressBar->setEnabled( enabled );
109 YWidget::setEnabled( enabled );
114 YQDownloadProgress::preferredWidth()
116 return sizeHint().width();
121 YQDownloadProgress::preferredHeight()
123 return sizeHint().height();
128 YQDownloadProgress::setSize( int newWidth, int newHeight )
130 resize( newWidth, newHeight );
134 #include "YQDownloadProgress.moc"