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

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

SMPlayer: update trunk to 0.8.6

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