30 #include <QVBoxLayout>
35 #define YUILogComponent "qt-ui"
36 #include <yui/YUILog.h>
42 #include "YQBusyIndicator.h"
43 #include "YQWidgetCaption.h"
46 #define REPAINT_INTERVAL 100
48 #define MINIMUM_WITDH 100
49 #define MINIMUM_HEIGHT 24
52 BusyBar::BusyBar(QWidget *parent)
58 setMinimumSize(MINIMUM_WITDH, MINIMUM_HEIGHT);
60 _timer =
new QTimer(
this);
61 connect(_timer, &pclass(_timer)::timeout,
this, &pclass(
this)::update);
62 _timer->start(REPAINT_INTERVAL);
64 setFrameStyle (QFrame::Panel | QFrame::Sunken );
69 void BusyBar::update()
74 if (_position > 1.0 - STEP_SIZE || _position < STEP_SIZE )
75 _rightwards = !_rightwards;
78 _position += STEP_SIZE;
80 _position -= STEP_SIZE;
95 void BusyBar::paintEvent( QPaintEvent * e )
98 QPalette palette = QApplication::palette();
99 QColor foreground = palette.color( QPalette::Active, QPalette::Highlight );
100 QColor background = palette.color( QPalette::Active, QPalette::Base );
102 QPainter painter(
this);
103 QLinearGradient gradient(0, 0, width()-1, 0 );
105 gradient.setColorAt( 0.0, background );
106 gradient.setColorAt( _position, foreground );
107 gradient.setColorAt( 1.0, background );
109 painter.setBrush( gradient );
110 painter.setPen( Qt::NoPen );
111 painter.drawRect( rect() );
114 QFrame::paintEvent( e );
119 const std::string & label,
121 : QFrame( (QWidget *) parent->widgetRep() )
122 , YBusyIndicator( parent, label, timeout )
126 _timer =
new QTimer(
this);
127 connect(_timer, &pclass(_timer)::timeout,
this, &pclass(
this)::setStalled);
128 _timer->start(_timeout);
130 QVBoxLayout* layout =
new QVBoxLayout(
this );
133 setWidgetRep(
this );
135 layout->setSpacing( YQWidgetSpacing );
136 layout->setMargin ( YQWidgetMargin );
139 YUI_CHECK_NEW( _caption );
140 layout->addWidget( _caption );
143 YUI_CHECK_NEW ( _bar );
144 layout->addWidget( _bar );
145 _caption->setBuddy( _bar );
159 YBusyIndicator::setLabel( label );
165 YBusyIndicator::setAlive( newAlive );
170 _timer->start(_timeout);
180 void YQBusyIndicator::setStalled()
188 _timeout = newTimeout;
189 YBusyIndicator::setTimeout( newTimeout );
195 _caption->setEnabled( enabled );
196 _bar->setEnabled( enabled );
197 YWidget::setEnabled( enabled );
203 int hintWidth = !_caption->isHidden() ?
204 _caption->sizeHint().width() + layout()->margin() : 0;
206 return max( 200, hintWidth );
212 return sizeHint().height();
218 resize( newWidth, newHeight );
230 #include "YQBusyIndicator.moc"
virtual void setLabel(const std::string &label)
Set the label (the caption above the progress bar).
virtual int preferredHeight()
Preferred height of the widget.
void run()
start moving bar animation
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual int preferredWidth()
Preferred width of the widget.
void stop()
stop moving bar animation
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
virtual void setAlive(bool newAlive)
Send a keep allive message.
virtual void setTimeout(int newTimeout)
Set the timeout is ms after that the widget shows 'stalled' when no new tick is received.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
YQBusyIndicator(YWidget *parent, const std::string &label, int timeout=1000)
Constructor.
virtual ~YQBusyIndicator()
Destructor.