From: Jean-Baptiste Kempf Date: Tue, 9 Dec 2008 14:32:47 +0000 (+0100) Subject: [Qt] Rewrite of the controller and ToolBar edition. X-Git-Tag: 1.0.0-pre1~1899 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=1dbee6584667999d489f12203807c1f3570bc9b4;p=vlc [Qt] Rewrite of the controller and ToolBar edition. This is a big chunk, and is very experimental. Functionnalities are (at best) very limited. --- diff --git a/modules/gui/qt4/Modules.am b/modules/gui/qt4/Modules.am index f2aeaf609d..5cfb0cd04a 100644 --- a/modules/gui/qt4/Modules.am +++ b/modules/gui/qt4/Modules.am @@ -29,6 +29,7 @@ nodist_SOURCES_qt4 = \ dialogs/sout.moc.cpp \ dialogs/help.moc.cpp \ dialogs/gototime.moc.cpp \ + dialogs/toolbar.moc.cpp \ dialogs/open.moc.cpp \ dialogs/podcast_configuration.moc.cpp \ dialogs/vlm.moc.cpp \ @@ -209,6 +210,7 @@ SOURCES_qt4 = qt4.cpp \ dialogs/sout.cpp \ dialogs/help.cpp \ dialogs/gototime.cpp \ + dialogs/toolbar.cpp \ dialogs/open.cpp \ dialogs/vlm.cpp \ dialogs/podcast_configuration.cpp \ @@ -247,6 +249,7 @@ noinst_HEADERS = \ dialogs/sout.hpp \ dialogs/help.hpp \ dialogs/gototime.hpp \ + dialogs/toolbar.hpp \ dialogs/open.hpp \ dialogs/vlm.hpp \ dialogs/podcast_configuration.hpp \ diff --git a/modules/gui/qt4/components/controller.cpp b/modules/gui/qt4/components/controller.cpp index 599b543c2e..d6824f0622 100644 --- a/modules/gui/qt4/components/controller.cpp +++ b/modules/gui/qt4/components/controller.cpp @@ -50,29 +50,23 @@ #include #include -#define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media") - /********************************************************************** * TEH controls **********************************************************************/ /****** - * This is an abstract Toolbar/Controller - * This has helper to create any toolbar, any buttons and to manage the actions - * - *****/ + * This is an abstract Toolbar/Controller + * This has helper to create any toolbar, any buttons and to manage the actions + * + *****/ AbstractController::AbstractController( intf_thread_t * _p_i ) : QFrame( NULL ) { p_intf = _p_i; - - /* We need one layout. An controller without layout is stupid with - current architecture */ - controlLayout = new QGridLayout( this ); + advControls = NULL; /* Main action provider */ toolbarActionsMapper = new QSignalMapper( this ); - CONNECT( toolbarActionsMapper, mapped( int ), - this, doAction( int ) ); + CONNECT( toolbarActionsMapper, mapped( int ), this, doAction( int ) ); CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) ); } @@ -104,76 +98,80 @@ void AbstractController::setupButton( QAbstractButton *aButton ) /* Open the generic config line for the toolbar, parse it * and create the widgets accordingly */ -void AbstractController::parseAndCreateLine( QString config, int i_line ) +void AbstractController::parseAndCreate( QString config, + QBoxLayout *controlLayout ) { - int i_column = 0; QStringList list = config.split( ";" ) ; for( int i = 0; i < list.size(); i++ ) { - QStringList list2 = list.at( i ).split( "-" ); - if( list2.size() < 1 ) - { - msg_Warn( p_intf, "Parsing error. Report this" ); - continue; - } - - bool ok; - int i_option = WIDGET_NORMAL; - buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok ); - if( !ok ) - { - msg_Warn( p_intf, "Parsing error 0. Please report this" ); - continue; - } - /* Special case for SPACERS, who aren't QWidgets */ - if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND ) - { - controlLayout->setColumnMinimumWidth( i, 10 ); - i_column++; - controlLayout->setColumnStretch( i, - ( i_type == WIDGET_SPACER ) ? 0 : 10 ); - continue; - } + QStringList list2 = list.at( i ).split( "-" ); + if( list2.size() < 1 ) + { + msg_Warn( p_intf, "Parsing error. Report this" ); + continue; + } - if( list2.size() > 1 ) - { - i_option = list2.at( 1 ).toInt( &ok ); - if( !ok ) - { - msg_Warn( p_intf, "Parsing error 1. Please report this" ); - continue; - } - } + bool ok; + int i_option = WIDGET_NORMAL; + buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok ); + if( !ok ) + { + msg_Warn( p_intf, "Parsing error 0. Please report this" ); + continue; + } - int i_size; - QWidget *widg = createWidget( i_type, &i_size, i_option ); - if( !widg ) continue; + if( list2.size() > 1 ) + { + i_option = list2.at( 1 ).toInt( &ok ); + if( !ok ) + { + msg_Warn( p_intf, "Parsing error 1. Please report this" ); + continue; + } + } - if( list2.size() > 2 ) - { - i_size = list.at( 2 ).toInt( &ok ); + createAndAddWidget( controlLayout, -1, i_type, i_option ); + } +} - if( !ok ) - { - msg_Warn( p_intf, "Parsing error 2. Please report this" ); - continue; - } - } +void AbstractController::createAndAddWidget( QBoxLayout *controlLayout, + int i_index, + buttonType_e i_type, + int i_option ) +{ + /* Special case for SPACERS, who aren't QWidgets */ + if( i_type == WIDGET_SPACER ) + { + controlLayout->insertSpacing( i_index, 16 ); + return; + } - controlLayout->addWidget( widg, i_line, i_column, 1, i_size ); - i_column += i_size; + if( i_type == WIDGET_SPACER_EXTEND ) + { + controlLayout->insertSpacing( i_index, 10 ); + return; } + + QWidget *widg = createWidget( i_type, i_option ); + if( !widg ) return; + + controlLayout->insertWidget( i_index, widg ); } + #define CONNECT_MAP( a ) CONNECT( a, clicked(), toolbarActionsMapper, map() ) #define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b ) #define CONNECT_MAP_SET( a, b ) \ CONNECT_MAP( a ); \ SET_MAPPING( a, b ); -#define BUTTON_SET_BAR( button, image, tooltip ) \ +#define BUTTON_SET_BAR( a_button ) \ + a_button->setToolTip( tooltipL[button] ); \ + a_button->setIcon( QIcon( iconL[button] ) ); +#define BUTTON_SET_BAR2( button, image, tooltip ) \ button->setToolTip( tooltip ); \ button->setIcon( QIcon( ":/"#image ) ); + #define ENABLE_ON_VIDEO( a ) \ CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \ a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */ @@ -182,15 +180,12 @@ void AbstractController::parseAndCreateLine( QString config, int i_line ) CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \ a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */ -QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, - int options ) +QWidget *AbstractController::createWidget( buttonType_e button, int options ) { - assert( i_size ); bool b_flat = options & WIDGET_FLAT; bool b_big = options & WIDGET_BIG; bool b_shiny = options & WIDGET_SHINY; - *i_size = 1; QWidget *widget = NULL; switch( button ) @@ -198,7 +193,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, case PLAY_BUTTON: { PlayButton *playButton = new PlayButton; setupButton( playButton ); - BUTTON_SET_BAR( playButton, play_b, qtr( I_PLAY_TOOLTIP ) ); + BUTTON_SET_BAR( playButton ); CONNECT_MAP_SET( playButton, PLAY_ACTION ); CONNECT( this, inputPlaying( bool ), playButton, updateButton( bool )); @@ -209,7 +204,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *stopButton = new QToolButton; setupButton( stopButton ); CONNECT_MAP_SET( stopButton, STOP_ACTION ); - BUTTON_SET_BAR( stopButton, stop_b, qtr( "Stop playback" ) ); + BUTTON_SET_BAR( stopButton ); widget = stopButton; } break; @@ -217,8 +212,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *prevButton = new QToolButton; setupButton( prevButton ); CONNECT_MAP_SET( prevButton, PREVIOUS_ACTION ); - BUTTON_SET_BAR( prevButton, previous_b, - qtr( "Previous media in the playlist" ) ); + BUTTON_SET_BAR( prevButton ); widget = prevButton; } break; @@ -227,8 +221,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *nextButton = new QToolButton; setupButton( nextButton ); CONNECT_MAP_SET( nextButton, NEXT_ACTION ); - BUTTON_SET_BAR( nextButton, next_b, - qtr( "Next media in the playlist" ) ); + BUTTON_SET_BAR( nextButton ); widget = nextButton; } break; @@ -236,7 +229,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *slowerButton = new QToolButton; setupButton( slowerButton ); CONNECT_MAP_SET( slowerButton, SLOWER_ACTION ); - BUTTON_SET_BAR( slowerButton, slower, qtr( "Slower" ) ); + BUTTON_SET_BAR( slowerButton ); ENABLE_ON_INPUT( slowerButton ); widget = slowerButton; } @@ -245,7 +238,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *fasterButton = new QToolButton; setupButton( fasterButton ); CONNECT_MAP_SET( fasterButton, FASTER_ACTION ); - BUTTON_SET_BAR( fasterButton, faster, qtr( "Faster" ) ); + BUTTON_SET_BAR( fasterButton ); ENABLE_ON_INPUT( fasterButton ); widget = fasterButton; } @@ -254,7 +247,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *frameButton = new QToolButton; setupButton( frameButton ); CONNECT_MAP_SET( frameButton, FRAME_ACTION ); - BUTTON_SET_BAR( frameButton, frame, qtr( "Frame by frame" ) ); + BUTTON_SET_BAR( frameButton ); ENABLE_ON_VIDEO( frameButton ); widget = frameButton; } @@ -263,8 +256,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *fullscreenButton = new QToolButton; setupButton( fullscreenButton ); CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION ); - BUTTON_SET_BAR( fullscreenButton, fullscreen, - qtr( "Toggle the video in fullscreen" ) ); + BUTTON_SET_BAR( fullscreenButton ); ENABLE_ON_VIDEO( fullscreenButton ); widget = fullscreenButton; } @@ -273,8 +265,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *fullscreenButton = new QToolButton; setupButton( fullscreenButton ); CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION ); - BUTTON_SET_BAR( fullscreenButton, defullscreen, - qtr( "Toggle the video in fullscreen" ) ); + BUTTON_SET_BAR( fullscreenButton ) ENABLE_ON_VIDEO( fullscreenButton ); widget = fullscreenButton; } @@ -283,8 +274,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *extSettingsButton = new QToolButton; setupButton( extSettingsButton ); CONNECT_MAP_SET( extSettingsButton, EXTENDED_ACTION ); - BUTTON_SET_BAR( extSettingsButton, extended, - qtr( "Show extended settings" ) ); + BUTTON_SET_BAR( extSettingsButton ) widget = extSettingsButton; } break; @@ -292,8 +282,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *playlistButton = new QToolButton; setupButton( playlistButton ); CONNECT_MAP_SET( playlistButton, PLAYLIST_ACTION ); - BUTTON_SET_BAR( playlistButton, playlist, - qtr( "Show playlist" ) ); + BUTTON_SET_BAR( playlistButton ); widget = playlistButton; } break; @@ -301,7 +290,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *snapshotButton = new QToolButton; setupButton( snapshotButton ); CONNECT_MAP_SET( snapshotButton, SNAPSHOT_ACTION ); - BUTTON_SET_BAR( snapshotButton, snapshot, qtr( "Take a snapshot" ) ); + BUTTON_SET_BAR( snapshotButton ); ENABLE_ON_VIDEO( snapshotButton ); widget = snapshotButton; } @@ -310,7 +299,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, QToolButton *recordButton = new QToolButton; setupButton( recordButton ); CONNECT_MAP_SET( recordButton, RECORD_ACTION ); - BUTTON_SET_BAR( recordButton, record, qtr( "Record" ) ); + BUTTON_SET_BAR( recordButton ); ENABLE_ON_INPUT( recordButton ); widget = recordButton; } @@ -318,8 +307,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, case ATOB_BUTTON: { AtoB_Button *ABButton = new AtoB_Button; setupButton( ABButton ); - BUTTON_SET_BAR( ABButton, atob_nob, qtr( "Loop from point A to point " - "B continuously.\nClick to set point A" ) ); + BUTTON_SET_BAR( ABButton ); ENABLE_ON_INPUT( ABButton ); CONNECT_MAP_SET( ABButton, ATOB_ACTION ); CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool), @@ -329,31 +317,28 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, break; case INPUT_SLIDER: { InputSlider *slider = new InputSlider( Qt::Horizontal, NULL ); + /* Update the position when the IM has changed */ CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ), slider, setPosition( float, int, int ) ); /* And update the IM, when the position has changed */ CONNECT( slider, sliderDragged( float ), - THEMIM->getIM(), sliderUpdate( float ) ); - /* *i_size = -1; */ + THEMIM->getIM(), sliderUpdate( float ) ); widget = slider; } break; case MENU_BUTTONS: widget = discFrame(); - widget->hide(); - *i_size = 3; +// widget->hide(); break; case TELETEXT_BUTTONS: widget = telexFrame(); - widget->hide(); - *i_size = 4; +// widget->hide(); break; case VOLUME: { - SoundWidget *snd = new SoundWidget( p_intf, b_shiny ); + SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny ); widget = snd; - *i_size = 4; } break; case TIME_LABEL: @@ -376,14 +361,13 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, { advControls = new AdvControlsWidget( p_intf ); widget = advControls; - *i_size = advControls->getWidth(); } break; case REVERSE_BUTTON:{ QToolButton *reverseButton = new QToolButton; setupButton( reverseButton ); CONNECT_MAP_SET( reverseButton, REVERSE_ACTION ); - BUTTON_SET_BAR( reverseButton, reverse, qtr( "Reverse" ) ); + BUTTON_SET_BAR( reverseButton ); ENABLE_ON_INPUT( reverseButton ); widget = reverseButton; } @@ -405,7 +389,6 @@ QWidget *AbstractController::createWidget( buttonType_e button, int* i_size, { tmpButton->setFixedSize( QSize( 32, 32 ) ); tmpButton->setIconSize( QSize( 26, 26 ) ); - *i_size = 2; } } } @@ -422,22 +405,21 @@ QWidget *AbstractController::discFrame() QToolButton *prevSectionButton = new QToolButton( discFrame ); setupButton( prevSectionButton ); - BUTTON_SET_BAR( prevSectionButton, dvd_prev, + BUTTON_SET_BAR2( prevSectionButton, dvd_prev, qtr("Previous Chapter/Title" ) ); discLayout->addWidget( prevSectionButton ); QToolButton *menuButton = new QToolButton( discFrame ); setupButton( menuButton ); discLayout->addWidget( menuButton ); - BUTTON_SET_BAR( menuButton, dvd_menu, qtr( "Menu" ) ); + BUTTON_SET_BAR2( menuButton, dvd_menu, qtr( "Menu" ) ); QToolButton *nextSectionButton = new QToolButton( discFrame ); setupButton( nextSectionButton ); discLayout->addWidget( nextSectionButton ); - BUTTON_SET_BAR( nextSectionButton, dvd_next, + BUTTON_SET_BAR2( nextSectionButton, dvd_next, qtr("Next Chapter/Title" ) ); - /* Change the navigation button display when the IM navigation changes */ CONNECT( THEMIM->getIM(), titleChanged( bool ), @@ -470,7 +452,7 @@ QWidget *AbstractController::telexFrame() QToolButton *telexOn = new QToolButton; telexFrame->telexOn = telexOn; setupButton( telexOn ); - BUTTON_SET_BAR( telexOn, tv, qtr( "Teletext Activation" ) ); + BUTTON_SET_BAR2( telexOn, tv, qtr( "Teletext Activation" ) ); telexLayout->addWidget( telexOn ); /* Teletext Activation and set */ @@ -484,8 +466,8 @@ QWidget *AbstractController::telexFrame() QToolButton *telexTransparent = new QToolButton; telexFrame->telexTransparent = telexTransparent; setupButton( telexTransparent ); - BUTTON_SET_BAR( telexTransparent, tvtelx, - qtr( "Toggle Transparency " ) ); + BUTTON_SET_BAR2( telexTransparent, tvtelx, + qtr( "Toggle Transparency " ) ); telexTransparent->setEnabled( false ); telexLayout->addWidget( telexTransparent ); @@ -523,8 +505,9 @@ QWidget *AbstractController::telexFrame() #undef ENABLE_ON_VIDEO #undef ENABLE_ON_INPUT -SoundWidget::SoundWidget( intf_thread_t * _p_intf, bool b_shiny ) - : b_my_volume( false ) +SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf, + bool b_shiny ) + : b_my_volume( false ), QWidget( _parent ) { p_intf = _p_intf; QHBoxLayout *layout = new QHBoxLayout( this ); @@ -792,7 +775,7 @@ void AbstractController::frame() if( p_input ) var_SetVoid( p_input, "frame-next" ); } - +#include /***************************** * DA Control Widget ! *****************************/ @@ -804,14 +787,16 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i, /* advanced Controls handling */ b_advancedVisible = b_advControls; - advControls = NULL; - controlLayout->setSpacing( 0 ); + QVBoxLayout *controlLayout = new QVBoxLayout( this ); controlLayout->setLayoutMargins( 6, 4, 6, 2, 5 ); + controlLayout->setSpacing( 0 ); + QHBoxLayout *controlLayout1 = new QHBoxLayout; + controlLayout1->setSpacing( 0 ); - QString line1 = getSettings()->value( "MainWindow/Controls2", + QString line1 = getSettings()->value( "MainWindow/Controls1", "18;19;25" ).toString(); - parseAndCreateLine( line1, 0 ); + parseAndCreate( line1, controlLayout1 ); /* QString line2 = QString( "%1-2;%2;%3;%4;%5;%6;%6;%7;%8;%9;%6;%10;%11-4") .arg( PLAY_BUTTON ) .arg( WIDGET_SPACER ) @@ -821,11 +806,16 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i, .arg( EXTENDED_BUTTON ) .arg( WIDGET_SPACER_EXTEND ) .arg( VOLUME ); */ + QHBoxLayout *controlLayout2 = new QHBoxLayout; + controlLayout2->setSpacing( 0 ); QString line2 = getSettings()->value( "MainWindow/Controls2", - "0-2;21;21;4;2;5;21;21;8;11;10;21;22;20-4" ).toString(); - parseAndCreateLine( line2, 1 ); + "0-2;21;4;2;5;21;8;11;10;21;22;20-4" ).toString(); + parseAndCreate( line2, controlLayout2 ); if( !b_advancedVisible && advControls ) advControls->hide(); + + controlLayout->addLayout( controlLayout1 ); + controlLayout->addLayout( controlLayout2 ); } ControlsWidget::~ControlsWidget() @@ -851,6 +841,7 @@ void ControlsWidget::toggleAdvanced() AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) : AbstractController( _p_i ) { + controlLayout = new QHBoxLayout( this ); controlLayout->setMargin( 0 ); controlLayout->setSpacing( 0 ); @@ -861,12 +852,13 @@ AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) : QString line = getSettings()->value( "MainWindow/AdvControl", "12;13;14;15" ).toString(); - parseAndCreateLine( line, 0 ); + parseAndCreate( line, controlLayout ); } InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i ) : AbstractController( _p_i ) { + controlLayout = new QHBoxLayout( this ); controlLayout->setMargin( 0 ); controlLayout->setSpacing( 0 ); @@ -876,7 +868,7 @@ InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i ) : .arg( FASTER_BUTTON ); */ QString line = getSettings()->value( "MainWindow/InputControl", "6-1;16;7-1" ).toString(); - parseAndCreateLine( line, 0 ); + parseAndCreate( line, controlLayout ); } /********************************************************************** * Fullscrenn control widget @@ -905,11 +897,12 @@ FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i ) setFrameStyle( QFrame::Sunken ); setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); + controlLayout = new QHBoxLayout( this ); controlLayout->setLayoutMargins( 5, 2, 5, 2, 5 ); /* First line */ InputControlsWidget *inputC = new InputControlsWidget( p_intf ); - controlLayout->addWidget( inputC, 0, 0, 1, -1 ); +// controlLayout->addWidget( inputC, 0, 0, 1, -1 ); /* Second line */ /* QString line2 = QString( "%1-2;%2;%3;%4;%5;%2;%6;%2;%7;%2;%8;%9;%10-4") @@ -927,7 +920,7 @@ FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i ) QString line = getSettings()->value( "MainWindow/FSCline", "0-2;21;4;2;5;21;18;21;19;21;9;22;23-4" ).toString(); - parseAndCreateLine( line, 1 ); + parseAndCreate( line, controlLayout ); /* hiding timer */ p_hideTimer = new QTimer( this ); diff --git a/modules/gui/qt4/components/controller.hpp b/modules/gui/qt4/components/controller.hpp index 4b2515f828..21b6d307cb 100644 --- a/modules/gui/qt4/components/controller.hpp +++ b/modules/gui/qt4/components/controller.hpp @@ -41,6 +41,8 @@ #include #include +#define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media") + class QPixmap; class QLabel; class QGridLayout; @@ -54,11 +56,11 @@ class VolumeClickHandler; class QSignalMapper; class QTimer; +class WidgetListing; typedef enum buttonType_e { PLAY_BUTTON, - PAUSE_BUTTON, STOP_BUTTON, OPEN_BUTTON, PREVIOUS_BUTTON, @@ -73,23 +75,45 @@ typedef enum buttonType_e RECORD_BUTTON, ATOB_BUTTON, FRAME_BUTTON, + REVERSE_BUTTON, + BUTTON_MAX, + + SPLITTER = 0x20, INPUT_SLIDER, - VOLUME_SLIDER, - MENU_BUTTONS, - TELETEXT_BUTTONS, VOLUME, - WIDGET_SPACER, - WIDGET_SPACER_EXTEND, TIME_LABEL, - SPLITTER, + MENU_BUTTONS, + TELETEXT_BUTTONS, ADVANCED_CONTROLLER, - REVERSE_BUTTON, + SPECIAL_MAX, + + WIDGET_SPACER = 0x40, + WIDGET_SPACER_EXTEND, + WIDGET_MAX, } buttonType_e; +#include + +static const QString nameL[BUTTON_MAX] = { "Play", "Stop", "Open", + "Previous", "Next", "Slower", "Faster", "Fullscreen", "De-Fullscreen", + "Extended panel", "Playlist", "Snapshot", "Record", "A->B Loop", + "Frame By Frame", "Reverse" }; +static const QString tooltipL[BUTTON_MAX] = { I_PLAY_TOOLTIP, + _("Stop playback"), + _("Previous media in the playlist"), + _("Next media in the playlist"), _("Slower"), _("Faster"), + _("Toggle the video in fullscreen"), _("Toggle the video out fullscreen"), + _("Show extended settings" ), _( "Show playlist" ), _( "Take a snapshot" ), + _( "Record" ), _( "Loop from point A to point B continuously." ), + _("Frame by frame"), _("Reverse") }; +static const QString iconL[BUTTON_MAX] ={ ":/play_b", ":/stop_b", "", + ":/previous_b", ":/next_b", ":/slower", ":/faster", ":/fullscreen", + ":/defullscreen", ":/extended", ":/playlist", ":/snapshot", ":/record", + ":/atob_nob", ":/frame", ":/reverse" }; + typedef enum actionType_e { PLAY_ACTION, - PAUSE_ACTION, STOP_ACTION, PREVIOUS_ACTION, NEXT_ACTION, @@ -115,30 +139,34 @@ enum class AbstractController : public QFrame { + friend class WidgetListing; /* For ToolBar Edition HACKS */ + Q_OBJECT public: AbstractController( intf_thread_t *_p_i ); - int getWidth() { return controlLayout->columnCount(); } protected: intf_thread_t *p_intf; QSignalMapper *toolbarActionsMapper; - QGridLayout *controlLayout; + QHBoxLayout *controlLayout; + /* Change to BoxLayout if both dir are needed */ AdvControlsWidget *advControls; - void parseAndCreateLine( QString config, int i_line ); + void parseAndCreate( QString config, QBoxLayout *controlLayout ); + + virtual void createAndAddWidget( QBoxLayout *controlLayout, int i_index, + buttonType_e i_type, int i_option ); + QWidget *createWidget( buttonType_e, int options = WIDGET_NORMAL ); private: - QWidget *createWidget( buttonType_e, int *i_size, - int options = WIDGET_NORMAL ); - void setupButton( QAbstractButton * ); + static void setupButton( QAbstractButton * ); QWidget *discFrame(); QWidget *telexFrame(); -private slots: - void doAction( int ); +protected slots: + virtual void doAction( int ); protected slots: void play(); @@ -204,7 +232,7 @@ class SoundWidget : public QWidget friend class VolumeClickHandler; public: - SoundWidget( intf_thread_t *_p_i, bool ); + SoundWidget( QWidget *parent, intf_thread_t *_p_i, bool ); private: intf_thread_t *p_intf; diff --git a/modules/gui/qt4/dialogs/toolbar.cpp b/modules/gui/qt4/dialogs/toolbar.cpp new file mode 100644 index 0000000000..985412b5e1 --- /dev/null +++ b/modules/gui/qt4/dialogs/toolbar.cpp @@ -0,0 +1,433 @@ +/***************************************************************************** + * ToolbarEdit.cpp : ToolbarEdit and About dialogs + **************************************************************************** + * Copyright (C) 2008 the VideoLAN team + * $Id$ + * + * Authors: Jean-Baptiste Kempf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "dialogs/toolbar.hpp" + +#include "util/input_slider.hpp" +#include "util/customwidgets.hpp" +#include "components/interface_widgets.hpp" + +#include +#include +#include +#include +#include + +#include + +ToolbarEditDialog *ToolbarEditDialog::instance = NULL; + +ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf) + : QVLCFrame( _p_intf ) +{ + setWindowTitle( qtr( "Toolbars Edition" ) ); + QGridLayout *mainLayout = new QGridLayout( this ); + setMinimumWidth( 600 ); + + /* main GroupBox */ + QGroupBox *widgetBox = new QGroupBox( "Toolbar Elements", this ); + widgetBox->setSizePolicy( QSizePolicy::Preferred, + QSizePolicy::MinimumExpanding ); + QGridLayout *boxLayout = new QGridLayout( widgetBox ); + + boxLayout->addWidget( new WidgetListing( p_intf, this ), 0, 0, 1, -1); + flatBox = new QCheckBox( qtr( "Flat Button" ) ); + bigBox = new QCheckBox( qtr( "Big Button" ) ); + shinyBox = new QCheckBox( qtr( "Native Slider" ) ); + shinyBox->setChecked( true ); + boxLayout->addWidget( flatBox, 1, 0 ); + boxLayout->addWidget( bigBox, 1, 1 ); + boxLayout->addWidget( bigBox, 1, 2 ); + mainLayout->addWidget( widgetBox, 0, 0, 1, -1 ); + + + /* Main ToolBar */ + QGroupBox *mainToolbarBox = new QGroupBox( "Main Toolbar", this ); + QGridLayout *mainTboxLayout = new QGridLayout( mainToolbarBox ); + + QLabel *label = new QLabel( "Toolbar position:" ); + mainTboxLayout->addWidget(label, 0, 0, 1, 1); + + QComboBox *positionCombo = new QComboBox; + positionCombo->addItems( QStringList() << "Over the Video" + << "Under the Video" ); + mainTboxLayout->addWidget( positionCombo, 0, 1, 1, 1 ); + + QFrame *mainToolFrame = new QFrame; + mainToolFrame->setMinimumSize( QSize( 0, 25 ) ); + mainToolFrame->setFrameShape( QFrame::StyledPanel ); + mainToolFrame->setFrameShadow( QFrame::Raised ); + mainTboxLayout->addWidget( mainToolFrame, 1, 0, 1, 2 ); + mainToolFrame->setAcceptDrops( true ); + QHBoxLayout *mtlayout = new QHBoxLayout( mainToolFrame ); + + DroppingController *controller = new DroppingController( p_intf ); + mtlayout->addWidget( controller ); + + + QFrame *mainTool2Frame = new QFrame; + mainTool2Frame->setMinimumSize( QSize( 0, 25 ) ); + mainTool2Frame->setFrameShape( QFrame::StyledPanel ); + mainTool2Frame->setFrameShadow( QFrame::Raised ); + mainTboxLayout->addWidget( mainTool2Frame, 2, 0, 1, 2 ); + mainTool2Frame->setAcceptDrops( true ); + + mainLayout->addWidget( mainToolbarBox, 1, 0, 1, -1 ); +} + + +ToolbarEditDialog::~ToolbarEditDialog() +{ +} + +WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent ) + : QListWidget( _parent ) +{ + /* We need the parent to know the options checked */ + parent = qobject_cast(_parent); + assert( parent ); + + /* Normal options */ + setViewMode( QListView::IconMode ); + setSpacing( 20 ); + setDragEnabled( true ); + setMinimumHeight( 250 ); + + /* All the buttons do not need a special rendering */ + for( int i = 0; i < BUTTON_MAX; i++ ) + { + QListWidgetItem *widgetItem = new QListWidgetItem( this ); + widgetItem->setText( nameL[i] ); + widgetItem->setIcon( QIcon( iconL[i] ) ); + widgetItem->setData( Qt::UserRole, QVariant( i ) ); + addItem( widgetItem ); + } + + /* Spacers are yet again a different thing */ + QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/space" ), + qtr( "Spacer" ), this ); + widgetItem->setData( Qt::UserRole, WIDGET_SPACER ); + addItem( widgetItem ); + + widgetItem = new QListWidgetItem( QIcon( ":/space" ), + qtr( "Expanding Spacer" ), this ); + widgetItem->setData( Qt::UserRole, WIDGET_SPACER_EXTEND ); + addItem( widgetItem ); + + /** + * For all other widgets, we create then, do a pseudo rendering in + * a pixmaps for the view, and delete the object + * + * A lot of code is retaken from the Abstract, but not exactly... + * So, rewrite. + * They are better ways to deal with this, but I doubt that this is + * necessary. If you feel like you have the time, be my guest. + * -- + * jb + **/ + for( int i = SPLITTER; i < SPECIAL_MAX; i++ ) + { + QWidget *widget = NULL; + QListWidgetItem *widgetItem = new QListWidgetItem( this ); + switch( i ) + { + case SPLITTER: + { + QFrame *line = new QFrame( this ); + line->setFrameShape( QFrame::VLine ); + line->setFrameShadow( QFrame::Raised ); + line->setLineWidth( 0 ); line->setMidLineWidth( 1 ); + widget = line; + } + widgetItem->setText( qtr("Splitter") ); + break; + case INPUT_SLIDER: + { + InputSlider *slider = new InputSlider( Qt::Horizontal, this ); + widget = slider; + } + widgetItem->setText( qtr("Time Slider") ); + break; + case VOLUME: + { + bool b_shiny = false; + SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny ); + widget = snd; + } + widgetItem->setText( qtr("Volume") ); + break; + case TIME_LABEL: + { + QLabel *timeLabel = new QLabel( "12:42/2:12:42", this ); + widget = timeLabel; + } + widgetItem->setText( qtr("Time") ); + break; + case MENU_BUTTONS: + { + QWidget *discFrame = new QWidget( this ); + QHBoxLayout *discLayout = new QHBoxLayout( discFrame ); + discLayout->setSpacing( 0 ); discLayout->setMargin( 0 ); + + QToolButton *prevSectionButton = new QToolButton( discFrame ); + prevSectionButton->setIcon( QIcon( ":/dvd_prev" ) ); + discLayout->addWidget( prevSectionButton ); + + QToolButton *menuButton = new QToolButton( discFrame ); + menuButton->setIcon( QIcon( ":/dvd_menu" ) ); + discLayout->addWidget( menuButton ); + + QToolButton *nextButton = new QToolButton( discFrame ); + nextButton->setIcon( QIcon( ":/dvd_next" ) ); + discLayout->addWidget( nextButton ); + + widget = discFrame; + } + widgetItem->setText( qtr("DVD menus") ); + break; + case TELETEXT_BUTTONS: + { + QWidget *telexFrame = new QWidget( this ); + QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame ); + telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 ); + + QToolButton *telexOn = new QToolButton( telexFrame ); + telexOn->setIcon( QIcon( ":/tv" ) ); + telexLayout->addWidget( telexOn ); + + QToolButton *telexTransparent = new QToolButton; + telexOn->setIcon( QIcon( ":/tvtelx-trans" ) ); + telexLayout->addWidget( telexTransparent ); + + QSpinBox *telexPage = new QSpinBox; + telexLayout->addWidget( telexPage ); + + widget = telexFrame; + } + widgetItem->setText( qtr("Teletext") ); + break; + case ADVANCED_CONTROLLER: + { + AdvControlsWidget *advControls = new AdvControlsWidget( p_intf ); + widget = advControls; + } + widgetItem->setText( qtr("Advanced Buttons") ); + break; + default: + msg_Warn( p_intf, "This should not happen %i", i ); + break; + } + + if( widget == NULL ) continue; + + + widgetItem->setIcon( QIcon( QPixmap::grabWidget( widget ) ) ); + widget->hide(); + widgetItem->setData( Qt::UserRole, QVariant( i ) ); + + addItem( widgetItem ); + delete widget; + } +} + +void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ ) +{ + QListWidgetItem *item =currentItem(); + + QByteArray itemData; + QDataStream dataStream( &itemData, QIODevice::WriteOnly ); + + int i_type = item->data( Qt::UserRole ).toInt(); + int i_option = parent->getOptions(); + dataStream << i_type << i_option; + + QMimeData *mimeData = new QMimeData; + mimeData->setData( "vlc/button-bar", itemData ); + + QDrag *drag = new QDrag( this ); + drag->setMimeData( mimeData ); +// drag->setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2)); + + drag->exec(Qt::CopyAction | Qt::MoveAction ); +} + + +DroppingController::DroppingController( intf_thread_t *_p_intf ) + : AbstractController( _p_intf ) +{ + rubberband = NULL; + setAcceptDrops( true ); + controlLayout = new QHBoxLayout( this ); + controlLayout->setSpacing( 0 ); + controlLayout->setMargin( 0 ); + setFrameShape( QFrame::StyledPanel ); + setFrameShadow( QFrame::Raised ); + + QString line2 = getSettings()->value( "MainWindow/Controls2", + "0-2;21;4;2;5;21;8;11;10;21;22;20-4" ).toString(); + + parseAndCreate( line2, controlLayout ); + + //QString line1 = getSettings()->value( "MainWindow/Controls2", + // "18;19;25;0" ).toString(); + // parseAndCreate( line1, 1 ); + +} + +/* Overloading the AbstractController one, because we don't manage the + Spacing in the same ways */ +void DroppingController::createAndAddWidget( QBoxLayout *controlLayout, + int i_index, + buttonType_e i_type, + int i_option ) +{ + /* Special case for SPACERS, who aren't QWidgets */ + if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND ) + { + QLabel *label = new QLabel; + label->setPixmap( QPixmap( ":/space" ) ); + if( i_type == WIDGET_SPACER_EXTEND ) + { + label->setScaledContents( true ); + label->setSizePolicy( QSizePolicy::MinimumExpanding, + QSizePolicy::Preferred ); + } + else + label->setSizePolicy( QSizePolicy::Fixed, + QSizePolicy::Preferred ); + + controlLayout->insertWidget( i_index, label ); + } + else + { + QWidget *widg = createWidget( i_type, i_option ); + if( !widg ) return; + + /* Some Widgets are deactivated at creation */ + widg->setEnabled( true ); + controlLayout->insertWidget( i_index, widg ); + } +} + +void DroppingController::dragEnterEvent( QDragEnterEvent * event ) +{ + if( event->mimeData()->hasFormat( "vlc/button-bar" ) ) + event->accept(); + else + event->ignore(); +} + +void DroppingController::dragMoveEvent( QDragMoveEvent *event ) +{ + QPoint origin = event->pos(); + + int i_pos = getParentPosInLayout( origin ); + bool b_end = false; + + /* Both sides of the frame */ + if( i_pos == -1 ) + { + if( rubberband ) rubberband->hide(); + return; + } + + /* Last item is special because of underlying items */ + if( i_pos >= controlLayout->count() ) + { + i_pos--; + b_end = true; + } + + /* Query the underlying item for size && middles */ + QLayoutItem *tempItem = controlLayout->itemAt( i_pos ); assert( tempItem ); + QWidget *temp = tempItem->widget(); assert( temp ); + + /* Position assignment */ + origin.ry() = 0; + origin.rx() = temp->x() - 2; + + if( b_end ) origin.rx() += temp->width(); + + if( !rubberband ) + rubberband = new QRubberBand( QRubberBand::Line, this ); + rubberband->setGeometry( origin.x(), origin.y(), 4, height() ); + rubberband->show(); +} + +inline int DroppingController::getParentPosInLayout( QPoint point) +{ + point.ry() = height() / 2 ; + QPoint origin = mapToGlobal ( point ); + + QWidget *tempWidg = QApplication::widgetAt( origin ); + + int i = -1; + if( tempWidg != NULL) + { + i = controlLayout->indexOf( tempWidg ); + if( i == -1 ) + { + i = controlLayout->indexOf( tempWidg->parentWidget() ); + tempWidg = tempWidg->parentWidget(); + } + } + + /* Return the nearest position */ + if( ( point.x() - tempWidg->x() > tempWidg->width() / 2 ) && i != -1 ) + i++; + + // msg_Dbg( p_intf, "%i", i); + return i; +} + +void DroppingController::dropEvent( QDropEvent *event ) +{ + int i = getParentPosInLayout( event->pos() ); + + QByteArray data = event->mimeData()->data( "vlc/button-bar" ); + QDataStream dataStream(&data, QIODevice::ReadOnly); + + int i_option = 0, i_type = 0; + dataStream >> i_type >> i_option; + + createAndAddWidget( controlLayout, i, (buttonType_e)i_type, i_option ); + + /* Hide by precaution, you don't exactly know what could have happened in + between */ + if( rubberband ) rubberband->hide(); +} + +void DroppingController::dragLeaveEvent ( QDragLeaveEvent * event ) +{ + if( rubberband ) rubberband->hide(); +} + +/** + * Overloading doAction to block any action + **/ +void DroppingController::doAction( int i ){} +