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