1
/* Mpcgui for SMPlayer.
2
Copyright (C) 2008 matt_ <matt@endboss.org>
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.
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.
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
20
#include "mpcstyles.h"
21
#include "widgetactions.h"
22
#include "floatingwidget.h"
24
#include "mplayerwindow.h"
27
#include "toolbareditor.h"
28
#include "desktopinfo.h"
29
#include "colorutils.h"
35
#include <QApplication>
37
using namespace Global;
40
MpcGui::MpcGui( QWidget * parent, Qt::WindowFlags flags )
41
: BaseGuiPlus( parent, flags )
44
createControlWidget();
47
connect( this, SIGNAL(cursorNearBottom(QPoint)),
48
this, SLOT(showFloatingControl(QPoint)) );
50
connect( this, SIGNAL(cursorFarEdges()),
51
this, SLOT(hideFloatingControl()) );
57
if (pref->compact_mode) {
58
controlwidget->hide();
59
timeslidewidget->hide();
67
void MpcGui::createActions() {
68
timeslider_action = createTimeSliderAction(this);
69
timeslider_action->disable();
70
timeslider_action->setCustomStyle( new MpcTimeSlideStyle() );
73
volumeslider_action = createVolumeSliderAction(this);
74
volumeslider_action->disable();
75
volumeslider_action->setCustomStyle( new MpcVolumeSlideStyle() );
76
volumeslider_action->setFixedSize( QSize(50,18) );
77
volumeslider_action->setTickPosition( QSlider::NoTicks );
80
time_label_action = new TimeLabelAction(this);
81
time_label_action->setObjectName("timelabel_action");
83
connect( this, SIGNAL(timeChanged(QString)),
84
time_label_action, SLOT(setText(QString)) );
88
void MpcGui::createControlWidget() {
89
controlwidget = new QToolBar( this );
90
controlwidget->setObjectName("controlwidget");
91
controlwidget->setMovable(false);
92
controlwidget->setAllowedAreas(Qt::BottomToolBarArea);
93
controlwidget->addAction(playAct);
94
controlwidget->addAction(pauseAct);
95
controlwidget->addAction(stopAct);
96
controlwidget->addSeparator();
97
controlwidget->addAction(rewind3Act);
98
controlwidget->addAction(rewind1Act);
99
controlwidget->addAction(forward1Act);
100
controlwidget->addAction(forward3Act);
101
controlwidget->addSeparator();
102
controlwidget->addAction(frameStepAct);
103
controlwidget->addSeparator();
105
QLabel* pLabel = new QLabel(this);
106
pLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
107
controlwidget->addWidget(pLabel);
109
controlwidget->addAction(muteAct);
110
controlwidget->addAction(volumeslider_action);
112
timeslidewidget = new QToolBar( this );
113
timeslidewidget->setObjectName("timeslidewidget");
114
timeslidewidget->addAction(timeslider_action);
115
timeslidewidget->setMovable(false);
117
QColor SliderColor = palette().color(QPalette::Window);
118
QColor SliderBorderColor = palette().color(QPalette::Dark);
119
setIconSize( QSize( 16 , 16 ) );
121
addToolBar(Qt::BottomToolBarArea, controlwidget);
122
addToolBarBreak(Qt::BottomToolBarArea);
123
addToolBar(Qt::BottomToolBarArea, timeslidewidget);
125
controlwidget->setStyle(new MpcToolbarStyle() );
126
timeslidewidget->setStyle(new MpcToolbarStyle() );
131
void MpcGui::retranslateStrings() {
132
BaseGuiPlus::retranslateStrings();
134
controlwidget->setWindowTitle( tr("Control bar") );
139
#if AUTODISABLE_ACTIONS
140
void MpcGui::enableActionsOnPlaying() {
141
BaseGuiPlus::enableActionsOnPlaying();
143
timeslider_action->enable();
145
volumeslider_action->enable();
149
void MpcGui::disableActionsOnStop() {
150
BaseGuiPlus::disableActionsOnStop();
152
timeslider_action->disable();
154
volumeslider_action->disable();
157
#endif // AUTODISABLE_ACTIONS
159
void MpcGui::aboutToEnterFullscreen() {
160
BaseGuiPlus::aboutToEnterFullscreen();
162
if (!pref->compact_mode) {
163
controlwidget->hide();
164
timeslidewidget->hide();
169
void MpcGui::aboutToExitFullscreen() {
170
BaseGuiPlus::aboutToExitFullscreen();
172
if (!pref->compact_mode) {
173
controlwidget->show();
175
timeslidewidget->show();
179
void MpcGui::aboutToEnterCompactMode() {
180
BaseGuiPlus::aboutToEnterCompactMode();
182
controlwidget->hide();
183
timeslidewidget->hide();
187
void MpcGui::aboutToExitCompactMode() {
188
BaseGuiPlus::aboutToExitCompactMode();
191
controlwidget->show();
192
timeslidewidget->show();
195
void MpcGui::showFloatingControl(QPoint /*p*/) {
198
void MpcGui::hideFloatingControl() {
202
QSize MpcGui::mpcmumSizeHint() const {
203
return QSize(controlwidget->sizeHint().width(), 0);
208
void MpcGui::saveConfig() {
209
QSettings * set = settings;
211
set->beginGroup( "mpc_gui");
213
if (pref->save_window_size_on_exit) {
214
qDebug("MpcGui::saveConfig: w: %d h: %d", width(), height());
215
set->setValue( "pos", pos() );
216
set->setValue( "size", size() );
219
set->setValue( "toolbars_state", saveState(Helper::qtVersion()) );
222
#if USE_CONFIGURABLE_TOOLBARS
223
set->beginGroup( "actions" );
224
set->setValue("controlwidget", ToolbarEditor::save(controlwidget) );
232
void MpcGui::loadConfig() {
233
QSettings * set = settings;
235
set->beginGroup( "mpc_gui");
237
if (pref->save_window_size_on_exit) {
238
QPoint p = set->value("pos", pos()).toPoint();
239
QSize s = set->value("size", size()).toSize();
241
if ( (s.height() < 200) && (!pref->use_mplayer_window) ) {
242
s = pref->default_size;
248
if (!DesktopInfo::isInsideScreen(this)) {
250
qWarning("MpcGui::loadConfig: window is outside of the screen, moved to 0x0");
254
restoreState( set->value( "toolbars_state" ).toByteArray(), Helper::qtVersion() );
259
void MpcGui::setupIcons() {
260
playAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(0,0,16,16) );
261
playOrPauseAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(0,0,16,16) );
262
pauseAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(16,0,16,16) );
263
pauseAndStepAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(16,0,16,16) );
264
stopAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(32,0,16,16) );
265
rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) );
266
rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
267
rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
268
forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
269
forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
270
forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) );
271
frameStepAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(144,0,16,16) );
272
muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(192,0,16,16) );
274
pauseAct->setCheckable(true);
275
playAct->setCheckable(true);
276
stopAct->setCheckable(true);
277
connect( muteAct, SIGNAL(toggled(bool)),
278
this, SLOT(muteIconChange(bool)) );
280
connect( core , SIGNAL(mediaInfoChanged()),
281
this, SLOT(updateAudioChannels()) );
283
connect( core , SIGNAL(stateChanged(Core::State)),
284
this, SLOT(iconChange(Core::State)) );
287
void MpcGui::iconChange(Core::State state) {
288
playAct->blockSignals(true);
289
pauseAct->blockSignals(true);
290
stopAct->blockSignals(true);
292
if( state == Core::Paused )
294
playAct->setChecked(false);
295
pauseAct->setChecked(true);
296
stopAct->setChecked(false);
298
if( state == Core::Playing )
300
playAct->setChecked(true);
301
pauseAct->setChecked(false);
302
stopAct->setChecked(false);
304
if( state == Core::Stopped )
306
playAct->setChecked(false);
307
pauseAct->setChecked(false);
308
stopAct->setChecked(false);
311
playAct->blockSignals(false);
312
pauseAct->blockSignals(false);
313
stopAct->blockSignals(false);
316
void MpcGui::muteIconChange(bool b) {
317
if( sender() == muteAct )
320
muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(192,0,16,16) );
322
muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(208,0,16,16) );
329
void MpcGui::createStatusBar() {
331
// remove frames around statusbar items
332
statusBar()->setStyleSheet("QStatusBar::item { border: 0px solid black }; ");
334
// emulate mono/stereo display from mpc
335
audiochannel_display = new QLabel( statusBar() );
336
audiochannel_display->setContentsMargins(0,0,0,0);
337
audiochannel_display->setAlignment(Qt::AlignRight);
338
audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_stereo.png") );
339
audiochannel_display->setMinimumSize(audiochannel_display->sizeHint());
340
audiochannel_display->setMaximumSize(audiochannel_display->sizeHint());
341
audiochannel_display->setPixmap( QPixmap("") );
343
time_display = new QLabel( statusBar() );
344
time_display->setAlignment(Qt::AlignRight);
345
time_display->setText(" 88:88:88 / 88:88:88 ");
346
time_display->setMinimumSize(time_display->sizeHint());
347
time_display->setContentsMargins(15,2,1,1);
349
frame_display = new QLabel( statusBar() );
350
frame_display->setAlignment(Qt::AlignRight);
351
frame_display->setText("88888888");
352
frame_display->setMinimumSize(frame_display->sizeHint());
353
frame_display->setContentsMargins(15,2,1,1);
355
statusBar()->setAutoFillBackground(TRUE);
357
ColorUtils::setBackgroundColor( statusBar(), QColor(0,0,0) );
358
ColorUtils::setForegroundColor( statusBar(), QColor(255,255,255) );
359
ColorUtils::setBackgroundColor( time_display, QColor(0,0,0) );
360
ColorUtils::setForegroundColor( time_display, QColor(255,255,255) );
361
ColorUtils::setBackgroundColor( frame_display, QColor(0,0,0) );
362
ColorUtils::setForegroundColor( frame_display, QColor(255,255,255) );
363
ColorUtils::setBackgroundColor( audiochannel_display, QColor(0,0,0) );
364
ColorUtils::setForegroundColor( audiochannel_display, QColor(255,255,255) );
365
statusBar()->setSizeGripEnabled(FALSE);
369
statusBar()->addPermanentWidget( frame_display, 0 );
370
frame_display->setText( "0" );
372
statusBar()->addPermanentWidget( time_display, 0 );
373
time_display->setText(" 00:00:00 / 00:00:00 ");
375
statusBar()->addPermanentWidget( audiochannel_display, 0 );
377
time_display->show();
378
frame_display->hide();
380
connect( this, SIGNAL(timeChanged(QString)),
381
this, SLOT(displayTime(QString)) );
383
connect( this, SIGNAL(frameChanged(int)),
384
this, SLOT(displayFrame(int)) );
386
connect( this, SIGNAL(cursorNearBottom(QPoint)),
387
this, SLOT(showFullscreenControls()) );
389
connect( this, SIGNAL(cursorFarEdges()),
390
this, SLOT(hideFullscreenControls()) );
393
void MpcGui::displayTime(QString text) {
394
time_display->setText( text );
395
time_label_action->setText(text );
398
void MpcGui::displayFrame(int frame) {
399
if (frame_display->isVisible()) {
400
frame_display->setNum( frame );
404
void MpcGui::updateAudioChannels() {
405
if( core->mdat.audio_nch == 1 ) {
406
audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_mono.png") );
409
audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_stereo.png") );
413
void MpcGui::showFullscreenControls() {
415
if(pref->fullscreen && controlwidget->isHidden() && timeslidewidget->isHidden() &&
416
!pref->compact_mode )
418
controlwidget->show();
419
timeslidewidget->show();
424
void MpcGui::hideFullscreenControls() {
426
if(pref->fullscreen && controlwidget->isVisible() && timeslidewidget->isVisible() )
428
controlwidget->hide();
429
timeslidewidget->hide();
434
void MpcGui::setJumpTexts() {
435
rewind1Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking1)) );
436
rewind2Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking2)) );
437
rewind3Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking3)) );
439
forward1Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking1)) );
440
forward2Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking2)) );
441
forward3Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking3)) );
443
if (qApp->isLeftToRight()) {
444
rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
445
rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
446
rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) );
448
forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
449
forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
450
forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) );
453
rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
454
rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
455
rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) );
457
forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
458
forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
459
forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) );
463
void MpcGui::updateWidgets() {
465
BaseGui::updateWidgets();
468
frame_display->setVisible( pref->show_frame_counter );
471
#include "moc_mpcgui.cpp"