Make cursor change when hovering over object.

This commit is contained in:
Jim Evins
2015-08-14 15:21:57 -04:00
parent cdbc3a8c9b
commit e5f5ddaf17
11 changed files with 82 additions and 47 deletions
+23 -25
View File
@@ -80,15 +80,13 @@ void glabels::Handle::drawAt( QPainter* painter, double x, double y ) const
///
/// Create Handle path at x,y
///
QPainterPath glabels::Handle::pathAt( QPainter *painter, double x, double y ) const
QPainterPath glabels::Handle::pathAt( double scale, double x, double y ) const
{
QPainterPath path;
QTransform transform = painter->transform();
double sx = 1/transform.m11();
double sy = 1/transform.m22();
double s = 1/scale;
path.addRect( -sx*handlePixels/2, -sy*handlePixels/2, sx*handlePixels, sy*handlePixels );
path.addRect( -s*handlePixels/2, -s*handlePixels/2, s*handlePixels, s*handlePixels );
path.translate( x, y );
return path;
@@ -124,9 +122,9 @@ void glabels::HandleNorth::draw( QPainter* painter ) const
///
/// HandleNorth Path
///
QPainterPath glabels::HandleNorth::path( QPainter* painter ) const
QPainterPath glabels::HandleNorth::path( double scale ) const
{
return pathAt( painter, mOwner->w()/2, 0 );
return pathAt( scale, mOwner->w()/2, 0 );
}
@@ -159,9 +157,9 @@ void glabels::HandleNorthEast::draw( QPainter* painter ) const
///
/// HandleNorthEast Path
///
QPainterPath glabels::HandleNorthEast::path( QPainter* painter ) const
QPainterPath glabels::HandleNorthEast::path( double scale ) const
{
return pathAt( painter, mOwner->w(), 0 );
return pathAt( scale, mOwner->w(), 0 );
}
@@ -194,9 +192,9 @@ void glabels::HandleEast::draw( QPainter* painter ) const
///
/// HandleEast Path
///
QPainterPath glabels::HandleEast::path( QPainter* painter ) const
QPainterPath glabels::HandleEast::path( double scale ) const
{
return pathAt( painter, mOwner->w(), mOwner->h()/2 );
return pathAt( scale, mOwner->w(), mOwner->h()/2 );
}
@@ -229,9 +227,9 @@ void glabels::HandleSouthEast::draw( QPainter* painter ) const
///
/// HandleSouthEast Path
///
QPainterPath glabels::HandleSouthEast::path( QPainter* painter ) const
QPainterPath glabels::HandleSouthEast::path( double scale ) const
{
return pathAt( painter, mOwner->w(), mOwner->h() );
return pathAt( scale, mOwner->w(), mOwner->h() );
}
@@ -264,9 +262,9 @@ void glabels::HandleSouth::draw( QPainter* painter ) const
///
/// HandleSouth Path
///
QPainterPath glabels::HandleSouth::path( QPainter* painter ) const
QPainterPath glabels::HandleSouth::path( double scale ) const
{
return pathAt( painter, mOwner->w()/2, mOwner->h() );
return pathAt( scale, mOwner->w()/2, mOwner->h() );
}
@@ -299,9 +297,9 @@ void glabels::HandleSouthWest::draw( QPainter* painter ) const
///
/// HandleSouthWest Path
///
QPainterPath glabels::HandleSouthWest::path( QPainter* painter ) const
QPainterPath glabels::HandleSouthWest::path( double scale ) const
{
return pathAt( painter, 0, mOwner->w() );
return pathAt( scale, 0, mOwner->w() );
}
@@ -334,9 +332,9 @@ void glabels::HandleWest::draw( QPainter* painter ) const
///
/// HandleWest Path
///
QPainterPath glabels::HandleWest::path( QPainter* painter ) const
QPainterPath glabels::HandleWest::path( double scale ) const
{
return pathAt( painter, 0, mOwner->h()/2 );
return pathAt( scale, 0, mOwner->h()/2 );
}
@@ -369,9 +367,9 @@ void glabels::HandleNorthWest::draw( QPainter* painter ) const
///
/// HandleNorthWest Path
///
QPainterPath glabels::HandleNorthWest::path( QPainter* painter ) const
QPainterPath glabels::HandleNorthWest::path( double scale ) const
{
return pathAt( painter, 0, 0 );
return pathAt( scale, 0, 0 );
}
@@ -404,9 +402,9 @@ void glabels::HandleP1::draw( QPainter* painter ) const
///
/// HandleP1 Path
///
QPainterPath glabels::HandleP1::path( QPainter* painter ) const
QPainterPath glabels::HandleP1::path( double scale ) const
{
return pathAt( painter, 0, 0 );
return pathAt( scale, 0, 0 );
}
@@ -439,7 +437,7 @@ void glabels::HandleP2::draw( QPainter* painter ) const
///
/// HandleP2 Path
///
QPainterPath glabels::HandleP2::path( QPainter* painter ) const
QPainterPath glabels::HandleP2::path( double scale ) const
{
return pathAt( painter, mOwner->w(), mOwner->h() );
return pathAt( scale, mOwner->w(), mOwner->h() );
}
+12 -12
View File
@@ -51,10 +51,10 @@ namespace glabels
////////////////////////////
public:
virtual void draw( QPainter* painter ) const = 0;
virtual QPainterPath path( QPainter* painter ) const = 0;
virtual QPainterPath path( double scale ) const = 0;
protected:
void drawAt( QPainter* painter, double x, double y ) const;
QPainterPath pathAt( QPainter* painter, double x, double y ) const;
QPainterPath pathAt( double scale, double x, double y ) const;
////////////////////////////
@@ -84,7 +84,7 @@ namespace glabels
////////////////////////////
public:
virtual void draw( QPainter* painter ) const;
virtual QPainterPath path( QPainter* painter ) const;
virtual QPainterPath path( double scale ) const;
};
@@ -106,7 +106,7 @@ namespace glabels
////////////////////////////
public:
virtual void draw( QPainter* painter ) const;
virtual QPainterPath path( QPainter* painter ) const;
virtual QPainterPath path( double scale ) const;
};
@@ -128,7 +128,7 @@ namespace glabels
////////////////////////////
public:
virtual void draw( QPainter* painter ) const;
virtual QPainterPath path( QPainter* painter ) const;
virtual QPainterPath path( double scale ) const;
};
@@ -150,7 +150,7 @@ namespace glabels
////////////////////////////
public:
virtual void draw( QPainter* painter ) const;
virtual QPainterPath path( QPainter* painter ) const;
virtual QPainterPath path( double scale ) const;
};
@@ -172,7 +172,7 @@ namespace glabels
////////////////////////////
public:
virtual void draw( QPainter* painter ) const;
virtual QPainterPath path( QPainter* painter ) const;
virtual QPainterPath path( double scale ) const;
};
@@ -194,7 +194,7 @@ namespace glabels
////////////////////////////
public:
virtual void draw( QPainter* painter ) const;
virtual QPainterPath path( QPainter* painter ) const;
virtual QPainterPath path( double scale ) const;
};
@@ -216,7 +216,7 @@ namespace glabels
////////////////////////////
public:
virtual void draw( QPainter* painter ) const;
virtual QPainterPath path( QPainter* painter ) const;
virtual QPainterPath path( double scale ) const;
};
@@ -238,7 +238,7 @@ namespace glabels
////////////////////////////
public:
virtual void draw( QPainter* painter ) const;
virtual QPainterPath path( QPainter* painter ) const;
virtual QPainterPath path( double scale ) const;
};
@@ -260,7 +260,7 @@ namespace glabels
////////////////////////////
public:
virtual void draw( QPainter* painter ) const;
virtual QPainterPath path( QPainter* painter ) const;
virtual QPainterPath path( double scale ) const;
};
@@ -282,7 +282,7 @@ namespace glabels
////////////////////////////
public:
virtual void draw( QPainter* painter ) const;
virtual QPainterPath path( QPainter* painter ) const;
virtual QPainterPath path( double scale ) const;
};
+2 -2
View File
@@ -116,11 +116,11 @@ namespace glabels
///
/// Delete Object
///
LabelModelObject* LabelModel::objectAt( double x, double y )
LabelModelObject* LabelModel::objectAt( double scale, double x, double y )
{
foreach( LabelModelObject* object, mObjectList )
{
if ( object->isLocatedAt( x, y ) )
if ( object->isLocatedAt( scale, x, y ) )
{
return object;
}
+1 -1
View File
@@ -100,7 +100,7 @@ namespace glabels
void addObject( LabelModelObject* object );
void deleteObject( LabelModelObject* object );
LabelModelObject* objectAt( double x, double y );
LabelModelObject* objectAt( double scale, double x, double y );
/////////////////////////////////
+11
View File
@@ -102,4 +102,15 @@ namespace glabels
painter->drawRect( 0, 0, mW, mH );
}
///
/// Path representing object
///
QPainterPath LabelModelBoxObject::path() const
{
QPainterPath path;
path.addRect( 0, 0, mW, mH );
return path;
}
}
+1
View File
@@ -49,6 +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;
};
+19 -2
View File
@@ -895,10 +895,27 @@ namespace glabels
///
/// Default isLocatedAt method
/// Is this object locate at x,y?
///
bool LabelModelObject::isLocatedAt( double x, double y )
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 ) )
{
return true;
}
else if ( mOutline )
{
QPainterPath outlinePath = mMatrix.map( mOutline->path( scale ) );
if ( outlinePath.contains( p ) )
{
return true;
}
}
return false;
}
+2 -1
View File
@@ -385,7 +385,7 @@ namespace glabels
void rotate( double thetaDegs );
void flipHoriz();
void flipVert();
virtual bool isLocatedAt( double x, double y );
bool isLocatedAt( double scale, double x, double y ) const;
///////////////////////////////////////////////////////////////
@@ -398,6 +398,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;
///////////////////////////////////////////////////////////////
+9 -2
View File
@@ -30,6 +30,7 @@ namespace
{
const qreal dashSize = 1;
const double slopPixels = 2;
const double outlineWidthPixels = 1;
const QColor outlineColor1( 0, 0, 0 );
const QColor outlineColor2( 255, 255, 255 );
@@ -89,11 +90,17 @@ void glabels::Outline::draw( QPainter* painter ) const
///
/// Create Outline path
///
QPainterPath glabels::Outline::path( QPainter *painter ) const
QPainterPath glabels::Outline::path( double scale ) const
{
double s = 1 / scale;
QPainterPath path;
path.addRect( 0, 0, mOwner->w(), mOwner->h() );
path.addRect( -s*slopPixels, -s*slopPixels,
mOwner->w()+s*2*slopPixels, mOwner->h()+s*2*slopPixels );
path.closeSubpath();
path.addRect( s*slopPixels, s*slopPixels,
mOwner->w()-s*2*slopPixels, mOwner->h()-s*2*slopPixels );
return path;
}
+1 -1
View File
@@ -50,7 +50,7 @@ namespace glabels
////////////////////////////
public:
void draw( QPainter* painter ) const;
QPainterPath path( QPainter* painter ) const;
QPainterPath path( double scale ) const;
////////////////////////////
+1 -1
View File
@@ -346,7 +346,7 @@ glabels::View::mouseMoveEvent( QMouseEvent* event )
case IdleState:
/* @TODO handle handles. */
if ( mModel->objectAt( xWorld, yWorld ) )
if ( mModel->objectAt( mZoom, xWorld, yWorld ) )
{
setCursor( Qt::SizeAllCursor );
}