30 #include <QVBoxLayout>
35 #define YUILogComponent "qt-ui"
36 #include <yui/YUILog.h>
40 #include "YQBusyIndicator.h"
41 #include "YQWidgetCaption.h"
44 #define REPAINT_INTERVAL 100
46 #define MINIMUM_WITDH 100
47 #define MINIMUM_HEIGHT 24
53 BusyBar::BusyBar(QWidget *parent)
59 setMinimumSize(MINIMUM_WITDH, MINIMUM_HEIGHT);
61 _timer =
new QTimer(
this);
62 connect(_timer, &pclass(_timer)::timeout,
this, &pclass(
this)::update);
63 _timer->start(REPAINT_INTERVAL);
65 setFrameStyle (QFrame::Panel | QFrame::Sunken );
70 void BusyBar::update()
75 if (_position > 1.0 - STEP_SIZE || _position < STEP_SIZE )
76 _rightwards = !_rightwards;
79 _position += STEP_SIZE;
81 _position -= STEP_SIZE;
96 void BusyBar::paintEvent( QPaintEvent * e )
99 QPalette palette = QApplication::palette();
100 QColor foreground = palette.color( QPalette::Active, QPalette::Highlight );
101 QColor background = palette.color( QPalette::Active, QPalette::Base );
103 QPainter painter(
this);
104 QLinearGradient gradient(0, 0, width()-1, 0 );
106 gradient.setColorAt( 0.0, background );
107 gradient.setColorAt( _position, foreground );
108 gradient.setColorAt( 1.0, background );
110 painter.setBrush( gradient );
111 painter.setPen( Qt::NoPen );
112 painter.drawRect( rect() );
115 QFrame::paintEvent( e );
120 const string & label,
122 : QFrame( (QWidget *) parent->widgetRep() )
123 , YBusyIndicator( parent, label, timeout )
127 _timer =
new QTimer(
this);
128 connect(_timer, &pclass(_timer)::
timeout,
this, &pclass(
this)::setStalled);
129 _timer->start(_timeout);
131 QVBoxLayout* layout =
new QVBoxLayout(
this );
134 setWidgetRep(
this );
136 layout->setSpacing( YQWidgetSpacing );
137 layout->setMargin ( YQWidgetMargin );
140 YUI_CHECK_NEW( _caption );
141 layout->addWidget( _caption );
144 YUI_CHECK_NEW ( _bar );
145 layout->addWidget( _bar );
146 _caption->setBuddy( _bar );
160 YBusyIndicator::setLabel( label );
166 YBusyIndicator::setAlive( newAlive );
171 _timer->start(_timeout);
181 void YQBusyIndicator::setStalled()
189 _timeout = newTimeout;
190 YBusyIndicator::setTimeout( newTimeout );
196 _caption->setEnabled( enabled );
197 _bar->setEnabled( enabled );
198 YWidget::setEnabled( enabled );
204 int hintWidth = !_caption->isHidden() ?
205 _caption->sizeHint().width() + layout()->margin() : 0;
207 return std::max( 200, hintWidth );
213 return sizeHint().height();
219 resize( newWidth, newHeight );