libyui-qt  2.47.1
YQProgressBar.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: YQProgressBar.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #include <qprogressbar.h>
27 #include <QVBoxLayout>
28 
29 #include <qlabel.h>
30 #define YUILogComponent "qt-ui"
31 #include <yui/YUILog.h>
32 
33 using std::max;
34 
35 #include "utf8.h"
36 #include "YQUI.h"
37 #include "YQProgressBar.h"
38 #include "YQWidgetCaption.h"
39 
40 
41 YQProgressBar::YQProgressBar( YWidget * parent,
42  const std::string & label,
43  int maxValue )
44  : QFrame( (QWidget *) parent->widgetRep() )
45  , YProgressBar( parent, label, maxValue )
46 {
47  QVBoxLayout* layout = new QVBoxLayout( this );
48  setLayout( layout );
49 
50  setWidgetRep( this );
51 
52  layout->setSpacing( YQWidgetSpacing );
53  layout->setMargin ( YQWidgetMargin );
54 
55  _caption = new YQWidgetCaption( this, label );
56  YUI_CHECK_NEW( _caption );
57  layout->addWidget( _caption );
58 
59  _qt_progressbar = new QProgressBar( this );
60  _qt_progressbar->setRange(0, maxValue);
61  YUI_CHECK_NEW( _qt_progressbar );
62  layout->addWidget( _qt_progressbar );
63 
64  _caption->setBuddy( _qt_progressbar );
65 }
66 
67 
69 {
70  // NOP
71 }
72 
73 
74 void YQProgressBar::setLabel( const std::string & label )
75 {
76  _caption->setText( label );
77  YProgressBar::setLabel( label );
78 }
79 
80 
81 void YQProgressBar::setValue( int newValue )
82 {
83  YProgressBar::setValue( newValue );
84  _qt_progressbar->setValue( value() );
85 }
86 
87 
88 
89 void YQProgressBar::setEnabled( bool enabled )
90 {
91  _caption->setEnabled( enabled );
92  _qt_progressbar->setEnabled( enabled );
93  YWidget::setEnabled( enabled );
94 }
95 
96 
98 {
99  int hintWidth = !_caption->isHidden() ?
100  _caption->sizeHint().width() + layout()->margin() : 0;
101 
102  return max( 200, hintWidth );
103 }
104 
105 
107 {
108  return sizeHint().height();
109 }
110 
111 
112 void YQProgressBar::setSize( int newWidth, int newHeight )
113 {
114  resize( newWidth, newHeight );
115 }
116 
117 
119 {
120  _qt_progressbar->setFocus();
121 
122  return true;
123 }
124 
125 
126 #include "YQProgressBar.moc"
YQProgressBar::setLabel
virtual void setLabel(const std::string &label)
Set the label (the caption above the progress bar).
Definition: YQProgressBar.cc:74
YQProgressBar::YQProgressBar
YQProgressBar(YWidget *parent, const std::string &label, int maxValue=100)
Constructor.
Definition: YQProgressBar.cc:41
YQProgressBar::setSize
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQProgressBar.cc:112
YQWidgetCaption::setText
virtual void setText(const std::string &newText)
Change the text and handle visibility: If the new text is empty, hide this widget.
Definition: YQWidgetCaption.cc:56
YQProgressBar::preferredHeight
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQProgressBar.cc:106
YQProgressBar::setKeyboardFocus
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQProgressBar.cc:118
YQProgressBar::setValue
virtual void setValue(int newValue)
Set the current progress value ( <= maxValue() ).
Definition: YQProgressBar.cc:81
YQProgressBar::preferredWidth
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQProgressBar.cc:97
YQProgressBar::setEnabled
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQProgressBar.cc:89
YQWidgetCaption
Helper class for captions (labels) above a widget: Takes care of hiding itself when its text is empty...
Definition: YQWidgetCaption.h:38
YQProgressBar::~YQProgressBar
virtual ~YQProgressBar()
Destructor.
Definition: YQProgressBar.cc:68