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