libyui-qt  2.52.4
YQDownloadProgress.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQLogView.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #include <qlabel.h>
27 #include <qtimer.h>
28 #define YUILogComponent "qt-ui"
29 #include <yui/YUILog.h>
30 
31 #include "utf8.h"
32 #include "YQUI.h"
33 #include "YQDownloadProgress.h"
34 #include "YQWidgetCaption.h"
35 #include <QVBoxLayout>
36 #include <QProgressBar>
37 
38 using std::string;
39 
40 
42  const string & label,
43  const string & filename,
44  YFileSize_t expectedSize )
45  : QFrame( (QWidget *) parent->widgetRep() )
46  , YDownloadProgress( parent, label, filename, expectedSize )
47 {
48  QVBoxLayout* layout = new QVBoxLayout( this );
49  setLayout( layout );
50 
51  setWidgetRep( this );
52  layout->setMargin( YQWidgetMargin );
53 
54  _caption = new YQWidgetCaption( this, label );
55  YUI_CHECK_NEW( _caption );
56  layout->addWidget( _caption );
57 
58  _qt_progressBar = new QProgressBar( this );
59  YUI_CHECK_NEW( _qt_progressBar );
60  layout->addWidget( _qt_progressBar );
61 
62  _qt_progressBar->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
63  _qt_progressBar->setRange( 0, 100 ); // Using percent
64  _qt_progressBar->setValue( currentPercent() );
65 
66  _timer = new QTimer( this );
67 
68  connect( _timer, &pclass(_timer)::timeout,
69  this, &pclass(this)::pollFileSize );
70 
71  _timer->setSingleShot(false);
72  _timer->start( 250 );// millisec
73 }
74 
75 
77 {
78  // NOP
79 }
80 
81 
82 void
83 YQDownloadProgress::setLabel( const string & label )
84 {
85  _caption->setText( label );
86  YDownloadProgress::setLabel( label );
87 }
88 
89 
90 void
91 YQDownloadProgress::setFilename( const string & filename )
92 {
93  YDownloadProgress::setFilename( filename );
94  _qt_progressBar->setValue( currentPercent() );
95 }
96 
97 
98 void
99 YQDownloadProgress::setExpectedSize( YFileSize_t expectedSize )
100 {
101  _qt_progressBar->setValue( currentPercent() );
102  YDownloadProgress::setExpectedSize( expectedSize );
103 }
104 
105 
106 void
108 {
109  _qt_progressBar->setValue( currentPercent() );
110 }
111 
112 
113 void
115 {
116  _caption->setEnabled( enabled );
117  _qt_progressBar->setEnabled( enabled );
118  YWidget::setEnabled( enabled );
119 }
120 
121 
122 int
124 {
125  return sizeHint().width();
126 }
127 
128 
129 int
131 {
132  return sizeHint().height();
133 }
134 
135 
136 void
137 YQDownloadProgress::setSize( int newWidth, int newHeight )
138 {
139  resize( newWidth, newHeight );
140 }
141 
virtual int preferredWidth()
Preferred width of the widget.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual void setText(const std::string &newText)
Change the text and handle visibility: If the new text is empty, hide this widget.
virtual int preferredHeight()
Preferred height of the widget.
virtual void setExpectedSize(YFileSize_t expectedSize)
Change the expected file size.
virtual ~YQDownloadProgress()
Destructor.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
YQDownloadProgress(YWidget *parent, const std::string &label, const std::string &filename, YFileSize_t expectedSize)
Constructor.
virtual void setFilename(const std::string &filename)
Set the name of a new file to monitor.
Helper class for captions (labels) above a widget: Takes care of hiding itself when its text is empty...
void pollFileSize(void)
Slot for polling and displaying the file size.
virtual void setLabel(const std::string &label)
Set the label (the text above the progress bar).