Improved detection of hover
- account for presence of fill or outline colors - allow for a couple of pixels of slop
This commit is contained in:
@@ -24,6 +24,12 @@
|
|||||||
#include <QPen>
|
#include <QPen>
|
||||||
|
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const double slopPixels = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace glabels
|
namespace glabels
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -105,12 +111,30 @@ namespace glabels
|
|||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Path representing object
|
/// Path to test for hover condition
|
||||||
///
|
///
|
||||||
QPainterPath LabelModelBoxObject::path() const
|
QPainterPath LabelModelBoxObject::hoverPath( double scale ) const
|
||||||
{
|
{
|
||||||
|
double s = 1 / scale;
|
||||||
|
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
path.addRect( 0, 0, mW, mH );
|
|
||||||
|
if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() )
|
||||||
|
{
|
||||||
|
path.addRect( -mLineWidth/2, -mLineWidth/2, mW+mLineWidth, mH+mLineWidth );
|
||||||
|
}
|
||||||
|
else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) )
|
||||||
|
{
|
||||||
|
path.addRect( 0, 0, mW, mH );
|
||||||
|
}
|
||||||
|
else if ( mLineColorNode.color().alpha() )
|
||||||
|
{
|
||||||
|
path.addRect( (-mLineWidth/2)-s*slopPixels, (-mLineWidth/2)-s*slopPixels,
|
||||||
|
mW+mLineWidth+s*2*slopPixels, mH+mLineWidth+s*2*slopPixels );
|
||||||
|
path.closeSubpath();
|
||||||
|
path.addRect( mLineWidth/2+s*slopPixels, mLineWidth/2+s*slopPixels,
|
||||||
|
mW-mLineWidth-s*2*slopPixels, mH-mLineWidth-s*2*slopPixels );
|
||||||
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace glabels
|
|||||||
protected:
|
protected:
|
||||||
virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const;
|
virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const;
|
||||||
virtual void drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const;
|
virtual void drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const;
|
||||||
virtual QPainterPath path() const;
|
virtual QPainterPath hoverPath( double scale ) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -905,17 +905,20 @@ namespace glabels
|
|||||||
bool LabelModelObject::isLocatedAt( double scale, double x, double y ) const
|
bool LabelModelObject::isLocatedAt( double scale, double x, double y ) const
|
||||||
{
|
{
|
||||||
QPointF p( x, y );
|
QPointF p( x, y );
|
||||||
p -= QPointF( mX0, mY0 ); // Translate point to x0,y0
|
|
||||||
|
|
||||||
QPainterPath objectPath = mMatrix.map( path() );
|
/*
|
||||||
if ( objectPath.contains( p ) )
|
* Change point to object relative coordinates
|
||||||
|
*/
|
||||||
|
p -= QPointF( mX0, mY0 ); // Translate point to x0,y0
|
||||||
|
p = mMatrix.inverted().map( p );
|
||||||
|
|
||||||
|
if ( hoverPath( scale ).contains( p ) )
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if ( mOutline )
|
else if ( isSelected() && mOutline )
|
||||||
{
|
{
|
||||||
QPainterPath outlinePath = mMatrix.map( mOutline->path( scale ) );
|
if ( mOutline->hoverPath( scale ).contains( p ) )
|
||||||
if ( outlinePath.contains( p ) )
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -399,7 +399,7 @@ namespace glabels
|
|||||||
protected:
|
protected:
|
||||||
virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const = 0;
|
virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const = 0;
|
||||||
virtual void drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const = 0;
|
virtual void drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const = 0;
|
||||||
virtual QPainterPath path() const = 0;
|
virtual QPainterPath hoverPath( double scale ) const = 0;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
|
|||||||
+2
-2
@@ -88,9 +88,9 @@ void glabels::Outline::draw( QPainter* painter ) const
|
|||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Create Outline path
|
/// Create path for testing for hover condition
|
||||||
///
|
///
|
||||||
QPainterPath glabels::Outline::path( double scale ) const
|
QPainterPath glabels::Outline::hoverPath( double scale ) const
|
||||||
{
|
{
|
||||||
double s = 1 / scale;
|
double s = 1 / scale;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -49,8 +49,8 @@ namespace glabels
|
|||||||
// Drawing Methods
|
// Drawing Methods
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
public:
|
public:
|
||||||
void draw( QPainter* painter ) const;
|
void draw( QPainter* painter ) const;
|
||||||
QPainterPath path( double scale ) const;
|
QPainterPath hoverPath( double scale ) const;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|||||||
+1
-1
@@ -730,7 +730,7 @@ glabels::View::handleResizeMotion( double xWorld, double yWorld )
|
|||||||
Handle::Location location = mResizeHandle->location();
|
Handle::Location location = mResizeHandle->location();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Change to item relative coordinates
|
* Change point to object relative coordinates
|
||||||
*/
|
*/
|
||||||
p -= QPointF( mResizeObject->x0(), mResizeObject->y0() );
|
p -= QPointF( mResizeObject->x0(), mResizeObject->y0() );
|
||||||
p = mResizeObject->matrix().inverted().map( p );
|
p = mResizeObject->matrix().inverted().map( p );
|
||||||
|
|||||||
Reference in New Issue
Block a user