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

Last change on this file since 93 was 93, checked in by Silvan Scherrer, 15 years ago

smplayer: 0.6.9

File size: 14.4 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 "toolbareditor.h"
28#include "desktopinfo.h"
29#include "colorutils.h"
30
31#include <QToolBar>
32#include <QStatusBar>
33#include <QLabel>
34#include <QSlider>
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
47 connect( this, SIGNAL(cursorNearBottom(QPoint)),
48 this, SLOT(showFloatingControl(QPoint)) );
49
50 connect( this, SIGNAL(cursorFarEdges()),
51 this, SLOT(hideFloatingControl()) );
52
53 retranslateStrings();
54
55 loadConfig();
56
57 if (pref->compact_mode) {
58 controlwidget->hide();
59 timeslidewidget->hide();
60 }
61}
62
63MpcGui::~MpcGui() {
64 saveConfig();
65}
66
67void MpcGui::createActions() {
68 timeslider_action = createTimeSliderAction(this);
69 timeslider_action->disable();
70 timeslider_action->setCustomStyle( new MpcTimeSlideStyle() );
71
72#if USE_VOLUME_BAR
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 );
78#endif
79
80 time_label_action = new TimeLabelAction(this);
81 time_label_action->setObjectName("timelabel_action");
82
83 connect( this, SIGNAL(timeChanged(QString)),
84 time_label_action, SLOT(setText(QString)) );
85}
86
87
88void 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();
104
105 QLabel* pLabel = new QLabel(this);
106 pLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
107 controlwidget->addWidget(pLabel);
108
109 controlwidget->addAction(muteAct);
110 controlwidget->addAction(volumeslider_action);
111
112 timeslidewidget = new QToolBar( this );
113 timeslidewidget->setObjectName("timeslidewidget");
114 timeslidewidget->addAction(timeslider_action);
115 timeslidewidget->setMovable(false);
116
117 QColor SliderColor = palette().color(QPalette::Window);
118 QColor SliderBorderColor = palette().color(QPalette::Dark);
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::retranslateStrings() {
132 BaseGuiPlus::retranslateStrings();
133
134 controlwidget->setWindowTitle( tr("Control 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/*
222#if USE_CONFIGURABLE_TOOLBARS
223 set->beginGroup( "actions" );
224 set->setValue("controlwidget", ToolbarEditor::save(controlwidget) );
225 set->endGroup();
226#endif
227*/
228
229 set->endGroup();
230}
231
232void MpcGui::loadConfig() {
233 QSettings * set = settings;
234
235 set->beginGroup( "mpc_gui");
236
237 if (pref->save_window_size_on_exit) {
238 QPoint p = set->value("pos", pos()).toPoint();
239 QSize s = set->value("size", size()).toSize();
240
241 if ( (s.height() < 200) && (!pref->use_mplayer_window) ) {
242 s = pref->default_size;
243 }
244
245 move(p);
246 resize(s);
247
248 if (!DesktopInfo::isInsideScreen(this)) {
249 move(0,0);
250 qWarning("MpcGui::loadConfig: window is outside of the screen, moved to 0x0");
251 }
252 }
253
254 restoreState( set->value( "toolbars_state" ).toByteArray(), Helper::qtVersion() );
255
256 set->endGroup();
257}
258
259void 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) );
273
274 pauseAct->setCheckable(true);
275 playAct->setCheckable(true);
276 stopAct->setCheckable(true);
277 connect( muteAct, SIGNAL(toggled(bool)),
278 this, SLOT(muteIconChange(bool)) );
279
280 connect( core , SIGNAL(mediaInfoChanged()),
281 this, SLOT(updateAudioChannels()) );
282
283 connect( core , SIGNAL(stateChanged(Core::State)),
284 this, SLOT(iconChange(Core::State)) );
285}
286
287void MpcGui::iconChange(Core::State state) {
288 playAct->blockSignals(true);
289 pauseAct->blockSignals(true);
290 stopAct->blockSignals(true);
291
292 if( state == Core::Paused )
293 {
294 playAct->setChecked(false);
295 pauseAct->setChecked(true);
296 stopAct->setChecked(false);
297 }
298 if( state == Core::Playing )
299 {
300 playAct->setChecked(true);
301 pauseAct->setChecked(false);
302 stopAct->setChecked(false);
303 }
304 if( state == Core::Stopped )
305 {
306 playAct->setChecked(false);
307 pauseAct->setChecked(false);
308 stopAct->setChecked(false);
309 }
310
311 playAct->blockSignals(false);
312 pauseAct->blockSignals(false);
313 stopAct->blockSignals(false);
314}
315
316void MpcGui::muteIconChange(bool b) {
317 if( sender() == muteAct )
318 {
319 if(!b) {
320 muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(192,0,16,16) );
321 } else {
322 muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(208,0,16,16) );
323 }
324 }
325
326}
327
328
329void MpcGui::createStatusBar() {
330
331 // remove frames around statusbar items
332 statusBar()->setStyleSheet("QStatusBar::item { border: 0px solid black }; ");
333
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("") );
342
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);
348
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);
354
355 statusBar()->setAutoFillBackground(TRUE);
356
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);
366
367
368
369 statusBar()->addPermanentWidget( frame_display, 0 );
370 frame_display->setText( "0" );
371
372 statusBar()->addPermanentWidget( time_display, 0 );
373 time_display->setText(" 00:00:00 / 00:00:00 ");
374
375 statusBar()->addPermanentWidget( audiochannel_display, 0 );
376
377 time_display->show();
378 frame_display->hide();
379
380 connect( this, SIGNAL(timeChanged(QString)),
381 this, SLOT(displayTime(QString)) );
382
383 connect( this, SIGNAL(frameChanged(int)),
384 this, SLOT(displayFrame(int)) );
385
386 connect( this, SIGNAL(cursorNearBottom(QPoint)),
387 this, SLOT(showFullscreenControls()) );
388
389 connect( this, SIGNAL(cursorFarEdges()),
390 this, SLOT(hideFullscreenControls()) );
391}
392
393void MpcGui::displayTime(QString text) {
394 time_display->setText( text );
395 time_label_action->setText(text );
396}
397
398void MpcGui::displayFrame(int frame) {
399 if (frame_display->isVisible()) {
400 frame_display->setNum( frame );
401 }
402}
403
404void MpcGui::updateAudioChannels() {
405 if( core->mdat.audio_nch == 1 ) {
406 audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_mono.png") );
407 }
408 else {
409 audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_stereo.png") );
410 }
411}
412
413void MpcGui::showFullscreenControls() {
414
415 if(pref->fullscreen && controlwidget->isHidden() && timeslidewidget->isHidden() &&
416 !pref->compact_mode )
417 {
418 controlwidget->show();
419 timeslidewidget->show();
420 statusBar()->show();
421 }
422}
423
424void MpcGui::hideFullscreenControls() {
425
426 if(pref->fullscreen && controlwidget->isVisible() && timeslidewidget->isVisible() )
427 {
428 controlwidget->hide();
429 timeslidewidget->hide();
430 statusBar()->hide();
431 }
432}
433
434void 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)) );
438
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)) );
442
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) );
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
463void MpcGui::updateWidgets() {
464
465 BaseGui::updateWidgets();
466
467 // Frame counter
468 /* frame_display->setVisible( pref->show_frame_counter ); */
469}
470
471#include "moc_mpcgui.cpp"
472
Note: See TracBrowser for help on using the repository browser.