| 1 | #include "MantidQtAPI/FadingFrame.h" |
|---|
| 2 | |
|---|
| 3 | #include <QByteArray> |
|---|
| 4 | #include <QEasingCurve> |
|---|
| 5 | #include <QParallelAnimationGroup> |
|---|
| 6 | #include <QPropertyAnimation> |
|---|
| 7 | #include <QWidget> |
|---|
| 8 | |
|---|
| 9 | namespace // anonymous |
|---|
| 10 | { |
|---|
| 11 | QPropertyAnimation * fade(QWidget * widget, |
|---|
| 12 | int length, |
|---|
| 13 | const QColor & normalColor, |
|---|
| 14 | const QColor & fadeColor, |
|---|
| 15 | const QByteArray & animationPropertyName) |
|---|
| 16 | { |
|---|
| 17 | QPropertyAnimation * animation = new QPropertyAnimation(widget, animationPropertyName); |
|---|
| 18 | animation->setDuration(length); |
|---|
| 19 | animation->setStartValue(fadeColor); |
|---|
| 20 | animation->setEndValue(normalColor); |
|---|
| 21 | animation->setEasingCurve(QEasingCurve::InExpo); |
|---|
| 22 | return animation; |
|---|
| 23 | } |
|---|
| 24 | } // anonymous namespace |
|---|
| 25 | |
|---|
| 26 | namespace MantidQt |
|---|
| 27 | { |
|---|
| 28 | namespace API |
|---|
| 29 | { |
|---|
| 30 | FadingFrame::FadingFrame(QWidget * parent) : QFrame(parent) |
|---|
| 31 | { |
|---|
| 32 | setFrameShape(QFrame::Panel); |
|---|
| 33 | const QColor defaultColor = palette().color(QPalette::Background); |
|---|
| 34 | setStyle(defaultColor, defaultColor); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | void FadingFrame::setFadeBorderColor( const QColor & fadeBorderColor ) |
|---|
| 38 | { |
|---|
| 39 | m_fadeBorderColor = fadeBorderColor; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | void FadingFrame::setFadeBackgroundColor( const QColor & fadeBackgroundColor ) |
|---|
| 43 | { |
|---|
| 44 | m_fadeBackgroundColor = fadeBackgroundColor; |
|---|
| 45 | setStyle(m_fadeBorderColor, m_fadeBackgroundColor); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | void FadingFrame::setStyle(const QColor & borderColor, const QColor & backgroundColor) |
|---|
| 49 | { |
|---|
| 50 | setStyleSheet("QLabel{ border-color : " + borderColor.name() + ";" |
|---|
| 51 | "border-width : 1px;" |
|---|
| 52 | "border-radius : 3px;" |
|---|
| 53 | "border-style : solid;" |
|---|
| 54 | "background-color : " + backgroundColor.name() + "; }"); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | void FadingFrame::doFadeAnimation() |
|---|
| 58 | { |
|---|
| 59 | static const QColor MANTID_GREEN = QColor(153,193,147); |
|---|
| 60 | static const QColor BLACK = QColor(0,0,0); |
|---|
| 61 | static const int LENGTH = 3000; |
|---|
| 62 | |
|---|
| 63 | QParallelAnimationGroup * group = new QParallelAnimationGroup(this); |
|---|
| 64 | group->addAnimation(fade(this, LENGTH, palette().color(QPalette::Background), BLACK, "fadeBorderColor")); |
|---|
| 65 | group->addAnimation(fade(this, LENGTH, palette().color(QPalette::Background), MANTID_GREEN, "fadeBackgroundColor")); |
|---|
| 66 | group->start(); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | } // namespace MantidQt |
|---|
| 70 | } // namespace API |
|---|