{
// QCursor* cursor = nullptr;
switch (handlePosition) {
case dimension:
{
setCursor(Qt::SizeHorCursor);
DPS_ResizeableHandleRect * rectItem = dynamic_cast<DPS_ResizeableHandleRect *>( parentItem());
if(rectItem){
QRectF boundingFrameRect
= rectItem
->selectorFrameBounds
();
boundingFrameRect.setRight(event->pos().x() + 5);
rectItem->setSelectorFrameBounds(boundingFrameRect);
}
}
break;
}
}
void DPS_ResizeableHandleRect::drawHandlesDimension()
{
//Populate handles in list
if(handleListCenter.count() == 0){
// handleListCenter.append(new DPS_HandleItem(DPS_HandleItem::LeftCenter));
handleListCenter.append(new DPS_HandleItem(DPS_HandleItem::dimension));
}
//Set up pen
mPen.setWidth(1);
mPen.setColor(Qt::darkGreen);
//Right Center handle
QPointF centerRightCorner
= selectorFrameBounds
().
topRight() + QPointF(-4.5, selectorFrameBounds
().
height()/2.0 - 4.5);
centerRightHandleRect
= QRectF(centerRightCorner,
QSize(9,
9));
handleListCenter[0]->setRect(centerRightHandleRect);
if(!handleListCenter.isEmpty() && (!handlesAddedToScene)){
handleListCenter[0]->setPen(mPen);
handleListCenter
[0]->setBrush
(QBrush(Qt
::darkGreen));
ownerItem->scene()->addItem(handleListCenter[0]);
handleListCenter[0]->setParentItem(ownerItem);
}
handlesAddedToScene = true;
}
void DPS_ResizeableHandleRect::drawHandlesDimensionIfNecessary()
{
if(!ownerItem){
qWarning() << "ResizableHandleRect : No ownerItem set. Not drawing any\
handle. Please call setOwnerItem on your ResizableHandleRect subclass";
return;
}
if(ownerItem->isSelected()){
drawHandlesDimension();
handlesAddedToScene = true;
}else{
//Remove the handles
foreach (DPS_HandleItem * handleItem, handleListCenter) {
ownerItem->scene()->removeItem(handleItem);
}
qDeleteAll(handleListCenter);
handleListCenter.clear();
handlesAddedToScene = false;
}
}
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->save();
painter->setPen(pen());
painter->setBrush(brush());
painter->drawPath(starFromRect(boundingRect().adjusted(pen().width(), pen().width(),
-pen().width(),-pen().width())));
painter
->setPen
(QPen(Qt
::green,
1));
painter->drawRect(rect());
drawHandlesDimensionIfNecessary();
painter->restore();
}