}
}
-//virtual
void GraphicsSceneRectMove::keyPressEvent(QKeyEvent * keyEvent)
{
- if (m_selectedItem == NULL) {
+ if (m_selectedItem == NULL || !(m_selectedItem->flags() & QGraphicsItem::ItemIsMovable)) {
QGraphicsScene::keyPressEvent(keyEvent);
return;
}
emit actionFinished();
}
-//virtual
void GraphicsSceneRectMove::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e)
{
QPointF p = e->scenePos();
p += QPoint(-2, -2);
m_resizeMode = NoResize;
m_selectedItem = NULL;
- QGraphicsItem* g = items(QRectF(p , QSizeF(4, 4)).toRect()).at(0);
+
+ // http://www.kdenlive.org/mantis/view.php?id=1035
+ QList<QGraphicsItem*> i = items(QRectF(p , QSizeF(4, 4)).toRect());
+ if (i.size() <= 0) return;
+
+ QGraphicsItem* g = i.at(0);
if (g) {
if (g->type() == 8) {
QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(g);
break;
}
}
- if (item == NULL) {
+ if (item == NULL || !(item->flags() & QGraphicsItem::ItemIsSelectable)) {
if (m_selectedItem && m_selectedItem->type() == 8) {
// disable text editing
QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(m_selectedItem);
}
}
}
- if (item != NULL) {
+ if (item != NULL && item->flags() & QGraphicsItem::ItemIsMovable) {
m_sceneClickPoint = e->scenePos();
m_selectedItem = item;
kDebug() << "///////// ITEM TYPE: " << item->type();
QGraphicsLineItem borderLeft(bottomLeft.x(), bottomLeft.y(), topLeft.x(), topLeft.y());
// The area interested by the mouse pointer
QPainterPath mouseArea;
- mouseArea.addRect(e->scenePos().toPoint().x() - 3 / m_zoom, e->scenePos().toPoint().y() - 3 / m_zoom, 6 / m_zoom, 6 / m_zoom);
+ mouseArea.addRect(e->scenePos().toPoint().x() - 4 / m_zoom, e->scenePos().toPoint().y() - 4 / m_zoom, 8 / m_zoom, 8 / m_zoom);
// Check for collisions between the mouse and the borders
if (borderLeft.collidesWithPath(mouseArea) && borderTop.collidesWithPath(mouseArea))
m_resizeMode = TopLeft;
clearSelection();
}
-//virtual
void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
{
if ((e->screenPos() - m_clickPoint).manhattanLength() < QApplication::startDragDistance()) {
}
if (m_selectedItem->type() == 3 && m_resizeMode != NoResize) {
QGraphicsRectItem *gi = (QGraphicsRectItem*)m_selectedItem;
+ // Resize using aspect ratio
+ if (!m_selectedItem->data(0).isNull()) {
+ // we want to keep aspect ratio
+ double hRatio = (double) newrect.width() / m_selectedItem->data(0).toInt();
+ double vRatio = (double) newrect.height() / m_selectedItem->data(1).toInt();
+ if (hRatio < vRatio) newrect.setHeight(m_selectedItem->data(1).toInt() * hRatio);
+ else newrect.setWidth(m_selectedItem->data(0).toInt() * vRatio);
+ }
+
gi->setRect(newrect);
}
/*else {
QGraphicsLineItem borderLeft(bottomLeft.x(), bottomLeft.y(), topLeft.x(), topLeft.y());
// The area interested by the mouse pointer
QPainterPath mouseArea;
- mouseArea.addRect(e->scenePos().toPoint().x() - 3 / m_zoom, e->scenePos().toPoint().y() - 3 / m_zoom, 6 / m_zoom, 6 / m_zoom);
+ mouseArea.addRect(e->scenePos().toPoint().x() - 4 / m_zoom, e->scenePos().toPoint().y() - 4 / m_zoom, 8 / m_zoom, 8 / m_zoom);
// Check for collisions between the mouse and the borders
- if (borderLeft.collidesWithPath(mouseArea) && borderTop.collidesWithPath(mouseArea))
- setCursor(QCursor(Qt::SizeFDiagCursor));
- else if (borderLeft.collidesWithPath(mouseArea) && borderBottom.collidesWithPath(mouseArea))
- setCursor(QCursor(Qt::SizeBDiagCursor));
- else if (borderRight.collidesWithPath(mouseArea) && borderTop.collidesWithPath(mouseArea))
- setCursor(QCursor(Qt::SizeBDiagCursor));
- else if (borderRight.collidesWithPath(mouseArea) && borderBottom.collidesWithPath(mouseArea))
- setCursor(QCursor(Qt::SizeFDiagCursor));
- else if (borderLeft.collidesWithPath(mouseArea))
- setCursor(Qt::SizeHorCursor);
- else if (borderRight.collidesWithPath(mouseArea))
- setCursor(Qt::SizeHorCursor);
- else if (borderTop.collidesWithPath(mouseArea))
- setCursor(Qt::SizeVerCursor);
- else if (borderBottom.collidesWithPath(mouseArea))
- setCursor(Qt::SizeVerCursor);
+ if ((borderLeft.collidesWithPath(mouseArea) && borderTop.collidesWithPath(mouseArea)) || (borderRight.collidesWithPath(mouseArea) && borderBottom.collidesWithPath(mouseArea)))
+ setResizeCursor(borderLeft.line().angle() - 45);
+ else if ((borderLeft.collidesWithPath(mouseArea) && borderBottom.collidesWithPath(mouseArea)) || (borderRight.collidesWithPath(mouseArea) && borderTop.collidesWithPath(mouseArea)))
+ setResizeCursor(borderLeft.line().angle() + 45);
+ else if (borderLeft.collidesWithPath(mouseArea) || borderRight.collidesWithPath(mouseArea))
+ setResizeCursor(borderLeft.line().angle());
+ else if (borderTop.collidesWithPath(mouseArea) || borderBottom.collidesWithPath(mouseArea))
+ setResizeCursor(borderTop.line().angle());
else
setCursor(Qt::OpenHandCursor);
break;
}
QGraphicsScene::mouseMoveEvent(e);
} else if (m_tool == TITLE_RECTANGLE && e->buttons() & Qt::LeftButton) {
- if (m_selectedItem == NULL && (m_clickPoint - e->screenPos()).manhattanLength() >= QApplication::startDragDistance()) {
+ if (m_selectedItem == NULL) {
// create new rect item
- m_selectedItem = addRect(0, 0, e->scenePos().x() - m_sceneClickPoint.x(), e->scenePos().y() - m_sceneClickPoint.y());
+ QRectF r(0, 0, e->scenePos().x() - m_sceneClickPoint.x(), e->scenePos().y() - m_sceneClickPoint.y());
+ r = r.normalized();
+ m_selectedItem = addRect(QRectF(0, 0, r.width(), r.height()));
emit newRect((QGraphicsRectItem *) m_selectedItem);
m_selectedItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
m_selectedItem->setPos(m_sceneClickPoint);
v->setCursor(c);
}
}
+
+void GraphicsSceneRectMove::setResizeCursor(qreal angle)
+{
+ // % is not working...
+ while (angle < 0)
+ angle += 180;
+ while (angle >= 180)
+ angle -= 180;
+ if (angle > 157.5 || angle <= 22.5)
+ setCursor(Qt::SizeVerCursor);
+ else if (angle > 22.5 && angle <= 67.5)
+ setCursor(Qt::SizeFDiagCursor);
+ else if (angle > 67.5 && angle <= 112.5)
+ setCursor(Qt::SizeHorCursor);
+ else if (angle > 112.5 && angle <= 157.5)
+ setCursor(Qt::SizeBDiagCursor);
+}