]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQDownloadProgress.cc
restart qt4 porting
[duncan/yast2-qt4.git] / src / YQDownloadProgress.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQLogView.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #include <qlabel.h>
21 #include <qprogressbar.h>
22 #include <qtimer.h>
23 #define y2log_component "qt-ui"
24 #include <ycp/y2log.h>
25
26 #include "utf8.h"
27 #include "YQUI.h"
28 #include "YQDownloadProgress.h"
29 #include "YQWidgetCaption.h"
30
31
32 YQDownloadProgress::YQDownloadProgress( YWidget *       parent,
33                                         const string &  label,
34                                         const string &  filename,
35                                         YFileSize_t     expectedSize )
36     : QVBox( (QWidget *) parent->widgetRep() )
37     , YDownloadProgress( parent, label, filename, expectedSize )
38 {
39     setWidgetRep( this );
40     setMargin( YQWidgetMargin );
41
42     _caption = new YQWidgetCaption( this, label );
43     YUI_CHECK_NEW( _caption );
44
45     _qt_progressBar = new QProgressBar( this );
46     YUI_CHECK_NEW( _qt_progressBar );
47
48     _qt_progressBar->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
49     _qt_progressBar->setTotalSteps( 100 ); // Using percent
50     _qt_progressBar->setProgress( currentPercent() );
51
52     _timer = new QTimer( this );
53
54     connect( _timer,    SIGNAL( timeout()      ),
55              this,      SLOT  ( pollFileSize() ) );
56
57     _timer->start( 250,         // millisec
58                    false );     // single shot?
59 }
60
61
62 YQDownloadProgress::~YQDownloadProgress()
63 {
64     // NOP
65 }
66
67
68 void
69 YQDownloadProgress::setLabel( const string & label )
70 {
71     _caption->setText( label );
72     YDownloadProgress::setLabel( label );
73 }
74
75
76 void
77 YQDownloadProgress::setFilename( const string & filename )
78 {
79     YDownloadProgress::setFilename( filename );
80     _qt_progressBar->setProgress( currentPercent() );
81 }
82
83
84 void
85 YQDownloadProgress::setExpectedSize( YFileSize_t expectedSize )
86 {
87     _qt_progressBar->setProgress( currentPercent() );
88     YDownloadProgress::setExpectedSize( expectedSize );
89 }
90
91
92 void
93 YQDownloadProgress::pollFileSize()
94 {
95     _qt_progressBar->setProgress( currentPercent() );
96 }
97
98
99 void
100 YQDownloadProgress::setEnabled( bool enabled )
101 {
102     _caption->setEnabled( enabled );
103     _qt_progressBar->setEnabled( enabled );
104     YWidget::setEnabled( enabled );
105 }
106
107
108 int
109 YQDownloadProgress::preferredWidth()
110 {
111     return sizeHint().width();
112 }
113
114
115 int
116 YQDownloadProgress::preferredHeight()
117 {
118     return sizeHint().height();
119 }
120
121
122 void
123 YQDownloadProgress::setSize( int newWidth, int newHeight )
124 {
125     resize( newWidth, newHeight );
126 }
127
128
129 #include "YQDownloadProgress.moc"