source: smplayer/trunk/src/widgetactions.cpp@ 188

Last change on this file since 188 was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

  • Property svn:eol-style set to LF
File size: 7.1 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2017 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 "widgetactions.h"
20#include "colorutils.h"
21#include "helper.h"
22#include <QLabel>
23#include <QDebug>
24
25#if MINI_ARROW_BUTTONS
26#include <QToolButton>
27#endif
28
29MyWidgetAction::MyWidgetAction( QWidget * parent )
30 : QWidgetAction(parent)
31{
32 custom_style = 0;
33 custom_stylesheet = "";
34}
35
36MyWidgetAction::~MyWidgetAction() {
37}
38
39void MyWidgetAction::enable() {
40 propagate_enabled(true);
41}
42
43void MyWidgetAction::disable() {
44 propagate_enabled(false);
45}
46
47void MyWidgetAction::propagate_enabled(bool b) {
48 QList<QWidget *> l = createdWidgets();
49 for (int n=0; n < l.count(); n++) {
50 l[n]->setEnabled(b);
51 }
52 setEnabled(b);
53}
54
55
56TimeSliderAction::TimeSliderAction( QWidget * parent )
57 : MyWidgetAction(parent)
58{
59#if ENABLE_DELAYED_DRAGGING
60 drag_delay = 200;
61#endif
62}
63
64TimeSliderAction::~TimeSliderAction() {
65}
66
67void TimeSliderAction::setPos(int v) {
68 QList<QWidget *> l = createdWidgets();
69 for (int n=0; n < l.count(); n++) {
70 TimeSlider *s = (TimeSlider*) l[n];
71 bool was_blocked= s->blockSignals(true);
72 s->setPos(v);
73 s->blockSignals(was_blocked);
74 }
75}
76
77int TimeSliderAction::pos() {
78 QList<QWidget *> l = createdWidgets();
79 if (l.count() >= 1) {
80 TimeSlider *s = (TimeSlider*) l[0];
81 return s->pos();
82 } else {
83 return -1;
84 }
85}
86
87void TimeSliderAction::setDuration(double t) {
88 qDebug() << "TimeSliderAction::setDuration:" << t;
89 total_time = t;
90 QList<QWidget *> l = createdWidgets();
91 for (int n=0; n < l.count(); n++) {
92 TimeSlider *s = (TimeSlider*) l[n];
93 s->setDuration(t);
94 }
95}
96
97#if ENABLE_DELAYED_DRAGGING
98void TimeSliderAction::setDragDelay(int d) {
99 drag_delay = d;
100
101 QList<QWidget *> l = createdWidgets();
102 for (int n=0; n < l.count(); n++) {
103 TimeSlider *s = (TimeSlider*) l[n];
104 s->setDragDelay(drag_delay);
105 }
106}
107
108int TimeSliderAction::dragDelay() {
109 return drag_delay;
110}
111#endif
112
113QWidget * TimeSliderAction::createWidget ( QWidget * parent ) {
114 TimeSlider *t = new TimeSlider(parent);
115 t->setEnabled( isEnabled() );
116
117 if (custom_style) t->setStyle(custom_style);
118 if (!custom_stylesheet.isEmpty()) t->setStyleSheet(custom_stylesheet);
119
120 connect( t, SIGNAL(posChanged(int)),
121 this, SIGNAL(posChanged(int)) );
122 connect( t, SIGNAL(draggingPos(int)),
123 this, SIGNAL(draggingPos(int)) );
124#if ENABLE_DELAYED_DRAGGING
125 t->setDragDelay(drag_delay);
126
127 connect( t, SIGNAL(delayedDraggingPos(int)),
128 this, SIGNAL(delayedDraggingPos(int)) );
129#endif
130
131 connect(t, SIGNAL(wheelUp()), this, SIGNAL(wheelUp()));
132 connect(t, SIGNAL(wheelDown()), this, SIGNAL(wheelDown()));
133
134 return t;
135}
136
137
138VolumeSliderAction::VolumeSliderAction( QWidget * parent )
139 : MyWidgetAction(parent)
140{
141 tick_position = QSlider::TicksBelow;
142}
143
144VolumeSliderAction::~VolumeSliderAction() {
145}
146
147void VolumeSliderAction::setValue(int v) {
148 QList<QWidget *> l = createdWidgets();
149 for (int n=0; n < l.count(); n++) {
150 MySlider *s = (MySlider*) l[n];
151 bool was_blocked = s->blockSignals(true);
152 s->setValue(v);
153 s->blockSignals(was_blocked);
154 }
155}
156
157int VolumeSliderAction::value() {
158 QList<QWidget *> l = createdWidgets();
159 if (l.count() >= 1) {
160 MySlider *s = (MySlider*) l[0];
161 return s->value();
162 } else {
163 return -1;
164 }
165}
166
167void VolumeSliderAction::setTickPosition(QSlider::TickPosition position) {
168 // For new widgets
169 tick_position = position;
170
171 // Propagate changes to all existing widgets
172 QList<QWidget *> l = createdWidgets();
173 for (int n=0; n < l.count(); n++) {
174 MySlider *s = (MySlider*) l[n];
175 s->setTickPosition(tick_position);
176 }
177}
178
179QWidget * VolumeSliderAction::createWidget ( QWidget * parent ) {
180 MySlider *t = new MySlider(parent);
181
182 if (custom_style) t->setStyle(custom_style);
183 if (!custom_stylesheet.isEmpty()) t->setStyleSheet(custom_stylesheet);
184 if (fixed_size.isValid()) t->setFixedSize(fixed_size);
185
186 t->setMinimum(0);
187 t->setMaximum(100);
188 t->setValue(50);
189 t->setOrientation( Qt::Horizontal );
190 t->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
191 t->setFocusPolicy( Qt::NoFocus );
192 t->setTickPosition( tick_position );
193 t->setTickInterval( 10 );
194 t->setSingleStep( 1 );
195 t->setPageStep( 10 );
196 t->setToolTip( tr("Volume") );
197 t->setEnabled( isEnabled() );
198 t->setAttribute(Qt::WA_NoMousePropagation);
199
200 connect( t, SIGNAL(valueChanged(int)),
201 this, SIGNAL(valueChanged(int)) );
202 return t;
203}
204
205
206TimeLabelAction::TimeLabelAction(TimeLabelType type, QWidget * parent )
207 : MyWidgetAction(parent)
208{
209 label_type = type;
210 current_time = 0;
211 total_time = 0;
212 updateText();
213}
214
215TimeLabelAction::~TimeLabelAction() {
216}
217
218void TimeLabelAction::setCurrentTime(double t) {
219 current_time = t;
220 updateText();
221}
222
223void TimeLabelAction::setTotalTime(double t) {
224 total_time = t;
225 updateText();
226}
227
228void TimeLabelAction::updateText() {
229 QString ct = Helper::formatTime(current_time);
230 QString tt = Helper::formatTime(total_time);
231 QString rt;
232 if (total_time < 1) rt = "00:00:00"; else rt = "-" + Helper::formatTime(total_time - current_time);
233
234 switch (label_type) {
235 case CurrentTime: setText(ct); break;
236 case TotalTime: setText(tt); break;
237 case CurrentAndTotalTime: setText(ct + " / " + tt); break;
238 case RemainingTime: setText(rt); break;
239 }
240}
241
242void TimeLabelAction::setText(QString s) {
243 current_text = s;
244 emit newText(s);
245}
246
247QWidget * TimeLabelAction::createWidget ( QWidget * parent ) {
248 QLabel * time_label = new QLabel(parent);
249 time_label->setObjectName("time_label");
250 time_label->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
251 //time_label->setAutoFillBackground(true);
252
253 //ColorUtils::setBackgroundColor( time_label, QColor(0,0,0) );
254 //ColorUtils::setForegroundColor( time_label, QColor(255,255,255) );
255
256 if (current_text.isEmpty()) current_text = "00:00:00 / 00:00:00";
257 time_label->setText(current_text);
258
259 //time_label->setFrameShape( QFrame::Panel );
260 //time_label->setFrameShadow( QFrame::Sunken );
261
262 connect( this, SIGNAL(newText(QString)),
263 time_label, SLOT(setText(QString)) );
264
265 return time_label;
266}
267
268#if MINI_ARROW_BUTTONS
269SeekingButton::SeekingButton( QList<QAction*> actions, QWidget * parent )
270 : QWidgetAction(parent)
271{
272 _actions = actions;
273}
274
275SeekingButton::~SeekingButton() {
276}
277
278QWidget * SeekingButton::createWidget( QWidget * parent ) {
279 QToolButton * button = new QToolButton(parent);
280 button->setPopupMode(QToolButton::MenuButtonPopup);
281
282 if (_actions.count() > 0 ) {
283 button->setDefaultAction( _actions[0] );
284 }
285 for (int n = 1; n < _actions.count(); n++) {
286 button->addAction( _actions[n] );
287 }
288
289 return button;
290}
291#endif
292
293#include "moc_widgetactions.cpp"
Note: See TracBrowser for help on using the repository browser.