picking up branches/tmp/sh/qt4-port/, merging it with trunk
[duncan/yast2-qt4.git] / src / YQProgressBar.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQProgressBar.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #include <qprogressbar.h>
21 #include <QVBoxLayout>
22
23 #include <qlabel.h>
24 #define y2log_component "qt-ui"
25 #include <ycp/y2log.h>
26
27 using std::max;
28
29 #include "utf8.h"
30 #include "YQUI.h"
31 #include "YQProgressBar.h"
32 #include "YQWidgetCaption.h"
33
34
35 YQProgressBar::YQProgressBar( YWidget *         parent,
36                               const string &    label,
37                               int               maxValue )
38     : QFrame( (QWidget *) parent->widgetRep() )
39     , YProgressBar( parent, label, maxValue )
40 {
41     QVBoxLayout* layout = new QVBoxLayout( this );
42     setLayout( layout );
43
44     setWidgetRep( this );
45
46     layout->setSpacing( YQWidgetSpacing );
47     layout->setMargin ( YQWidgetMargin  );
48
49     _caption = new YQWidgetCaption( this, label );
50     YUI_CHECK_NEW( _caption );
51     layout->addWidget( _caption );
52     
53     _qt_progressbar = new QProgressBar( this );
54     _qt_progressbar->setRange(0, maxValue);
55     YUI_CHECK_NEW( _qt_progressbar );
56     layout->addWidget( _qt_progressbar );
57
58     _caption->setBuddy( _qt_progressbar );
59 }
60
61
62 YQProgressBar::~YQProgressBar()
63 {
64     // NOP
65 }
66
67
68 void YQProgressBar::setLabel( const string & label )
69 {
70     _caption->setText( label );
71     YProgressBar::setLabel( label );
72 }
73
74
75 void YQProgressBar::setValue( int newValue )
76 {
77     YProgressBar::setValue( newValue );
78     _qt_progressbar->setValue( value() );
79 }
80
81
82
83 void YQProgressBar::setEnabled( bool enabled )
84 {
85     _caption->setEnabled( enabled );
86     _qt_progressbar->setEnabled( enabled );
87     YWidget::setEnabled( enabled );
88 }
89
90
91 int YQProgressBar::preferredWidth()
92 {
93     int hintWidth = _caption->isShown() ?
94       _caption->sizeHint().width() + layout()->margin() : 0;
95
96     return max( 200, hintWidth );
97 }
98
99
100 int YQProgressBar::preferredHeight()
101 {
102     return sizeHint().height();
103 }
104
105
106 void YQProgressBar::setSize( int newWidth, int newHeight )
107 {
108     resize( newWidth, newHeight );
109 }
110
111
112 bool YQProgressBar::setKeyboardFocus()
113 {
114     _qt_progressbar->setFocus();
115
116     return true;
117 }
118
119
120 #include "YQProgressBar.moc"