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