From fba1291c975c6f1f3c2bb6f487732c0fbf9f2399 Mon Sep 17 00:00:00 2001 From: Marco Gittler Date: Tue, 26 Feb 2008 12:47:22 +0000 Subject: [PATCH] rect changeable in size svn path=/branches/KDE4/; revision=1948 --- src/CMakeLists.txt | 1 + src/graphicsscenerectmove.cpp | 129 ++++++++++++++++++++++++++++++++++ src/graphicsscenerectmove.h | 16 +++++ src/titlewidget.cpp | 6 +- src/titlewidget.h | 2 +- 5 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 src/graphicsscenerectmove.cpp create mode 100644 src/graphicsscenerectmove.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3815962d..d12fd869 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -82,6 +82,7 @@ set(kdenlive_SRCS kdenlivesettingsdialog.cpp complexparameter.cpp titlewidget.cpp + graphicsscenerectmove.cpp ) kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc ) diff --git a/src/graphicsscenerectmove.cpp b/src/graphicsscenerectmove.cpp new file mode 100644 index 00000000..62474765 --- /dev/null +++ b/src/graphicsscenerectmove.cpp @@ -0,0 +1,129 @@ +#include "graphicsscenerectmove.h" +#include +#include +#include +#include +#include + +QGraphicsItem* selected=NULL; +int button=0; +int resizeMode=-1; +enum resizeMode {NoResize,TopLeft,BottomLeft,TopRight,BottomRight,Left,Right,Up,Down}; +GraphicsSceneRectMove::GraphicsSceneRectMove(QObject *parent):QGraphicsScene(parent){ + //grabMouse(); +} + +void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e){ + + if (selected && selected->type()==3 &&button==1){ + + QGraphicsRectItem *gi=(QGraphicsRectItem*)selected; + QRectF newrect=gi->rect(); + QPointF newpoint=e->scenePos(); + newpoint-=selected->scenePos(); + switch (resizeMode){ + case TopLeft: + newrect.setTopLeft(newpoint); + break; + case BottomLeft: + newrect.setBottomLeft(newpoint); + break; + case TopRight: + newrect.setTopRight(newpoint); + break; + case BottomRight: + newrect.setBottomRight(newpoint); + break; + case Left: + newrect.setLeft(newpoint.x()); + break; + case Right: + newrect.setRight(newpoint.x()); + break; + case Up: + newrect.setTop(newpoint.y()); + break; + case Down: + newrect.setBottom(newpoint.y()); + break; + } + + gi->setRect(newrect); + gi->setPos(selected->scenePos()); + } + kDebug() << "move"; + QPointF p=e->scenePos(); + p+=QPoint(-2,-2); + resizeMode=NoResize; + selected=NULL; + foreach(QGraphicsItem* g, items( QRectF( p , QSizeF(4,4) ).toRect() ) ){ + + if (g->type()==3 ){ + + QGraphicsRectItem *gi=(QGraphicsRectItem*)g; + QRectF r=gi->rect(); + r.translate(gi->scenePos()); + + if ( (r.toRect().topLeft()-=e->scenePos().toPoint() ).manhattanLength()<3 ){ + resizeMode=TopLeft; + }else if ((r.toRect().bottomLeft()-=e->scenePos().toPoint() ).manhattanLength()<3 ){ + resizeMode=BottomLeft; + }else if ((r.toRect().topRight()-=e->scenePos().toPoint() ).manhattanLength()<3 ){ + resizeMode=TopRight; + }else if ((r.toRect().bottomRight()-=e->scenePos().toPoint() ).manhattanLength()<3 ){ + resizeMode=BottomRight; + }else if ( qAbs(r.toRect().left()-e->scenePos().toPoint().x() ) <3){ + resizeMode=Left; + }else if ( qAbs(r.toRect().right()-e->scenePos().toPoint().x() ) <3){ + resizeMode=Right; + }else if ( qAbs(r.toRect().top()-e->scenePos().toPoint().y() ) <3){ + resizeMode=Up; + }else if ( qAbs(r.toRect().bottom()-e->scenePos().toPoint().y() ) <3){ + resizeMode=Down; + } + if (resizeMode!=NoResize) + selected=gi; + } + } + switch (resizeMode){ + case TopLeft: + case BottomRight: + setCursor(QCursor(Qt::SizeFDiagCursor)); + break; + case BottomLeft: + case TopRight: + setCursor(QCursor(Qt::SizeBDiagCursor)); + break; + case Left: + case Right: + setCursor(Qt::SizeHorCursor); + break; + case Up: + case Down: + setCursor(Qt::SizeVerCursor); + break; + default: + setCursor(QCursor(Qt::ArrowCursor)); + QGraphicsScene::mouseMoveEvent(e); + } + + +} + +void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e){ + button=e->button(); + if (!selected || selected->type()!=3) + QGraphicsScene::mousePressEvent(e); +} +void GraphicsSceneRectMove::mouseReleaseEvent(QGraphicsSceneMouseEvent* e){ + button=0; + if (!selected || selected->type()!=3) + QGraphicsScene::mouseReleaseEvent(e); +} + +void GraphicsSceneRectMove::setCursor(QCursor c){ + QList l=views(); + foreach(QGraphicsView* v, l){ + v->setCursor(c); + } +} diff --git a/src/graphicsscenerectmove.h b/src/graphicsscenerectmove.h new file mode 100644 index 00000000..d67369e7 --- /dev/null +++ b/src/graphicsscenerectmove.h @@ -0,0 +1,16 @@ +#ifndef GRAPHICSVIEWRECTMOVE_H +#define GRAPHICSVIEWRECTMOVE_H + +#include + +class GraphicsSceneRectMove: public QGraphicsScene { +public: + GraphicsSceneRectMove(QObject* parent=0); + void mouseMoveEvent(QGraphicsSceneMouseEvent*); + void mousePressEvent(QGraphicsSceneMouseEvent*); + void mouseReleaseEvent(QGraphicsSceneMouseEvent*); +private: + void setCursor(QCursor); +}; + +#endif diff --git a/src/titlewidget.cpp b/src/titlewidget.cpp index b0b9b6f9..6633dd8b 100644 --- a/src/titlewidget.cpp +++ b/src/titlewidget.cpp @@ -1,5 +1,5 @@ #include "titlewidget.h" -#include +#include "graphicsscenerectmove.h" #include #include #include @@ -12,7 +12,7 @@ TitleWidget::TitleWidget (QDialog *parent):QDialog(parent){ connect (horizontalSlider, SIGNAL ( valueChanged(int) ), this, SLOT( slotChangeBackground()) ) ; connect (ktextedit, SIGNAL(textChanged()), this , SLOT (textChanged())); - QGraphicsScene *scene=new QGraphicsScene(this); + GraphicsSceneRectMove *scene=new GraphicsSceneRectMove(this); @@ -82,5 +82,7 @@ void TitleWidget::textChanged(){ ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml()); } } + + #include "moc_titlewidget.cpp" diff --git a/src/titlewidget.h b/src/titlewidget.h index 82c6fc63..b19ce754 100644 --- a/src/titlewidget.h +++ b/src/titlewidget.h @@ -7,7 +7,7 @@ class TitleWidget : public QDialog , public Ui::TitleWidget_UI{ Q_OBJECT public: - TitleWidget(QDialog *parent=0); + TitleWidget(QDialog *parent=0); public slots: void slotNewText(); void slotNewRect(); -- 2.39.2