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

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

SMPlayer: update trunk to latest 0.8.7

  • Property svn:eol-style set to LF
File size: 15.0 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
139void MpcGui::retranslateStrings() {
140 BaseGuiPlus::retranslateStrings();
141
142 controlwidget->setWindowTitle( tr("Control bar") );
143 timeslidewidget->setWindowTitle( tr("Seek bar") );
144
145 setupIcons();
146}
147
148#if AUTODISABLE_ACTIONS
149void MpcGui::enableActionsOnPlaying() {
150 BaseGuiPlus::enableActionsOnPlaying();
151
152 timeslider_action->enable();
153#if USE_VOLUME_BAR
154 volumeslider_action->enable();
155#endif
156}
157
158void MpcGui::disableActionsOnStop() {
159 BaseGuiPlus::disableActionsOnStop();
160
161 timeslider_action->disable();
162#if USE_VOLUME_BAR
163 volumeslider_action->disable();
164#endif
165}
166#endif // AUTODISABLE_ACTIONS
167
168void MpcGui::aboutToEnterFullscreen() {
169 BaseGuiPlus::aboutToEnterFullscreen();
170
171 // Show floating_control
172 // Move controls to the floating_control layout
173 removeToolBarBreak(controlwidget);
174 removeToolBar(controlwidget);
175 removeToolBar(timeslidewidget);
176 floating_control->layout()->addWidget(timeslidewidget);
177 floating_control->layout()->addItem(spacer);
178 floating_control->layout()->addWidget(controlwidget);
179 controlwidget->show();
180 timeslidewidget->show();
181 floating_control->adjustSize();
182
183 floating_control->setMargin(pref->floating_control_margin);
184 floating_control->setPercWidth(pref->floating_control_width);
185 floating_control->setAnimated(pref->floating_control_animated);
186 floating_control->setActivationArea( (AutohideWidget::Activation) pref->floating_activation_area);
187 floating_control->setHideDelay(pref->floating_hide_delay);
188 QTimer::singleShot(500, floating_control, SLOT(activate()));
189
190
191 if (!pref->compact_mode) {
192 //controlwidget->hide();
193 //timeslidewidget->hide();
194 statusBar()->hide();
195 }
196}
197
198void MpcGui::aboutToExitFullscreen() {
199 BaseGuiPlus::aboutToExitFullscreen();
200
201 // Remove controls from the floating_control and put them back to the mainwindow
202 floating_control->deactivate();
203 floating_control->layout()->removeWidget(controlwidget);
204 floating_control->layout()->removeWidget(timeslidewidget);
205 floating_control->layout()->removeItem(spacer);
206 addToolBar(Qt::BottomToolBarArea, controlwidget);
207 addToolBarBreak(Qt::BottomToolBarArea);
208 addToolBar(Qt::BottomToolBarArea, timeslidewidget);
209
210 if (!pref->compact_mode) {
211 controlwidget->show();
212 statusBar()->show();
213 timeslidewidget->show();
214 } else {
215 controlwidget->hide();
216 timeslidewidget->hide();
217 }
218}
219
220void MpcGui::aboutToEnterCompactMode() {
221 BaseGuiPlus::aboutToEnterCompactMode();
222
223 controlwidget->hide();
224 timeslidewidget->hide();
225 statusBar()->hide();
226}
227
228void MpcGui::aboutToExitCompactMode() {
229 BaseGuiPlus::aboutToExitCompactMode();
230
231 statusBar()->show();
232 controlwidget->show();
233 timeslidewidget->show();
234}
235
236#if USE_mpcMUMSIZE
237QSize MpcGui::mpcmumSizeHint() const {
238 return QSize(controlwidget->sizeHint().width(), 0);
239}
240#endif
241
242
243void MpcGui::saveConfig() {
244 QSettings * set = settings;
245
246 set->beginGroup( "mpc_gui");
247
248 if (pref->save_window_size_on_exit) {
249 qDebug("MpcGui::saveConfig: w: %d h: %d", width(), height());
250 set->setValue( "pos", pos() );
251 set->setValue( "size", size() );
252 set->setValue( "state", (int) windowState() );
253 }
254
255 set->setValue( "toolbars_state", saveState(Helper::qtVersion()) );
256
257 set->endGroup();
258}
259
260void MpcGui::loadConfig() {
261 QSettings * set = settings;
262
263 set->beginGroup( "mpc_gui");
264
265 if (pref->save_window_size_on_exit) {
266 QPoint p = set->value("pos", pos()).toPoint();
267 QSize s = set->value("size", size()).toSize();
268
269 if ( (s.height() < 200) && (!pref->use_mplayer_window) ) {
270 s = pref->default_size;
271 }
272
273 move(p);
274 resize(s);
275
276 setWindowState( (Qt::WindowStates) set->value("state", 0).toInt() );
277
278 if (!DesktopInfo::isInsideScreen(this)) {
279 move(0,0);
280 qWarning("MpcGui::loadConfig: window is outside of the screen, moved to 0x0");
281 }
282 }
283
284 restoreState( set->value( "toolbars_state" ).toByteArray(), Helper::qtVersion() );
285
286 set->endGroup();
287}
288
289void MpcGui::setupIcons() {
290 playAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(0,0,16,16) );
291 playOrPauseAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(0,0,16,16) );
292 pauseAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(16,0,16,16) );
293 pauseAndStepAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(16,0,16,16) );
294 stopAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(32,0,16,16) );
295 rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) );
296 rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
297 rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
298 forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
299 forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
300 forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) );
301 frameStepAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(144,0,16,16) );
302 muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(192,0,16,16) );
303
304 pauseAct->setCheckable(true);
305 playAct->setCheckable(true);
306 stopAct->setCheckable(true);
307 connect( muteAct, SIGNAL(toggled(bool)),
308 this, SLOT(muteIconChange(bool)) );
309
310 connect( core , SIGNAL(mediaInfoChanged()),
311 this, SLOT(updateAudioChannels()) );
312
313 connect( core , SIGNAL(stateChanged(Core::State)),
314 this, SLOT(iconChange(Core::State)) );
315}
316
317void MpcGui::iconChange(Core::State state) {
318 playAct->blockSignals(true);
319 pauseAct->blockSignals(true);
320 stopAct->blockSignals(true);
321
322 if( state == Core::Paused )
323 {
324 playAct->setChecked(false);
325 pauseAct->setChecked(true);
326 stopAct->setChecked(false);
327 }
328 if( state == Core::Playing )
329 {
330 playAct->setChecked(true);
331 pauseAct->setChecked(false);
332 stopAct->setChecked(false);
333 }
334 if( state == Core::Stopped )
335 {
336 playAct->setChecked(false);
337 pauseAct->setChecked(false);
338 stopAct->setChecked(false);
339 }
340
341 playAct->blockSignals(false);
342 pauseAct->blockSignals(false);
343 stopAct->blockSignals(false);
344}
345
346void MpcGui::muteIconChange(bool b) {
347 if( sender() == muteAct )
348 {
349 if(!b) {
350 muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(192,0,16,16) );
351 } else {
352 muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(208,0,16,16) );
353 }
354 }
355
356}
357
358
359void MpcGui::createStatusBar() {
360
361 // remove frames around statusbar items
362 statusBar()->setStyleSheet("QStatusBar::item { border: 0px solid black }; ");
363
364 // emulate mono/stereo display from mpc
365 audiochannel_display = new QLabel( statusBar() );
366 audiochannel_display->setContentsMargins(0,0,0,0);
367 audiochannel_display->setAlignment(Qt::AlignRight);
368 audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_stereo.png") );
369 audiochannel_display->setMinimumSize(audiochannel_display->sizeHint());
370 audiochannel_display->setMaximumSize(audiochannel_display->sizeHint());
371 audiochannel_display->setPixmap( QPixmap("") );
372
373 time_display = new QLabel( statusBar() );
374 time_display->setAlignment(Qt::AlignRight);
375 time_display->setText(" 88:88:88 / 88:88:88 ");
376 time_display->setMinimumSize(time_display->sizeHint());
377 time_display->setContentsMargins(15,2,1,1);
378
379 frame_display = new QLabel( statusBar() );
380 frame_display->setAlignment(Qt::AlignRight);
381 frame_display->setText("88888888");
382 frame_display->setMinimumSize(frame_display->sizeHint());
383 frame_display->setContentsMargins(15,2,1,1);
384
385 statusBar()->setAutoFillBackground(TRUE);
386
387 ColorUtils::setBackgroundColor( statusBar(), QColor(0,0,0) );
388 ColorUtils::setForegroundColor( statusBar(), QColor(255,255,255) );
389 ColorUtils::setBackgroundColor( time_display, QColor(0,0,0) );
390 ColorUtils::setForegroundColor( time_display, QColor(255,255,255) );
391 ColorUtils::setBackgroundColor( frame_display, QColor(0,0,0) );
392 ColorUtils::setForegroundColor( frame_display, QColor(255,255,255) );
393 ColorUtils::setBackgroundColor( audiochannel_display, QColor(0,0,0) );
394 ColorUtils::setForegroundColor( audiochannel_display, QColor(255,255,255) );
395 statusBar()->setSizeGripEnabled(FALSE);
396
397
398
399 statusBar()->addPermanentWidget( frame_display, 0 );
400 frame_display->setText( "0" );
401
402 statusBar()->addPermanentWidget( time_display, 0 );
403 time_display->setText(" 00:00:00 / 00:00:00 ");
404
405 statusBar()->addPermanentWidget( audiochannel_display, 0 );
406
407 time_display->show();
408 frame_display->hide();
409
410 connect( this, SIGNAL(timeChanged(QString)),
411 this, SLOT(displayTime(QString)) );
412
413 connect( this, SIGNAL(frameChanged(int)),
414 this, SLOT(displayFrame(int)) );
415}
416
417void MpcGui::displayTime(QString text) {
418 time_display->setText( text );
419 time_label_action->setText(text );
420}
421
422void MpcGui::displayFrame(int frame) {
423 if (frame_display->isVisible()) {
424 frame_display->setNum( frame );
425 }
426}
427
428void MpcGui::updateAudioChannels() {
429 if( core->mdat.audio_nch == 1 ) {
430 audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_mono.png") );
431 }
432 else {
433 audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_stereo.png") );
434 }
435}
436
437void MpcGui::showFullscreenControls() {
438
439 if(pref->fullscreen && controlwidget->isHidden() && timeslidewidget->isHidden() &&
440 !pref->compact_mode )
441 {
442 controlwidget->show();
443 timeslidewidget->show();
444 statusBar()->show();
445 }
446}
447
448void MpcGui::hideFullscreenControls() {
449
450 if(pref->fullscreen && controlwidget->isVisible() && timeslidewidget->isVisible() )
451 {
452 controlwidget->hide();
453 timeslidewidget->hide();
454 statusBar()->hide();
455 }
456}
457
458void MpcGui::setJumpTexts() {
459 rewind1Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking1)) );
460 rewind2Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking2)) );
461 rewind3Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking3)) );
462
463 forward1Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking1)) );
464 forward2Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking2)) );
465 forward3Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking3)) );
466
467 /*
468 if (qApp->isLeftToRight()) {
469 */
470 rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
471 rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
472 rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) );
473
474 forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
475 forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
476 forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) );
477 /*
478 } else {
479 rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
480 rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) );
481 rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) );
482
483 forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
484 forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) );
485 forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) );
486 }
487 */
488}
489
490void MpcGui::updateWidgets() {
491
492 BaseGui::updateWidgets();
493
494 // Frame counter
495 /* frame_display->setVisible( pref->show_frame_counter ); */
496}
497
498#include "moc_mpcgui.cpp"
499
Note: See TracBrowser for help on using the repository browser.