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

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

smplayer: restore some os/2 removals from vendor, fix branding

  • Property svn:eol-style set to LF
File size: 29.3 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#ifndef Q_OS_OS2
225 optionsMenu->addAction(showTrayAct);
226#else
227 trayAvailable();
228 connect( optionsMenu, SIGNAL(aboutToShow()),
229 this, SLOT(trayAvailable()) );
230#endif
231 }
232
233#ifdef DETACH_VIDEO_OPTION
234 optionsMenu->addAction(detachVideoAct);
235#endif
236
237#ifdef SCREENS_SUPPORT
238 videoMenu->insertMenu(videosize_menu->menuAction(), sendToScreen_menu);
239 //optionsMenu->addMenu(sendToScreen_menu);
240
241 if (!pref->tablet_mode) {
242 viewMenu->addSeparator();
243 viewMenu->addAction(showScreensInfoAct);
244 }
245
246 access_menu->insertMenu(tabletModeAct, sendToScreen_menu);
247#endif
248}
249
250bool BaseGuiPlus::startHidden() {
251#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
252 return false;
253#else
254 if ( (!showTrayAct->isChecked()) || (mainwindow_visible) )
255 return false;
256 else
257 return true;
258#endif
259}
260
261void BaseGuiPlus::closeEvent( QCloseEvent * e ) {
262 qDebug("BaseGuiPlus::closeEvent");
263 e->ignore();
264 closeWindow();
265}
266
267void BaseGuiPlus::closeWindow() {
268 qDebug("BaseGuiPlus::closeWindow");
269
270 if (tray->isVisible()) {
271 //e->ignore();
272 exitFullscreen();
273 showAll(false); // Hide windows
274 if (core->state() == Core::Playing) core->stop();
275
276 if (pref->balloon_count > 0) {
277 tray->showMessage( "SMPlayer",
278 tr("SMPlayer is still running here"),
279 QSystemTrayIcon::Information, 3000 );
280 pref->balloon_count--;
281 }
282
283 } else {
284 BaseGui::closeWindow();
285 }
286 //tray->hide();
287
288}
289
290void BaseGuiPlus::quit() {
291 qDebug("BaseGuiPlus::quit");
292 BaseGui::closeWindow();
293}
294
295void BaseGuiPlus::retranslateStrings() {
296 BaseGui::retranslateStrings();
297
298 tray->setIcon(Images::icon("logo", 22));
299
300 quitAct->change( Images::icon("exit"), tr("&Quit") );
301 showTrayAct->change( Images::icon("systray"), tr("S&how icon in system tray") );
302
303 updateShowAllAct();
304
305#if DOCK_PLAYLIST
306 playlistdock->setWindowTitle( tr("Playlist") );
307#endif
308
309#ifdef DETACH_VIDEO_OPTION
310 detachVideoAct->change("Detach video");
311#endif
312
313#ifdef SCREENS_SUPPORT
314 sendToScreen_menu->menuAction()->setText( tr("Send &video to screen") );
315 sendToScreen_menu->menuAction()->setIcon(Images::icon("send_to_screen"));
316 showScreensInfoAct->change(tr("Information about connected &screens"));
317
318 detached_label->setText("<img src=\"" + Images::file("send_to_screen") + "\">" +
319 "<p style=\"color: white;\">" + tr("Video is sent to an external screen") +"</p");
320#endif
321}
322
323void BaseGuiPlus::updateShowAllAct() {
324 if (isVisible())
325 showAllAct->change( tr("&Hide") );
326 else
327 showAllAct->change( tr("&Restore") );
328}
329
330void BaseGuiPlus::saveConfig() {
331 qDebug("BaseGuiPlus::saveConfig");
332
333 QSettings * set = settings;
334
335 set->beginGroup( "base_gui_plus");
336
337 set->setValue( "show_tray_icon", showTrayAct->isChecked() );
338 set->setValue( "mainwindow_visible", isVisible() );
339
340 set->setValue( "trayicon_playlist_was_visible", trayicon_playlist_was_visible );
341 set->setValue( "widgets_size", widgets_size );
342#if DOCK_PLAYLIST
343 set->setValue( "fullscreen_playlist_was_visible", fullscreen_playlist_was_visible );
344 set->setValue( "fullscreen_playlist_was_floating", fullscreen_playlist_was_floating );
345 set->setValue( "compact_playlist_was_visible", compact_playlist_was_visible );
346 set->setValue( "ignore_playlist_events", ignore_playlist_events );
347#endif
348
349/*
350#if DOCK_PLAYLIST
351 set->setValue( "playlist_and_toolbars_state", saveState() );
352#endif
353*/
354
355 set->endGroup();
356}
357
358void BaseGuiPlus::loadConfig() {
359 qDebug("BaseGuiPlus::loadConfig");
360
361 QSettings * set = settings;
362
363 set->beginGroup( "base_gui_plus");
364
365 bool show_tray_icon = set->value( "show_tray_icon", false).toBool();
366 showTrayAct->setChecked( show_tray_icon );
367 //tray->setVisible( show_tray_icon );
368
369 mainwindow_visible = set->value("mainwindow_visible", true).toBool();
370
371 trayicon_playlist_was_visible = set->value( "trayicon_playlist_was_visible", trayicon_playlist_was_visible ).toBool();
372 widgets_size = set->value( "widgets_size", widgets_size ).toInt();
373#if DOCK_PLAYLIST
374 fullscreen_playlist_was_visible = set->value( "fullscreen_playlist_was_visible", fullscreen_playlist_was_visible ).toBool();
375 fullscreen_playlist_was_floating = set->value( "fullscreen_playlist_was_floating", fullscreen_playlist_was_floating ).toBool();
376 compact_playlist_was_visible = set->value( "compact_playlist_was_visible", compact_playlist_was_visible ).toBool();
377 ignore_playlist_events = set->value( "ignore_playlist_events", ignore_playlist_events ).toBool();
378#endif
379
380/*
381#if DOCK_PLAYLIST
382 restoreState( set->value( "playlist_and_toolbars_state" ).toByteArray() );
383#endif
384*/
385
386 set->endGroup();
387
388 updateShowAllAct();
389}
390
391
392void BaseGuiPlus::trayIconActivated(QSystemTrayIcon::ActivationReason reason) {
393 qDebug("DefaultGui::trayIconActivated: %d", reason);
394
395 updateShowAllAct();
396
397 if (reason == QSystemTrayIcon::Trigger) {
398 toggleShowAll();
399 }
400 else
401 if (reason == QSystemTrayIcon::MiddleClick) {
402 core->pause();
403 }
404}
405
406void BaseGuiPlus::toggleShowAll() {
407 // Ignore if tray is not visible
408 if (tray->isVisible()) {
409 showAll( !isVisible() );
410 }
411}
412
413void BaseGuiPlus::showAll() {
414 if (!isVisible()) showAll(true);
415}
416
417void BaseGuiPlus::showAll(bool b) {
418 if (!b) {
419 // Hide all
420#if DOCK_PLAYLIST
421 trayicon_playlist_was_visible = (playlistdock->isVisible() &&
422 playlistdock->isFloating() );
423 if (trayicon_playlist_was_visible)
424 playlistdock->hide();
425
426 /*
427 trayicon_playlist_was_visible = playlistdock->isVisible();
428 playlistdock->hide();
429 */
430#else
431 trayicon_playlist_was_visible = playlist->isVisible();
432 playlist_pos = playlist->pos();
433 playlist->hide();
434#endif
435
436 mainwindow_pos = pos();
437 hide();
438
439 /*
440 infowindow_visible = info_window->isVisible();
441 infowindow_pos = info_window->pos();
442 info_window->hide();
443 */
444 } else {
445 // Show all
446 move(mainwindow_pos);
447 show();
448
449#if DOCK_PLAYLIST
450 if (trayicon_playlist_was_visible) {
451 playlistdock->show();
452 }
453#else
454 if (trayicon_playlist_was_visible) {
455 playlist->move(playlist_pos);
456 playlist->show();
457 }
458#endif
459
460 /*
461 if (infowindow_visible) {
462 info_window->show();
463 info_window->move(infowindow_pos);
464 }
465 */
466 }
467 updateShowAllAct();
468}
469
470void BaseGuiPlus::resizeWindow(int w, int h) {
471 qDebug("BaseGuiPlus::resizeWindow: %d, %d", w, h);
472
473 if ( (tray->isVisible()) && (!isVisible()) ) showAll(true);
474
475 BaseGui::resizeWindow(w, h );
476}
477
478void BaseGuiPlus::updateMediaInfo() {
479 qDebug("BaseGuiPlus::updateMediaInfo");
480 BaseGui::updateMediaInfo();
481
482 tray->setToolTip( windowTitle() );
483}
484
485void BaseGuiPlus::setWindowCaption(const QString & title) {
486 tray->setToolTip( title );
487
488 BaseGui::setWindowCaption( title );
489}
490
491
492// Playlist stuff
493void BaseGuiPlus::aboutToEnterFullscreen() {
494 qDebug("BaseGuiPlus::aboutToEnterFullscreen");
495
496 BaseGui::aboutToEnterFullscreen();
497
498#if DOCK_PLAYLIST
499 playlistdock->setAllowedAreas(Qt::NoDockWidgetArea);
500
501 int playlist_screen = QApplication::desktop()->screenNumber(playlistdock);
502 int mainwindow_screen = QApplication::desktop()->screenNumber(this);
503 qDebug("BaseGuiPlus::aboutToEnterFullscreen: mainwindow screen: %d, playlist screen: %d", mainwindow_screen, playlist_screen);
504
505 fullscreen_playlist_was_visible = playlistdock->isVisible();
506 fullscreen_playlist_was_floating = playlistdock->isFloating();
507
508 ignore_playlist_events = true;
509
510 // Hide the playlist if it's in the same screen as the main window
511 if ((playlist_screen == mainwindow_screen) /* ||
512 (!fullscreen_playlist_was_floating) */ )
513 {
514 #if QT_VERSION < 0x050000 || !defined(Q_OS_LINUX)
515 playlistdock->setFloating(true);
516 #endif
517 playlistdock->hide();
518 }
519#endif
520}
521
522void BaseGuiPlus::aboutToExitFullscreen() {
523 qDebug("BaseGuiPlus::aboutToExitFullscreen");
524
525 BaseGui::aboutToExitFullscreen();
526
527#if DOCK_PLAYLIST
528 playlistdock->setAllowedAreas(Qt::TopDockWidgetArea |
529 Qt::BottomDockWidgetArea
530 #if PLAYLIST_ON_SIDES
531 | Qt::LeftDockWidgetArea |
532 Qt::RightDockWidgetArea
533 #endif
534 );
535
536 if (fullscreen_playlist_was_visible) {
537 playlistdock->show();
538 }
539 playlistdock->setFloating( fullscreen_playlist_was_floating );
540 ignore_playlist_events = false;
541#endif
542}
543
544void BaseGuiPlus::aboutToEnterCompactMode() {
545#if DOCK_PLAYLIST
546 compact_playlist_was_visible = (playlistdock->isVisible() &&
547 !playlistdock->isFloating());
548 if (compact_playlist_was_visible)
549 playlistdock->hide();
550#endif
551
552 widgets_size = height() - panel->height();
553 qDebug("BaseGuiPlus::aboutToEnterCompactMode: widgets_size: %d", widgets_size);
554
555 BaseGui::aboutToEnterCompactMode();
556
557 if (pref->resize_method == Preferences::Always) {
558 resize( width(), height() - widgets_size );
559 }
560}
561
562void BaseGuiPlus::aboutToExitCompactMode() {
563 BaseGui::aboutToExitCompactMode();
564
565 if (pref->resize_method == Preferences::Always) {
566 resize( width(), height() + widgets_size );
567 }
568
569#if DOCK_PLAYLIST
570 if (compact_playlist_was_visible)
571 playlistdock->show();
572#endif
573}
574
575#if DOCK_PLAYLIST
576void BaseGuiPlus::showPlaylist(bool b) {
577 qDebug("BaseGuiPlus::showPlaylist: %d", b);
578 qDebug("BaseGuiPlus::showPlaylist (before): playlist visible: %d", playlistdock->isVisible());
579 qDebug("BaseGuiPlus::showPlaylist (before): playlist position: %d, %d", playlistdock->pos().x(), playlistdock->pos().y());
580 qDebug("BaseGuiPlus::showPlaylist (before): playlist size: %d x %d", playlistdock->size().width(), playlistdock->size().height());
581
582 if ( !b ) {
583 playlistdock->hide();
584 } else {
585 exitFullscreenIfNeeded();
586 playlistdock->show();
587
588 // Check if playlist is outside of the screen
589 if (playlistdock->isFloating()) {
590 if (!DesktopInfo::isInsideScreen(playlistdock)) {
591 qWarning("BaseGuiPlus::showPlaylist: playlist is outside of the screen");
592 playlistdock->move(0,0);
593 }
594 }
595 }
596 //updateWidgets();
597
598 qDebug("BaseGuiPlus::showPlaylist (after): playlist visible: %d", playlistdock->isVisible());
599 qDebug("BaseGuiPlus::showPlaylist (after): playlist position: %d, %d", playlistdock->pos().x(), playlistdock->pos().y());
600 qDebug("BaseGuiPlus::showPlaylist (after): playlist size: %d x %d", playlistdock->size().width(), playlistdock->size().height());
601
602}
603
604void BaseGuiPlus::playlistClosed() {
605 showPlaylistAct->setChecked(false);
606}
607
608#if !USE_DOCK_TOPLEVEL_EVENT
609void BaseGuiPlus::dockVisibilityChanged(bool visible) {
610 qDebug("BaseGuiPlus::dockVisibilityChanged: %d", visible);
611
612 if (!playlistdock->isFloating()) {
613 if (!visible) shrinkWindow(); else stretchWindow();
614 }
615}
616
617#else
618
619void BaseGuiPlus::dockTopLevelChanged(bool floating) {
620 qDebug("BaseGuiPlus::dockTopLevelChanged: %d", floating);
621
622 if (floating) shrinkWindow(); else stretchWindow();
623}
624#endif
625
626void BaseGuiPlus::stretchWindow() {
627 qDebug("BaseGuiPlus::stretchWindow");
628 if ((ignore_playlist_events) || (pref->resize_method!=Preferences::Always)) return;
629
630 qDebug("BaseGuiPlus::stretchWindow: dockWidgetArea: %d", (int) dockWidgetArea(playlistdock) );
631
632 if ( (dockWidgetArea(playlistdock) == Qt::TopDockWidgetArea) ||
633 (dockWidgetArea(playlistdock) == Qt::BottomDockWidgetArea) )
634 {
635 int new_height = height() + playlistdock->height();
636
637 //if (new_height > DesktopInfo::desktop_size(this).height())
638 // new_height = DesktopInfo::desktop_size(this).height() - 20;
639
640 qDebug("BaseGuiPlus::stretchWindow: stretching: new height: %d", new_height);
641 resize( width(), new_height );
642
643 //resizeWindow(core->mset.win_width, core->mset.win_height);
644 }
645
646 else
647
648 if ( (dockWidgetArea(playlistdock) == Qt::LeftDockWidgetArea) ||
649 (dockWidgetArea(playlistdock) == Qt::RightDockWidgetArea) )
650 {
651 int new_width = width() + playlistdock->width();
652
653 qDebug("BaseGuiPlus::stretchWindow: stretching: new width: %d", new_width);
654 resize( new_width, height() );
655 }
656}
657
658void BaseGuiPlus::shrinkWindow() {
659 qDebug("BaseGuiPlus::shrinkWindow");
660 if ((ignore_playlist_events) || (pref->resize_method!=Preferences::Always)) return;
661
662 qDebug("BaseGuiPlus::shrinkWindow: dockWidgetArea: %d", (int) dockWidgetArea(playlistdock) );
663
664 if ( (dockWidgetArea(playlistdock) == Qt::TopDockWidgetArea) ||
665 (dockWidgetArea(playlistdock) == Qt::BottomDockWidgetArea) )
666 {
667 int new_height = height() - playlistdock->height();
668 qDebug("DefaultGui::shrinkWindow: shrinking: new height: %d", new_height);
669 resize( width(), new_height );
670
671 //resizeWindow(core->mset.win_width, core->mset.win_height);
672 }
673
674 else
675
676 if ( (dockWidgetArea(playlistdock) == Qt::LeftDockWidgetArea) ||
677 (dockWidgetArea(playlistdock) == Qt::RightDockWidgetArea) )
678 {
679 int new_width = width() - playlistdock->width();
680
681 qDebug("BaseGuiPlus::shrinkWindow: shrinking: new width: %d", new_width);
682 resize( new_width, height() );
683 }
684}
685
686#endif
687
688#ifdef GLOBALSHORTCUTS
689void BaseGuiPlus::showPreferencesDialog() {
690 qDebug("BaseGuiPlus::showPreferencesDialog");
691 global_shortcuts->setEnabled(false);
692 BaseGui::showPreferencesDialog();
693}
694
695void BaseGuiPlus::updateGlobalShortcuts() {
696 qDebug("BaseGuiPlus::updateGlobalShortcuts");
697 global_shortcuts->setEnabled(pref->use_global_shortcuts);
698}
699#endif
700
701#ifdef Q_OS_OS2
702/*
703 * we test if xcenter is available at all. if not disable the tray action.
704 * this is possible when xcenter is not opened or crashed
705 */
706void BaseGuiPlus::trayAvailable() {
707 if (!tray->isSystemTrayAvailable())
708 optionsMenu->removeAction(showTrayAct);
709 else
710 optionsMenu->addAction(showTrayAct);
711}
712#endif
713
714// Convenience functions intended for other GUI's
715TimeSliderAction * BaseGuiPlus::createTimeSliderAction(QWidget * parent) {
716 TimeSliderAction * timeslider_action = new TimeSliderAction( parent );
717 timeslider_action->setObjectName("timeslider_action");
718
719#ifdef SEEKBAR_RESOLUTION
720 connect( timeslider_action, SIGNAL( posChanged(int) ),
721 core, SLOT(goToPosition(int)) );
722 connect( core, SIGNAL(positionChanged(int)),
723 timeslider_action, SLOT(setPos(int)) );
724#else
725 connect( timeslider_action, SIGNAL( posChanged(int) ),
726 core, SLOT(goToPos(int)) );
727 connect( core, SIGNAL(posChanged(int)),
728 timeslider_action, SLOT(setPos(int)) );
729#endif
730 connect( timeslider_action, SIGNAL( draggingPos(int) ),
731 this, SLOT(displayGotoTime(int)) );
732#if ENABLE_DELAYED_DRAGGING
733 timeslider_action->setDragDelay( pref->time_slider_drag_delay );
734
735 connect( timeslider_action, SIGNAL( delayedDraggingPos(int) ),
736 this, SLOT(goToPosOnDragging(int)) );
737#else
738 connect( timeslider_action, SIGNAL( draggingPos(int) ),
739 this, SLOT(goToPosOnDragging(int)) );
740#endif
741
742 connect(timeslider_action, SIGNAL(wheelUp()), core, SLOT(wheelUp()));
743 connect(timeslider_action, SIGNAL(wheelDown()), core, SLOT(wheelDown()));
744
745 connect(core, SIGNAL(newDuration(double)), timeslider_action, SLOT(setDuration(double)));
746
747 return timeslider_action;
748}
749
750VolumeSliderAction * BaseGuiPlus::createVolumeSliderAction(QWidget * parent) {
751 VolumeSliderAction * volumeslider_action = new VolumeSliderAction(parent);
752 volumeslider_action->setObjectName("volumeslider_action");
753
754 connect( volumeslider_action, SIGNAL( valueChanged(int) ),
755 core, SLOT( setVolume(int) ) );
756 connect( core, SIGNAL(volumeChanged(int)),
757 volumeslider_action, SLOT(setValue(int)) );
758
759 return volumeslider_action;
760}
761
762TimeLabelAction * BaseGuiPlus::createTimeLabelAction(TimeLabelAction::TimeLabelType type, QWidget * parent) {
763 TimeLabelAction * time_label_action = new TimeLabelAction(type, parent);
764 time_label_action->setObjectName("timelabel_action");
765
766 connect(this, SIGNAL(timeChanged(double)), time_label_action, SLOT(setCurrentTime(double)));
767 connect(core, SIGNAL(newDuration(double)), time_label_action, SLOT(setTotalTime(double)));
768
769 return time_label_action;
770}
771
772#ifdef SCREENS_SUPPORT
773void BaseGuiPlus::showScreensInfo() {
774 qDebug("BaseGuiPlus::showScreensInfo");
775
776 /*
777 updateSendToScreen();
778 */
779
780 if (!screens_info_window) {
781 screens_info_window = new InfoWindow(this);
782 screens_info_window->setWindowTitle(tr("Information about connected screens"));
783 }
784
785 QString t = "<h1>" + tr("Connected screens") + "</h1>";
786#if QT_VERSION >= 0x050000
787 QList<QScreen *> screen_list = qApp->screens();
788 t += "<p>" + tr("Number of screens: %1").arg(screen_list.count());
789 QString screen_name = qApp->primaryScreen()->name();
790 #ifdef Q_OS_WIN
791 screen_name = screen_name.replace("\\\\.\\","");
792 #endif
793 t += "<p>" + tr("Primary screen: %1").arg(screen_name);
794
795 t += "<ul>";
796 foreach(QScreen *screen, screen_list) {
797 screen_name = screen->name();
798 #ifdef Q_OS_WIN
799 screen_name = screen_name.replace("\\\\.\\","");
800 #endif
801 t += "<li>" + tr("Information for screen %1").arg(screen_name);
802 t += "<ul>";
803 t += "<li>" + tr("Available geometry: %1 %2 %3 x %4").arg(screen->availableGeometry().x()).arg(screen->availableGeometry().y())
804 .arg(screen->availableGeometry().width()).arg(screen->availableGeometry().height()) + "</li>";
805 t += "<li>" + tr("Available size: %1 x %2").arg(screen->availableSize().width()).arg(screen->availableSize().height()) + "</li>";
806 t += "<li>" + tr("Available virtual geometry: %1 %2 %3 x %4").arg(screen->availableVirtualGeometry().x())
807 .arg(screen->availableVirtualGeometry().y())
808 .arg(screen->availableVirtualGeometry().width())
809 .arg(screen->availableVirtualGeometry().height()) + "</li>";
810 t += "<li>" + tr("Available virtual size: %1 x %2").arg(screen->availableVirtualSize().width())
811 .arg(screen->availableVirtualSize().height()) + "</li>";
812 t += "<li>" + tr("Depth: %1 bits").arg(screen->depth()) + "</li>";
813 t += "<li>" + tr("Geometry: %1 %2 %3 x %4").arg(screen->geometry().x()).arg(screen->geometry().y())
814 .arg(screen->geometry().width()).arg(screen->geometry().height()) + "</li>";
815 t += "<li>" + tr("Logical DPI: %1").arg(screen->logicalDotsPerInch()) + "</li>";
816 //t += "<li>" + tr("Orientation: %1").arg(screen->orientation()) + "</li>";
817 t += "<li>" + tr("Physical DPI: %1").arg(screen->physicalDotsPerInch()) + "</li>";
818 t += "<li>" + tr("Physical size: %1 x %2 mm").arg(screen->physicalSize().width()).arg(screen->physicalSize().height()) + "</li>";
819 //t += "<li>" + tr("Primary orientation: %1").arg(screen->primaryOrientation()) + "</li>";
820 t += "<li>" + tr("Refresh rate: %1 Hz").arg(screen->refreshRate()) + "</li>";
821 t += "<li>" + tr("Size: %1 x %2").arg(screen->size().width()).arg(screen->size().height()) + "</li>";
822 t += "<li>" + tr("Virtual geometry: %1 %2 %3 x %4").arg(screen->virtualGeometry().x()).arg(screen->virtualGeometry().y())
823 .arg(screen->virtualGeometry().width()).arg(screen->virtualGeometry().height()) + "</li>";
824 t += "<li>" + tr("Virtual size: %1 x %2").arg(screen->virtualSize().width()).arg(screen->virtualSize().height()) + "</li>";
825 t += "</ul></li>";
826 }
827 t += "</ul>";
828#else
829 QDesktopWidget * dw = qApp->desktop();
830 t += "<p>" + tr("Number of screens: %1").arg(dw->screenCount());
831 t += "<p>" + tr("Primary screen: %1").arg(dw->primaryScreen()+1);
832
833 t += "<ul>";
834 for (int n = 0; n < dw->screenCount(); n++) {
835 t += "<li>" + tr("Information for screen %1").arg(n+1);
836 t += "<ul>";
837 t += "<li>" + tr("Available geometry: %1 %2 %3 x %4").arg(dw->availableGeometry(n).x()).arg(dw->availableGeometry(n).y())
838 .arg(dw->availableGeometry(n).width()).arg(dw->availableGeometry(n).height()) + "</li>";
839 t += "<li>" + tr("Geometry: %1 %2 %3 x %4").arg(dw->screenGeometry(n).x()).arg(dw->screenGeometry(n).y())
840 .arg(dw->screenGeometry(n).width()).arg(dw->screenGeometry(n).height()) + "</li>";
841 t += "</ul></li>";
842 }
843 t += "</ul>";
844#endif
845
846 screens_info_window->setHtml(t);
847 screens_info_window->show();
848}
849
850void BaseGuiPlus::updateSendToScreen() {
851 qDebug("BaseGuiPlus::updateSendToScreen");
852
853 sendToScreenGroup->clear(true);
854
855#if QT_VERSION >= 0x050000
856 QList<QScreen *> screen_list = qApp->screens();
857 int n_screens = screen_list.count();
858#else
859 QDesktopWidget * dw = qApp->desktop();
860 int n_screens = dw->screenCount();
861#endif
862
863 for (int n = 0; n < n_screens; n++) {
864 QString name;
865 #if QT_VERSION >= 0x050000
866 name = screen_list[n]->name();
867 #ifdef Q_OS_WIN
868 name = name.replace("\\\\.\\","");
869 #endif
870 bool is_primary_screen = (screen_list[n] == qApp->primaryScreen());
871 #else
872 bool is_primary_screen = (n == dw->primaryScreen());
873 #endif
874 MyAction * screen_item = new MyActionGroupItem(this, sendToScreenGroup, QString("send_to_screen_%1").arg(n+1).toLatin1().constData(), n);
875 QString desc = "&" + QString::number(n+1);
876 if (!name.isEmpty()) desc += " - " + name;
877 if (is_primary_screen) desc += " (" + tr("Primary screen") + ")";
878 screen_item->change(desc);
879 }
880
881 sendToScreen_menu->clear();
882 sendToScreen_menu->addActions(sendToScreenGroup->actions());
883
884 if (n_screens == 1 && isVideoDetached()) detachVideo(false);
885}
886
887void BaseGuiPlus::sendVideoToScreen(int screen) {
888 qDebug() << "BaseGuiPlus::sendVideoToScreen:" << screen;
889
890#if QT_VERSION >= 0x050000
891 QList<QScreen *> screen_list = qApp->screens();
892 int n_screens = screen_list.count();
893#else
894 QDesktopWidget * dw = qApp->desktop();
895 int n_screens = dw->screenCount();
896#endif
897
898 if (screen < n_screens) {
899 #if QT_VERSION >= 0x050000
900 bool is_primary_screen = (screen_list[screen] == qApp->primaryScreen());
901 QRect geometry = screen_list[screen]->geometry();
902 #else
903 bool is_primary_screen = (screen == dw->primaryScreen());
904 QRect geometry = dw->screenGeometry(screen);
905 qDebug() << "BaseGuiPlus::sendVideoToScreen: screen geometry:" << geometry;
906 #endif
907 qDebug() << "BaseGuiPlus::sendVideoToScreen: is_primary_screen:" << is_primary_screen;
908 //is_primary_screen = false;
909 if (is_primary_screen) {
910 mplayerwindow->showNormal();
911 detachVideo(false);
912 } else {
913 detachVideo(true);
914 //#if QT_VERSION >= 0x050000
915 //mplayerwindow->windowHandle()->setScreen(screen_list[screen]); // Doesn't work
916 //#else
917 mplayerwindow->move(geometry.x(), geometry.y());
918 //#endif
919 qApp->processEvents();
920 //toggleFullscreen(true);
921 mplayerwindow->showFullScreen();
922 }
923 } else {
924 // Error
925 qWarning() << "BaseGuiPlus::sendVideoToScreen: screen" << screen << "is not valid";
926 }
927}
928
929bool BaseGuiPlus::isVideoDetached() {
930 return (mplayerwindow->parent() == 0);
931}
932
933void BaseGuiPlus::detachVideo(bool detach) {
934 qDebug() << "BaseGuiPlus::detachVideo:" << detach;
935
936 if (detach) {
937 if (!isVideoDetached()) {
938 toggleFullscreen(false);
939 fullscreenAct->setEnabled(false);
940
941 panel->layout()->removeWidget(mplayerwindow);
942 mplayerwindow->setParent(0);
943 mplayerwindow->setWindowTitle(tr("SMPlayer external screen output"));
944
945 detached_label->show();
946 }
947 mplayerwindow->show();
948 } else {
949 if (isVideoDetached()) {
950 fullscreenAct->setEnabled(true);
951
952 detached_label->hide();
953
954 mplayerwindow->setWindowTitle(QString::null);
955 mplayerwindow->setParent(panel);
956 panel->layout()->addWidget(mplayerwindow);
957 }
958 }
959}
960
961/*
962void BaseGuiPlus::toggleFullscreen(bool b) {
963 qDebug() << "BaseGuiPlus::toggleFullscreen:" << b;
964 if (!isVideoDetached()) {
965 BaseGui::toggleFullscreen(b);
966 } else {
967 if (b == pref->fullscreen) return;
968 pref->fullscreen = b;
969
970 if (pref->fullscreen) {
971 //aboutToEnterFullscreen();
972 mplayerwindow->showFullScreen();
973 } else {
974 mplayerwindow->showNormal();
975 //aboutToExitFullscreen();
976 }
977 }
978}
979*/
980#endif
981
982#include "moc_baseguiplus.cpp"
Note: See TracBrowser for help on using the repository browser.