source: smplayer/trunk/src/skingui/skingui.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

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