General improvements window manager

Add support to multi window mode.
Clean code and fix some functions to manage the active windows and
detect close and focus
This commit is contained in:
jfmcarreira committed 2015-01-23 01:21:23 +00:00
1 parent 826bac655c
commit 56e466346b
9 files changed
+135 -70

No files matched your search

+7
View File
@@ -32,6 +32,13 @@ PlaYUVerMdiSubWindow::PlaYUVerMdiSubWindow( QWidget *parent ) :
{
}
QSize PlaYUVerMdiSubWindow::sizeHint() const
{
QSize sizeHint = widget()->sizeHint();
return sizeHint;
}
Void PlaYUVerMdiSubWindow::closeEvent( QCloseEvent *event )
{
emit aboutToClose( this );
+1
View File
@@ -47,6 +47,7 @@ Q_SIGNALS:
void aboutToClose( PlaYUVerMdiSubWindow* );
protected:
QSize sizeHint() const;
void closeEvent( QCloseEvent *event );
};
+69 -19
View File
@@ -57,25 +57,62 @@ private:
PlaYUVerSubWindowHandle::PlaYUVerSubWindowHandle( QWidget *parent ) :
QWidget( parent )
{
m_bMdiModeEnabled = true;
m_uiWindowMode = 0;
m_pcMdiArea = new PlaYUVerMdiArea( this );
m_pcMdiArea->setActivationOrder( QMdiArea::ActivationHistoryOrder );
QHBoxLayout* m_pcWindowManagerLayout = new QHBoxLayout( this );
m_pcWindowManagerLayout->addWidget( m_pcMdiArea );
setLayout( m_pcWindowManagerLayout );
connect( m_pcMdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( updateActiveSubWindow() ) );
setWindowMode( MdiWSubWindows );
m_pcActiveWindow = NULL;
m_apcSubWindowList.clear();
m_apcMdiSubWindowList.clear();
}
Void PlaYUVerSubWindowHandle::updateActiveSubWindow()
Void PlaYUVerSubWindowHandle::resetWindowMode()
{
if( m_bMdiModeEnabled )
if( m_uiWindowMode == MdiWSubWindows )
{
removeAllSubWindow();
m_apcMdiSubWindowList.clear();
if( m_pcMdiArea )
delete m_pcMdiArea;
if( m_pcWindowManagerLayout )
delete m_pcWindowManagerLayout;
}
}
Void PlaYUVerSubWindowHandle::setWindowMode( UInt uiWindowMode )
{
if( m_uiWindowMode == uiWindowMode )
return;
resetWindowMode();
if( uiWindowMode == NormalSubWindows )
{
}
if( uiWindowMode == MdiWSubWindows )
{
m_pcMdiArea = new PlaYUVerMdiArea( this );
m_pcMdiArea->setActivationOrder( QMdiArea::ActivationHistoryOrder );
connect( m_pcMdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( updateActiveSubWindow() ) );
m_pcWindowManagerLayout = new QHBoxLayout( this );
m_pcWindowManagerLayout->addWidget( m_pcMdiArea );
setLayout( m_pcWindowManagerLayout );
}
m_uiWindowMode = uiWindowMode;
}
Void PlaYUVerSubWindowHandle::updateActiveSubWindow( SubWindowHandle *window )
{
if( m_uiWindowMode == NormalSubWindows )
{
if( window )
m_pcActiveWindow = window;
}
if( m_uiWindowMode == MdiWSubWindows )
{
m_pcActiveWindow = NULL;
QMdiSubWindow* mdiSubWindow = m_pcMdiArea->activeSubWindow();
@@ -94,7 +131,12 @@ Void PlaYUVerSubWindowHandle::updateActiveSubWindow()
Void PlaYUVerSubWindowHandle::addSubWindow( SubWindowHandle *window, Qt::WindowFlags flags )
{
if( m_bMdiModeEnabled )
if( m_uiWindowMode == NormalSubWindows )
{
connect( window, SIGNAL( aboutToActivate( SubWindowHandle* ) ), this, SLOT( aboutToActivate( SubWindowHandle* ) ) );
connect( window, SIGNAL( aboutToClose( SubWindowHandle* ) ), this, SLOT( removeMdiSubWindow( SubWindowHandle* ) ) );
}
if( m_uiWindowMode == MdiWSubWindows )
{
PlaYUVerMdiSubWindow* mdiSubWindow = new PlaYUVerMdiSubWindow( this );
mdiSubWindow->setWidget( window );
@@ -109,16 +151,24 @@ Void PlaYUVerSubWindowHandle::removeSubWindow( Int windowIdx )
{
if( windowIdx >= 0 )
{
if( m_bMdiModeEnabled )
if( m_uiWindowMode == NormalSubWindows )
{
SubWindowHandle* subWindow = m_apcSubWindowList.at( windowIdx );
m_apcSubWindowList.removeAt( windowIdx );
subWindow->close();
}
if( m_uiWindowMode == MdiWSubWindows )
{
PlaYUVerMdiSubWindow* mdiSubWindow = m_apcMdiSubWindowList.at( windowIdx );
m_apcMdiSubWindowList.removeAt( windowIdx );
m_pcMdiArea->removeSubWindow( m_apcSubWindowList.at( windowIdx ) );
mdiSubWindow->close();
m_apcSubWindowList.removeAt( windowIdx );
}
m_apcSubWindowList.removeAt( windowIdx );
if( !m_apcSubWindowList.isEmpty() )
m_apcSubWindowList.front()->setFocus();
}
m_apcSubWindowList.front()->activateWindow();
}
Void PlaYUVerSubWindowHandle::removeSubWindow( SubWindowHandle* window )
@@ -179,7 +229,7 @@ QList<SubWindowHandle*> PlaYUVerSubWindowHandle::findSubWindow( const UInt uiCat
return apcSubWindowList;
}
SubWindowHandle* PlaYUVerSubWindowHandle::findSubWindow( const SubWindowHandle* subWindow )
SubWindowHandle* PlaYUVerSubWindowHandle::findSubWindow( const SubWindowHandle* subWindow ) const
{
QList<SubWindowHandle*> subWindowList = findSubWindow();
for( Int i = 0; i < subWindowList.size(); i++ )
@@ -201,7 +251,7 @@ Void PlaYUVerSubWindowHandle::setActiveSubWindow( QWidget *window )
Void PlaYUVerSubWindowHandle::tileSubWindows()
{
if( m_bMdiModeEnabled )
if( m_uiWindowMode == MdiWSubWindows )
{
m_pcMdiArea->tileSubWindows();
}
@@ -209,7 +259,7 @@ Void PlaYUVerSubWindowHandle::tileSubWindows()
Void PlaYUVerSubWindowHandle::cascadeSubWindows()
{
if( m_bMdiModeEnabled )
if( m_uiWindowMode == MdiWSubWindows )
{
m_pcMdiArea->cascadeSubWindows();
}
@@ -225,7 +275,7 @@ Void PlaYUVerSubWindowHandle::createActions()
m_arrayActions[CLOSE_ACT] = new QAction( tr( "&Close" ), this );
m_arrayActions[CLOSE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) );
m_arrayActions[CLOSE_ACT]->setStatusTip( tr( "Close the active window" ) );
connect( m_arrayActions[CLOSE_ACT], SIGNAL( triggered() ), this, SLOT( closeActiveWindow() ) );
connect( m_arrayActions[CLOSE_ACT], SIGNAL( triggered() ), this, SLOT( removeActiveSubWindow() ) );
m_arrayActions[CLOSE_ALL_ACT] = new QAction( tr( "Close &All" ), this );
m_arrayActions[CLOSE_ALL_ACT]->setStatusTip( tr( "Close all the windows" ) );
+12 -4
View File
@@ -48,13 +48,12 @@ public:
PlaYUVerSubWindowHandle( QWidget *parent = 0 );
Void addSubWindow( SubWindowHandle *widget, Qt::WindowFlags flags = 0 );
Void removeSubWindow( SubWindowHandle *window );
SubWindowHandle *activeSubWindow() const;
QList<SubWindowHandle*> findSubWindow( const QString &aName = QString() ) const;
QList<SubWindowHandle*> findSubWindow( const UInt uiCategory ) const;
SubWindowHandle* findSubWindow( const SubWindowHandle* subWindow );
SubWindowHandle* findSubWindow( const SubWindowHandle* subWindow ) const;
Void createActions();
QMenu* createMenu();
@@ -62,8 +61,14 @@ public:
Void readSettings();
Void writeSettings();
enum WindowMode
{
NormalSubWindows = 0,
MdiWSubWindows = 1,
};
private:
Bool m_bMdiModeEnabled;
UInt m_uiWindowMode;
QList<SubWindowHandle*> m_apcSubWindowList;
QHBoxLayout* m_pcWindowManagerLayout;
@@ -90,11 +95,14 @@ private:
/**
* Internal functions
*/
Void resetWindowMode();
Void setWindowMode( UInt uiWindowMode );
Void removeSubWindow( Int windowIdx );
public Q_SLOTS:
void updateActiveSubWindow();
void updateActiveSubWindow( SubWindowHandle *window = 0 );
void setActiveSubWindow( QWidget *window );
void removeSubWindow( SubWindowHandle *window );
void removeMdiSubWindow( PlaYUVerMdiSubWindow* window );
void removeActiveSubWindow();
void removeAllSubWindow();
+8 -2
View File
@@ -31,6 +31,7 @@ SubWindowHandle::SubWindowHandle( QWidget * parent, UInt category ) :
QScrollArea( parent )
{
setParent( parent );
setFocusPolicy( Qt::StrongFocus );
setAttribute( Qt::WA_DeleteOnClose );
setBackgroundRole( QPalette::Light );
@@ -43,9 +44,8 @@ SubWindowHandle::SubWindowHandle( QWidget * parent, UInt category ) :
setWidgetResizable( true );
m_cLastScroll = QPoint();
m_uiCategory = category;
m_cLastScroll = QPoint();
m_cWindowName = QString( " " );
}
@@ -132,8 +132,14 @@ Bool SubWindowHandle::mayClose()
return true;
}
Void SubWindowHandle::focusInEvent( QFocusEvent * event )
{
emit aboutToActivate( this );
}
Void SubWindowHandle::closeEvent( QCloseEvent *event )
{
emit aboutToClose( this );
event->accept();
}
+4
View File
@@ -91,6 +91,7 @@ public:
}
protected:
virtual void focusInEvent( QFocusEvent * event );
virtual void closeEvent( QCloseEvent *event );
QSize getScrollSize();
@@ -108,6 +109,9 @@ Q_SIGNALS:
*/
void updateStatusBar( const QString& );
void aboutToActivate( SubWindowHandle* );
void aboutToClose( SubWindowHandle* );
public Q_SLOTS:
void adjustScrollBarByScale( double scale, QPoint center );
void adjustScrollBarByOffset( QPoint Offset );
+22 -19
View File
@@ -38,9 +38,9 @@ QDataStream& operator<<( QDataStream& out, const PlaYUVerStreamInfoVector& array
{
d = array.at( i );
out << d.m_cFilename << d.m_uiWidth
<< d.m_uiHeight
<< d.m_iPelFormat
<< d.m_uiFrameRate;
<< d.m_uiHeight
<< d.m_iPelFormat
<< d.m_uiFrameRate;
}
return out;
@@ -72,12 +72,12 @@ Int findPlaYUVerStreamInfo( PlaYUVerStreamInfoVector array, QString filename )
}
VideoSubWindow::VideoSubWindow( QWidget * parent, Bool isModule ) :
SubWindowHandle( parent, SubWindowHandle::VIDEO_SUBWINDOW ),
m_pCurrStream( NULL ),
m_pcCurrFrame( NULL ),
m_pcReferenceSubWindow( NULL ),
m_bIsPlaying( false ),
m_bIsModule( isModule )
SubWindowHandle( parent, SubWindowHandle::VIDEO_SUBWINDOW ),
m_pCurrStream( NULL ),
m_pcCurrFrame( NULL ),
m_pcReferenceSubWindow( NULL ),
m_bIsPlaying( false ),
m_bIsModule( isModule )
{
setVisible( false );
@@ -343,11 +343,11 @@ Void VideoSubWindow::stop()
Void VideoSubWindow::normalSize()
{
Double factor = 1.0;
Double curFactor = getScaleFactor() ;
Double curFactor = getScaleFactor();
if( factor != curFactor )
{
Double usedScale;
usedScale = m_cViewArea->scaleZoomFactor( factor/curFactor, QPoint() );
usedScale = m_cViewArea->scaleZoomFactor( factor / curFactor, QPoint() );
adjustScrollBarByScale( usedScale, QPoint() );
}
}
@@ -358,22 +358,22 @@ Void VideoSubWindow::zoomToFit()
scaleView( getScrollSize() );
}
Void VideoSubWindow::zoomToFactor( Double factor , QPoint center )
Void VideoSubWindow::zoomToFactor( Double factor, QPoint center )
{
Double curFactor;
curFactor = getScaleFactor() ;
curFactor = getScaleFactor();
if( factor != curFactor )
{
Double usedScale;
usedScale = m_cViewArea->scaleZoomFactor( factor/curFactor, center );
usedScale = m_cViewArea->scaleZoomFactor( factor / curFactor, center );
adjustScrollBarByScale( usedScale, center );
}
}
Void VideoSubWindow::scaleView( Double scale , QPoint center )
Void VideoSubWindow::scaleView( Double scale, QPoint center )
{
Q_ASSERT( m_cViewArea->image() );
if(scale!=1.0)
if( scale != 1.0 )
{
Double usedScale;
usedScale = m_cViewArea->scaleZoomFactor( scale, center );
@@ -404,11 +404,11 @@ Void VideoSubWindow::scaleView( const QSize & size, QPoint center )
else
factor = hfactor;
Double curFactor = getScaleFactor() ;
Double curFactor = getScaleFactor();
if( factor != curFactor )
{
Double usedScale;
usedScale = m_cViewArea->scaleZoomFactor( factor/curFactor, center );
usedScale = m_cViewArea->scaleZoomFactor( factor / curFactor, center );
adjustScrollBarByScale( usedScale, center );
}
}
@@ -452,7 +452,6 @@ Void VideoSubWindow::updatePixelValueStatusBar( const QPoint& pos )
}
}
QSize VideoSubWindow::sizeHint() const
{
QSize maxSize; // The size of the parent (viewport widget
@@ -463,6 +462,10 @@ QSize VideoSubWindow::sizeHint() const
{
maxSize = p->size();
}
else
{
maxSize = QApplication::desktop()->availableGeometry().size();
}
QSize isize;
if( m_pcCurrFrame )
+12 -24
View File
@@ -39,6 +39,7 @@ plaYUVerApp::plaYUVerApp()
{
setWindowModality( Qt::ApplicationModal );
setWindowModality( Qt::NonModal );
// DBus
#ifdef USE_QTDBUS
@@ -138,13 +139,6 @@ Void plaYUVerApp::closeEvent( QCloseEvent *event )
}
}
Void plaYUVerApp::closeActiveWindow()
{
SubWindowHandle *currSubWindow = activeSubWindow();
m_appModuleVideo->closeSubWindow( qobject_cast<VideoSubWindow*>( currSubWindow ) );
m_pcWindowHandle->removeSubWindow( currSubWindow );
}
Void plaYUVerApp::closeAll()
{
m_pcWindowHandle->removeAllSubWindow();
@@ -163,7 +157,7 @@ Void plaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo )
m_pcWindowHandle->setActiveSubWindow( videoSubWindow );
return;
}
videoSubWindow = new VideoSubWindow( this ); //createSubWindow();
videoSubWindow = new VideoSubWindow; //createSubWindow();
SubWindowHandle *subWindow = videoSubWindow;
if( !pStreamInfo )
{
@@ -190,8 +184,8 @@ Void plaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo )
connect( subWindow, SIGNAL( updateStatusBar( const QString& ) ), this, SLOT( updateStatusBar( const QString& ) ) );
connect( subWindow, SIGNAL( zoomFactorChanged_SWindow( const double, const QPoint ) ), this, SLOT( updateZoomFactorSBox() ) );
connect( subWindow, SIGNAL( zoomFactorChanged_SWindow( const double, const QPoint ) ), this, SLOT( zoomToFactorAll( double, QPoint ) ) );
connect( subWindow, SIGNAL( scrollBarMoved_SWindow( const QPoint ) ), this, SLOT( moveAllScrollBars( const QPoint ) ) );
//connect( subWindow, SIGNAL( zoomFactorChanged_SWindow( const double, const QPoint ) ), this, SLOT( zoomToFactorAll( double, QPoint ) ) );
//connect( subWindow, SIGNAL( scrollBarMoved_SWindow( const QPoint ) ), this, SLOT( moveAllScrollBars( const QPoint ) ) );
videoSubWindow->zoomToFit();
videoSubWindow->getViewArea()->setTool( ( ViewArea::eTool )m_uiViewTool );
@@ -447,10 +441,11 @@ Void plaYUVerApp::scaleFrame( int ratio )
Void plaYUVerApp::zoomFromSBox( double zoom )
{
SubWindowHandle *activeSubWindow = m_pcWindowHandle->activeSubWindow();
Double factor = zoom / 100;
if( activeSubWindow() )
if( activeSubWindow )
{
activeSubWindow()->zoomToFactor( factor );
activeSubWindow->zoomToFactor( factor );
}
}
@@ -499,13 +494,6 @@ Void plaYUVerApp::dropEvent( QDropEvent *event )
// ----------------------- Sub Window Functions -----------------------
SubWindowHandle *plaYUVerApp::activeSubWindow()
{
if( SubWindowHandle *activeSubWindow = m_pcWindowHandle->activeSubWindow() )
return activeSubWindow;
return NULL;
}
VideoSubWindow* plaYUVerApp::findVideoStreamSubWindow( const PlaYUVerSubWindowHandle* windowManager, const QString& fileName )
{
QString canonicalFilePath = QFileInfo( fileName ).canonicalFilePath();
@@ -524,15 +512,15 @@ VideoSubWindow* plaYUVerApp::findVideoStreamSubWindow( const PlaYUVerSubWindowHa
Void plaYUVerApp::update()
{
SubWindowHandle *new_window = activeSubWindow();
SubWindowHandle *activeSubWindow = m_pcWindowHandle->activeSubWindow();
QCoreApplication::processEvents();
//if( activeSubWindow() != m_pcCurrentSubWindow )
{
m_pcCurrentSubWindow = NULL;
m_pcCurrentVideoSubWindow = NULL;
if( activeSubWindow() )
if( activeSubWindow )
{
m_pcCurrentSubWindow = new_window;
m_pcCurrentSubWindow = activeSubWindow;
switch( m_pcCurrentSubWindow->getCategory() )
{
@@ -572,7 +560,7 @@ Void plaYUVerApp::updateStatusBar( const QString& statusBarString )
Void plaYUVerApp::updateMenus()
{
Bool hasSubWindow = ( activeSubWindow() != 0 );
Bool hasSubWindow = ( m_pcWindowHandle->activeSubWindow() != 0 );
m_arrayMenu[RECENT_MENU]->setEnabled( m_aRecentFileStreamInfo.size() > 0 ? true : false );
@@ -650,7 +638,7 @@ Void plaYUVerApp::createActions()
m_arrayActions[CLOSE_ACT] = new QAction( tr( "&Close" ), this );
m_arrayActions[CLOSE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) );
m_arrayActions[CLOSE_ACT]->setStatusTip( tr( "Close the active window" ) );
connect( m_arrayActions[CLOSE_ACT], SIGNAL( triggered() ), this, SLOT( closeActiveWindow() ) );
connect( m_arrayActions[CLOSE_ACT], SIGNAL( triggered() ), m_pcWindowHandle, SLOT( removeActiveSubWindow() ) );
m_arrayActions[CLOSEALL_ACT] = new QAction( tr( "Close &All" ), this );
m_arrayActions[CLOSEALL_ACT]->setStatusTip( tr( "Close all the windows" ) );
-2
View File
@@ -76,7 +76,6 @@ private Q_SLOTS:
void reload();
void reloadAll();
void loadAll();
void closeActiveWindow();
void closeAll();
/**
@@ -114,7 +113,6 @@ private:
QString m_cLastOpenPath;
SubWindowHandle *activeSubWindow();
static VideoSubWindow* findVideoStreamSubWindow( const PlaYUVerSubWindowHandle* windowManager, const QString& fileName );
Void updateMenus();