source: smplayer/trunk/src/baseguiplus.cpp@ 181

Last change on this file since 181 was 181, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.8.0

  • Property svn:eol-style set to LF
File size: 28.9 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 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 "baseguiplus.h"
20#include "config.h"
21#include "myaction.h"
22#include "global.h"
23#include "images.h"
24#include "playlist.h"
25
26#ifdef TV_SUPPORT
27#include "tvlist.h"
28#else
29#include "favorites.h"
30#endif
31
32#include "widgetactions.h"
33#include "myactiongroup.h"
34
35#include <QMenu>
36#include <QCloseEvent>
37#include <QApplication>
38#include <QDesktopWidget>
39
40#if DOCK_PLAYLIST
41#include <QDockWidget>
42#include "playlistdock.h"
43#include "desktopinfo.h"
44
45#define PLAYLIST_ON_SIDES 1
46#endif
47
48#ifdef SCREENS_SUPPORT
49#include <QVBoxLayout>
50#include <QLabel>
51#include "mplayerwindow.h"
52#include "infowindow.h"
53
54#if QT_VERSION >= 0x050000
55#include <QScreen>
56#include <QWindow>
57#endif
58#endif
59
60#ifdef GLOBALSHORTCUTS
61#include "globalshortcuts/globalshortcuts.h"
62#include "preferencesdialog.h"
63#include "prefinput.h"
64#endif
65
66using namespace Global;
67
68BaseGuiPlus::BaseGuiPlus( QWidget * parent, Qt::WindowFlags flags)
69 : BaseGui( parent, flags )
70#ifdef SCREENS_SUPPORT
71 , screens_info_window(0)
72 , detached_label(0)
73#endif
74 , mainwindow_visible(true)
75 , trayicon_playlist_was_visible(false)
76 , widgets_size(0)
77#if DOCK_PLAYLIST
78 , fullscreen_playlist_was_visible(false)
79 , fullscreen_playlist_was_floating(false)
80 , compact_playlist_was_visible(false)
81 , ignore_playlist_events(false)
82#endif
83{
84 // Initialize variables
85 //infowindow_visible = false;
86 mainwindow_pos = pos();
87
88 tray = new QSystemTrayIcon(this);
89
90 tray->setToolTip( "SMPlayer" );
91 connect( tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
92 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
93
94 quitAct = new MyAction(QKeySequence("Ctrl+Q"), this, "quit");
95 connect( quitAct, SIGNAL(triggered()), this, SLOT(quit()) );
96
97 showTrayAct = new MyAction(this, "show_tray_icon" );
98 showTrayAct->setCheckable(true);
99 connect( showTrayAct, SIGNAL(toggled(bool)),
100 tray, SLOT(setVisible(bool)) );
101
102 showAllAct = new MyAction(this, "restore/hide");
103 connect( showAllAct, SIGNAL(triggered()),
104 this, SLOT(toggleShowAll()) );
105
106 context_menu = new QMenu(this);
107 context_menu->addAction(showAllAct);
108 context_menu->addSeparator();
109 context_menu->addAction(openFileAct);
110 context_menu->addMenu(recentfiles_menu);
111 context_menu->addAction(openDirectoryAct);
112 context_menu->addAction(openDVDAct);
113 context_menu->addAction(openURLAct);
114 context_menu->addMenu(favorites);
115#if defined(TV_SUPPORT) && !defined(Q_OS_WIN)
116 context_menu->addMenu(tvlist);
117 context_menu->addMenu(radiolist);
118#endif
119 context_menu->addSeparator();
120 context_menu->addAction(playOrPauseAct);
121 context_menu->addAction(stopAct);
122 context_menu->addSeparator();
123 context_menu->addAction(playPrevAct);
124 context_menu->addAction(playNextAct);
125 context_menu->addSeparator();
126 context_menu->addAction(showPlaylistAct);
127 context_menu->addAction(showPreferencesAct);
128 context_menu->addSeparator();
129 context_menu->addAction(quitAct);
130
131 tray->setContextMenu( context_menu );
132
133#if DOCK_PLAYLIST
134 // Playlistdock
135 playlistdock = new PlaylistDock(this);
136 playlistdock->setObjectName("playlistdock");
137 playlistdock->setFloating(false); // To avoid that the playlist is visible for a moment
138 playlistdock->setWidget(playlist);
139 playlistdock->setAllowedAreas(Qt::TopDockWidgetArea |
140 Qt::BottomDockWidgetArea
141#if PLAYLIST_ON_SIDES
142 | Qt::LeftDockWidgetArea |
143 Qt::RightDockWidgetArea
144#endif
145 );
146 addDockWidget(Qt::BottomDockWidgetArea, playlistdock);
147 playlistdock->hide();
148 playlistdock->setFloating(true); // Floating by default
149
150 connect( playlistdock, SIGNAL(closed()), this, SLOT(playlistClosed()) );
151#if USE_DOCK_TOPLEVEL_EVENT
152 connect( playlistdock, SIGNAL(topLevelChanged(bool)),
153 this, SLOT(dockTopLevelChanged(bool)) );
154#else
155 connect( playlistdock, SIGNAL(visibilityChanged(bool)),
156 this, SLOT(dockVisibilityChanged(bool)) );
157#endif // USE_DOCK_TOPLEVEL_EVENT
158
159 connect(this, SIGNAL(openFileRequested()), this, SLOT(showAll()));
160
161 ignore_playlist_events = false;
162#endif // DOCK_PLAYLIST
163
164#ifdef DETACH_VIDEO_OPTION
165 detachVideoAct = new MyAction(this, "detach_video");
166 detachVideoAct->setCheckable(true);
167 connect(detachVideoAct, SIGNAL(toggled(bool)), this, SLOT(detachVideo(bool)));
168#endif
169
170#ifdef SCREENS_SUPPORT
171 sendToScreen_menu = new QMenu(this);
172 sendToScreen_menu->menuAction()->setObjectName("send_to_screen_menu");
173
174 sendToScreenGroup = new MyActionGroup(this);
175 connect(sendToScreenGroup, SIGNAL(activated(int)), this, SLOT(sendVideoToScreen(int)));
176
177 updateSendToScreen();
178
179 showScreensInfoAct = new MyAction(this, "screens_info");
180 connect(showScreensInfoAct, SIGNAL(triggered()), this, SLOT(showScreensInfo()));
181
182 #if QT_VERSION >= 0x040600 && QT_VERSION < 0x050000
183 connect(qApp->desktop(), SIGNAL(screenCountChanged(int)), this, SLOT(updateSendToScreen()));
184 #endif
185 #if QT_VERSION >= 0x050000
186 connect(qApp, SIGNAL(screenAdded(QScreen *)), this, SLOT(updateSendToScreen()));
187 #endif
188 #if QT_VERSION >= 0x050400
189 connect(qApp, SIGNAL(screenRemoved(QScreen *)), this, SLOT(updateSendToScreen()));
190 #endif
191 #if QT_VERSION >= 0x050600
192 connect(qApp, SIGNAL(primaryScreenChanged(QScreen *)), this, SLOT(updateSendToScreen()));
193 #endif
194
195 // Label that replaces the mplayerwindow when detached
196 detached_label = new QLabel(panel);
197 detached_label->setAlignment(Qt::AlignCenter);
198 panel->layout()->addWidget(detached_label);
199 detached_label->hide();
200#endif
201
202#ifdef GLOBALSHORTCUTS
203 global_shortcuts = new GlobalShortcuts(this);
204 global_shortcuts->setEnabled(pref->use_global_shortcuts);
205 connect(this, SIGNAL(preferencesChanged()), this, SLOT(updateGlobalShortcuts()));
206#endif
207
208 retranslateStrings();
209 loadConfig();
210}
211
212BaseGuiPlus::~BaseGuiPlus() {
213 saveConfig();
214 tray->hide();
215}
216
217void BaseGuiPlus::populateMainMenu() {
218 qDebug("BaseGuiPlus::populateMainMenu");
219
220 BaseGui::populateMainMenu();
221
222 if (!pref->tablet_mode) {
223 openMenu->addAction(quitAct);
224 optionsMenu->addAction(showTrayAct);
225 }
226
227#ifdef DETACH_VIDEO_OPTION
228 optionsMenu->addAction(detachVideoAct);
229#endif
230
231#ifdef SCREENS_SUPPORT
232 videoMenu->insertMenu(videosize_menu->menuAction(), sendToScreen_menu);
233 //optionsMenu->addMenu(sendToScreen_menu);
234
235 if (!pref->tablet_mode) {
236 viewMenu->addSeparator();
237 viewMenu->addAction(showScreensInfoAct);
238 }
239
240 access_menu->insertMenu(tabletModeAct, sendToScreen_menu);
241#endif
242}
243
244bool BaseGuiPlus::startHidden() {
245#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
246 return false;
247#else
248 if ( (!showTrayAct->isChecked()) || (mainwindow_visible) )
249 return false;
250 else
251 return true;
252#endif
253}
254
255void BaseGuiPlus::closeEvent( QCloseEvent * e ) {
256 qDebug("BaseGuiPlus::closeEvent");
257 e->ignore();
258 closeWindow();
259}
260
261void BaseGuiPlus::closeWindow() {
262 qDebug("BaseGuiPlus::closeWindow");
263
264 if (tray->isVisible()) {
265 //e->ignore();
266 exitFullscreen();
267 showAll(false); // Hide windows
268 if (core->state() == Core::Playing) core->stop();
269
270 if (pref->balloon_count > 0) {
271 tray->showMessage( "SMPlayer",
272 tr("SMPlayer is still running here"),
273 QSystemTrayIcon::Information, 3000 );
274 pref->balloon_count--;
275 }
276
277 } else {
278 BaseGui::closeWindow();
279 }
280 //tray->hide();
281
282}
283
284void BaseGuiPlus::quit() {
285 qDebug("BaseGuiPlus::quit");
286 BaseGui::closeWindow();
287}
288
289void BaseGuiPlus::retranslateStrings() {
290 BaseGui::retranslateStrings();
291
292 tray->setIcon(Images::icon("logo", 22));
293
294 quitAct->change( Images::icon("exit"), tr("&Quit") );
295 showTrayAct->change( Images::icon("systray"), tr("S&how icon in system tray") );
296
297 updateShowAllAct();
298
299#if DOCK_PLAYLIST
300 playlistdock->setWindowTitle( tr("Playlist") );
301#endif
302
303#ifdef DETACH_VIDEO_OPTION
304 detachVideoAct->change("Detach video");
305#endif
306
307#ifdef SCREENS_SUPPORT
308 sendToScreen_menu->menuAction()->setText( tr("Send &video to screen") );
309 sendToScreen_menu->menuAction()->setIcon(Images::icon("send_to_screen"));
310 showScreensInfoAct->change(tr("Information about connected &screens"));
311
312 detached_label->setText("<img src=\"" + Images::file("send_to_screen") + "\">" +
313 "<p style=\"color: white;\">" + tr("Video is sent to an external screen") +"</p");
314#endif
315}
316
317void BaseGuiPlus::updateShowAllAct() {
318 if (isVisible())
319 showAllAct->change( tr("&Hide") );
320 else
321 showAllAct->change( tr("&Restore") );
322}
323
324void BaseGuiPlus::saveConfig() {
325 qDebug("BaseGuiPlus::saveConfig");
326
327 QSettings * set = settings;
328
329 set->beginGroup( "base_gui_plus");
330
331 set->setValue( "show_tray_icon", showTrayAct->isChecked() );
332 set->setValue( "mainwindow_visible", isVisible() );
333
334 set->setValue( "trayicon_playlist_was_visible", trayicon_playlist_was_visible );
335 set->setValue( "widgets_size", widgets_size );
336#if DOCK_PLAYLIST
337 set->setValue( "fullscreen_playlist_was_visible", fullscreen_playlist_was_visible );
338 set->setValue( "fullscreen_playlist_was_floating", fullscreen_playlist_was_floating );
339 set->setValue( "compact_playlist_was_visible", compact_playlist_was_visible );
340 set->setValue( "ignore_playlist_events", ignore_playlist_events );
341#endif
342
343/*
344#if DOCK_PLAYLIST
345 set->setValue( "playlist_and_toolbars_state", saveState() );
346#endif
347*/
348
349 set->endGroup();
350}
351
352void BaseGuiPlus::loadConfig() {
353 qDebug("BaseGuiPlus::loadConfig");
354
355 QSettings * set = settings;
356
357 set->beginGroup( "base_gui_plus");
358
359 bool show_tray_icon = set->value( "show_tray_icon", false).toBool();
360 showTrayAct->setChecked( show_tray_icon );
361 //tray->setVisible( show_tray_icon );
362
363 mainwindow_visible = set->value("mainwindow_visible", true).toBool();
364
365 trayicon_playlist_was_visible = set->value( "trayicon_playlist_was_visible", trayicon_playlist_was_visible ).toBool();
366 widgets_size = set->value( "widgets_size", widgets_size ).toInt();
367#if DOCK_PLAYLIST
368 fullscreen_playlist_was_visible = set->value( "fullscreen_playlist_was_visible", fullscreen_playlist_was_visible ).toBool();
369 fullscreen_playlist_was_floating = set->value( "fullscreen_playlist_was_floating", fullscreen_playlist_was_floating ).toBool();
370 compact_playlist_was_visible = set->value( "compact_playlist_was_visible", compact_playlist_was_visible ).toBool();
371 ignore_playlist_events = set->value( "ignore_playlist_events", ignore_playlist_events ).toBool();
372#endif
373
374/*
375#if DOCK_PLAYLIST
376 restoreState( set->value( "playlist_and_toolbars_state" ).toByteArray() );
377#endif
378*/
379
380 set->endGroup();
381
382 updateShowAllAct();
383}
384
385
386void BaseGuiPlus::trayIconActivated(QSystemTrayIcon::ActivationReason reason) {
387 qDebug("DefaultGui::trayIconActivated: %d", reason);
388
389 updateShowAllAct();
390
391 if (reason == QSystemTrayIcon::Trigger) {
392 toggleShowAll();
393 }
394 else
395 if (reason == QSystemTrayIcon::MiddleClick) {
396 core->pause();
397 }
398}
399
400void BaseGuiPlus::toggleShowAll() {
401 // Ignore if tray is not visible
402 if (tray->isVisible()) {
403 showAll( !isVisible() );
404 }
405}
406
407void BaseGuiPlus::showAll() {
408 if (!isVisible()) showAll(true);
409}
410
411void BaseGuiPlus::showAll(bool b) {
412 if (!b) {
413 // Hide all
414#if DOCK_PLAYLIST
415 trayicon_playlist_was_visible = (playlistdock->isVisible() &&
416 playlistdock->isFloating() );
417 if (trayicon_playlist_was_visible)
418 playlistdock->hide();
419
420 /*
421 trayicon_playlist_was_visible = playlistdock->isVisible();
422 playlistdock->hide();
423 */
424#else
425 trayicon_playlist_was_visible = playlist->isVisible();
426 playlist_pos = playlist->pos();
427 playlist->hide();
428#endif
429
430 mainwindow_pos = pos();
431 hide();
432
433 /*
434 infowindow_visible = info_window->isVisible();
435 infowindow_pos = info_window->pos();
436 info_window->hide();
437 */
438 } else {
439 // Show all
440 move(mainwindow_pos);
441 show();
442
443#if DOCK_PLAYLIST
444 if (trayicon_playlist_was_visible) {
445 playlistdock->show();
446 }
447#else
448 if (trayicon_playlist_was_visible) {
449 playlist->move(playlist_pos);
450 playlist->show();
451 }
452#endif
453
454 /*
455 if (infowindow_visible) {
456 info_window->show();
457 info_window->move(infowindow_pos);
458 }
459 */
460 }
461 updateShowAllAct();
462}
463
464void BaseGuiPlus::resizeWindow(int w, int h) {
465 qDebug("BaseGuiPlus::resizeWindow: %d, %d", w, h);
466
467 if ( (tray->isVisible()) && (!isVisible()) ) showAll(true);
468
469 BaseGui::resizeWindow(w, h );
470}
471
472void BaseGuiPlus::updateMediaInfo() {
473 qDebug("BaseGuiPlus::updateMediaInfo");
474 BaseGui::updateMediaInfo();
475
476 tray->setToolTip( windowTitle() );
477}
478
479void BaseGuiPlus::setWindowCaption(const QString & title) {
480 tray->setToolTip( title );
481
482 BaseGui::setWindowCaption( title );
483}
484
485
486// Playlist stuff
487void BaseGuiPlus::aboutToEnterFullscreen() {
488 qDebug("BaseGuiPlus::aboutToEnterFullscreen");
489
490 BaseGui::aboutToEnterFullscreen();
491
492#if DOCK_PLAYLIST
493 playlistdock->setAllowedAreas(Qt::NoDockWidgetArea);
494
495 int playlist_screen = QApplication::desktop()->screenNumber(playlistdock);
496 int mainwindow_screen = QApplication::desktop()->screenNumber(this);
497 qDebug("BaseGuiPlus::aboutToEnterFullscreen: mainwindow screen: %d, playlist screen: %d", mainwindow_screen, playlist_screen);
498
499 fullscreen_playlist_was_visible = playlistdock->isVisible();
500 fullscreen_playlist_was_floating = playlistdock->isFloating();
501
502 ignore_playlist_events = true;
503
504 // Hide the playlist if it's in the same screen as the main window
505 if ((playlist_screen == mainwindow_screen) /* ||
506 (!fullscreen_playlist_was_floating) */ )
507 {
508 #if QT_VERSION < 0x050000 || !defined(Q_OS_LINUX)
509 playlistdock->setFloating(true);
510 #endif
511 playlistdock->hide();
512 }
513#endif
514}
515
516void BaseGuiPlus::aboutToExitFullscreen() {
517 qDebug("BaseGuiPlus::aboutToExitFullscreen");
518
519 BaseGui::aboutToExitFullscreen();
520
521#if DOCK_PLAYLIST
522 playlistdock->setAllowedAreas(Qt::TopDockWidgetArea |
523 Qt::BottomDockWidgetArea
524 #if PLAYLIST_ON_SIDES
525 | Qt::LeftDockWidgetArea |
526 Qt::RightDockWidgetArea
527 #endif
528 );
529
530 if (fullscreen_playlist_was_visible) {
531 playlistdock->show();
532 }
533 playlistdock->setFloating( fullscreen_playlist_was_floating );
534 ignore_playlist_events = false;
535#endif
536}
537
538void BaseGuiPlus::aboutToEnterCompactMode() {
539#if DOCK_PLAYLIST
540 compact_playlist_was_visible = (playlistdock->isVisible() &&
541 !playlistdock->isFloating());
542 if (compact_playlist_was_visible)
543 playlistdock->hide();
544#endif
545
546 widgets_size = height() - panel->height();
547 qDebug("BaseGuiPlus::aboutToEnterCompactMode: widgets_size: %d", widgets_size);
548
549 BaseGui::aboutToEnterCompactMode();
550
551 if (pref->resize_method == Preferences::Always) {
552 resize( width(), height() - widgets_size );
553 }
554}
555
556void BaseGuiPlus::aboutToExitCompactMode() {
557 BaseGui::aboutToExitCompactMode();
558
559 if (pref->resize_method == Preferences::Always) {
560 resize( width(), height() + widgets_size );
561 }
562
563#if DOCK_PLAYLIST
564 if (compact_playlist_was_visible)
565 playlistdock->show();
566#endif
567}
568
569#if DOCK_PLAYLIST
570void BaseGuiPlus::showPlaylist(bool b) {
571 qDebug("BaseGuiPlus::showPlaylist: %d", b);
572 qDebug("BaseGuiPlus::showPlaylist (before): playlist visible: %d", playlistdock->isVisible());
573 qDebug("BaseGuiPlus::showPlaylist (before): playlist position: %d, %d", playlistdock->pos().x(), playlistdock->pos().y());
574 qDebug("BaseGuiPlus::showPlaylist (before): playlist size: %d x %d", playlistdock->size().width(), playlistdock->size().height());
575
576 if ( !b ) {
577 playlistdock->hide();
578 } else {
579 exitFullscreenIfNeeded();
580 playlistdock->show();
581
582 // Check if playlist is outside of the screen
583 if (playlistdock->isFloating()) {
584 if (!DesktopInfo::isInsideScreen(playlistdock)) {
585 qWarning("BaseGuiPlus::showPlaylist: playlist is outside of the screen");
586 playlistdock->move(0,0);
587 }
588 }
589 }
590 //updateWidgets();
591
592 qDebug("BaseGuiPlus::showPlaylist (after): playlist visible: %d", playlistdock->isVisible());
593 qDebug("BaseGuiPlus::showPlaylist (after): playlist position: %d, %d", playlistdock->pos().x(), playlistdock->pos().y());
594 qDebug("BaseGuiPlus::showPlaylist (after): playlist size: %d x %d", playlistdock->size().width(), playlistdock->size().height());
595
596}
597
598void BaseGuiPlus::playlistClosed() {
599 showPlaylistAct->setChecked(false);
600}
601
602#if !USE_DOCK_TOPLEVEL_EVENT
603void BaseGuiPlus::dockVisibilityChanged(bool visible) {
604 qDebug("BaseGuiPlus::dockVisibilityChanged: %d", visible);
605
606 if (!playlistdock->isFloating()) {
607 if (!visible) shrinkWindow(); else stretchWindow();
608 }
609}
610
611#else
612
613void BaseGuiPlus::dockTopLevelChanged(bool floating) {
614 qDebug("BaseGuiPlus::dockTopLevelChanged: %d", floating);
615
616 if (floating) shrinkWindow(); else stretchWindow();
617}
618#endif
619
620void BaseGuiPlus::stretchWindow() {
621 qDebug("BaseGuiPlus::stretchWindow");
622 if ((ignore_playlist_events) || (pref->resize_method!=Preferences::Always)) return;
623
624 qDebug("BaseGuiPlus::stretchWindow: dockWidgetArea: %d", (int) dockWidgetArea(playlistdock) );
625
626 if ( (dockWidgetArea(playlistdock) == Qt::TopDockWidgetArea) ||
627 (dockWidgetArea(playlistdock) == Qt::BottomDockWidgetArea) )
628 {
629 int new_height = height() + playlistdock->height();
630
631 //if (new_height > DesktopInfo::desktop_size(this).height())
632 // new_height = DesktopInfo::desktop_size(this).height() - 20;
633
634 qDebug("BaseGuiPlus::stretchWindow: stretching: new height: %d", new_height);
635 resize( width(), new_height );
636
637 //resizeWindow(core->mset.win_width, core->mset.win_height);
638 }
639
640 else
641
642 if ( (dockWidgetArea(playlistdock) == Qt::LeftDockWidgetArea) ||
643 (dockWidgetArea(playlistdock) == Qt::RightDockWidgetArea) )
644 {
645 int new_width = width() + playlistdock->width();
646
647 qDebug("BaseGuiPlus::stretchWindow: stretching: new width: %d", new_width);
648 resize( new_width, height() );
649 }
650}
651
652void BaseGuiPlus::shrinkWindow() {
653 qDebug("BaseGuiPlus::shrinkWindow");
654 if ((ignore_playlist_events) || (pref->resize_method!=Preferences::Always)) return;
655
656 qDebug("BaseGuiPlus::shrinkWindow: dockWidgetArea: %d", (int) dockWidgetArea(playlistdock) );
657
658 if ( (dockWidgetArea(playlistdock) == Qt::TopDockWidgetArea) ||
659 (dockWidgetArea(playlistdock) == Qt::BottomDockWidgetArea) )
660 {
661 int new_height = height() - playlistdock->height();
662 qDebug("DefaultGui::shrinkWindow: shrinking: new height: %d", new_height);
663 resize( width(), new_height );
664
665 //resizeWindow(core->mset.win_width, core->mset.win_height);
666 }
667
668 else
669
670 if ( (dockWidgetArea(playlistdock) == Qt::LeftDockWidgetArea) ||
671 (dockWidgetArea(playlistdock) == Qt::RightDockWidgetArea) )
672 {
673 int new_width = width() - playlistdock->width();
674
675 qDebug("BaseGuiPlus::shrinkWindow: shrinking: new width: %d", new_width);
676 resize( new_width, height() );
677 }
678}
679
680#endif
681
682#ifdef GLOBALSHORTCUTS
683void BaseGuiPlus::showPreferencesDialog() {
684 qDebug("BaseGuiPlus::showPreferencesDialog");
685 global_shortcuts->setEnabled(false);
686 BaseGui::showPreferencesDialog();
687}
688
689void BaseGuiPlus::updateGlobalShortcuts() {
690 qDebug("BaseGuiPlus::updateGlobalShortcuts");
691 global_shortcuts->setEnabled(pref->use_global_shortcuts);
692}
693#endif
694
695
696// Convenience functions intended for other GUI's
697TimeSliderAction * BaseGuiPlus::createTimeSliderAction(QWidget * parent) {
698 TimeSliderAction * timeslider_action = new TimeSliderAction( parent );
699 timeslider_action->setObjectName("timeslider_action");
700
701#ifdef SEEKBAR_RESOLUTION
702 connect( timeslider_action, SIGNAL( posChanged(int) ),
703 core, SLOT(goToPosition(int)) );
704 connect( core, SIGNAL(positionChanged(int)),
705 timeslider_action, SLOT(setPos(int)) );
706#else
707 connect( timeslider_action, SIGNAL( posChanged(int) ),
708 core, SLOT(goToPos(int)) );
709 connect( core, SIGNAL(posChanged(int)),
710 timeslider_action, SLOT(setPos(int)) );
711#endif
712 connect( timeslider_action, SIGNAL( draggingPos(int) ),
713 this, SLOT(displayGotoTime(int)) );
714#if ENABLE_DELAYED_DRAGGING
715 timeslider_action->setDragDelay( pref->time_slider_drag_delay );
716
717 connect( timeslider_action, SIGNAL( delayedDraggingPos(int) ),
718 this, SLOT(goToPosOnDragging(int)) );
719#else
720 connect( timeslider_action, SIGNAL( draggingPos(int) ),
721 this, SLOT(goToPosOnDragging(int)) );
722#endif
723
724 connect(timeslider_action, SIGNAL(wheelUp()), core, SLOT(wheelUp()));
725 connect(timeslider_action, SIGNAL(wheelDown()), core, SLOT(wheelDown()));
726
727 connect(core, SIGNAL(newDuration(double)), timeslider_action, SLOT(setDuration(double)));
728
729 return timeslider_action;
730}
731
732VolumeSliderAction * BaseGuiPlus::createVolumeSliderAction(QWidget * parent) {
733 VolumeSliderAction * volumeslider_action = new VolumeSliderAction(parent);
734 volumeslider_action->setObjectName("volumeslider_action");
735
736 connect( volumeslider_action, SIGNAL( valueChanged(int) ),
737 core, SLOT( setVolume(int) ) );
738 connect( core, SIGNAL(volumeChanged(int)),
739 volumeslider_action, SLOT(setValue(int)) );
740
741 return volumeslider_action;
742}
743
744TimeLabelAction * BaseGuiPlus::createTimeLabelAction(TimeLabelAction::TimeLabelType type, QWidget * parent) {
745 TimeLabelAction * time_label_action = new TimeLabelAction(type, parent);
746 time_label_action->setObjectName("timelabel_action");
747
748 connect(this, SIGNAL(timeChanged(double)), time_label_action, SLOT(setCurrentTime(double)));
749 connect(core, SIGNAL(newDuration(double)), time_label_action, SLOT(setTotalTime(double)));
750
751 return time_label_action;
752}
753
754#ifdef SCREENS_SUPPORT
755void BaseGuiPlus::showScreensInfo() {
756 qDebug("BaseGuiPlus::showScreensInfo");
757
758 /*
759 updateSendToScreen();
760 */
761
762 if (!screens_info_window) {
763 screens_info_window = new InfoWindow(this);
764 screens_info_window->setWindowTitle(tr("Information about connected screens"));
765 }
766
767 QString t = "<h1>" + tr("Connected screens") + "</h1>";
768#if QT_VERSION >= 0x050000
769 QList<QScreen *> screen_list = qApp->screens();
770 t += "<p>" + tr("Number of screens: %1").arg(screen_list.count());
771 QString screen_name = qApp->primaryScreen()->name();
772 #ifdef Q_OS_WIN
773 screen_name = screen_name.replace("\\\\.\\","");
774 #endif
775 t += "<p>" + tr("Primary screen: %1").arg(screen_name);
776
777 t += "<ul>";
778 foreach(QScreen *screen, screen_list) {
779 screen_name = screen->name();
780 #ifdef Q_OS_WIN
781 screen_name = screen_name.replace("\\\\.\\","");
782 #endif
783 t += "<li>" + tr("Information for screen %1").arg(screen_name);
784 t += "<ul>";
785 t += "<li>" + tr("Available geometry: %1 %2 %3 x %4").arg(screen->availableGeometry().x()).arg(screen->availableGeometry().y())
786 .arg(screen->availableGeometry().width()).arg(screen->availableGeometry().height()) + "</li>";
787 t += "<li>" + tr("Available size: %1 x %2").arg(screen->availableSize().width()).arg(screen->availableSize().height()) + "</li>";
788 t += "<li>" + tr("Available virtual geometry: %1 %2 %3 x %4").arg(screen->availableVirtualGeometry().x())
789 .arg(screen->availableVirtualGeometry().y())
790 .arg(screen->availableVirtualGeometry().width())
791 .arg(screen->availableVirtualGeometry().height()) + "</li>";
792 t += "<li>" + tr("Available virtual size: %1 x %2").arg(screen->availableVirtualSize().width())
793 .arg(screen->availableVirtualSize().height()) + "</li>";
794 t += "<li>" + tr("Depth: %1 bits").arg(screen->depth()) + "</li>";
795 t += "<li>" + tr("Geometry: %1 %2 %3 x %4").arg(screen->geometry().x()).arg(screen->geometry().y())
796 .arg(screen->geometry().width()).arg(screen->geometry().height()) + "</li>";
797 t += "<li>" + tr("Logical DPI: %1").arg(screen->logicalDotsPerInch()) + "</li>";
798 //t += "<li>" + tr("Orientation: %1").arg(screen->orientation()) + "</li>";
799 t += "<li>" + tr("Physical DPI: %1").arg(screen->physicalDotsPerInch()) + "</li>";
800 t += "<li>" + tr("Physical size: %1 x %2 mm").arg(screen->physicalSize().width()).arg(screen->physicalSize().height()) + "</li>";
801 //t += "<li>" + tr("Primary orientation: %1").arg(screen->primaryOrientation()) + "</li>";
802 t += "<li>" + tr("Refresh rate: %1 Hz").arg(screen->refreshRate()) + "</li>";
803 t += "<li>" + tr("Size: %1 x %2").arg(screen->size().width()).arg(screen->size().height()) + "</li>";
804 t += "<li>" + tr("Virtual geometry: %1 %2 %3 x %4").arg(screen->virtualGeometry().x()).arg(screen->virtualGeometry().y())
805 .arg(screen->virtualGeometry().width()).arg(screen->virtualGeometry().height()) + "</li>";
806 t += "<li>" + tr("Virtual size: %1 x %2").arg(screen->virtualSize().width()).arg(screen->virtualSize().height()) + "</li>";
807 t += "</ul></li>";
808 }
809 t += "</ul>";
810#else
811 QDesktopWidget * dw = qApp->desktop();
812 t += "<p>" + tr("Number of screens: %1").arg(dw->screenCount());
813 t += "<p>" + tr("Primary screen: %1").arg(dw->primaryScreen()+1);
814
815 t += "<ul>";
816 for (int n = 0; n < dw->screenCount(); n++) {
817 t += "<li>" + tr("Information for screen %1").arg(n+1);
818 t += "<ul>";
819 t += "<li>" + tr("Available geometry: %1 %2 %3 x %4").arg(dw->availableGeometry(n).x()).arg(dw->availableGeometry(n).y())
820 .arg(dw->availableGeometry(n).width()).arg(dw->availableGeometry(n).height()) + "</li>";
821 t += "<li>" + tr("Geometry: %1 %2 %3 x %4").arg(dw->screenGeometry(n).x()).arg(dw->screenGeometry(n).y())
822 .arg(dw->screenGeometry(n).width()).arg(dw->screenGeometry(n).height()) + "</li>";
823 t += "</ul></li>";
824 }
825 t += "</ul>";
826#endif
827
828 screens_info_window->setHtml(t);
829 screens_info_window->show();
830}
831
832void BaseGuiPlus::updateSendToScreen() {
833 qDebug("BaseGuiPlus::updateSendToScreen");
834
835 sendToScreenGroup->clear(true);
836
837#if QT_VERSION >= 0x050000
838 QList<QScreen *> screen_list = qApp->screens();
839 int n_screens = screen_list.count();
840#else
841 QDesktopWidget * dw = qApp->desktop();
842 int n_screens = dw->screenCount();
843#endif
844
845 for (int n = 0; n < n_screens; n++) {
846 QString name;
847 #if QT_VERSION >= 0x050000
848 name = screen_list[n]->name();
849 #ifdef Q_OS_WIN
850 name = name.replace("\\\\.\\","");
851 #endif
852 bool is_primary_screen = (screen_list[n] == qApp->primaryScreen());
853 #else
854 bool is_primary_screen = (n == dw->primaryScreen());
855 #endif
856 MyAction * screen_item = new MyActionGroupItem(this, sendToScreenGroup, QString("send_to_screen_%1").arg(n+1).toLatin1().constData(), n);
857 QString desc = "&" + QString::number(n+1);
858 if (!name.isEmpty()) desc += " - " + name;
859 if (is_primary_screen) desc += " (" + tr("Primary screen") + ")";
860 screen_item->change(desc);
861 }
862
863 sendToScreen_menu->clear();
864 sendToScreen_menu->addActions(sendToScreenGroup->actions());
865
866 if (n_screens == 1 && isVideoDetached()) detachVideo(false);
867}
868
869void BaseGuiPlus::sendVideoToScreen(int screen) {
870 qDebug() << "BaseGuiPlus::sendVideoToScreen:" << screen;
871
872#if QT_VERSION >= 0x050000
873 QList<QScreen *> screen_list = qApp->screens();
874 int n_screens = screen_list.count();
875#else
876 QDesktopWidget * dw = qApp->desktop();
877 int n_screens = dw->screenCount();
878#endif
879
880 if (screen < n_screens) {
881 #if QT_VERSION >= 0x050000
882 bool is_primary_screen = (screen_list[screen] == qApp->primaryScreen());
883 QRect geometry = screen_list[screen]->geometry();
884 #else
885 bool is_primary_screen = (screen == dw->primaryScreen());
886 QRect geometry = dw->screenGeometry(screen);
887 qDebug() << "BaseGuiPlus::sendVideoToScreen: screen geometry:" << geometry;
888 #endif
889 qDebug() << "BaseGuiPlus::sendVideoToScreen: is_primary_screen:" << is_primary_screen;
890 //is_primary_screen = false;
891 if (is_primary_screen) {
892 mplayerwindow->showNormal();
893 detachVideo(false);
894 } else {
895 detachVideo(true);
896 //#if QT_VERSION >= 0x050000
897 //mplayerwindow->windowHandle()->setScreen(screen_list[screen]); // Doesn't work
898 //#else
899 mplayerwindow->move(geometry.x(), geometry.y());
900 //#endif
901 qApp->processEvents();
902 //toggleFullscreen(true);
903 mplayerwindow->showFullScreen();
904 }
905 } else {
906 // Error
907 qWarning() << "BaseGuiPlus::sendVideoToScreen: screen" << screen << "is not valid";
908 }
909}
910
911bool BaseGuiPlus::isVideoDetached() {
912 return (mplayerwindow->parent() == 0);
913}
914
915void BaseGuiPlus::detachVideo(bool detach) {
916 qDebug() << "BaseGuiPlus::detachVideo:" << detach;
917
918 if (detach) {
919 if (!isVideoDetached()) {
920 toggleFullscreen(false);
921 fullscreenAct->setEnabled(false);
922
923 panel->layout()->removeWidget(mplayerwindow);
924 mplayerwindow->setParent(0);
925 mplayerwindow->setWindowTitle(tr("SMPlayer external screen output"));
926
927 detached_label->show();
928 }
929 mplayerwindow->show();
930 } else {
931 if (isVideoDetached()) {
932 fullscreenAct->setEnabled(true);
933
934 detached_label->hide();
935
936 mplayerwindow->setWindowTitle(QString::null);
937 mplayerwindow->setParent(panel);
938 panel->layout()->addWidget(mplayerwindow);
939 }
940 }
941}
942
943/*
944void BaseGuiPlus::toggleFullscreen(bool b) {
945 qDebug() << "BaseGuiPlus::toggleFullscreen:" << b;
946 if (!isVideoDetached()) {
947 BaseGui::toggleFullscreen(b);
948 } else {
949 if (b == pref->fullscreen) return;
950 pref->fullscreen = b;
951
952 if (pref->fullscreen) {
953 //aboutToEnterFullscreen();
954 mplayerwindow->showFullScreen();
955 } else {
956 mplayerwindow->showNormal();
957 //aboutToExitFullscreen();
958 }
959 }
960}
961*/
962#endif
963
964#include "moc_baseguiplus.cpp"
Note: See TracBrowser for help on using the repository browser.