]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQDownloadProgress.cc
compile
[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 <q3progressbar.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 #include <QVBoxLayout>
31 #include <QProgressBar>
32
33 YQDownloadProgress::YQDownloadProgress( YWidget *       parent,
34                                         const string &  label,
35                                         const string &  filename,
36                                         YFileSize_t     expectedSize )
37     : QFrame( (QWidget *) parent->widgetRep() )
38     , YDownloadProgress( parent, label, filename, expectedSize )
39 {
40     QVBoxLayout* layout = new QVBoxLayout( this );
41     setLayout( layout );
42
43     setWidgetRep( this );
44     layout->setMargin( YQWidgetMargin );
45
46     _caption = new YQWidgetCaption( this, label );
47     YUI_CHECK_NEW( _caption );
48     layout->addWidget( _caption );
49
50     _qt_progressBar = new QProgressBar( this );
51     YUI_CHECK_NEW( _qt_progressBar );
52     layout->addWidget( _qt_progressBar );
53
54     _qt_progressBar->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
55     _qt_progressBar->setRange( 0, 100 ); // Using percent
56     _qt_progressBar->setValue( currentPercent() );
57
58     _timer = new QTimer( this );
59
60     connect( _timer,    SIGNAL( timeout()      ),
61              this,      SLOT  ( pollFileSize() ) );
62
63     _timer->setSingleShot(false);
64     _timer->start( 250 );// millisec
65 }
66
67
68 YQDownloadProgress::~YQDownloadProgress()
69 {
70     // NOP
71 }
72
73
74 void
75 YQDownloadProgress::setLabel( const string & label )
76 {
77     _caption->setText( label );
78     YDownloadProgress::setLabel( label );
79 }
80
81
82 void
83 YQDownloadProgress::setFilename( const string & filename )
84 {
85     YDownloadProgress::setFilename( filename );
86     _qt_progressBar->setValue( currentPercent() );
87 }
88
89
90 void
91 YQDownloadProgress::setExpectedSize( YFileSize_t expectedSize )
92 {
93     _qt_progressBar->setValue( currentPercent() );
94     YDownloadProgress::setExpectedSize( expectedSize );
95 }
96
97
98 void
99 YQDownloadProgress::pollFileSize()
100 {
101     _qt_progressBar->setValue( currentPercent() );
102 }
103
104
105 void
106 YQDownloadProgress::setEnabled( bool enabled )
107 {
108     _caption->setEnabled( enabled );
109     _qt_progressBar->setEnabled( enabled );
110     YWidget::setEnabled( enabled );
111 }
112
113
114 int
115 YQDownloadProgress::preferredWidth()
116 {
117     return sizeHint().width();
118 }
119
120
121 int
122 YQDownloadProgress::preferredHeight()
123 {
124     return sizeHint().height();
125 }
126
127
128 void
129 YQDownloadProgress::setSize( int newWidth, int newHeight )
130 {
131     resize( newWidth, newHeight );
132 }
133
134
135 #include "YQDownloadProgress.moc"