mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-27 15:57:08 -05:00
Add AutoHide to RSImageBlockWidget
This commit is contained in:
parent
368a429846
commit
9780f1ff78
@ -198,6 +198,7 @@ ChatWidget::ChatWidget(QWidget *parent) :
|
|||||||
|
|
||||||
ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages());
|
ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages());
|
||||||
ui->textBrowser->setImageBlockWidget(ui->imageBlockWidget);
|
ui->textBrowser->setImageBlockWidget(ui->imageBlockWidget);
|
||||||
|
ui->imageBlockWidget->setAutoHide(true);
|
||||||
ui->textBrowser->installEventFilter(this);
|
ui->textBrowser->installEventFilter(this);
|
||||||
ui->textBrowser->viewport()->installEventFilter(this);
|
ui->textBrowser->viewport()->installEventFilter(this);
|
||||||
ui->chatTextEdit->installEventFilter(this);
|
ui->chatTextEdit->installEventFilter(this);
|
||||||
|
@ -26,15 +26,28 @@
|
|||||||
|
|
||||||
RSImageBlockWidget::RSImageBlockWidget(QWidget *parent) :
|
RSImageBlockWidget::RSImageBlockWidget(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::RSImageBlockWidget)
|
ui(new Ui::RSImageBlockWidget),
|
||||||
|
mAutoHide(false), mAutoHideHeight(4), mAutoHideTimeToStart(3000), mAutoHideDuration(3000)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
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()));
|
connect(ui->loadImagesButton, SIGNAL(clicked()), this, SIGNAL(showImages()));
|
||||||
}
|
}
|
||||||
|
|
||||||
RSImageBlockWidget::~RSImageBlockWidget()
|
RSImageBlockWidget::~RSImageBlockWidget()
|
||||||
{
|
{
|
||||||
|
delete mAnimation;
|
||||||
|
mTimer->stop();
|
||||||
|
delete mTimer;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,3 +77,61 @@ void RSImageBlockWidget::addButtonAction(const QString &text, const QObject *rec
|
|||||||
connect(action, SIGNAL(triggered()), this, SIGNAL(showImages()));
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -22,8 +22,11 @@
|
|||||||
#ifndef RSIMAGEBLOCKWIDGET_H
|
#ifndef RSIMAGEBLOCKWIDGET_H
|
||||||
#define RSIMAGEBLOCKWIDGET_H
|
#define RSIMAGEBLOCKWIDGET_H
|
||||||
|
|
||||||
|
#include <QPropertyAnimation>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "util/RsProtectedTimer.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class RSImageBlockWidget;
|
class RSImageBlockWidget;
|
||||||
}
|
}
|
||||||
@ -32,17 +35,48 @@ class RSImageBlockWidget : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
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:
|
public:
|
||||||
explicit RSImageBlockWidget(QWidget *parent = 0);
|
explicit RSImageBlockWidget(QWidget *parent = 0);
|
||||||
~RSImageBlockWidget();
|
~RSImageBlockWidget();
|
||||||
|
|
||||||
void addButtonAction(const QString &text, const QObject *receiver, const char *member, bool standardAction);
|
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:
|
signals:
|
||||||
void showImages();
|
void showImages();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void startAutoHide();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::RSImageBlockWidget *ui;
|
Ui::RSImageBlockWidget *ui;
|
||||||
|
QPropertyAnimation *mAnimation;
|
||||||
|
QRect mDefaultRect;
|
||||||
|
RsProtectedTimer *mTimer;
|
||||||
|
bool mAutoHide;
|
||||||
|
int mAutoHideHeight;
|
||||||
|
int mAutoHideTimeToStart;
|
||||||
|
int mAutoHideDuration;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RSIMAGEBLOCKWIDGET_H
|
#endif // RSIMAGEBLOCKWIDGET_H
|
||||||
|
@ -13,11 +13,20 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="RSImageBlockWidgetHLayout">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="margin">
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
@ -92,8 +101,17 @@
|
|||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::Box</enum>
|
<enum>QFrame::Box</enum>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="infoFrameHLayout">
|
||||||
<property name="margin">
|
<property name="leftMargin">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
@ -114,7 +132,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="infoFrameHSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "retroshare/rspeers.h"
|
#include "retroshare/rspeers.h"
|
||||||
#include "retroshare/rsservicecontrol.h"
|
#include "retroshare/rsservicecontrol.h"
|
||||||
#include "util/RsProtectedTimer.h"
|
|
||||||
#include "retroshare-gui/RsAutoUpdatePage.h"
|
#include "retroshare-gui/RsAutoUpdatePage.h"
|
||||||
#include "BandwidthStatsWidget.h"
|
#include "BandwidthStatsWidget.h"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user