source: smplayer/vendor/current/src/widgetactions.cpp@ 168

Last change on this file since 168 was 168, checked in by Silvan Scherrer, 11 years ago

SMPlayer: update vendor to 14.9.0

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