Qt: Force custom toolbars not to follow RTL auto layout changes.
[vlc/solaris.git] / modules / gui / qt4 / components / controller.cpp
blobc83af0f888565a408793bfa6e5feff6c7ea19e10
1 /*****************************************************************************
2 * Controller.cpp : Controller for the main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2009 the VideoLAN team
5 * $Id$
7 * Authors: Jean-Baptiste Kempf <jb@videolan.org>
8 * Ilkka Ollakka <ileoo@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * ( at your option ) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include <vlc_vout.h> /* vout_thread_t for FSC */
31 /* Widgets */
32 #include "components/controller.hpp"
33 #include "components/controller_widget.hpp"
34 #include "components/interface_widgets.hpp"
35 #include "util/buttons/DeckButtonsLayout.hpp"
36 #include "util/buttons/BrowseButton.hpp"
37 #include "util/buttons/RoundButton.hpp"
39 #include "dialogs_provider.hpp" /* Opening Dialogs */
40 #include "actions_manager.hpp" /* *_ACTION */
42 #include "util/input_slider.hpp" /* SeekSlider */
43 #include "util/customwidgets.hpp" /* qEventToKey */
45 #include "adapters/seekpoints.hpp"
47 #include <QToolButton>
48 #include <QHBoxLayout>
49 #include <QRegion>
50 #include <QSignalMapper>
51 #include <QTimer>
53 //#define DEBUG_LAYOUT 1
55 /**********************************************************************
56 * TEH controls
57 **********************************************************************/
59 /******
60 * This is an abstract Toolbar/Controller
61 * This has helper to create any toolbar, any buttons and to manage the actions
63 *****/
64 AbstractController::AbstractController( intf_thread_t * _p_i, QWidget *_parent )
65 : QFrame( _parent )
67 p_intf = _p_i;
68 advControls = NULL;
69 buttonGroupLayout = NULL;
71 /* Main action provider */
72 toolbarActionsMapper = new QSignalMapper( this );
73 CONNECT( toolbarActionsMapper, mapped( int ),
74 ActionsManager::getInstance( p_intf ), doAction( int ) );
75 CONNECT( THEMIM->getIM(), playingStatusChanged( int ), this, setStatus( int ) );
77 setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
80 /* Reemit some signals on status Change to activate some buttons */
81 void AbstractController::setStatus( int status )
83 bool b_hasInput = THEMIM->getIM()->hasInput();
84 /* Activate the interface buttons according to the presence of the input */
85 emit inputExists( b_hasInput );
87 emit inputPlaying( status == PLAYING_S );
89 emit inputIsRecordable( b_hasInput &&
90 var_GetBool( THEMIM->getInput(), "can-record" ) );
92 emit inputIsTrickPlayable( b_hasInput &&
93 var_GetBool( THEMIM->getInput(), "can-rewind" ) );
96 /* Generic button setup */
97 void AbstractController::setupButton( QAbstractButton *aButton )
99 static QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
100 sizePolicy.setHorizontalStretch( 0 );
101 sizePolicy.setVerticalStretch( 0 );
103 aButton->setSizePolicy( sizePolicy );
104 aButton->setFixedSize( QSize( 26, 26 ) );
105 aButton->setIconSize( QSize( 20, 20 ) );
106 aButton->setFocusPolicy( Qt::NoFocus );
109 /* Open the generic config line for the toolbar, parse it
110 * and create the widgets accordingly */
111 void AbstractController::parseAndCreate( const QString& config,
112 QBoxLayout *controlLayout )
114 QStringList list = config.split( ";", QString::SkipEmptyParts ) ;
115 for( int i = 0; i < list.count(); i++ )
117 QStringList list2 = list.at( i ).split( "-" );
118 if( list2.count() < 1 )
120 msg_Warn( p_intf, "Parsing error 1. Please, report this." );
121 continue;
124 bool ok;
125 int i_option = WIDGET_NORMAL;
126 buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok );
127 if( !ok )
129 msg_Warn( p_intf, "Parsing error 2. Please report this." );
130 continue;
133 if( list2.count() > 1 )
135 i_option = list2.at( 1 ).toInt( &ok );
136 if( !ok )
138 msg_Warn( p_intf, "Parsing error 3. Please, report this." );
139 continue;
142 createAndAddWidget( controlLayout, -1, i_type, i_option );
145 if( buttonGroupLayout )
147 controlLayout->addLayout( buttonGroupLayout );
148 buttonGroupLayout = NULL;
152 void AbstractController::createAndAddWidget( QBoxLayout *controlLayout,
153 int i_index,
154 buttonType_e i_type,
155 int i_option )
157 VLC_UNUSED( i_index ); // i_index should only be required for edition
159 /* Close the current buttonGroup if we have a special widget or a spacer */
160 if( buttonGroupLayout && i_type > BUTTON_MAX )
162 controlLayout->addLayout( buttonGroupLayout );
163 buttonGroupLayout = NULL;
166 /* Special case for SPACERS, who aren't QWidgets */
167 if( i_type == WIDGET_SPACER )
169 controlLayout->addSpacing( 12 );
171 else if( i_type == WIDGET_SPACER_EXTEND )
173 controlLayout->addStretch( 12 );
175 else
177 /* Create the widget */
178 QWidget *widg = createWidget( i_type, i_option );
179 if( !widg ) return;
181 /* Buttons */
182 if( i_type < BUTTON_MAX )
184 if( !buttonGroupLayout )
186 buttonGroupLayout = new QHBoxLayout;
189 buttonGroupLayout->addWidget( widg );
191 else /* Special widgets */
193 controlLayout->addWidget( widg );
199 #define CONNECT_MAP( a ) CONNECT( a, clicked(), toolbarActionsMapper, map() )
200 #define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b )
201 #define CONNECT_MAP_SET( a, b ) \
202 CONNECT_MAP( a ); \
203 SET_MAPPING( a, b );
204 #define BUTTON_SET_BAR( a_button ) \
205 a_button->setToolTip( qtr( tooltipL[button] ) ); \
206 a_button->setIcon( QIcon( iconL[button] ) );
207 #define BUTTON_SET_BAR2( button, image, tooltip ) \
208 button->setToolTip( tooltip ); \
209 button->setIcon( QIcon( ":/"#image ) );
211 #define ENABLE_ON_VIDEO( a ) \
212 CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \
213 a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */
215 #define ENABLE_ON_INPUT( a ) \
216 CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \
217 a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */
219 #define NORMAL_BUTTON( name ) \
220 QToolButton * name ## Button = new QToolButton; \
221 setupButton( name ## Button ); \
222 CONNECT_MAP_SET( name ## Button, name ## _ACTION ); \
223 BUTTON_SET_BAR( name ## Button ); \
224 widget = name ## Button;
226 QWidget *AbstractController::createWidget( buttonType_e button, int options )
228 bool b_flat = options & WIDGET_FLAT;
229 bool b_big = options & WIDGET_BIG;
230 bool b_shiny = options & WIDGET_SHINY;
231 bool b_special = false;
233 QWidget *widget = NULL;
234 switch( button )
236 case PLAY_BUTTON: {
237 PlayButton *playButton = new PlayButton;
238 setupButton( playButton );
239 BUTTON_SET_BAR( playButton );
240 CONNECT_MAP_SET( playButton, PLAY_ACTION );
241 CONNECT( this, inputPlaying( bool ),
242 playButton, updateButtonIcons( bool ));
243 widget = playButton;
245 break;
246 case STOP_BUTTON:{
247 NORMAL_BUTTON( STOP );
249 break;
250 case OPEN_BUTTON:{
251 NORMAL_BUTTON( OPEN );
253 break;
254 case OPEN_SUB_BUTTON:{
255 NORMAL_BUTTON( OPEN_SUB );
257 break;
258 case PREVIOUS_BUTTON:{
259 NORMAL_BUTTON( PREVIOUS );
261 break;
262 case NEXT_BUTTON: {
263 NORMAL_BUTTON( NEXT );
265 break;
266 case SLOWER_BUTTON:{
267 NORMAL_BUTTON( SLOWER );
268 ENABLE_ON_INPUT( SLOWERButton );
270 break;
271 case FASTER_BUTTON:{
272 NORMAL_BUTTON( FASTER );
273 ENABLE_ON_INPUT( FASTERButton );
275 break;
276 case PREV_SLOW_BUTTON:{
277 QToolButtonExt *but = new QToolButtonExt;
278 setupButton( but );
279 BUTTON_SET_BAR( but );
280 CONNECT( but, shortClicked(), THEMIM, prev() );
281 CONNECT( but, longClicked(), THEAM, skipBackward() );
282 widget = but;
284 break;
285 case NEXT_FAST_BUTTON:{
286 QToolButtonExt *but = new QToolButtonExt;
287 setupButton( but );
288 BUTTON_SET_BAR( but );
289 CONNECT( but, shortClicked(), THEMIM, next() );
290 CONNECT( but, longClicked(), THEAM, skipForward() );
291 widget = but;
293 break;
294 case FRAME_BUTTON: {
295 NORMAL_BUTTON( FRAME );
296 ENABLE_ON_VIDEO( FRAMEButton );
298 break;
299 case FULLSCREEN_BUTTON:
300 case DEFULLSCREEN_BUTTON:
302 NORMAL_BUTTON( FULLSCREEN );
303 ENABLE_ON_VIDEO( FULLSCREENButton );
305 break;
306 case EXTENDED_BUTTON:{
307 NORMAL_BUTTON( EXTENDED );
309 break;
310 case PLAYLIST_BUTTON:{
311 NORMAL_BUTTON( PLAYLIST );
313 break;
314 case SNAPSHOT_BUTTON:{
315 NORMAL_BUTTON( SNAPSHOT );
316 ENABLE_ON_VIDEO( SNAPSHOTButton );
318 break;
319 case RECORD_BUTTON:{
320 QToolButton *recordButton = new QToolButton;
321 setupButton( recordButton );
322 CONNECT_MAP_SET( recordButton, RECORD_ACTION );
323 BUTTON_SET_BAR( recordButton );
324 ENABLE_ON_INPUT( recordButton );
325 recordButton->setCheckable( true );
326 CONNECT( THEMIM->getIM(), recordingStateChanged( bool ),
327 recordButton, setChecked( bool ) );
328 widget = recordButton;
330 break;
331 case ATOB_BUTTON: {
332 AtoB_Button *ABButton = new AtoB_Button;
333 setupButton( ABButton );
334 ABButton->setShortcut( qtr("Shift+L") );
335 BUTTON_SET_BAR( ABButton );
336 ENABLE_ON_INPUT( ABButton );
337 CONNECT_MAP_SET( ABButton, ATOB_ACTION );
338 CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
339 ABButton, updateButtonIcons( bool, bool ) );
340 widget = ABButton;
342 break;
343 case INPUT_SLIDER: {
344 SeekSlider *slider = new SeekSlider( Qt::Horizontal, NULL );
345 SeekPoints *chapters = new SeekPoints( this, p_intf );
346 CONNECT( THEMIM->getIM(), titleChanged( bool ), chapters, update() );
347 slider->setChapters( chapters );
349 /* Update the position when the IM has changed */
350 CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
351 slider, setPosition( float, int64_t, int ) );
352 /* And update the IM, when the position has changed */
353 CONNECT( slider, sliderDragged( float ),
354 THEMIM->getIM(), sliderUpdate( float ) );
355 CONNECT( THEMIM->getIM(), cachingChanged( float ),
356 slider, updateBuffering( float ) );
357 widget = slider;
359 break;
360 case MENU_BUTTONS:
361 widget = discFrame();
362 widget->hide();
363 break;
364 case TELETEXT_BUTTONS:
365 widget = telexFrame();
366 widget->hide();
367 break;
368 case VOLUME_SPECIAL:
369 b_special = true;
370 case VOLUME:
372 SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny, b_special );
373 widget = snd;
375 break;
376 case TIME_LABEL:
378 TimeLabel *timeLabel = new TimeLabel( p_intf );
379 widget = timeLabel;
381 break;
382 case SPLITTER:
384 QFrame *line = new QFrame;
385 line->setFrameShape( QFrame::VLine );
386 line->setFrameShadow( QFrame::Raised );
387 line->setLineWidth( 0 );
388 line->setMidLineWidth( 1 );
389 widget = line;
391 break;
392 case ADVANCED_CONTROLLER:
394 advControls = new AdvControlsWidget( p_intf, this );
395 widget = advControls;
397 break;
398 case REVERSE_BUTTON:{
399 QToolButton *reverseButton = new QToolButton;
400 setupButton( reverseButton );
401 CONNECT_MAP_SET( reverseButton, REVERSE_ACTION );
402 BUTTON_SET_BAR( reverseButton );
403 reverseButton->setCheckable( true );
404 /* You should, of COURSE change this to the correct event,
405 when/if we have one, that tells us if trickplay is possible . */
406 CONNECT( this, inputIsTrickPlayable( bool ), reverseButton, setVisible( bool ) );
407 reverseButton->setVisible( false );
408 widget = reverseButton;
410 break;
411 case SKIP_BACK_BUTTON: {
412 NORMAL_BUTTON( SKIP_BACK );
413 ENABLE_ON_INPUT( SKIP_BACKButton );
415 break;
416 case SKIP_FW_BUTTON: {
417 NORMAL_BUTTON( SKIP_FW );
418 ENABLE_ON_INPUT( SKIP_FWButton );
420 break;
421 case QUIT_BUTTON: {
422 NORMAL_BUTTON( QUIT );
424 break;
425 case RANDOM_BUTTON: {
426 NORMAL_BUTTON( RANDOM );
427 RANDOMButton->setCheckable( true );
428 RANDOMButton->setChecked( var_GetBool( THEPL, "random" ) );
429 CONNECT( THEMIM, randomChanged( bool ),
430 RANDOMButton, setChecked( bool ) );
432 break;
433 case LOOP_BUTTON:{
434 LoopButton *loopButton = new LoopButton;
435 setupButton( loopButton );
436 loopButton->setToolTip( qtr( "Click to toggle between loop all, loop one and no loop") );
437 loopButton->setCheckable( true );
438 int i_state = 2 * var_GetBool( THEPL, "loop" ) + var_GetBool( THEPL, "repeat" );
439 loopButton->updateButtonIcons( i_state );
440 CONNECT( THEMIM, repeatLoopChanged( int ), loopButton, updateButtonIcons( int ) );
441 CONNECT( loopButton, clicked(), THEMIM, loopRepeatLoopStatus() );
442 widget = loopButton;
444 break;
445 case INFO_BUTTON: {
446 NORMAL_BUTTON( INFO );
448 break;
449 case PLAYBACK_BUTTONS:{
450 widget = new QWidget;
451 DeckButtonsLayout *layout = new DeckButtonsLayout( widget );
452 BrowseButton *prev = new BrowseButton( widget, BrowseButton::Backward );
453 BrowseButton *next = new BrowseButton( widget );
454 RoundButton *play = new RoundButton( widget );
455 layout->setBackwardButton( prev );
456 layout->setForwardButton( next );
457 layout->setRoundButton( play );
458 CONNECT_MAP_SET( prev, PREVIOUS_ACTION );
459 CONNECT_MAP_SET( next, NEXT_ACTION );
460 CONNECT_MAP_SET( play, PLAY_ACTION );
462 break;
463 default:
464 msg_Warn( p_intf, "This should not happen %i", button );
465 break;
468 /* Customize Buttons */
469 if( b_flat || b_big )
471 QFrame *frame = qobject_cast<QFrame *>(widget);
472 if( frame )
474 QList<QToolButton *> allTButtons = frame->findChildren<QToolButton *>();
475 for( int i = 0; i < allTButtons.count(); i++ )
476 applyAttributes( allTButtons[i], b_flat, b_big );
478 else
480 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
481 if( tmpButton )
482 applyAttributes( tmpButton, b_flat, b_big );
485 return widget;
487 #undef NORMAL_BUTTON
489 void AbstractController::applyAttributes( QToolButton *tmpButton, bool b_flat, bool b_big )
491 if( tmpButton )
493 if( b_flat )
494 tmpButton->setAutoRaise( b_flat );
495 if( b_big )
497 tmpButton->setFixedSize( QSize( 32, 32 ) );
498 tmpButton->setIconSize( QSize( 26, 26 ) );
503 QFrame *AbstractController::discFrame()
505 /** Disc and Menus handling */
506 QFrame *discFrame = new QFrame( this );
508 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
509 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
511 QToolButton *prevSectionButton = new QToolButton( discFrame );
512 setupButton( prevSectionButton );
513 BUTTON_SET_BAR2( prevSectionButton, toolbar/dvd_prev,
514 qtr("Previous Chapter/Title" ) );
515 discLayout->addWidget( prevSectionButton );
517 QToolButton *menuButton = new QToolButton( discFrame );
518 setupButton( menuButton );
519 discLayout->addWidget( menuButton );
520 BUTTON_SET_BAR2( menuButton, toolbar/dvd_menu, qtr( "Menu" ) );
522 QToolButton *nextSectionButton = new QToolButton( discFrame );
523 setupButton( nextSectionButton );
524 discLayout->addWidget( nextSectionButton );
525 BUTTON_SET_BAR2( nextSectionButton, toolbar/dvd_next,
526 qtr("Next Chapter/Title" ) );
528 /* Change the navigation button display when the IM
529 navigation changes */
530 CONNECT( THEMIM->getIM(), titleChanged( bool ),
531 discFrame, setVisible( bool ) );
532 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
533 menuButton, setVisible( bool ) );
534 /* Changes the IM navigation when triggered on the nav buttons */
535 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
536 sectionPrev() );
537 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
538 sectionNext() );
539 CONNECT( menuButton, clicked(), THEMIM->getIM(),
540 sectionMenu() );
542 return discFrame;
545 QFrame *AbstractController::telexFrame()
548 * Telextext QFrame
550 QFrame *telexFrame = new QFrame( this );
551 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
552 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
553 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
554 telexFrame, setVisible( bool ) );
556 /* On/Off button */
557 QToolButton *telexOn = new QToolButton;
558 setupButton( telexOn );
559 BUTTON_SET_BAR2( telexOn, toolbar/tv, qtr( "Teletext Activation" ) );
560 telexOn->setEnabled( false );
561 telexOn->setCheckable( true );
563 telexLayout->addWidget( telexOn );
565 /* Teletext Activation and set */
566 CONNECT( telexOn, clicked( bool ),
567 THEMIM->getIM(), activateTeletext( bool ) );
568 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
569 telexOn, setEnabled( bool ) );
571 /* Transparency button */
572 QToolButton *telexTransparent = new QToolButton;
573 setupButton( telexTransparent );
574 BUTTON_SET_BAR2( telexTransparent, toolbar/tvtelx,
575 qtr( "Toggle Transparency " ) );
576 telexTransparent->setEnabled( false );
577 telexTransparent->setCheckable( true );
578 telexLayout->addWidget( telexTransparent );
580 /* Transparency change and set */
581 CONNECT( telexTransparent, clicked( bool ),
582 THEMIM->getIM(), telexSetTransparency( bool ) );
583 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
584 telexTransparent, setChecked( bool ) );
587 /* Page setting */
588 QSpinBox *telexPage = new QSpinBox( telexFrame );
589 telexPage->setRange( 0, 999 );
590 telexPage->setValue( 100 );
591 telexPage->setAccelerated( true );
592 telexPage->setWrapping( true );
593 telexPage->setAlignment( Qt::AlignRight );
594 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
595 telexPage->setEnabled( false );
596 telexLayout->addWidget( telexPage );
598 /* Page change and set */
599 CONNECT( telexPage, valueChanged( int ),
600 THEMIM->getIM(), telexSetPage( int ) );
601 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
602 telexPage, setValue( int ) );
604 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexPage, setEnabled( bool ) );
605 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexTransparent, setEnabled( bool ) );
606 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexOn, setChecked( bool ) );
607 return telexFrame;
609 #undef CONNECT_MAP
610 #undef SET_MAPPING
611 #undef CONNECT_MAP_SET
612 #undef BUTTON_SET_BAR
613 #undef BUTTON_SET_BAR2
614 #undef ENABLE_ON_VIDEO
615 #undef ENABLE_ON_INPUT
617 #include <QHBoxLayout>
618 /*****************************
619 * DA Control Widget !
620 *****************************/
621 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
622 bool b_advControls,
623 QWidget *_parent ) :
624 AbstractController( _p_i, _parent )
626 RTL_UNAFFECTED_WIDGET
627 /* advanced Controls handling */
628 b_advancedVisible = b_advControls;
629 #ifdef DEBUG_LAYOUT
630 setStyleSheet( "background: red ");
631 #endif
632 setAttribute( Qt::WA_MacBrushedMetal);
633 QVBoxLayout *controlLayout = new QVBoxLayout( this );
634 controlLayout->setContentsMargins( 4, 1, 0, 0 );
635 controlLayout->setSpacing( 0 );
636 QHBoxLayout *controlLayout1 = new QHBoxLayout;
637 controlLayout1->setSpacing( 0 ); controlLayout1->setMargin( 0 );
639 QString line1 = getSettings()->value( "MainToolbar1", MAIN_TB1_DEFAULT )
640 .toString();
641 parseAndCreate( line1, controlLayout1 );
643 QHBoxLayout *controlLayout2 = new QHBoxLayout;
644 controlLayout2->setSpacing( 0 ); controlLayout2->setMargin( 0 );
645 QString line2 = getSettings()->value( "MainToolbar2", MAIN_TB2_DEFAULT )
646 .toString();
647 parseAndCreate( line2, controlLayout2 );
649 grip = new QSizeGrip( this );
650 controlLayout2->addWidget( grip, 0, Qt::AlignBottom|Qt::AlignRight );
652 if( !b_advancedVisible && advControls ) advControls->hide();
654 controlLayout->addLayout( controlLayout1 );
655 controlLayout->addLayout( controlLayout2 );
658 void ControlsWidget::toggleAdvanced()
660 if( !advControls ) return;
662 if( !b_advancedVisible )
664 advControls->show();
665 b_advancedVisible = true;
667 else
669 advControls->hide();
670 b_advancedVisible = false;
672 emit advancedControlsToggled( b_advancedVisible );
675 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
676 AbstractController( _p_i, _parent )
678 RTL_UNAFFECTED_WIDGET
679 controlLayout = new QHBoxLayout( this );
680 controlLayout->setMargin( 0 );
681 controlLayout->setSpacing( 0 );
682 #ifdef DEBUG_LAYOUT
683 setStyleSheet( "background: orange ");
684 #endif
687 QString line = getSettings()->value( "AdvToolbar", ADV_TB_DEFAULT )
688 .toString();
689 parseAndCreate( line, controlLayout );
692 InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
693 AbstractController( _p_i, _parent )
695 RTL_UNAFFECTED_WIDGET
696 controlLayout = new QHBoxLayout( this );
697 controlLayout->setMargin( 0 );
698 controlLayout->setSpacing( 0 );
699 #ifdef DEBUG_LAYOUT
700 setStyleSheet( "background: green ");
701 #endif
703 QString line = getSettings()->value( "InputToolbar", INPT_TB_DEFAULT ).toString();
704 parseAndCreate( line, controlLayout );
706 /**********************************************************************
707 * Fullscrenn control widget
708 **********************************************************************/
709 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i, QWidget *_parent )
710 : AbstractController( _p_i, _parent )
712 RTL_UNAFFECTED_WIDGET
713 i_mouse_last_x = -1;
714 i_mouse_last_y = -1;
715 b_mouse_over = false;
716 i_mouse_last_move_x = -1;
717 i_mouse_last_move_y = -1;
718 #if HAVE_TRANSPARENCY
719 b_slow_hide_begin = false;
720 i_slow_hide_timeout = 1;
721 #endif
722 b_fullscreen = false;
723 i_hide_timeout = 1;
724 i_screennumber = -1;
726 vout.clear();
728 setWindowFlags( Qt::ToolTip );
729 setMinimumWidth( 600 );
731 setFrameShape( QFrame::StyledPanel );
732 setFrameStyle( QFrame::Sunken );
733 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
735 QVBoxLayout *controlLayout2 = new QVBoxLayout( this );
736 controlLayout2->setContentsMargins( 4, 6, 4, 2 );
738 /* First line */
739 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
740 controlLayout2->addWidget( inputC );
742 controlLayout = new QHBoxLayout;
743 QString line = getSettings()->value( "MainWindow/FSCtoolbar", FSC_TB_DEFAULT ).toString();
744 parseAndCreate( line, controlLayout );
745 controlLayout2->addLayout( controlLayout );
747 /* hiding timer */
748 p_hideTimer = new QTimer( this );
749 p_hideTimer->setSingleShot( true );
750 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
752 /* slow hiding timer */
753 #if HAVE_TRANSPARENCY
754 p_slowHideTimer = new QTimer( this );
755 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
756 f_opacity = var_InheritFloat( p_intf, "qt-fs-opacity" );
757 #endif
759 vlc_mutex_init_recursive( &lock );
761 DCONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
762 this, setVoutList( vout_thread_t **, int ) );
764 /* First Move */
765 QRect rect1 = getSettings()->value( "FullScreen/screen" ).toRect();
766 QPoint pos1 = getSettings()->value( "FullScreen/pos" ).toPoint();
767 int number = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
768 if( number == -1 || number > QApplication::desktop()->numScreens() )
769 number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
771 QRect rect = QApplication::desktop()->screenGeometry( number );
772 if( rect == rect1 && rect.contains( pos1, true ) )
774 move( pos1 );
775 i_screennumber = number;
776 screenRes = QApplication::desktop()->screenGeometry(number);
778 else
780 centerFSC( number );
785 FullscreenControllerWidget::~FullscreenControllerWidget()
787 QPoint pos1 = pos();
788 QRect rect1 = QApplication::desktop()->screenGeometry( pos1 );
789 getSettings()->setValue( "FullScreen/pos", pos1 );
790 getSettings()->setValue( "FullScreen/screen", rect1 );
792 setVoutList( NULL, 0 );
793 vlc_mutex_destroy( &lock );
796 void FullscreenControllerWidget::centerFSC( int number )
798 screenRes = QApplication::desktop()->screenGeometry(number);
800 /* screen has changed, calculate new position */
801 QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (sizeHint().width() / 2),
802 screenRes.y() + screenRes.height() - sizeHint().height());
803 move( pos );
805 i_screennumber = number;
809 * Show fullscreen controller
811 void FullscreenControllerWidget::showFSC()
813 adjustSize();
815 int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
817 if( number != i_screennumber ||
818 screenRes != QApplication::desktop()->screenGeometry(number) )
820 centerFSC( number );
821 msg_Dbg( p_intf, "Recentering the Fullscreen Controller" );
824 #if HAVE_TRANSPARENCY
825 setWindowOpacity( f_opacity );
826 #endif
828 #ifdef Q_WS_X11
829 // Tell kwin that we do not want a shadow around the fscontroller
830 setMask( QRegion( 0, 0, width(), height() ) );
831 #endif
833 show();
837 * Plane to hide fullscreen controller
839 void FullscreenControllerWidget::planHideFSC()
841 vlc_mutex_lock( &lock );
842 int i_timeout = i_hide_timeout;
843 vlc_mutex_unlock( &lock );
845 p_hideTimer->start( i_timeout );
847 #if HAVE_TRANSPARENCY
848 b_slow_hide_begin = true;
849 i_slow_hide_timeout = i_timeout;
850 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
851 #endif
855 * Hidding fullscreen controller slowly
856 * Linux: need composite manager
857 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
859 void FullscreenControllerWidget::slowHideFSC()
861 #if HAVE_TRANSPARENCY
862 if( b_slow_hide_begin )
864 b_slow_hide_begin = false;
866 p_slowHideTimer->stop();
867 /* the last part of time divided to 100 pieces */
868 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
871 else
873 if ( windowOpacity() > 0.0 )
875 /* we should use 0.01 because of 100 pieces ^^^
876 but than it cannt be done in time */
877 setWindowOpacity( windowOpacity() - 0.02 );
880 if ( windowOpacity() <= 0.0 )
881 p_slowHideTimer->stop();
883 #endif
887 * event handling
888 * events: show, hide, start timer for hiding
890 void FullscreenControllerWidget::customEvent( QEvent *event )
892 bool b_fs;
894 switch( (int)event->type() )
896 /* This is used when the 'i' hotkey is used, to force quick toggle */
897 case FullscreenControlToggle_Type:
898 vlc_mutex_lock( &lock );
899 b_fs = b_fullscreen;
900 vlc_mutex_unlock( &lock );
902 if( b_fs )
904 if( isHidden() )
906 p_hideTimer->stop();
907 showFSC();
909 else
910 hideFSC();
912 break;
913 /* Event called to Show the FSC on mouseChanged() */
914 case FullscreenControlShow_Type:
915 vlc_mutex_lock( &lock );
916 b_fs = b_fullscreen;
917 vlc_mutex_unlock( &lock );
919 if( b_fs )
920 showFSC();
922 break;
923 /* Start the timer to hide later, called usually with above case */
924 case FullscreenControlPlanHide_Type:
925 if( !b_mouse_over ) // Only if the mouse is not over FSC
926 planHideFSC();
927 break;
928 /* Hide */
929 case FullscreenControlHide_Type:
930 hideFSC();
931 break;
932 default:
933 break;
938 * On mouse move
939 * moving with FSC
941 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
943 if( event->buttons() == Qt::LeftButton )
945 if( i_mouse_last_x == -1 || i_mouse_last_y == -1 )
946 return;
948 int i_moveX = event->globalX() - i_mouse_last_x;
949 int i_moveY = event->globalY() - i_mouse_last_y;
951 move( x() + i_moveX, y() + i_moveY );
953 i_mouse_last_x = event->globalX();
954 i_mouse_last_y = event->globalY();
959 * On mouse press
960 * store position of cursor
962 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
964 i_mouse_last_x = event->globalX();
965 i_mouse_last_y = event->globalY();
966 event->accept();
969 void FullscreenControllerWidget::mouseReleaseEvent( QMouseEvent *event )
971 i_mouse_last_x = -1;
972 i_mouse_last_y = -1;
973 event->accept();
977 * On mouse go above FSC
979 void FullscreenControllerWidget::enterEvent( QEvent *event )
981 b_mouse_over = true;
983 p_hideTimer->stop();
984 #if HAVE_TRANSPARENCY
985 p_slowHideTimer->stop();
986 setWindowOpacity( f_opacity );
987 #endif
988 event->accept();
992 * On mouse go out from FSC
994 void FullscreenControllerWidget::leaveEvent( QEvent *event )
996 planHideFSC();
998 b_mouse_over = false;
999 event->accept();
1003 * When you get pressed key, send it to video output
1005 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1007 emit keyPressed( event );
1010 /* */
1011 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
1012 const char *variable, vlc_value_t old_val,
1013 vlc_value_t new_val, void *data )
1015 VLC_UNUSED( variable ); VLC_UNUSED( old_val );
1017 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1019 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
1020 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1022 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1024 return VLC_SUCCESS;
1026 /* */
1027 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1028 vlc_value_t old_val, vlc_value_t new_val,
1029 void *data )
1031 VLC_UNUSED( variable ); VLC_UNUSED( old_val );
1033 vout_thread_t *p_vout = (vout_thread_t *)vlc_object;
1034 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1036 /* Get the value from the Vout - Trust the vout more than Qt */
1037 p_fs->mouseChanged( p_vout, new_val.coords.x, new_val.coords.y );
1039 return VLC_SUCCESS;
1043 * It is call to update the list of vout handled by the fullscreen controller
1045 void FullscreenControllerWidget::setVoutList( vout_thread_t **pp_vout, int i_vout )
1047 QList<vout_thread_t*> del;
1048 QList<vout_thread_t*> add;
1050 QList<vout_thread_t*> set;
1052 /* */
1053 for( int i = 0; i < i_vout; i++ )
1054 set += pp_vout[i];
1056 /* Vout to remove */
1057 vlc_mutex_lock( &lock );
1058 foreach( vout_thread_t *p_vout, vout )
1060 if( !set.contains( p_vout ) )
1061 del += p_vout;
1063 vlc_mutex_unlock( &lock );
1065 foreach( vout_thread_t *p_vout, del )
1067 var_DelCallback( p_vout, "fullscreen",
1068 FullscreenControllerWidgetFullscreenChanged, this );
1069 vlc_mutex_lock( &lock );
1070 fullscreenChanged( p_vout, false, 0 );
1071 vout.removeAll( p_vout );
1072 vlc_mutex_unlock( &lock );
1074 vlc_object_release( VLC_OBJECT(p_vout) );
1077 /* Vout to track */
1078 vlc_mutex_lock( &lock );
1079 foreach( vout_thread_t *p_vout, set )
1081 if( !vout.contains( p_vout ) )
1082 add += p_vout;
1084 vlc_mutex_unlock( &lock );
1086 foreach( vout_thread_t *p_vout, add )
1088 vlc_object_hold( VLC_OBJECT(p_vout) );
1090 vlc_mutex_lock( &lock );
1091 vout.append( p_vout );
1092 var_AddCallback( p_vout, "fullscreen",
1093 FullscreenControllerWidgetFullscreenChanged, this );
1094 /* I miss a add and fire */
1095 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1096 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1097 vlc_mutex_unlock( &lock );
1101 * Register and unregister callback for mouse moving
1103 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1104 bool b_fs, int i_timeout )
1106 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1108 vlc_mutex_lock( &lock );
1109 /* Entering fullscreen, register callback */
1110 if( b_fs && !b_fullscreen )
1112 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1113 b_fullscreen = true;
1114 i_hide_timeout = i_timeout;
1115 var_AddCallback( p_vout, "mouse-moved",
1116 FullscreenControllerWidgetMouseMoved, this );
1118 /* Quitting fullscreen, unregistering callback */
1119 else if( !b_fs && b_fullscreen )
1121 msg_Dbg( p_vout, "Qt: Quitting Fullscreen" );
1122 b_fullscreen = false;
1123 i_hide_timeout = i_timeout;
1124 var_DelCallback( p_vout, "mouse-moved",
1125 FullscreenControllerWidgetMouseMoved, this );
1127 /* Force fs hiding */
1128 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1129 QApplication::postEvent( this, eHide );
1131 vlc_mutex_unlock( &lock );
1135 * Mouse change callback (show/hide the controller on mouse movement)
1137 void FullscreenControllerWidget::mouseChanged( vout_thread_t *, int i_mousex, int i_mousey )
1139 bool b_toShow;
1141 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1143 b_toShow = false;
1144 if( ( i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1 ) ||
1145 ( abs( i_mouse_last_move_x - i_mousex ) > 2 ||
1146 abs( i_mouse_last_move_y - i_mousey ) > 2 ) )
1148 i_mouse_last_move_x = i_mousex;
1149 i_mouse_last_move_y = i_mousey;
1150 b_toShow = true;
1153 if( b_toShow )
1155 /* Show event */
1156 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1157 QApplication::postEvent( this, eShow );
1159 /* Plan hide event */
1160 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1161 QApplication::postEvent( this, eHide );