OSDN Git Service

MacGui: Remove Target Size as a rate control option as it doesn't really work correct...
[handbrake-jp/handbrake-jp-git.git] / qt4 / faderwidget.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2006 Trolltech AS. All rights reserved.
4 **
5 ** This file is part of the documentation of Qt. It was originally
6 ** published as part of Qt Quarterly.
7 **
8 ** This file may be used under the terms of the GNU General Public License
9 ** version 2.0 as published by the Free Software Foundation or under the
10 ** terms of the Qt Commercial License Agreement. The respective license
11 ** texts for these are provided with the open source and commercial
12 ** editions of Qt.
13 **
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** sales department at sales@trolltech.com.
18 **
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 **
22 ****************************************************************************/
23
24 #include <QtGui>
25
26 #include "faderwidget.h"
27
28 FaderWidget::FaderWidget(QWidget *parent)
29     : QWidget(parent)
30 {
31     if (parent) {
32         startColor = endColor = parent->palette().window().color();
33     } else {
34         startColor = endColor = Qt::white;
35     }
36
37     currentAlpha = 0;
38     duration = 333;
39     fadeOut = false;
40
41     timer = new QTimer(this);
42     connect(timer, SIGNAL(timeout()), this, SLOT(update()));
43
44     setAttribute(Qt::WA_DeleteOnClose);
45     resize(parent->size());
46 }
47
48 void FaderWidget::start()
49 {
50     currentAlpha = 255;
51     fadeOut = false;
52     timer->start(33);
53     show();
54 }
55
56 void FaderWidget::startFadeOut()
57 {
58     currentAlpha = 0;
59     fadeOut = true;
60     timer->start(33);
61     show();
62 }
63
64 void FaderWidget::paintEvent(QPaintEvent * /* event */)
65 {
66     QPainter painter(this);
67     QColor semiTransparentColor = startColor;
68     semiTransparentColor.setAlpha(currentAlpha);
69     painter.fillRect(rect(), semiTransparentColor);
70
71     if (fadeOut) {
72         currentAlpha += 255 * timer->interval() / duration;
73         if (currentAlpha >= 255) {
74             timer->stop();
75             emit done( (QWidget *)parent() );
76             close();
77         }
78     } else {
79         currentAlpha -= 255 * timer->interval() / duration;
80         if (currentAlpha <= 0) {
81             timer->stop();
82             emit done( (QWidget *)parent() );
83             close();
84         }
85     }
86 }