File: faderdialog.cpp

package info (click to toggle)
nixnote2 2.0~beta11-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,448 kB
  • ctags: 7,058
  • sloc: cpp: 68,338; java: 1,096; sh: 834; makefile: 27
file content (55 lines) | stat: -rw-r--r-- 1,590 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//***********************************************************************************************
//* This code was shamelessly copied from the Qt Centre forums:
//* http://www.qtcentre.org/threads/56737-Implementing-fade-in-fade-out-for-a-modal-QDialog
//***********************************************************************************************

#include "faderdialog.h"

FaderDialog::FaderDialog( QWidget * parent ) : QDialog( parent ), mResult( 0 ) {
    setWindowFlags(Qt::SplashScreen);

    layout = new QVBoxLayout();
    text = new QLabel();
    layout->addWidget(text);
    setLayout(layout);

    // Create the fade-in / fade-out animators
    mpFadeIn = new QPropertyAnimation( this, "windowOpacity" );
    mpFadeIn->setDuration( 2000 );
    mpFadeIn->setStartValue( 0.0 );
    mpFadeIn->setEndValue( 1.0 );

    mpFadeOut = new QPropertyAnimation( this, "windowOpacity" );
    mpFadeOut->setDuration( 2000 );
    mpFadeOut->setStartValue( 1.0 );
    mpFadeOut->setEndValue( 0.0 );

    connect( mpFadeIn, SIGNAL(finished()), this, SLOT(done()));
    connect( mpFadeOut, SIGNAL( finished() ), this, SLOT( onFadeOutFinished() ) );
}


void FaderDialog::setText(QString value) {
    this->text->setText(value);
}

void FaderDialog::showEvent( QShowEvent * )
{
    mpFadeIn->start();
}


void FaderDialog::done() {
    this->done(0);
}

void FaderDialog::done( int result )
{
    mResult = result;  // remember the result in a member variable
    mpFadeOut->start();
}

void FaderDialog::onFadeOutFinished()
{
    QDialog::done( mResult );  // now call the real done() slot
}