| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
|
|---|
| 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 |
|
|---|
| 27 | MyWidgetAction::MyWidgetAction( QWidget * parent )
|
|---|
| 28 | : QWidgetAction(parent)
|
|---|
| 29 | {
|
|---|
| 30 | custom_style = 0;
|
|---|
| 31 | custom_stylesheet = "";
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | MyWidgetAction::~MyWidgetAction() {
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | void MyWidgetAction::enable() {
|
|---|
| 38 | propagate_enabled(true);
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | void MyWidgetAction::disable() {
|
|---|
| 42 | propagate_enabled(false);
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | void 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 |
|
|---|
| 55 | TimeSliderAction::TimeSliderAction( QWidget * parent )
|
|---|
| 56 | : MyWidgetAction(parent)
|
|---|
| 57 | {
|
|---|
| 58 | #if ENABLE_DELAYED_DRAGGING
|
|---|
| 59 | drag_delay = 200;
|
|---|
| 60 | #endif
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | TimeSliderAction::~TimeSliderAction() {
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | void 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 |
|
|---|
| 76 | int 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
|
|---|
| 87 | void 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 |
|
|---|
| 97 | int TimeSliderAction::dragDelay() {
|
|---|
| 98 | return drag_delay;
|
|---|
| 99 | }
|
|---|
| 100 | #endif
|
|---|
| 101 |
|
|---|
| 102 | QWidget * 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 | return t;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 | VolumeSliderAction::VolumeSliderAction( QWidget * parent )
|
|---|
| 125 | : MyWidgetAction(parent)
|
|---|
| 126 | {
|
|---|
| 127 | tick_position = QSlider::TicksBelow;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | VolumeSliderAction::~VolumeSliderAction() {
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | void VolumeSliderAction::setValue(int v) {
|
|---|
| 134 | QList<QWidget *> l = createdWidgets();
|
|---|
| 135 | for (int n=0; n < l.count(); n++) {
|
|---|
| 136 | MySlider *s = (MySlider*) l[n];
|
|---|
| 137 | bool was_blocked = s->blockSignals(true);
|
|---|
| 138 | s->setValue(v);
|
|---|
| 139 | s->blockSignals(was_blocked);
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | int VolumeSliderAction::value() {
|
|---|
| 144 | QList<QWidget *> l = createdWidgets();
|
|---|
| 145 | if (l.count() >= 1) {
|
|---|
| 146 | MySlider *s = (MySlider*) l[0];
|
|---|
| 147 | return s->value();
|
|---|
| 148 | } else {
|
|---|
| 149 | return -1;
|
|---|
| 150 | }
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | void VolumeSliderAction::setTickPosition(QSlider::TickPosition position) {
|
|---|
| 154 | // For new widgets
|
|---|
| 155 | tick_position = position;
|
|---|
| 156 |
|
|---|
| 157 | // Propagate changes to all existing widgets
|
|---|
| 158 | QList<QWidget *> l = createdWidgets();
|
|---|
| 159 | for (int n=0; n < l.count(); n++) {
|
|---|
| 160 | MySlider *s = (MySlider*) l[n];
|
|---|
| 161 | s->setTickPosition(tick_position);
|
|---|
| 162 | }
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | QWidget * VolumeSliderAction::createWidget ( QWidget * parent ) {
|
|---|
| 166 | MySlider *t = new MySlider(parent);
|
|---|
| 167 |
|
|---|
| 168 | if (custom_style) t->setStyle(custom_style);
|
|---|
| 169 | if (!custom_stylesheet.isEmpty()) t->setStyleSheet(custom_stylesheet);
|
|---|
| 170 | if (fixed_size.isValid()) t->setFixedSize(fixed_size);
|
|---|
| 171 |
|
|---|
| 172 | t->setMinimum(0);
|
|---|
| 173 | t->setMaximum(100);
|
|---|
| 174 | t->setValue(50);
|
|---|
| 175 | t->setOrientation( Qt::Horizontal );
|
|---|
| 176 | t->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
|---|
| 177 | t->setFocusPolicy( Qt::NoFocus );
|
|---|
| 178 | t->setTickPosition( tick_position );
|
|---|
| 179 | t->setTickInterval( 10 );
|
|---|
| 180 | t->setSingleStep( 1 );
|
|---|
| 181 | t->setPageStep( 10 );
|
|---|
| 182 | t->setToolTip( tr("Volume") );
|
|---|
| 183 | t->setEnabled( isEnabled() );
|
|---|
| 184 | t->setAttribute(Qt::WA_NoMousePropagation);
|
|---|
| 185 |
|
|---|
| 186 | connect( t, SIGNAL(valueChanged(int)),
|
|---|
| 187 | this, SIGNAL(valueChanged(int)) );
|
|---|
| 188 | return t;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 | TimeLabelAction::TimeLabelAction( QWidget * parent )
|
|---|
| 193 | : MyWidgetAction(parent)
|
|---|
| 194 | {
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | TimeLabelAction::~TimeLabelAction() {
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | void TimeLabelAction::setText(QString s) {
|
|---|
| 201 | _text = s;
|
|---|
| 202 | emit newText(s);
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | QWidget * TimeLabelAction::createWidget ( QWidget * parent ) {
|
|---|
| 206 | QLabel * time_label = new QLabel(parent);
|
|---|
| 207 | time_label->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
|
|---|
| 208 | time_label->setAutoFillBackground(true);
|
|---|
| 209 |
|
|---|
| 210 | ColorUtils::setBackgroundColor( time_label, QColor(0,0,0) );
|
|---|
| 211 | ColorUtils::setForegroundColor( time_label, QColor(255,255,255) );
|
|---|
| 212 | time_label->setText( "00:00:00 / 00:00:00" );
|
|---|
| 213 | time_label->setFrameShape( QFrame::Panel );
|
|---|
| 214 | time_label->setFrameShadow( QFrame::Sunken );
|
|---|
| 215 |
|
|---|
| 216 | connect( this, SIGNAL(newText(QString)),
|
|---|
| 217 | time_label, SLOT(setText(QString)) );
|
|---|
| 218 |
|
|---|
| 219 | return time_label;
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | #if MINI_ARROW_BUTTONS
|
|---|
| 223 | SeekingButton::SeekingButton( QList<QAction*> actions, QWidget * parent )
|
|---|
| 224 | : QWidgetAction(parent)
|
|---|
| 225 | {
|
|---|
| 226 | _actions = actions;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | SeekingButton::~SeekingButton() {
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | QWidget * SeekingButton::createWidget( QWidget * parent ) {
|
|---|
| 233 | QToolButton * button = new QToolButton(parent);
|
|---|
| 234 | button->setPopupMode(QToolButton::MenuButtonPopup);
|
|---|
| 235 |
|
|---|
| 236 | if (_actions.count() > 0 ) {
|
|---|
| 237 | button->setDefaultAction( _actions[0] );
|
|---|
| 238 | }
|
|---|
| 239 | for (int n = 1; n < _actions.count(); n++) {
|
|---|
| 240 | button->addAction( _actions[n] );
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | return button;
|
|---|
| 244 | }
|
|---|
| 245 | #endif
|
|---|
| 246 |
|
|---|
| 247 | #include "moc_widgetactions.cpp"
|
|---|