File indexing completed on 2024-04-28 04:49:49
0001 /* 0002 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "k3bbusywidget.h" 0008 0009 #include <QTimer> 0010 #include <QPainter> 0011 #include <QFrame> 0012 0013 0014 K3b::BusyWidget::BusyWidget( QWidget* parent ) 0015 : QFrame( parent ) 0016 { 0017 m_busyTimer = new QTimer( this ); 0018 m_iBusyPosition = 0; 0019 0020 connect( m_busyTimer, SIGNAL(timeout()), this, SLOT(animateBusy()) ); 0021 0022 m_bBusy = false; 0023 } 0024 0025 K3b::BusyWidget::~BusyWidget() 0026 { 0027 } 0028 0029 0030 void K3b::BusyWidget::showBusy( bool b ) 0031 { 0032 m_bBusy = b; 0033 0034 // if( b ) { 0035 // m_iBusyCounter++; 0036 // } 0037 // else if( m_iBusyCounter > 0 ) { 0038 // m_iBusyCounter--; 0039 // } 0040 0041 if( m_bBusy ) { 0042 if( !m_busyTimer->isActive() ) 0043 m_busyTimer->start( 500 ); 0044 } 0045 else { 0046 if( m_busyTimer->isActive() ) 0047 m_busyTimer->stop(); 0048 update(); 0049 m_iBusyPosition = 0; 0050 } 0051 } 0052 0053 0054 void K3b::BusyWidget::animateBusy() 0055 { 0056 m_iBusyPosition++; 0057 update(); 0058 } 0059 0060 0061 QSize K3b::BusyWidget::sizeHint() const 0062 { 0063 return minimumSizeHint(); 0064 } 0065 0066 0067 QSize K3b::BusyWidget::minimumSizeHint() const 0068 { 0069 return QSize( 2*frameWidth() + 62, 10 ); 0070 } 0071 0072 0073 void K3b::BusyWidget::paintEvent( QPaintEvent* ) 0074 { 0075 QPainter p(this); 0076 QRect rect = contentsRect(); 0077 0078 int squareSize = 8; 0079 0080 int pos = 2 + m_iBusyPosition * (squareSize + 2); 0081 0082 // check if the position is in the visible area 0083 if( pos + 8 + 2> rect.width() ) { 0084 m_iBusyPosition = 0; 0085 pos = 2; 0086 } 0087 0088 // p->eraseRect( rect ); 0089 if( m_bBusy ) 0090 p.fillRect( pos, (rect.height() - squareSize)/2, squareSize, squareSize, palette().highlight() ); 0091 } 0092 0093 #include "moc_k3bbusywidget.cpp"