|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the examples of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "progressbar.h" |
|
43 #include "spectrum.h" |
|
44 #include <QPainter> |
|
45 |
|
46 ProgressBar::ProgressBar(QWidget *parent) |
|
47 : QWidget(parent) |
|
48 , m_bufferDuration(0) |
|
49 , m_recordPosition(0) |
|
50 , m_playPosition(0) |
|
51 , m_windowPosition(0) |
|
52 , m_windowLength(0) |
|
53 { |
|
54 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
|
55 setMinimumHeight(30); |
|
56 #ifdef SUPERIMPOSE_PROGRESS_ON_WAVEFORM |
|
57 setAutoFillBackground(false); |
|
58 #endif |
|
59 } |
|
60 |
|
61 ProgressBar::~ProgressBar() |
|
62 { |
|
63 |
|
64 } |
|
65 |
|
66 void ProgressBar::reset() |
|
67 { |
|
68 m_bufferDuration = 0; |
|
69 m_recordPosition = 0; |
|
70 m_playPosition = 0; |
|
71 m_windowPosition = 0; |
|
72 m_windowLength = 0; |
|
73 update(); |
|
74 } |
|
75 |
|
76 void ProgressBar::paintEvent(QPaintEvent * /*event*/) |
|
77 { |
|
78 QPainter painter(this); |
|
79 |
|
80 QColor bufferColor(0, 0, 255); |
|
81 QColor windowColor(0, 255, 0); |
|
82 |
|
83 #ifdef SUPERIMPOSE_PROGRESS_ON_WAVEFORM |
|
84 bufferColor.setAlphaF(0.5); |
|
85 windowColor.setAlphaF(0.5); |
|
86 #else |
|
87 painter.fillRect(rect(), Qt::black); |
|
88 #endif |
|
89 |
|
90 if (m_bufferDuration) { |
|
91 QRect bar = rect(); |
|
92 const qreal play = qreal(m_playPosition) / m_bufferDuration; |
|
93 bar.setLeft(rect().left() + play * rect().width()); |
|
94 const qreal record = qreal(m_recordPosition) / m_bufferDuration; |
|
95 bar.setRight(rect().left() + record * rect().width()); |
|
96 painter.fillRect(bar, bufferColor); |
|
97 |
|
98 QRect window = rect(); |
|
99 const qreal windowLeft = qreal(m_windowPosition) / m_bufferDuration; |
|
100 window.setLeft(rect().left() + windowLeft * rect().width()); |
|
101 const qreal windowWidth = qreal(m_windowLength) / m_bufferDuration; |
|
102 window.setWidth(windowWidth * rect().width()); |
|
103 painter.fillRect(window, windowColor); |
|
104 } |
|
105 } |
|
106 |
|
107 void ProgressBar::bufferDurationChanged(qint64 bufferSize) |
|
108 { |
|
109 m_bufferDuration = bufferSize; |
|
110 m_recordPosition = 0; |
|
111 m_playPosition = 0; |
|
112 m_windowPosition = 0; |
|
113 m_windowLength = 0; |
|
114 repaint(); |
|
115 } |
|
116 |
|
117 void ProgressBar::recordPositionChanged(qint64 recordPosition) |
|
118 { |
|
119 Q_ASSERT(recordPosition >= 0); |
|
120 Q_ASSERT(recordPosition <= m_bufferDuration); |
|
121 m_recordPosition = recordPosition; |
|
122 repaint(); |
|
123 } |
|
124 |
|
125 void ProgressBar::playPositionChanged(qint64 playPosition) |
|
126 { |
|
127 Q_ASSERT(playPosition >= 0); |
|
128 Q_ASSERT(playPosition <= m_bufferDuration); |
|
129 m_playPosition = playPosition; |
|
130 repaint(); |
|
131 } |
|
132 |
|
133 void ProgressBar::windowChanged(qint64 position, qint64 length) |
|
134 { |
|
135 Q_ASSERT(position >= 0); |
|
136 Q_ASSERT(position <= m_bufferDuration); |
|
137 Q_ASSERT(position + length <= m_bufferDuration); |
|
138 m_windowPosition = position; |
|
139 m_windowLength = length; |
|
140 repaint(); |
|
141 } |