Move Scode external libs to PlaYUVer main source code.

This commit is contained in:
Luis Lucas committed 2014-03-22 18:19:25 +00:00
1 parent c0f773ca18
commit 9c5cc4d1a6
12 files changed
+94 -555

No files matched your search

+272
View File
@@ -0,0 +1,272 @@
/***************************************************************************
* This file is a part of SCode project *
* IT - Instituto de Telecomunicacoes *
* http://www.it.pt *
* *
* Copyright (C) 2008 by Ricardo N. Rocha Sardo *
* ricardo.sardo@co.it.pt *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QBitmap>
#include <QPainter>
#include <QRect>
#include <QRectF>
#include <QPoint>
#include <QColor>
#include <QPen>
#include <QDebug>
#include "GridManager.h"
#include "plaYUVerSettings.h"
namespace plaYUVer
{
////////////////////////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////////////////////////
GridManager::GridManager()
{
m_nearPos = QPoint();
}
////////////////////////////////////////////////////////////////////////////////
// Grid Drawer
////////////////////////////////////////////////////////////////////////////////
void GridManager::drawGrid( QPixmap &image, const QRect& area, QPainter *painter )
{
PlaYUVerSettings settings;
int offsetx = 0; // Grid offset doesn't applies to SCODE
int offsety = 0; // project for now...
int imageWidth = image.width();
int imageHeight = image.height();
int hSpacing = settings.gridHSpacing();
int vSpacing = settings.gridVSpacing();
QColor color = settings.gridColor();
Style style = settings.gridStyle();
// Set pen for solid line.
QPen mainPen = QPen( color, 1, Qt::SolidLine );
switch( style )
{
case IntersectionDot:
case IntersectionCross:
{
painter->setPen( mainPen );
// Draw crosses or dots on intersections
for( int x = offsetx; x <= area.right(); x += hSpacing )
{
if( x >= imageWidth )
break;
for( int y = offsety; y <= area.bottom(); y += vSpacing )
{
if( y >= imageHeight )
break;
if( x >= area.x() && y >= area.y() )
{
if( style == IntersectionDot )
painter->drawPoint( x, y ); // Dot
else
{ // Crosses:
painter->drawLine( x, y - 1, x, y + 1 ); // Ver.line
painter->drawLine( x - 1, y, x + 1, y ); // Hor.line
}
}
}
}
break;
}
case Dashed:
{
// Change pen to the dashed line
mainPen.setStyle( Qt::DashLine );
}
default: // Solid:
{
painter->setPen( mainPen );
// Draw vertical line
for( int x = offsetx; x <= area.right(); x += hSpacing )
{
if( x >= imageWidth )
break;
if( x >= area.x() )
{
// Always draw the full line otherwise the line stippling
// varies with the location of view area and we get glitchy
// patterns.
painter->drawLine( x, 0, x, imageHeight - 1 );
}
}
// Draw horizontal line
for( int y = offsety; y <= area.bottom(); y += vSpacing )
{
if( y >= imageHeight )
break;
if( y >= area.y() )
{
painter->drawLine( 0, y, imageWidth - 1, y );
}
}
break;
}
}
}
////////////////////////////////////////////////////////////////////////////////
QRect GridManager::rectContains( const QPoint &pos ) const
{
return rectContains( pos.x(), pos.y() );
}
QRect GridManager::rectContains( int x, int y ) const
{
QRect rect;
QPoint pos;
int multiPosX;
int multiPosY;
PlaYUVerSettings settings;
int hSpacing = settings.gridHSpacing();
int vSpacing = settings.gridVSpacing();
if( ( x < 0 ) || ( y < 0 ) )
{
return rect;
}
// Find the multiple factor for the fisrt (x,y) position of the grid that
// is less than the given (x,y)
multiPosX = x / hSpacing;
multiPosY = y / vSpacing;
// Grid intersection position (x,y) that is less than the given (x,y)
pos = QPoint( multiPosX * hSpacing, multiPosY * vSpacing );
rect = QRect( pos.x(), pos.y(), hSpacing, vSpacing );
return rect;
}
bool GridManager::contains( int x, int y )
{
int resX;
int resY;
PlaYUVerSettings settings;
int hSpacing = settings.gridHSpacing();
int vSpacing = settings.gridVSpacing();
if( ( x < hSpacing ) || ( y < vSpacing ) || ( x < 0 ) || ( y < 0 ) )
return false;
if( ( x == 0 ) && ( y == 0 ) )
return true;
resX = 0;
if( hSpacing )
resX = x % hSpacing;
resY = 0;
if( vSpacing )
resY = y % vSpacing;
if( resX || resY )
return false;
else
return true;
}
QPoint GridManager::nearPos( int x, int y )
{
if( ( x != -1 ) && ( y != -1 ) )
isNear( x, y );
return m_nearPos;
}
bool GridManager::isNear( int x, int y )
{
qreal rectWidth;
qreal rectHeight;
int multiPosX;
int multiPosY;
PlaYUVerSettings settings;
int hSpacing = settings.gridHSpacing();
int vSpacing = settings.gridVSpacing();
if( ( x < 0 ) || ( y < 0 ) )
{
m_nearPos = QPoint( -1, -1 );
return false;
}
// We go to consider an area with ray equal 25% of the distance between
// spaces of the gride. In this in case, we have one rectangle centered
// in 25% of this distance.
rectWidth = 2 * 0.25 * hSpacing;
rectHeight = 2 * 0.25 * vSpacing;
QRectF rect( 0, 0, rectWidth, rectHeight );
// Find the multiple factor for the fisrt (x,y) position of the grid that
// is less than the given (x,y)
multiPosX = x / hSpacing;
multiPosY = y / vSpacing;
QPointF gridPoint( 0, 0 );
int gx;
int gy;
// In the worse case we have 4 points of the gride surrounding
for( int j = 0; j < 2; j++ )
{
for( int i = 0; i < 2; i++ )
{
gx = ( int )( multiPosX * hSpacing + i * hSpacing );
gy = ( int )( multiPosY * vSpacing + j * vSpacing );
gridPoint.setX( gx );
gridPoint.setY( gy );
rect.moveCenter( gridPoint );
if( rect.contains( x, y ) )
{
m_nearPos = QPoint( gx, gy );
return true;
}
}
}
m_nearPos = QPoint( -1, -1 );
return false;
}
bool GridManager::isNear( const QPoint &pos )
{
return isNear( pos.x(), pos.y() );
}
} // NameSpace plaYUVer
+99
View File
@@ -0,0 +1,99 @@
/***************************************************************************
* This file is a part of SCode project *
* IT - Instituto de Telecomunicacoes *
* http://www.it.pt *
* *
* Copyright (C) 2008 by Ricardo N. Rocha Sardo *
* ricardo.sardo@co.it.pt *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef __GRIDMANAGER_H__
#define __GRIDMANAGER_H__
#include <QRect>
#include <QColor>
#include <QPen>
class QPoint;
class QBitmap;
class QPainter;
namespace plaYUVer
{
/**
*
*/
class GridManager
{
public:
enum Style
{
IntersectionDot = 0, IntersectionCross, Dashed, Solid
};
GridManager();
void drawGrid( QPixmap &image, const QRect& area, QPainter *painter );
/**
* @returns a QRect defined by the grid that contains the point (x, y).
*/
QRect rectContains( int x, int y ) const;
/**
* This is an overloaded member function, provided for convenience.
* @returns a QRect defined by the grid that contains the QPoint pos.
*/
QRect rectContains( const QPoint &pos ) const;
/**
* @returns @c true if the point (x, y) is over a grid crossing, otherwise
* returns @c false
*/
bool contains( int x, int y );
/**
* @returns @c true if the point (x, y) is near a grid crossing, otherwise
* returns @c false.
* @see @p nearPos()
*/
bool isNear( int x, int y );
/**
* This is an overloaded member function, provided for convenience.
* @returns @c true if the given point is near a grid crossing, otherwise
* returns @c false.
* @see @p nearPos()
*/
bool isNear( const QPoint &pos );
/**
* @returns the grid crossing position that is near the point (x,y). If
* either the x or y are iqual to -1 (default) than returns the last near
* grid position found by @p isNear().
*/
QPoint nearPos( int x = -1, int y = -1 );
private:
QPoint m_nearPos;
};
} // NameSpace plaYUVer
#endif // __GRIDMANAGER_H__
+1 -1
View File
@@ -23,7 +23,7 @@
#include "ConfigureFormatDialog.h"
#include "SubWindowHandle.h"
#include "viewarea.h"
#include "ViewArea.h"
namespace plaYUVer
{
+1 -3
View File
@@ -34,14 +34,12 @@
#include "TypeDef.h"
#include "InputStream.h"
#include "viewarea.h"
#include "ViewArea.h"
#include "PlaYUVerModuleIf.h"
namespace plaYUVer
{
using namespace SCode;
class SubWindowHandle: public QMdiSubWindow
{
Q_OBJECT
+752
View File
@@ -0,0 +1,752 @@
/***************************************************************************
* This file is a part of SCode project *
* IT - Instituto de Telecomunicacoes *
* http://www.it.pt *
* *
* Copyright (C) 2008 by Ricardo N. Rocha Sardo *
* ricardo.sardo@co.it.pt *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <cmath>
#include <QPainter>
#include <QPainterPath>
#include <QMouseEvent>
#include <QImage>
#include <QColor>
#include <QString>
#include <QPixmapCache>
#include <QRectF>
#include <QDebug>
#include "ViewArea.h"
#include "GridManager.h"
namespace plaYUVer
{
static const QColor selectionColor = Qt::cyan;
static const QColor imageMaskColor = Qt::green;
static const QColor eraserColor = Qt::red;
ViewArea::ViewArea( QWidget *parent ) :
QWidget( parent )
{
setAttribute( Qt::WA_StaticContents );
// setAttribute( Qt::WA_NoBackground );
setMouseTracking( true );
m_pixmap = QPixmap();
m_grid = GridManager();
m_mask = QBitmap();
m_selectedArea = QRect();
m_zoomFactor = 1;
m_xOffset = 0;
m_yOffset = 0;
m_mode = NormalMode;
m_tool = NormalSelectionTool;
m_gridVisible = false;
m_snapToGrid = false;
m_blockTrackEnable = false;
}
void ViewArea::setImage( const QPixmap &pixmap )
{
m_pixmap = pixmap;
m_mask = QBitmap( pixmap.width(), pixmap.height() );
m_mask.clear();
updateSize();
update();
updateGeometry();
}
void ViewArea::clear()
{
m_pixmap = QPixmap();
m_mask = QBitmap();
m_mode = NormalMode;
updateSize();
update();
updateGeometry();
}
void ViewArea::clearMask()
{
m_mask.clear();
}
// QSize ViewArea::sizeHint() const
// {
// int w = m_pixmap.width()*m_zoomFactor;
// int h = m_pixmap.height()*m_zoomFactor;
// return QSize( w, h );
// }
void ViewArea::setZoomFactor( double f )
{
if( f == m_zoomFactor )
return;
m_zoomFactor = f;
emit( zoomFactorChanged( m_zoomFactor ) );
updateSize();
repaint();
updateGeometry();
}
void ViewArea::setMode( ViewMode mode )
{
if( m_mode == mode )
return;
m_mode = mode;
update();
}
void ViewArea::setNormalMode()
{
setMode( NormalMode );
}
void ViewArea::setMaskMode()
{
setMode( MaskMode );
}
void ViewArea::setMaskColor( const QColor &color )
{
m_maskColor = color;
update();
}
void ViewArea::setTool( Tool tool )
{
m_tool = tool;
}
void ViewArea::setMaskTool()
{
setMode( MaskMode );
setTool( MaskTool );
m_blockTrackEnable = true;
}
void ViewArea::setEraserTool()
{
setMode( MaskMode );
setTool( EraserTool );
m_blockTrackEnable = true;
}
void ViewArea::setNormalSelectionTool()
{
setMode( NormalMode );
setTool( NormalSelectionTool );
m_blockTrackEnable = false;
}
void ViewArea::setBlockSelectionTool()
{
setMode( NormalMode );
setTool( BlockSelectionTool );
m_blockTrackEnable = true;
}
void ViewArea::setGridVisible( bool enable )
{
m_gridVisible = enable;
update();
}
void ViewArea::setSnapToGrid( bool enable )
{
m_snapToGrid = enable;
}
void ViewArea::setSelectedArea( QRect &rect )
{
if( rect.isNull() )
{
update();
return;
}
QRect updateRect;
setNormalMode();
if( m_selectedArea.isNull() )
{
m_selectedArea = rect.normalized();
updateRect = m_selectedArea;
}
else
{
updateRect = m_selectedArea;
m_selectedArea = rect.normalized();
updateRect = updateRect.united( m_selectedArea );
}
updateRect.adjust( 0, 0, 1, 1 );
update( updateRect.normalized() );
}
////////////////////////////////////////////////////////////////////////////////
// Geometry Updates
////////////////////////////////////////////////////////////////////////////////
void ViewArea::updateSize()
{
int w = m_pixmap.width() * m_zoomFactor;
int h = m_pixmap.height() * m_zoomFactor;
setMinimumSize( w, h );
QWidget *p = parentWidget();
if( p )
{
// If the parent size is bigger than the minimum area to view the
// image, resize() will call resizeEvent(); otherwise, we need to
// perform the necessary updates (updateOffset).
resize( p->width(), p->height() );
}
if( w <= width() && h <= height() )
updateOffset();
}
void ViewArea::updateOffset()
{
if( width() > m_pixmap.width() * m_zoomFactor )
{
m_xOffset = ( width() - m_pixmap.width() * m_zoomFactor ) / 2;
}
else
{
m_xOffset = 0;
}
if( height() > m_pixmap.height() * m_zoomFactor )
{
m_yOffset = ( height() - m_pixmap.height() * m_zoomFactor ) / 2;
}
else
{
m_yOffset = 0;
}
}
////////////////////////////////////////////////////////////////////////////////
// Resize Event
////////////////////////////////////////////////////////////////////////////////
void ViewArea::resizeEvent( QResizeEvent */* event */)
{
if( size().isEmpty() || m_pixmap.isNull() )
return;
updateOffset();
}
////////////////////////////////////////////////////////////////////////////////
// Paint Event
////////////////////////////////////////////////////////////////////////////////
void ViewArea::paintEvent( QPaintEvent *event )
{
QRect winRect = event->rect();
if( size().isEmpty() || m_pixmap.isNull() )
return;
QPainter painter( this );
// Save the actual painter properties and scales the coordinate system.
painter.save();
painter.translate( m_xOffset, m_yOffset );
painter.scale( m_zoomFactor, m_zoomFactor );
// Draw the pixmap.
painter.drawPixmap( QPoint( 0, 0 ), m_pixmap );
// Draw the Grid if it's visible.
if( m_gridVisible )
{
// Do we need to draw the whole grid?
// To know that, we need to perform a transformation of the rectangle
// area that the painter needs to update - transform the windows
// coordinates (origin at the top-left corner of the widget), to the
// relatives coordinates of the image at it's original size (origin at
// the top-left corner of the image).
QRect vr = windowToView( winRect );
// Now we have the (to update) rectangle area on a coordinates system
// that has it's origin at the top-left corner of the image. That
// is, is referenced to the not scaled image.
// To know what image area we need to update, just intersects the
// rectangle area with the image area.
vr &= QRect( 0, 0, m_pixmap.width(), m_pixmap.height() );
// Set up for the grid drawer.
painter.setRenderHint( QPainter::Antialiasing );
// Draw grid.
m_grid.drawGrid( m_pixmap, vr, &painter );
}
painter.restore();
// Draw a border around the image.
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 );
}
QRect sr = viewToWindow( m_selectedArea );
QRect ir = sr & winRect;
if( ( mode() == NormalMode ) && !selectedArea().isNull() )
{
if( m_newShape || m_blockTrackEnable )
{
// Set the tool color
QColor selectColor = selectionColor;
selectColor.setAlpha( 120 );
QBrush brush( selectColor );
if( m_blockTrackEnable )
painter.setBrush( Qt::NoBrush );
else
painter.setBrush( brush );
painter.setPen( Qt::darkCyan );
// painter.drawRect( sr/*m_selectedArea*/ );
}
else
{
// 1) Cover the image with a light gray except the selected area
QColor fill( Qt::lightGray );
fill.setAlpha( 150 );
QBrush brush( fill );
painter.setBrush( fill );
painter.setPen( Qt::NoPen );
QPainterPath myPath;
QRect imgr = viewToWindow( QRect( 0, 0, m_pixmap.width(), m_pixmap.height() ) );
myPath.addRect( imgr );
myPath.addRect( sr/*m_selectedArea*/);
painter.drawPath( myPath );
// 2) Draw the selection rectangle
painter.setBrush( Qt::NoBrush );
painter.setPen( Qt::darkCyan );
// painter.drawRect( sr/*m_selectedArea*/ );
}
if( !ir.isNull() )
painter.drawRect( sr/*m_selectedArea*/);
}
// Mask Mode ----------------------------------------------------------
if( mode() != MaskMode )
return;
QColor color;
QBrush brush;
// Draw Mask
// Set the tool color
if( m_maskColor.isValid() )
color = m_maskColor;
else
color = imageMaskColor;
color.setAlpha( 120 );
painter.setPen( color );
painter.save();
painter.translate( m_xOffset, m_yOffset );
painter.scale( m_zoomFactor, m_zoomFactor );
painter.drawPixmap( QPoint( 0, 0 ), m_mask );
painter.restore();
if( !m_selectedArea.isNull() )
{
if( m_newShape || m_blockTrackEnable )
{
switch( tool() )
{
case MaskTool:
{
if( m_maskColor.isValid() )
color = m_maskColor;
else
color = imageMaskColor;
break;
}
case EraserTool:
{
color = eraserColor;
break;
}
default:
color = selectionColor; // ?Problems!
}
color.setAlpha( 120 );
brush = QBrush( color );
if( m_blockTrackEnable )
painter.setBrush( Qt::NoBrush );
else
painter.setBrush( brush );
painter.setPen( color );
if( !ir.isNull() )
painter.drawRect( sr );
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Mouse Events
////////////////////////////////////////////////////////////////////////////////
void ViewArea::wheelEvent( QWheelEvent *event )
{
double f;
f = m_zoomFactor + 0.001 * event->delta();
if( f < ( 32.0 / m_pixmap.width() ) )
f = 32.0 / m_pixmap.width();
setZoomFactor( f );
}
void ViewArea::mousePressEvent( QMouseEvent *event )
{
event->accept();
QPoint vpos = windowToView( event->pos() );
if( event->button() == Qt::LeftButton )
{
// Is the mouse over the image? If yes, save the mouse position;
// otherwise, QPoint( -1, -1 ) indicates an invalid position.
if( isPosValid( vpos ) )
{
m_lastPos = vpos;
}
else
{
m_lastPos = QPoint( -1, -1 );
return;
}
// If grid tracking
if( m_snapToGrid )
{
// Find if the cursor is near a grid intersection
bool isNear = m_grid.isNear( m_lastPos );
if( isNear )
{
// The grid 'near intersection' found when used isNear()
m_lastPos = m_grid.nearPos();
}
}
m_newShape = true;
if( tool() == NormalSelectionTool )
{
m_blockTrackEnable = false;
return;
}
if( mode() == MaskMode )
{
// Disable the block track to enable fill the block
m_blockTrackEnable = false;
}
// Block selection
m_selectedArea = m_grid.rectContains( m_lastPos );
QRect updateRect = viewToWindow( m_selectedArea );
updateRect.adjust( 0, 0, 1, 1 );
update( updateRect.normalized() );
}
}
void ViewArea::mouseMoveEvent( QMouseEvent *event )
{
event->accept();
QPoint actualPos = windowToView( event->pos() );
QRect updateRect;
emit positionChanged( actualPos );
// If mouse left button pressed
if( event->buttons() == Qt::LeftButton && m_lastPos != QPoint( -1, -1 ) )
{
// Grid tracking
if( m_snapToGrid )
{
// Find if the cursor is near a grid intersection
bool isNear = m_grid.isNear( actualPos );
if( isNear )
{
// Return the last grid near intersection found
actualPos = m_grid.nearPos();
}
}
updateRect = viewToWindow( m_selectedArea );
if( tool() == NormalSelectionTool )
{
// If the selection is only vertical or horizontal then we have one
// of the dimentions null.
if( actualPos.x() == m_lastPos.x() || actualPos.y() == m_lastPos.y() )
{
m_selectedArea = QRect();
}
// Selection from top to bottom
else if( m_lastPos.y() < actualPos.y() )
{
// From left to right
if( m_lastPos.x() < actualPos.x() )
{
QPoint bottomR = actualPos - QPoint( 1, 1 );
m_selectedArea = QRect( m_lastPos, bottomR );
}
// From right to left
else
{
QPoint topL( actualPos.x(), m_lastPos.y() );
QPoint bottomR( m_lastPos.x() - 1, actualPos.y() - 1 );
m_selectedArea = QRect( topL, bottomR );
}
}
// Selection from bottom to top
else
{
// From left to right
if( m_lastPos.x() < actualPos.x() )
{
QPoint topL( m_lastPos.x(), actualPos.y() );
QPoint bottomR( actualPos.x() - 1, m_lastPos.y() - 1 );
m_selectedArea = QRect( topL, bottomR );
}
// From right to left
else
{
QPoint bottomR = m_lastPos - QPoint( 1, 1 );
m_selectedArea = QRect( actualPos, bottomR );
}
}
}
else // if tool() == BlockSelectionTool || MaskTool || EraserTool
{
m_blockTrackEnable = false;
// If cursor is inside the selected area, we most redraw
// the selection rect because it may be smaller.
if( m_selectedArea.contains( actualPos ) )
{
m_selectedArea = m_grid.rectContains( m_lastPos );
}
m_selectedArea = m_selectedArea.united( m_grid.rectContains( actualPos ) );
}
// Intercept the selected area with the image area to limit the
// selection only to the image area, preventing it to come outside
// the image.
m_selectedArea &= QRect( 0, 0, m_pixmap.width(), m_pixmap.height() );
// Update only the united area
updateRect = updateRect.united( viewToWindow( m_selectedArea ) );
// "When rendering with a one pixel wide pen the QRect's
// boundary line will be rendered to the right and below the
// mathematical rectangle's boundary line.", in QT4 doc.
// Our selection pen width is 1, let's adjust the rendering area.
updateRect.adjust( 0, 0, 1, 1 );
update( updateRect.normalized() );
return;
}
// If no mouse button is pressed and bloks selection tool is set, then
// track the bloks.
if( m_blockTrackEnable )
{
updateRect = viewToWindow( m_selectedArea );
if( isPosValid( actualPos ) )
{
m_selectedArea = m_grid.rectContains( actualPos );
}
else
{
m_selectedArea = QRect();
}
updateRect = updateRect.united( viewToWindow( m_selectedArea ) );
updateRect.adjust( 0, 0, 1, 1 );
update( updateRect );
return;
}
}
void ViewArea::mouseReleaseEvent( QMouseEvent *event )
{
event->accept();
QPoint vpos = windowToView( event->pos() );
if( event->button() == Qt::LeftButton && m_lastPos != QPoint( -1, -1 ) )
{
// Normal Mode ------------------------------------------------------
if( mode() == NormalMode )
{
if( vpos == m_lastPos )
{
m_selectedArea = QRect();
if( tool() == BlockSelectionTool )
m_blockTrackEnable = true;
}
emit selectionChanged( m_selectedArea );
}
// Mask Mode -----------------------------------------------------------
else if( mode() == MaskMode )
{
if( !m_selectedArea.isNull() )
{
updateMask( m_selectedArea );
}
m_selectedArea = QRect();
m_blockTrackEnable = true;
}
m_newShape = false;
update();
unsetCursor();
m_lastPos = QPoint( -1, -1 );
}
}
////////////////////////////////////////////////////////////////////////////////
bool ViewArea::isPosValid( const QPoint &pos ) const
{
if( pos.x() < 0 || pos.y() < 0 || pos.x() >= m_pixmap.width() || pos.y() >= m_pixmap.height() )
return false;
else
return true;
}
////////////////////////////////////////////////////////////////////////////////
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 ) );
return p;
}
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.setBottomRight( windowToView( rc.bottomRight() ) );
return r;
}
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 ) );
return p;
}
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);
// 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.setBottomRight( viewToWindow( rc.bottomRight() ) );
return r;
}
////////////////////////////////////////////////////////////////////////////////
// Masks Management
////////////////////////////////////////////////////////////////////////////////
void ViewArea::updateMask( const QRect &rect )
{
switch( tool() )
{
case MaskTool:
{
// Add rect to the mask
QPainter painter( &m_mask );
painter.setBrush( Qt::color1 );
painter.setPen( Qt::NoPen );
painter.drawRect( rect );
painter.end();
break;
}
case EraserTool:
{
// Clears rect area in the mask
QPainter painter( &m_mask );
painter.setBrush( Qt::color0 );
painter.setPen( Qt::NoPen );
painter.drawRect( rect );
painter.end();
break;
}
default: /* Do Nothing */
;
}
}
} // NameSpace plaYUVer
+164
View File
@@ -0,0 +1,164 @@
/***************************************************************************
* This file is a part of SCode project *
* IT - Instituto de Telecomunicacoes *
* http://www.it.pt *
* *
* Copyright (C) 2008 by Ricardo N. Rocha Sardo *
* ricardo.sardo@co.it.pt *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef __VIEWAREA_H__
#define __VIEWAREA_H__
#include <QWidget>
#include <QPixmap>
#include <QBitmap>
#include <QColor>
#include "GridManager.h"
namespace plaYUVer
{
/**
*
*/
class ViewArea: public QWidget
{
Q_OBJECT
public:
enum ViewMode
{
NormalMode, MaskMode,
};
enum Tool
{
NormalSelectionTool, BlockSelectionTool, MaskTool, EraserTool
};
ViewArea( QWidget *parent = 0 );
void setImage( const QPixmap &pixmap );
void setMode( ViewMode mode );
void setTool( Tool tool );
void setMaskColor( const QColor &color = QColor() );
/**
* Clears any contents.
*/
void clear();
/**
* Clears any mask content.
*/
void clearMask();
QPixmap image() const
{
return m_pixmap;
}
QBitmap mask() const
{
return m_mask;
}
QRect selectedArea() const
{
return m_selectedArea;
}
GridManager gridManager() const
{
return m_grid;
}
ViewMode mode() const
{
return m_mode;
}
Tool tool() const
{
return m_tool;
}
QColor maskColor() const
{
return m_maskColor;
}
// QSize sizeHint() const;
signals:
void selectionChanged( const QRect &rect );
void positionChanged( const QPoint &pos );
void updateStatusBar( const QPoint &actualPos, int &luma, int &chromaU, int &chromaV );
void zoomFactorChanged( double );
public slots:
void setNormalMode();
void setMaskMode();
void setMaskTool();
void setEraserTool();
void setNormalSelectionTool();
void setBlockSelectionTool();
void setGridVisible( bool enable );
void setSnapToGrid( bool enable );
void setSelectedArea( QRect &rect );
void setZoomFactor( double f );
protected:
void paintEvent( QPaintEvent *event );
void resizeEvent( QResizeEvent * event );
void mousePressEvent( QMouseEvent *event );
void mouseMoveEvent( QMouseEvent *event );
void mouseReleaseEvent( QMouseEvent *event );
void wheelEvent( QWheelEvent *event );
void updateSize();
void updateOffset();
private:
bool isPosValid( const QPoint &pos ) const;
void updateMask( const QRect &rect );
QPoint windowToView( const QPoint& pt ) const;
QRect windowToView( const QRect& rc ) const;
QPoint viewToWindow( const QPoint& pt ) const;
QRect viewToWindow( const QRect& rc ) const;
QPixmap m_pixmap;
QBitmap m_mask;
QRect m_selectedArea;
QPoint m_lastPos;
GridManager m_grid;
ViewMode m_mode;
Tool m_tool;
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;
};
} // NameSpace plaYUVer
#endif // __VIEWAREA_H__
+12 -9
View File
@@ -633,16 +633,19 @@ void plaYUVerApp::updatePixelValueStatusBar(const QPoint & pos)
Int posX = pos.x(), posY = pos.y();
QString strStatus = QString("X=%1 Y=%2 ").arg(posX).arg(posY);
SubWindowHandle *currentSubWindow = activeSubWindow();
iWidth = currentSubWindow->getInputStream()->getWidth();
iHeight = currentSubWindow->getInputStream()->getHeight();
if( (posX<iWidth) && (posX>=0) && (posY<iHeight) && (posY>=0) )
SubWindowHandle *currentSubWindow = m_pcCurrentSubWindow;
if(currentSubWindow)
{
pixel = currentSubWindow->getInputStream()->getCurrentFrame()->getPixelValueFromYUV(pos, LUMA);
QString strAux = QString("Luma= %1").arg(pixel);
strStatus.append(strAux);
statusBar()->showMessage( strStatus , 0 );
iWidth = currentSubWindow->getInputStream()->getWidth();
iHeight = currentSubWindow->getInputStream()->getHeight();
if( (posX<iWidth) && (posX>=0) && (posY<iHeight) && (posY>=0) )
{
pixel = currentSubWindow->getInputStream()->getCurrentFrame()->getPixelValueFromYUV(pos, LUMA);
QString strAux = QString("Luma= %1").arg(pixel);
strStatus.append(strAux);
statusBar()->showMessage( strStatus , 0 );
}
}
}
+43
View File
@@ -314,4 +314,47 @@ void PlaYUVerSettings::setImgVDec( QString str )
m_settings.setValue( "MMPdec/imgV", str );
}
// - - - - - - - - - - - - - - Grid Settings - - - - - - - - - - - - - - - - - -
GridManager::Style PlaYUVerSettings::gridStyle()
{
return ( GridManager::Style )m_settings.value( "Grid/style", 0 ).toInt();
}
void PlaYUVerSettings::setGridStyle( GridManager::Style v )
{
m_settings.setValue( "Grid/style", v );
}
QColor PlaYUVerSettings::gridColor()
{
return m_settings.value( "Grid/color", QColor( Qt::white ) ).value<QColor>();
}
void PlaYUVerSettings::setGridColor( const QColor & v )
{
m_settings.setValue( "Grid/color", v );
}
int PlaYUVerSettings::gridHSpacing()
{
return m_settings.value( "Grid/hSpacing", 16 ).toInt();
}
void PlaYUVerSettings::setGridHSpacing( int v )
{
m_settings.setValue( "Grid/hSpacing", v );
}
int PlaYUVerSettings::gridVSpacing()
{
return m_settings.value( "Grid/vSpacing", 16 ).toInt();
}
void PlaYUVerSettings::setGridVSpacing( int v )
{
m_settings.setValue( "Grid/vSpacing", v );
}
} // NAMESPACE
+14 -1
View File
@@ -28,7 +28,7 @@
#include <QtCore>
#include "gridmanager.h"
#include "GridManager.h"
namespace plaYUVer
{
@@ -121,6 +121,19 @@ public:
QString imgVDec();
void setImgVDec( QString str );
// - - - - - - - - - - - - Grid Settings - - - - - - - - - - - - - - -
GridManager::Style gridStyle();
void setGridStyle( GridManager::Style v );
QColor gridColor();
void setGridColor( const QColor &v );
int gridHSpacing();
void setGridHSpacing( int v );
int gridVSpacing();
void setGridVSpacing( int v );
private:
QSettings m_settings;
};