CollectEntryDlg: fixed random crashes caused by first external paint event, finished collection routines.

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@109 b624d157-de02-0410-bad0-e51aec6abb33
master
tarek_saidi 18 years ago
parent 83d561d3a4
commit 29f3d8b2b3
  1. 54
      src/dialogs/CollectEntropyDlg.cpp
  2. 12
      src/dialogs/CollectEntropyDlg.h
  3. 42
      src/forms/CollectEntropyDlg.ui
  4. 50
      src/lib/WaitAnimationWidget.cpp
  5. 3
      src/lib/WaitAnimationWidget.h
  6. 8
      src/main.cpp
  7. 6
      src/mainwindow.cpp

@ -19,15 +19,27 @@
***************************************************************************/
#include <QPainter>
#include <QCursor>
#include "CollectEntropyDlg.h"
#include "main.h"
CollectEntropyDlg::CollectEntropyDlg(QWidget* parent):QDialog(parent){
setupUi(this);
createBanner(&BannerPixmap,Icon_Settings32x32,tr("Entropy Collection"),width());
createBanner(&BannerPixmap,NULL,tr("Entropy Collection"),width());
KeyEntropyBuffer=new unsigned char[105];
MouseEntropyBuffer=new quint16[210];
KeyCounter=0;
MouseCounter=0;
QTimer* timer=new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(trackMousePos()));
timer->setInterval(50);
timer->start();
ReseedDone=false;
}
CollectEntropyDlg::~CollectEntropyDlg(){
delete [] KeyEntropyBuffer;
delete [] MouseEntropyBuffer;
}
void CollectEntropyDlg::paintEvent(QPaintEvent *event){
@ -36,3 +48,39 @@ void CollectEntropyDlg::paintEvent(QPaintEvent *event){
painter.setClipRegion(event->region());
painter.drawPixmap(QPoint(0,0),BannerPixmap);
}
void CollectEntropyDlg::trackMousePos(){
QPoint p=QCursor::pos();
if(LastPos-p==QPoint(0,0))return;
LastPos=p;
if(MouseCounter==105 || ReseedDone)return;
MouseEntropyBuffer[2*MouseCounter]=p.x();
MouseEntropyBuffer[2*MouseCounter+1]=p.y();
MouseCounter++;
updateProgress();
}
void CollectEntropyDlg::keyReleaseEvent(QKeyEvent* event ){
QDialog::keyReleaseEvent(event);
if(KeyCounter==105 || ReseedDone)return;
KeyEntropyBuffer[KeyCounter]=event->key();
KeyCounter++;
updateProgress();
}
void CollectEntropyDlg::updateProgress(){
if(4*KeyCounter+4*MouseCounter>=420){
progressBar->setValue(420);
ReseedDone=true;
}
else
progressBar->setValue(4*KeyCounter+4*MouseCounter);
}
void CollectEntropyDlg::showEvent(QShowEvent* event){
if(!event->spontaneous()){
Animation->start();
}
}

@ -24,15 +24,27 @@
#include "ui_CollectEntropyDlg.h"
#include <QDialog>
#include <QPaintEvent>
#include <QShowEvent>
class CollectEntropyDlg: public QDialog, public Ui_CollectEntropyDlg{
Q_OBJECT
public:
CollectEntropyDlg(QWidget* parent);
~CollectEntropyDlg();
private:
QPixmap BannerPixmap;
virtual void paintEvent(QPaintEvent* event);
virtual void keyReleaseEvent(QKeyEvent* event );
virtual void showEvent(QShowEvent* event);
void updateProgress();
unsigned char* KeyEntropyBuffer;
quint16* MouseEntropyBuffer;
int KeyCounter,MouseCounter;
QPoint LastPos;
bool ReseedDone;
private slots:
void trackMousePos();
};

@ -32,22 +32,6 @@ Please move the mouse and/or press some keys until enought entropy for a reseed
<bool>true</bool>
</property>
</widget>
<widget class="QProgressBar" name="progressBar" >
<property name="geometry" >
<rect>
<x>70</x>
<y>140</y>
<width>391</width>
<height>23</height>
</rect>
</property>
<property name="value" >
<number>24</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="geometry" >
<rect>
@ -67,13 +51,35 @@ Please move the mouse and/or press some keys until enought entropy for a reseed
<widget class="WaitAnimationWidget" native="1" name="Animation" >
<property name="geometry" >
<rect>
<x>420</x>
<y>10</y>
<x>8</x>
<y>5</y>
<width>41</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QProgressBar" name="progressBar" >
<property name="geometry" >
<rect>
<x>10</x>
<y>140</y>
<width>451</width>
<height>23</height>
</rect>
</property>
<property name="maximum" >
<number>420</number>
</property>
<property name="value" >
<number>0</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="format" >
<string>%v Bits</string>
</property>
</widget>
</widget>
<customwidgets>
<customwidget>

@ -21,6 +21,8 @@
#include <math.h>
#include <QPainter>
#include <QRectF>
#include "PwmConfig.h"
#include "main.h"
#include "WaitAnimationWidget.h"
@ -28,9 +30,28 @@ WaitAnimationWidget::WaitAnimationWidget(QWidget* parent):QWidget(parent){
speed=60;
setRefreshRate(25);
CurAngle=0;
connect(&timer,SIGNAL(timeout()),this,SLOT(refreshAnimation()));
timer.start();
for(int i=0;i<6;i++){
float diff=CurAngle-i*0.16666667f;
if(diff>0.5f)
diff=1.0f-diff;
if(diff<-0.5f)
diff=1.0f+diff;
CircSizes[i]=1.0+exp(-14.0f*diff*diff);
}
connect(&timer,SIGNAL(timeout()),this,SLOT(refreshAnimation()));
}
WaitAnimationWidget::~WaitAnimationWidget(){
timer.stop();
}
void WaitAnimationWidget::start(){
timer.start();
}
void WaitAnimationWidget::stop(){
timer.stop();
repaint();
}
void WaitAnimationWidget::setRefreshRate(int fps){
@ -53,16 +74,17 @@ void WaitAnimationWidget::refreshAnimation(){
}
void WaitAnimationWidget::paintEvent(QPaintEvent* event){
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing,true);
painter.setBrush(QColor(255,255,255));
painter.setPen(QColor(255,255,255));
for(int i=0;i<6;i++){
float d=CircSizes[i]*5.0;
QRectF rect(CircPositions[i].x()-d/2,CircPositions[i].y()-d/2,d,d);
painter.drawEllipse(rect);
}
if(timer.isActive()){
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing,true);
painter.setBrush(config.BannerTextColor);
painter.setPen(config.BannerTextColor);
for(int i=0;i<6;i++){
float d=CircSizes[i]*5.0;
QRectF rect(CircPositions[i].x()-d/2,CircPositions[i].y()-d/2,d,d);
painter.drawEllipse(rect);
}
}
}
void WaitAnimationWidget::resizeEvent(QResizeEvent* event){
@ -75,5 +97,5 @@ void WaitAnimationWidget::resizeEvent(QResizeEvent* event){
CircPositions[i].setX((r-10)*cos(-2.0*3.14159265*(0.16666667*i))+r);
CircPositions[i].setY((r-10)*sin(-2.0*3.14159265*(0.16666667*i))+r);
}
}
}

@ -28,8 +28,11 @@ class WaitAnimationWidget:public QWidget{
Q_OBJECT
public:
WaitAnimationWidget(QWidget* parent);
~WaitAnimationWidget();
void setSpeed(int rpm){speed=rpm;}
void setRefreshRate(int fps);
void start();
void stop();
public slots:
void refreshAnimation();
private:

@ -187,9 +187,11 @@ void createBanner(QPixmap* Pixmap, QPixmap* IconAlpha,const QString& Text,int Wi
painter.drawRect(0,0,Width,50);
QPixmap Icon(32,32);
Icon.fill(TextColor);
Icon.setAlphaChannel(*IconAlpha);
painter.drawPixmap(10,10,Icon);
if(IconAlpha){
Icon.fill(TextColor);
Icon.setAlphaChannel(*IconAlpha);
painter.drawPixmap(10,10,Icon);
}
painter.setPen(QPen(TextColor));
painter.setFont(QFont(QApplication::font().family(),16));

@ -373,13 +373,15 @@ return true;
void KeepassMainWindow::OnFileNewKdb(){
/*
//Test
/*
CollectEntropyDlg dialog(this);
dialog.exec();
return;
//~Test
*/
//~Test
CPasswordDialog dlg(this,true,false,true);
dlg.setWindowTitle("New Database");