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;
}