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:
Jim Evins
2015-09-08 17:53:37 -04:00
parent 81923681b3
commit b12f4a2478
7 changed files with 43 additions and 16 deletions
+27 -3
View File
@@ -24,6 +24,12 @@
#include <QPen>
namespace
{
const double slopPixels = 2;
}
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;
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;
}
+1 -1
View File
@@ -49,7 +49,7 @@ namespace glabels
protected:
virtual void drawShadow( 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;
};
+9 -6
View File
@@ -905,17 +905,20 @@ namespace glabels
bool LabelModelObject::isLocatedAt( double scale, double x, double y ) const
{
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;
}
else if ( mOutline )
else if ( isSelected() && mOutline )
{
QPainterPath outlinePath = mMatrix.map( mOutline->path( scale ) );
if ( outlinePath.contains( p ) )
if ( mOutline->hoverPath( scale ).contains( p ) )
{
return true;
}
+1 -1
View File
@@ -399,7 +399,7 @@ namespace glabels
protected:
virtual void drawShadow( 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
View File
@@ -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;
+2 -2
View File
@@ -49,8 +49,8 @@ namespace glabels
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter ) const;
QPainterPath path( double scale ) const;
void draw( QPainter* painter ) const;
QPainterPath hoverPath( double scale ) const;
////////////////////////////
+1 -1
View File
@@ -730,7 +730,7 @@ glabels::View::handleResizeMotion( double xWorld, double yWorld )
Handle::Location location = mResizeHandle->location();
/*
* Change to item relative coordinates
* Change point to object relative coordinates
*/
p -= QPointF( mResizeObject->x0(), mResizeObject->y0() );
p = mResizeObject->matrix().inverted().map( p );