Make cursor change when hovering over object.
This commit is contained in:
+23
-25
@@ -80,15 +80,13 @@ void glabels::Handle::drawAt( QPainter* painter, double x, double y ) const
|
|||||||
///
|
///
|
||||||
/// Create Handle path at x,y
|
/// 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;
|
QPainterPath path;
|
||||||
|
|
||||||
QTransform transform = painter->transform();
|
double s = 1/scale;
|
||||||
double sx = 1/transform.m11();
|
|
||||||
double sy = 1/transform.m22();
|
|
||||||
|
|
||||||
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 );
|
path.translate( x, y );
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
@@ -124,9 +122,9 @@ void glabels::HandleNorth::draw( QPainter* painter ) const
|
|||||||
///
|
///
|
||||||
/// HandleNorth Path
|
/// 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
|
/// 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
|
/// 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
|
/// 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
|
/// 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
|
/// 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
|
/// 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
|
/// 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
|
/// 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
|
/// 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
@@ -51,10 +51,10 @@ namespace glabels
|
|||||||
////////////////////////////
|
////////////////////////////
|
||||||
public:
|
public:
|
||||||
virtual void draw( QPainter* painter ) const = 0;
|
virtual void draw( QPainter* painter ) const = 0;
|
||||||
virtual QPainterPath path( QPainter* painter ) const = 0;
|
virtual QPainterPath path( double scale ) const = 0;
|
||||||
protected:
|
protected:
|
||||||
void drawAt( QPainter* painter, double x, double y ) const;
|
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:
|
public:
|
||||||
virtual void draw( QPainter* painter ) const;
|
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:
|
public:
|
||||||
virtual void draw( QPainter* painter ) const;
|
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:
|
public:
|
||||||
virtual void draw( QPainter* painter ) const;
|
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:
|
public:
|
||||||
virtual void draw( QPainter* painter ) const;
|
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:
|
public:
|
||||||
virtual void draw( QPainter* painter ) const;
|
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:
|
public:
|
||||||
virtual void draw( QPainter* painter ) const;
|
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:
|
public:
|
||||||
virtual void draw( QPainter* painter ) const;
|
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:
|
public:
|
||||||
virtual void draw( QPainter* painter ) const;
|
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:
|
public:
|
||||||
virtual void draw( QPainter* painter ) const;
|
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:
|
public:
|
||||||
virtual void draw( QPainter* painter ) const;
|
virtual void draw( QPainter* painter ) const;
|
||||||
virtual QPainterPath path( QPainter* painter ) const;
|
virtual QPainterPath path( double scale ) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -116,11 +116,11 @@ namespace glabels
|
|||||||
///
|
///
|
||||||
/// Delete Object
|
/// Delete Object
|
||||||
///
|
///
|
||||||
LabelModelObject* LabelModel::objectAt( double x, double y )
|
LabelModelObject* LabelModel::objectAt( double scale, double x, double y )
|
||||||
{
|
{
|
||||||
foreach( LabelModelObject* object, mObjectList )
|
foreach( LabelModelObject* object, mObjectList )
|
||||||
{
|
{
|
||||||
if ( object->isLocatedAt( x, y ) )
|
if ( object->isLocatedAt( scale, x, y ) )
|
||||||
{
|
{
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ namespace glabels
|
|||||||
void addObject( LabelModelObject* object );
|
void addObject( LabelModelObject* object );
|
||||||
void deleteObject( LabelModelObject* object );
|
void deleteObject( LabelModelObject* object );
|
||||||
|
|
||||||
LabelModelObject* objectAt( double x, double y );
|
LabelModelObject* objectAt( double scale, double x, double y );
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
|||||||
@@ -102,4 +102,15 @@ namespace glabels
|
|||||||
painter->drawRect( 0, 0, mW, mH );
|
painter->drawRect( 0, 0, mW, mH );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Path representing object
|
||||||
|
///
|
||||||
|
QPainterPath LabelModelBoxObject::path() const
|
||||||
|
{
|
||||||
|
QPainterPath path;
|
||||||
|
path.addRect( 0, 0, mW, mH );
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -385,7 +385,7 @@ namespace glabels
|
|||||||
void rotate( double thetaDegs );
|
void rotate( double thetaDegs );
|
||||||
void flipHoriz();
|
void flipHoriz();
|
||||||
void flipVert();
|
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:
|
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;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
|
|||||||
+9
-2
@@ -30,6 +30,7 @@ namespace
|
|||||||
{
|
{
|
||||||
const qreal dashSize = 1;
|
const qreal dashSize = 1;
|
||||||
|
|
||||||
|
const double slopPixels = 2;
|
||||||
const double outlineWidthPixels = 1;
|
const double outlineWidthPixels = 1;
|
||||||
const QColor outlineColor1( 0, 0, 0 );
|
const QColor outlineColor1( 0, 0, 0 );
|
||||||
const QColor outlineColor2( 255, 255, 255 );
|
const QColor outlineColor2( 255, 255, 255 );
|
||||||
@@ -89,11 +90,17 @@ void glabels::Outline::draw( QPainter* painter ) const
|
|||||||
///
|
///
|
||||||
/// Create Outline path
|
/// Create Outline path
|
||||||
///
|
///
|
||||||
QPainterPath glabels::Outline::path( QPainter *painter ) const
|
QPainterPath glabels::Outline::path( double scale ) const
|
||||||
{
|
{
|
||||||
|
double s = 1 / scale;
|
||||||
|
|
||||||
QPainterPath path;
|
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;
|
return path;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ namespace glabels
|
|||||||
////////////////////////////
|
////////////////////////////
|
||||||
public:
|
public:
|
||||||
void draw( QPainter* painter ) const;
|
void draw( QPainter* painter ) const;
|
||||||
QPainterPath path( QPainter* painter ) const;
|
QPainterPath path( double scale ) const;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|||||||
+1
-1
@@ -346,7 +346,7 @@ glabels::View::mouseMoveEvent( QMouseEvent* event )
|
|||||||
|
|
||||||
case IdleState:
|
case IdleState:
|
||||||
/* @TODO handle handles. */
|
/* @TODO handle handles. */
|
||||||
if ( mModel->objectAt( xWorld, yWorld ) )
|
if ( mModel->objectAt( mZoom, xWorld, yWorld ) )
|
||||||
{
|
{
|
||||||
setCursor( Qt::SizeAllCursor );
|
setCursor( Qt::SizeAllCursor );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user