libyui-qt  2.43.5
/usr/src/RPM/BUILD/libyui-qt-2.43.5/src/YQDownloadProgress.cc
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:       YQLogView.cc
00020 
00021   Author:     Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #include <qlabel.h>
00027 #include <qtimer.h>
00028 #define YUILogComponent "qt-ui"
00029 #include <yui/YUILog.h>
00030 
00031 #include "utf8.h"
00032 #include "YQUI.h"
00033 #include "YQDownloadProgress.h"
00034 #include "YQWidgetCaption.h"
00035 #include <QVBoxLayout>
00036 #include <QProgressBar>
00037 
00038 YQDownloadProgress::YQDownloadProgress( YWidget *       parent,
00039                                         const std::string &     label,
00040                                         const std::string &     filename,
00041                                         YFileSize_t     expectedSize )
00042     : QFrame( (QWidget *) parent->widgetRep() )
00043     , YDownloadProgress( parent, label, filename, expectedSize )
00044 {
00045     QVBoxLayout* layout = new QVBoxLayout( this );
00046     setLayout( layout );
00047 
00048     setWidgetRep( this );
00049     layout->setMargin( YQWidgetMargin );
00050 
00051     _caption = new YQWidgetCaption( this, label );
00052     YUI_CHECK_NEW( _caption );
00053     layout->addWidget( _caption );
00054 
00055     _qt_progressBar = new QProgressBar( this );
00056     YUI_CHECK_NEW( _qt_progressBar );
00057     layout->addWidget( _qt_progressBar );
00058 
00059     _qt_progressBar->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00060     _qt_progressBar->setRange( 0, 100 ); // Using percent
00061     _qt_progressBar->setValue( currentPercent() );
00062 
00063     _timer = new QTimer( this );
00064 
00065     connect( _timer,    SIGNAL( timeout()      ),
00066              this,      SLOT  ( pollFileSize() ) );
00067 
00068     _timer->setSingleShot(false);
00069     _timer->start( 250 );// millisec
00070 }
00071 
00072 
00073 YQDownloadProgress::~YQDownloadProgress()
00074 {
00075     // NOP
00076 }
00077 
00078 
00079 void
00080 YQDownloadProgress::setLabel( const std::string & label )
00081 {
00082     _caption->setText( label );
00083     YDownloadProgress::setLabel( label );
00084 }
00085 
00086 
00087 void
00088 YQDownloadProgress::setFilename( const std::string & filename )
00089 {
00090     YDownloadProgress::setFilename( filename );
00091     _qt_progressBar->setValue( currentPercent() );
00092 }
00093 
00094 
00095 void
00096 YQDownloadProgress::setExpectedSize( YFileSize_t expectedSize )
00097 {
00098     _qt_progressBar->setValue( currentPercent() );
00099     YDownloadProgress::setExpectedSize( expectedSize );
00100 }
00101 
00102 
00103 void
00104 YQDownloadProgress::pollFileSize()
00105 {
00106     _qt_progressBar->setValue( currentPercent() );
00107 }
00108 
00109 
00110 void
00111 YQDownloadProgress::setEnabled( bool enabled )
00112 {
00113     _caption->setEnabled( enabled );
00114     _qt_progressBar->setEnabled( enabled );
00115     YWidget::setEnabled( enabled );
00116 }
00117 
00118 
00119 int
00120 YQDownloadProgress::preferredWidth()
00121 {
00122     return sizeHint().width();
00123 }
00124 
00125 
00126 int
00127 YQDownloadProgress::preferredHeight()
00128 {
00129     return sizeHint().height();
00130 }
00131 
00132 
00133 void
00134 YQDownloadProgress::setSize( int newWidth, int newHeight )
00135 {
00136     resize( newWidth, newHeight );
00137 }
00138 
00139 
00140 #include "YQDownloadProgress.moc"
 All Classes Functions Variables