Some fixes on zoom and scroll functions, when image windows are overlapped
This commit is contained in:
1 parent
9b6af060c7
commit
2b68739d5a
4 files changed
+55
-25
No files matched your search
+42
-21
@@ -39,8 +39,8 @@ SubWindowHandle::SubWindowHandle( 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( updateLastScrollValue() ) );
|
||||
connect( verticalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateLastScrollValue() ) );
|
||||
connect( horizontalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateCurScrollValue() ) );
|
||||
connect( verticalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateCurScrollValue() ) );
|
||||
|
||||
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||
setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||
@@ -71,60 +71,81 @@ QSize SubWindowHandle::getScrollSize()
|
||||
|
||||
Void SubWindowHandle::adjustScrollBarByOffset( QPoint Offset )
|
||||
{
|
||||
QScrollBar *scrollBar = horizontalScrollBar();
|
||||
scrollBar->setValue( int( scrollBar->value() + Offset.x() ) );
|
||||
m_cLastScroll.setX( scrollBar->value() );
|
||||
scrollBar = verticalScrollBar();
|
||||
scrollBar->setValue( int( scrollBar->value() + Offset.y() ) );
|
||||
m_cLastScroll.setY( scrollBar->value() );
|
||||
updateLastScrollValue();
|
||||
QPoint cLastScroll = m_cCurrScroll;
|
||||
m_cCurrScroll.setX(int( cLastScroll.x() + Offset.x() ));
|
||||
m_cCurrScroll.setY(int( cLastScroll.y() + Offset.y() ));
|
||||
|
||||
if(!widget()->visibleRegion().isEmpty())
|
||||
{
|
||||
QScrollBar *scrollBar = horizontalScrollBar();
|
||||
scrollBar->setValue( m_cCurrScroll.x() );
|
||||
scrollBar = verticalScrollBar();
|
||||
scrollBar->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 SubWindowHandle::adjustScrollBarByScale( Double scale, QPoint center )
|
||||
{
|
||||
QPoint cLastScroll = m_cCurrScroll;
|
||||
QScrollBar *scrollBar = horizontalScrollBar();
|
||||
if( center.isNull() )
|
||||
{
|
||||
scrollBar->setValue( int( scale * scrollBar->value() + ( ( scale - 1 ) * scrollBar->pageStep() / 2 ) ) );
|
||||
m_cCurrScroll.setX(int( scale * cLastScroll.x() + ( ( scale - 1 ) * scrollBar->pageStep() / 2 ) ));
|
||||
}
|
||||
else
|
||||
{
|
||||
Int x = center.x() - m_cLastScroll.x();
|
||||
Int value = int( scale * m_cLastScroll.x() + ( ( scale - 1 ) * x ) );
|
||||
Int x = center.x() - cLastScroll.x();
|
||||
Int value = int( scale * cLastScroll.x() + ( ( scale - 1 ) * x ) );
|
||||
if( value > scrollBar->maximum() )
|
||||
value = scrollBar->maximum();
|
||||
if( value < scrollBar->minimum() )
|
||||
value = scrollBar->minimum();
|
||||
scrollBar->setValue( value );
|
||||
m_cCurrScroll.setX(value);
|
||||
}
|
||||
|
||||
scrollBar = verticalScrollBar();
|
||||
if( center.isNull() )
|
||||
{
|
||||
scrollBar->setValue( int( scale * scrollBar->value() + ( ( scale - 1 ) * scrollBar->pageStep() / 2 ) ) );
|
||||
m_cCurrScroll.setY(int( scale * cLastScroll.y() + ( ( scale - 1 ) * scrollBar->pageStep() / 2 ) ));
|
||||
}
|
||||
else
|
||||
{
|
||||
Int y = center.y() - m_cLastScroll.y();
|
||||
Int value = int( scale * m_cLastScroll.y() + ( ( scale - 1 ) * y ) );
|
||||
Int y = center.y() - cLastScroll.y();
|
||||
Int value = int( scale * cLastScroll.y() + ( ( scale - 1 ) * y ) );
|
||||
if( value > scrollBar->maximum() )
|
||||
value = scrollBar->maximum();
|
||||
if( value < scrollBar->minimum() )
|
||||
value = scrollBar->minimum();
|
||||
scrollBar->setValue( value );
|
||||
m_cCurrScroll.setY(value);
|
||||
}
|
||||
|
||||
updateLastScrollValue();
|
||||
if(!widget()->visibleRegion().isEmpty())
|
||||
{
|
||||
scrollBar = horizontalScrollBar();
|
||||
scrollBar->setValue( m_cCurrScroll.x() );
|
||||
scrollBar = verticalScrollBar();
|
||||
scrollBar->setValue( m_cCurrScroll.y() );
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
Void SubWindowHandle::updateLastScrollValue()
|
||||
Void SubWindowHandle::updateCurScrollValue()
|
||||
{
|
||||
QScrollBar *scrollBar = horizontalScrollBar();
|
||||
m_cLastScroll.setX( scrollBar->value() );
|
||||
m_cCurrScroll.setX( scrollBar->value() );
|
||||
scrollBar = verticalScrollBar();
|
||||
m_cLastScroll.setY( scrollBar->value() );
|
||||
m_cCurrScroll.setY( scrollBar->value() );
|
||||
}
|
||||
|
||||
Void SubWindowHandle::setCurScrollValues()
|
||||
{
|
||||
QScrollBar *scrollBar = horizontalScrollBar();
|
||||
scrollBar->setValue(m_cCurrScroll.x() );
|
||||
scrollBar = verticalScrollBar();
|
||||
scrollBar->setValue(m_cCurrScroll.y() );
|
||||
}
|
||||
|
||||
Void SubWindowHandle::setWindowName( QString name )
|
||||
|
||||
@@ -44,6 +44,7 @@ Q_OBJECT
|
||||
|
||||
private:
|
||||
QPoint m_cLastScroll;
|
||||
QPoint m_cCurrScroll;
|
||||
|
||||
UInt m_uiCategory;
|
||||
QString m_cWindowName;
|
||||
@@ -134,10 +135,11 @@ Q_SIGNALS:
|
||||
void aboutToClose( SubWindowHandle* );
|
||||
|
||||
public Q_SLOTS:
|
||||
void onDestroyed();
|
||||
void onDestroyed();
|
||||
void adjustScrollBarByScale( double scale, QPoint center );
|
||||
void adjustScrollBarByOffset( QPoint Offset );
|
||||
void updateLastScrollValue();
|
||||
void updateCurScrollValue();
|
||||
void setCurScrollValues();
|
||||
|
||||
};
|
||||
|
||||
|
||||
+6
-2
@@ -314,13 +314,17 @@ Void VideoHandle::moveAllScrollBars( const QPoint offset )
|
||||
{
|
||||
if( m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->isChecked() )
|
||||
{
|
||||
SubWindowHandle *subWindow;
|
||||
QList<SubWindowHandle*> subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowHandle::VIDEO_SUBWINDOW );
|
||||
for( Int i = 0; i < subWindowList.size(); i++ )
|
||||
{
|
||||
if( m_pcCurrentVideoSubWindow == subWindowList.at( i ) )
|
||||
subWindow = subWindowList.at( i );
|
||||
if( m_pcCurrentVideoSubWindow == subWindow )
|
||||
continue;
|
||||
else
|
||||
subWindowList.at( i )->adjustScrollBarByOffset( offset );
|
||||
{
|
||||
subWindow->adjustScrollBarByOffset( offset );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,6 +331,9 @@ void ViewArea::paintEvent( QPaintEvent *event )
|
||||
{
|
||||
QRect winRect = event->rect();
|
||||
|
||||
if(visibleRegion().isEmpty())
|
||||
return;
|
||||
|
||||
if( size().isEmpty() || m_pixmap.isNull() )
|
||||
return;
|
||||
|
||||
|
||||
Reference in new issue
Block a user