1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
21 #include <q3progressbar.h>
23 #define y2log_component "qt-ui"
24 #include <ycp/y2log.h>
28 #include "YQDownloadProgress.h"
29 #include "YQWidgetCaption.h"
30 #include <QVBoxLayout>
31 #include <QProgressBar>
33 YQDownloadProgress::YQDownloadProgress( YWidget * parent,
35 const string & filename,
36 YFileSize_t expectedSize )
37 : QFrame( (QWidget *) parent->widgetRep() )
38 , YDownloadProgress( parent, label, filename, expectedSize )
40 QVBoxLayout* layout = new QVBoxLayout( this );
44 layout->setMargin( YQWidgetMargin );
46 _caption = new YQWidgetCaption( this, label );
47 YUI_CHECK_NEW( _caption );
48 layout->addWidget( _caption );
50 _qt_progressBar = new QProgressBar( this );
51 YUI_CHECK_NEW( _qt_progressBar );
52 layout->addWidget( _qt_progressBar );
54 _qt_progressBar->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
55 _qt_progressBar->setRange( 0, 100 ); // Using percent
56 _qt_progressBar->setValue( currentPercent() );
58 _timer = new QTimer( this );
60 connect( _timer, SIGNAL( timeout() ),
61 this, SLOT ( pollFileSize() ) );
63 _timer->start( 250, // millisec
64 false ); // single shot?
68 YQDownloadProgress::~YQDownloadProgress()
75 YQDownloadProgress::setLabel( const string & label )
77 _caption->setText( label );
78 YDownloadProgress::setLabel( label );
83 YQDownloadProgress::setFilename( const string & filename )
85 YDownloadProgress::setFilename( filename );
86 _qt_progressBar->setValue( currentPercent() );
91 YQDownloadProgress::setExpectedSize( YFileSize_t expectedSize )
93 _qt_progressBar->setValue( currentPercent() );
94 YDownloadProgress::setExpectedSize( expectedSize );
99 YQDownloadProgress::pollFileSize()
101 _qt_progressBar->setValue( currentPercent() );
106 YQDownloadProgress::setEnabled( bool enabled )
108 _caption->setEnabled( enabled );
109 _qt_progressBar->setEnabled( enabled );
110 YWidget::setEnabled( enabled );
115 YQDownloadProgress::preferredWidth()
117 return sizeHint().width();
122 YQDownloadProgress::preferredHeight()
124 return sizeHint().height();
129 YQDownloadProgress::setSize( int newWidth, int newHeight )
131 resize( newWidth, newHeight );
135 #include "YQDownloadProgress.moc"