Move scroll area into VideoSubWindow
This commit is contained in:
+13
-103
@@ -26,6 +26,7 @@
|
||||
#include <QCloseEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QIcon>
|
||||
#include <QHBoxLayout>
|
||||
#include "SubWindowAbstract.h"
|
||||
#include "PlaYUVerMdiSubWindow.h"
|
||||
|
||||
@@ -33,7 +34,7 @@ namespace plaYUVer
|
||||
{
|
||||
|
||||
SubWindowAbstract::SubWindowAbstract( QWidget * parent, UInt category ) :
|
||||
QScrollArea( parent ),
|
||||
QWidget( parent ),
|
||||
m_cSubWindow( NULL )
|
||||
{
|
||||
setParent( parent );
|
||||
@@ -44,22 +45,12 @@ SubWindowAbstract::SubWindowAbstract( QWidget * parent, UInt category ) :
|
||||
|
||||
setWindowIcon( QIcon( ":/images/playuver.png" ) );
|
||||
|
||||
// Create a new scroll area inside the sub-window
|
||||
connect( horizontalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateCurScrollValues() ) );
|
||||
connect( verticalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateCurScrollValues() ) );
|
||||
|
||||
setWidgetResizable( true );
|
||||
|
||||
//setWidgetResizable( true );
|
||||
m_pcLayout = NULL;
|
||||
m_uiCategory = category;
|
||||
m_cLastScroll = QPoint();
|
||||
m_cWindowName = QString( " " );
|
||||
|
||||
connect(this, SIGNAL(destroyed()), this, SLOT(onDestroyed()));
|
||||
}
|
||||
|
||||
void SubWindowAbstract::onDestroyed()
|
||||
{
|
||||
return;
|
||||
connect( this, SIGNAL( destroyed() ), this, SLOT( onDestroyed() ) );
|
||||
}
|
||||
|
||||
SubWindowAbstract::~SubWindowAbstract()
|
||||
@@ -67,98 +58,17 @@ SubWindowAbstract::~SubWindowAbstract()
|
||||
return;
|
||||
}
|
||||
|
||||
QSize SubWindowAbstract::getScrollSize()
|
||||
Void SubWindowAbstract::setWidget( QWidget* widget )
|
||||
{
|
||||
return QSize( viewport()->size().width() - 5, viewport()->size().height() - 5 );
|
||||
if( !m_pcLayout )
|
||||
m_pcLayout = new QHBoxLayout( this );
|
||||
|
||||
m_pcLayout->addWidget( widget );
|
||||
}
|
||||
|
||||
Void SubWindowAbstract::adjustScrollBarByOffset( QPoint Offset )
|
||||
void SubWindowAbstract::onDestroyed()
|
||||
{
|
||||
QPoint cLastScroll = m_cCurrScroll;
|
||||
QScrollBar *scrollBarH, *scrollBarV;
|
||||
Int valueX, valueY;
|
||||
|
||||
valueX = int( cLastScroll.x() + Offset.x() );
|
||||
valueY = int( cLastScroll.y() + Offset.y() );
|
||||
|
||||
scrollBarH = horizontalScrollBar();
|
||||
if( valueX > scrollBarH->maximum() )
|
||||
valueX = scrollBarH->maximum();
|
||||
if( valueX < scrollBarH->minimum() )
|
||||
valueX = scrollBarH->minimum();
|
||||
m_cCurrScroll.setX(valueX);
|
||||
|
||||
scrollBarV = verticalScrollBar();
|
||||
if( valueY > scrollBarV->maximum() )
|
||||
valueY = scrollBarV->maximum();
|
||||
if( valueY < scrollBarV->minimum() )
|
||||
valueY = scrollBarV->minimum();
|
||||
m_cCurrScroll.setY( valueY );
|
||||
|
||||
// Update window scroll
|
||||
scrollBarH->setValue( m_cCurrScroll.x() );
|
||||
scrollBarV->setValue( m_cCurrScroll.y() );
|
||||
}
|
||||
|
||||
// This function was developed with help of the schematics presented in
|
||||
// http://stackoverflow.com/questions/13155382/jscrollpane-zoom-relative-to-mouse-position
|
||||
Void SubWindowAbstract::adjustScrollBarByScale( Double scale, QPoint center )
|
||||
{
|
||||
QPoint cLastScroll = m_cCurrScroll;
|
||||
QScrollBar *scrollBarH, *scrollBarV;
|
||||
|
||||
scrollBarH = horizontalScrollBar();
|
||||
if( center.isNull() )
|
||||
{
|
||||
m_cCurrScroll.setX(int( scale * cLastScroll.x() + ( ( scale - 1 ) * scrollBarH->pageStep() / 2 ) ));
|
||||
}
|
||||
else
|
||||
{
|
||||
Int x = center.x() - cLastScroll.x();
|
||||
Int value = int( scale * cLastScroll.x() + ( ( scale - 1 ) * x ) );
|
||||
if( value > scrollBarH->maximum() )
|
||||
value = scrollBarH->maximum();
|
||||
if( value < scrollBarH->minimum() )
|
||||
value = scrollBarH->minimum();
|
||||
m_cCurrScroll.setX(value);
|
||||
}
|
||||
|
||||
scrollBarV = verticalScrollBar();
|
||||
if( center.isNull() )
|
||||
{
|
||||
m_cCurrScroll.setY(int( scale * cLastScroll.y() + ( ( scale - 1 ) * scrollBarV->pageStep() / 2 ) ));
|
||||
}
|
||||
else
|
||||
{
|
||||
Int y = center.y() - cLastScroll.y();
|
||||
Int value = int( scale * cLastScroll.y() + ( ( scale - 1 ) * y ) );
|
||||
if( value > scrollBarV->maximum() )
|
||||
value = scrollBarV->maximum();
|
||||
if( value < scrollBarV->minimum() )
|
||||
value = scrollBarV->minimum();
|
||||
m_cCurrScroll.setY(value);
|
||||
}
|
||||
|
||||
// Update window scroll
|
||||
scrollBarH->setValue( m_cCurrScroll.x() );
|
||||
scrollBarV->setValue( m_cCurrScroll.y() );
|
||||
|
||||
}
|
||||
|
||||
Void SubWindowAbstract::updateCurScrollValues()
|
||||
{
|
||||
QScrollBar *scrollBar = horizontalScrollBar();
|
||||
m_cCurrScroll.setX( scrollBar->value() );
|
||||
scrollBar = verticalScrollBar();
|
||||
m_cCurrScroll.setY( scrollBar->value() );
|
||||
}
|
||||
|
||||
Void SubWindowAbstract::setCurScrollValues()
|
||||
{
|
||||
QScrollBar *scrollBar = horizontalScrollBar();
|
||||
scrollBar->setValue(m_cCurrScroll.x() );
|
||||
scrollBar = verticalScrollBar();
|
||||
scrollBar->setValue(m_cCurrScroll.y() );
|
||||
return;
|
||||
}
|
||||
|
||||
Void SubWindowAbstract::setWindowName( QString name )
|
||||
@@ -177,7 +87,7 @@ Bool SubWindowAbstract::mayClose()
|
||||
return true;
|
||||
}
|
||||
|
||||
QSize SubWindowAbstract::sizeHint( ) const
|
||||
QSize SubWindowAbstract::sizeHint() const
|
||||
{
|
||||
return QSize();
|
||||
}
|
||||
|
||||
+6
-10
@@ -39,11 +39,12 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "PlaYUVerAppDefs.h"
|
||||
#include <QScrollArea>
|
||||
#include <QWidget>
|
||||
#include <QString>
|
||||
#include <QPoint>
|
||||
#include <QSize>
|
||||
|
||||
class QHBoxLayout;
|
||||
class QFocusEvent;
|
||||
class QCloseEvent;
|
||||
|
||||
@@ -52,14 +53,12 @@ namespace plaYUVer
|
||||
|
||||
class PlaYUVerMdiSubWindow;
|
||||
|
||||
class SubWindowAbstract: public QScrollArea
|
||||
class SubWindowAbstract: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QPoint m_cLastScroll;
|
||||
QPoint m_cCurrScroll;
|
||||
|
||||
QHBoxLayout* m_pcLayout;
|
||||
UInt m_uiCategory;
|
||||
QString m_cWindowName;
|
||||
|
||||
@@ -156,7 +155,8 @@ public:
|
||||
protected:
|
||||
void focusInEvent( QFocusEvent* event );
|
||||
void closeEvent( QCloseEvent* event );
|
||||
QSize getScrollSize();
|
||||
|
||||
Void setWidget( QWidget* widget );
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
@@ -177,10 +177,6 @@ Q_SIGNALS:
|
||||
|
||||
public Q_SLOTS:
|
||||
void onDestroyed();
|
||||
void adjustScrollBarByScale( double scale, QPoint center );
|
||||
void adjustScrollBarByOffset( QPoint Offset );
|
||||
void updateCurScrollValues();
|
||||
void setCurScrollValues();
|
||||
|
||||
};
|
||||
|
||||
|
||||
+6
-6
@@ -332,11 +332,11 @@ Void VideoHandle::moveAllScrollBars( const QPoint offset )
|
||||
QPoint newOffset = offset;
|
||||
if( m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->isChecked() )
|
||||
{
|
||||
SubWindowAbstract *subWindow;
|
||||
VideoSubWindow *videoSubWindow;
|
||||
QList<SubWindowAbstract*> subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW );
|
||||
|
||||
QScrollBar *scrollBar;
|
||||
scrollBar = m_pcCurrentVideoSubWindow->horizontalScrollBar();
|
||||
scrollBar = m_pcCurrentVideoSubWindow->getScroll()->horizontalScrollBar();
|
||||
|
||||
// Do not move other images, if current image reached maximum or minimum scroll position
|
||||
if( scrollBar->value() == scrollBar->maximum() && offset.x() > 0 )
|
||||
@@ -344,7 +344,7 @@ Void VideoHandle::moveAllScrollBars( const QPoint offset )
|
||||
if( scrollBar->value() == scrollBar->minimum() && offset.x() < 0 )
|
||||
newOffset.setX( 0 );
|
||||
|
||||
scrollBar = m_pcCurrentVideoSubWindow->verticalScrollBar();
|
||||
scrollBar = m_pcCurrentVideoSubWindow->getScroll()->verticalScrollBar();
|
||||
if( scrollBar->value() == scrollBar->maximum() && offset.y() > 0 )
|
||||
newOffset.setY( 0 );
|
||||
if( scrollBar->value() == scrollBar->minimum() && offset.y() < 0 )
|
||||
@@ -352,12 +352,12 @@ Void VideoHandle::moveAllScrollBars( const QPoint offset )
|
||||
|
||||
for( Int i = 0; i < subWindowList.size(); i++ )
|
||||
{
|
||||
subWindow = subWindowList.at( i );
|
||||
if( m_pcCurrentVideoSubWindow == subWindow )
|
||||
videoSubWindow = qobject_cast<VideoSubWindow *>( subWindowList.at( i ) );
|
||||
if( m_pcCurrentVideoSubWindow == videoSubWindow )
|
||||
continue;
|
||||
else
|
||||
{
|
||||
subWindow->adjustScrollBarByOffset( newOffset );
|
||||
videoSubWindow->adjustScrollBarByOffset( newOffset );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+127
-15
@@ -26,6 +26,7 @@
|
||||
#include "ModulesHandle.h"
|
||||
#include "ConfigureFormatDialog.h"
|
||||
#include "SubWindowAbstract.h"
|
||||
#include <QScrollArea>
|
||||
#if( QT_VERSION_PLAYUVER == 5 )
|
||||
#include "QtConcurrent/qtconcurrentrun.h"
|
||||
#endif
|
||||
@@ -87,6 +88,13 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget
|
||||
m_bIsModule( category == MODULE_SUBWINDOW )
|
||||
{
|
||||
|
||||
// Create a new scroll area inside the sub-window
|
||||
m_pcScrollArea = new QScrollArea;
|
||||
connect( m_pcScrollArea->horizontalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateCurScrollValues() ) );
|
||||
connect( m_pcScrollArea->verticalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateCurScrollValues() ) );
|
||||
|
||||
m_cLastScroll = QPoint();
|
||||
|
||||
// Create a new interface to show images
|
||||
m_cViewArea = new ViewArea( this );
|
||||
connect( m_cViewArea, SIGNAL( zoomFactorChanged_byWheel( double , QPoint) ), this, SLOT( adjustScrollBarByScale( double, QPoint ) ) );
|
||||
@@ -98,12 +106,15 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget
|
||||
connect( m_cViewArea, SIGNAL( selectionChanged( QRect ) ), this, SLOT( updateSelectedArea( QRect ) ) );
|
||||
connect( m_cViewArea, SIGNAL( positionChanged( const QPoint & ) ), this, SLOT( updatePixelValueStatusBar( const QPoint & ) ) );
|
||||
|
||||
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||
setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||
m_pcScrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||
m_pcScrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||
|
||||
// Define the cViewArea as the widget inside the scroll area
|
||||
m_cViewArea->setMinimumSize( size() );
|
||||
setWidget( m_cViewArea );
|
||||
|
||||
m_pcScrollArea->setWidget( m_cViewArea );
|
||||
|
||||
setWidget( m_pcScrollArea );
|
||||
|
||||
m_apcCurrentModule.clear();
|
||||
|
||||
@@ -229,7 +240,7 @@ Bool VideoSubWindow::loadFile( PlaYUVerStreamInfo* streamInfo )
|
||||
Void VideoSubWindow::updateVideoWindowInfo()
|
||||
{
|
||||
m_cStreamInformation = "";
|
||||
if( m_bIsModule )
|
||||
if( m_pcCurrentDisplayModule )
|
||||
{
|
||||
m_cStreamInformation = "Module";
|
||||
}
|
||||
@@ -425,7 +436,8 @@ Void VideoSubWindow::setCurrFrame( PlaYUVerFrame* pcCurrFrame )
|
||||
}
|
||||
}
|
||||
|
||||
Void VideoSubWindow::refreshFrameOperation()
|
||||
Void VideoSubWindow::paintEvent( QPaintEvent *event )
|
||||
//Void VideoSubWindow::refreshFrameOperation()
|
||||
{
|
||||
Bool bSetFrame = false;
|
||||
if( m_pCurrStream )
|
||||
@@ -446,20 +458,26 @@ Void VideoSubWindow::refreshFrameOperation()
|
||||
{
|
||||
ModulesHandle::applyModuleIf( m_apcCurrentModule.at( i ), m_bIsPlaying );
|
||||
}
|
||||
//m_cViewArea->update();
|
||||
m_pcScrollArea->update();
|
||||
// QPainter p( this );
|
||||
// p.setPen( QColor( "red" ) );
|
||||
// p.drawLine( 0, 0, width(), height() );
|
||||
}
|
||||
|
||||
Void VideoSubWindow::refreshFrame( Bool bThreaded )
|
||||
{
|
||||
#ifndef QT_NO_CONCURRENT
|
||||
m_cRefreshResult.waitForFinished();
|
||||
if( bThreaded )
|
||||
//#ifndef QT_NO_CONCURRENT
|
||||
// m_cRefreshResult.waitForFinished();
|
||||
// if( bThreaded )
|
||||
// {
|
||||
// m_cRefreshResult = QtConcurrent::run( this, &VideoSubWindow::refreshFrameOperation );
|
||||
// }
|
||||
// else
|
||||
//#endif
|
||||
{
|
||||
m_cRefreshResult = QtConcurrent::run( this, &VideoSubWindow::refreshFrameOperation );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
refreshFrameOperation();
|
||||
//refreshFrameOperation();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,6 +571,100 @@ Void VideoSubWindow::stop()
|
||||
return;
|
||||
}
|
||||
|
||||
QSize VideoSubWindow::getScrollSize()
|
||||
{
|
||||
return QSize( m_pcScrollArea->viewport()->size().width() - 5, m_pcScrollArea->viewport()->size().height() - 5 );
|
||||
}
|
||||
|
||||
Void VideoSubWindow::adjustScrollBarByOffset( QPoint Offset )
|
||||
{
|
||||
QPoint cLastScroll = m_cCurrScroll;
|
||||
QScrollBar *scrollBarH, *scrollBarV;
|
||||
Int valueX, valueY;
|
||||
|
||||
valueX = int( cLastScroll.x() + Offset.x() );
|
||||
valueY = int( cLastScroll.y() + Offset.y() );
|
||||
|
||||
scrollBarH = m_pcScrollArea->horizontalScrollBar();
|
||||
if( valueX > scrollBarH->maximum() )
|
||||
valueX = scrollBarH->maximum();
|
||||
if( valueX < scrollBarH->minimum() )
|
||||
valueX = scrollBarH->minimum();
|
||||
m_cCurrScroll.setX( valueX );
|
||||
|
||||
scrollBarV = m_pcScrollArea->verticalScrollBar();
|
||||
if( valueY > scrollBarV->maximum() )
|
||||
valueY = scrollBarV->maximum();
|
||||
if( valueY < scrollBarV->minimum() )
|
||||
valueY = scrollBarV->minimum();
|
||||
m_cCurrScroll.setY( valueY );
|
||||
|
||||
// Update window scroll
|
||||
scrollBarH->setValue( m_cCurrScroll.x() );
|
||||
scrollBarV->setValue( m_cCurrScroll.y() );
|
||||
}
|
||||
|
||||
// This function was developed with help of the schematics presented in
|
||||
// http://stackoverflow.com/questions/13155382/jscrollpane-zoom-relative-to-mouse-position
|
||||
Void VideoSubWindow::adjustScrollBarByScale( Double scale, QPoint center )
|
||||
{
|
||||
QPoint cLastScroll = m_cCurrScroll;
|
||||
QScrollBar *scrollBarH, *scrollBarV;
|
||||
|
||||
scrollBarH = m_pcScrollArea->horizontalScrollBar();
|
||||
if( center.isNull() )
|
||||
{
|
||||
m_cCurrScroll.setX( int( scale * cLastScroll.x() + ( ( scale - 1 ) * scrollBarH->pageStep() / 2 ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Int x = center.x() - cLastScroll.x();
|
||||
Int value = int( scale * cLastScroll.x() + ( ( scale - 1 ) * x ) );
|
||||
if( value > scrollBarH->maximum() )
|
||||
value = scrollBarH->maximum();
|
||||
if( value < scrollBarH->minimum() )
|
||||
value = scrollBarH->minimum();
|
||||
m_cCurrScroll.setX( value );
|
||||
}
|
||||
|
||||
scrollBarV = m_pcScrollArea->verticalScrollBar();
|
||||
if( center.isNull() )
|
||||
{
|
||||
m_cCurrScroll.setY( int( scale * cLastScroll.y() + ( ( scale - 1 ) * scrollBarV->pageStep() / 2 ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Int y = center.y() - cLastScroll.y();
|
||||
Int value = int( scale * cLastScroll.y() + ( ( scale - 1 ) * y ) );
|
||||
if( value > scrollBarV->maximum() )
|
||||
value = scrollBarV->maximum();
|
||||
if( value < scrollBarV->minimum() )
|
||||
value = scrollBarV->minimum();
|
||||
m_cCurrScroll.setY( value );
|
||||
}
|
||||
|
||||
// Update window scroll
|
||||
scrollBarH->setValue( m_cCurrScroll.x() );
|
||||
scrollBarV->setValue( m_cCurrScroll.y() );
|
||||
|
||||
}
|
||||
|
||||
Void VideoSubWindow::updateCurScrollValues()
|
||||
{
|
||||
QScrollBar *scrollBar = m_pcScrollArea->horizontalScrollBar();
|
||||
m_cCurrScroll.setX( scrollBar->value() );
|
||||
scrollBar = m_pcScrollArea->verticalScrollBar();
|
||||
m_cCurrScroll.setY( scrollBar->value() );
|
||||
}
|
||||
|
||||
Void VideoSubWindow::setCurScrollValues()
|
||||
{
|
||||
QScrollBar *scrollBar = m_pcScrollArea->horizontalScrollBar();
|
||||
scrollBar->setValue( m_cCurrScroll.x() );
|
||||
scrollBar = m_pcScrollArea->verticalScrollBar();
|
||||
scrollBar->setValue( m_cCurrScroll.y() );
|
||||
}
|
||||
|
||||
Void VideoSubWindow::normalSize()
|
||||
{
|
||||
Double factor = 1.0;
|
||||
@@ -711,4 +823,4 @@ QSize VideoSubWindow::sizeHint( const QSize & maxSize ) const
|
||||
// }
|
||||
//}
|
||||
|
||||
} // NAMESPACE
|
||||
}// NAMESPACE
|
||||
|
||||
+19
-1
@@ -36,6 +36,8 @@
|
||||
#include "SubWindowAbstract.h"
|
||||
#include "ViewArea.h"
|
||||
|
||||
class QScrollArea;
|
||||
|
||||
namespace plaYUVer
|
||||
{
|
||||
|
||||
@@ -64,6 +66,10 @@ Q_OBJECT
|
||||
|
||||
private:
|
||||
|
||||
QScrollArea* m_pcScrollArea;
|
||||
QPoint m_cLastScroll;
|
||||
QPoint m_cCurrScroll;
|
||||
|
||||
ViewArea* m_cViewArea;
|
||||
|
||||
QString m_cFilename;
|
||||
@@ -102,9 +108,13 @@ private:
|
||||
* zoom to fit
|
||||
*/
|
||||
Void scaleView( const QSize & size, QPoint center = QPoint() );
|
||||
|
||||
Void updateVideoWindowInfo();
|
||||
|
||||
QSize getScrollSize();
|
||||
|
||||
protected:
|
||||
Void paintEvent( QPaintEvent *event );
|
||||
|
||||
public:
|
||||
enum VideoSubWindowCategories
|
||||
{
|
||||
@@ -136,6 +146,10 @@ public:
|
||||
|
||||
Void setCurrFrame( PlaYUVerFrame* pcCurrFrame );
|
||||
|
||||
QScrollArea* getScroll()
|
||||
{
|
||||
return m_pcScrollArea;
|
||||
}
|
||||
PlaYUVerStreamInfo getStreamInfo()
|
||||
{
|
||||
return m_sStreamInfo;
|
||||
@@ -241,6 +255,10 @@ public:
|
||||
//void closeEvent( QCloseEvent *event );
|
||||
|
||||
public Q_SLOTS:
|
||||
void adjustScrollBarByScale( double scale, QPoint center );
|
||||
void adjustScrollBarByOffset( QPoint Offset );
|
||||
void updateCurScrollValues();
|
||||
void setCurScrollValues();
|
||||
void updateSelectedArea( QRect area );
|
||||
void updatePixelValueStatusBar( const QPoint& pos );
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user