1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2014 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "timeslider.h"
|
---|
20 |
|
---|
21 | #include <QWheelEvent>
|
---|
22 | #include <QTimer>
|
---|
23 |
|
---|
24 | #define DEBUG 0
|
---|
25 |
|
---|
26 | TimeSlider::TimeSlider( QWidget * parent ) : MySlider(parent)
|
---|
27 | {
|
---|
28 | dont_update = false;
|
---|
29 | setMinimum(0);
|
---|
30 | #ifdef SEEKBAR_RESOLUTION
|
---|
31 | setMaximum(SEEKBAR_RESOLUTION);
|
---|
32 | #else
|
---|
33 | setMaximum(100);
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | setFocusPolicy( Qt::NoFocus );
|
---|
37 | setSizePolicy( QSizePolicy::Expanding , QSizePolicy::Fixed );
|
---|
38 |
|
---|
39 | connect( this, SIGNAL( sliderPressed() ), this, SLOT( stopUpdate() ) );
|
---|
40 | connect( this, SIGNAL( sliderReleased() ), this, SLOT( resumeUpdate() ) );
|
---|
41 | connect( this, SIGNAL( sliderReleased() ), this, SLOT( mouseReleased() ) );
|
---|
42 | connect( this, SIGNAL( valueChanged(int) ), this, SLOT( valueChanged_slot(int) ) );
|
---|
43 | #if ENABLE_DELAYED_DRAGGING
|
---|
44 | connect( this, SIGNAL(draggingPos(int) ), this, SLOT(checkDragging(int)) );
|
---|
45 |
|
---|
46 | last_pos_to_send = -1;
|
---|
47 | timer = new QTimer(this);
|
---|
48 | connect( timer, SIGNAL(timeout()), this, SLOT(sendDelayedPos()) );
|
---|
49 | timer->start(200);
|
---|
50 | #endif
|
---|
51 | }
|
---|
52 |
|
---|
53 | TimeSlider::~TimeSlider() {
|
---|
54 | }
|
---|
55 |
|
---|
56 | void TimeSlider::stopUpdate() {
|
---|
57 | #if DEBUG
|
---|
58 | qDebug("TimeSlider::stopUpdate");
|
---|
59 | #endif
|
---|
60 | dont_update = true;
|
---|
61 | }
|
---|
62 |
|
---|
63 | void TimeSlider::resumeUpdate() {
|
---|
64 | #if DEBUG
|
---|
65 | qDebug("TimeSlider::resumeUpdate");
|
---|
66 | #endif
|
---|
67 | dont_update = false;
|
---|
68 | }
|
---|
69 |
|
---|
70 | void TimeSlider::mouseReleased() {
|
---|
71 | #if DEBUG
|
---|
72 | qDebug("TimeSlider::mouseReleased");
|
---|
73 | #endif
|
---|
74 | emit posChanged( value() );
|
---|
75 | }
|
---|
76 |
|
---|
77 | void TimeSlider::valueChanged_slot(int v) {
|
---|
78 | #if DEBUG
|
---|
79 | qDebug("TimeSlider::changedValue_slot: %d", v);
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | // Only to make things clear:
|
---|
83 | bool dragging = dont_update;
|
---|
84 | if (!dragging) {
|
---|
85 | if (v!=position) {
|
---|
86 | #if DEBUG
|
---|
87 | qDebug(" emitting posChanged");
|
---|
88 | #endif
|
---|
89 | emit posChanged(v);
|
---|
90 | }
|
---|
91 | } else {
|
---|
92 | #if DEBUG
|
---|
93 | qDebug(" emitting draggingPos");
|
---|
94 | #endif
|
---|
95 | emit draggingPos(v);
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | #if ENABLE_DELAYED_DRAGGING
|
---|
100 | void TimeSlider::setDragDelay(int d) {
|
---|
101 | qDebug("TimeSlider::setDragDelay: %d", d);
|
---|
102 | timer->setInterval(d);
|
---|
103 | }
|
---|
104 |
|
---|
105 | int TimeSlider::dragDelay() {
|
---|
106 | return timer->interval();
|
---|
107 | }
|
---|
108 |
|
---|
109 | void TimeSlider::checkDragging(int v) {
|
---|
110 | qDebug("TimeSlider::checkDragging: %d", v);
|
---|
111 | last_pos_to_send = v;
|
---|
112 | }
|
---|
113 |
|
---|
114 | void TimeSlider::sendDelayedPos() {
|
---|
115 | if (last_pos_to_send != -1) {
|
---|
116 | qDebug("TimeSlider::sendDelayedPos: %d", last_pos_to_send);
|
---|
117 | emit delayedDraggingPos(last_pos_to_send);
|
---|
118 | last_pos_to_send = -1;
|
---|
119 | }
|
---|
120 | }
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | void TimeSlider::setPos(int v) {
|
---|
124 | #if DEBUG
|
---|
125 | qDebug("TimeSlider::setPos: %d", v);
|
---|
126 | qDebug(" dont_update: %d", dont_update);
|
---|
127 | #endif
|
---|
128 |
|
---|
129 | if (v!=pos()) {
|
---|
130 | if (!dont_update) {
|
---|
131 | position = v;
|
---|
132 | setValue(v);
|
---|
133 | }
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | int TimeSlider::pos() {
|
---|
138 | return position;
|
---|
139 | }
|
---|
140 |
|
---|
141 | /*
|
---|
142 | void TimeSlider::wheelEvent( QWheelEvent * e ) {
|
---|
143 | e->ignore();
|
---|
144 | }
|
---|
145 | */
|
---|
146 |
|
---|
147 | #include "moc_timeslider.cpp"
|
---|