]> git.sesse.net Git - kdenlive/commitdiff
rect changeable in size
authorMarco Gittler <marco@gitma.de>
Tue, 26 Feb 2008 12:47:22 +0000 (12:47 +0000)
committerMarco Gittler <marco@gitma.de>
Tue, 26 Feb 2008 12:47:22 +0000 (12:47 +0000)
svn path=/branches/KDE4/; revision=1948

src/CMakeLists.txt
src/graphicsscenerectmove.cpp [new file with mode: 0644]
src/graphicsscenerectmove.h [new file with mode: 0644]
src/titlewidget.cpp
src/titlewidget.h

index 3815962df0f6fa8063bdcc68048a14c367c447b7..d12fd8695ea4975156d26b5245d7cd671448830c 100644 (file)
@@ -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 (file)
index 0000000..6247476
--- /dev/null
@@ -0,0 +1,129 @@
+#include "graphicsscenerectmove.h"
+#include <KDebug>
+#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsRectItem>
+#include <QGraphicsView>
+#include <QCursor>
+
+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<QGraphicsView*> l=views();
+       foreach(QGraphicsView* v, l){
+               v->setCursor(c);
+       }
+}
diff --git a/src/graphicsscenerectmove.h b/src/graphicsscenerectmove.h
new file mode 100644 (file)
index 0000000..d67369e
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef GRAPHICSVIEWRECTMOVE_H
+#define GRAPHICSVIEWRECTMOVE_H
+
+#include <QGraphicsScene>
+
+class GraphicsSceneRectMove: public QGraphicsScene {
+public:
+       GraphicsSceneRectMove(QObject* parent=0);
+       void mouseMoveEvent(QGraphicsSceneMouseEvent*);
+       void mousePressEvent(QGraphicsSceneMouseEvent*);
+       void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
+private:
+       void setCursor(QCursor);
+};
+
+#endif
index b0b9b6f90a970b198c22787f91e688dd1da80a5f..6633dd8b8088f33eec466d3e2ea52061ca497945 100644 (file)
@@ -1,5 +1,5 @@
 #include "titlewidget.h"
-#include <QGraphicsScene>
+#include "graphicsscenerectmove.h"
 #include <QGraphicsView>
 #include <KDebug>
 #include <QGraphicsItem>
@@ -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"
 
index 82c6fc63389358fb77f8aa446f98a50ad7f12db7..b19ce754fc8618da07e2891886d333eacac834c1 100644 (file)
@@ -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();