source: smplayer/trunk/src/skingui/skingui.cpp@ 142

Last change on this file since 142 was 142, checked in by Silvan Scherrer, 12 years ago

SMPlayer: update trunk to 0.8.5

File size: 17.8 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2013 Ricardo Villalba <rvm@users.sourceforge.net>
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 "skingui.h"
20#include "helper.h"
21#include "colorutils.h"
22#include "core.h"
23#include "global.h"
24#include "widgetactions.h"
25#include "playlist.h"
26#include "mplayerwindow.h"
27#include "myaction.h"
28#include "images.h"
29#include "floatingwidget.h"
30#include "desktopinfo.h"
31#include "editabletoolbar.h"
32#include "mediabarpanel.h"
33#include "actionseditor.h"
34
35#if DOCK_PLAYLIST
36#include "playlistdock.h"
37#endif
38
39#include <QMenu>
40#include <QSettings>
41#include <QLabel>
42#include <QStatusBar>
43#include <QPushButton>
44#include <QToolButton>
45#include <QMenuBar>
46#include <QLayout>
47#include <QApplication>
48#include <QDir>
49
50#define TOOLBAR_VERSION 1
51
52using namespace Global;
53
54SkinGui::SkinGui( QWidget * parent, Qt::WindowFlags flags )
55 : BaseGuiPlus( parent, flags )
56{
57 connect( this, SIGNAL(timeChanged(QString)),
58 this, SLOT(displayTime(QString)) );
59
60 connect( this, SIGNAL(cursorNearBottom(QPoint)),
61 this, SLOT(showFloatingControl(QPoint)) );
62 connect( this, SIGNAL(cursorNearTop(QPoint)),
63 this, SLOT(showFloatingMenu(QPoint)) );
64 connect( this, SIGNAL(cursorFarEdges()),
65 this, SLOT(hideFloatingControls()) );
66
67 createActions();
68 createMainToolBars();
69 createControlWidget();
70#if SKIN_CONTROLWIDGET_OVER_VIDEO
71 createFloatingControl();
72#endif
73 createMenus();
74
75#if USE_CONFIGURABLE_TOOLBARS
76 connect( editToolbar1Act, SIGNAL(triggered()),
77 toolbar1, SLOT(edit()) );
78 #if SKIN_CONTROLWIDGET_OVER_VIDEO
79 floating_control->toolbar()->takeAvailableActionsFrom(this);
80 connect( editFloatingControlAct, SIGNAL(triggered()),
81 floating_control->toolbar(), SLOT(edit()) );
82 #endif
83#endif
84
85 retranslateStrings();
86
87 loadConfig();
88
89 //if (playlist_visible) showPlaylist(true);
90
91 if (pref->compact_mode) {
92 controlwidget->hide();
93 toolbar1->hide();
94 }
95
96 statusBar()->hide();
97
98 changeStyleSheet(pref->iconset);
99}
100
101SkinGui::~SkinGui() {
102 saveConfig();
103}
104
105void SkinGui::changeStyleSheet(QString style) {
106 if (style.isEmpty()) {
107 qApp->setStyleSheet("");
108 }
109 else {
110 QString qss = Images::styleSheet();
111 QDir current = QDir::current();
112 QString td = Images::themesDirectory();
113 QString relativePath = current.relativeFilePath(td);
114 qss.replace(QRegExp("url\\s*\\(\\s*([^\\);]+)\\s*\\)", Qt::CaseSensitive, QRegExp::RegExp2),
115 QString("url(%1\\1)").arg(relativePath + "/"));
116 //qDebug("qss: %s", qss.toLatin1().constData());
117 qApp->setStyleSheet(qss);
118 }
119}
120
121void SkinGui::createActions() {
122 qDebug("SkinGui::createActions");
123
124 timeslider_action = createTimeSliderAction(this);
125 timeslider_action->disable();
126
127 volumeslider_action = createVolumeSliderAction(this);
128 volumeslider_action->disable();
129
130 // Create the time label
131 time_label_action = new TimeLabelAction(this);
132 time_label_action->setObjectName("timelabel_action");
133
134#if MINI_ARROW_BUTTONS
135 QList<QAction*> rewind_actions;
136 rewind_actions << rewind1Act << rewind2Act << rewind3Act;
137 rewindbutton_action = new SeekingButton(rewind_actions, this);
138 rewindbutton_action->setObjectName("rewindbutton_action");
139
140 QList<QAction*> forward_actions;
141 forward_actions << forward1Act << forward2Act << forward3Act;
142 forwardbutton_action = new SeekingButton(forward_actions, this);
143 forwardbutton_action->setObjectName("forwardbutton_action");
144#endif
145
146#if USE_CONFIGURABLE_TOOLBARS
147 editToolbar1Act = new MyAction( this, "edit_main_toolbar" );
148 #if SKIN_CONTROLWIDGET_OVER_VIDEO
149 editFloatingControlAct = new MyAction( this, "edit_floating_control" );
150 #endif
151#endif
152
153 playOrPauseAct->setCheckable(true);
154}
155
156#if AUTODISABLE_ACTIONS
157void SkinGui::enableActionsOnPlaying() {
158 qDebug("SkinGui::enableActionsOnPlaying");
159 BaseGuiPlus::enableActionsOnPlaying();
160
161 timeslider_action->enable();
162 volumeslider_action->enable();
163}
164
165void SkinGui::disableActionsOnStop() {
166 qDebug("SkinGui::disableActionsOnStop");
167 BaseGuiPlus::disableActionsOnStop();
168
169 timeslider_action->disable();
170 volumeslider_action->disable();
171}
172
173void SkinGui::togglePlayAction(Core::State state) {
174 qDebug("SkinGui::togglePlayAction");
175 BaseGuiPlus::togglePlayAction(state);
176
177 if (state == Core::Playing) {
178 playOrPauseAct->setChecked(true);
179 }
180 else {
181 playOrPauseAct->setChecked(false);
182 }
183}
184#endif // AUTODISABLE_ACTIONS
185
186void SkinGui::createMenus() {
187 menuBar()->setObjectName("menubar");
188 QFont font = menuBar()->font();
189 font.setPixelSize(11);
190 menuBar()->setFont(font);
191 menuBar()->setFixedHeight(21);
192
193 toolbar_menu = new QMenu(this);
194 toolbar_menu->addAction(toolbar1->toggleViewAction());
195#if USE_CONFIGURABLE_TOOLBARS
196 toolbar_menu->addSeparator();
197 toolbar_menu->addAction(editToolbar1Act);
198 #if SKIN_CONTROLWIDGET_OVER_VIDEO
199 toolbar_menu->addAction(editFloatingControlAct);
200 #endif
201#endif
202 optionsMenu->addSeparator();
203 optionsMenu->addMenu(toolbar_menu);
204}
205
206QMenu * SkinGui::createPopupMenu() {
207 QMenu * m = new QMenu(this);
208#if USE_CONFIGURABLE_TOOLBARS
209 m->addAction(editToolbar1Act);
210 #if SKIN_CONTROLWIDGET_OVER_VIDEO
211 m->addAction(editFloatingControlAct);
212 #endif
213#else
214 m->addAction(toolbar1->toggleViewAction());
215#endif
216 return m;
217}
218
219void SkinGui::createMainToolBars() {
220 toolbar1 = new EditableToolbar( this );
221 toolbar1->setObjectName("toolbar");
222 toolbar1->setMovable(false);
223 toolbar1->setFixedHeight(35);
224 addToolBar(Qt::TopToolBarArea, toolbar1);
225#if USE_CONFIGURABLE_TOOLBARS
226 QStringList toolbar1_actions;
227 toolbar1_actions << "open_file" << "open_url" << "favorites_menu" << "separator"
228 << "screenshot" << "separator" << "show_file_properties"
229 << "show_find_sub_dialog" << "show_tube_browser" << "show_preferences";
230 toolbar1->setDefaultActions(toolbar1_actions);
231#else
232 toolbar1->addAction(openFileAct);
233 toolbar1->addAction(openURLAct);
234 toolbar1->addSeparator();
235 toolbar1->addAction(compactAct);
236 toolbar1->addAction(fullscreenAct);
237 toolbar1->addSeparator();
238 toolbar1->addAction(screenshotAct);
239 toolbar1->addSeparator();
240 toolbar1->addAction(showPropertiesAct);
241 toolbar1->addAction(showFindSubtitlesDialogAct);
242 toolbar1->addAction(showPreferencesAct);
243 // Test:
244 //toolbar1->addSeparator();
245 //toolbar1->addAction(timeslider_action);
246 //toolbar1->addAction(volumeslider_action);
247#endif
248
249 // Modify toolbars' actions
250 QAction *tba;
251 tba = toolbar1->toggleViewAction();
252 tba->setObjectName("show_main_toolbar");
253 tba->setShortcut(Qt::Key_F5);
254}
255
256
257void SkinGui::createControlWidget() {
258 qDebug("SkinGui::createControlWidget");
259
260 controlwidget = new QToolBar( this );
261 controlwidget->setObjectName("controlwidget");
262 controlwidget->setStyleSheet("QToolBar { spacing: 0px; }");
263 controlwidget->setMovable(false);
264 addToolBar(Qt::BottomToolBarArea, controlwidget);
265
266 mediaBarPanel = new MediaBarPanel(panel);
267 mediaBarPanel->setObjectName("mediabar-panel");
268 mediaBarPanel->setCore(core);
269 /* panel->layout()->addWidget(mediaBarPanel); */
270
271 QList<QAction*> actions;
272 //actions << halveSpeedAct << playPrevAct << playOrPauseAct << stopAct << recordAct << playNextAct << doubleSpeedAct;
273 actions << rewind1Act << playPrevAct << playOrPauseAct << stopAct << playNextAct << forward1Act;
274 mediaBarPanel->setPlayControlActionCollection(actions);
275
276 actions.clear();
277 //actions << timeslider_action << shuffleAct << repeatPlaylistAct;
278 QAction * shuffleAct = ActionsEditor::findAction(playlist, "pl_shuffle");
279 QAction * repeatPlaylistAct = ActionsEditor::findAction(playlist, "pl_repeat");
280 if (shuffleAct) actions << shuffleAct;
281 if (repeatPlaylistAct) actions << repeatPlaylistAct;
282 mediaBarPanel->setMediaPanelActionCollection(actions);
283 connect(core, SIGNAL(stateChanged(Core::State)), mediaBarPanel, SLOT(setMplayerState(Core::State)));
284
285 actions.clear();
286 //actions << volumeslider_action << showPlaylistAct << fullscreenAct << equalizerAct;
287 actions << volumeslider_action << showPlaylistAct << fullscreenAct << videoEqualizerAct;
288 mediaBarPanel->setVolumeControlActionCollection(actions);
289
290 actions.clear();
291 actions << openFileAct << openDirectoryAct << openDVDAct << openURLAct << screenshotAct << showPropertiesAct;
292#ifdef FIND_SUBTITLES
293 actions << showFindSubtitlesDialogAct;
294#endif
295 actions << showPreferencesAct;
296 mediaBarPanel->setToolbarActionCollection(actions);
297
298 connect(mediaBarPanel, SIGNAL(volumeChanged(int)), core, SLOT(setVolume(int)));
299 connect(mediaBarPanel, SIGNAL(volumeSliderMoved(int)), core, SLOT(setVolume(int)));
300 connect(core, SIGNAL(volumeChanged(int)), mediaBarPanel, SLOT(setVolume(int)));
301
302#ifdef SEEKBAR_RESOLUTION
303 connect(mediaBarPanel, SIGNAL(seekerChanged(int)), core, SLOT(goToPosition(int)));
304 connect(core, SIGNAL(positionChanged(int)), mediaBarPanel, SLOT(setSeeker(int)));
305#else
306 connect(mediaBarPanel, SIGNAL(seekerChanged(int)), core, SLOT(goToPos(int)));
307 connect(core, SIGNAL(posChanged(int)),mediaBarPanel, SLOT(setSeeker(int)));
308#endif
309
310 controlwidget->addWidget(mediaBarPanel);
311}
312
313#if SKIN_CONTROLWIDGET_OVER_VIDEO
314void SkinGui::createFloatingControl() {
315 // Floating control
316 floating_control = new FloatingWidget(this);
317
318#if USE_CONFIGURABLE_TOOLBARS
319 QStringList floatingcontrol_actions;
320 floatingcontrol_actions << "play" << "pause" << "stop" << "separator";
321 #if MINI_ARROW_BUTTONS
322 floatingcontrol_actions << "rewindbutton_action";
323 #else
324 floatingcontrol_actions << "rewind3" << "rewind2" << "rewind1";
325 #endif
326 floatingcontrol_actions << "timeslider_action";
327 #if MINI_ARROW_BUTTONS
328 floatingcontrol_actions << "forwardbutton_action";
329 #else
330 floatingcontrol_actions << "forward1" << "forward2" << "forward3";
331 #endif
332 floatingcontrol_actions << "separator" << "fullscreen" << "mute" << "volumeslider_action" << "separator" << "timelabel_action";
333 floating_control->toolbar()->setDefaultActions(floatingcontrol_actions);
334#else
335 floating_control->toolbar()->addAction(playAct);
336 floating_control->toolbar()->addAction(pauseAct);
337 floating_control->toolbar()->addAction(stopAct);
338 floating_control->toolbar()->addSeparator();
339
340 #if MINI_ARROW_BUTTONS
341 floating_control->toolbar()->addAction( rewindbutton_action );
342 #else
343 floating_control->toolbar()->addAction(rewind3Act);
344 floating_control->toolbar()->addAction(rewind2Act);
345 floating_control->toolbar()->addAction(rewind1Act);
346 #endif
347
348 floating_control->toolbar()->addAction(timeslider_action);
349
350 #if MINI_ARROW_BUTTONS
351 floating_control->toolbar()->addAction( forwardbutton_action );
352 #else
353 floating_control->toolbar()->addAction(forward1Act);
354 floating_control->toolbar()->addAction(forward2Act);
355 floating_control->toolbar()->addAction(forward3Act);
356 #endif
357
358 floating_control->toolbar()->addSeparator();
359 floating_control->toolbar()->addAction(fullscreenAct);
360 floating_control->toolbar()->addAction(muteAct);
361 floating_control->toolbar()->addAction(volumeslider_action);
362 floating_control->toolbar()->addSeparator();
363 floating_control->toolbar()->addAction(time_label_action);
364#endif // USE_CONFIGURABLE_TOOLBARS
365
366#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
367 // To make work the ESC key (exit fullscreen) and Ctrl-X (close) in Windows and OS2
368 floating_control->addAction(exitFullscreenAct);
369 floating_control->addAction(exitAct);
370#endif
371
372#if !USE_CONFIGURABLE_TOOLBARS
373 floating_control->adjustSize();
374#endif
375}
376#endif
377
378void SkinGui::retranslateStrings() {
379 BaseGuiPlus::retranslateStrings();
380
381 toolbar_menu->menuAction()->setText( tr("&Toolbars") );
382 toolbar_menu->menuAction()->setIcon( Images::icon("toolbars") );
383
384 toolbar1->setWindowTitle( tr("&Main toolbar") );
385 toolbar1->toggleViewAction()->setIcon(Images::icon("main_toolbar"));
386
387#if USE_CONFIGURABLE_TOOLBARS
388 editToolbar1Act->change( tr("Edit main &toolbar") );
389 #if SKIN_CONTROLWIDGET_OVER_VIDEO
390 editFloatingControlAct->change( tr("Edit &floating control") );
391 #endif
392#endif
393
394 mediaBarPanel->setVolume(core->mset.volume);
395}
396
397void SkinGui::displayTime(QString text) {
398 time_label_action->setText(text);
399}
400
401void SkinGui::displayState(Core::State state) {
402 BaseGuiPlus::displayState(state);
403
404 switch (state) {
405 case Core::Playing: mediaBarPanel->displayMessage( tr("Playing %1").arg(core->mdat.filename)); break;
406 case Core::Paused: mediaBarPanel->displayMessage( tr("Pause") ); break;
407 case Core::Stopped: mediaBarPanel->displayMessage( tr("Stop") ); break;
408 }
409}
410
411void SkinGui::displayMessage(QString message) {
412 BaseGuiPlus::displayMessage(message);
413 mediaBarPanel->displayMessage(message);
414}
415
416void SkinGui::updateWidgets() {
417 qDebug("SkinGui::updateWidgets");
418
419 BaseGuiPlus::updateWidgets();
420
421 panel->setFocus();
422}
423
424void SkinGui::aboutToEnterFullscreen() {
425 qDebug("SkinGui::aboutToEnterFullscreen");
426
427 BaseGuiPlus::aboutToEnterFullscreen();
428
429 // Save visibility of toolbars
430 fullscreen_toolbar1_was_visible = toolbar1->isVisible();
431
432 if (!pref->compact_mode) {
433 controlwidget->hide();
434 toolbar1->hide();
435 }
436}
437
438void SkinGui::aboutToExitFullscreen() {
439 qDebug("SkinGui::aboutToExitFullscreen");
440
441 BaseGuiPlus::aboutToExitFullscreen();
442
443#if SKIN_CONTROLWIDGET_OVER_VIDEO
444 floating_control->hide();
445#endif
446
447 if (!pref->compact_mode) {
448 statusBar()->hide();
449 controlwidget->show();
450 toolbar1->setVisible( fullscreen_toolbar1_was_visible );
451 }
452}
453
454void SkinGui::aboutToEnterCompactMode() {
455
456 BaseGuiPlus::aboutToEnterCompactMode();
457
458 // Save visibility of toolbars
459 compact_toolbar1_was_visible = toolbar1->isVisible();
460
461 controlwidget->hide();
462 toolbar1->hide();
463}
464
465void SkinGui::aboutToExitCompactMode() {
466 BaseGuiPlus::aboutToExitCompactMode();
467
468 statusBar()->hide();
469 controlwidget->show();
470 toolbar1->setVisible( compact_toolbar1_was_visible );
471
472 // Recheck size of controlwidget
473 /* resizeEvent( new QResizeEvent( size(), size() ) ); */
474}
475
476void SkinGui::showFloatingControl(QPoint /*p*/) {
477 qDebug("SkinGui::showFloatingControl");
478
479#if SKIN_CONTROLWIDGET_OVER_VIDEO
480 if ((pref->compact_mode) && (!pref->fullscreen)) {
481 floating_control->setAnimated( false );
482 } else {
483 floating_control->setAnimated( pref->floating_control_animated );
484 }
485 floating_control->setMargin(pref->floating_control_margin);
486 #ifndef Q_OS_WIN
487 floating_control->setBypassWindowManager(pref->bypass_window_manager);
488 #endif
489 floating_control->showOver(panel, pref->floating_control_width);
490#else
491 if (!controlwidget->isVisible()) {
492 controlwidget->show();
493 }
494#endif
495}
496
497void SkinGui::showFloatingMenu(QPoint /*p*/) {
498#if !SKIN_CONTROLWIDGET_OVER_VIDEO
499 qDebug("SkinGui::showFloatingMenu");
500
501 if (!menuBar()->isVisible())
502 menuBar()->show();
503#endif
504}
505
506void SkinGui::hideFloatingControls() {
507 qDebug("SkinGui::hideFloatingControls");
508
509#if SKIN_CONTROLWIDGET_OVER_VIDEO
510 floating_control->hide();
511#else
512 if (controlwidget->isVisible())
513 controlwidget->hide();
514
515 if (menuBar()->isVisible())
516 menuBar()->hide();
517#endif
518}
519
520void SkinGui::saveConfig() {
521 qDebug("SkinGui::saveConfig");
522
523 QSettings * set = settings;
524
525 set->beginGroup( "skin_gui");
526
527 set->setValue("fullscreen_toolbar1_was_visible", fullscreen_toolbar1_was_visible);
528 set->setValue("compact_toolbar1_was_visible", compact_toolbar1_was_visible);
529
530 if (pref->save_window_size_on_exit) {
531 qDebug("SkinGui::saveConfig: w: %d h: %d", width(), height());
532 set->setValue( "pos", pos() );
533 set->setValue( "size", size() );
534 }
535
536 set->setValue( "toolbars_state", saveState(Helper::qtVersion()) );
537
538#if USE_CONFIGURABLE_TOOLBARS
539 set->beginGroup( "actions" );
540 set->setValue("toolbar1", toolbar1->actionsToStringList() );
541 #if SKIN_CONTROLWIDGET_OVER_VIDEO
542 set->setValue("floating_control", floating_control->toolbar()->actionsToStringList() );
543 #endif
544 set->setValue("toolbar1_version", TOOLBAR_VERSION);
545 set->endGroup();
546#endif
547
548 set->endGroup();
549}
550
551void SkinGui::loadConfig() {
552 qDebug("SkinGui::loadConfig");
553
554 QSettings * set = settings;
555
556 set->beginGroup( "skin_gui");
557
558 fullscreen_toolbar1_was_visible = set->value("fullscreen_toolbar1_was_visible", fullscreen_toolbar1_was_visible).toBool();
559 compact_toolbar1_was_visible = set->value("compact_toolbar1_was_visible", compact_toolbar1_was_visible).toBool();
560
561 if (pref->save_window_size_on_exit) {
562 QPoint p = set->value("pos", pos()).toPoint();
563 QSize s = set->value("size", size()).toSize();
564
565 if ( (s.height() < 200) && (!pref->use_mplayer_window) ) {
566 s = pref->default_size;
567 }
568
569 move(p);
570 resize(s);
571
572 if (!DesktopInfo::isInsideScreen(this)) {
573 move(0,0);
574 qWarning("SkinGui::loadConfig: window is outside of the screen, moved to 0x0");
575 }
576 }
577
578#if USE_CONFIGURABLE_TOOLBARS
579 set->beginGroup( "actions" );
580 int toolbar_version = set->value("toolbar1_version", 0).toInt();
581 if (toolbar_version >= TOOLBAR_VERSION) {
582 toolbar1->setActionsFromStringList( set->value("toolbar1", toolbar1->defaultActions()).toStringList() );
583 } else {
584 qDebug("SkinGui::loadConfig: toolbar too old, loading default one");
585 toolbar1->setActionsFromStringList( toolbar1->defaultActions() );
586 }
587 #if SKIN_CONTROLWIDGET_OVER_VIDEO
588 floating_control->toolbar()->setActionsFromStringList( set->value("floating_control", floating_control->toolbar()->defaultActions()).toStringList() );
589 floating_control->adjustSize();
590 #endif
591 set->endGroup();
592#endif
593
594 restoreState( set->value( "toolbars_state" ).toByteArray(), Helper::qtVersion() );
595
596#if DOCK_PLAYLIST
597 qDebug("SkinGui::loadConfig: playlist visible: %d", playlistdock->isVisible());
598 qDebug("SkinGui::loadConfig: playlist position: %d, %d", playlistdock->pos().x(), playlistdock->pos().y());
599 qDebug("SkinGui::loadConfig: playlist size: %d x %d", playlistdock->size().width(), playlistdock->size().height());
600#endif
601
602 set->endGroup();
603
604 updateWidgets();
605}
606
607#include "moc_skingui.cpp"
Note: See TracBrowser for help on using the repository browser.