mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
refs #883, added functions for fade in/out
This commit is contained in:
committed by
Mathew Sutcliffe
parent
873823eaa1
commit
1690c560b7
@@ -29,8 +29,11 @@
|
||||
#include <QTabWidget>
|
||||
#include <QThreadStorage>
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <Qt>
|
||||
#include <QtGlobal>
|
||||
#include <QGraphicsOpacityEffect>
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
@@ -345,4 +348,33 @@ namespace BlackGui
|
||||
{
|
||||
return QApplication::topLevelWidgets().contains(widget);
|
||||
}
|
||||
|
||||
QGraphicsOpacityEffect *CGuiUtility::fadeInWidget(int durationMs, QWidget *widget, double startValue, double endValue)
|
||||
{
|
||||
// http://stackoverflow.com/questions/19087822/how-to-make-qt-widgets-fade-in-or-fade-out#
|
||||
Q_ASSERT(widget);
|
||||
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(widget);
|
||||
widget->setGraphicsEffect(effect);
|
||||
QPropertyAnimation *a = new QPropertyAnimation(effect, "opacity");
|
||||
a->setDuration(durationMs);
|
||||
a->setStartValue(startValue);
|
||||
a->setEndValue(endValue);
|
||||
a->setEasingCurve(QEasingCurve::InBack);
|
||||
a->start(QPropertyAnimation::DeleteWhenStopped);
|
||||
return effect;
|
||||
}
|
||||
|
||||
QGraphicsOpacityEffect *CGuiUtility::fadeOutWidget(int durationMs, QWidget *widget, double startValue, double endValue)
|
||||
{
|
||||
Q_ASSERT(widget);
|
||||
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(widget);
|
||||
widget->setGraphicsEffect(effect);
|
||||
QPropertyAnimation *a = new QPropertyAnimation(effect, "opacity");
|
||||
a->setDuration(durationMs);
|
||||
a->setStartValue(startValue);
|
||||
a->setEndValue(endValue);
|
||||
a->setEasingCurve(QEasingCurve::OutBack);
|
||||
a->start(QPropertyAnimation::DeleteWhenStopped);
|
||||
return effect;
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -27,6 +27,7 @@ class QLayout;
|
||||
class QMimeData;
|
||||
class QTabWidget;
|
||||
class QWidget;
|
||||
class QGraphicsOpacityEffect;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -106,6 +107,12 @@ namespace BlackGui
|
||||
//! Is top level widget?
|
||||
static bool isTopLevelWidget(QWidget *widget);
|
||||
|
||||
//! Fade in a widget
|
||||
static QGraphicsOpacityEffect *fadeInWidget(int durationMs, QWidget *widget, double startValue = 0.0, double endValue = 1.0);
|
||||
|
||||
//! Fade out a widget
|
||||
static QGraphicsOpacityEffect *fadeOutWidget(int durationMs, QWidget *widget, double startValue = 1.0, double endValue = 0.0);
|
||||
|
||||
private:
|
||||
//! Constructor, use static methods only
|
||||
CGuiUtility() {}
|
||||
|
||||
Reference in New Issue
Block a user