Commit 9d9ffe9f authored by Jakob Leben's avatar Jakob Leben

Qt: make ground for proper main interface size management

- Simplify switching between widgets in central stack: showTab() allows
switching only between two states - video state and playlist state - and
does everything needed according to circumstances

- Do not setMinimumWidth/Height/Size() on main interface, because it
inhibits children sizeHint() evaluation, thus preventing interface
self-adjustment when controls are added/removed or shown/hidden.

- Subclass QStackedWidget so it's minimumSizeHint() matches exactly
the one of the currentWidget(), and not the sum of all children.

- Suggest compact mode implementation (commented out for now):
setSizeConstraint( QLayout::SetFixedSize ) on main interface layout.
This automatically keeps and adjusts fixed size in respect to
sizeHint() of children.
parent 02ee6240
...@@ -75,6 +75,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -75,6 +75,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
bgWidget = NULL; bgWidget = NULL;
videoWidget = NULL; videoWidget = NULL;
playlistWidget = NULL; playlistWidget = NULL;
videoRoleWidget = NULL;
#ifndef HAVE_MAEMO #ifndef HAVE_MAEMO
sysTray = NULL; sysTray = NULL;
#endif #endif
...@@ -150,6 +151,11 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -150,6 +151,11 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ), CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
this, destroyPopupMenu() ); this, destroyPopupMenu() );
minWidthHolder = new QWidget;
minWidthHolder->setMinimumWidth(
__MAX( menuBar()->sizeHint().width() + 30, 400 ) );
mainLayout->addWidget( minWidthHolder );
/********************************* /*********************************
* Create the Systray Management * * Create the Systray Management *
*********************************/ *********************************/
...@@ -244,13 +250,13 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -244,13 +250,13 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
/* resize to previously saved main window size if appicable */ /* resize to previously saved main window size if appicable */
//FIXME remove. //FIXME remove.
if( b_keep_size ) /*if( b_keep_size )
{ {
if( i_visualmode ) if( i_visualmode )
resize( mainVideoSize ); resize( mainVideoSize );
else else
resize( mainBasedSize ); resize( mainBasedSize );
} }*/
/* Playlist */ /* Playlist */
int i_plVis = settings->value( "playlist-visible", 0 ).toInt(); int i_plVis = settings->value( "playlist-visible", 0 ).toInt();
...@@ -262,19 +268,17 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -262,19 +268,17 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
/* Final sizing and showing */ /* Final sizing and showing */
setVisible( !b_hideAfterCreation ); setVisible( !b_hideAfterCreation );
setMinimumWidth( __MAX( controls->sizeHint().width(),
menuBar()->sizeHint().width() ) + 30 );
/* Switch to minimal view if needed, must be called after the show() */ /* Switch to minimal view if needed, must be called after the show() */
if( i_visualmode ) if( i_visualmode )
toggleMinimalView( true ); toggleMinimalView( true );
else
showTab();
} }
MainInterface::~MainInterface() MainInterface::~MainInterface()
{ {
/* Unsure we hide the videoWidget before destroying it */ /* Unsure we hide the videoWidget before destroying it */
if( stackCentralOldWidget == playlistWidget ) //showTab( PLAYLIST_TAB );
showBg();
/* Save playlist state */ /* Save playlist state */
if( playlistWidget ) if( playlistWidget )
...@@ -361,11 +365,12 @@ void MainInterface::createMainWidget( QSettings *settings ) ...@@ -361,11 +365,12 @@ void MainInterface::createMainWidget( QSettings *settings )
mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 ); mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 );
/* */ /* */
stackCentralW = new QStackedWidget( main ); stackCentralW = new QVLCStackedWidget( main );
/* Bg Cone */ /* Bg Cone */
bgWidget = new BackgroundWidget( p_intf ); bgWidget = new BackgroundWidget( p_intf );
stackCentralW->addWidget( bgWidget ); stackCentralW->addWidget( bgWidget );
videoRoleWidget = bgWidget;
/* And video Outputs */ /* And video Outputs */
if( b_videoEmbedded ) if( b_videoEmbedded )
...@@ -378,6 +383,7 @@ void MainInterface::createMainWidget( QSettings *settings ) ...@@ -378,6 +383,7 @@ void MainInterface::createMainWidget( QSettings *settings )
/* Create the CONTROLS Widget */ /* Create the CONTROLS Widget */
controls = new ControlsWidget( p_intf, controls = new ControlsWidget( p_intf,
settings->value( "adv-controls", false ).toBool(), this ); settings->value( "adv-controls", false ).toBool(), this );
CONNECT( controls, advancedControlsToggled( bool ), CONNECT( controls, advancedControlsToggled( bool ),
this, adaptGeometry() ); this, adaptGeometry() );
CONNECT( controls, sizeChanged(), CONNECT( controls, sizeChanged(),
...@@ -481,7 +487,7 @@ inline void MainInterface::createStatusBar() ...@@ -481,7 +487,7 @@ inline void MainInterface::createStatusBar()
*/ */
void MainInterface::adaptGeometry() void MainInterface::adaptGeometry()
{ {
resize( sizeHint() ); //resize( sizeHint() );
#ifdef DEBUG_INTF #ifdef DEBUG_INTF
debug(); debug();
...@@ -501,36 +507,40 @@ void MainInterface::debug() ...@@ -501,36 +507,40 @@ void MainInterface::debug()
#endif #endif
} }
inline void MainInterface::showVideo() { showTab( videoWidget ); } inline void MainInterface::showTab( StackTab tab )
inline void MainInterface::showBg() { showTab( bgWidget ); }
inline void MainInterface::showTab( QWidget *widget )
{ {
#ifdef DEBUG_INTF if( tab == PLAYLIST_TAB && !b_plDocked ) return;
msg_Warn( p_intf, "Old stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
#endif
stackCentralOldWidget = stackCentralW->currentWidget();
stackCentralW->setCurrentWidget( widget );
#ifdef DEBUG_INTF QWidget *widget;
msg_Warn( p_intf, "State change %i", stackCentralW->currentIndex() ); switch ( tab )
msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) ); {
#endif case PLAYLIST_TAB: widget = playlistWidget; break;
} case VIDEO_TAB: widget = videoRoleWidget; break;
case CURRENT_TAB: widget = stackCentralW->currentWidget(); break;
}
inline void MainInterface::restoreStackOldWidget() stackCentralW->setCurrentWidget( widget );
{
#ifdef DEBUG_INTF
msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
#endif
QWidget *wTemp = stackCentralW->currentWidget();
stackCentralW->setCurrentWidget( stackCentralOldWidget ); // Go into compact mode if needed (stackCentralW hidden)
if( widget == bgWidget && !b_keep_size && controls->isVisible() && !isFullScreen() )
{
resize( 0, 0 );
}
stackCentralOldWidget = wTemp; /* TODO Alternatively, for compact mode the best thing would be to setSizeConstraint
#ifdef DEBUG_INTF on layout, but sadly, we can only constrain the whole size, while we should
msg_Warn( p_intf, "Debug %i %i",stackCentralW->indexOf( wTemp ), stackCentralW->indexOf( stackCentralW->currentWidget() ) ); constrain height only */
#endif /*if( widget == bgWidget && !b_keep_size && controls->isVisible() && !isFullScreen() )
{
stackCentralW->hide();
layout()->setSizeConstraint( QLayout::SetFixedSize );
}
else
{
layout()->setSizeConstraint( QLayout::SetDefaultConstraint );
setMaximumSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX );
stackCentralW->show();
}*/
} }
void MainInterface::destroyPopupMenu() void MainInterface::destroyPopupMenu()
...@@ -602,8 +612,9 @@ void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y, ...@@ -602,8 +612,9 @@ void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
/* ask videoWidget to show */ /* ask videoWidget to show */
videoWidget->SetSizing( *pi_width, *pi_height ); videoWidget->SetSizing( *pi_width, *pi_height );
videoRoleWidget = videoWidget;
/* Consider the video active now */ /* Consider the video active now */
showVideo(); showTab( VIDEO_TAB );
} }
} }
...@@ -616,12 +627,11 @@ void MainInterface::releaseVideo( void ) ...@@ -616,12 +627,11 @@ void MainInterface::releaseVideo( void )
/* Function that is CONNECTED to the previous emit */ /* Function that is CONNECTED to the previous emit */
void MainInterface::releaseVideoSlot( void ) void MainInterface::releaseVideoSlot( void )
{ {
videoWidget->release(); videoRoleWidget = bgWidget;
restoreStackOldWidget(); showTab( b_plDocked && playlistVisible ? PLAYLIST_TAB : VIDEO_TAB );
/* We don't want to have a blank video to popup */ videoWidget->release();
stackCentralOldWidget = bgWidget;
} }
/* Asynchronous call from WindowControl function */ /* Asynchronous call from WindowControl function */
...@@ -687,19 +697,8 @@ void MainInterface::togglePlaylist() ...@@ -687,19 +697,8 @@ void MainInterface::togglePlaylist()
if( b_plDocked ) if( b_plDocked )
{ {
/* Playlist is not visible, show it */ showTab( stackCentralW->currentWidget() != playlistWidget ?
if( stackCentralW->currentWidget() != playlistWidget ) PLAYLIST_TAB : VIDEO_TAB );
{
playlistWidget->forceShow();
showTab( playlistWidget );
}
else /* Hide it! */
{
restoreStackOldWidget();
stackCentralW->updateGeometry();
// HACK: So it doesn't limit the stackWidget minimumSize
playlistWidget->forceHide();
}
playlistVisible = ( stackCentralW->currentWidget() == playlistWidget ); playlistVisible = ( stackCentralW->currentWidget() == playlistWidget );
} }
else else
...@@ -719,20 +718,21 @@ void MainInterface::dockPlaylist( bool p_docked ) ...@@ -719,20 +718,21 @@ void MainInterface::dockPlaylist( bool p_docked )
if( !playlistWidget ) return; /* Playlist wasn't created yet */ if( !playlistWidget ) return; /* Playlist wasn't created yet */
if( !p_docked ) if( !p_docked )
{ {
showTab( VIDEO_TAB );
stackCentralW->removeWidget( playlistWidget ); stackCentralW->removeWidget( playlistWidget );
playlistWidget->setWindowFlags( Qt::Window ); playlistWidget->setWindowFlags( Qt::Window );
QVLCTools::restoreWidgetPosition( p_intf, "Playlist", QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
playlistWidget, QSize( 600, 300 ) ); playlistWidget, QSize( 600, 300 ) );
playlistWidget->show(); playlistWidget->show();
restoreStackOldWidget();
} }
else else
{ {
playlistWidget->setWindowFlags( Qt::Widget ); // Probably a Qt bug here playlistWidget->setWindowFlags( Qt::Widget ); // Probably a Qt bug here
// It would be logical that QStackWidget::addWidget reset the flags... // It would be logical that QStackWidget::addWidget reset the flags...
stackCentralW->addWidget( playlistWidget ); stackCentralW->addWidget( playlistWidget );
stackCentralW->setCurrentWidget( playlistWidget ); showTab( PLAYLIST_TAB );
} }
playlistVisible = true;
} }
/* /*
...@@ -740,30 +740,14 @@ void MainInterface::dockPlaylist( bool p_docked ) ...@@ -740,30 +740,14 @@ void MainInterface::dockPlaylist( bool p_docked )
*/ */
void MainInterface::toggleMinimalView( bool b_switch ) void MainInterface::toggleMinimalView( bool b_switch )
{ {
if( i_visualmode == 0 )
{ /* NORMAL MODE then */
if( !videoWidget || stackCentralW->currentWidget() != videoWidget )
{
showBg();
}
else
{
/* If video is visible, then toggle the status of bgWidget */
//FIXME
//bgWasVisible = !bgWasVisible;
/* if( stackCentralOldState == BACK G_TAB )
stackCentralOldState = HID DEN_TAB;
else
stackCentralOldState = BACK G_TAB;
*/
}
}
menuBar()->setVisible( !b_switch ); menuBar()->setVisible( !b_switch );
controls->setVisible( !b_switch ); controls->setVisible( !b_switch );
statusBar()->setVisible( !b_switch ); statusBar()->setVisible( !b_switch );
inputC->setVisible( !b_switch ); inputC->setVisible( !b_switch );
minWidthHolder->setVisible( !b_switch );
// Go to compact mode and back if needed
showTab();
emit minimalViewToggled( b_switch ); emit minimalViewToggled( b_switch );
} }
...@@ -1159,6 +1143,7 @@ void MainInterface::toggleFullScreen() ...@@ -1159,6 +1143,7 @@ void MainInterface::toggleFullScreen()
showFullScreen(); showFullScreen();
emit fullscreenInterfaceToggled( true ); emit fullscreenInterfaceToggled( true );
} }
showTab();
} }
/***************************************************************************** /*****************************************************************************
......
...@@ -114,10 +114,13 @@ private: ...@@ -114,10 +114,13 @@ private:
void handleSystray(); void handleSystray();
/* Central StackWidget Management */ /* Central StackWidget Management */
void showTab( QWidget *); enum StackTab
void showVideo(); {
void showBg(); PLAYLIST_TAB,
void restoreStackOldWidget(); VIDEO_TAB,
CURRENT_TAB
};
void showTab( StackTab = CURRENT_TAB );
/* */ /* */
QSettings *settings; QSettings *settings;
...@@ -138,15 +141,14 @@ private: ...@@ -138,15 +141,14 @@ private:
VideoWidget *videoWidget; VideoWidget *videoWidget;
BackgroundWidget *bgWidget; BackgroundWidget *bgWidget;
PlaylistWidget *playlistWidget; PlaylistWidget *playlistWidget;
QWidget *videoRoleWidget;
//VisualSelector *visualSelector; //VisualSelector *visualSelector;
QWidget *minWidthHolder;
/* Status Bar */ /* Status Bar */
QLabel *nameLabel; QLabel *nameLabel;
QLabel *cryptedLabel; QLabel *cryptedLabel;
/* Status and flags */
QWidget *stackCentralOldWidget;
/* Flags */ /* Flags */
bool b_notificationEnabled; /// Systray Notifications bool b_notificationEnabled; /// Systray Notifications
bool b_keep_size; ///< persistent resizeable window bool b_keep_size; ///< persistent resizeable window
...@@ -226,4 +228,14 @@ signals: ...@@ -226,4 +228,14 @@ signals:
}; };
class QVLCStackedWidget : public QStackedWidget
{
public:
QVLCStackedWidget( QWidget *parent ) : QStackedWidget( parent ) { }
virtual QSize minimumSizeHint () const
{
return currentWidget() ? currentWidget()->minimumSizeHint() : QSize();
}
};
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment