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. 30
      src/lib/WaitAnimationWidget.cpp
  5. 3
      src/lib/WaitAnimationWidget.h
  6. 2
      src/main.cpp
  7. 6
      src/mainwindow.cpp

@ -19,15 +19,27 @@
***************************************************************************/ ***************************************************************************/
#include <QPainter> #include <QPainter>
#include <QCursor>
#include "CollectEntropyDlg.h" #include "CollectEntropyDlg.h"
#include "main.h" #include "main.h"
CollectEntropyDlg::CollectEntropyDlg(QWidget* parent):QDialog(parent){ CollectEntropyDlg::CollectEntropyDlg(QWidget* parent):QDialog(parent){
setupUi(this); 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){ void CollectEntropyDlg::paintEvent(QPaintEvent *event){
@ -36,3 +48,39 @@ void CollectEntropyDlg::paintEvent(QPaintEvent *event){
painter.setClipRegion(event->region()); painter.setClipRegion(event->region());
painter.drawPixmap(QPoint(0,0),BannerPixmap); 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 "ui_CollectEntropyDlg.h"
#include <QDialog> #include <QDialog>
#include <QPaintEvent> #include <QPaintEvent>
#include <QShowEvent>
class CollectEntropyDlg: public QDialog, public Ui_CollectEntropyDlg{ class CollectEntropyDlg: public QDialog, public Ui_CollectEntropyDlg{
Q_OBJECT Q_OBJECT
public: public:
CollectEntropyDlg(QWidget* parent); CollectEntropyDlg(QWidget* parent);
~CollectEntropyDlg();
private: private:
QPixmap BannerPixmap; QPixmap BannerPixmap;
virtual void paintEvent(QPaintEvent* event); 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> <bool>true</bool>
</property> </property>
</widget> </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" > <widget class="QDialogButtonBox" name="buttonBox" >
<property name="geometry" > <property name="geometry" >
<rect> <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" > <widget class="WaitAnimationWidget" native="1" name="Animation" >
<property name="geometry" > <property name="geometry" >
<rect> <rect>
<x>420</x> <x>8</x>
<y>10</y> <y>5</y>
<width>41</width> <width>41</width>
<height>41</height> <height>41</height>
</rect> </rect>
</property> </property>
</widget> </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> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

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

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

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

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