parent
511c58d608
commit
343acaf434
@ -17,11 +17,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QGraphicsOpacityEffect>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
class ScrollBar : public QScrollBar
|
class ScrollBar : public QScrollBar
|
||||||
{
|
{
|
||||||
@ -32,9 +30,6 @@ class ScrollBar : public QScrollBar
|
|||||||
public:
|
public:
|
||||||
ScrollBar(QScrollArea *area, QWidget *parent = nullptr);
|
ScrollBar(QScrollArea *area, QWidget *parent = nullptr);
|
||||||
|
|
||||||
void fadeIn();
|
|
||||||
void fadeOut();
|
|
||||||
|
|
||||||
QColor backgroundColor() const { return bgColor_; }
|
QColor backgroundColor() const { return bgColor_; }
|
||||||
void setBackgroundColor(QColor &color) { bgColor_ = color; }
|
void setBackgroundColor(QColor &color) { bgColor_ = color; }
|
||||||
|
|
||||||
@ -43,20 +38,14 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void sliderChange(SliderChange change) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int roundRadius_ = 4;
|
int roundRadius_ = 4;
|
||||||
int handleWidth_ = 7;
|
int handleWidth_ = 7;
|
||||||
int minHandleHeight_ = 20;
|
int minHandleHeight_ = 20;
|
||||||
bool isActive = false;
|
|
||||||
|
|
||||||
const int AnimationDuration = 300;
|
|
||||||
const int Padding = 4;
|
const int Padding = 4;
|
||||||
|
|
||||||
QGraphicsOpacityEffect *eff;
|
|
||||||
QTimer hideTimer_;
|
|
||||||
|
|
||||||
QScrollArea *area_;
|
QScrollArea *area_;
|
||||||
QRect handle_;
|
QRect handle_;
|
||||||
|
|
||||||
|
@ -15,60 +15,12 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QGraphicsOpacityEffect>
|
|
||||||
#include <QPropertyAnimation>
|
|
||||||
|
|
||||||
#include "ScrollBar.h"
|
#include "ScrollBar.h"
|
||||||
|
|
||||||
ScrollBar::ScrollBar(QScrollArea *area, QWidget *parent)
|
ScrollBar::ScrollBar(QScrollArea *area, QWidget *parent)
|
||||||
: QScrollBar(parent)
|
: QScrollBar(parent)
|
||||||
, area_{area}
|
, area_{area}
|
||||||
{
|
{}
|
||||||
hideTimer_.setSingleShot(true);
|
|
||||||
|
|
||||||
connect(&hideTimer_, &QTimer::timeout, this, &ScrollBar::fadeOut);
|
|
||||||
|
|
||||||
eff = new QGraphicsOpacityEffect(this);
|
|
||||||
setGraphicsEffect(eff);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ScrollBar::fadeOut()
|
|
||||||
{
|
|
||||||
isActive = false;
|
|
||||||
|
|
||||||
QPropertyAnimation *anim = new QPropertyAnimation(eff, "opacity");
|
|
||||||
anim->setDuration(AnimationDuration);
|
|
||||||
anim->setStartValue(1);
|
|
||||||
anim->setEndValue(0);
|
|
||||||
anim->setEasingCurve(QEasingCurve::Linear);
|
|
||||||
anim->start(QPropertyAnimation::DeleteWhenStopped);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ScrollBar::fadeIn()
|
|
||||||
{
|
|
||||||
QPropertyAnimation *anim = new QPropertyAnimation(eff, "opacity");
|
|
||||||
anim->setDuration(AnimationDuration);
|
|
||||||
anim->setStartValue(0);
|
|
||||||
anim->setEndValue(1);
|
|
||||||
anim->setEasingCurve(QEasingCurve::Linear);
|
|
||||||
anim->start(QPropertyAnimation::DeleteWhenStopped);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ScrollBar::sliderChange(SliderChange change)
|
|
||||||
{
|
|
||||||
if (!isActive)
|
|
||||||
fadeIn();
|
|
||||||
|
|
||||||
hideTimer_.stop();
|
|
||||||
hideTimer_.start(1500);
|
|
||||||
isActive = true;
|
|
||||||
|
|
||||||
QScrollBar::sliderChange(change);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScrollBar::paintEvent(QPaintEvent *)
|
ScrollBar::paintEvent(QPaintEvent *)
|
||||||
|
Loading…
Reference in New Issue
Block a user