diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 08e097578..2ff3c7436 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -198,6 +198,7 @@ ChatWidget::ChatWidget(QWidget *parent) : ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages()); ui->textBrowser->setImageBlockWidget(ui->imageBlockWidget); + ui->imageBlockWidget->setAutoHide(true); ui->textBrowser->installEventFilter(this); ui->textBrowser->viewport()->installEventFilter(this); ui->chatTextEdit->installEventFilter(this); diff --git a/retroshare-gui/src/gui/common/RSImageBlockWidget.cpp b/retroshare-gui/src/gui/common/RSImageBlockWidget.cpp index 98f6193c3..f2d62452f 100644 --- a/retroshare-gui/src/gui/common/RSImageBlockWidget.cpp +++ b/retroshare-gui/src/gui/common/RSImageBlockWidget.cpp @@ -26,15 +26,28 @@ RSImageBlockWidget::RSImageBlockWidget(QWidget *parent) : QWidget(parent), - ui(new Ui::RSImageBlockWidget) + ui(new Ui::RSImageBlockWidget), + mAutoHide(false), mAutoHideHeight(4), mAutoHideTimeToStart(3000), mAutoHideDuration(3000) { ui->setupUi(this); + mDefaultRect = this->geometry(); + + ui->infoFrame->installEventFilter(this); + + mTimer = new RsProtectedTimer(this); + mTimer->setSingleShot(true); + connect(mTimer, SIGNAL(timeout()), this, SLOT(startAutoHide())); + + mAnimation = new QPropertyAnimation(this, "geometry"); connect(ui->loadImagesButton, SIGNAL(clicked()), this, SIGNAL(showImages())); } RSImageBlockWidget::~RSImageBlockWidget() { + delete mAnimation; + mTimer->stop(); + delete mTimer; delete ui; } @@ -64,3 +77,61 @@ void RSImageBlockWidget::addButtonAction(const QString &text, const QObject *rec connect(action, SIGNAL(triggered()), this, SIGNAL(showImages())); } } + +bool RSImageBlockWidget::eventFilter(QObject *obj, QEvent *event) +{ + if (mAutoHide) { + if (event->type() == QEvent::Show) { + mTimer->start(mAutoHideTimeToStart); + } + if (event->type() == QEvent::Hide) { + mTimer->stop(); + } + if (event->type() == QEvent::Enter) { + mAnimation->stop(); + this->setGeometry(mDefaultRect); + this->updateGeometry(); + mTimer->start(mAutoHideTimeToStart); + mAnimation->setCurrentTime(0); + } + } + if (mAnimation->currentTime() == 0) { + mDefaultRect = this->geometry(); + } else if (mAnimation->state() == QAbstractAnimation::Running) { + this->updateGeometry(); + } + + // pass the event on to the parent class + return QObject::eventFilter(obj, event); +} + +void RSImageBlockWidget::setAutoHide(const bool value) +{ + if(value && !mAutoHide) { + if (this->isVisible()) mTimer->start(mAutoHideTimeToStart); + } else if (!value && mAutoHide) { + mTimer->stop(); + } + mAutoHide = value; +} + +void RSImageBlockWidget::startAutoHide() +{ + QRect r = mDefaultRect; + r.setHeight(mAutoHideHeight); + this->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Preferred); + mAnimation->setDuration(mAutoHideDuration); + mAnimation->setStartValue(mDefaultRect); + mAnimation->setEndValue(r); + + mAnimation->start(); +} + +QSize RSImageBlockWidget::sizeHint() const +{ + if (mAnimation->currentTime() == 0) { + return mDefaultRect.size(); + } else { + return mAnimation->currentValue().toRect().size(); + } +} diff --git a/retroshare-gui/src/gui/common/RSImageBlockWidget.h b/retroshare-gui/src/gui/common/RSImageBlockWidget.h index f4dfffbfc..b435fbfbf 100644 --- a/retroshare-gui/src/gui/common/RSImageBlockWidget.h +++ b/retroshare-gui/src/gui/common/RSImageBlockWidget.h @@ -22,8 +22,11 @@ #ifndef RSIMAGEBLOCKWIDGET_H #define RSIMAGEBLOCKWIDGET_H +#include #include +#include "util/RsProtectedTimer.h" + namespace Ui { class RSImageBlockWidget; } @@ -32,17 +35,48 @@ class RSImageBlockWidget : public QWidget { Q_OBJECT + Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide) + Q_PROPERTY(int autoHideHeight READ autoHideHeight WRITE setAutoHideHeight) + Q_PROPERTY(int autoHideTimeToStart READ autoHideTimeToStart WRITE setAutoHideTimeToStart) + Q_PROPERTY(int autoHideDuration READ autoHideDuration WRITE setAutoHideDuration) + public: explicit RSImageBlockWidget(QWidget *parent = 0); ~RSImageBlockWidget(); void addButtonAction(const QString &text, const QObject *receiver, const char *member, bool standardAction); + virtual QSize sizeHint() const;//To update parent layout. + virtual QSize minimumSizeHint() const { return sizeHint();}//To update parent layout. + + bool autoHide() { return mAutoHide; } + int autoHideHeight() { return mAutoHideHeight; } + int autoHideTimeToStart() { return mAutoHideTimeToStart; } + int autoHideDuration() { return mAutoHideDuration; } + + void setAutoHide(const bool value); + void setAutoHideHeight(const int value) { mAutoHideHeight = value; } + void setAutoHideTimeToStart(const int value) { mAutoHideTimeToStart = value; } + void setAutoHideDuration(const int value) { mAutoHideDuration = value; } + signals: void showImages(); +private slots: + void startAutoHide(); + +protected: + bool eventFilter(QObject *obj, QEvent *event); + private: Ui::RSImageBlockWidget *ui; + QPropertyAnimation *mAnimation; + QRect mDefaultRect; + RsProtectedTimer *mTimer; + bool mAutoHide; + int mAutoHideHeight; + int mAutoHideTimeToStart; + int mAutoHideDuration; }; #endif // RSIMAGEBLOCKWIDGET_H diff --git a/retroshare-gui/src/gui/common/RSImageBlockWidget.ui b/retroshare-gui/src/gui/common/RSImageBlockWidget.ui index 37f1c54b8..ffae88bad 100644 --- a/retroshare-gui/src/gui/common/RSImageBlockWidget.ui +++ b/retroshare-gui/src/gui/common/RSImageBlockWidget.ui @@ -13,11 +13,20 @@ Form - + 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -92,8 +101,17 @@ QFrame::Box - - + + + 6 + + + 6 + + + 6 + + 6 @@ -114,7 +132,7 @@ - + Qt::Horizontal diff --git a/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp b/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp index 3d29f2cc9..fac2af2d4 100644 --- a/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp +++ b/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp @@ -3,7 +3,6 @@ #include "retroshare/rspeers.h" #include "retroshare/rsservicecontrol.h" -#include "util/RsProtectedTimer.h" #include "retroshare-gui/RsAutoUpdatePage.h" #include "BandwidthStatsWidget.h"