source: smplayer/trunk/src/mpcgui/mpcgui.cpp@ 174

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

SMPlayer: updated trunk to 14.9.0

  • Property svn:eol-style set to LF
File size: 15.5 KB
Line 
1/* Mpcgui for SMPlayer.
2 Copyright (C) 2008 matt_ <matt@endboss.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 "mpcgui.h"
20#include "mpcstyles.h"
21#include "widgetactions.h"
22#include "autohidewidget.h"
23#include "myaction.h"
24#include "mplayerwindow.h"
25#include "global.h"
26#include "helper.h"
27#include "desktopinfo.h"
28#include "colorutils.h"
29
30#include <QToolBar>
31#include <QStatusBar>
32#include <QLabel>
33#include <QSlider>
34#include <QLayout>
35#include <QApplication>
36
37using namespace Global;
38
39
40MpcGui::MpcGui( QWidget * parent, Qt::WindowFlags flags )
41 : BaseGuiPlus( parent, flags )
42{
43 createActions();
44 createControlWidget();
45 createStatusBar();
46 createFloatingControl();
47
48 retranslateStrings();
49
50 loadConfig();
51
52 if (pref->compact_mode) {
53 controlwidget->hide();
54 timeslidewidget->hide();
55 }
56}
57
58MpcGui::~MpcGui() {
59 saveConfig();
60}
61
62void MpcGui::createActions() {
63 timeslider_action = createTimeSliderAction(this);
64 timeslider_action->disable();
65 timeslider_action->setCustomStyle( new MpcTimeSlideStyle() );
66
67#if USE_VOLUME_BAR
68 volumeslider_action = createVolumeSliderAction(this);
69 volumeslider_action->disable();
70 volumeslider_action->setCustomStyle( new MpcVolumeSlideStyle() );
71 volumeslider_action->setFixedSize( QSize(50,18) );
72 volumeslider_action->setTickPosition( QSlider::NoTicks );
73#endif
74
75 time_label_action = new TimeLabelAction(this);
76 time_label_action->setObjectName("timelabel_action");
77
78 connect( this, SIGNAL(timeChanged(QString)),
79 time_label_action, SLOT(setText(QString)) );
80}
81
82
83void MpcGui::createControlWidget() {
84 controlwidget = new QToolBar( this );
85 controlwidget->setObjectName("controlwidget");
86 controlwidget->setLayoutDirection(Qt::LeftToRight);
87
88 controlwidget->setMovable(false);
89 controlwidget->setAllowedAreas(Qt::BottomToolBarArea);
90 controlwidget->addAction(playAct);
91 controlwidget->addAction(pauseAct);
92 controlwidget->addAction(stopAct);
93 controlwidget->addSeparator();
94 controlwidget->addAction(rewind3Act);
95 controlwidget->addAction(rewind1Act);
96 controlwidget->addAction(forward1Act);
97 controlwidget->addAction(forward3Act);
98 controlwidget->addSeparator();
99 controlwidget->addAction(frameStepAct);
100 controlwidget->addSeparator();
101
102 QLabel* pLabel = new QLabel(this);
103 pLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
104 controlwidget->addWidget(pLabel);
105
106 controlwidget->addAction(muteAct);
107 controlwidget->addAction(volumeslider_action);
108
109 timeslidewidget = new QToolBar( this );
110 timeslidewidget->setObjectName("timeslidewidget");
111 timeslidewidget->setLayoutDirection(Qt::LeftToRight);
112 timeslidewidget->addAction(timeslider_action);
113 timeslidewidget->setMovable(false);
114
115 /*
116 QColor SliderColor = palette().color(QPalette::Window);
117 QColor SliderBorderColor = palette().color(QPalette::Dark);
118 */
119 setIconSize( QSize( 16 , 16 ) );
120
121 addToolBar(Qt::BottomToolBarArea, controlwidget);
122 addToolBarBreak(Qt::BottomToolBarArea);
123 addToolBar(Qt::BottomToolBarArea, timeslidewidget);
124
125 controlwidget->setStyle(new MpcToolbarStyle() );
126 timeslidewidget->setStyle(new MpcToolbarStyle() );
127
128 statusBar()->show();
129}
130
131void MpcGui::createFloatingControl() {
132 // Floating control
133 floating_control = new AutohideWidget(panel);
134 floating_control->setAutoHide(true);
135 floating_control->hide();
136 spacer = new QSpacerItem(10,10);
137
138 floating_control_time = new QLabel(floating_control);
139 floating_control_time->setAlignment(Qt::AlignRight);
140 floating_control_time->setAutoFillBackground(true);
141 ColorUtils::setBackgroundColor( floating_control_time, QColor(0,0,0) );
142 ColorUtils::setForegroundColor( floating_control_time, QColor(255,255,255) );
143
144}
145
146void MpcGui::retranslateStrings() {
147 BaseGuiPlus::retranslateStrings();
148
149 controlwidget->setWindowTitle( tr("Control bar") );
150 timeslidewidget->setWindowTitle( tr("Seek bar") );
151
152 setupIcons();
153}
154
155#if AUTODISABLE_ACTIONS
156void MpcGui::enableActionsOnPlaying() {
157 BaseGuiPlus::enableActionsOnPlaying();
158
159 timeslider_action->enable();
160#if USE_VOLUME_BAR
161 volumeslider_action->enable();
162#endif
163}
164
165void MpcGui::disableActionsOnStop() {
166 BaseGuiPlus::disableActionsOnStop();
167
168 timeslider_action->disable();
169#if USE_VOLUME_BAR
170 volumeslider_action->disable();
171#endif
172}
173#endif // AUTODISABLE_ACTIONS
174
175void MpcGui::aboutToEnterFullscreen() {
176 BaseGuiPlus::aboutToEnterFullscreen();
177
178 // Show floating_control
179 // Move controls to the floating_control layout
180 removeToolBarBreak(controlwidget);
181 removeToolBar(controlwidget);
182 removeToolBar(timeslidewidget);
183 floating_control->layout()->addWidget(timeslidewidget);
184 floating_control->layout()->addItem(spacer);
185 floating_control->layout()->addWidget(controlwidget);
186 floating_control->layout()->addWidget(floating_control_time);
187 controlwidget->show();
188 timeslidewidget->show();
189 floating_control->adjustSize();
190
191 floating_control->setMargin(pref->floating_control_margin);
192 floating_control->setPercWidth(pref->floating_control_width);
193 floating_control->setAnimated(pref->floating_control_animated);
194 floating_control->setActivationArea( (AutohideWidget::Activation) pref->floating_activation_area);
195 floating_control->setHideDelay(pref->floating_hide_delay);
196 QTimer::singleShot(500, floating_control, SLOT(activate()));
197
198
199 if (!pref->compact_mode) {
200 //controlwidget->hide();
201 //timeslidewidget->hide();
202 statusBar()->hide();
203 }
204}
205
206void MpcGui::aboutToExitFullscreen() {
207 BaseGuiPlus::aboutToExitFullscreen();
208
209 // Remove controls from the floating_control and put them back to the mainwindow
210 floating_control->deactivate();
211 floating_control->layout()->removeWidget(controlwidget);
212 floating_control->layout()->removeWidget(timeslidewidget);
213 floating_control->layout()->removeItem(spacer);
214 floating_control->layout()->removeWidget(floating_control_time);
215 addToolBar(Qt::BottomToolBarArea, controlwidget);
216 addToolBarBreak(Qt::BottomToolBarArea);
217 addToolBar(Qt::BottomToolBarArea, timeslidewidget);
218
219 if (!pref->compact_mode) {
220 controlwidget->show();
221 statusBar()->show();
222 timeslidewidget->show();
223 } else {
224 controlwidget->hide();
225 timeslidewidget->hide();
226 }
227}
228
229void MpcGui::aboutToEnterCompactMode() {
230 BaseGuiPlus::aboutToEnterCompactMode();
231
232 controlwidget->hide();
233 timeslidewidget->hide();
234 statusBar()->hide();
235}
236
237void MpcGui::aboutToExitCompactMode() {
238 BaseGuiPlus::aboutToExitCompactMode();
239
240 statusBar()->show();
241 controlwidget->show();
242 timeslidewidget->show();
243}
244
245#if USE_mpcMUMSIZE
246QSize MpcGui::mpcmumSizeHint() const {
247 return QSize(controlwidget->sizeHint().width(), 0);
248}
249#endif
250
251
252void MpcGui::saveConfig() {
253 QSettings * set = settings;
254
255 set->beginGroup( "mpc_gui");
256
257 if (pref->save_window_size_on_exit) {
258 qDebug("MpcGui::saveConfig: w: %d h: %d", width(), height());
259 set->setValue( "pos", pos() );
260 set->setValue( "size", size() );
261 set->setValue( "state", (int) windowState() );
262 }
263
264 set->setValue( "toolbars_state", saveState(Helper::qtVersion()) );
265
266 set->endGroup();
267}
268
269void MpcGui::loadConfig() {
270 QSettings * set = settings;
271
272 set->beginGroup( "mpc_gui");
273
274 if (pref->save_window_size_on_exit) {
275 QPoint p = set->value("pos", pos()).toPoint();
276 QSize s = set->value("size", size()).toSize();
277
278 if ( (s.height() < 200) && (!pref->use_mplayer_window) ) {
279 s = pref->default_size;
280 }
281
282 move(p);
283 resize(s);
284
285 setWindowState( (Qt::WindowStates) set->value("state", 0).toInt() );
286
287 if (!DesktopInfo::isInsideScreen(this)) {
288 move(0,0);
289 qWarning("MpcGui::loadConfig: window is outside of the screen, moved to 0x0");
290 }
291 }
292
293 restoreState( set->value( "toolbars_state" ).toByteArray(), Helper::qtVersion() );
294
295 set->endGroup();
296}
297
298void MpcGui::setupIcons() {
299 playAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(0,0,16,16) );
300 playOrPauseAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(0,0,16,16) );
301 pauseAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(16,0,16,16) );
302 pauseAndStepAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(16,0,16,16) );
303 stopAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(32,0,16,16) );
304 rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) );
305 rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
306 rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
307 forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
308 forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
309 forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) );
310 frameStepAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(144,0,16,16) );
311 muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(192,0,16,16) );
312
313 pauseAct->setCheckable(true);
314 playAct->setCheckable(true);
315 stopAct->setCheckable(true);
316 connect( muteAct, SIGNAL(toggled(bool)),
317 this, SLOT(muteIconChange(bool)) );
318
319 connect( core , SIGNAL(mediaInfoChanged()),
320 this, SLOT(updateAudioChannels()) );
321
322 connect( core , SIGNAL(stateChanged(Core::State)),
323 this, SLOT(iconChange(Core::State)) );
324}
325
326void MpcGui::iconChange(Core::State state) {
327 playAct->blockSignals(true);
328 pauseAct->blockSignals(true);
329 stopAct->blockSignals(true);
330
331 if( state == Core::Paused )
332 {
333 playAct->setChecked(false);
334 pauseAct->setChecked(true);
335 stopAct->setChecked(false);
336 }
337 if( state == Core::Playing )
338 {
339 playAct->setChecked(true);
340 pauseAct->setChecked(false);
341 stopAct->setChecked(false);
342 }
343 if( state == Core::Stopped )
344 {
345 playAct->setChecked(false);
346 pauseAct->setChecked(false);
347 stopAct->setChecked(false);
348 }
349
350 playAct->blockSignals(false);
351 pauseAct->blockSignals(false);
352 stopAct->blockSignals(false);
353}
354
355void MpcGui::muteIconChange(bool b) {
356 if( sender() == muteAct )
357 {
358 if(!b) {
359 muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(192,0,16,16) );
360 } else {
361 muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(208,0,16,16) );
362 }
363 }
364
365}
366
367
368void MpcGui::createStatusBar() {
369
370 // remove frames around statusbar items
371 statusBar()->setStyleSheet("QStatusBar::item { border: 0px solid black }; ");
372
373 // emulate mono/stereo display from mpc
374 audiochannel_display = new QLabel( statusBar() );
375 audiochannel_display->setContentsMargins(0,0,0,0);
376 audiochannel_display->setAlignment(Qt::AlignRight);
377 audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_stereo.png") );
378 audiochannel_display->setMinimumSize(audiochannel_display->sizeHint());
379 audiochannel_display->setMaximumSize(audiochannel_display->sizeHint());
380 audiochannel_display->setPixmap( QPixmap("") );
381
382 time_display = new QLabel( statusBar() );
383 time_display->setAlignment(Qt::AlignRight);
384 time_display->setText(" 88:88:88 / 88:88:88 ");
385 time_display->setMinimumSize(time_display->sizeHint());
386 time_display->setContentsMargins(15,2,1,1);
387
388 frame_display = new QLabel( statusBar() );
389 frame_display->setAlignment(Qt::AlignRight);
390 frame_display->setText("88888888");
391 frame_display->setMinimumSize(frame_display->sizeHint());
392 frame_display->setContentsMargins(15,2,1,1);
393
394 statusBar()->setAutoFillBackground(TRUE);
395
396 ColorUtils::setBackgroundColor( statusBar(), QColor(0,0,0) );
397 ColorUtils::setForegroundColor( statusBar(), QColor(255,255,255) );
398 ColorUtils::setBackgroundColor( time_display, QColor(0,0,0) );
399 ColorUtils::setForegroundColor( time_display, QColor(255,255,255) );
400 ColorUtils::setBackgroundColor( frame_display, QColor(0,0,0) );
401 ColorUtils::setForegroundColor( frame_display, QColor(255,255,255) );
402 ColorUtils::setBackgroundColor( audiochannel_display, QColor(0,0,0) );
403 ColorUtils::setForegroundColor( audiochannel_display, QColor(255,255,255) );
404 statusBar()->setSizeGripEnabled(FALSE);
405
406
407
408 statusBar()->addPermanentWidget( frame_display, 0 );
409 frame_display->setText( "0" );
410
411 statusBar()->addPermanentWidget( time_display, 0 );
412 time_display->setText(" 00:00:00 / 00:00:00 ");
413
414 statusBar()->addPermanentWidget( audiochannel_display, 0 );
415
416 time_display->show();
417 frame_display->hide();
418
419 connect( this, SIGNAL(timeChanged(QString)),
420 this, SLOT(displayTime(QString)) );
421
422 connect( this, SIGNAL(frameChanged(int)),
423 this, SLOT(displayFrame(int)) );
424}
425
426void MpcGui::displayTime(QString text) {
427 time_display->setText( text );
428 time_label_action->setText(text );
429 floating_control_time->setText(text);
430}
431
432void MpcGui::displayFrame(int frame) {
433 if (frame_display->isVisible()) {
434 frame_display->setNum( frame );
435 }
436}
437
438void MpcGui::updateAudioChannels() {
439 if( core->mdat.audio_nch == 1 ) {
440 audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_mono.png") );
441 }
442 else {
443 audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_stereo.png") );
444 }
445}
446
447void MpcGui::showFullscreenControls() {
448
449 if(pref->fullscreen && controlwidget->isHidden() && timeslidewidget->isHidden() &&
450 !pref->compact_mode )
451 {
452 controlwidget->show();
453 timeslidewidget->show();
454 statusBar()->show();
455 }
456}
457
458void MpcGui::hideFullscreenControls() {
459
460 if(pref->fullscreen && controlwidget->isVisible() && timeslidewidget->isVisible() )
461 {
462 controlwidget->hide();
463 timeslidewidget->hide();
464 statusBar()->hide();
465 }
466}
467
468void MpcGui::setJumpTexts() {
469 rewind1Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking1)) );
470 rewind2Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking2)) );
471 rewind3Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking3)) );
472
473 forward1Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking1)) );
474 forward2Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking2)) );
475 forward3Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking3)) );
476
477 /*
478 if (qApp->isLeftToRight()) {
479 */
480 rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
481 rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
482 rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) );
483
484 forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
485 forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
486 forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) );
487 /*
488 } else {
489 rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
490 rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
491 rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) );
492
493 forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
494 forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
495 forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) );
496 }
497 */
498}
499
500void MpcGui::updateWidgets() {
501
502 BaseGui::updateWidgets();
503
504 // Frame counter
505 /* frame_display->setVisible( pref->show_frame_counter ); */
506}
507
508#include "moc_mpcgui.cpp"
509
Note: See TracBrowser for help on using the repository browser.