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

Last change on this file since 139 was 128, checked in by Silvan Scherrer, 13 years ago

SMPlayer: trunk update to latest svn

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