@@ -46,6 +46,7 @@ namespace hal {
4646 BusyIndicator::BusyIndicator (QWidget* parent)
4747 : AbstractBusyIndicator(parent)
4848 {
49+ mMutex = new QMutex;
4950 QVBoxLayout* layout = new QVBoxLayout (this );
5051 layout->setAlignment (Qt::AlignHCenter);
5152 layout->addWidget (mLabel = new QLabel (this ));
@@ -60,12 +61,18 @@ namespace hal {
6061 BusyIndicator::~BusyIndicator ()
6162 {
6263 mTimer ->stop ();
64+ delete mMutex ;
6365 }
6466
6567 BusyAnimation::BusyAnimation (QWidget* parent)
66- : QWidget(parent), mImage (QImage(" :/icons/hal9000" ," PNG" )), mAngle (0 )
68+ : QWidget(parent), mImage (QImage(" :/icons/hal9000" ," PNG" )), mAngle (0 ), mMutex ( new QMutex)
6769 {;}
6870
71+ BusyAnimation::~BusyAnimation ()
72+ {
73+ delete mMutex ;
74+ }
75+
6976 void BusyAnimation::handleTimeout ()
7077 {
7178 mAngle += 5 ;
@@ -76,50 +83,57 @@ namespace hal {
7683 void BusyAnimation::paintEvent (QPaintEvent* event)
7784 {
7885 Q_UNUSED (event);
79- QPainter p (this );
80- p.setRenderHint (QPainter::Antialiasing);
86+ if (mMutex ->try_lock ())
87+ {
88+ QPainter p (this );
89+ p.setRenderHint (QPainter::Antialiasing);
8190
82- int rw = rect ().width ();
83- int rh = rect ().height ();
91+ int rw = rect ().width ();
92+ int rh = rect ().height ();
8493
85- int w = rw > rh ? rh : rw;
86- int h = w;
94+ int w = rw > rh ? rh : rw;
95+ int h = w;
8796
88- QRect rimg ((rw-w)/2 ,(rh-h)/2 ,w,h);
97+ QRect rimg ((rw-w)/2 ,(rh-h)/2 ,w,h);
8998
90- // p.fillRect(rimg,QBrush(Qt::gray));
91- QImage img = mImage .scaled (w,h);
92- double xc = w / 2 .;
93- double yc = h / 2 .;
99+ // p.fillRect(rimg,QBrush(Qt::gray));
100+ QImage img = mImage .scaled (w,h);
101+ double xc = w / 2 .;
102+ double yc = h / 2 .;
94103
95- for (int y = 0 ; y<h; y++)
96- for (int x=0 ; x<w; x++)
97- {
98- QRgb col = img.pixel (x,y);
99- if (col & 0xFF000000 )
104+ for (int y = 0 ; y<h; y++)
105+ for (int x=0 ; x<w; x++)
100106 {
101- double angle = atan2 (y-yc,x-xc) / M_PI * 180 .;
102- double da = angle >= mAngle ? angle - mAngle : angle + 360 . - mAngle ;
103- int opaque = floor (da / 360 .*256 );
104- opaque <<= 24 ;
105- col = (col & 0xFFFFFF ) | opaque;
106- img.setPixel (x,y,col);
107+ QRgb col = img.pixel (x,y);
108+ if (col & 0xFF000000 )
109+ {
110+ double angle = atan2 (y-yc,x-xc) / M_PI * 180 .;
111+ double da = angle >= mAngle ? angle - mAngle : angle + 360 . - mAngle ;
112+ int opaque = floor (da / 360 .*256 );
113+ opaque <<= 24 ;
114+ col = (col & 0xFFFFFF ) | opaque;
115+ img.setPixel (x,y,col);
116+ }
107117 }
108- }
109118
110- p.drawImage (rimg,img);
119+ p.drawImage (rimg,img);
120+ mMutex ->unlock ();
121+ }
111122 }
112123
113124 void BusyIndicator::setValue (int percent)
114125 {
126+ if (mProgressBar ->value () == percent) return ; // nothing to do
127+ QMutexLocker lock (mMutex );
115128 mProgressBar ->setValue (percent);
116129 update ();
117130 qApp->processEvents ();
118131 }
119132
120133 void BusyIndicator::setText (const QString &txt)
121134 {
122- if (mLabel ->text () == txt) return ;
135+ if (mLabel ->text () == txt) return ; // nothing to do
136+ QMutexLocker lock (mMutex );
123137 mLabel ->setText (txt);
124138 qApp->processEvents ();
125139 }
0 commit comments