Add option to enable and disable grid

This commit is contained in:
2015-11-08 20:04:16 +00:00
parent b46019acc9
commit e32dc61f93
6 changed files with 69 additions and 69 deletions
-4
View File
@@ -70,10 +70,6 @@ public:
}
Void setTool( UInt uiTool )
{
}
/**
* Virtual functions from SubWindowAbstract
*/
+11 -7
View File
@@ -160,7 +160,7 @@ Void VideoHandle::createActions()
m_arrayActions[SHOW_GRID_ACT] = new QAction( "Show grid", this );
m_arrayActions[SHOW_GRID_ACT]->setCheckable( true );
m_arrayActions[SHOW_GRID_ACT]->setChecked( false );
connect( m_arrayActions[SHOW_GRID_ACT], SIGNAL( triggered() ), this, SLOT( toogleGrid() ) );
connect( m_arrayActions[SHOW_GRID_ACT], SIGNAL( toggled(bool) ), this, SLOT( toggleGrid(bool) ) );
}
QMenu* VideoHandle::createVideoMenu()
@@ -183,9 +183,9 @@ QMenu* VideoHandle::createImageMenu()
m_pcMenuImage = new QMenu( "Image", this );
m_pcMenuImage->addAction( m_arrayActions[NAVIGATION_TOOL_ACT] );
m_pcMenuImage->addAction( m_arrayActions[SELECTION_TOOL_ACT] );
//m_pcMenuImage->addAction( m_arrayActions[BLOCK_SELECTION_TOOL_ACT] );
//m_pcMenuImage->addSeparator();
//m_pcMenuImage->addAction( m_arrayActions[SHOW_GRID_ACT] );
m_pcMenuImage->addAction( m_arrayActions[BLOCK_SELECTION_TOOL_ACT] );
m_pcMenuImage->addSeparator();
m_pcMenuImage->addAction( m_arrayActions[SHOW_GRID_ACT] );
return m_pcMenuImage;
}
@@ -762,13 +762,17 @@ Void VideoHandle::setTool( Int tool )
QList<SubWindowAbstract*> subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW );
for( Int i = 0; i < subWindowList.size(); i++ )
{
qobject_cast<VideoSubWindow*>( subWindowList.at( i ) )->setTool( m_uiViewTool );
qobject_cast<VideoSubWindow*>( subWindowList.at( i ) )->getViewArea()->setTool( m_uiViewTool );
}
}
Void VideoHandle::toggleGrid()
Void VideoHandle::toggleGrid( Bool checked )
{
QList<SubWindowAbstract*> subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW );
for( Int i = 0; i < subWindowList.size(); i++ )
{
qobject_cast<VideoSubWindow*>( subWindowList.at( i ) )->getViewArea()->setGridVisible( checked );
}
}
} // NAMESPACE
+1 -1
View File
@@ -146,7 +146,7 @@ private Q_SLOTS:
void seekVideo();
void videoSelectionButtonEvent();
void setTool( int tool );
void toggleGrid();
void toggleGrid( bool checked );
};
-5
View File
@@ -211,11 +211,6 @@ public:
return apcModulesArray;
}
Void setTool( UInt uiTool )
{
m_cViewArea->setTool( uiTool );
}
/**
* Virtual functions from SubWindowAbstract
*/
+44 -45
View File
@@ -56,12 +56,12 @@ ViewArea::ViewArea( QWidget *parent ) :
m_grid = GridManager();
m_mask = QBitmap();
m_selectedArea = QRect();
m_zoomFactor = 1;
m_dZoomFactor = 1;
m_xOffset = 0;
m_yOffset = 0;
m_mode = NormalMode;
m_eTool = NavigationTool;
m_gridVisible = false;
m_bGridVisible = false;
m_snapToGrid = false;
m_blockTrackEnable = false;
m_visibleZoomRect = true;
@@ -129,6 +129,12 @@ Void ViewArea::setTool( UInt view )
update();
}
Void ViewArea::setGridVisible( Bool enable )
{
m_bGridVisible = enable;
update();
}
Void ViewArea::clearMask()
{
m_mask.clear();
@@ -144,7 +150,7 @@ Void ViewArea::startZoomWinTimer()
Void ViewArea::setZoomFactor( Double f )
{
m_zoomFactor = f;
m_dZoomFactor = f;
updateSize();
startZoomWinTimer();
@@ -157,21 +163,21 @@ Double ViewArea::scaleZoomFactor( Double scale, QPoint center, QSize minimumSize
Double minZoom = 0.01; //( 1.0 / m_pixmap.width() );
Double new_scale = 1.0;
if( ( m_zoomFactor == minZoom ) && ( scale < 1 ) )
if( ( m_dZoomFactor == minZoom ) && ( scale < 1 ) )
return new_scale;
if( ( m_zoomFactor == maxZoom ) && ( scale > 1 ) )
if( ( m_dZoomFactor == maxZoom ) && ( scale > 1 ) )
return new_scale;
Double zoomFactor = m_zoomFactor * scale * 100.0;
Double zoomFactor = m_dZoomFactor * scale * 100.0;
zoomFactor = round( zoomFactor );
zoomFactor = zoomFactor / 100.0;
scale = zoomFactor / m_zoomFactor;
scale = zoomFactor / m_dZoomFactor;
if( !minimumSize.isNull() )
{
Double cw = m_pixmap.width() * m_zoomFactor;
Double ch = m_pixmap.height() * m_zoomFactor;
Double cw = m_pixmap.width() * m_dZoomFactor;
Double ch = m_pixmap.height() * m_dZoomFactor;
Double fw = m_pixmap.width() * zoomFactor;
Double fh = m_pixmap.height() * zoomFactor;
Double mw = minimumSize.width();
@@ -195,7 +201,7 @@ Double ViewArea::scaleZoomFactor( Double scale, QPoint center, QSize minimumSize
zoomFactor = zoomFactor * scale * 100.0;
zoomFactor = floor( zoomFactor );
zoomFactor = zoomFactor / 100.0;
scale = zoomFactor / m_zoomFactor;
scale = zoomFactor / m_dZoomFactor;
}
}
@@ -204,14 +210,14 @@ Double ViewArea::scaleZoomFactor( Double scale, QPoint center, QSize minimumSize
if( zoomFactor < minZoom )
{
zoomFactor = minZoom;
new_scale = zoomFactor / m_zoomFactor;
new_scale = zoomFactor / m_dZoomFactor;
}
else
{
if( zoomFactor > maxZoom )
{
zoomFactor = maxZoom;
new_scale = zoomFactor / m_zoomFactor;
new_scale = zoomFactor / m_dZoomFactor;
}
}
@@ -273,12 +279,6 @@ Double ViewArea::scaleZoomFactor( Double scale, QPoint center, QSize minimumSize
// m_blockTrackEnable = true;
//}
Void ViewArea::setGridVisible( Bool enable )
{
m_gridVisible = enable;
update();
}
Void ViewArea::setSnapToGrid( Bool enable )
{
m_snapToGrid = enable;
@@ -362,8 +362,8 @@ Void ViewArea::initZoomWinRect()
////////////////////////////////////////////////////////////////////////////////
Void ViewArea::updateSize()
{
Int w = m_pixmap.width() * m_zoomFactor;
Int h = m_pixmap.height() * m_zoomFactor;
Int w = m_pixmap.width() * m_dZoomFactor;
Int h = m_pixmap.height() * m_dZoomFactor;
setMinimumSize( w, h );
QWidget *p = parentWidget();
@@ -381,17 +381,17 @@ Void ViewArea::updateSize()
Void ViewArea::updateOffset()
{
if( width() > m_pixmap.width() * m_zoomFactor )
if( width() > m_pixmap.width() * m_dZoomFactor )
{
m_xOffset = ( width() - m_pixmap.width() * m_zoomFactor ) / 2;
m_xOffset = ( width() - m_pixmap.width() * m_dZoomFactor ) / 2;
}
else
{
m_xOffset = 0;
}
if( height() > m_pixmap.height() * m_zoomFactor )
if( height() > m_pixmap.height() * m_dZoomFactor )
{
m_yOffset = ( height() - m_pixmap.height() * m_zoomFactor ) / 2;
m_yOffset = ( height() - m_pixmap.height() * m_dZoomFactor ) / 2;
}
else
{
@@ -430,7 +430,7 @@ Void ViewArea::paintEvent( QPaintEvent *event )
// Save the actual paInter properties and scales the coordinate system.
paInter.save();
paInter.translate( m_xOffset, m_yOffset );
paInter.scale( m_zoomFactor, m_zoomFactor );
paInter.scale( m_dZoomFactor, m_dZoomFactor );
// This line is for fast paiting. Only visible area of the image is paInted.
// We take the exposed rect from the event (that gives us scroll/expose optimizations for free – no need
@@ -442,8 +442,7 @@ Void ViewArea::paintEvent( QPaintEvent *event )
paInter.drawPixmap( exposedRect, m_pixmap, exposedRect );
// Draw the Grid if it's visible.
//m_gridVisible = true;
if( m_gridVisible )
if( m_bGridVisible )
{
// Do we need to draw the whole grid?
// To know that, we need to perform a transformation of the rectangle
@@ -473,11 +472,11 @@ Void ViewArea::paintEvent( QPaintEvent *event )
/* if( m_xOffset || m_yOffset )
{
paInter.setPen( Qt::black );
paInter.drawRect( m_xOffset - 1, m_yOffset - 1, m_pixmap.width() * m_zoomFactor + 1, m_pixmap.height() * m_zoomFactor + 1 );
paInter.drawRect( m_xOffset - 1, m_yOffset - 1, m_pixmap.width() * m_dZoomFactor + 1, m_pixmap.height() * m_dZoomFactor + 1 );
}*/
// Draw pixel values in grid
if( m_zoomFactor >= 50.0 )
if( m_dZoomFactor >= 50.0 )
{
Int imageWidth = m_pixmap.width();
Int imageHeight = m_pixmap.height();
@@ -496,7 +495,7 @@ Void ViewArea::paintEvent( QPaintEvent *event )
{
QPoint pixelTopLeft( i, j );
QRect pixelRect( viewToWindow( pixelTopLeft ), QSize( m_zoomFactor, m_zoomFactor ) );
QRect pixelRect( viewToWindow( pixelTopLeft ), QSize( m_dZoomFactor, m_dZoomFactor ) );
Int frFormat = m_pcCurrFrame->getColorSpace();
@@ -676,7 +675,7 @@ Void ViewArea::paintEvent( QPaintEvent *event )
paInter.setPen( color );
paInter.save();
paInter.translate( m_xOffset, m_yOffset );
paInter.scale( m_zoomFactor, m_zoomFactor );
paInter.scale( m_dZoomFactor, m_dZoomFactor );
paInter.drawPixmap( QPoint( 0, 0 ), m_mask );
paInter.restore();
@@ -1013,8 +1012,8 @@ Bool ViewArea::isPosValid( const QPoint &pos ) const
QPoint ViewArea::windowToView( const QPoint& pt ) const
{
QPoint p;
p.setX( static_cast<Int>( ( pt.x() - m_xOffset ) / m_zoomFactor ) );
p.setY( static_cast<Int>( ( pt.y() - m_yOffset ) / m_zoomFactor ) );
p.setX( static_cast<Int>( ( pt.x() - m_xOffset ) / m_dZoomFactor ) );
p.setY( static_cast<Int>( ( pt.y() - m_yOffset ) / m_dZoomFactor ) );
return p;
}
@@ -1024,10 +1023,10 @@ QRect ViewArea::windowToView( const QRect& rc ) const
QRect r;
r.setTopLeft( windowToView( rc.topLeft() ) );
// r.setRight ( (Int)( ceil(( rc.right() - m_xOffset)/m_zoomFactor )));
// r.setBottom( (Int)( ceil(( rc.bottom()- m_yOffset)/m_zoomFactor )));
// r.setRight ( static_cast<Int>(( rc.right() - m_xOffset ) / m_zoomFactor +1));
// r.setBottom( static_cast<Int>(( rc.bottom() - m_xOffset ) / m_zoomFactor+1));
// r.setRight ( (Int)( ceil(( rc.right() - m_xOffset)/m_dZoomFactor )));
// r.setBottom( (Int)( ceil(( rc.bottom()- m_yOffset)/m_dZoomFactor )));
// r.setRight ( static_cast<Int>(( rc.right() - m_xOffset ) / m_dZoomFactor +1));
// r.setBottom( static_cast<Int>(( rc.bottom() - m_xOffset ) / m_dZoomFactor+1));
r.setBottomRight( windowToView( rc.bottomRight() ) );
return r;
}
@@ -1036,8 +1035,8 @@ QPoint ViewArea::viewToWindow( const QPoint& pt ) const
{
QPoint p;
p.setX( static_cast<Int>( pt.x() * m_zoomFactor + m_xOffset ) );
p.setY( static_cast<Int>( pt.y() * m_zoomFactor + m_yOffset ) );
p.setX( static_cast<Int>( pt.x() * m_dZoomFactor + m_xOffset ) );
p.setY( static_cast<Int>( pt.y() * m_dZoomFactor + m_yOffset ) );
return p;
}
@@ -1047,13 +1046,13 @@ QRect ViewArea::viewToWindow( const QRect& rc ) const
QRect r;
r.setTopLeft( viewToWindow( rc.topLeft() ) );
// r.setRight ( (Int)( ceil(( rc.right() +1+m_xOffset )*m_zoomFactor ) - 1 ));
// r.setBottom( (Int)( ceil(( rc.bottom()+1+m_yOffset )*m_zoomFactor ) - 1 ));
// r.setRight ( (Int)( ceil(( rc.right()+0.5)*m_zoomFactor )+ m_xOffset )-1);
// r.setBottom( (Int)( ceil(( rc.bottom()+0.5)*m_zoomFactor ) +m_yOffset )-1);
// r.setRight ( (Int)( ceil(( rc.right() +1+m_xOffset )*m_dZoomFactor ) - 1 ));
// r.setBottom( (Int)( ceil(( rc.bottom()+1+m_yOffset )*m_dZoomFactor ) - 1 ));
// r.setRight ( (Int)( ceil(( rc.right()+0.5)*m_dZoomFactor )+ m_xOffset )-1);
// r.setBottom( (Int)( ceil(( rc.bottom()+0.5)*m_dZoomFactor ) +m_yOffset )-1);
// qDebug()<<"Right = "<< r.right();
// r.setRight ( static_cast<Int>(( rc.right()+1) * m_zoomFactor + m_xOffset -1) );
// r.setBottom( static_cast<Int>(( rc.bottom()+1) * m_zoomFactor + m_yOffset -1));
// r.setRight ( static_cast<Int>(( rc.right()+1) * m_dZoomFactor + m_xOffset -1) );
// r.setBottom( static_cast<Int>(( rc.bottom()+1) * m_dZoomFactor + m_yOffset -1));
r.setBottomRight( viewToWindow( rc.bottomRight() ) );
return r;
+13 -7
View File
@@ -75,6 +75,8 @@ public:
*/
Void setTool( UInt view );
Void setGridVisible( Bool enable );
/**
* Clears any mask content.
*/
@@ -104,7 +106,7 @@ public:
Double getZoomFactor()
{
return m_zoomFactor;
return m_dZoomFactor;
}
// Scale function. Return used scale value (it may change when it touches the min or max zoom value)
@@ -123,7 +125,6 @@ public Q_SLOTS:
// Void setEraserTool();
// Void setNormalSelectionTool();
// Void setBlockSelectionTool();
void setGridVisible( bool enable );
void setSnapToGrid( bool enable );
// void setSelectedArea( QRect &rect );
@@ -178,7 +179,16 @@ private:
QRect viewToWindow( const QRect& rc ) const;
PlaYUVerFrame *m_pcCurrFrame;
Pel m_uiPixelHalfScale;
Tool m_eTool;
Bool m_bGridVisible;
QTimer m_zoomWinTimer;
Double m_dZoomWinRatio;
Double m_dZoomFactor;
QPixmap m_pixmap;
QBitmap m_mask;
QRect m_selectedArea;
@@ -186,19 +196,15 @@ private:
QPoint m_lastWindowPos;
GridManager m_grid;
ViewMode m_mode;
Tool m_eTool;
QColor m_maskColor;
Double m_zoomFactor;
Int m_xOffset;
Int m_yOffset;
Bool m_blockTrackEnable;
Bool m_newShape;
Bool m_gridVisible;
Bool m_snapToGrid;
Bool m_cursorInGrid;
Bool m_visibleZoomRect;
Double m_dZoomWinRatio;
QTimer m_zoomWinTimer;
};