From 1cd64ce0fd669612dd8f2298c348509640a13068 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 25 Jan 2017 22:41:23 +0100 Subject: [PATCH] improved EE --- retroshare-gui/src/gui/AboutWidget.cpp | 211 +++++++++++++++++++++---- retroshare-gui/src/gui/AboutWidget.h | 21 ++- 2 files changed, 194 insertions(+), 38 deletions(-) diff --git a/retroshare-gui/src/gui/AboutWidget.cpp b/retroshare-gui/src/gui/AboutWidget.cpp index ff8faf431..46932b33a 100644 --- a/retroshare-gui/src/gui/AboutWidget.cpp +++ b/retroshare-gui/src/gui/AboutWidget.cpp @@ -55,6 +55,7 @@ AboutWidget::AboutWidget(QWidget* parent) frame->setContentsMargins(0, 0, 0, 0); frame->setLayout(l); tWidget = NULL; + aWidget = NULL; installAWidget(); updateTitle(); @@ -65,10 +66,14 @@ AboutWidget::AboutWidget(QWidget* parent) void AboutWidget::installAWidget() { assert(tWidget == NULL); - AWidget* aWidget = new AWidget(); + aWidget = new AWidget(); QVBoxLayout* l = (QVBoxLayout*)frame->layout(); l->insertWidget(0, aWidget); l->setStretchFactor(aWidget, 100); + aWidget->setFocus(); + + delete tWidget ; + tWidget = NULL; } void AboutWidget::installTWidget() { @@ -105,6 +110,9 @@ void AboutWidget::installTWidget() { connect(this, SIGNAL(si_levelChanged(QString)), levelLabel, SLOT(setText(QString))); tWidget->setFocus(); tWidget->start(); + + delete aWidget ; + aWidget = NULL; } void AboutWidget::switchPages() { @@ -142,21 +150,26 @@ void AboutWidget::updateTitle() } } -void AboutWidget::keyPressEvent(QKeyEvent *e) { - if (e->key() == Qt::Key_T) { - switchPages(); - } else if (tWidget!=NULL && (e->key() == Qt::Key_P || e->key() == Qt::Key_Pause)) { - tWidget->pause(); - } - QWidget::keyPressEvent(e); -} +//void AboutWidget::keyPressEvent(QKeyEvent *e) { +// if(aWidget != NULL) +// aWidget->keyPressEvent(e) ; +//} void AboutWidget::mousePressEvent(QMouseEvent *e) { QPoint globalPos = mapToGlobal(e->pos()); QPoint framePos = frame->mapFromGlobal(globalPos); + if (frame->contentsRect().contains(framePos)) { - switchPages(); + { + if(e->modifiers() & Qt::ControlModifier) + switchPages(); + else + { + if(aWidget) + aWidget->switchState(); + } + } } QWidget::mousePressEvent(e); } @@ -167,6 +180,26 @@ void AboutWidget::on_help_button_clicked() helpdlg.exec(); } +void AWidget::switchState() +{ + mState = 1 - mState ; + + if(mState == 1) + { + mStep = 1 ; + initGoL(); + drawBitField(); + + mTimerId = startTimer(50); + } + else + killTimer(mTimerId); + + + update(); + +} + void AWidget::resizeEvent(QResizeEvent *e) { mImagesReady = false ; @@ -180,8 +213,6 @@ void AWidget::initImages() image1 = QImage(width(),height(),QImage::Format_ARGB32); image1.fill(palette().color(QPalette::Background)); - std::cerr << "width=" << width() << ", height=" << height() << std::endl; - //QImage image(":/images/logo/logo_info.png"); QPixmap image(":/images/logo/logo_splash.png"); QPainter p(&image1); @@ -204,32 +235,130 @@ void AWidget::initImages() // setFixedSize(image1.size()); image2 = image1 ; + mImagesReady = true ; + + initGoL(); + drawBitField(); + + update() ; +} + +void AWidget::initGoL() +{ + int w = image1.width(); + int h = image1.height(); + + int s = mStep ; // pixels per cell + int bw = w/s ; + int bh = h/s ; + + bitfield1.clear(); + + bitfield1.resize(bw*bh,0); + + for(int i=0;i= mMaxStep) + { + for(int i=0;i<=bh;++i) p.drawLine(0,i*s,bw*s,i*s) ; + for(int i=0;i<=bw;++i) p.drawLine(i*s,0,i*s,bh*s) ; + } + + p.setPen(Qt::black); + + for(int i=0;i= mMaxStep) + computeNextState(); + else + { + initGoL(); + mStep++ ; + } + + drawBitField(); + +#ifdef REMOVED drawWater((QRgb*)image1.bits(), (QRgb*)image2.bits()); calcWater(page, density); page ^= 1; @@ -241,6 +370,7 @@ void AWidget::timerEvent(QTimerEvent* e) { int y = 1 + r + qrand()%(image1.height()-2*r-1); addBlob(x, y, r, h); } +#endif update(); QObject::timerEvent(e); @@ -249,15 +379,29 @@ void AWidget::timerEvent(QTimerEvent* e) { void AWidget::paintEvent(QPaintEvent* e) { - QWidget::paintEvent(e); - - if(!mImagesReady) - initImages(); + QWidget::paintEvent(e); - QPainter p(this); - p.drawImage(0, 0, image1); + switch(mState) + { + default: + case 0: + { + if(!mImagesReady) initImages(); + QPainter p(this); + p.drawImage(0, 0, image1); + } + break; + + case 1: + { + QPainter p(this); + p.drawImage(0, 0, image2); + } + break; + } } +#ifdef REMOVED void AWidget::mouseMoveEvent(QMouseEvent* e) { QPoint point = e->pos(); addBlob(point.x() - 15,point.y(), 5, 400); @@ -274,11 +418,11 @@ void AWidget::calcWater(int npage, int density) { int *newptr; int *oldptr; if(npage == 0) { - newptr = &heightField1.front(); - oldptr = &heightField2.front(); + newptr = &bitfield1.front(); + oldptr = &bitfield2.front(); } else { - newptr = &heightField2.front(); - oldptr = &heightField1.front(); + newptr = &bitfield2.front(); + oldptr = &bitfield1.front(); } for (int y = (h-1)*w; count < y; count += 2) { @@ -307,10 +451,10 @@ void AWidget::addBlob(int x, int y, int radius, int height) { int *newptr; // int *oldptr; if (page == 0) { - newptr = &heightField1.front(); + newptr = &bitfield1.front(); // oldptr = &heightField2.front(); } else { - newptr = &heightField2.front(); + newptr = &bitfield2.front(); // oldptr = &heightField1.front(); } @@ -344,7 +488,7 @@ void AWidget::drawWater(QRgb* srcImage,QRgb* dstImage) { int lIndex; int lBreak = w * h; - int *ptr = &heightField1.front(); + int *ptr = &bitfield1.front(); for (int y = (h-1)*w; offset < y; offset += 2) { for (int x = offset+w-2; offset < x; ++offset) { @@ -370,6 +514,7 @@ void AWidget::drawWater(QRgb* srcImage,QRgb* dstImage) { } } } +#endif ////////////////////////////////////////////////////////////////////////// // T diff --git a/retroshare-gui/src/gui/AboutWidget.h b/retroshare-gui/src/gui/AboutWidget.h index fa891b740..51a056bcd 100644 --- a/retroshare-gui/src/gui/AboutWidget.h +++ b/retroshare-gui/src/gui/AboutWidget.h @@ -58,7 +58,7 @@ signals: void si_levelChanged(QString); protected: - void keyPressEvent(QKeyEvent *event); + //void keyPressEvent(QKeyEvent *event); void mousePressEvent(QMouseEvent *event); private: void switchPages(); @@ -66,6 +66,7 @@ private: void installTWidget(); void updateTitle(); + AWidget* aWidget; TBoard* tWidget; }; @@ -77,14 +78,18 @@ class AWidget : public QWidget { public: AWidget(); + void switchState() ; + protected: void timerEvent(QTimerEvent* e); void paintEvent(QPaintEvent* e); - void mouseMoveEvent(QMouseEvent* e); + //void mouseMoveEvent(QMouseEvent* e); void resizeEvent(QResizeEvent *); - + //void keyPressEvent(QKeyEvent *e); + private: void initImages(); + void computeNextState(); void calcWater(int npage, int density); void addBlob(int x, int y, int radius, int height); @@ -96,15 +101,21 @@ private: qBound(0, qGreen(color) - shift,255), qBound(0, qBlue(color) - shift, 255)); } + void initGoL(); + void drawBitField(); int page; int density; - QVector heightField1; - QVector heightField2; + std::vector bitfield1; + std::vector bitfield2; QImage image1; QImage image2; bool mImagesReady ; + int mState; + int mTimerId; + int mStep; + int mMaxStep; }; //////////////////////////////////////////////////////////////////////////