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